raspberry-pi.patch 3.1 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655446564465744658446594466044661446624466344664446654466644667446684466944670446714467244673446744467544676446774467844679446804468144682446834468444685446864468744688446894469044691446924469344694446954469644697446984469944700447014470244703447044470544706447074470844709447104471144712447134471444715447164471744718447194472044721447224472344724447254472644727447284472944730447314473244733447344473544736447374473844739447404474144742447434474444745447464474744748447494475044751447524475344754447554475644757447584475944760447614476244763447644476544766447674476844769447704477144772447734477444775447764477744778447794478044781447824478344784447854478644787447884478944790447914479244793447944479544796447974479844799448004480144802448034480444805448064480744808448094481044811448124481344814448154481644817448184481944820448214482244823448244482544826448274482844829448304483144832448334483444835448364483744838448394484044841448424484344844448454484644847448484484944850448514485244853448544485544856448574485844859448604486144862448634486444865448664486744868448694487044871448724487344874448754487644877448784487944880448814488244883448844488544886448874488844889448904489144892448934489444895448964489744898448994490044901449024490344904449054490644907449084490944910449114491244913449144491544916449174491844919449204492144922449234492444925449264492744928449294493044931449324493344934449354493644937449384493944940449414494244943449444494544946449474494844949449504495144952449534495444955449564495744958449594496044961449624496344964449654496644967449684496944970449714497244973449744497544976449774497844979449804498144982449834498444985449864498744988449894499044991449924499344994449954499644997449984499945000450014500245003450044500545006450074500845009450104501145012450134501445015450164501745018450194502045021450224502345024450254502645027450284502945030450314503245033450344503545036450374503845039450404504145042450434504445045450464504745048450494505045051450524505345054450554505645057450584505945060450614506245063450644506545066450674506845069450704507145072450734507445075450764507745078450794508045081450824508345084450854508645087450884508945090450914509245093450944509545096450974509845099451004510145102451034510445105451064510745108451094511045111451124511345114451154511645117451184511945120451214512245123451244512545126451274512845129451304513145132451334513445135451364513745138451394514045141451424514345144451454514645147451484514945150451514515245153451544515545156451574515845159451604516145162451634516445165451664516745168451694517045171451724517345174451754517645177451784517945180451814518245183451844518545186451874518845189451904519145192451934519445195451964519745198451994520045201452024520345204452054520645207452084520945210452114521245213452144521545216452174521845219452204522145222452234522445225452264522745228452294523045231452324523345234452354523645237452384523945240452414524245243452444524545246452474524845249452504525145252452534525445255452564525745258452594526045261452624526345264452654526645267452684526945270452714527245273452744527545276452774527845279452804528145282452834528445285452864528745288452894529045291452924529345294452954529645297452984529945300453014530245303453044530545306453074530845309453104531145312453134531445315453164531745318453194532045321453224532345324453254532645327453284532945330453314533245333453344533545336453374533845339453404534145342453434534445345453464534745348453494535045351453524535345354453554535645357453584535945360453614536245363453644536545366453674536845369453704537145372453734537445375453764537745378453794538045381453824538345384453854538645387453884538945390453914539245393453944539545396453974539845399454004540145402454034540445405454064540745408454094541045411454124541345414454154541645417454184541945420454214542245423454244542545426454274542845429454304543145432454334543445435454364543745438454394544045441454424544345444454454544645447454484544945450454514545245453454544545545456454574545845459454604546145462454634546445465454664546745468454694547045471454724547345474454754547645477454784547945480454814548245483454844548545486454874548845489454904549145492454934549445495454964549745498454994550045501455024550345504455054550645507455084550945510455114551245513455144551545516455174551845519455204552145522455234552445525455264552745528455294553045531455324553345534455354553645537455384553945540455414554245543455444554545546455474554845549455504555145552455534555445555455564555745558455594556045561455624556345564455654556645567455684556945570455714557245573455744557545576455774557845579455804558145582455834558445585455864558745588455894559045591455924559345594455954559645597455984559945600456014560245603456044560545606456074560845609456104561145612456134561445615456164561745618456194562045621456224562345624456254562645627456284562945630456314563245633456344563545636456374563845639456404564145642456434564445645456464564745648456494565045651456524565345654456554565645657456584565945660456614566245663456644566545666456674566845669456704567145672456734567445675456764567745678456794568045681456824568345684456854568645687456884568945690456914569245693456944569545696456974569845699457004570145702457034570445705457064570745708457094571045711457124571345714457154571645717457184571945720457214572245723457244572545726457274572845729457304573145732457334573445735457364573745738457394574045741457424574345744457454574645747457484574945750457514575245753457544575545756457574575845759457604576145762457634576445765457664576745768457694577045771457724577345774457754577645777457784577945780457814578245783457844578545786457874578845789457904579145792457934579445795457964579745798457994580045801458024580345804458054580645807458084580945810458114581245813458144581545816458174581845819458204582145822458234582445825458264582745828458294583045831458324583345834458354583645837458384583945840458414584245843458444584545846458474584845849458504585145852458534585445855458564585745858458594586045861458624586345864458654586645867458684586945870458714587245873458744587545876458774587845879458804588145882458834588445885458864588745888458894589045891458924589345894458954589645897458984589945900459014590245903459044590545906459074590845909459104591145912459134591445915459164591745918459194592045921459224592345924459254592645927459284592945930459314593245933459344593545936459374593845939459404594145942459434594445945459464594745948459494595045951459524595345954459554595645957459584595945960459614596245963459644596545966459674596845969459704597145972459734597445975459764597745978459794598045981459824598345984459854598645987459884598945990459914599245993459944599545996459974599845999460004600146002460034600446005460064600746008460094601046011460124601346014460154601646017460184601946020460214602246023460244602546026460274602846029460304603146032460334603446035460364603746038460394604046041460424604346044460454604646047460484604946050460514605246053460544605546056460574605846059460604606146062460634606446065460664606746068460694607046071460724607346074460754607646077460784607946080460814608246083460844608546086460874608846089460904609146092460934609446095460964609746098460994610046101461024610346104461054610646107461084610946110461114611246113461144611546116461174611846119461204612146122461234612446125461264612746128461294613046131461324613346134461354613646137461384613946140461414614246143461444614546146461474614846149461504615146152461534615446155461564615746158461594616046161461624616346164461654616646167461684616946170461714617246173461744617546176461774617846179461804618146182461834618446185461864618746188461894619046191461924619346194461954619646197461984619946200462014620246203462044620546206462074620846209462104621146212462134621446215462164621746218462194622046221462224622346224462254622646227462284622946230462314623246233462344623546236462374623846239462404624146242462434624446245462464624746248462494625046251462524625346254462554625646257462584625946260462614626246263462644626546266462674626846269462704627146272462734627446275462764627746278462794628046281462824628346284462854628646287462884628946290462914629246293462944629546296462974629846299463004630146302463034630446305463064630746308463094631046311463124631346314463154631646317463184631946320463214632246323463244632546326463274632846329463304633146332463334633446335463364633746338463394634046341463424634346344463454634646347463484634946350463514635246353463544635546356463574635846359463604636146362463634636446365463664636746368463694637046371463724637346374463754637646377463784637946380463814638246383463844638546386463874638846389463904639146392463934639446395463964639746398463994640046401464024640346404464054640646407464084640946410464114641246413464144641546416464174641846419464204642146422464234642446425464264642746428464294643046431464324643346434464354643646437464384643946440464414644246443464444644546446464474644846449464504645146452464534645446455464564645746458464594646046461464624646346464464654646646467464684646946470464714647246473464744647546476464774647846479464804648146482464834648446485464864648746488464894649046491464924649346494464954649646497464984649946500465014650246503465044650546506465074650846509465104651146512465134651446515465164651746518465194652046521465224652346524465254652646527465284652946530465314653246533465344653546536465374653846539465404654146542465434654446545465464654746548465494655046551465524655346554465554655646557465584655946560465614656246563465644656546566465674656846569465704657146572465734657446575465764657746578465794658046581465824658346584465854658646587465884658946590465914659246593465944659546596465974659846599466004660146602466034660446605466064660746608466094661046611466124661346614466154661646617466184661946620466214662246623466244662546626466274662846629466304663146632466334663446635466364663746638466394664046641466424664346644466454664646647466484664946650466514665246653466544665546656466574665846659466604666146662466634666446665466664666746668466694667046671466724667346674466754667646677466784667946680466814668246683466844668546686466874668846689466904669146692466934669446695466964669746698466994670046701467024670346704467054670646707467084670946710467114671246713467144671546716467174671846719467204672146722467234672446725467264672746728467294673046731467324673346734467354673646737467384673946740467414674246743467444674546746467474674846749467504675146752467534675446755467564675746758467594676046761467624676346764467654676646767467684676946770467714677246773467744677546776467774677846779467804678146782467834678446785467864678746788467894679046791467924679346794467954679646797467984679946800468014680246803468044680546806468074680846809468104681146812468134681446815468164681746818468194682046821468224682346824468254682646827468284682946830468314683246833468344683546836468374683846839468404684146842468434684446845468464684746848468494685046851468524685346854468554685646857468584685946860468614686246863468644686546866468674686846869468704687146872468734687446875468764687746878468794688046881468824688346884468854688646887468884688946890468914689246893468944689546896468974689846899469004690146902469034690446905469064690746908469094691046911469124691346914469154691646917469184691946920469214692246923469244692546926469274692846929469304693146932469334693446935469364693746938469394694046941469424694346944469454694646947469484694946950469514695246953469544695546956469574695846959469604696146962469634696446965469664696746968469694697046971469724697346974469754697646977469784697946980469814698246983469844698546986469874698846989469904699146992469934699446995469964699746998469994700047001470024700347004470054700647007470084700947010470114701247013470144701547016470174701847019470204702147022470234702447025470264702747028470294703047031470324703347034470354703647037470384703947040470414704247043470444704547046470474704847049470504705147052470534705447055470564705747058470594706047061470624706347064470654706647067470684706947070470714707247073470744707547076470774707847079470804708147082470834708447085470864708747088470894709047091470924709347094470954709647097470984709947100471014710247103471044710547106471074710847109471104711147112471134711447115471164711747118471194712047121471224712347124471254712647127471284712947130471314713247133471344713547136471374713847139471404714147142471434714447145471464714747148471494715047151471524715347154471554715647157471584715947160471614716247163471644716547166471674716847169471704717147172471734717447175471764717747178471794718047181471824718347184471854718647187471884718947190471914719247193471944719547196471974719847199472004720147202472034720447205472064720747208472094721047211472124721347214472154721647217472184721947220472214722247223472244722547226472274722847229472304723147232472334723447235472364723747238472394724047241472424724347244472454724647247472484724947250472514725247253472544725547256472574725847259472604726147262472634726447265472664726747268472694727047271472724727347274472754727647277472784727947280472814728247283472844728547286472874728847289472904729147292472934729447295472964729747298472994730047301473024730347304473054730647307473084730947310473114731247313473144731547316473174731847319473204732147322473234732447325473264732747328473294733047331473324733347334473354733647337473384733947340473414734247343473444734547346473474734847349473504735147352473534735447355473564735747358473594736047361473624736347364473654736647367473684736947370473714737247373473744737547376473774737847379473804738147382473834738447385473864738747388473894739047391473924739347394473954739647397473984739947400474014740247403474044740547406474074740847409474104741147412474134741447415474164741747418474194742047421474224742347424474254742647427474284742947430474314743247433474344743547436474374743847439474404744147442474434744447445474464744747448474494745047451474524745347454474554745647457474584745947460474614746247463474644746547466474674746847469474704747147472474734747447475474764747747478474794748047481474824748347484474854748647487474884748947490474914749247493474944749547496474974749847499475004750147502475034750447505475064750747508475094751047511475124751347514475154751647517475184751947520475214752247523475244752547526475274752847529475304753147532475334753447535475364753747538475394754047541475424754347544475454754647547475484754947550475514755247553475544755547556475574755847559475604756147562475634756447565475664756747568475694757047571475724757347574475754757647577475784757947580475814758247583475844758547586475874758847589475904759147592475934759447595475964759747598475994760047601476024760347604476054760647607476084760947610476114761247613476144761547616476174761847619476204762147622476234762447625476264762747628476294763047631476324763347634476354763647637476384763947640476414764247643476444764547646476474764847649476504765147652476534765447655476564765747658476594766047661476624766347664476654766647667476684766947670476714767247673476744767547676476774767847679476804768147682476834768447685476864768747688476894769047691476924769347694476954769647697476984769947700477014770247703477044770547706477074770847709477104771147712477134771447715477164771747718477194772047721477224772347724477254772647727477284772947730477314773247733477344773547736477374773847739477404774147742477434774447745477464774747748477494775047751477524775347754477554775647757477584775947760477614776247763477644776547766477674776847769477704777147772477734777447775477764777747778477794778047781477824778347784477854778647787477884778947790477914779247793477944779547796477974779847799478004780147802478034780447805478064780747808478094781047811478124781347814478154781647817478184781947820478214782247823478244782547826478274782847829478304783147832478334783447835478364783747838478394784047841478424784347844478454784647847478484784947850478514785247853478544785547856478574785847859478604786147862478634786447865478664786747868478694787047871478724787347874478754787647877478784787947880478814788247883478844788547886478874788847889478904789147892478934789447895478964789747898478994790047901479024790347904479054790647907479084790947910479114791247913479144791547916479174791847919479204792147922479234792447925479264792747928479294793047931479324793347934479354793647937479384793947940479414794247943479444794547946479474794847949479504795147952479534795447955479564795747958479594796047961479624796347964479654796647967479684796947970479714797247973479744797547976479774797847979479804798147982479834798447985479864798747988479894799047991479924799347994479954799647997479984799948000480014800248003480044800548006480074800848009480104801148012480134801448015480164801748018480194802048021480224802348024480254802648027480284802948030480314803248033480344803548036480374803848039480404804148042480434804448045480464804748048480494805048051480524805348054480554805648057480584805948060480614806248063480644806548066480674806848069480704807148072480734807448075480764807748078480794808048081480824808348084480854808648087480884808948090480914809248093480944809548096480974809848099481004810148102481034810448105481064810748108481094811048111481124811348114481154811648117481184811948120481214812248123481244812548126481274812848129481304813148132481334813448135481364813748138481394814048141481424814348144481454814648147481484814948150481514815248153481544815548156481574815848159481604816148162481634816448165481664816748168481694817048171481724817348174481754817648177481784817948180481814818248183481844818548186481874818848189481904819148192481934819448195481964819748198481994820048201482024820348204482054820648207482084820948210482114821248213482144821548216482174821848219482204822148222482234822448225482264822748228482294823048231482324823348234482354823648237482384823948240482414824248243482444824548246482474824848249482504825148252482534825448255482564825748258482594826048261482624826348264482654826648267482684826948270482714827248273482744827548276482774827848279482804828148282482834828448285482864828748288482894829048291482924829348294482954829648297482984829948300483014830248303483044830548306483074830848309483104831148312483134831448315483164831748318483194832048321483224832348324483254832648327483284832948330483314833248333483344833548336483374833848339483404834148342483434834448345483464834748348483494835048351483524835348354483554835648357483584835948360483614836248363483644836548366483674836848369483704837148372483734837448375483764837748378483794838048381483824838348384483854838648387483884838948390483914839248393483944839548396483974839848399484004840148402484034840448405484064840748408484094841048411484124841348414484154841648417484184841948420484214842248423484244842548426484274842848429484304843148432484334843448435484364843748438484394844048441484424844348444484454844648447484484844948450484514845248453484544845548456484574845848459484604846148462484634846448465484664846748468484694847048471484724847348474484754847648477484784847948480484814848248483484844848548486484874848848489484904849148492484934849448495484964849748498484994850048501485024850348504485054850648507485084850948510485114851248513485144851548516485174851848519485204852148522485234852448525485264852748528485294853048531485324853348534485354853648537485384853948540485414854248543485444854548546485474854848549485504855148552485534855448555485564855748558485594856048561485624856348564485654856648567485684856948570485714857248573485744857548576485774857848579485804858148582485834858448585485864858748588485894859048591485924859348594485954859648597485984859948600486014860248603486044860548606486074860848609486104861148612486134861448615486164861748618486194862048621486224862348624486254862648627486284862948630486314863248633486344863548636486374863848639486404864148642486434864448645486464864748648486494865048651486524865348654486554865648657486584865948660486614866248663486644866548666486674866848669486704867148672486734867448675486764867748678486794868048681486824868348684486854868648687486884868948690486914869248693486944869548696486974869848699487004870148702487034870448705487064870748708487094871048711487124871348714487154871648717487184871948720487214872248723487244872548726487274872848729487304873148732487334873448735487364873748738487394874048741487424874348744487454874648747487484874948750487514875248753487544875548756487574875848759487604876148762487634876448765487664876748768487694877048771487724877348774487754877648777487784877948780487814878248783487844878548786487874878848789487904879148792487934879448795487964879748798487994880048801488024880348804488054880648807488084880948810488114881248813488144881548816488174881848819488204882148822488234882448825488264882748828488294883048831488324883348834488354883648837488384883948840488414884248843488444884548846488474884848849488504885148852488534885448855488564885748858488594886048861488624886348864488654886648867488684886948870488714887248873488744887548876488774887848879488804888148882488834888448885488864888748888488894889048891488924889348894488954889648897488984889948900489014890248903489044890548906489074890848909489104891148912489134891448915489164891748918489194892048921489224892348924489254892648927489284892948930489314893248933489344893548936489374893848939489404894148942489434894448945489464894748948489494895048951489524895348954489554895648957489584895948960489614896248963489644896548966489674896848969489704897148972489734897448975489764897748978489794898048981489824898348984489854898648987489884898948990489914899248993489944899548996489974899848999490004900149002490034900449005490064900749008490094901049011490124901349014490154901649017490184901949020490214902249023490244902549026490274902849029490304903149032490334903449035490364903749038490394904049041490424904349044490454904649047490484904949050490514905249053490544905549056490574905849059490604906149062490634906449065490664906749068490694907049071490724907349074490754907649077490784907949080490814908249083490844908549086490874908849089490904909149092490934909449095490964909749098490994910049101491024910349104491054910649107491084910949110491114911249113491144911549116491174911849119491204912149122491234912449125491264912749128491294913049131491324913349134491354913649137491384913949140491414914249143491444914549146491474914849149491504915149152491534915449155491564915749158491594916049161491624916349164491654916649167491684916949170491714917249173491744917549176491774917849179491804918149182491834918449185491864918749188491894919049191491924919349194491954919649197491984919949200492014920249203492044920549206492074920849209492104921149212492134921449215492164921749218492194922049221492224922349224492254922649227492284922949230492314923249233492344923549236492374923849239492404924149242492434924449245492464924749248492494925049251492524925349254492554925649257492584925949260492614926249263492644926549266492674926849269492704927149272492734927449275492764927749278492794928049281492824928349284492854928649287492884928949290492914929249293492944929549296492974929849299493004930149302493034930449305493064930749308493094931049311493124931349314493154931649317493184931949320493214932249323493244932549326493274932849329493304933149332493334933449335493364933749338493394934049341493424934349344493454934649347493484934949350493514935249353493544935549356493574935849359493604936149362493634936449365493664936749368493694937049371493724937349374493754937649377493784937949380493814938249383493844938549386493874938849389493904939149392493934939449395493964939749398493994940049401494024940349404494054940649407494084940949410494114941249413494144941549416494174941849419494204942149422494234942449425494264942749428494294943049431494324943349434494354943649437494384943949440494414944249443494444944549446494474944849449494504945149452494534945449455494564945749458494594946049461494624946349464494654946649467494684946949470494714947249473494744947549476494774947849479494804948149482494834948449485494864948749488494894949049491494924949349494494954949649497494984949949500495014950249503495044950549506495074950849509495104951149512495134951449515495164951749518495194952049521495224952349524495254952649527495284952949530495314953249533495344953549536495374953849539495404954149542495434954449545495464954749548495494955049551495524955349554495554955649557495584955949560495614956249563495644956549566495674956849569495704957149572495734957449575495764957749578495794958049581495824958349584495854958649587495884958949590495914959249593495944959549596495974959849599496004960149602496034960449605496064960749608496094961049611496124961349614496154961649617496184961949620496214962249623496244962549626496274962849629496304963149632496334963449635496364963749638496394964049641496424964349644496454964649647496484964949650496514965249653496544965549656496574965849659496604966149662496634966449665496664966749668496694967049671496724967349674496754967649677496784967949680496814968249683496844968549686496874968849689496904969149692496934969449695496964969749698496994970049701497024970349704497054970649707497084970949710497114971249713497144971549716497174971849719497204972149722497234972449725497264972749728497294973049731497324973349734497354973649737497384973949740497414974249743497444974549746497474974849749497504975149752497534975449755497564975749758497594976049761497624976349764497654976649767497684976949770497714977249773497744977549776497774977849779497804978149782497834978449785497864978749788497894979049791497924979349794497954979649797497984979949800498014980249803498044980549806498074980849809498104981149812498134981449815498164981749818498194982049821498224982349824498254982649827498284982949830498314983249833498344983549836498374983849839498404984149842498434984449845498464984749848498494985049851498524985349854498554985649857498584985949860498614986249863498644986549866498674986849869498704987149872498734987449875498764987749878498794988049881498824988349884498854988649887498884988949890498914989249893498944989549896498974989849899499004990149902499034990449905499064990749908499094991049911499124991349914499154991649917499184991949920499214992249923499244992549926499274992849929499304993149932499334993449935499364993749938499394994049941499424994349944499454994649947499484994949950499514995249953499544995549956499574995849959499604996149962499634996449965499664996749968499694997049971499724997349974499754997649977499784997949980499814998249983499844998549986499874998849989499904999149992499934999449995499964999749998499995000050001500025000350004500055000650007500085000950010500115001250013500145001550016500175001850019500205002150022500235002450025500265002750028500295003050031500325003350034500355003650037500385003950040500415004250043500445004550046500475004850049500505005150052500535005450055500565005750058500595006050061500625006350064500655006650067500685006950070500715007250073500745007550076500775007850079500805008150082500835008450085500865008750088500895009050091500925009350094500955009650097500985009950100501015010250103501045010550106501075010850109501105011150112501135011450115501165011750118501195012050121501225012350124501255012650127501285012950130501315013250133501345013550136501375013850139501405014150142501435014450145501465014750148501495015050151501525015350154501555015650157501585015950160501615016250163501645016550166501675016850169501705017150172501735017450175501765017750178501795018050181501825018350184501855018650187501885018950190501915019250193501945019550196501975019850199502005020150202502035020450205502065020750208502095021050211502125021350214502155021650217502185021950220502215022250223502245022550226502275022850229502305023150232502335023450235502365023750238502395024050241502425024350244502455024650247502485024950250502515025250253502545025550256502575025850259502605026150262502635026450265502665026750268502695027050271502725027350274502755027650277502785027950280502815028250283502845028550286502875028850289502905029150292502935029450295502965029750298502995030050301503025030350304503055030650307503085030950310503115031250313503145031550316503175031850319503205032150322503235032450325503265032750328503295033050331503325033350334503355033650337503385033950340503415034250343503445034550346503475034850349503505035150352503535035450355503565035750358503595036050361503625036350364503655036650367503685036950370503715037250373503745037550376503775037850379503805038150382503835038450385503865038750388503895039050391503925039350394503955039650397503985039950400504015040250403504045040550406504075040850409504105041150412504135041450415504165041750418504195042050421504225042350424504255042650427504285042950430504315043250433504345043550436504375043850439504405044150442504435044450445504465044750448504495045050451504525045350454504555045650457504585045950460504615046250463504645046550466504675046850469504705047150472504735047450475504765047750478504795048050481504825048350484504855048650487504885048950490504915049250493504945049550496504975049850499505005050150502505035050450505505065050750508505095051050511505125051350514505155051650517505185051950520505215052250523505245052550526505275052850529505305053150532505335053450535505365053750538505395054050541505425054350544505455054650547505485054950550505515055250553505545055550556505575055850559505605056150562505635056450565505665056750568505695057050571505725057350574505755057650577505785057950580505815058250583505845058550586505875058850589505905059150592505935059450595505965059750598505995060050601506025060350604506055060650607506085060950610506115061250613506145061550616506175061850619506205062150622506235062450625506265062750628506295063050631506325063350634506355063650637506385063950640506415064250643506445064550646506475064850649506505065150652506535065450655506565065750658506595066050661506625066350664506655066650667506685066950670506715067250673506745067550676506775067850679506805068150682506835068450685506865068750688506895069050691506925069350694506955069650697506985069950700507015070250703507045070550706507075070850709507105071150712507135071450715507165071750718507195072050721507225072350724507255072650727507285072950730507315073250733507345073550736507375073850739507405074150742507435074450745507465074750748507495075050751507525075350754507555075650757507585075950760507615076250763507645076550766507675076850769507705077150772507735077450775507765077750778507795078050781507825078350784507855078650787507885078950790507915079250793507945079550796507975079850799508005080150802508035080450805508065080750808508095081050811508125081350814508155081650817508185081950820508215082250823508245082550826508275082850829508305083150832508335083450835508365083750838508395084050841508425084350844508455084650847508485084950850508515085250853508545085550856508575085850859508605086150862508635086450865508665086750868508695087050871508725087350874508755087650877508785087950880508815088250883508845088550886508875088850889508905089150892508935089450895508965089750898508995090050901509025090350904509055090650907509085090950910509115091250913509145091550916509175091850919509205092150922509235092450925509265092750928509295093050931509325093350934509355093650937509385093950940509415094250943509445094550946509475094850949509505095150952509535095450955509565095750958509595096050961509625096350964509655096650967509685096950970509715097250973509745097550976509775097850979509805098150982509835098450985509865098750988509895099050991509925099350994509955099650997509985099951000510015100251003510045100551006510075100851009510105101151012510135101451015510165101751018510195102051021510225102351024510255102651027510285102951030510315103251033510345103551036510375103851039510405104151042510435104451045510465104751048510495105051051510525105351054510555105651057510585105951060510615106251063510645106551066510675106851069510705107151072510735107451075510765107751078510795108051081510825108351084510855108651087510885108951090510915109251093510945109551096510975109851099511005110151102511035110451105511065110751108511095111051111511125111351114511155111651117511185111951120511215112251123511245112551126511275112851129511305113151132511335113451135511365113751138511395114051141511425114351144511455114651147511485114951150511515115251153511545115551156511575115851159511605116151162511635116451165511665116751168511695117051171511725117351174511755117651177511785117951180511815118251183511845118551186511875118851189511905119151192511935119451195511965119751198511995120051201512025120351204512055120651207512085120951210512115121251213512145121551216512175121851219512205122151222512235122451225512265122751228512295123051231512325123351234512355123651237512385123951240512415124251243512445124551246512475124851249512505125151252512535125451255512565125751258512595126051261512625126351264512655126651267512685126951270512715127251273512745127551276512775127851279512805128151282512835128451285512865128751288512895129051291512925129351294512955129651297512985129951300513015130251303513045130551306513075130851309513105131151312513135131451315513165131751318513195132051321513225132351324513255132651327513285132951330513315133251333513345133551336513375133851339513405134151342513435134451345513465134751348513495135051351513525135351354513555135651357513585135951360513615136251363513645136551366513675136851369513705137151372513735137451375513765137751378513795138051381513825138351384513855138651387513885138951390513915139251393513945139551396513975139851399514005140151402514035140451405514065140751408514095141051411514125141351414514155141651417514185141951420514215142251423514245142551426514275142851429514305143151432514335143451435514365143751438514395144051441514425144351444514455144651447514485144951450514515145251453514545145551456514575145851459514605146151462514635146451465514665146751468514695147051471514725147351474514755147651477514785147951480514815148251483514845148551486514875148851489514905149151492514935149451495514965149751498514995150051501515025150351504515055150651507515085150951510515115151251513515145151551516515175151851519515205152151522515235152451525515265152751528515295153051531515325153351534515355153651537515385153951540515415154251543515445154551546515475154851549515505155151552515535155451555515565155751558515595156051561515625156351564515655156651567515685156951570515715157251573515745157551576515775157851579515805158151582515835158451585515865158751588515895159051591515925159351594515955159651597515985159951600516015160251603516045160551606516075160851609516105161151612516135161451615516165161751618516195162051621516225162351624516255162651627516285162951630516315163251633516345163551636516375163851639516405164151642516435164451645516465164751648516495165051651516525165351654516555165651657516585165951660516615166251663516645166551666516675166851669516705167151672516735167451675516765167751678516795168051681516825168351684516855168651687516885168951690516915169251693516945169551696516975169851699517005170151702517035170451705517065170751708517095171051711517125171351714517155171651717517185171951720517215172251723517245172551726517275172851729517305173151732517335173451735517365173751738517395174051741517425174351744517455174651747517485174951750517515175251753517545175551756517575175851759517605176151762517635176451765517665176751768517695177051771517725177351774517755177651777517785177951780517815178251783517845178551786517875178851789517905179151792517935179451795517965179751798517995180051801518025180351804518055180651807518085180951810518115181251813518145181551816518175181851819518205182151822518235182451825518265182751828518295183051831518325183351834518355183651837518385183951840518415184251843518445184551846518475184851849518505185151852518535185451855518565185751858518595186051861518625186351864518655186651867518685186951870518715187251873518745187551876518775187851879518805188151882518835188451885518865188751888518895189051891518925189351894518955189651897518985189951900519015190251903519045190551906519075190851909519105191151912519135191451915519165191751918519195192051921519225192351924519255192651927519285192951930519315193251933519345193551936519375193851939519405194151942519435194451945519465194751948519495195051951519525195351954519555195651957519585195951960519615196251963519645196551966519675196851969519705197151972519735197451975519765197751978519795198051981519825198351984519855198651987519885198951990519915199251993519945199551996519975199851999520005200152002520035200452005520065200752008520095201052011520125201352014520155201652017520185201952020520215202252023520245202552026520275202852029520305203152032520335203452035520365203752038520395204052041520425204352044520455204652047520485204952050520515205252053520545205552056520575205852059520605206152062520635206452065520665206752068520695207052071520725207352074520755207652077520785207952080520815208252083520845208552086520875208852089520905209152092520935209452095520965209752098520995210052101521025210352104521055210652107521085210952110521115211252113521145211552116521175211852119521205212152122521235212452125521265212752128521295213052131521325213352134521355213652137521385213952140521415214252143521445214552146521475214852149521505215152152521535215452155521565215752158521595216052161521625216352164521655216652167521685216952170521715217252173521745217552176521775217852179521805218152182521835218452185521865218752188521895219052191521925219352194521955219652197521985219952200522015220252203522045220552206522075220852209522105221152212522135221452215522165221752218522195222052221522225222352224522255222652227522285222952230522315223252233522345223552236522375223852239522405224152242522435224452245522465224752248522495225052251522525225352254522555225652257522585225952260522615226252263522645226552266522675226852269522705227152272522735227452275522765227752278522795228052281522825228352284522855228652287522885228952290522915229252293522945229552296522975229852299523005230152302523035230452305523065230752308523095231052311523125231352314523155231652317523185231952320523215232252323523245232552326523275232852329523305233152332523335233452335523365233752338523395234052341523425234352344523455234652347523485234952350523515235252353523545235552356523575235852359523605236152362523635236452365523665236752368523695237052371523725237352374523755237652377523785237952380523815238252383523845238552386523875238852389523905239152392523935239452395523965239752398523995240052401524025240352404524055240652407524085240952410524115241252413524145241552416524175241852419524205242152422524235242452425524265242752428524295243052431524325243352434524355243652437524385243952440524415244252443524445244552446524475244852449524505245152452524535245452455524565245752458524595246052461524625246352464524655246652467524685246952470524715247252473524745247552476524775247852479524805248152482524835248452485524865248752488524895249052491524925249352494524955249652497524985249952500525015250252503525045250552506525075250852509525105251152512525135251452515525165251752518525195252052521525225252352524525255252652527525285252952530525315253252533525345253552536525375253852539525405254152542525435254452545525465254752548525495255052551525525255352554525555255652557525585255952560525615256252563525645256552566525675256852569525705257152572525735257452575525765257752578525795258052581525825258352584525855258652587525885258952590525915259252593525945259552596525975259852599526005260152602526035260452605526065260752608526095261052611526125261352614526155261652617526185261952620526215262252623526245262552626526275262852629526305263152632526335263452635526365263752638526395264052641526425264352644526455264652647526485264952650526515265252653526545265552656526575265852659526605266152662526635266452665526665266752668526695267052671526725267352674526755267652677526785267952680526815268252683526845268552686526875268852689526905269152692526935269452695526965269752698526995270052701527025270352704527055270652707527085270952710527115271252713527145271552716527175271852719527205272152722527235272452725527265272752728527295273052731527325273352734527355273652737527385273952740527415274252743527445274552746527475274852749527505275152752527535275452755527565275752758527595276052761527625276352764527655276652767527685276952770527715277252773527745277552776527775277852779527805278152782527835278452785527865278752788527895279052791527925279352794527955279652797527985279952800528015280252803528045280552806528075280852809528105281152812528135281452815528165281752818528195282052821528225282352824528255282652827528285282952830528315283252833528345283552836528375283852839528405284152842528435284452845528465284752848528495285052851528525285352854528555285652857528585285952860528615286252863528645286552866528675286852869528705287152872528735287452875528765287752878528795288052881528825288352884528855288652887528885288952890528915289252893528945289552896528975289852899529005290152902529035290452905529065290752908529095291052911529125291352914529155291652917529185291952920529215292252923529245292552926529275292852929529305293152932529335293452935529365293752938529395294052941529425294352944529455294652947529485294952950529515295252953529545295552956529575295852959529605296152962529635296452965529665296752968529695297052971529725297352974529755297652977529785297952980529815298252983529845298552986529875298852989529905299152992529935299452995529965299752998529995300053001530025300353004530055300653007530085300953010530115301253013530145301553016530175301853019530205302153022530235302453025530265302753028530295303053031530325303353034530355303653037530385303953040530415304253043530445304553046530475304853049530505305153052530535305453055530565305753058530595306053061530625306353064530655306653067530685306953070530715307253073530745307553076530775307853079530805308153082530835308453085530865308753088530895309053091530925309353094530955309653097530985309953100531015310253103531045310553106531075310853109531105311153112531135311453115531165311753118531195312053121531225312353124531255312653127531285312953130531315313253133531345313553136531375313853139531405314153142531435314453145531465314753148531495315053151531525315353154531555315653157531585315953160531615316253163531645316553166531675316853169531705317153172531735317453175531765317753178531795318053181531825318353184531855318653187531885318953190531915319253193531945319553196531975319853199532005320153202532035320453205532065320753208532095321053211532125321353214532155321653217532185321953220532215322253223532245322553226532275322853229532305323153232532335323453235532365323753238532395324053241532425324353244532455324653247532485324953250532515325253253532545325553256532575325853259532605326153262532635326453265532665326753268532695327053271532725327353274532755327653277532785327953280532815328253283532845328553286532875328853289532905329153292532935329453295532965329753298532995330053301533025330353304533055330653307533085330953310533115331253313533145331553316533175331853319533205332153322533235332453325533265332753328533295333053331533325333353334533355333653337533385333953340533415334253343533445334553346533475334853349533505335153352533535335453355533565335753358533595336053361533625336353364533655336653367533685336953370533715337253373533745337553376533775337853379533805338153382533835338453385533865338753388533895339053391533925339353394533955339653397533985339953400534015340253403534045340553406534075340853409534105341153412534135341453415534165341753418534195342053421534225342353424534255342653427534285342953430534315343253433534345343553436534375343853439534405344153442534435344453445534465344753448534495345053451534525345353454534555345653457534585345953460534615346253463534645346553466534675346853469534705347153472534735347453475534765347753478534795348053481534825348353484534855348653487534885348953490534915349253493534945349553496534975349853499535005350153502535035350453505535065350753508535095351053511535125351353514535155351653517535185351953520535215352253523535245352553526535275352853529535305353153532535335353453535535365353753538535395354053541535425354353544535455354653547535485354953550535515355253553535545355553556535575355853559535605356153562535635356453565535665356753568535695357053571535725357353574535755357653577535785357953580535815358253583535845358553586535875358853589535905359153592535935359453595535965359753598535995360053601536025360353604536055360653607536085360953610536115361253613536145361553616536175361853619536205362153622536235362453625536265362753628536295363053631536325363353634536355363653637536385363953640536415364253643536445364553646536475364853649536505365153652536535365453655536565365753658536595366053661536625366353664536655366653667536685366953670536715367253673536745367553676536775367853679536805368153682536835368453685536865368753688536895369053691536925369353694536955369653697536985369953700537015370253703537045370553706537075370853709537105371153712537135371453715537165371753718537195372053721537225372353724537255372653727537285372953730537315373253733537345373553736537375373853739537405374153742537435374453745537465374753748537495375053751537525375353754537555375653757537585375953760537615376253763537645376553766537675376853769537705377153772537735377453775537765377753778537795378053781537825378353784537855378653787537885378953790537915379253793537945379553796537975379853799538005380153802538035380453805538065380753808538095381053811538125381353814538155381653817538185381953820538215382253823538245382553826538275382853829538305383153832538335383453835538365383753838538395384053841538425384353844538455384653847538485384953850538515385253853538545385553856538575385853859538605386153862538635386453865538665386753868538695387053871538725387353874538755387653877538785387953880538815388253883538845388553886538875388853889538905389153892538935389453895538965389753898538995390053901539025390353904539055390653907539085390953910539115391253913539145391553916539175391853919539205392153922539235392453925539265392753928539295393053931539325393353934539355393653937539385393953940539415394253943539445394553946539475394853949539505395153952539535395453955539565395753958539595396053961539625396353964539655396653967539685396953970539715397253973539745397553976539775397853979539805398153982539835398453985539865398753988539895399053991539925399353994539955399653997539985399954000540015400254003540045400554006540075400854009540105401154012540135401454015540165401754018540195402054021540225402354024540255402654027540285402954030540315403254033540345403554036540375403854039540405404154042540435404454045540465404754048540495405054051540525405354054540555405654057540585405954060540615406254063540645406554066540675406854069540705407154072540735407454075540765407754078540795408054081540825408354084540855408654087540885408954090540915409254093540945409554096540975409854099541005410154102541035410454105541065410754108541095411054111541125411354114541155411654117541185411954120541215412254123541245412554126541275412854129541305413154132541335413454135541365413754138541395414054141541425414354144541455414654147541485414954150541515415254153541545415554156541575415854159541605416154162541635416454165541665416754168541695417054171541725417354174541755417654177541785417954180541815418254183541845418554186541875418854189541905419154192541935419454195541965419754198541995420054201542025420354204542055420654207542085420954210542115421254213542145421554216542175421854219542205422154222542235422454225542265422754228542295423054231542325423354234542355423654237542385423954240542415424254243542445424554246542475424854249542505425154252542535425454255542565425754258542595426054261542625426354264542655426654267542685426954270542715427254273542745427554276542775427854279542805428154282542835428454285542865428754288542895429054291542925429354294542955429654297542985429954300543015430254303543045430554306543075430854309543105431154312543135431454315543165431754318543195432054321543225432354324543255432654327543285432954330543315433254333543345433554336543375433854339543405434154342543435434454345543465434754348543495435054351543525435354354543555435654357543585435954360543615436254363543645436554366543675436854369543705437154372543735437454375543765437754378543795438054381543825438354384543855438654387543885438954390543915439254393543945439554396543975439854399544005440154402544035440454405544065440754408544095441054411544125441354414544155441654417544185441954420544215442254423544245442554426544275442854429544305443154432544335443454435544365443754438544395444054441544425444354444544455444654447544485444954450544515445254453544545445554456544575445854459544605446154462544635446454465544665446754468544695447054471544725447354474544755447654477544785447954480544815448254483544845448554486544875448854489544905449154492544935449454495544965449754498544995450054501545025450354504545055450654507545085450954510545115451254513545145451554516545175451854519545205452154522545235452454525545265452754528545295453054531545325453354534545355453654537545385453954540545415454254543545445454554546545475454854549545505455154552545535455454555545565455754558545595456054561545625456354564545655456654567545685456954570545715457254573545745457554576545775457854579545805458154582545835458454585545865458754588545895459054591545925459354594545955459654597545985459954600546015460254603546045460554606546075460854609546105461154612546135461454615546165461754618546195462054621546225462354624546255462654627546285462954630546315463254633546345463554636546375463854639546405464154642546435464454645546465464754648546495465054651546525465354654546555465654657546585465954660546615466254663546645466554666546675466854669546705467154672546735467454675546765467754678546795468054681546825468354684546855468654687546885468954690546915469254693546945469554696546975469854699547005470154702547035470454705547065470754708547095471054711547125471354714547155471654717547185471954720547215472254723547245472554726547275472854729547305473154732547335473454735547365473754738547395474054741547425474354744547455474654747547485474954750547515475254753547545475554756547575475854759547605476154762547635476454765547665476754768547695477054771547725477354774547755477654777547785477954780547815478254783547845478554786547875478854789547905479154792547935479454795547965479754798547995480054801548025480354804548055480654807548085480954810548115481254813548145481554816548175481854819548205482154822548235482454825548265482754828548295483054831548325483354834548355483654837548385483954840548415484254843548445484554846548475484854849548505485154852548535485454855548565485754858548595486054861548625486354864548655486654867548685486954870548715487254873548745487554876548775487854879548805488154882548835488454885548865488754888548895489054891548925489354894548955489654897548985489954900549015490254903549045490554906549075490854909549105491154912549135491454915549165491754918549195492054921549225492354924549255492654927549285492954930549315493254933549345493554936549375493854939549405494154942549435494454945549465494754948549495495054951549525495354954549555495654957549585495954960549615496254963549645496554966549675496854969549705497154972549735497454975549765497754978549795498054981549825498354984549855498654987549885498954990549915499254993549945499554996549975499854999550005500155002550035500455005550065500755008550095501055011550125501355014550155501655017550185501955020550215502255023550245502555026550275502855029550305503155032550335503455035550365503755038550395504055041550425504355044550455504655047550485504955050550515505255053550545505555056550575505855059550605506155062550635506455065550665506755068550695507055071550725507355074550755507655077550785507955080550815508255083550845508555086550875508855089550905509155092550935509455095550965509755098550995510055101551025510355104551055510655107551085510955110551115511255113551145511555116551175511855119551205512155122551235512455125551265512755128551295513055131551325513355134551355513655137551385513955140551415514255143551445514555146551475514855149551505515155152551535515455155551565515755158551595516055161551625516355164551655516655167551685516955170551715517255173551745517555176551775517855179551805518155182551835518455185551865518755188551895519055191551925519355194551955519655197551985519955200552015520255203552045520555206552075520855209552105521155212552135521455215552165521755218552195522055221552225522355224552255522655227552285522955230552315523255233552345523555236552375523855239552405524155242552435524455245552465524755248552495525055251552525525355254552555525655257552585525955260552615526255263552645526555266552675526855269552705527155272552735527455275552765527755278552795528055281552825528355284552855528655287552885528955290552915529255293552945529555296552975529855299553005530155302553035530455305553065530755308553095531055311553125531355314553155531655317553185531955320553215532255323553245532555326553275532855329553305533155332553335533455335553365533755338553395534055341553425534355344553455534655347553485534955350553515535255353553545535555356553575535855359553605536155362553635536455365553665536755368553695537055371553725537355374553755537655377553785537955380553815538255383553845538555386553875538855389553905539155392553935539455395553965539755398553995540055401554025540355404554055540655407554085540955410554115541255413554145541555416554175541855419554205542155422554235542455425554265542755428554295543055431554325543355434554355543655437554385543955440554415544255443554445544555446554475544855449554505545155452554535545455455554565545755458554595546055461554625546355464554655546655467554685546955470554715547255473554745547555476554775547855479554805548155482554835548455485554865548755488554895549055491554925549355494554955549655497554985549955500555015550255503555045550555506555075550855509555105551155512555135551455515555165551755518555195552055521555225552355524555255552655527555285552955530555315553255533555345553555536555375553855539555405554155542555435554455545555465554755548555495555055551555525555355554555555555655557555585555955560555615556255563555645556555566555675556855569555705557155572555735557455575555765557755578555795558055581555825558355584555855558655587555885558955590555915559255593555945559555596555975559855599556005560155602556035560455605556065560755608556095561055611556125561355614556155561655617556185561955620556215562255623556245562555626556275562855629556305563155632556335563455635556365563755638556395564055641556425564355644556455564655647556485564955650556515565255653556545565555656556575565855659556605566155662556635566455665556665566755668556695567055671556725567355674556755567655677556785567955680556815568255683556845568555686556875568855689556905569155692556935569455695556965569755698556995570055701557025570355704557055570655707557085570955710557115571255713557145571555716557175571855719557205572155722557235572455725557265572755728557295573055731557325573355734557355573655737557385573955740557415574255743557445574555746557475574855749557505575155752557535575455755557565575755758557595576055761557625576355764557655576655767557685576955770557715577255773557745577555776557775577855779557805578155782557835578455785557865578755788557895579055791557925579355794557955579655797557985579955800558015580255803558045580555806558075580855809558105581155812558135581455815558165581755818558195582055821558225582355824558255582655827558285582955830558315583255833558345583555836558375583855839558405584155842558435584455845558465584755848558495585055851558525585355854558555585655857558585585955860558615586255863558645586555866558675586855869558705587155872558735587455875558765587755878558795588055881558825588355884558855588655887558885588955890558915589255893558945589555896558975589855899559005590155902559035590455905559065590755908559095591055911559125591355914559155591655917559185591955920559215592255923559245592555926559275592855929559305593155932559335593455935559365593755938559395594055941559425594355944559455594655947559485594955950559515595255953559545595555956559575595855959559605596155962559635596455965559665596755968559695597055971559725597355974559755597655977559785597955980559815598255983559845598555986559875598855989559905599155992559935599455995559965599755998559995600056001560025600356004560055600656007560085600956010560115601256013560145601556016560175601856019560205602156022560235602456025560265602756028560295603056031560325603356034560355603656037560385603956040560415604256043560445604556046560475604856049560505605156052560535605456055560565605756058560595606056061560625606356064560655606656067560685606956070560715607256073560745607556076560775607856079560805608156082560835608456085560865608756088560895609056091560925609356094560955609656097560985609956100561015610256103561045610556106561075610856109561105611156112561135611456115561165611756118561195612056121561225612356124561255612656127561285612956130561315613256133561345613556136561375613856139561405614156142561435614456145561465614756148561495615056151561525615356154561555615656157561585615956160561615616256163561645616556166561675616856169561705617156172561735617456175561765617756178561795618056181561825618356184561855618656187561885618956190561915619256193561945619556196561975619856199562005620156202562035620456205562065620756208562095621056211562125621356214562155621656217562185621956220562215622256223562245622556226562275622856229562305623156232562335623456235562365623756238562395624056241562425624356244562455624656247562485624956250562515625256253562545625556256562575625856259562605626156262562635626456265562665626756268562695627056271562725627356274562755627656277562785627956280562815628256283562845628556286562875628856289562905629156292562935629456295562965629756298562995630056301563025630356304563055630656307563085630956310563115631256313563145631556316563175631856319563205632156322563235632456325563265632756328563295633056331563325633356334563355633656337563385633956340563415634256343563445634556346563475634856349563505635156352563535635456355563565635756358563595636056361563625636356364563655636656367563685636956370563715637256373563745637556376563775637856379563805638156382563835638456385563865638756388563895639056391563925639356394563955639656397563985639956400564015640256403564045640556406564075640856409564105641156412564135641456415564165641756418564195642056421564225642356424564255642656427564285642956430564315643256433564345643556436564375643856439564405644156442564435644456445564465644756448564495645056451564525645356454564555645656457564585645956460564615646256463564645646556466564675646856469564705647156472564735647456475564765647756478564795648056481564825648356484564855648656487564885648956490564915649256493564945649556496564975649856499565005650156502565035650456505565065650756508565095651056511565125651356514565155651656517565185651956520565215652256523565245652556526565275652856529565305653156532565335653456535565365653756538565395654056541565425654356544565455654656547565485654956550565515655256553565545655556556565575655856559565605656156562565635656456565565665656756568565695657056571565725657356574565755657656577565785657956580565815658256583565845658556586565875658856589565905659156592565935659456595565965659756598565995660056601566025660356604566055660656607566085660956610566115661256613566145661556616566175661856619566205662156622566235662456625566265662756628566295663056631566325663356634566355663656637566385663956640566415664256643566445664556646566475664856649566505665156652566535665456655566565665756658566595666056661566625666356664566655666656667566685666956670566715667256673566745667556676566775667856679566805668156682566835668456685566865668756688566895669056691566925669356694566955669656697566985669956700567015670256703567045670556706567075670856709567105671156712567135671456715567165671756718567195672056721567225672356724567255672656727567285672956730567315673256733567345673556736567375673856739567405674156742567435674456745567465674756748567495675056751567525675356754567555675656757567585675956760567615676256763567645676556766567675676856769567705677156772567735677456775567765677756778567795678056781567825678356784567855678656787567885678956790567915679256793567945679556796567975679856799568005680156802568035680456805568065680756808568095681056811568125681356814568155681656817568185681956820568215682256823568245682556826568275682856829568305683156832568335683456835568365683756838568395684056841568425684356844568455684656847568485684956850568515685256853568545685556856568575685856859568605686156862568635686456865568665686756868568695687056871568725687356874568755687656877568785687956880568815688256883568845688556886568875688856889568905689156892568935689456895568965689756898568995690056901569025690356904569055690656907569085690956910569115691256913569145691556916569175691856919569205692156922569235692456925569265692756928569295693056931569325693356934569355693656937569385693956940569415694256943569445694556946569475694856949569505695156952569535695456955569565695756958569595696056961569625696356964569655696656967569685696956970569715697256973569745697556976569775697856979569805698156982569835698456985569865698756988569895699056991569925699356994569955699656997569985699957000570015700257003570045700557006570075700857009570105701157012570135701457015570165701757018570195702057021570225702357024570255702657027570285702957030570315703257033570345703557036570375703857039570405704157042570435704457045570465704757048570495705057051570525705357054570555705657057570585705957060570615706257063570645706557066570675706857069570705707157072570735707457075570765707757078570795708057081570825708357084570855708657087570885708957090570915709257093570945709557096570975709857099571005710157102571035710457105571065710757108571095711057111571125711357114571155711657117571185711957120571215712257123571245712557126571275712857129571305713157132571335713457135571365713757138571395714057141571425714357144571455714657147571485714957150571515715257153571545715557156571575715857159571605716157162571635716457165571665716757168571695717057171571725717357174571755717657177571785717957180571815718257183571845718557186571875718857189571905719157192571935719457195571965719757198571995720057201572025720357204572055720657207572085720957210572115721257213572145721557216572175721857219572205722157222572235722457225572265722757228572295723057231572325723357234572355723657237572385723957240572415724257243572445724557246572475724857249572505725157252572535725457255572565725757258572595726057261572625726357264572655726657267572685726957270572715727257273572745727557276572775727857279572805728157282572835728457285572865728757288572895729057291572925729357294572955729657297572985729957300573015730257303573045730557306573075730857309573105731157312573135731457315573165731757318573195732057321573225732357324573255732657327573285732957330573315733257333573345733557336573375733857339573405734157342573435734457345573465734757348573495735057351573525735357354573555735657357573585735957360573615736257363573645736557366573675736857369573705737157372573735737457375573765737757378573795738057381573825738357384573855738657387573885738957390573915739257393573945739557396573975739857399574005740157402574035740457405574065740757408574095741057411574125741357414574155741657417574185741957420574215742257423574245742557426574275742857429574305743157432574335743457435574365743757438574395744057441574425744357444574455744657447574485744957450574515745257453574545745557456574575745857459574605746157462574635746457465574665746757468574695747057471574725747357474574755747657477574785747957480574815748257483574845748557486574875748857489574905749157492574935749457495574965749757498574995750057501575025750357504575055750657507575085750957510575115751257513575145751557516575175751857519575205752157522575235752457525575265752757528575295753057531575325753357534575355753657537575385753957540575415754257543575445754557546575475754857549575505755157552575535755457555575565755757558575595756057561575625756357564575655756657567575685756957570575715757257573575745757557576575775757857579575805758157582575835758457585575865758757588575895759057591575925759357594575955759657597575985759957600576015760257603576045760557606576075760857609576105761157612576135761457615576165761757618576195762057621576225762357624576255762657627576285762957630576315763257633576345763557636576375763857639576405764157642576435764457645576465764757648576495765057651576525765357654576555765657657576585765957660576615766257663576645766557666576675766857669576705767157672576735767457675576765767757678576795768057681576825768357684576855768657687576885768957690576915769257693576945769557696576975769857699577005770157702577035770457705577065770757708577095771057711577125771357714577155771657717577185771957720577215772257723577245772557726577275772857729577305773157732577335773457735577365773757738577395774057741577425774357744577455774657747577485774957750577515775257753577545775557756577575775857759577605776157762577635776457765577665776757768577695777057771577725777357774577755777657777577785777957780577815778257783577845778557786577875778857789577905779157792577935779457795577965779757798577995780057801578025780357804578055780657807578085780957810578115781257813578145781557816578175781857819578205782157822578235782457825578265782757828578295783057831578325783357834578355783657837578385783957840578415784257843578445784557846578475784857849578505785157852578535785457855578565785757858578595786057861578625786357864578655786657867578685786957870578715787257873578745787557876578775787857879578805788157882578835788457885578865788757888578895789057891578925789357894578955789657897578985789957900579015790257903579045790557906579075790857909579105791157912579135791457915579165791757918579195792057921579225792357924579255792657927579285792957930579315793257933579345793557936579375793857939579405794157942579435794457945579465794757948579495795057951579525795357954579555795657957579585795957960579615796257963579645796557966579675796857969579705797157972579735797457975579765797757978579795798057981579825798357984579855798657987579885798957990579915799257993579945799557996579975799857999580005800158002580035800458005580065800758008580095801058011580125801358014580155801658017580185801958020580215802258023580245802558026580275802858029580305803158032580335803458035580365803758038580395804058041580425804358044580455804658047580485804958050580515805258053580545805558056580575805858059580605806158062580635806458065580665806758068580695807058071580725807358074580755807658077580785807958080580815808258083580845808558086580875808858089580905809158092580935809458095580965809758098580995810058101581025810358104581055810658107581085810958110581115811258113581145811558116581175811858119581205812158122581235812458125581265812758128581295813058131581325813358134581355813658137581385813958140581415814258143581445814558146581475814858149581505815158152581535815458155581565815758158581595816058161581625816358164581655816658167581685816958170581715817258173581745817558176581775817858179581805818158182581835818458185581865818758188581895819058191581925819358194581955819658197581985819958200582015820258203582045820558206582075820858209582105821158212582135821458215582165821758218582195822058221582225822358224582255822658227582285822958230582315823258233582345823558236582375823858239582405824158242582435824458245582465824758248582495825058251582525825358254582555825658257582585825958260582615826258263582645826558266582675826858269582705827158272582735827458275582765827758278582795828058281582825828358284582855828658287582885828958290582915829258293582945829558296582975829858299583005830158302583035830458305583065830758308583095831058311583125831358314583155831658317583185831958320583215832258323583245832558326583275832858329583305833158332583335833458335583365833758338583395834058341583425834358344583455834658347583485834958350583515835258353583545835558356583575835858359583605836158362583635836458365583665836758368583695837058371583725837358374583755837658377583785837958380583815838258383583845838558386583875838858389583905839158392583935839458395583965839758398583995840058401584025840358404584055840658407584085840958410584115841258413584145841558416584175841858419584205842158422584235842458425584265842758428584295843058431584325843358434584355843658437584385843958440584415844258443584445844558446584475844858449584505845158452584535845458455584565845758458584595846058461584625846358464584655846658467584685846958470584715847258473584745847558476584775847858479584805848158482584835848458485584865848758488584895849058491584925849358494584955849658497584985849958500585015850258503585045850558506585075850858509585105851158512585135851458515585165851758518585195852058521585225852358524585255852658527585285852958530585315853258533585345853558536585375853858539585405854158542585435854458545585465854758548585495855058551585525855358554585555855658557585585855958560585615856258563585645856558566585675856858569585705857158572585735857458575585765857758578585795858058581585825858358584585855858658587585885858958590585915859258593585945859558596585975859858599586005860158602586035860458605586065860758608586095861058611586125861358614586155861658617586185861958620586215862258623586245862558626586275862858629586305863158632586335863458635586365863758638586395864058641586425864358644586455864658647586485864958650586515865258653586545865558656586575865858659586605866158662586635866458665586665866758668586695867058671586725867358674586755867658677586785867958680586815868258683586845868558686586875868858689586905869158692586935869458695586965869758698586995870058701587025870358704587055870658707587085870958710587115871258713587145871558716587175871858719587205872158722587235872458725587265872758728587295873058731587325873358734587355873658737587385873958740587415874258743587445874558746587475874858749587505875158752587535875458755587565875758758587595876058761587625876358764587655876658767587685876958770587715877258773587745877558776587775877858779587805878158782587835878458785587865878758788587895879058791587925879358794587955879658797587985879958800588015880258803588045880558806588075880858809588105881158812588135881458815588165881758818588195882058821588225882358824588255882658827588285882958830588315883258833588345883558836588375883858839588405884158842588435884458845588465884758848588495885058851588525885358854588555885658857588585885958860588615886258863588645886558866588675886858869588705887158872588735887458875588765887758878588795888058881588825888358884588855888658887588885888958890588915889258893588945889558896588975889858899589005890158902589035890458905589065890758908589095891058911589125891358914589155891658917589185891958920589215892258923589245892558926589275892858929589305893158932589335893458935589365893758938589395894058941589425894358944589455894658947589485894958950589515895258953589545895558956589575895858959589605896158962589635896458965589665896758968589695897058971589725897358974589755897658977589785897958980589815898258983589845898558986589875898858989589905899158992589935899458995589965899758998589995900059001590025900359004590055900659007590085900959010590115901259013590145901559016590175901859019590205902159022590235902459025590265902759028590295903059031590325903359034590355903659037590385903959040590415904259043590445904559046590475904859049590505905159052590535905459055590565905759058590595906059061590625906359064590655906659067590685906959070590715907259073590745907559076590775907859079590805908159082590835908459085590865908759088590895909059091590925909359094590955909659097590985909959100591015910259103591045910559106591075910859109591105911159112591135911459115591165911759118591195912059121591225912359124591255912659127591285912959130591315913259133591345913559136591375913859139591405914159142591435914459145591465914759148591495915059151591525915359154591555915659157591585915959160591615916259163591645916559166591675916859169591705917159172591735917459175591765917759178591795918059181591825918359184591855918659187591885918959190591915919259193591945919559196591975919859199592005920159202592035920459205592065920759208592095921059211592125921359214592155921659217592185921959220592215922259223592245922559226592275922859229592305923159232592335923459235592365923759238592395924059241592425924359244592455924659247592485924959250592515925259253592545925559256592575925859259592605926159262592635926459265592665926759268592695927059271592725927359274592755927659277592785927959280592815928259283592845928559286592875928859289592905929159292592935929459295592965929759298592995930059301593025930359304593055930659307593085930959310593115931259313593145931559316593175931859319593205932159322593235932459325593265932759328593295933059331593325933359334593355933659337593385933959340593415934259343593445934559346593475934859349593505935159352593535935459355593565935759358593595936059361593625936359364593655936659367593685936959370593715937259373593745937559376593775937859379593805938159382593835938459385593865938759388593895939059391593925939359394593955939659397593985939959400594015940259403594045940559406594075940859409594105941159412594135941459415594165941759418594195942059421594225942359424594255942659427594285942959430594315943259433594345943559436594375943859439594405944159442594435944459445594465944759448594495945059451594525945359454594555945659457594585945959460594615946259463594645946559466594675946859469594705947159472594735947459475594765947759478594795948059481594825948359484594855948659487594885948959490594915949259493594945949559496594975949859499595005950159502595035950459505595065950759508595095951059511595125951359514595155951659517595185951959520595215952259523595245952559526595275952859529595305953159532595335953459535595365953759538595395954059541595425954359544595455954659547595485954959550595515955259553595545955559556595575955859559595605956159562595635956459565595665956759568595695957059571595725957359574595755957659577595785957959580595815958259583595845958559586595875958859589595905959159592595935959459595595965959759598595995960059601596025960359604596055960659607596085960959610596115961259613596145961559616596175961859619596205962159622596235962459625596265962759628596295963059631596325963359634596355963659637596385963959640596415964259643596445964559646596475964859649596505965159652596535965459655596565965759658596595966059661596625966359664596655966659667596685966959670596715967259673596745967559676596775967859679596805968159682596835968459685596865968759688596895969059691596925969359694596955969659697596985969959700597015970259703597045970559706597075970859709597105971159712597135971459715597165971759718597195972059721597225972359724597255972659727597285972959730597315973259733597345973559736597375973859739597405974159742597435974459745597465974759748597495975059751597525975359754597555975659757597585975959760597615976259763597645976559766597675976859769597705977159772597735977459775597765977759778597795978059781597825978359784597855978659787597885978959790597915979259793597945979559796597975979859799598005980159802598035980459805598065980759808598095981059811598125981359814598155981659817598185981959820598215982259823598245982559826598275982859829598305983159832598335983459835598365983759838598395984059841598425984359844598455984659847598485984959850598515985259853598545985559856598575985859859598605986159862598635986459865598665986759868598695987059871598725987359874598755987659877598785987959880598815988259883598845988559886598875988859889598905989159892598935989459895598965989759898598995990059901599025990359904599055990659907599085990959910599115991259913599145991559916599175991859919599205992159922599235992459925599265992759928599295993059931599325993359934599355993659937599385993959940599415994259943599445994559946599475994859949599505995159952599535995459955599565995759958599595996059961599625996359964599655996659967599685996959970599715997259973599745997559976599775997859979599805998159982599835998459985599865998759988599895999059991599925999359994599955999659997599985999960000600016000260003600046000560006600076000860009600106001160012600136001460015600166001760018600196002060021600226002360024600256002660027600286002960030600316003260033600346003560036600376003860039600406004160042600436004460045600466004760048600496005060051600526005360054600556005660057600586005960060600616006260063600646006560066600676006860069600706007160072600736007460075600766007760078600796008060081600826008360084600856008660087600886008960090600916009260093600946009560096600976009860099601006010160102601036010460105601066010760108601096011060111601126011360114601156011660117601186011960120601216012260123601246012560126601276012860129601306013160132601336013460135601366013760138601396014060141601426014360144601456014660147601486014960150601516015260153601546015560156601576015860159601606016160162601636016460165601666016760168601696017060171601726017360174601756017660177601786017960180601816018260183601846018560186601876018860189601906019160192601936019460195601966019760198601996020060201602026020360204602056020660207602086020960210602116021260213602146021560216602176021860219602206022160222602236022460225602266022760228602296023060231602326023360234602356023660237602386023960240602416024260243602446024560246602476024860249602506025160252602536025460255602566025760258602596026060261602626026360264602656026660267602686026960270602716027260273602746027560276602776027860279602806028160282602836028460285602866028760288602896029060291602926029360294602956029660297602986029960300603016030260303603046030560306603076030860309603106031160312603136031460315603166031760318603196032060321603226032360324603256032660327603286032960330603316033260333603346033560336603376033860339603406034160342603436034460345603466034760348603496035060351603526035360354603556035660357603586035960360603616036260363603646036560366603676036860369603706037160372603736037460375603766037760378603796038060381603826038360384603856038660387603886038960390603916039260393603946039560396603976039860399604006040160402604036040460405604066040760408604096041060411604126041360414604156041660417604186041960420604216042260423604246042560426604276042860429604306043160432604336043460435604366043760438604396044060441604426044360444604456044660447604486044960450604516045260453604546045560456604576045860459604606046160462604636046460465604666046760468604696047060471604726047360474604756047660477604786047960480604816048260483604846048560486604876048860489604906049160492604936049460495604966049760498604996050060501605026050360504605056050660507605086050960510605116051260513605146051560516605176051860519605206052160522605236052460525605266052760528605296053060531605326053360534605356053660537605386053960540605416054260543605446054560546605476054860549605506055160552605536055460555605566055760558605596056060561605626056360564605656056660567605686056960570605716057260573605746057560576605776057860579605806058160582605836058460585605866058760588605896059060591605926059360594605956059660597605986059960600606016060260603606046060560606606076060860609606106061160612606136061460615606166061760618606196062060621606226062360624606256062660627606286062960630606316063260633606346063560636606376063860639606406064160642606436064460645606466064760648606496065060651606526065360654606556065660657606586065960660606616066260663606646066560666606676066860669606706067160672606736067460675606766067760678606796068060681606826068360684606856068660687606886068960690606916069260693606946069560696606976069860699607006070160702607036070460705607066070760708607096071060711607126071360714607156071660717607186071960720607216072260723607246072560726607276072860729607306073160732607336073460735607366073760738607396074060741607426074360744607456074660747607486074960750607516075260753607546075560756607576075860759607606076160762607636076460765607666076760768607696077060771607726077360774607756077660777607786077960780607816078260783607846078560786607876078860789607906079160792607936079460795607966079760798607996080060801608026080360804608056080660807608086080960810608116081260813608146081560816608176081860819608206082160822608236082460825608266082760828608296083060831608326083360834608356083660837608386083960840608416084260843608446084560846608476084860849608506085160852608536085460855608566085760858608596086060861608626086360864608656086660867608686086960870608716087260873608746087560876608776087860879608806088160882608836088460885608866088760888608896089060891608926089360894608956089660897608986089960900609016090260903609046090560906609076090860909609106091160912609136091460915609166091760918609196092060921609226092360924609256092660927609286092960930609316093260933609346093560936609376093860939609406094160942609436094460945609466094760948609496095060951609526095360954609556095660957609586095960960609616096260963609646096560966609676096860969609706097160972609736097460975609766097760978609796098060981609826098360984609856098660987609886098960990609916099260993609946099560996609976099860999610006100161002610036100461005610066100761008610096101061011610126101361014610156101661017610186101961020610216102261023610246102561026610276102861029610306103161032610336103461035610366103761038610396104061041610426104361044610456104661047610486104961050610516105261053610546105561056610576105861059610606106161062610636106461065610666106761068610696107061071610726107361074610756107661077610786107961080610816108261083610846108561086610876108861089610906109161092610936109461095610966109761098610996110061101611026110361104611056110661107611086110961110611116111261113611146111561116611176111861119611206112161122611236112461125611266112761128611296113061131611326113361134611356113661137611386113961140611416114261143611446114561146611476114861149611506115161152611536115461155611566115761158611596116061161611626116361164611656116661167611686116961170611716117261173611746117561176611776117861179611806118161182611836118461185611866118761188611896119061191611926119361194611956119661197611986119961200612016120261203612046120561206612076120861209612106121161212612136121461215612166121761218612196122061221612226122361224612256122661227612286122961230612316123261233612346123561236612376123861239612406124161242612436124461245612466124761248612496125061251612526125361254612556125661257612586125961260612616126261263612646126561266612676126861269612706127161272612736127461275612766127761278612796128061281612826128361284612856128661287612886128961290612916129261293612946129561296612976129861299613006130161302613036130461305613066130761308613096131061311613126131361314613156131661317613186131961320613216132261323613246132561326613276132861329613306133161332613336133461335613366133761338613396134061341613426134361344613456134661347613486134961350613516135261353613546135561356613576135861359613606136161362613636136461365613666136761368613696137061371613726137361374613756137661377613786137961380613816138261383613846138561386613876138861389613906139161392613936139461395613966139761398613996140061401614026140361404614056140661407614086140961410614116141261413614146141561416614176141861419614206142161422614236142461425614266142761428614296143061431614326143361434614356143661437614386143961440614416144261443614446144561446614476144861449614506145161452614536145461455614566145761458614596146061461614626146361464614656146661467614686146961470614716147261473614746147561476614776147861479614806148161482614836148461485614866148761488614896149061491614926149361494614956149661497614986149961500615016150261503615046150561506615076150861509615106151161512615136151461515615166151761518615196152061521615226152361524615256152661527615286152961530615316153261533615346153561536615376153861539615406154161542615436154461545615466154761548615496155061551615526155361554615556155661557615586155961560615616156261563615646156561566615676156861569615706157161572615736157461575615766157761578615796158061581615826158361584615856158661587615886158961590615916159261593615946159561596615976159861599616006160161602616036160461605616066160761608616096161061611616126161361614616156161661617616186161961620616216162261623616246162561626616276162861629616306163161632616336163461635616366163761638616396164061641616426164361644616456164661647616486164961650616516165261653616546165561656616576165861659616606166161662616636166461665616666166761668616696167061671616726167361674616756167661677616786167961680616816168261683616846168561686616876168861689616906169161692616936169461695616966169761698616996170061701617026170361704617056170661707617086170961710617116171261713617146171561716617176171861719617206172161722617236172461725617266172761728617296173061731617326173361734617356173661737617386173961740617416174261743617446174561746617476174861749617506175161752617536175461755617566175761758617596176061761617626176361764617656176661767617686176961770617716177261773617746177561776617776177861779617806178161782617836178461785617866178761788617896179061791617926179361794617956179661797617986179961800618016180261803618046180561806618076180861809618106181161812618136181461815618166181761818618196182061821618226182361824618256182661827618286182961830618316183261833618346183561836618376183861839618406184161842618436184461845618466184761848618496185061851618526185361854618556185661857618586185961860618616186261863618646186561866618676186861869618706187161872618736187461875618766187761878618796188061881618826188361884618856188661887618886188961890618916189261893618946189561896618976189861899619006190161902619036190461905619066190761908619096191061911619126191361914619156191661917619186191961920619216192261923619246192561926619276192861929619306193161932619336193461935619366193761938619396194061941619426194361944619456194661947619486194961950619516195261953619546195561956619576195861959619606196161962619636196461965619666196761968619696197061971619726197361974619756197661977619786197961980619816198261983619846198561986619876198861989619906199161992619936199461995619966199761998619996200062001620026200362004620056200662007620086200962010620116201262013620146201562016620176201862019620206202162022620236202462025620266202762028620296203062031620326203362034620356203662037620386203962040620416204262043620446204562046620476204862049620506205162052620536205462055620566205762058620596206062061620626206362064620656206662067620686206962070620716207262073620746207562076620776207862079620806208162082620836208462085620866208762088620896209062091620926209362094620956209662097620986209962100621016210262103621046210562106621076210862109621106211162112621136211462115621166211762118621196212062121621226212362124621256212662127621286212962130621316213262133621346213562136621376213862139621406214162142621436214462145621466214762148621496215062151621526215362154621556215662157621586215962160621616216262163621646216562166621676216862169621706217162172621736217462175621766217762178621796218062181621826218362184621856218662187621886218962190621916219262193621946219562196621976219862199622006220162202622036220462205622066220762208622096221062211622126221362214622156221662217622186221962220622216222262223622246222562226622276222862229622306223162232622336223462235622366223762238622396224062241622426224362244622456224662247622486224962250622516225262253622546225562256622576225862259622606226162262622636226462265622666226762268622696227062271622726227362274622756227662277622786227962280622816228262283622846228562286622876228862289622906229162292622936229462295622966229762298622996230062301623026230362304623056230662307623086230962310623116231262313623146231562316623176231862319623206232162322623236232462325623266232762328623296233062331623326233362334623356233662337623386233962340623416234262343623446234562346623476234862349623506235162352623536235462355623566235762358623596236062361623626236362364623656236662367623686236962370623716237262373623746237562376623776237862379623806238162382623836238462385623866238762388623896239062391623926239362394623956239662397623986239962400624016240262403624046240562406624076240862409624106241162412624136241462415624166241762418624196242062421624226242362424624256242662427624286242962430624316243262433624346243562436624376243862439624406244162442624436244462445624466244762448624496245062451624526245362454624556245662457624586245962460624616246262463624646246562466624676246862469624706247162472624736247462475624766247762478624796248062481624826248362484624856248662487624886248962490624916249262493624946249562496624976249862499625006250162502625036250462505625066250762508625096251062511625126251362514625156251662517625186251962520625216252262523625246252562526625276252862529625306253162532625336253462535625366253762538625396254062541625426254362544625456254662547625486254962550625516255262553625546255562556625576255862559625606256162562625636256462565625666256762568625696257062571625726257362574625756257662577625786257962580625816258262583625846258562586625876258862589625906259162592625936259462595625966259762598625996260062601626026260362604626056260662607626086260962610626116261262613626146261562616626176261862619626206262162622626236262462625626266262762628626296263062631626326263362634626356263662637626386263962640626416264262643626446264562646626476264862649626506265162652626536265462655626566265762658626596266062661626626266362664626656266662667626686266962670626716267262673626746267562676626776267862679626806268162682626836268462685626866268762688626896269062691626926269362694626956269662697626986269962700627016270262703627046270562706627076270862709627106271162712627136271462715627166271762718627196272062721627226272362724627256272662727627286272962730627316273262733627346273562736627376273862739627406274162742627436274462745627466274762748627496275062751627526275362754627556275662757627586275962760627616276262763627646276562766627676276862769627706277162772627736277462775627766277762778627796278062781627826278362784627856278662787627886278962790627916279262793627946279562796627976279862799628006280162802628036280462805628066280762808628096281062811628126281362814628156281662817628186281962820628216282262823628246282562826628276282862829628306283162832628336283462835628366283762838628396284062841628426284362844628456284662847628486284962850628516285262853628546285562856628576285862859628606286162862628636286462865628666286762868628696287062871628726287362874628756287662877628786287962880628816288262883628846288562886628876288862889628906289162892628936289462895628966289762898628996290062901629026290362904629056290662907629086290962910629116291262913629146291562916629176291862919629206292162922629236292462925629266292762928629296293062931629326293362934629356293662937629386293962940629416294262943629446294562946629476294862949629506295162952629536295462955629566295762958629596296062961629626296362964629656296662967629686296962970629716297262973629746297562976629776297862979629806298162982629836298462985629866298762988629896299062991629926299362994629956299662997629986299963000630016300263003630046300563006630076300863009630106301163012630136301463015630166301763018630196302063021630226302363024630256302663027630286302963030630316303263033630346303563036630376303863039630406304163042630436304463045630466304763048630496305063051630526305363054630556305663057630586305963060630616306263063630646306563066630676306863069630706307163072630736307463075630766307763078630796308063081630826308363084630856308663087630886308963090630916309263093630946309563096630976309863099631006310163102631036310463105631066310763108631096311063111631126311363114631156311663117631186311963120631216312263123631246312563126631276312863129631306313163132631336313463135631366313763138631396314063141631426314363144631456314663147631486314963150631516315263153631546315563156631576315863159631606316163162631636316463165631666316763168631696317063171631726317363174631756317663177631786317963180631816318263183631846318563186631876318863189631906319163192631936319463195631966319763198631996320063201632026320363204632056320663207632086320963210632116321263213632146321563216632176321863219632206322163222632236322463225632266322763228632296323063231632326323363234632356323663237632386323963240632416324263243632446324563246632476324863249632506325163252632536325463255632566325763258632596326063261632626326363264632656326663267632686326963270632716327263273632746327563276632776327863279632806328163282632836328463285632866328763288632896329063291632926329363294632956329663297632986329963300633016330263303633046330563306633076330863309633106331163312633136331463315633166331763318633196332063321633226332363324633256332663327633286332963330633316333263333633346333563336633376333863339633406334163342633436334463345633466334763348633496335063351633526335363354633556335663357633586335963360633616336263363633646336563366633676336863369633706337163372633736337463375633766337763378633796338063381633826338363384633856338663387633886338963390633916339263393633946339563396633976339863399634006340163402634036340463405634066340763408634096341063411634126341363414634156341663417634186341963420634216342263423634246342563426634276342863429634306343163432634336343463435634366343763438634396344063441634426344363444634456344663447634486344963450634516345263453634546345563456634576345863459634606346163462634636346463465634666346763468634696347063471634726347363474634756347663477634786347963480634816348263483634846348563486634876348863489634906349163492634936349463495634966349763498634996350063501635026350363504635056350663507635086350963510635116351263513635146351563516635176351863519635206352163522635236352463525635266352763528635296353063531635326353363534635356353663537635386353963540635416354263543635446354563546635476354863549635506355163552635536355463555635566355763558635596356063561635626356363564635656356663567635686356963570635716357263573635746357563576635776357863579635806358163582635836358463585635866358763588635896359063591635926359363594635956359663597635986359963600636016360263603636046360563606636076360863609636106361163612636136361463615636166361763618636196362063621636226362363624636256362663627636286362963630636316363263633636346363563636636376363863639636406364163642636436364463645636466364763648636496365063651636526365363654636556365663657636586365963660636616366263663636646366563666636676366863669636706367163672636736367463675636766367763678636796368063681636826368363684636856368663687636886368963690636916369263693636946369563696636976369863699637006370163702637036370463705637066370763708637096371063711637126371363714637156371663717637186371963720637216372263723637246372563726637276372863729637306373163732637336373463735637366373763738637396374063741637426374363744637456374663747637486374963750637516375263753637546375563756637576375863759637606376163762637636376463765637666376763768637696377063771637726377363774637756377663777637786377963780637816378263783637846378563786637876378863789637906379163792637936379463795637966379763798637996380063801638026380363804638056380663807638086380963810638116381263813638146381563816638176381863819638206382163822638236382463825638266382763828638296383063831638326383363834638356383663837638386383963840638416384263843638446384563846638476384863849638506385163852638536385463855638566385763858638596386063861638626386363864638656386663867638686386963870638716387263873638746387563876638776387863879638806388163882638836388463885638866388763888638896389063891638926389363894638956389663897638986389963900639016390263903639046390563906639076390863909639106391163912639136391463915639166391763918639196392063921639226392363924639256392663927639286392963930639316393263933639346393563936639376393863939639406394163942639436394463945639466394763948639496395063951639526395363954639556395663957639586395963960639616396263963639646396563966639676396863969639706397163972639736397463975639766397763978639796398063981639826398363984639856398663987639886398963990639916399263993639946399563996639976399863999640006400164002640036400464005640066400764008640096401064011640126401364014640156401664017640186401964020640216402264023640246402564026640276402864029640306403164032640336403464035640366403764038640396404064041640426404364044640456404664047640486404964050640516405264053640546405564056640576405864059640606406164062640636406464065640666406764068640696407064071640726407364074640756407664077640786407964080640816408264083640846408564086640876408864089640906409164092640936409464095640966409764098640996410064101641026410364104641056410664107641086410964110641116411264113641146411564116641176411864119641206412164122641236412464125641266412764128641296413064131641326413364134641356413664137641386413964140641416414264143641446414564146641476414864149641506415164152641536415464155641566415764158641596416064161641626416364164641656416664167641686416964170641716417264173641746417564176641776417864179641806418164182641836418464185641866418764188641896419064191641926419364194641956419664197641986419964200642016420264203642046420564206642076420864209642106421164212642136421464215642166421764218642196422064221642226422364224642256422664227642286422964230642316423264233642346423564236642376423864239642406424164242642436424464245642466424764248642496425064251642526425364254642556425664257642586425964260642616426264263642646426564266642676426864269642706427164272642736427464275642766427764278642796428064281642826428364284642856428664287642886428964290642916429264293642946429564296642976429864299643006430164302643036430464305643066430764308643096431064311643126431364314643156431664317643186431964320643216432264323643246432564326643276432864329643306433164332643336433464335643366433764338643396434064341643426434364344643456434664347643486434964350643516435264353643546435564356643576435864359643606436164362643636436464365643666436764368643696437064371643726437364374643756437664377643786437964380643816438264383643846438564386643876438864389643906439164392643936439464395643966439764398643996440064401644026440364404644056440664407644086440964410644116441264413644146441564416644176441864419644206442164422644236442464425644266442764428644296443064431644326443364434644356443664437644386443964440644416444264443644446444564446644476444864449644506445164452644536445464455644566445764458644596446064461644626446364464644656446664467644686446964470644716447264473644746447564476644776447864479644806448164482644836448464485644866448764488644896449064491644926449364494644956449664497644986449964500645016450264503645046450564506645076450864509645106451164512645136451464515645166451764518645196452064521645226452364524645256452664527645286452964530645316453264533645346453564536645376453864539645406454164542645436454464545645466454764548645496455064551645526455364554645556455664557645586455964560645616456264563645646456564566645676456864569645706457164572645736457464575645766457764578645796458064581645826458364584645856458664587645886458964590645916459264593645946459564596645976459864599646006460164602646036460464605646066460764608646096461064611646126461364614646156461664617646186461964620646216462264623646246462564626646276462864629646306463164632646336463464635646366463764638646396464064641646426464364644646456464664647646486464964650646516465264653646546465564656646576465864659646606466164662646636466464665646666466764668646696467064671646726467364674646756467664677646786467964680646816468264683646846468564686646876468864689646906469164692646936469464695646966469764698646996470064701647026470364704647056470664707647086470964710647116471264713647146471564716647176471864719647206472164722647236472464725647266472764728647296473064731647326473364734647356473664737647386473964740647416474264743647446474564746647476474864749647506475164752647536475464755647566475764758647596476064761647626476364764647656476664767647686476964770647716477264773647746477564776647776477864779647806478164782647836478464785647866478764788647896479064791647926479364794647956479664797647986479964800648016480264803648046480564806648076480864809648106481164812648136481464815648166481764818648196482064821648226482364824648256482664827648286482964830648316483264833648346483564836648376483864839648406484164842648436484464845648466484764848648496485064851648526485364854648556485664857648586485964860648616486264863648646486564866648676486864869648706487164872648736487464875648766487764878648796488064881648826488364884648856488664887648886488964890648916489264893648946489564896648976489864899649006490164902649036490464905649066490764908649096491064911649126491364914649156491664917649186491964920649216492264923649246492564926649276492864929649306493164932649336493464935649366493764938649396494064941649426494364944649456494664947649486494964950649516495264953649546495564956649576495864959649606496164962649636496464965649666496764968649696497064971649726497364974649756497664977649786497964980649816498264983649846498564986649876498864989649906499164992649936499464995649966499764998649996500065001650026500365004650056500665007650086500965010650116501265013650146501565016650176501865019650206502165022650236502465025650266502765028650296503065031650326503365034650356503665037650386503965040650416504265043650446504565046650476504865049650506505165052650536505465055650566505765058650596506065061650626506365064650656506665067650686506965070650716507265073650746507565076650776507865079650806508165082650836508465085650866508765088650896509065091650926509365094650956509665097650986509965100651016510265103651046510565106651076510865109651106511165112651136511465115651166511765118651196512065121651226512365124651256512665127651286512965130651316513265133651346513565136651376513865139651406514165142651436514465145651466514765148651496515065151651526515365154651556515665157651586515965160651616516265163651646516565166651676516865169651706517165172651736517465175651766517765178651796518065181651826518365184651856518665187651886518965190651916519265193651946519565196651976519865199652006520165202652036520465205652066520765208652096521065211652126521365214652156521665217652186521965220652216522265223652246522565226652276522865229652306523165232652336523465235652366523765238652396524065241652426524365244652456524665247652486524965250652516525265253652546525565256652576525865259652606526165262652636526465265652666526765268652696527065271652726527365274652756527665277652786527965280652816528265283652846528565286652876528865289652906529165292652936529465295652966529765298652996530065301653026530365304653056530665307653086530965310653116531265313653146531565316653176531865319653206532165322653236532465325653266532765328653296533065331653326533365334653356533665337653386533965340653416534265343653446534565346653476534865349653506535165352653536535465355653566535765358653596536065361653626536365364653656536665367653686536965370653716537265373653746537565376653776537865379653806538165382653836538465385653866538765388653896539065391653926539365394653956539665397653986539965400654016540265403654046540565406654076540865409654106541165412654136541465415654166541765418654196542065421654226542365424654256542665427654286542965430654316543265433654346543565436654376543865439654406544165442654436544465445654466544765448654496545065451654526545365454654556545665457654586545965460654616546265463654646546565466654676546865469654706547165472654736547465475654766547765478654796548065481654826548365484654856548665487654886548965490654916549265493654946549565496654976549865499655006550165502655036550465505655066550765508655096551065511655126551365514655156551665517655186551965520655216552265523655246552565526655276552865529655306553165532655336553465535655366553765538655396554065541655426554365544655456554665547655486554965550655516555265553655546555565556655576555865559655606556165562655636556465565655666556765568655696557065571655726557365574655756557665577655786557965580655816558265583655846558565586655876558865589655906559165592655936559465595655966559765598655996560065601656026560365604656056560665607656086560965610656116561265613656146561565616656176561865619656206562165622656236562465625656266562765628656296563065631656326563365634656356563665637656386563965640656416564265643656446564565646656476564865649656506565165652656536565465655656566565765658656596566065661656626566365664656656566665667656686566965670656716567265673656746567565676656776567865679656806568165682656836568465685656866568765688656896569065691656926569365694656956569665697656986569965700657016570265703657046570565706657076570865709657106571165712657136571465715657166571765718657196572065721657226572365724657256572665727657286572965730657316573265733657346573565736657376573865739657406574165742657436574465745657466574765748657496575065751657526575365754657556575665757657586575965760657616576265763657646576565766657676576865769657706577165772657736577465775657766577765778657796578065781657826578365784657856578665787657886578965790657916579265793657946579565796657976579865799658006580165802658036580465805658066580765808658096581065811658126581365814658156581665817658186581965820658216582265823658246582565826658276582865829658306583165832658336583465835658366583765838658396584065841658426584365844658456584665847658486584965850658516585265853658546585565856658576585865859658606586165862658636586465865658666586765868658696587065871658726587365874658756587665877658786587965880658816588265883658846588565886658876588865889658906589165892658936589465895658966589765898658996590065901659026590365904659056590665907659086590965910659116591265913659146591565916659176591865919659206592165922659236592465925659266592765928659296593065931659326593365934659356593665937659386593965940659416594265943659446594565946659476594865949659506595165952659536595465955659566595765958659596596065961659626596365964659656596665967659686596965970659716597265973659746597565976659776597865979659806598165982659836598465985659866598765988659896599065991659926599365994659956599665997659986599966000660016600266003660046600566006660076600866009660106601166012660136601466015660166601766018660196602066021660226602366024660256602666027660286602966030660316603266033660346603566036660376603866039660406604166042660436604466045660466604766048660496605066051660526605366054660556605666057660586605966060660616606266063660646606566066660676606866069660706607166072660736607466075660766607766078660796608066081660826608366084660856608666087660886608966090660916609266093660946609566096660976609866099661006610166102661036610466105661066610766108661096611066111661126611366114661156611666117661186611966120661216612266123661246612566126661276612866129661306613166132661336613466135661366613766138661396614066141661426614366144661456614666147661486614966150661516615266153661546615566156661576615866159661606616166162661636616466165661666616766168661696617066171661726617366174661756617666177661786617966180661816618266183661846618566186661876618866189661906619166192661936619466195661966619766198661996620066201662026620366204662056620666207662086620966210662116621266213662146621566216662176621866219662206622166222662236622466225662266622766228662296623066231662326623366234662356623666237662386623966240662416624266243662446624566246662476624866249662506625166252662536625466255662566625766258662596626066261662626626366264662656626666267662686626966270662716627266273662746627566276662776627866279662806628166282662836628466285662866628766288662896629066291662926629366294662956629666297662986629966300663016630266303663046630566306663076630866309663106631166312663136631466315663166631766318663196632066321663226632366324663256632666327663286632966330663316633266333663346633566336663376633866339663406634166342663436634466345663466634766348663496635066351663526635366354663556635666357663586635966360663616636266363663646636566366663676636866369663706637166372663736637466375663766637766378663796638066381663826638366384663856638666387663886638966390663916639266393663946639566396663976639866399664006640166402664036640466405664066640766408664096641066411664126641366414664156641666417664186641966420664216642266423664246642566426664276642866429664306643166432664336643466435664366643766438664396644066441664426644366444664456644666447664486644966450664516645266453664546645566456664576645866459664606646166462664636646466465664666646766468664696647066471664726647366474664756647666477664786647966480664816648266483664846648566486664876648866489664906649166492664936649466495664966649766498664996650066501665026650366504665056650666507665086650966510665116651266513665146651566516665176651866519665206652166522665236652466525665266652766528665296653066531665326653366534665356653666537665386653966540665416654266543665446654566546665476654866549665506655166552665536655466555665566655766558665596656066561665626656366564665656656666567665686656966570665716657266573665746657566576665776657866579665806658166582665836658466585665866658766588665896659066591665926659366594665956659666597665986659966600666016660266603666046660566606666076660866609666106661166612666136661466615666166661766618666196662066621666226662366624666256662666627666286662966630666316663266633666346663566636666376663866639666406664166642666436664466645666466664766648666496665066651666526665366654666556665666657666586665966660666616666266663666646666566666666676666866669666706667166672666736667466675666766667766678666796668066681666826668366684666856668666687666886668966690666916669266693666946669566696666976669866699667006670166702667036670466705667066670766708667096671066711667126671366714667156671666717667186671966720667216672266723667246672566726667276672866729667306673166732667336673466735667366673766738667396674066741667426674366744667456674666747667486674966750667516675266753667546675566756667576675866759667606676166762667636676466765667666676766768667696677066771667726677366774667756677666777667786677966780667816678266783667846678566786667876678866789667906679166792667936679466795667966679766798667996680066801668026680366804668056680666807668086680966810668116681266813668146681566816668176681866819668206682166822668236682466825668266682766828668296683066831668326683366834668356683666837668386683966840668416684266843668446684566846668476684866849668506685166852668536685466855668566685766858668596686066861668626686366864668656686666867668686686966870668716687266873668746687566876668776687866879668806688166882668836688466885668866688766888668896689066891668926689366894668956689666897668986689966900669016690266903669046690566906669076690866909669106691166912669136691466915669166691766918669196692066921669226692366924669256692666927669286692966930669316693266933669346693566936669376693866939669406694166942669436694466945669466694766948669496695066951669526695366954669556695666957669586695966960669616696266963669646696566966669676696866969669706697166972669736697466975669766697766978669796698066981669826698366984669856698666987669886698966990669916699266993669946699566996669976699866999670006700167002670036700467005670066700767008670096701067011670126701367014670156701667017670186701967020670216702267023670246702567026670276702867029670306703167032670336703467035670366703767038670396704067041670426704367044670456704667047670486704967050670516705267053670546705567056670576705867059670606706167062670636706467065670666706767068670696707067071670726707367074670756707667077670786707967080670816708267083670846708567086670876708867089670906709167092670936709467095670966709767098670996710067101671026710367104671056710667107671086710967110671116711267113671146711567116671176711867119671206712167122671236712467125671266712767128671296713067131671326713367134671356713667137671386713967140671416714267143671446714567146671476714867149671506715167152671536715467155671566715767158671596716067161671626716367164671656716667167671686716967170671716717267173671746717567176671776717867179671806718167182671836718467185671866718767188671896719067191671926719367194671956719667197671986719967200672016720267203672046720567206672076720867209672106721167212672136721467215672166721767218672196722067221672226722367224672256722667227672286722967230672316723267233672346723567236672376723867239672406724167242672436724467245672466724767248672496725067251672526725367254672556725667257672586725967260672616726267263672646726567266672676726867269672706727167272672736727467275672766727767278672796728067281672826728367284672856728667287672886728967290672916729267293672946729567296672976729867299673006730167302673036730467305673066730767308673096731067311673126731367314673156731667317673186731967320673216732267323673246732567326673276732867329673306733167332673336733467335673366733767338673396734067341673426734367344673456734667347673486734967350673516735267353673546735567356673576735867359673606736167362673636736467365673666736767368673696737067371673726737367374673756737667377673786737967380673816738267383673846738567386673876738867389673906739167392673936739467395673966739767398673996740067401674026740367404674056740667407674086740967410674116741267413674146741567416674176741867419674206742167422674236742467425674266742767428674296743067431674326743367434674356743667437674386743967440674416744267443674446744567446674476744867449674506745167452674536745467455674566745767458674596746067461674626746367464674656746667467674686746967470674716747267473674746747567476674776747867479674806748167482674836748467485674866748767488674896749067491674926749367494674956749667497674986749967500675016750267503675046750567506675076750867509675106751167512675136751467515675166751767518675196752067521675226752367524675256752667527675286752967530675316753267533675346753567536675376753867539675406754167542675436754467545675466754767548675496755067551675526755367554675556755667557675586755967560675616756267563675646756567566675676756867569675706757167572675736757467575675766757767578675796758067581675826758367584675856758667587675886758967590675916759267593675946759567596675976759867599676006760167602676036760467605676066760767608676096761067611676126761367614676156761667617676186761967620676216762267623676246762567626676276762867629676306763167632676336763467635676366763767638676396764067641676426764367644676456764667647676486764967650676516765267653676546765567656676576765867659676606766167662676636766467665676666766767668676696767067671676726767367674676756767667677676786767967680676816768267683676846768567686676876768867689676906769167692676936769467695676966769767698676996770067701677026770367704677056770667707677086770967710677116771267713677146771567716677176771867719677206772167722677236772467725677266772767728677296773067731677326773367734677356773667737677386773967740677416774267743677446774567746677476774867749677506775167752677536775467755677566775767758677596776067761677626776367764677656776667767677686776967770677716777267773677746777567776677776777867779677806778167782677836778467785677866778767788677896779067791677926779367794677956779667797677986779967800678016780267803678046780567806678076780867809678106781167812678136781467815678166781767818678196782067821678226782367824678256782667827678286782967830678316783267833678346783567836678376783867839678406784167842678436784467845678466784767848678496785067851678526785367854678556785667857678586785967860678616786267863678646786567866678676786867869678706787167872678736787467875678766787767878678796788067881678826788367884678856788667887678886788967890678916789267893678946789567896678976789867899679006790167902679036790467905679066790767908679096791067911679126791367914679156791667917679186791967920679216792267923679246792567926679276792867929679306793167932679336793467935679366793767938679396794067941679426794367944679456794667947679486794967950679516795267953679546795567956679576795867959679606796167962679636796467965679666796767968679696797067971679726797367974679756797667977679786797967980679816798267983679846798567986679876798867989679906799167992679936799467995679966799767998679996800068001680026800368004680056800668007680086800968010680116801268013680146801568016680176801868019680206802168022680236802468025680266802768028680296803068031680326803368034680356803668037680386803968040680416804268043680446804568046680476804868049680506805168052680536805468055680566805768058680596806068061680626806368064680656806668067680686806968070680716807268073680746807568076680776807868079680806808168082680836808468085680866808768088680896809068091680926809368094680956809668097680986809968100681016810268103681046810568106681076810868109681106811168112681136811468115681166811768118681196812068121681226812368124681256812668127681286812968130681316813268133681346813568136681376813868139681406814168142681436814468145681466814768148681496815068151681526815368154681556815668157681586815968160681616816268163681646816568166681676816868169681706817168172681736817468175681766817768178681796818068181681826818368184681856818668187681886818968190681916819268193681946819568196681976819868199682006820168202682036820468205682066820768208682096821068211682126821368214682156821668217682186821968220682216822268223682246822568226682276822868229682306823168232682336823468235682366823768238682396824068241682426824368244682456824668247682486824968250682516825268253682546825568256682576825868259682606826168262682636826468265682666826768268682696827068271682726827368274682756827668277682786827968280682816828268283682846828568286682876828868289682906829168292682936829468295682966829768298682996830068301683026830368304683056830668307683086830968310683116831268313683146831568316683176831868319683206832168322683236832468325683266832768328683296833068331683326833368334683356833668337683386833968340683416834268343683446834568346683476834868349683506835168352683536835468355683566835768358683596836068361683626836368364683656836668367683686836968370683716837268373683746837568376683776837868379683806838168382683836838468385683866838768388683896839068391683926839368394683956839668397683986839968400684016840268403684046840568406684076840868409684106841168412684136841468415684166841768418684196842068421684226842368424684256842668427684286842968430684316843268433684346843568436684376843868439684406844168442684436844468445684466844768448684496845068451684526845368454684556845668457684586845968460684616846268463684646846568466684676846868469684706847168472684736847468475684766847768478684796848068481684826848368484684856848668487684886848968490684916849268493684946849568496684976849868499685006850168502685036850468505685066850768508685096851068511685126851368514685156851668517685186851968520685216852268523685246852568526685276852868529685306853168532685336853468535685366853768538685396854068541685426854368544685456854668547685486854968550685516855268553685546855568556685576855868559685606856168562685636856468565685666856768568685696857068571685726857368574685756857668577685786857968580685816858268583685846858568586685876858868589685906859168592685936859468595685966859768598685996860068601686026860368604686056860668607686086860968610686116861268613686146861568616686176861868619686206862168622686236862468625686266862768628686296863068631686326863368634686356863668637686386863968640686416864268643686446864568646686476864868649686506865168652686536865468655686566865768658686596866068661686626866368664686656866668667686686866968670686716867268673686746867568676686776867868679686806868168682686836868468685686866868768688686896869068691686926869368694686956869668697686986869968700687016870268703687046870568706687076870868709687106871168712687136871468715687166871768718687196872068721687226872368724687256872668727687286872968730687316873268733687346873568736687376873868739687406874168742687436874468745687466874768748687496875068751687526875368754687556875668757687586875968760687616876268763687646876568766687676876868769687706877168772687736877468775687766877768778687796878068781687826878368784687856878668787687886878968790687916879268793687946879568796687976879868799688006880168802688036880468805688066880768808688096881068811688126881368814688156881668817688186881968820688216882268823688246882568826688276882868829688306883168832688336883468835688366883768838688396884068841688426884368844688456884668847688486884968850688516885268853688546885568856688576885868859688606886168862688636886468865688666886768868688696887068871688726887368874688756887668877688786887968880688816888268883688846888568886688876888868889688906889168892688936889468895688966889768898688996890068901689026890368904689056890668907689086890968910689116891268913689146891568916689176891868919689206892168922689236892468925689266892768928689296893068931689326893368934689356893668937689386893968940689416894268943689446894568946689476894868949689506895168952689536895468955689566895768958689596896068961689626896368964689656896668967689686896968970689716897268973689746897568976689776897868979689806898168982689836898468985689866898768988689896899068991689926899368994689956899668997689986899969000690016900269003690046900569006690076900869009690106901169012690136901469015690166901769018690196902069021690226902369024690256902669027690286902969030690316903269033690346903569036690376903869039690406904169042690436904469045690466904769048690496905069051690526905369054690556905669057690586905969060690616906269063690646906569066690676906869069690706907169072690736907469075690766907769078690796908069081690826908369084690856908669087690886908969090690916909269093690946909569096690976909869099691006910169102691036910469105691066910769108691096911069111691126911369114691156911669117691186911969120691216912269123691246912569126691276912869129691306913169132691336913469135691366913769138691396914069141691426914369144691456914669147691486914969150691516915269153691546915569156691576915869159691606916169162691636916469165691666916769168691696917069171691726917369174691756917669177691786917969180691816918269183691846918569186691876918869189691906919169192691936919469195691966919769198691996920069201692026920369204692056920669207692086920969210692116921269213692146921569216692176921869219692206922169222692236922469225692266922769228692296923069231692326923369234692356923669237692386923969240692416924269243692446924569246692476924869249692506925169252692536925469255692566925769258692596926069261692626926369264692656926669267692686926969270692716927269273692746927569276692776927869279692806928169282692836928469285692866928769288692896929069291692926929369294692956929669297692986929969300693016930269303693046930569306693076930869309693106931169312693136931469315693166931769318693196932069321693226932369324693256932669327693286932969330693316933269333693346933569336693376933869339693406934169342693436934469345693466934769348693496935069351693526935369354693556935669357693586935969360693616936269363693646936569366693676936869369693706937169372693736937469375693766937769378693796938069381693826938369384693856938669387693886938969390693916939269393693946939569396693976939869399694006940169402694036940469405694066940769408694096941069411694126941369414694156941669417694186941969420694216942269423694246942569426694276942869429694306943169432694336943469435694366943769438694396944069441694426944369444694456944669447694486944969450694516945269453694546945569456694576945869459694606946169462694636946469465694666946769468694696947069471694726947369474694756947669477694786947969480694816948269483694846948569486694876948869489694906949169492694936949469495694966949769498694996950069501695026950369504695056950669507695086950969510695116951269513695146951569516695176951869519695206952169522695236952469525695266952769528695296953069531695326953369534695356953669537695386953969540695416954269543695446954569546695476954869549695506955169552695536955469555695566955769558695596956069561695626956369564695656956669567695686956969570695716957269573695746957569576695776957869579695806958169582695836958469585695866958769588695896959069591695926959369594695956959669597695986959969600696016960269603696046960569606696076960869609696106961169612696136961469615696166961769618696196962069621696226962369624696256962669627696286962969630696316963269633696346963569636696376963869639696406964169642696436964469645696466964769648696496965069651696526965369654696556965669657696586965969660696616966269663696646966569666696676966869669696706967169672696736967469675696766967769678696796968069681696826968369684696856968669687696886968969690696916969269693696946969569696696976969869699697006970169702697036970469705697066970769708697096971069711697126971369714697156971669717697186971969720697216972269723697246972569726697276972869729697306973169732697336973469735697366973769738697396974069741697426974369744697456974669747697486974969750697516975269753697546975569756697576975869759697606976169762697636976469765697666976769768697696977069771697726977369774697756977669777697786977969780697816978269783697846978569786697876978869789697906979169792697936979469795697966979769798697996980069801698026980369804698056980669807698086980969810698116981269813698146981569816698176981869819698206982169822698236982469825698266982769828698296983069831698326983369834698356983669837698386983969840698416984269843698446984569846698476984869849698506985169852698536985469855698566985769858698596986069861698626986369864698656986669867698686986969870698716987269873698746987569876698776987869879698806988169882698836988469885698866988769888698896989069891698926989369894698956989669897698986989969900699016990269903699046990569906699076990869909699106991169912699136991469915699166991769918699196992069921699226992369924699256992669927699286992969930699316993269933699346993569936699376993869939699406994169942699436994469945699466994769948699496995069951699526995369954699556995669957699586995969960699616996269963699646996569966699676996869969699706997169972699736997469975699766997769978699796998069981699826998369984699856998669987699886998969990699916999269993699946999569996699976999869999700007000170002700037000470005700067000770008700097001070011700127001370014700157001670017700187001970020700217002270023700247002570026700277002870029700307003170032700337003470035700367003770038700397004070041700427004370044700457004670047700487004970050700517005270053700547005570056700577005870059700607006170062700637006470065700667006770068700697007070071700727007370074700757007670077700787007970080700817008270083700847008570086700877008870089700907009170092700937009470095700967009770098700997010070101701027010370104701057010670107701087010970110701117011270113701147011570116701177011870119701207012170122701237012470125701267012770128701297013070131701327013370134701357013670137701387013970140701417014270143701447014570146701477014870149701507015170152701537015470155701567015770158701597016070161701627016370164701657016670167701687016970170701717017270173701747017570176701777017870179701807018170182701837018470185701867018770188701897019070191701927019370194701957019670197701987019970200702017020270203702047020570206702077020870209702107021170212702137021470215702167021770218702197022070221702227022370224702257022670227702287022970230702317023270233702347023570236702377023870239702407024170242702437024470245702467024770248702497025070251702527025370254702557025670257702587025970260702617026270263702647026570266702677026870269702707027170272702737027470275702767027770278702797028070281702827028370284702857028670287702887028970290702917029270293702947029570296702977029870299703007030170302703037030470305703067030770308703097031070311703127031370314703157031670317703187031970320703217032270323703247032570326703277032870329703307033170332703337033470335703367033770338703397034070341703427034370344703457034670347703487034970350703517035270353703547035570356703577035870359703607036170362703637036470365703667036770368703697037070371703727037370374703757037670377703787037970380703817038270383703847038570386703877038870389703907039170392703937039470395703967039770398703997040070401704027040370404704057040670407704087040970410704117041270413704147041570416704177041870419704207042170422704237042470425704267042770428704297043070431704327043370434704357043670437704387043970440704417044270443704447044570446704477044870449704507045170452704537045470455704567045770458704597046070461704627046370464704657046670467704687046970470704717047270473704747047570476704777047870479704807048170482704837048470485704867048770488704897049070491704927049370494704957049670497704987049970500705017050270503705047050570506705077050870509705107051170512705137051470515705167051770518705197052070521705227052370524705257052670527705287052970530705317053270533705347053570536705377053870539705407054170542705437054470545705467054770548705497055070551705527055370554705557055670557705587055970560705617056270563705647056570566705677056870569705707057170572705737057470575705767057770578705797058070581705827058370584705857058670587705887058970590705917059270593705947059570596705977059870599706007060170602706037060470605706067060770608706097061070611706127061370614706157061670617706187061970620706217062270623706247062570626706277062870629706307063170632706337063470635706367063770638706397064070641706427064370644706457064670647706487064970650706517065270653706547065570656706577065870659706607066170662706637066470665706667066770668706697067070671706727067370674706757067670677706787067970680706817068270683706847068570686706877068870689706907069170692706937069470695706967069770698706997070070701707027070370704707057070670707707087070970710707117071270713707147071570716707177071870719707207072170722707237072470725707267072770728707297073070731707327073370734707357073670737707387073970740707417074270743707447074570746707477074870749707507075170752707537075470755707567075770758707597076070761707627076370764707657076670767707687076970770707717077270773707747077570776707777077870779707807078170782707837078470785707867078770788707897079070791707927079370794707957079670797707987079970800708017080270803708047080570806708077080870809708107081170812708137081470815708167081770818708197082070821708227082370824708257082670827708287082970830708317083270833708347083570836708377083870839708407084170842708437084470845708467084770848708497085070851708527085370854708557085670857708587085970860708617086270863708647086570866708677086870869708707087170872708737087470875708767087770878708797088070881708827088370884708857088670887708887088970890708917089270893708947089570896708977089870899709007090170902709037090470905709067090770908709097091070911709127091370914709157091670917709187091970920709217092270923709247092570926709277092870929709307093170932709337093470935709367093770938709397094070941709427094370944709457094670947709487094970950709517095270953709547095570956709577095870959709607096170962709637096470965709667096770968709697097070971709727097370974709757097670977709787097970980709817098270983709847098570986709877098870989709907099170992709937099470995709967099770998709997100071001710027100371004710057100671007710087100971010710117101271013710147101571016710177101871019710207102171022710237102471025710267102771028710297103071031710327103371034710357103671037710387103971040710417104271043710447104571046710477104871049710507105171052710537105471055710567105771058710597106071061710627106371064710657106671067710687106971070710717107271073710747107571076710777107871079710807108171082710837108471085710867108771088710897109071091710927109371094710957109671097710987109971100711017110271103711047110571106711077110871109711107111171112711137111471115711167111771118711197112071121711227112371124711257112671127711287112971130711317113271133711347113571136711377113871139711407114171142711437114471145711467114771148711497115071151711527115371154711557115671157711587115971160711617116271163711647116571166711677116871169711707117171172711737117471175711767117771178711797118071181711827118371184711857118671187711887118971190711917119271193711947119571196711977119871199712007120171202712037120471205712067120771208712097121071211712127121371214712157121671217712187121971220712217122271223712247122571226712277122871229712307123171232712337123471235712367123771238712397124071241712427124371244712457124671247712487124971250712517125271253712547125571256712577125871259712607126171262712637126471265712667126771268712697127071271712727127371274712757127671277712787127971280712817128271283712847128571286712877128871289712907129171292712937129471295712967129771298712997130071301713027130371304713057130671307713087130971310713117131271313713147131571316713177131871319713207132171322713237132471325713267132771328713297133071331713327133371334713357133671337713387133971340713417134271343713447134571346713477134871349713507135171352713537135471355713567135771358713597136071361713627136371364713657136671367713687136971370713717137271373713747137571376713777137871379713807138171382713837138471385713867138771388713897139071391713927139371394713957139671397713987139971400714017140271403714047140571406714077140871409714107141171412714137141471415714167141771418714197142071421714227142371424714257142671427714287142971430714317143271433714347143571436714377143871439714407144171442714437144471445714467144771448714497145071451714527145371454714557145671457714587145971460714617146271463714647146571466714677146871469714707147171472714737147471475714767147771478714797148071481714827148371484714857148671487714887148971490714917149271493714947149571496714977149871499715007150171502715037150471505715067150771508715097151071511715127151371514715157151671517715187151971520715217152271523715247152571526715277152871529715307153171532715337153471535715367153771538715397154071541715427154371544715457154671547715487154971550715517155271553715547155571556715577155871559715607156171562715637156471565715667156771568715697157071571715727157371574715757157671577715787157971580715817158271583715847158571586715877158871589715907159171592715937159471595715967159771598715997160071601716027160371604716057160671607716087160971610716117161271613716147161571616716177161871619716207162171622716237162471625716267162771628716297163071631716327163371634716357163671637716387163971640716417164271643716447164571646716477164871649716507165171652716537165471655716567165771658716597166071661716627166371664716657166671667716687166971670716717167271673716747167571676716777167871679716807168171682716837168471685716867168771688716897169071691716927169371694716957169671697716987169971700717017170271703717047170571706717077170871709717107171171712717137171471715717167171771718717197172071721717227172371724717257172671727717287172971730717317173271733717347173571736717377173871739717407174171742717437174471745717467174771748717497175071751717527175371754717557175671757717587175971760717617176271763717647176571766717677176871769717707177171772717737177471775717767177771778717797178071781717827178371784717857178671787717887178971790717917179271793717947179571796717977179871799718007180171802718037180471805718067180771808718097181071811718127181371814718157181671817718187181971820718217182271823718247182571826718277182871829718307183171832718337183471835718367183771838718397184071841718427184371844718457184671847718487184971850718517185271853718547185571856718577185871859718607186171862718637186471865718667186771868718697187071871718727187371874718757187671877718787187971880718817188271883718847188571886718877188871889718907189171892718937189471895718967189771898718997190071901719027190371904719057190671907719087190971910719117191271913719147191571916719177191871919719207192171922719237192471925719267192771928719297193071931719327193371934719357193671937719387193971940719417194271943719447194571946719477194871949719507195171952719537195471955719567195771958719597196071961719627196371964719657196671967719687196971970719717197271973719747197571976719777197871979719807198171982719837198471985719867198771988719897199071991719927199371994719957199671997719987199972000720017200272003720047200572006720077200872009720107201172012720137201472015720167201772018720197202072021720227202372024720257202672027720287202972030720317203272033720347203572036720377203872039720407204172042720437204472045720467204772048720497205072051720527205372054720557205672057720587205972060720617206272063720647206572066720677206872069720707207172072720737207472075720767207772078720797208072081720827208372084720857208672087720887208972090720917209272093720947209572096720977209872099721007210172102721037210472105721067210772108721097211072111721127211372114721157211672117721187211972120721217212272123721247212572126721277212872129721307213172132721337213472135721367213772138721397214072141721427214372144721457214672147721487214972150721517215272153721547215572156721577215872159721607216172162721637216472165721667216772168721697217072171721727217372174721757217672177721787217972180721817218272183721847218572186721877218872189721907219172192721937219472195721967219772198721997220072201722027220372204722057220672207722087220972210722117221272213722147221572216722177221872219722207222172222722237222472225722267222772228722297223072231722327223372234722357223672237722387223972240722417224272243722447224572246722477224872249722507225172252722537225472255722567225772258722597226072261722627226372264722657226672267722687226972270722717227272273722747227572276722777227872279722807228172282722837228472285722867228772288722897229072291722927229372294722957229672297722987229972300723017230272303723047230572306723077230872309723107231172312723137231472315723167231772318723197232072321723227232372324723257232672327723287232972330723317233272333723347233572336723377233872339723407234172342723437234472345723467234772348723497235072351723527235372354723557235672357723587235972360723617236272363723647236572366723677236872369723707237172372723737237472375723767237772378723797238072381723827238372384723857238672387723887238972390723917239272393723947239572396723977239872399724007240172402724037240472405724067240772408724097241072411724127241372414724157241672417724187241972420724217242272423724247242572426724277242872429724307243172432724337243472435724367243772438724397244072441724427244372444724457244672447724487244972450724517245272453724547245572456724577245872459724607246172462724637246472465724667246772468724697247072471724727247372474724757247672477724787247972480724817248272483724847248572486724877248872489724907249172492724937249472495724967249772498724997250072501725027250372504725057250672507725087250972510725117251272513725147251572516725177251872519725207252172522725237252472525725267252772528725297253072531725327253372534725357253672537725387253972540725417254272543725447254572546725477254872549725507255172552725537255472555725567255772558725597256072561725627256372564725657256672567725687256972570725717257272573725747257572576725777257872579725807258172582725837258472585725867258772588725897259072591725927259372594725957259672597725987259972600726017260272603726047260572606726077260872609726107261172612726137261472615726167261772618726197262072621726227262372624726257262672627726287262972630726317263272633726347263572636726377263872639726407264172642726437264472645726467264772648726497265072651726527265372654726557265672657726587265972660726617266272663726647266572666726677266872669726707267172672726737267472675726767267772678726797268072681726827268372684726857268672687726887268972690726917269272693726947269572696726977269872699727007270172702727037270472705727067270772708727097271072711727127271372714727157271672717727187271972720727217272272723727247272572726727277272872729727307273172732727337273472735727367273772738727397274072741727427274372744727457274672747727487274972750727517275272753727547275572756727577275872759727607276172762727637276472765727667276772768727697277072771727727277372774727757277672777727787277972780727817278272783727847278572786727877278872789727907279172792727937279472795727967279772798727997280072801728027280372804728057280672807728087280972810728117281272813728147281572816728177281872819728207282172822728237282472825728267282772828728297283072831728327283372834728357283672837728387283972840728417284272843728447284572846728477284872849728507285172852728537285472855728567285772858728597286072861728627286372864728657286672867728687286972870728717287272873728747287572876728777287872879728807288172882728837288472885728867288772888728897289072891728927289372894728957289672897728987289972900729017290272903729047290572906729077290872909729107291172912729137291472915729167291772918729197292072921729227292372924729257292672927729287292972930729317293272933729347293572936729377293872939729407294172942729437294472945729467294772948729497295072951729527295372954729557295672957729587295972960729617296272963729647296572966729677296872969729707297172972729737297472975729767297772978729797298072981729827298372984729857298672987729887298972990729917299272993729947299572996729977299872999730007300173002730037300473005730067300773008730097301073011730127301373014730157301673017730187301973020730217302273023730247302573026730277302873029730307303173032730337303473035730367303773038730397304073041730427304373044730457304673047730487304973050730517305273053730547305573056730577305873059730607306173062730637306473065730667306773068730697307073071730727307373074730757307673077730787307973080730817308273083730847308573086730877308873089730907309173092730937309473095730967309773098730997310073101731027310373104731057310673107731087310973110731117311273113731147311573116731177311873119731207312173122731237312473125731267312773128731297313073131731327313373134731357313673137731387313973140731417314273143731447314573146731477314873149731507315173152731537315473155731567315773158731597316073161731627316373164731657316673167731687316973170731717317273173731747317573176731777317873179731807318173182731837318473185731867318773188731897319073191731927319373194731957319673197731987319973200732017320273203732047320573206732077320873209732107321173212732137321473215732167321773218732197322073221732227322373224732257322673227732287322973230732317323273233732347323573236732377323873239732407324173242732437324473245732467324773248732497325073251732527325373254732557325673257732587325973260732617326273263732647326573266732677326873269732707327173272732737327473275732767327773278732797328073281732827328373284732857328673287732887328973290732917329273293732947329573296732977329873299733007330173302733037330473305733067330773308733097331073311733127331373314733157331673317733187331973320733217332273323733247332573326733277332873329733307333173332733337333473335733367333773338733397334073341733427334373344733457334673347733487334973350733517335273353733547335573356733577335873359733607336173362733637336473365733667336773368733697337073371733727337373374733757337673377733787337973380733817338273383733847338573386733877338873389733907339173392733937339473395733967339773398733997340073401734027340373404734057340673407734087340973410734117341273413734147341573416734177341873419734207342173422734237342473425734267342773428734297343073431734327343373434734357343673437734387343973440734417344273443734447344573446734477344873449734507345173452734537345473455734567345773458734597346073461734627346373464734657346673467734687346973470734717347273473734747347573476734777347873479734807348173482734837348473485734867348773488734897349073491734927349373494734957349673497734987349973500735017350273503735047350573506735077350873509735107351173512735137351473515735167351773518735197352073521735227352373524735257352673527735287352973530735317353273533735347353573536735377353873539735407354173542735437354473545735467354773548735497355073551735527355373554735557355673557735587355973560735617356273563735647356573566735677356873569735707357173572735737357473575735767357773578735797358073581735827358373584735857358673587735887358973590735917359273593735947359573596735977359873599736007360173602736037360473605736067360773608736097361073611736127361373614736157361673617736187361973620736217362273623736247362573626736277362873629736307363173632736337363473635736367363773638736397364073641736427364373644736457364673647736487364973650736517365273653736547365573656736577365873659736607366173662736637366473665736667366773668736697367073671736727367373674736757367673677736787367973680736817368273683736847368573686736877368873689736907369173692736937369473695736967369773698736997370073701737027370373704737057370673707737087370973710737117371273713737147371573716737177371873719737207372173722737237372473725737267372773728737297373073731737327373373734737357373673737737387373973740737417374273743737447374573746737477374873749737507375173752737537375473755737567375773758737597376073761737627376373764737657376673767737687376973770737717377273773737747377573776737777377873779737807378173782737837378473785737867378773788737897379073791737927379373794737957379673797737987379973800738017380273803738047380573806738077380873809738107381173812738137381473815738167381773818738197382073821738227382373824738257382673827738287382973830738317383273833738347383573836738377383873839738407384173842738437384473845738467384773848738497385073851738527385373854738557385673857738587385973860738617386273863738647386573866738677386873869738707387173872738737387473875738767387773878738797388073881738827388373884738857388673887738887388973890738917389273893738947389573896738977389873899739007390173902739037390473905739067390773908739097391073911739127391373914739157391673917739187391973920739217392273923739247392573926739277392873929739307393173932739337393473935739367393773938739397394073941739427394373944739457394673947739487394973950739517395273953739547395573956739577395873959739607396173962739637396473965739667396773968739697397073971739727397373974739757397673977739787397973980739817398273983739847398573986739877398873989739907399173992739937399473995739967399773998739997400074001740027400374004740057400674007740087400974010740117401274013740147401574016740177401874019740207402174022740237402474025740267402774028740297403074031740327403374034740357403674037740387403974040740417404274043740447404574046740477404874049740507405174052740537405474055740567405774058740597406074061740627406374064740657406674067740687406974070740717407274073740747407574076740777407874079740807408174082740837408474085740867408774088740897409074091740927409374094740957409674097740987409974100741017410274103741047410574106741077410874109741107411174112741137411474115741167411774118741197412074121741227412374124741257412674127741287412974130741317413274133741347413574136741377413874139741407414174142741437414474145741467414774148741497415074151741527415374154741557415674157741587415974160741617416274163741647416574166741677416874169741707417174172741737417474175741767417774178741797418074181741827418374184741857418674187741887418974190741917419274193741947419574196741977419874199742007420174202742037420474205742067420774208742097421074211742127421374214742157421674217742187421974220742217422274223742247422574226742277422874229742307423174232742337423474235742367423774238742397424074241742427424374244742457424674247742487424974250742517425274253742547425574256742577425874259742607426174262742637426474265742667426774268742697427074271742727427374274742757427674277742787427974280742817428274283742847428574286742877428874289742907429174292742937429474295742967429774298742997430074301743027430374304743057430674307743087430974310743117431274313743147431574316743177431874319743207432174322743237432474325743267432774328743297433074331743327433374334743357433674337743387433974340743417434274343743447434574346743477434874349743507435174352743537435474355743567435774358743597436074361743627436374364743657436674367743687436974370743717437274373743747437574376743777437874379743807438174382743837438474385743867438774388743897439074391743927439374394743957439674397743987439974400744017440274403744047440574406744077440874409744107441174412744137441474415744167441774418744197442074421744227442374424744257442674427744287442974430744317443274433744347443574436744377443874439744407444174442744437444474445744467444774448744497445074451744527445374454744557445674457744587445974460744617446274463744647446574466744677446874469744707447174472744737447474475744767447774478744797448074481744827448374484744857448674487744887448974490744917449274493744947449574496744977449874499745007450174502745037450474505745067450774508745097451074511745127451374514745157451674517745187451974520745217452274523745247452574526745277452874529745307453174532745337453474535745367453774538745397454074541745427454374544745457454674547745487454974550745517455274553745547455574556745577455874559745607456174562745637456474565745667456774568745697457074571745727457374574745757457674577745787457974580745817458274583745847458574586745877458874589745907459174592745937459474595745967459774598745997460074601746027460374604746057460674607746087460974610746117461274613746147461574616746177461874619746207462174622746237462474625746267462774628746297463074631746327463374634746357463674637746387463974640746417464274643746447464574646746477464874649746507465174652746537465474655746567465774658746597466074661746627466374664746657466674667746687466974670746717467274673746747467574676746777467874679746807468174682746837468474685746867468774688746897469074691746927469374694746957469674697746987469974700747017470274703747047470574706747077470874709747107471174712747137471474715747167471774718747197472074721747227472374724747257472674727747287472974730747317473274733747347473574736747377473874739747407474174742747437474474745747467474774748747497475074751747527475374754747557475674757747587475974760747617476274763747647476574766747677476874769747707477174772747737477474775747767477774778747797478074781747827478374784747857478674787747887478974790747917479274793747947479574796747977479874799748007480174802748037480474805748067480774808748097481074811748127481374814748157481674817748187481974820748217482274823748247482574826748277482874829748307483174832748337483474835748367483774838748397484074841748427484374844748457484674847748487484974850748517485274853748547485574856748577485874859748607486174862748637486474865748667486774868748697487074871748727487374874748757487674877748787487974880748817488274883748847488574886748877488874889748907489174892748937489474895748967489774898748997490074901749027490374904749057490674907749087490974910749117491274913749147491574916749177491874919749207492174922749237492474925749267492774928749297493074931749327493374934749357493674937749387493974940749417494274943749447494574946749477494874949749507495174952749537495474955749567495774958749597496074961749627496374964749657496674967749687496974970749717497274973749747497574976749777497874979749807498174982749837498474985749867498774988749897499074991749927499374994749957499674997749987499975000750017500275003750047500575006750077500875009750107501175012750137501475015750167501775018750197502075021750227502375024750257502675027750287502975030750317503275033750347503575036750377503875039750407504175042750437504475045750467504775048750497505075051750527505375054750557505675057750587505975060750617506275063750647506575066750677506875069750707507175072750737507475075750767507775078750797508075081750827508375084750857508675087750887508975090750917509275093750947509575096750977509875099751007510175102751037510475105751067510775108751097511075111751127511375114751157511675117751187511975120751217512275123751247512575126751277512875129751307513175132751337513475135751367513775138751397514075141751427514375144751457514675147751487514975150751517515275153751547515575156751577515875159751607516175162751637516475165751667516775168751697517075171751727517375174751757517675177751787517975180751817518275183751847518575186751877518875189751907519175192751937519475195751967519775198751997520075201752027520375204752057520675207752087520975210752117521275213752147521575216752177521875219752207522175222752237522475225752267522775228752297523075231752327523375234752357523675237752387523975240752417524275243752447524575246752477524875249752507525175252752537525475255752567525775258752597526075261752627526375264752657526675267752687526975270752717527275273752747527575276752777527875279752807528175282752837528475285752867528775288752897529075291752927529375294752957529675297752987529975300753017530275303753047530575306753077530875309753107531175312753137531475315753167531775318753197532075321753227532375324753257532675327753287532975330753317533275333753347533575336753377533875339753407534175342753437534475345753467534775348753497535075351753527535375354753557535675357753587535975360753617536275363753647536575366753677536875369753707537175372753737537475375753767537775378753797538075381753827538375384753857538675387753887538975390753917539275393753947539575396753977539875399754007540175402754037540475405754067540775408754097541075411754127541375414754157541675417754187541975420754217542275423754247542575426754277542875429754307543175432754337543475435754367543775438754397544075441754427544375444754457544675447754487544975450754517545275453754547545575456754577545875459754607546175462754637546475465754667546775468754697547075471754727547375474754757547675477754787547975480754817548275483754847548575486754877548875489754907549175492754937549475495754967549775498754997550075501755027550375504755057550675507755087550975510755117551275513755147551575516755177551875519755207552175522755237552475525755267552775528755297553075531755327553375534755357553675537755387553975540755417554275543755447554575546755477554875549755507555175552755537555475555755567555775558755597556075561755627556375564755657556675567755687556975570755717557275573755747557575576755777557875579755807558175582755837558475585755867558775588755897559075591755927559375594755957559675597755987559975600756017560275603756047560575606756077560875609756107561175612756137561475615756167561775618756197562075621756227562375624756257562675627756287562975630756317563275633756347563575636756377563875639756407564175642756437564475645756467564775648756497565075651756527565375654756557565675657756587565975660756617566275663756647566575666756677566875669756707567175672756737567475675756767567775678756797568075681756827568375684756857568675687756887568975690756917569275693756947569575696756977569875699757007570175702757037570475705757067570775708757097571075711757127571375714757157571675717757187571975720757217572275723757247572575726757277572875729757307573175732757337573475735757367573775738757397574075741757427574375744757457574675747757487574975750757517575275753757547575575756757577575875759757607576175762757637576475765757667576775768757697577075771757727577375774757757577675777757787577975780757817578275783757847578575786757877578875789757907579175792757937579475795757967579775798757997580075801758027580375804758057580675807758087580975810758117581275813758147581575816758177581875819758207582175822758237582475825758267582775828758297583075831758327583375834758357583675837758387583975840758417584275843758447584575846758477584875849758507585175852758537585475855758567585775858758597586075861758627586375864758657586675867758687586975870758717587275873758747587575876758777587875879758807588175882758837588475885758867588775888758897589075891758927589375894758957589675897758987589975900759017590275903759047590575906759077590875909759107591175912759137591475915759167591775918759197592075921759227592375924759257592675927759287592975930759317593275933759347593575936759377593875939759407594175942759437594475945759467594775948759497595075951759527595375954759557595675957759587595975960759617596275963759647596575966759677596875969759707597175972759737597475975759767597775978759797598075981759827598375984759857598675987759887598975990759917599275993759947599575996759977599875999760007600176002760037600476005760067600776008760097601076011760127601376014760157601676017760187601976020760217602276023760247602576026760277602876029760307603176032760337603476035760367603776038760397604076041760427604376044760457604676047760487604976050760517605276053760547605576056760577605876059760607606176062760637606476065760667606776068760697607076071760727607376074760757607676077760787607976080760817608276083760847608576086760877608876089760907609176092760937609476095760967609776098760997610076101761027610376104761057610676107761087610976110761117611276113761147611576116761177611876119761207612176122761237612476125761267612776128761297613076131761327613376134761357613676137761387613976140761417614276143761447614576146761477614876149761507615176152761537615476155761567615776158761597616076161761627616376164761657616676167761687616976170761717617276173761747617576176761777617876179761807618176182761837618476185761867618776188761897619076191761927619376194761957619676197761987619976200762017620276203762047620576206762077620876209762107621176212762137621476215762167621776218762197622076221762227622376224762257622676227762287622976230762317623276233762347623576236762377623876239762407624176242762437624476245762467624776248762497625076251762527625376254762557625676257762587625976260762617626276263762647626576266762677626876269762707627176272762737627476275762767627776278762797628076281762827628376284762857628676287762887628976290762917629276293762947629576296762977629876299763007630176302763037630476305763067630776308763097631076311763127631376314763157631676317763187631976320763217632276323763247632576326763277632876329763307633176332763337633476335763367633776338763397634076341763427634376344763457634676347763487634976350763517635276353763547635576356763577635876359763607636176362763637636476365763667636776368763697637076371763727637376374763757637676377763787637976380763817638276383763847638576386763877638876389763907639176392763937639476395763967639776398763997640076401764027640376404764057640676407764087640976410764117641276413764147641576416764177641876419764207642176422764237642476425764267642776428764297643076431764327643376434764357643676437764387643976440764417644276443764447644576446764477644876449764507645176452764537645476455764567645776458764597646076461764627646376464764657646676467764687646976470764717647276473764747647576476764777647876479764807648176482764837648476485764867648776488764897649076491764927649376494764957649676497764987649976500765017650276503765047650576506765077650876509765107651176512765137651476515765167651776518765197652076521765227652376524765257652676527765287652976530765317653276533765347653576536765377653876539765407654176542765437654476545765467654776548765497655076551765527655376554765557655676557765587655976560765617656276563765647656576566765677656876569765707657176572765737657476575765767657776578765797658076581765827658376584765857658676587765887658976590765917659276593765947659576596765977659876599766007660176602766037660476605766067660776608766097661076611766127661376614766157661676617766187661976620766217662276623766247662576626766277662876629766307663176632766337663476635766367663776638766397664076641766427664376644766457664676647766487664976650766517665276653766547665576656766577665876659766607666176662766637666476665766667666776668766697667076671766727667376674766757667676677766787667976680766817668276683766847668576686766877668876689766907669176692766937669476695766967669776698766997670076701767027670376704767057670676707767087670976710767117671276713767147671576716767177671876719767207672176722767237672476725767267672776728767297673076731767327673376734767357673676737767387673976740767417674276743767447674576746767477674876749767507675176752767537675476755767567675776758767597676076761767627676376764767657676676767767687676976770767717677276773767747677576776767777677876779767807678176782767837678476785767867678776788767897679076791767927679376794767957679676797767987679976800768017680276803768047680576806768077680876809768107681176812768137681476815768167681776818768197682076821768227682376824768257682676827768287682976830768317683276833768347683576836768377683876839768407684176842768437684476845768467684776848768497685076851768527685376854768557685676857768587685976860768617686276863768647686576866768677686876869768707687176872768737687476875768767687776878768797688076881768827688376884768857688676887768887688976890768917689276893768947689576896768977689876899769007690176902769037690476905769067690776908769097691076911769127691376914769157691676917769187691976920769217692276923769247692576926769277692876929769307693176932769337693476935769367693776938769397694076941769427694376944769457694676947769487694976950769517695276953769547695576956769577695876959769607696176962769637696476965769667696776968769697697076971769727697376974769757697676977769787697976980769817698276983769847698576986769877698876989769907699176992769937699476995769967699776998769997700077001770027700377004770057700677007770087700977010770117701277013770147701577016770177701877019770207702177022770237702477025770267702777028770297703077031770327703377034770357703677037770387703977040770417704277043770447704577046770477704877049770507705177052770537705477055770567705777058770597706077061770627706377064770657706677067770687706977070770717707277073770747707577076770777707877079770807708177082770837708477085770867708777088770897709077091770927709377094770957709677097770987709977100771017710277103771047710577106771077710877109771107711177112771137711477115771167711777118771197712077121771227712377124771257712677127771287712977130771317713277133771347713577136771377713877139771407714177142771437714477145771467714777148771497715077151771527715377154771557715677157771587715977160771617716277163771647716577166771677716877169771707717177172771737717477175771767717777178771797718077181771827718377184771857718677187771887718977190771917719277193771947719577196771977719877199772007720177202772037720477205772067720777208772097721077211772127721377214772157721677217772187721977220772217722277223772247722577226772277722877229772307723177232772337723477235772367723777238772397724077241772427724377244772457724677247772487724977250772517725277253772547725577256772577725877259772607726177262772637726477265772667726777268772697727077271772727727377274772757727677277772787727977280772817728277283772847728577286772877728877289772907729177292772937729477295772967729777298772997730077301773027730377304773057730677307773087730977310773117731277313773147731577316773177731877319773207732177322773237732477325773267732777328773297733077331773327733377334773357733677337773387733977340773417734277343773447734577346773477734877349773507735177352773537735477355773567735777358773597736077361773627736377364773657736677367773687736977370773717737277373773747737577376773777737877379773807738177382773837738477385773867738777388773897739077391773927739377394773957739677397773987739977400774017740277403774047740577406774077740877409774107741177412774137741477415774167741777418774197742077421774227742377424774257742677427774287742977430774317743277433774347743577436774377743877439774407744177442774437744477445774467744777448774497745077451774527745377454774557745677457774587745977460774617746277463774647746577466774677746877469774707747177472774737747477475774767747777478774797748077481774827748377484774857748677487774887748977490774917749277493774947749577496774977749877499775007750177502775037750477505775067750777508775097751077511775127751377514775157751677517775187751977520775217752277523775247752577526775277752877529775307753177532775337753477535775367753777538775397754077541775427754377544775457754677547775487754977550775517755277553775547755577556775577755877559775607756177562775637756477565775667756777568775697757077571775727757377574775757757677577775787757977580775817758277583775847758577586775877758877589775907759177592775937759477595775967759777598775997760077601776027760377604776057760677607776087760977610776117761277613776147761577616776177761877619776207762177622776237762477625776267762777628776297763077631776327763377634776357763677637776387763977640776417764277643776447764577646776477764877649776507765177652776537765477655776567765777658776597766077661776627766377664776657766677667776687766977670776717767277673776747767577676776777767877679776807768177682776837768477685776867768777688776897769077691776927769377694776957769677697776987769977700777017770277703777047770577706777077770877709777107771177712777137771477715777167771777718777197772077721777227772377724777257772677727777287772977730777317773277733777347773577736777377773877739777407774177742777437774477745777467774777748777497775077751777527775377754777557775677757777587775977760777617776277763777647776577766777677776877769777707777177772777737777477775777767777777778777797778077781777827778377784777857778677787777887778977790777917779277793777947779577796777977779877799778007780177802778037780477805778067780777808778097781077811778127781377814778157781677817778187781977820778217782277823778247782577826778277782877829778307783177832778337783477835778367783777838778397784077841778427784377844778457784677847778487784977850778517785277853778547785577856778577785877859778607786177862778637786477865778667786777868778697787077871778727787377874778757787677877778787787977880778817788277883778847788577886778877788877889778907789177892778937789477895778967789777898778997790077901779027790377904779057790677907779087790977910779117791277913779147791577916779177791877919779207792177922779237792477925779267792777928779297793077931779327793377934779357793677937779387793977940779417794277943779447794577946779477794877949779507795177952779537795477955779567795777958779597796077961779627796377964779657796677967779687796977970779717797277973779747797577976779777797877979779807798177982779837798477985779867798777988779897799077991779927799377994779957799677997779987799978000780017800278003780047800578006780077800878009780107801178012780137801478015780167801778018780197802078021780227802378024780257802678027780287802978030780317803278033780347803578036780377803878039780407804178042780437804478045780467804778048780497805078051780527805378054780557805678057780587805978060780617806278063780647806578066780677806878069780707807178072780737807478075780767807778078780797808078081780827808378084780857808678087780887808978090780917809278093780947809578096780977809878099781007810178102781037810478105781067810778108781097811078111781127811378114781157811678117781187811978120781217812278123781247812578126781277812878129781307813178132781337813478135781367813778138781397814078141781427814378144781457814678147781487814978150781517815278153781547815578156781577815878159781607816178162781637816478165781667816778168781697817078171781727817378174781757817678177781787817978180781817818278183781847818578186781877818878189781907819178192781937819478195781967819778198781997820078201782027820378204782057820678207782087820978210782117821278213782147821578216782177821878219782207822178222782237822478225782267822778228782297823078231782327823378234782357823678237782387823978240782417824278243782447824578246782477824878249782507825178252782537825478255782567825778258782597826078261782627826378264782657826678267782687826978270782717827278273782747827578276782777827878279782807828178282782837828478285782867828778288782897829078291782927829378294782957829678297782987829978300783017830278303783047830578306783077830878309783107831178312783137831478315783167831778318783197832078321783227832378324783257832678327783287832978330783317833278333783347833578336783377833878339783407834178342783437834478345783467834778348783497835078351783527835378354783557835678357783587835978360783617836278363783647836578366783677836878369783707837178372783737837478375783767837778378783797838078381783827838378384783857838678387783887838978390783917839278393783947839578396783977839878399784007840178402784037840478405784067840778408784097841078411784127841378414784157841678417784187841978420784217842278423784247842578426784277842878429784307843178432784337843478435784367843778438784397844078441784427844378444784457844678447784487844978450784517845278453784547845578456784577845878459784607846178462784637846478465784667846778468784697847078471784727847378474784757847678477784787847978480784817848278483784847848578486784877848878489784907849178492784937849478495784967849778498784997850078501785027850378504785057850678507785087850978510785117851278513785147851578516785177851878519785207852178522785237852478525785267852778528785297853078531785327853378534785357853678537785387853978540785417854278543785447854578546785477854878549785507855178552785537855478555785567855778558785597856078561785627856378564785657856678567785687856978570785717857278573785747857578576785777857878579785807858178582785837858478585785867858778588785897859078591785927859378594785957859678597785987859978600786017860278603786047860578606786077860878609786107861178612786137861478615786167861778618786197862078621786227862378624786257862678627786287862978630786317863278633786347863578636786377863878639786407864178642786437864478645786467864778648786497865078651786527865378654786557865678657786587865978660786617866278663786647866578666786677866878669786707867178672786737867478675786767867778678786797868078681786827868378684786857868678687786887868978690786917869278693786947869578696786977869878699787007870178702787037870478705787067870778708787097871078711787127871378714787157871678717787187871978720787217872278723787247872578726787277872878729787307873178732787337873478735787367873778738787397874078741787427874378744787457874678747787487874978750787517875278753787547875578756787577875878759787607876178762787637876478765787667876778768787697877078771787727877378774787757877678777787787877978780787817878278783787847878578786787877878878789787907879178792787937879478795787967879778798787997880078801788027880378804788057880678807788087880978810788117881278813788147881578816788177881878819788207882178822788237882478825788267882778828788297883078831788327883378834788357883678837788387883978840788417884278843788447884578846788477884878849788507885178852788537885478855788567885778858788597886078861788627886378864788657886678867788687886978870788717887278873788747887578876788777887878879788807888178882788837888478885788867888778888788897889078891788927889378894788957889678897788987889978900789017890278903789047890578906789077890878909789107891178912789137891478915789167891778918789197892078921789227892378924789257892678927789287892978930789317893278933789347893578936789377893878939789407894178942789437894478945789467894778948789497895078951789527895378954789557895678957789587895978960789617896278963789647896578966789677896878969789707897178972789737897478975789767897778978789797898078981789827898378984789857898678987789887898978990789917899278993789947899578996789977899878999790007900179002790037900479005790067900779008790097901079011790127901379014790157901679017790187901979020790217902279023790247902579026790277902879029790307903179032790337903479035790367903779038790397904079041790427904379044790457904679047790487904979050790517905279053790547905579056790577905879059790607906179062790637906479065790667906779068790697907079071790727907379074790757907679077790787907979080790817908279083790847908579086790877908879089790907909179092790937909479095790967909779098790997910079101791027910379104791057910679107791087910979110791117911279113791147911579116791177911879119791207912179122791237912479125791267912779128791297913079131791327913379134791357913679137791387913979140791417914279143791447914579146791477914879149791507915179152791537915479155791567915779158791597916079161791627916379164791657916679167791687916979170791717917279173791747917579176791777917879179791807918179182791837918479185791867918779188791897919079191791927919379194791957919679197791987919979200792017920279203792047920579206792077920879209792107921179212792137921479215792167921779218792197922079221792227922379224792257922679227792287922979230792317923279233792347923579236792377923879239792407924179242792437924479245792467924779248792497925079251792527925379254792557925679257792587925979260792617926279263792647926579266792677926879269792707927179272792737927479275792767927779278792797928079281792827928379284792857928679287792887928979290792917929279293792947929579296792977929879299793007930179302793037930479305793067930779308793097931079311793127931379314793157931679317793187931979320793217932279323793247932579326793277932879329793307933179332793337933479335793367933779338793397934079341793427934379344793457934679347793487934979350793517935279353793547935579356793577935879359793607936179362793637936479365793667936779368793697937079371793727937379374793757937679377793787937979380793817938279383793847938579386793877938879389793907939179392793937939479395793967939779398793997940079401794027940379404794057940679407794087940979410794117941279413794147941579416794177941879419794207942179422794237942479425794267942779428794297943079431794327943379434794357943679437794387943979440794417944279443794447944579446794477944879449794507945179452794537945479455794567945779458794597946079461794627946379464794657946679467794687946979470794717947279473794747947579476794777947879479794807948179482794837948479485794867948779488794897949079491794927949379494794957949679497794987949979500795017950279503795047950579506795077950879509795107951179512795137951479515795167951779518795197952079521795227952379524795257952679527795287952979530795317953279533795347953579536795377953879539795407954179542795437954479545795467954779548795497955079551795527955379554795557955679557795587955979560795617956279563795647956579566795677956879569795707957179572795737957479575795767957779578795797958079581795827958379584795857958679587795887958979590795917959279593795947959579596795977959879599796007960179602796037960479605796067960779608796097961079611796127961379614796157961679617796187961979620796217962279623796247962579626796277962879629796307963179632796337963479635796367963779638796397964079641796427964379644796457964679647796487964979650796517965279653796547965579656796577965879659796607966179662796637966479665796667966779668796697967079671796727967379674796757967679677796787967979680796817968279683796847968579686796877968879689796907969179692796937969479695796967969779698796997970079701797027970379704797057970679707797087970979710797117971279713797147971579716797177971879719797207972179722797237972479725797267972779728797297973079731797327973379734797357973679737797387973979740797417974279743797447974579746797477974879749797507975179752797537975479755797567975779758797597976079761797627976379764797657976679767797687976979770797717977279773797747977579776797777977879779797807978179782797837978479785797867978779788797897979079791797927979379794797957979679797797987979979800798017980279803798047980579806798077980879809798107981179812798137981479815798167981779818798197982079821798227982379824798257982679827798287982979830798317983279833798347983579836798377983879839798407984179842798437984479845798467984779848798497985079851798527985379854798557985679857798587985979860798617986279863798647986579866798677986879869798707987179872798737987479875798767987779878798797988079881798827988379884798857988679887798887988979890798917989279893798947989579896798977989879899799007990179902799037990479905799067990779908799097991079911799127991379914799157991679917799187991979920799217992279923799247992579926799277992879929799307993179932799337993479935799367993779938799397994079941799427994379944799457994679947799487994979950799517995279953799547995579956799577995879959799607996179962799637996479965799667996779968799697997079971799727997379974799757997679977799787997979980799817998279983799847998579986799877998879989799907999179992799937999479995799967999779998799998000080001800028000380004800058000680007800088000980010800118001280013800148001580016800178001880019800208002180022800238002480025800268002780028800298003080031800328003380034800358003680037800388003980040800418004280043800448004580046800478004880049800508005180052800538005480055800568005780058800598006080061800628006380064800658006680067800688006980070800718007280073800748007580076800778007880079800808008180082800838008480085800868008780088800898009080091800928009380094800958009680097800988009980100801018010280103801048010580106801078010880109801108011180112801138011480115801168011780118801198012080121801228012380124801258012680127801288012980130801318013280133801348013580136801378013880139801408014180142801438014480145801468014780148801498015080151801528015380154801558015680157801588015980160801618016280163801648016580166801678016880169801708017180172801738017480175801768017780178801798018080181801828018380184801858018680187801888018980190801918019280193801948019580196801978019880199802008020180202802038020480205802068020780208802098021080211802128021380214802158021680217802188021980220802218022280223802248022580226802278022880229802308023180232802338023480235802368023780238802398024080241802428024380244802458024680247802488024980250802518025280253802548025580256802578025880259802608026180262802638026480265802668026780268802698027080271802728027380274802758027680277802788027980280802818028280283802848028580286802878028880289802908029180292802938029480295802968029780298802998030080301803028030380304803058030680307803088030980310803118031280313803148031580316803178031880319803208032180322803238032480325803268032780328803298033080331803328033380334803358033680337803388033980340803418034280343803448034580346803478034880349803508035180352803538035480355803568035780358803598036080361803628036380364803658036680367803688036980370803718037280373803748037580376803778037880379803808038180382803838038480385803868038780388803898039080391803928039380394803958039680397803988039980400804018040280403804048040580406804078040880409804108041180412804138041480415804168041780418804198042080421804228042380424804258042680427804288042980430804318043280433804348043580436804378043880439804408044180442804438044480445804468044780448804498045080451804528045380454804558045680457804588045980460804618046280463804648046580466804678046880469804708047180472804738047480475804768047780478804798048080481804828048380484804858048680487804888048980490804918049280493804948049580496804978049880499805008050180502805038050480505805068050780508805098051080511805128051380514805158051680517805188051980520805218052280523805248052580526805278052880529805308053180532805338053480535805368053780538805398054080541805428054380544805458054680547805488054980550805518055280553805548055580556805578055880559805608056180562805638056480565805668056780568805698057080571805728057380574805758057680577805788057980580805818058280583805848058580586805878058880589805908059180592805938059480595805968059780598805998060080601806028060380604806058060680607806088060980610806118061280613806148061580616806178061880619806208062180622806238062480625806268062780628806298063080631806328063380634806358063680637806388063980640806418064280643806448064580646806478064880649806508065180652806538065480655806568065780658806598066080661806628066380664806658066680667806688066980670806718067280673806748067580676806778067880679806808068180682806838068480685806868068780688806898069080691806928069380694806958069680697806988069980700807018070280703807048070580706807078070880709807108071180712807138071480715807168071780718807198072080721807228072380724807258072680727807288072980730807318073280733807348073580736807378073880739807408074180742807438074480745807468074780748807498075080751807528075380754807558075680757807588075980760807618076280763807648076580766807678076880769807708077180772807738077480775807768077780778807798078080781807828078380784807858078680787807888078980790807918079280793807948079580796807978079880799808008080180802808038080480805808068080780808808098081080811808128081380814808158081680817808188081980820808218082280823808248082580826808278082880829808308083180832808338083480835808368083780838808398084080841808428084380844808458084680847808488084980850808518085280853808548085580856808578085880859808608086180862808638086480865808668086780868808698087080871808728087380874808758087680877808788087980880808818088280883808848088580886808878088880889808908089180892808938089480895808968089780898808998090080901809028090380904809058090680907809088090980910809118091280913809148091580916809178091880919809208092180922809238092480925809268092780928809298093080931809328093380934809358093680937809388093980940809418094280943809448094580946809478094880949809508095180952809538095480955809568095780958809598096080961809628096380964809658096680967809688096980970809718097280973809748097580976809778097880979809808098180982809838098480985809868098780988809898099080991809928099380994809958099680997809988099981000810018100281003810048100581006810078100881009810108101181012810138101481015810168101781018810198102081021810228102381024810258102681027810288102981030810318103281033810348103581036810378103881039810408104181042810438104481045810468104781048810498105081051810528105381054810558105681057810588105981060810618106281063810648106581066810678106881069810708107181072810738107481075810768107781078810798108081081810828108381084810858108681087810888108981090810918109281093810948109581096810978109881099811008110181102811038110481105811068110781108811098111081111811128111381114811158111681117811188111981120811218112281123811248112581126811278112881129811308113181132811338113481135811368113781138811398114081141811428114381144811458114681147811488114981150811518115281153811548115581156811578115881159811608116181162811638116481165811668116781168811698117081171811728117381174811758117681177811788117981180811818118281183811848118581186811878118881189811908119181192811938119481195811968119781198811998120081201812028120381204812058120681207812088120981210812118121281213812148121581216812178121881219812208122181222812238122481225812268122781228812298123081231812328123381234812358123681237812388123981240812418124281243812448124581246812478124881249812508125181252812538125481255812568125781258812598126081261812628126381264812658126681267812688126981270812718127281273812748127581276812778127881279812808128181282812838128481285812868128781288812898129081291812928129381294812958129681297812988129981300813018130281303813048130581306813078130881309813108131181312813138131481315813168131781318813198132081321813228132381324813258132681327813288132981330813318133281333813348133581336813378133881339813408134181342813438134481345813468134781348813498135081351813528135381354813558135681357813588135981360813618136281363813648136581366813678136881369813708137181372813738137481375813768137781378813798138081381813828138381384813858138681387813888138981390813918139281393813948139581396813978139881399814008140181402814038140481405814068140781408814098141081411814128141381414814158141681417814188141981420814218142281423814248142581426814278142881429814308143181432814338143481435814368143781438814398144081441814428144381444814458144681447814488144981450814518145281453814548145581456814578145881459814608146181462814638146481465814668146781468814698147081471814728147381474814758147681477814788147981480814818148281483814848148581486814878148881489814908149181492814938149481495814968149781498814998150081501815028150381504815058150681507815088150981510815118151281513815148151581516815178151881519815208152181522815238152481525815268152781528815298153081531815328153381534815358153681537815388153981540815418154281543815448154581546815478154881549815508155181552815538155481555815568155781558815598156081561815628156381564815658156681567815688156981570815718157281573815748157581576815778157881579815808158181582815838158481585815868158781588815898159081591815928159381594815958159681597815988159981600816018160281603816048160581606816078160881609816108161181612816138161481615816168161781618816198162081621816228162381624816258162681627816288162981630816318163281633816348163581636816378163881639816408164181642816438164481645816468164781648816498165081651816528165381654816558165681657816588165981660816618166281663816648166581666816678166881669816708167181672816738167481675816768167781678816798168081681816828168381684816858168681687816888168981690816918169281693816948169581696816978169881699817008170181702817038170481705817068170781708817098171081711817128171381714817158171681717817188171981720817218172281723817248172581726817278172881729817308173181732817338173481735817368173781738817398174081741817428174381744817458174681747817488174981750817518175281753817548175581756817578175881759817608176181762817638176481765817668176781768817698177081771817728177381774817758177681777817788177981780817818178281783817848178581786817878178881789817908179181792817938179481795817968179781798817998180081801818028180381804818058180681807818088180981810818118181281813818148181581816818178181881819818208182181822818238182481825818268182781828818298183081831818328183381834818358183681837818388183981840818418184281843818448184581846818478184881849818508185181852818538185481855818568185781858818598186081861818628186381864818658186681867818688186981870818718187281873818748187581876818778187881879818808188181882818838188481885818868188781888818898189081891818928189381894818958189681897818988189981900819018190281903819048190581906819078190881909819108191181912819138191481915819168191781918819198192081921819228192381924819258192681927819288192981930819318193281933819348193581936819378193881939819408194181942819438194481945819468194781948819498195081951819528195381954819558195681957819588195981960819618196281963819648196581966819678196881969819708197181972819738197481975819768197781978819798198081981819828198381984819858198681987819888198981990819918199281993819948199581996819978199881999820008200182002820038200482005820068200782008820098201082011820128201382014820158201682017820188201982020820218202282023820248202582026820278202882029820308203182032820338203482035820368203782038820398204082041820428204382044820458204682047820488204982050820518205282053820548205582056820578205882059820608206182062820638206482065820668206782068820698207082071820728207382074820758207682077820788207982080820818208282083820848208582086820878208882089820908209182092820938209482095820968209782098820998210082101821028210382104821058210682107821088210982110821118211282113821148211582116821178211882119821208212182122821238212482125821268212782128821298213082131821328213382134821358213682137821388213982140821418214282143821448214582146821478214882149821508215182152821538215482155821568215782158821598216082161821628216382164821658216682167821688216982170821718217282173821748217582176821778217882179821808218182182821838218482185821868218782188821898219082191821928219382194821958219682197821988219982200822018220282203822048220582206822078220882209822108221182212822138221482215822168221782218822198222082221822228222382224822258222682227822288222982230822318223282233822348223582236822378223882239822408224182242822438224482245822468224782248822498225082251822528225382254822558225682257822588225982260822618226282263822648226582266822678226882269822708227182272822738227482275822768227782278822798228082281822828228382284822858228682287822888228982290822918229282293822948229582296822978229882299823008230182302823038230482305823068230782308823098231082311823128231382314823158231682317823188231982320823218232282323823248232582326823278232882329823308233182332823338233482335823368233782338823398234082341823428234382344823458234682347823488234982350823518235282353823548235582356823578235882359823608236182362823638236482365823668236782368823698237082371823728237382374823758237682377823788237982380823818238282383823848238582386823878238882389823908239182392823938239482395823968239782398823998240082401824028240382404824058240682407824088240982410824118241282413824148241582416824178241882419824208242182422824238242482425824268242782428824298243082431824328243382434824358243682437824388243982440824418244282443824448244582446824478244882449824508245182452824538245482455824568245782458824598246082461824628246382464824658246682467824688246982470824718247282473824748247582476824778247882479824808248182482824838248482485824868248782488824898249082491824928249382494824958249682497824988249982500825018250282503825048250582506825078250882509825108251182512825138251482515825168251782518825198252082521825228252382524825258252682527825288252982530825318253282533825348253582536825378253882539825408254182542825438254482545825468254782548825498255082551825528255382554825558255682557825588255982560825618256282563825648256582566825678256882569825708257182572825738257482575825768257782578825798258082581825828258382584825858258682587825888258982590825918259282593825948259582596825978259882599826008260182602826038260482605826068260782608826098261082611826128261382614826158261682617826188261982620826218262282623826248262582626826278262882629826308263182632826338263482635826368263782638826398264082641826428264382644826458264682647826488264982650826518265282653826548265582656826578265882659826608266182662826638266482665826668266782668826698267082671826728267382674826758267682677826788267982680826818268282683826848268582686826878268882689826908269182692826938269482695826968269782698826998270082701827028270382704827058270682707827088270982710827118271282713827148271582716827178271882719827208272182722827238272482725827268272782728827298273082731827328273382734827358273682737827388273982740827418274282743827448274582746827478274882749827508275182752827538275482755827568275782758827598276082761827628276382764827658276682767827688276982770827718277282773827748277582776827778277882779827808278182782827838278482785827868278782788827898279082791827928279382794827958279682797827988279982800828018280282803828048280582806828078280882809828108281182812828138281482815828168281782818828198282082821828228282382824828258282682827828288282982830828318283282833828348283582836828378283882839828408284182842828438284482845828468284782848828498285082851828528285382854828558285682857828588285982860828618286282863828648286582866828678286882869828708287182872828738287482875828768287782878828798288082881828828288382884828858288682887828888288982890828918289282893828948289582896828978289882899829008290182902829038290482905829068290782908829098291082911829128291382914829158291682917829188291982920829218292282923829248292582926829278292882929829308293182932829338293482935829368293782938829398294082941829428294382944829458294682947829488294982950829518295282953829548295582956829578295882959829608296182962829638296482965829668296782968829698297082971829728297382974829758297682977829788297982980829818298282983829848298582986829878298882989829908299182992829938299482995829968299782998829998300083001830028300383004830058300683007830088300983010830118301283013830148301583016830178301883019830208302183022830238302483025830268302783028830298303083031830328303383034830358303683037830388303983040830418304283043830448304583046830478304883049830508305183052830538305483055830568305783058830598306083061830628306383064830658306683067830688306983070830718307283073830748307583076830778307883079830808308183082830838308483085830868308783088830898309083091830928309383094830958309683097830988309983100831018310283103831048310583106831078310883109831108311183112831138311483115831168311783118831198312083121831228312383124831258312683127831288312983130831318313283133831348313583136831378313883139831408314183142831438314483145831468314783148831498315083151831528315383154831558315683157831588315983160831618316283163831648316583166831678316883169831708317183172831738317483175831768317783178831798318083181831828318383184831858318683187831888318983190831918319283193831948319583196831978319883199832008320183202832038320483205832068320783208832098321083211832128321383214832158321683217832188321983220832218322283223832248322583226832278322883229832308323183232832338323483235832368323783238832398324083241832428324383244832458324683247832488324983250832518325283253832548325583256832578325883259832608326183262832638326483265832668326783268832698327083271832728327383274832758327683277832788327983280832818328283283832848328583286832878328883289832908329183292832938329483295832968329783298832998330083301833028330383304833058330683307833088330983310833118331283313833148331583316833178331883319833208332183322833238332483325833268332783328833298333083331833328333383334833358333683337833388333983340833418334283343833448334583346833478334883349833508335183352833538335483355833568335783358833598336083361833628336383364833658336683367833688336983370833718337283373833748337583376833778337883379833808338183382833838338483385833868338783388833898339083391833928339383394833958339683397833988339983400834018340283403834048340583406834078340883409834108341183412834138341483415834168341783418834198342083421834228342383424834258342683427834288342983430834318343283433834348343583436834378343883439834408344183442834438344483445834468344783448834498345083451834528345383454834558345683457834588345983460834618346283463834648346583466834678346883469834708347183472834738347483475834768347783478834798348083481834828348383484834858348683487834888348983490834918349283493834948349583496834978349883499835008350183502835038350483505835068350783508835098351083511835128351383514835158351683517835188351983520835218352283523835248352583526835278352883529835308353183532835338353483535835368353783538835398354083541835428354383544835458354683547835488354983550835518355283553835548355583556835578355883559835608356183562835638356483565835668356783568835698357083571835728357383574835758357683577835788357983580835818358283583835848358583586835878358883589835908359183592835938359483595835968359783598835998360083601836028360383604836058360683607836088360983610836118361283613836148361583616836178361883619836208362183622836238362483625836268362783628836298363083631836328363383634836358363683637836388363983640836418364283643836448364583646836478364883649836508365183652836538365483655836568365783658836598366083661836628366383664836658366683667836688366983670836718367283673836748367583676836778367883679836808368183682836838368483685836868368783688836898369083691836928369383694836958369683697836988369983700837018370283703837048370583706837078370883709837108371183712837138371483715837168371783718837198372083721837228372383724837258372683727837288372983730837318373283733837348373583736837378373883739837408374183742837438374483745837468374783748837498375083751837528375383754837558375683757837588375983760837618376283763837648376583766837678376883769837708377183772837738377483775837768377783778837798378083781837828378383784837858378683787837888378983790837918379283793837948379583796837978379883799838008380183802838038380483805838068380783808838098381083811838128381383814838158381683817838188381983820838218382283823838248382583826838278382883829838308383183832838338383483835838368383783838838398384083841838428384383844838458384683847838488384983850838518385283853838548385583856838578385883859838608386183862838638386483865838668386783868838698387083871838728387383874838758387683877838788387983880838818388283883838848388583886838878388883889838908389183892838938389483895838968389783898838998390083901839028390383904839058390683907839088390983910839118391283913839148391583916839178391883919839208392183922839238392483925839268392783928839298393083931839328393383934839358393683937839388393983940839418394283943839448394583946839478394883949839508395183952839538395483955839568395783958839598396083961839628396383964839658396683967839688396983970839718397283973839748397583976839778397883979839808398183982839838398483985839868398783988839898399083991839928399383994839958399683997839988399984000840018400284003840048400584006840078400884009840108401184012840138401484015840168401784018840198402084021840228402384024840258402684027840288402984030840318403284033840348403584036840378403884039840408404184042840438404484045840468404784048840498405084051840528405384054840558405684057840588405984060840618406284063840648406584066840678406884069840708407184072840738407484075840768407784078840798408084081840828408384084840858408684087840888408984090840918409284093840948409584096840978409884099841008410184102841038410484105841068410784108841098411084111841128411384114841158411684117841188411984120841218412284123841248412584126841278412884129841308413184132841338413484135841368413784138841398414084141841428414384144841458414684147841488414984150841518415284153841548415584156841578415884159841608416184162841638416484165841668416784168841698417084171841728417384174841758417684177841788417984180841818418284183841848418584186841878418884189841908419184192841938419484195841968419784198841998420084201842028420384204842058420684207842088420984210842118421284213842148421584216842178421884219842208422184222842238422484225842268422784228842298423084231842328423384234842358423684237842388423984240842418424284243842448424584246842478424884249842508425184252842538425484255842568425784258842598426084261842628426384264842658426684267842688426984270842718427284273842748427584276842778427884279842808428184282842838428484285842868428784288842898429084291842928429384294842958429684297842988429984300843018430284303843048430584306843078430884309843108431184312843138431484315843168431784318843198432084321843228432384324843258432684327843288432984330843318433284333843348433584336843378433884339843408434184342843438434484345843468434784348843498435084351843528435384354843558435684357843588435984360843618436284363843648436584366843678436884369843708437184372843738437484375843768437784378843798438084381843828438384384843858438684387843888438984390843918439284393843948439584396843978439884399844008440184402844038440484405844068440784408844098441084411844128441384414844158441684417844188441984420844218442284423844248442584426844278442884429844308443184432844338443484435844368443784438844398444084441844428444384444844458444684447844488444984450844518445284453844548445584456844578445884459844608446184462844638446484465844668446784468844698447084471844728447384474844758447684477844788447984480844818448284483844848448584486844878448884489844908449184492844938449484495844968449784498844998450084501845028450384504845058450684507845088450984510845118451284513845148451584516845178451884519845208452184522845238452484525845268452784528845298453084531845328453384534845358453684537845388453984540845418454284543845448454584546845478454884549845508455184552845538455484555845568455784558845598456084561845628456384564845658456684567845688456984570845718457284573845748457584576845778457884579845808458184582845838458484585845868458784588845898459084591845928459384594845958459684597845988459984600846018460284603846048460584606846078460884609846108461184612846138461484615846168461784618846198462084621846228462384624846258462684627846288462984630846318463284633846348463584636846378463884639846408464184642846438464484645846468464784648846498465084651846528465384654846558465684657846588465984660846618466284663846648466584666846678466884669846708467184672846738467484675846768467784678846798468084681846828468384684846858468684687846888468984690846918469284693846948469584696846978469884699847008470184702847038470484705847068470784708847098471084711847128471384714847158471684717847188471984720847218472284723847248472584726847278472884729847308473184732847338473484735847368473784738847398474084741847428474384744847458474684747847488474984750847518475284753847548475584756847578475884759847608476184762847638476484765847668476784768847698477084771847728477384774847758477684777847788477984780847818478284783847848478584786847878478884789847908479184792847938479484795847968479784798847998480084801848028480384804848058480684807848088480984810848118481284813848148481584816848178481884819848208482184822848238482484825848268482784828848298483084831848328483384834848358483684837848388483984840848418484284843848448484584846848478484884849848508485184852848538485484855848568485784858848598486084861848628486384864848658486684867848688486984870848718487284873848748487584876848778487884879848808488184882848838488484885848868488784888848898489084891848928489384894848958489684897848988489984900849018490284903849048490584906849078490884909849108491184912849138491484915849168491784918849198492084921849228492384924849258492684927849288492984930849318493284933849348493584936849378493884939849408494184942849438494484945849468494784948849498495084951849528495384954849558495684957849588495984960849618496284963849648496584966849678496884969849708497184972849738497484975849768497784978849798498084981849828498384984849858498684987849888498984990849918499284993849948499584996849978499884999850008500185002850038500485005850068500785008850098501085011850128501385014850158501685017850188501985020850218502285023850248502585026850278502885029850308503185032850338503485035850368503785038850398504085041850428504385044850458504685047850488504985050850518505285053850548505585056850578505885059850608506185062850638506485065850668506785068850698507085071850728507385074850758507685077850788507985080850818508285083850848508585086850878508885089850908509185092850938509485095850968509785098850998510085101851028510385104851058510685107851088510985110851118511285113851148511585116851178511885119851208512185122851238512485125851268512785128851298513085131851328513385134851358513685137851388513985140851418514285143851448514585146851478514885149851508515185152851538515485155851568515785158851598516085161851628516385164851658516685167851688516985170851718517285173851748517585176851778517885179851808518185182851838518485185851868518785188851898519085191851928519385194851958519685197851988519985200852018520285203852048520585206852078520885209852108521185212852138521485215852168521785218852198522085221852228522385224852258522685227852288522985230852318523285233852348523585236852378523885239852408524185242852438524485245852468524785248852498525085251852528525385254852558525685257852588525985260852618526285263852648526585266852678526885269852708527185272852738527485275852768527785278852798528085281852828528385284852858528685287852888528985290852918529285293852948529585296852978529885299853008530185302853038530485305853068530785308853098531085311853128531385314853158531685317853188531985320853218532285323853248532585326853278532885329853308533185332853338533485335853368533785338853398534085341853428534385344853458534685347853488534985350853518535285353853548535585356853578535885359853608536185362853638536485365853668536785368853698537085371853728537385374853758537685377853788537985380853818538285383853848538585386853878538885389853908539185392853938539485395853968539785398853998540085401854028540385404854058540685407854088540985410854118541285413854148541585416854178541885419854208542185422854238542485425854268542785428854298543085431854328543385434854358543685437854388543985440854418544285443854448544585446854478544885449854508545185452854538545485455854568545785458854598546085461854628546385464854658546685467854688546985470854718547285473854748547585476854778547885479854808548185482854838548485485854868548785488854898549085491854928549385494854958549685497854988549985500855018550285503855048550585506855078550885509855108551185512855138551485515855168551785518855198552085521855228552385524855258552685527855288552985530855318553285533855348553585536855378553885539855408554185542855438554485545855468554785548855498555085551855528555385554855558555685557855588555985560855618556285563855648556585566855678556885569855708557185572855738557485575855768557785578855798558085581855828558385584855858558685587855888558985590855918559285593855948559585596855978559885599856008560185602856038560485605856068560785608856098561085611856128561385614856158561685617856188561985620856218562285623856248562585626856278562885629856308563185632856338563485635856368563785638856398564085641856428564385644856458564685647856488564985650856518565285653856548565585656856578565885659856608566185662856638566485665856668566785668856698567085671856728567385674856758567685677856788567985680856818568285683856848568585686856878568885689856908569185692856938569485695856968569785698856998570085701857028570385704857058570685707857088570985710857118571285713857148571585716857178571885719857208572185722857238572485725857268572785728857298573085731857328573385734857358573685737857388573985740857418574285743857448574585746857478574885749857508575185752857538575485755857568575785758857598576085761857628576385764857658576685767857688576985770857718577285773857748577585776857778577885779857808578185782857838578485785857868578785788857898579085791857928579385794857958579685797857988579985800858018580285803858048580585806858078580885809858108581185812858138581485815858168581785818858198582085821858228582385824858258582685827858288582985830858318583285833858348583585836858378583885839858408584185842858438584485845858468584785848858498585085851858528585385854858558585685857858588585985860858618586285863858648586585866858678586885869858708587185872858738587485875858768587785878858798588085881858828588385884858858588685887858888588985890858918589285893858948589585896858978589885899859008590185902859038590485905859068590785908859098591085911859128591385914859158591685917859188591985920859218592285923859248592585926859278592885929859308593185932859338593485935859368593785938859398594085941859428594385944859458594685947859488594985950859518595285953859548595585956859578595885959859608596185962859638596485965859668596785968859698597085971859728597385974859758597685977859788597985980859818598285983859848598585986859878598885989859908599185992859938599485995859968599785998859998600086001860028600386004860058600686007860088600986010860118601286013860148601586016860178601886019860208602186022860238602486025860268602786028860298603086031860328603386034860358603686037860388603986040860418604286043860448604586046860478604886049860508605186052860538605486055860568605786058860598606086061860628606386064860658606686067860688606986070860718607286073860748607586076860778607886079860808608186082860838608486085860868608786088860898609086091860928609386094860958609686097860988609986100861018610286103861048610586106861078610886109861108611186112861138611486115861168611786118861198612086121861228612386124861258612686127861288612986130861318613286133861348613586136861378613886139861408614186142861438614486145861468614786148861498615086151861528615386154861558615686157861588615986160861618616286163861648616586166861678616886169861708617186172861738617486175861768617786178861798618086181861828618386184861858618686187861888618986190861918619286193861948619586196861978619886199862008620186202862038620486205862068620786208862098621086211862128621386214862158621686217862188621986220862218622286223862248622586226862278622886229862308623186232862338623486235862368623786238862398624086241862428624386244862458624686247862488624986250862518625286253862548625586256862578625886259862608626186262862638626486265862668626786268862698627086271862728627386274862758627686277862788627986280862818628286283862848628586286862878628886289862908629186292862938629486295862968629786298862998630086301863028630386304863058630686307863088630986310863118631286313863148631586316863178631886319863208632186322863238632486325863268632786328863298633086331863328633386334863358633686337863388633986340863418634286343863448634586346863478634886349863508635186352863538635486355863568635786358863598636086361863628636386364863658636686367863688636986370863718637286373863748637586376863778637886379863808638186382863838638486385863868638786388863898639086391863928639386394863958639686397863988639986400864018640286403864048640586406864078640886409864108641186412864138641486415864168641786418864198642086421864228642386424864258642686427864288642986430864318643286433864348643586436864378643886439864408644186442864438644486445864468644786448864498645086451864528645386454864558645686457864588645986460864618646286463864648646586466864678646886469864708647186472864738647486475864768647786478864798648086481864828648386484864858648686487864888648986490864918649286493864948649586496864978649886499865008650186502865038650486505865068650786508865098651086511865128651386514865158651686517865188651986520865218652286523865248652586526865278652886529865308653186532865338653486535865368653786538865398654086541865428654386544865458654686547865488654986550865518655286553865548655586556865578655886559865608656186562865638656486565865668656786568865698657086571865728657386574865758657686577865788657986580865818658286583865848658586586865878658886589865908659186592865938659486595865968659786598865998660086601866028660386604866058660686607866088660986610866118661286613866148661586616866178661886619866208662186622866238662486625866268662786628866298663086631866328663386634866358663686637866388663986640866418664286643866448664586646866478664886649866508665186652866538665486655866568665786658866598666086661866628666386664866658666686667866688666986670866718667286673866748667586676866778667886679866808668186682866838668486685866868668786688866898669086691866928669386694866958669686697866988669986700867018670286703867048670586706867078670886709867108671186712867138671486715867168671786718867198672086721867228672386724867258672686727867288672986730867318673286733867348673586736867378673886739867408674186742867438674486745867468674786748867498675086751867528675386754867558675686757867588675986760867618676286763867648676586766867678676886769867708677186772867738677486775867768677786778867798678086781867828678386784867858678686787867888678986790867918679286793867948679586796867978679886799868008680186802868038680486805868068680786808868098681086811868128681386814868158681686817868188681986820868218682286823868248682586826868278682886829868308683186832868338683486835868368683786838868398684086841868428684386844868458684686847868488684986850868518685286853868548685586856868578685886859868608686186862868638686486865868668686786868868698687086871868728687386874868758687686877868788687986880868818688286883868848688586886868878688886889868908689186892868938689486895868968689786898868998690086901869028690386904869058690686907869088690986910869118691286913869148691586916869178691886919869208692186922869238692486925869268692786928869298693086931869328693386934869358693686937869388693986940869418694286943869448694586946869478694886949869508695186952869538695486955869568695786958869598696086961869628696386964869658696686967869688696986970869718697286973869748697586976869778697886979869808698186982869838698486985869868698786988869898699086991869928699386994869958699686997869988699987000870018700287003870048700587006870078700887009870108701187012870138701487015870168701787018870198702087021870228702387024870258702687027870288702987030870318703287033870348703587036870378703887039870408704187042870438704487045870468704787048870498705087051870528705387054870558705687057870588705987060870618706287063870648706587066870678706887069870708707187072870738707487075870768707787078870798708087081870828708387084870858708687087870888708987090870918709287093870948709587096870978709887099871008710187102871038710487105871068710787108871098711087111871128711387114871158711687117871188711987120871218712287123871248712587126871278712887129871308713187132871338713487135871368713787138871398714087141871428714387144871458714687147871488714987150871518715287153871548715587156871578715887159871608716187162871638716487165871668716787168871698717087171871728717387174871758717687177871788717987180871818718287183871848718587186871878718887189871908719187192871938719487195871968719787198871998720087201872028720387204872058720687207872088720987210872118721287213872148721587216872178721887219872208722187222872238722487225872268722787228872298723087231872328723387234872358723687237872388723987240872418724287243872448724587246872478724887249872508725187252872538725487255872568725787258872598726087261872628726387264872658726687267872688726987270872718727287273872748727587276872778727887279872808728187282872838728487285872868728787288872898729087291872928729387294872958729687297872988729987300873018730287303873048730587306873078730887309873108731187312873138731487315873168731787318873198732087321873228732387324873258732687327873288732987330873318733287333873348733587336873378733887339873408734187342873438734487345873468734787348873498735087351873528735387354873558735687357873588735987360873618736287363873648736587366873678736887369873708737187372873738737487375873768737787378873798738087381873828738387384873858738687387873888738987390873918739287393873948739587396873978739887399874008740187402874038740487405874068740787408874098741087411874128741387414874158741687417874188741987420874218742287423874248742587426874278742887429874308743187432874338743487435874368743787438874398744087441874428744387444874458744687447874488744987450874518745287453874548745587456874578745887459874608746187462874638746487465874668746787468874698747087471874728747387474874758747687477874788747987480874818748287483874848748587486874878748887489874908749187492874938749487495874968749787498874998750087501875028750387504875058750687507875088750987510875118751287513875148751587516875178751887519875208752187522875238752487525875268752787528875298753087531875328753387534875358753687537875388753987540875418754287543875448754587546875478754887549875508755187552875538755487555875568755787558875598756087561875628756387564875658756687567875688756987570875718757287573875748757587576875778757887579875808758187582875838758487585875868758787588875898759087591875928759387594875958759687597875988759987600876018760287603876048760587606876078760887609876108761187612876138761487615876168761787618876198762087621876228762387624876258762687627876288762987630876318763287633876348763587636876378763887639876408764187642876438764487645876468764787648876498765087651876528765387654876558765687657876588765987660876618766287663876648766587666876678766887669876708767187672876738767487675876768767787678876798768087681876828768387684876858768687687876888768987690876918769287693876948769587696876978769887699877008770187702877038770487705877068770787708877098771087711877128771387714877158771687717877188771987720877218772287723877248772587726877278772887729877308773187732877338773487735877368773787738877398774087741877428774387744877458774687747877488774987750877518775287753877548775587756877578775887759877608776187762877638776487765877668776787768877698777087771877728777387774877758777687777877788777987780877818778287783877848778587786877878778887789877908779187792877938779487795877968779787798877998780087801878028780387804878058780687807878088780987810878118781287813878148781587816878178781887819878208782187822878238782487825878268782787828878298783087831878328783387834878358783687837878388783987840878418784287843878448784587846878478784887849878508785187852878538785487855878568785787858878598786087861878628786387864878658786687867878688786987870878718787287873878748787587876878778787887879878808788187882878838788487885878868788787888878898789087891878928789387894878958789687897878988789987900879018790287903879048790587906879078790887909879108791187912879138791487915879168791787918879198792087921879228792387924879258792687927879288792987930879318793287933879348793587936879378793887939879408794187942879438794487945879468794787948879498795087951879528795387954879558795687957879588795987960879618796287963879648796587966879678796887969879708797187972879738797487975879768797787978879798798087981879828798387984879858798687987879888798987990879918799287993879948799587996879978799887999880008800188002880038800488005880068800788008880098801088011880128801388014880158801688017880188801988020880218802288023880248802588026880278802888029880308803188032880338803488035880368803788038880398804088041880428804388044880458804688047880488804988050880518805288053880548805588056880578805888059880608806188062880638806488065880668806788068880698807088071880728807388074880758807688077880788807988080880818808288083880848808588086880878808888089880908809188092880938809488095880968809788098880998810088101881028810388104881058810688107881088810988110881118811288113881148811588116881178811888119881208812188122881238812488125881268812788128881298813088131881328813388134881358813688137881388813988140881418814288143881448814588146881478814888149881508815188152881538815488155881568815788158881598816088161881628816388164881658816688167881688816988170881718817288173881748817588176881778817888179881808818188182881838818488185881868818788188881898819088191881928819388194881958819688197881988819988200882018820288203882048820588206882078820888209882108821188212882138821488215882168821788218882198822088221882228822388224882258822688227882288822988230882318823288233882348823588236882378823888239882408824188242882438824488245882468824788248882498825088251882528825388254882558825688257882588825988260882618826288263882648826588266882678826888269882708827188272882738827488275882768827788278882798828088281882828828388284882858828688287882888828988290882918829288293882948829588296882978829888299883008830188302883038830488305883068830788308883098831088311883128831388314883158831688317883188831988320883218832288323883248832588326883278832888329883308833188332883338833488335883368833788338883398834088341883428834388344883458834688347883488834988350883518835288353883548835588356883578835888359883608836188362883638836488365883668836788368883698837088371883728837388374883758837688377883788837988380883818838288383883848838588386883878838888389883908839188392883938839488395883968839788398883998840088401884028840388404884058840688407884088840988410884118841288413884148841588416884178841888419884208842188422884238842488425884268842788428884298843088431884328843388434884358843688437884388843988440884418844288443884448844588446884478844888449884508845188452884538845488455884568845788458884598846088461884628846388464884658846688467884688846988470884718847288473884748847588476884778847888479884808848188482884838848488485884868848788488884898849088491884928849388494884958849688497884988849988500885018850288503885048850588506885078850888509885108851188512885138851488515885168851788518885198852088521885228852388524885258852688527885288852988530885318853288533885348853588536885378853888539885408854188542885438854488545885468854788548885498855088551885528855388554885558855688557885588855988560885618856288563885648856588566885678856888569885708857188572885738857488575885768857788578885798858088581885828858388584885858858688587885888858988590885918859288593885948859588596885978859888599886008860188602886038860488605886068860788608886098861088611886128861388614886158861688617886188861988620886218862288623886248862588626886278862888629886308863188632886338863488635886368863788638886398864088641886428864388644886458864688647886488864988650886518865288653886548865588656886578865888659886608866188662886638866488665886668866788668886698867088671886728867388674886758867688677886788867988680886818868288683886848868588686886878868888689886908869188692886938869488695886968869788698886998870088701887028870388704887058870688707887088870988710887118871288713887148871588716887178871888719887208872188722887238872488725887268872788728887298873088731887328873388734887358873688737887388873988740887418874288743887448874588746887478874888749887508875188752887538875488755887568875788758887598876088761887628876388764887658876688767887688876988770887718877288773887748877588776887778877888779887808878188782887838878488785887868878788788887898879088791887928879388794887958879688797887988879988800888018880288803888048880588806888078880888809888108881188812888138881488815888168881788818888198882088821888228882388824888258882688827888288882988830888318883288833888348883588836888378883888839888408884188842888438884488845888468884788848888498885088851888528885388854888558885688857888588885988860888618886288863888648886588866888678886888869888708887188872888738887488875888768887788878888798888088881888828888388884888858888688887888888888988890888918889288893888948889588896888978889888899889008890188902889038890488905889068890788908889098891088911889128891388914889158891688917889188891988920889218892288923889248892588926889278892888929889308893188932889338893488935889368893788938889398894088941889428894388944889458894688947889488894988950889518895288953889548895588956889578895888959889608896188962889638896488965889668896788968889698897088971889728897388974889758897688977889788897988980889818898288983889848898588986889878898888989889908899188992889938899488995889968899788998889998900089001890028900389004890058900689007890088900989010890118901289013890148901589016890178901889019890208902189022890238902489025890268902789028890298903089031890328903389034890358903689037890388903989040890418904289043890448904589046890478904889049890508905189052890538905489055890568905789058890598906089061890628906389064890658906689067890688906989070890718907289073890748907589076890778907889079890808908189082890838908489085890868908789088890898909089091890928909389094890958909689097890988909989100891018910289103891048910589106891078910889109891108911189112891138911489115891168911789118891198912089121891228912389124891258912689127891288912989130891318913289133891348913589136891378913889139891408914189142891438914489145891468914789148891498915089151891528915389154891558915689157891588915989160891618916289163891648916589166891678916889169891708917189172891738917489175891768917789178891798918089181891828918389184891858918689187891888918989190891918919289193891948919589196891978919889199892008920189202892038920489205892068920789208892098921089211892128921389214892158921689217892188921989220892218922289223892248922589226892278922889229892308923189232892338923489235892368923789238892398924089241892428924389244892458924689247892488924989250892518925289253892548925589256892578925889259892608926189262892638926489265892668926789268892698927089271892728927389274892758927689277892788927989280892818928289283892848928589286892878928889289892908929189292892938929489295892968929789298892998930089301893028930389304893058930689307893088930989310893118931289313893148931589316893178931889319893208932189322893238932489325893268932789328893298933089331893328933389334893358933689337893388933989340893418934289343893448934589346893478934889349893508935189352893538935489355893568935789358893598936089361893628936389364893658936689367893688936989370893718937289373893748937589376893778937889379893808938189382893838938489385893868938789388893898939089391893928939389394893958939689397893988939989400894018940289403894048940589406894078940889409894108941189412894138941489415894168941789418894198942089421894228942389424894258942689427894288942989430894318943289433894348943589436894378943889439894408944189442894438944489445894468944789448894498945089451894528945389454894558945689457894588945989460894618946289463894648946589466894678946889469894708947189472894738947489475894768947789478894798948089481894828948389484894858948689487894888948989490894918949289493894948949589496894978949889499895008950189502895038950489505895068950789508895098951089511895128951389514895158951689517895188951989520895218952289523895248952589526895278952889529895308953189532895338953489535895368953789538895398954089541895428954389544895458954689547895488954989550895518955289553895548955589556895578955889559895608956189562895638956489565895668956789568895698957089571895728957389574895758957689577895788957989580895818958289583895848958589586895878958889589895908959189592895938959489595895968959789598895998960089601896028960389604896058960689607896088960989610896118961289613896148961589616896178961889619896208962189622896238962489625896268962789628896298963089631896328963389634896358963689637896388963989640896418964289643896448964589646896478964889649896508965189652896538965489655896568965789658896598966089661896628966389664896658966689667896688966989670896718967289673896748967589676896778967889679896808968189682896838968489685896868968789688896898969089691896928969389694896958969689697896988969989700897018970289703897048970589706897078970889709897108971189712897138971489715897168971789718897198972089721897228972389724897258972689727897288972989730897318973289733897348973589736897378973889739897408974189742897438974489745897468974789748897498975089751897528975389754897558975689757897588975989760897618976289763897648976589766897678976889769897708977189772897738977489775897768977789778897798978089781897828978389784897858978689787897888978989790897918979289793897948979589796897978979889799898008980189802898038980489805898068980789808898098981089811898128981389814898158981689817898188981989820898218982289823898248982589826898278982889829898308983189832898338983489835898368983789838898398984089841898428984389844898458984689847898488984989850898518985289853898548985589856898578985889859898608986189862898638986489865898668986789868898698987089871898728987389874898758987689877898788987989880898818988289883898848988589886898878988889889898908989189892898938989489895898968989789898898998990089901899028990389904899058990689907899088990989910899118991289913899148991589916899178991889919899208992189922899238992489925899268992789928899298993089931899328993389934899358993689937899388993989940899418994289943899448994589946899478994889949899508995189952899538995489955899568995789958899598996089961899628996389964899658996689967899688996989970899718997289973899748997589976899778997889979899808998189982899838998489985899868998789988899898999089991899928999389994899958999689997899988999990000900019000290003900049000590006900079000890009900109001190012900139001490015900169001790018900199002090021900229002390024900259002690027900289002990030900319003290033900349003590036900379003890039900409004190042900439004490045900469004790048900499005090051900529005390054900559005690057900589005990060900619006290063900649006590066900679006890069900709007190072900739007490075900769007790078900799008090081900829008390084900859008690087900889008990090900919009290093900949009590096900979009890099901009010190102901039010490105901069010790108901099011090111901129011390114901159011690117901189011990120901219012290123901249012590126901279012890129901309013190132901339013490135901369013790138901399014090141901429014390144901459014690147901489014990150901519015290153901549015590156901579015890159901609016190162901639016490165901669016790168901699017090171901729017390174901759017690177901789017990180901819018290183901849018590186901879018890189901909019190192901939019490195901969019790198901999020090201902029020390204902059020690207902089020990210902119021290213902149021590216902179021890219902209022190222902239022490225902269022790228902299023090231902329023390234902359023690237902389023990240902419024290243902449024590246902479024890249902509025190252902539025490255902569025790258902599026090261902629026390264902659026690267902689026990270902719027290273902749027590276902779027890279902809028190282902839028490285902869028790288902899029090291902929029390294902959029690297902989029990300903019030290303903049030590306903079030890309903109031190312903139031490315903169031790318903199032090321903229032390324903259032690327903289032990330903319033290333903349033590336903379033890339903409034190342903439034490345903469034790348903499035090351903529035390354903559035690357903589035990360903619036290363903649036590366903679036890369903709037190372903739037490375903769037790378903799038090381903829038390384903859038690387903889038990390903919039290393903949039590396903979039890399904009040190402904039040490405904069040790408904099041090411904129041390414904159041690417904189041990420904219042290423904249042590426904279042890429904309043190432904339043490435904369043790438904399044090441904429044390444904459044690447904489044990450904519045290453904549045590456904579045890459904609046190462904639046490465904669046790468904699047090471904729047390474904759047690477904789047990480904819048290483904849048590486904879048890489904909049190492904939049490495904969049790498904999050090501905029050390504905059050690507905089050990510905119051290513905149051590516905179051890519905209052190522905239052490525905269052790528905299053090531905329053390534905359053690537905389053990540905419054290543905449054590546905479054890549905509055190552905539055490555905569055790558905599056090561905629056390564905659056690567905689056990570905719057290573905749057590576905779057890579905809058190582905839058490585905869058790588905899059090591905929059390594905959059690597905989059990600906019060290603906049060590606906079060890609906109061190612906139061490615906169061790618906199062090621906229062390624906259062690627906289062990630906319063290633906349063590636906379063890639906409064190642906439064490645906469064790648906499065090651906529065390654906559065690657906589065990660906619066290663906649066590666906679066890669906709067190672906739067490675906769067790678906799068090681906829068390684906859068690687906889068990690906919069290693906949069590696906979069890699907009070190702907039070490705907069070790708907099071090711907129071390714907159071690717907189071990720907219072290723907249072590726907279072890729907309073190732907339073490735907369073790738907399074090741907429074390744907459074690747907489074990750907519075290753907549075590756907579075890759907609076190762907639076490765907669076790768907699077090771907729077390774907759077690777907789077990780907819078290783907849078590786907879078890789907909079190792907939079490795907969079790798907999080090801908029080390804908059080690807908089080990810908119081290813908149081590816908179081890819908209082190822908239082490825908269082790828908299083090831908329083390834908359083690837908389083990840908419084290843908449084590846908479084890849908509085190852908539085490855908569085790858908599086090861908629086390864908659086690867908689086990870908719087290873908749087590876908779087890879908809088190882908839088490885908869088790888908899089090891908929089390894908959089690897908989089990900909019090290903909049090590906909079090890909909109091190912909139091490915909169091790918909199092090921909229092390924909259092690927909289092990930909319093290933909349093590936909379093890939909409094190942909439094490945909469094790948909499095090951909529095390954909559095690957909589095990960909619096290963909649096590966909679096890969909709097190972909739097490975909769097790978909799098090981909829098390984909859098690987909889098990990909919099290993909949099590996909979099890999910009100191002910039100491005910069100791008910099101091011910129101391014910159101691017910189101991020910219102291023910249102591026910279102891029910309103191032910339103491035910369103791038910399104091041910429104391044910459104691047910489104991050910519105291053910549105591056910579105891059910609106191062910639106491065910669106791068910699107091071910729107391074910759107691077910789107991080910819108291083910849108591086910879108891089910909109191092910939109491095910969109791098910999110091101911029110391104911059110691107911089110991110911119111291113911149111591116911179111891119911209112191122911239112491125911269112791128911299113091131911329113391134911359113691137911389113991140911419114291143911449114591146911479114891149911509115191152911539115491155911569115791158911599116091161911629116391164911659116691167911689116991170911719117291173911749117591176911779117891179911809118191182911839118491185911869118791188911899119091191911929119391194911959119691197911989119991200912019120291203912049120591206912079120891209912109121191212912139121491215912169121791218912199122091221912229122391224912259122691227912289122991230912319123291233912349123591236912379123891239912409124191242912439124491245912469124791248912499125091251912529125391254912559125691257912589125991260912619126291263912649126591266912679126891269912709127191272912739127491275912769127791278912799128091281912829128391284912859128691287912889128991290912919129291293912949129591296912979129891299913009130191302913039130491305913069130791308913099131091311913129131391314913159131691317913189131991320913219132291323913249132591326913279132891329913309133191332913339133491335913369133791338913399134091341913429134391344913459134691347913489134991350913519135291353913549135591356913579135891359913609136191362913639136491365913669136791368913699137091371913729137391374913759137691377913789137991380913819138291383913849138591386913879138891389913909139191392913939139491395913969139791398913999140091401914029140391404914059140691407914089140991410914119141291413914149141591416914179141891419914209142191422914239142491425914269142791428914299143091431914329143391434914359143691437914389143991440914419144291443914449144591446914479144891449914509145191452914539145491455914569145791458914599146091461914629146391464914659146691467914689146991470914719147291473914749147591476914779147891479914809148191482914839148491485914869148791488914899149091491914929149391494914959149691497914989149991500915019150291503915049150591506915079150891509915109151191512915139151491515915169151791518915199152091521915229152391524915259152691527915289152991530915319153291533915349153591536915379153891539915409154191542915439154491545915469154791548915499155091551915529155391554915559155691557915589155991560915619156291563915649156591566915679156891569915709157191572915739157491575915769157791578915799158091581915829158391584915859158691587915889158991590915919159291593915949159591596915979159891599916009160191602916039160491605916069160791608916099161091611916129161391614916159161691617916189161991620916219162291623916249162591626916279162891629916309163191632916339163491635916369163791638916399164091641916429164391644916459164691647916489164991650916519165291653916549165591656916579165891659916609166191662916639166491665916669166791668916699167091671916729167391674916759167691677916789167991680916819168291683916849168591686916879168891689916909169191692916939169491695916969169791698916999170091701917029170391704917059170691707917089170991710917119171291713917149171591716917179171891719917209172191722917239172491725917269172791728917299173091731917329173391734917359173691737917389173991740917419174291743917449174591746917479174891749917509175191752917539175491755917569175791758917599176091761917629176391764917659176691767917689176991770917719177291773917749177591776917779177891779917809178191782917839178491785917869178791788917899179091791917929179391794917959179691797917989179991800918019180291803918049180591806918079180891809918109181191812918139181491815918169181791818918199182091821918229182391824918259182691827918289182991830918319183291833918349183591836918379183891839918409184191842918439184491845918469184791848918499185091851918529185391854918559185691857918589185991860918619186291863918649186591866918679186891869918709187191872918739187491875918769187791878918799188091881918829188391884918859188691887918889188991890918919189291893918949189591896918979189891899919009190191902919039190491905919069190791908919099191091911919129191391914919159191691917919189191991920919219192291923919249192591926919279192891929919309193191932919339193491935919369193791938919399194091941919429194391944919459194691947919489194991950919519195291953919549195591956919579195891959919609196191962919639196491965919669196791968919699197091971919729197391974919759197691977919789197991980919819198291983919849198591986919879198891989919909199191992919939199491995919969199791998919999200092001920029200392004920059200692007920089200992010920119201292013920149201592016920179201892019920209202192022920239202492025920269202792028920299203092031920329203392034920359203692037920389203992040920419204292043920449204592046920479204892049920509205192052920539205492055920569205792058920599206092061920629206392064920659206692067920689206992070920719207292073920749207592076920779207892079920809208192082920839208492085920869208792088920899209092091920929209392094920959209692097920989209992100921019210292103921049210592106921079210892109921109211192112921139211492115921169211792118921199212092121921229212392124921259212692127921289212992130921319213292133921349213592136921379213892139921409214192142921439214492145921469214792148921499215092151921529215392154921559215692157921589215992160921619216292163921649216592166921679216892169921709217192172921739217492175921769217792178921799218092181921829218392184921859218692187921889218992190921919219292193921949219592196921979219892199922009220192202922039220492205922069220792208922099221092211922129221392214922159221692217922189221992220922219222292223922249222592226922279222892229922309223192232922339223492235922369223792238922399224092241922429224392244922459224692247922489224992250922519225292253922549225592256922579225892259922609226192262922639226492265922669226792268922699227092271922729227392274922759227692277922789227992280922819228292283922849228592286922879228892289922909229192292922939229492295922969229792298922999230092301923029230392304923059230692307923089230992310923119231292313923149231592316923179231892319923209232192322923239232492325923269232792328923299233092331923329233392334923359233692337923389233992340923419234292343923449234592346923479234892349923509235192352923539235492355923569235792358923599236092361923629236392364923659236692367923689236992370923719237292373923749237592376923779237892379923809238192382923839238492385923869238792388923899239092391923929239392394923959239692397923989239992400924019240292403924049240592406924079240892409924109241192412924139241492415924169241792418924199242092421924229242392424924259242692427924289242992430924319243292433924349243592436924379243892439924409244192442924439244492445924469244792448924499245092451924529245392454924559245692457924589245992460924619246292463924649246592466924679246892469924709247192472924739247492475924769247792478924799248092481924829248392484924859248692487924889248992490924919249292493924949249592496924979249892499925009250192502925039250492505925069250792508925099251092511925129251392514925159251692517925189251992520925219252292523925249252592526925279252892529925309253192532925339253492535925369253792538925399254092541925429254392544925459254692547925489254992550925519255292553925549255592556925579255892559925609256192562925639256492565925669256792568925699257092571925729257392574925759257692577925789257992580925819258292583925849258592586925879258892589925909259192592925939259492595925969259792598925999260092601926029260392604926059260692607926089260992610926119261292613926149261592616926179261892619926209262192622926239262492625926269262792628926299263092631926329263392634926359263692637926389263992640926419264292643926449264592646926479264892649926509265192652926539265492655926569265792658926599266092661926629266392664926659266692667926689266992670926719267292673926749267592676926779267892679926809268192682926839268492685926869268792688926899269092691926929269392694926959269692697926989269992700927019270292703927049270592706927079270892709927109271192712927139271492715927169271792718927199272092721927229272392724927259272692727927289272992730927319273292733927349273592736927379273892739927409274192742927439274492745927469274792748927499275092751927529275392754927559275692757927589275992760927619276292763927649276592766927679276892769927709277192772927739277492775927769277792778927799278092781927829278392784927859278692787927889278992790927919279292793927949279592796927979279892799928009280192802928039280492805928069280792808928099281092811928129281392814928159281692817928189281992820928219282292823928249282592826928279282892829928309283192832928339283492835928369283792838928399284092841928429284392844928459284692847928489284992850928519285292853928549285592856928579285892859928609286192862928639286492865928669286792868928699287092871928729287392874928759287692877928789287992880928819288292883928849288592886928879288892889928909289192892928939289492895928969289792898928999290092901929029290392904929059290692907929089290992910929119291292913929149291592916929179291892919929209292192922929239292492925929269292792928929299293092931929329293392934929359293692937929389293992940929419294292943929449294592946929479294892949929509295192952929539295492955929569295792958929599296092961929629296392964929659296692967929689296992970929719297292973929749297592976929779297892979929809298192982929839298492985929869298792988929899299092991929929299392994929959299692997929989299993000930019300293003930049300593006930079300893009930109301193012930139301493015930169301793018930199302093021930229302393024930259302693027930289302993030930319303293033930349303593036930379303893039930409304193042930439304493045930469304793048930499305093051930529305393054930559305693057930589305993060930619306293063930649306593066930679306893069930709307193072930739307493075930769307793078930799308093081930829308393084930859308693087930889308993090930919309293093930949309593096930979309893099931009310193102931039310493105931069310793108931099311093111931129311393114931159311693117931189311993120931219312293123931249312593126931279312893129931309313193132931339313493135931369313793138931399314093141931429314393144931459314693147931489314993150931519315293153931549315593156931579315893159931609316193162931639316493165931669316793168931699317093171931729317393174931759317693177931789317993180931819318293183931849318593186931879318893189931909319193192931939319493195931969319793198931999320093201932029320393204932059320693207932089320993210932119321293213932149321593216932179321893219932209322193222932239322493225932269322793228932299323093231932329323393234932359323693237932389323993240932419324293243932449324593246932479324893249932509325193252932539325493255932569325793258932599326093261932629326393264932659326693267932689326993270932719327293273932749327593276932779327893279932809328193282932839328493285932869328793288932899329093291932929329393294932959329693297932989329993300933019330293303933049330593306933079330893309933109331193312933139331493315933169331793318933199332093321933229332393324933259332693327933289332993330933319333293333933349333593336933379333893339933409334193342933439334493345933469334793348933499335093351933529335393354933559335693357933589335993360933619336293363933649336593366933679336893369933709337193372933739337493375933769337793378933799338093381933829338393384933859338693387933889338993390933919339293393933949339593396933979339893399934009340193402934039340493405934069340793408934099341093411934129341393414934159341693417934189341993420934219342293423934249342593426934279342893429934309343193432934339343493435934369343793438934399344093441934429344393444934459344693447934489344993450934519345293453934549345593456934579345893459934609346193462934639346493465934669346793468934699347093471934729347393474934759347693477934789347993480934819348293483934849348593486934879348893489934909349193492934939349493495934969349793498934999350093501935029350393504935059350693507935089350993510935119351293513935149351593516935179351893519935209352193522935239352493525935269352793528935299353093531935329353393534935359353693537935389353993540935419354293543935449354593546935479354893549935509355193552935539355493555935569355793558935599356093561935629356393564935659356693567935689356993570935719357293573935749357593576935779357893579935809358193582935839358493585935869358793588935899359093591935929359393594935959359693597935989359993600936019360293603936049360593606936079360893609936109361193612936139361493615936169361793618936199362093621936229362393624936259362693627936289362993630936319363293633936349363593636936379363893639936409364193642936439364493645936469364793648936499365093651936529365393654936559365693657936589365993660936619366293663936649366593666936679366893669936709367193672936739367493675936769367793678936799368093681936829368393684936859368693687936889368993690936919369293693936949369593696936979369893699937009370193702937039370493705937069370793708937099371093711937129371393714937159371693717937189371993720937219372293723937249372593726937279372893729937309373193732937339373493735937369373793738937399374093741937429374393744937459374693747937489374993750937519375293753937549375593756937579375893759937609376193762937639376493765937669376793768937699377093771937729377393774937759377693777937789377993780937819378293783937849378593786937879378893789937909379193792937939379493795937969379793798937999380093801938029380393804938059380693807938089380993810938119381293813938149381593816938179381893819938209382193822938239382493825938269382793828938299383093831938329383393834938359383693837938389383993840938419384293843938449384593846938479384893849938509385193852938539385493855938569385793858938599386093861938629386393864938659386693867938689386993870938719387293873938749387593876938779387893879938809388193882938839388493885938869388793888938899389093891938929389393894938959389693897938989389993900939019390293903939049390593906939079390893909939109391193912939139391493915939169391793918939199392093921939229392393924939259392693927939289392993930939319393293933939349393593936939379393893939939409394193942939439394493945939469394793948939499395093951939529395393954939559395693957939589395993960939619396293963939649396593966939679396893969939709397193972939739397493975939769397793978939799398093981939829398393984939859398693987939889398993990939919399293993939949399593996939979399893999940009400194002940039400494005940069400794008940099401094011940129401394014940159401694017940189401994020940219402294023940249402594026940279402894029940309403194032940339403494035940369403794038940399404094041940429404394044940459404694047940489404994050940519405294053940549405594056940579405894059940609406194062940639406494065940669406794068940699407094071940729407394074940759407694077940789407994080940819408294083940849408594086940879408894089940909409194092940939409494095940969409794098940999410094101941029410394104941059410694107941089410994110941119411294113941149411594116941179411894119941209412194122941239412494125941269412794128941299413094131941329413394134941359413694137941389413994140941419414294143941449414594146941479414894149941509415194152941539415494155941569415794158941599416094161941629416394164941659416694167941689416994170941719417294173941749417594176941779417894179941809418194182941839418494185941869418794188941899419094191941929419394194941959419694197941989419994200942019420294203942049420594206942079420894209942109421194212942139421494215942169421794218942199422094221942229422394224942259422694227942289422994230942319423294233942349423594236942379423894239942409424194242942439424494245942469424794248942499425094251942529425394254942559425694257942589425994260942619426294263942649426594266942679426894269942709427194272942739427494275942769427794278942799428094281942829428394284942859428694287942889428994290942919429294293942949429594296942979429894299943009430194302943039430494305943069430794308943099431094311943129431394314943159431694317943189431994320943219432294323943249432594326943279432894329943309433194332943339433494335943369433794338943399434094341943429434394344943459434694347943489434994350943519435294353943549435594356943579435894359943609436194362943639436494365943669436794368943699437094371943729437394374943759437694377943789437994380943819438294383943849438594386943879438894389943909439194392943939439494395943969439794398943999440094401944029440394404944059440694407944089440994410944119441294413944149441594416944179441894419944209442194422944239442494425944269442794428944299443094431944329443394434944359443694437944389443994440944419444294443944449444594446944479444894449944509445194452944539445494455944569445794458944599446094461944629446394464944659446694467944689446994470944719447294473944749447594476944779447894479944809448194482944839448494485944869448794488944899449094491944929449394494944959449694497944989449994500945019450294503945049450594506945079450894509945109451194512945139451494515945169451794518945199452094521945229452394524945259452694527945289452994530945319453294533945349453594536945379453894539945409454194542945439454494545945469454794548945499455094551945529455394554945559455694557945589455994560945619456294563945649456594566945679456894569945709457194572945739457494575945769457794578945799458094581945829458394584945859458694587945889458994590945919459294593945949459594596945979459894599946009460194602946039460494605946069460794608946099461094611946129461394614946159461694617946189461994620946219462294623946249462594626946279462894629946309463194632946339463494635946369463794638946399464094641946429464394644946459464694647946489464994650946519465294653946549465594656946579465894659946609466194662946639466494665946669466794668946699467094671946729467394674946759467694677946789467994680946819468294683946849468594686946879468894689946909469194692946939469494695946969469794698946999470094701947029470394704947059470694707947089470994710947119471294713947149471594716947179471894719947209472194722947239472494725947269472794728947299473094731947329473394734947359473694737947389473994740947419474294743947449474594746947479474894749947509475194752947539475494755947569475794758947599476094761947629476394764947659476694767947689476994770947719477294773947749477594776947779477894779947809478194782947839478494785947869478794788947899479094791947929479394794947959479694797947989479994800948019480294803948049480594806948079480894809948109481194812948139481494815948169481794818948199482094821948229482394824948259482694827948289482994830948319483294833948349483594836948379483894839948409484194842948439484494845948469484794848948499485094851948529485394854948559485694857948589485994860948619486294863948649486594866948679486894869948709487194872948739487494875948769487794878948799488094881948829488394884948859488694887948889488994890948919489294893948949489594896948979489894899949009490194902949039490494905949069490794908949099491094911949129491394914949159491694917949189491994920949219492294923949249492594926949279492894929949309493194932949339493494935949369493794938949399494094941949429494394944949459494694947949489494994950949519495294953949549495594956949579495894959949609496194962949639496494965949669496794968949699497094971949729497394974949759497694977949789497994980949819498294983949849498594986949879498894989949909499194992949939499494995949969499794998949999500095001950029500395004950059500695007950089500995010950119501295013950149501595016950179501895019950209502195022950239502495025950269502795028950299503095031950329503395034950359503695037950389503995040950419504295043950449504595046950479504895049950509505195052950539505495055950569505795058950599506095061950629506395064950659506695067950689506995070950719507295073950749507595076950779507895079950809508195082950839508495085950869508795088950899509095091950929509395094950959509695097950989509995100951019510295103951049510595106951079510895109951109511195112951139511495115951169511795118951199512095121951229512395124951259512695127951289512995130951319513295133951349513595136951379513895139951409514195142951439514495145951469514795148951499515095151951529515395154951559515695157951589515995160951619516295163951649516595166951679516895169951709517195172951739517495175951769517795178951799518095181951829518395184951859518695187951889518995190951919519295193951949519595196951979519895199952009520195202952039520495205952069520795208952099521095211952129521395214952159521695217952189521995220952219522295223952249522595226952279522895229952309523195232952339523495235952369523795238952399524095241952429524395244952459524695247952489524995250952519525295253952549525595256952579525895259952609526195262952639526495265952669526795268952699527095271952729527395274952759527695277952789527995280952819528295283952849528595286952879528895289952909529195292952939529495295952969529795298952999530095301953029530395304953059530695307953089530995310953119531295313953149531595316953179531895319953209532195322953239532495325953269532795328953299533095331953329533395334953359533695337953389533995340953419534295343953449534595346953479534895349953509535195352953539535495355953569535795358953599536095361953629536395364953659536695367953689536995370953719537295373953749537595376953779537895379953809538195382953839538495385953869538795388953899539095391953929539395394953959539695397953989539995400954019540295403954049540595406954079540895409954109541195412954139541495415954169541795418954199542095421954229542395424954259542695427954289542995430954319543295433954349543595436954379543895439954409544195442954439544495445954469544795448954499545095451954529545395454954559545695457954589545995460954619546295463954649546595466954679546895469954709547195472954739547495475954769547795478954799548095481954829548395484954859548695487954889548995490954919549295493954949549595496954979549895499955009550195502955039550495505955069550795508955099551095511955129551395514955159551695517955189551995520955219552295523955249552595526955279552895529955309553195532955339553495535955369553795538955399554095541955429554395544955459554695547955489554995550955519555295553955549555595556955579555895559955609556195562955639556495565955669556795568955699557095571955729557395574955759557695577955789557995580955819558295583955849558595586955879558895589955909559195592955939559495595955969559795598955999560095601956029560395604956059560695607956089560995610956119561295613956149561595616956179561895619956209562195622956239562495625956269562795628956299563095631956329563395634956359563695637956389563995640956419564295643956449564595646956479564895649956509565195652956539565495655956569565795658956599566095661956629566395664956659566695667956689566995670956719567295673956749567595676956779567895679956809568195682956839568495685956869568795688956899569095691956929569395694956959569695697956989569995700957019570295703957049570595706957079570895709957109571195712957139571495715957169571795718957199572095721957229572395724957259572695727957289572995730957319573295733957349573595736957379573895739957409574195742957439574495745957469574795748957499575095751957529575395754957559575695757957589575995760957619576295763957649576595766957679576895769957709577195772957739577495775957769577795778957799578095781957829578395784957859578695787957889578995790957919579295793957949579595796957979579895799958009580195802958039580495805958069580795808958099581095811958129581395814958159581695817958189581995820958219582295823958249582595826958279582895829958309583195832958339583495835958369583795838958399584095841958429584395844958459584695847958489584995850958519585295853958549585595856958579585895859958609586195862958639586495865958669586795868958699587095871958729587395874958759587695877958789587995880958819588295883958849588595886958879588895889958909589195892958939589495895958969589795898958999590095901959029590395904959059590695907959089590995910959119591295913959149591595916959179591895919959209592195922959239592495925959269592795928959299593095931959329593395934959359593695937959389593995940959419594295943959449594595946959479594895949959509595195952959539595495955959569595795958959599596095961959629596395964959659596695967959689596995970959719597295973959749597595976959779597895979959809598195982959839598495985959869598795988959899599095991959929599395994959959599695997959989599996000960019600296003960049600596006960079600896009960109601196012960139601496015960169601796018960199602096021960229602396024960259602696027960289602996030960319603296033960349603596036960379603896039960409604196042960439604496045960469604796048960499605096051960529605396054960559605696057960589605996060960619606296063960649606596066960679606896069960709607196072960739607496075960769607796078960799608096081960829608396084960859608696087960889608996090960919609296093960949609596096960979609896099961009610196102961039610496105961069610796108961099611096111961129611396114961159611696117961189611996120961219612296123961249612596126961279612896129961309613196132961339613496135961369613796138961399614096141961429614396144961459614696147961489614996150961519615296153961549615596156961579615896159961609616196162961639616496165961669616796168961699617096171961729617396174961759617696177961789617996180961819618296183961849618596186961879618896189961909619196192961939619496195961969619796198961999620096201962029620396204962059620696207962089620996210962119621296213962149621596216962179621896219962209622196222962239622496225962269622796228962299623096231962329623396234962359623696237962389623996240962419624296243962449624596246962479624896249962509625196252962539625496255962569625796258962599626096261962629626396264962659626696267962689626996270962719627296273962749627596276962779627896279962809628196282962839628496285962869628796288962899629096291962929629396294962959629696297962989629996300963019630296303963049630596306963079630896309963109631196312963139631496315963169631796318963199632096321963229632396324963259632696327963289632996330963319633296333963349633596336963379633896339963409634196342963439634496345963469634796348963499635096351963529635396354963559635696357963589635996360963619636296363963649636596366963679636896369963709637196372963739637496375963769637796378963799638096381963829638396384963859638696387963889638996390963919639296393963949639596396963979639896399964009640196402964039640496405964069640796408964099641096411964129641396414964159641696417964189641996420964219642296423964249642596426964279642896429964309643196432964339643496435964369643796438964399644096441964429644396444964459644696447964489644996450964519645296453964549645596456964579645896459964609646196462964639646496465964669646796468964699647096471964729647396474964759647696477964789647996480964819648296483964849648596486964879648896489964909649196492964939649496495964969649796498964999650096501965029650396504965059650696507965089650996510965119651296513965149651596516965179651896519965209652196522965239652496525965269652796528965299653096531965329653396534965359653696537965389653996540965419654296543965449654596546965479654896549965509655196552965539655496555965569655796558965599656096561965629656396564965659656696567965689656996570965719657296573965749657596576965779657896579965809658196582965839658496585965869658796588965899659096591965929659396594965959659696597965989659996600966019660296603966049660596606966079660896609966109661196612966139661496615966169661796618966199662096621966229662396624966259662696627966289662996630966319663296633966349663596636966379663896639966409664196642966439664496645966469664796648966499665096651966529665396654966559665696657966589665996660966619666296663966649666596666966679666896669966709667196672966739667496675966769667796678966799668096681966829668396684966859668696687966889668996690966919669296693966949669596696966979669896699967009670196702967039670496705967069670796708967099671096711967129671396714967159671696717967189671996720967219672296723967249672596726967279672896729967309673196732967339673496735967369673796738967399674096741967429674396744967459674696747967489674996750967519675296753967549675596756967579675896759967609676196762967639676496765967669676796768967699677096771967729677396774967759677696777967789677996780967819678296783967849678596786967879678896789967909679196792967939679496795967969679796798967999680096801968029680396804968059680696807968089680996810968119681296813968149681596816968179681896819968209682196822968239682496825968269682796828968299683096831968329683396834968359683696837968389683996840968419684296843968449684596846968479684896849968509685196852968539685496855968569685796858968599686096861968629686396864968659686696867968689686996870968719687296873968749687596876968779687896879968809688196882968839688496885968869688796888968899689096891968929689396894968959689696897968989689996900969019690296903969049690596906969079690896909969109691196912969139691496915969169691796918969199692096921969229692396924969259692696927969289692996930969319693296933969349693596936969379693896939969409694196942969439694496945969469694796948969499695096951969529695396954969559695696957969589695996960969619696296963969649696596966969679696896969969709697196972969739697496975969769697796978969799698096981969829698396984969859698696987969889698996990969919699296993969949699596996969979699896999970009700197002970039700497005970069700797008970099701097011970129701397014970159701697017970189701997020970219702297023970249702597026970279702897029970309703197032970339703497035970369703797038970399704097041970429704397044970459704697047970489704997050970519705297053970549705597056970579705897059970609706197062970639706497065970669706797068970699707097071970729707397074970759707697077970789707997080970819708297083970849708597086970879708897089970909709197092970939709497095970969709797098970999710097101971029710397104971059710697107971089710997110971119711297113971149711597116971179711897119971209712197122971239712497125971269712797128971299713097131971329713397134971359713697137971389713997140971419714297143971449714597146971479714897149971509715197152971539715497155971569715797158971599716097161971629716397164971659716697167971689716997170971719717297173971749717597176971779717897179971809718197182971839718497185971869718797188971899719097191971929719397194971959719697197971989719997200972019720297203972049720597206972079720897209972109721197212972139721497215972169721797218972199722097221972229722397224972259722697227972289722997230972319723297233972349723597236972379723897239972409724197242972439724497245972469724797248972499725097251972529725397254972559725697257972589725997260972619726297263972649726597266972679726897269972709727197272972739727497275972769727797278972799728097281972829728397284972859728697287972889728997290972919729297293972949729597296972979729897299973009730197302973039730497305973069730797308973099731097311973129731397314973159731697317973189731997320973219732297323973249732597326973279732897329973309733197332973339733497335973369733797338973399734097341973429734397344973459734697347973489734997350973519735297353973549735597356973579735897359973609736197362973639736497365973669736797368973699737097371973729737397374973759737697377973789737997380973819738297383973849738597386973879738897389973909739197392973939739497395973969739797398973999740097401974029740397404974059740697407974089740997410974119741297413974149741597416974179741897419974209742197422974239742497425974269742797428974299743097431974329743397434974359743697437974389743997440974419744297443974449744597446974479744897449974509745197452974539745497455974569745797458974599746097461974629746397464974659746697467974689746997470974719747297473974749747597476974779747897479974809748197482974839748497485974869748797488974899749097491974929749397494974959749697497974989749997500975019750297503975049750597506975079750897509975109751197512975139751497515975169751797518975199752097521975229752397524975259752697527975289752997530975319753297533975349753597536975379753897539975409754197542975439754497545975469754797548975499755097551975529755397554975559755697557975589755997560975619756297563975649756597566975679756897569975709757197572975739757497575975769757797578975799758097581975829758397584975859758697587975889758997590975919759297593975949759597596975979759897599976009760197602976039760497605976069760797608976099761097611976129761397614976159761697617976189761997620976219762297623976249762597626976279762897629976309763197632976339763497635976369763797638976399764097641976429764397644976459764697647976489764997650976519765297653976549765597656976579765897659976609766197662976639766497665976669766797668976699767097671976729767397674976759767697677976789767997680976819768297683976849768597686976879768897689976909769197692976939769497695976969769797698976999770097701977029770397704977059770697707977089770997710977119771297713977149771597716977179771897719977209772197722977239772497725977269772797728977299773097731977329773397734977359773697737977389773997740977419774297743977449774597746977479774897749977509775197752977539775497755977569775797758977599776097761977629776397764977659776697767977689776997770977719777297773977749777597776977779777897779977809778197782977839778497785977869778797788977899779097791977929779397794977959779697797977989779997800978019780297803978049780597806978079780897809978109781197812978139781497815978169781797818978199782097821978229782397824978259782697827978289782997830978319783297833978349783597836978379783897839978409784197842978439784497845978469784797848978499785097851978529785397854978559785697857978589785997860978619786297863978649786597866978679786897869978709787197872978739787497875978769787797878978799788097881978829788397884978859788697887978889788997890978919789297893978949789597896978979789897899979009790197902979039790497905979069790797908979099791097911979129791397914979159791697917979189791997920979219792297923979249792597926979279792897929979309793197932979339793497935979369793797938979399794097941979429794397944979459794697947979489794997950979519795297953979549795597956979579795897959979609796197962979639796497965979669796797968979699797097971979729797397974979759797697977979789797997980979819798297983979849798597986979879798897989979909799197992979939799497995979969799797998979999800098001980029800398004980059800698007980089800998010980119801298013980149801598016980179801898019980209802198022980239802498025980269802798028980299803098031980329803398034980359803698037980389803998040980419804298043980449804598046980479804898049980509805198052980539805498055980569805798058980599806098061980629806398064980659806698067980689806998070980719807298073980749807598076980779807898079980809808198082980839808498085980869808798088980899809098091980929809398094980959809698097980989809998100981019810298103981049810598106981079810898109981109811198112981139811498115981169811798118981199812098121981229812398124981259812698127981289812998130981319813298133981349813598136981379813898139981409814198142981439814498145981469814798148981499815098151981529815398154981559815698157981589815998160981619816298163981649816598166981679816898169981709817198172981739817498175981769817798178981799818098181981829818398184981859818698187981889818998190981919819298193981949819598196981979819898199982009820198202982039820498205982069820798208982099821098211982129821398214982159821698217982189821998220982219822298223982249822598226982279822898229982309823198232982339823498235982369823798238982399824098241982429824398244982459824698247982489824998250982519825298253982549825598256982579825898259982609826198262982639826498265982669826798268982699827098271982729827398274982759827698277982789827998280982819828298283982849828598286982879828898289982909829198292982939829498295982969829798298982999830098301983029830398304983059830698307983089830998310983119831298313983149831598316983179831898319983209832198322983239832498325983269832798328983299833098331983329833398334983359833698337983389833998340983419834298343983449834598346983479834898349983509835198352983539835498355983569835798358983599836098361983629836398364983659836698367983689836998370983719837298373983749837598376983779837898379983809838198382983839838498385983869838798388983899839098391983929839398394983959839698397983989839998400984019840298403984049840598406984079840898409984109841198412984139841498415984169841798418984199842098421984229842398424984259842698427984289842998430984319843298433984349843598436984379843898439984409844198442984439844498445984469844798448984499845098451984529845398454984559845698457984589845998460984619846298463984649846598466984679846898469984709847198472984739847498475984769847798478984799848098481984829848398484984859848698487984889848998490984919849298493984949849598496984979849898499985009850198502985039850498505985069850798508985099851098511985129851398514985159851698517985189851998520985219852298523985249852598526985279852898529985309853198532985339853498535985369853798538985399854098541985429854398544985459854698547985489854998550985519855298553985549855598556985579855898559985609856198562985639856498565985669856798568985699857098571985729857398574985759857698577985789857998580985819858298583985849858598586985879858898589985909859198592985939859498595985969859798598985999860098601986029860398604986059860698607986089860998610986119861298613986149861598616986179861898619986209862198622986239862498625986269862798628986299863098631986329863398634986359863698637986389863998640986419864298643986449864598646986479864898649986509865198652986539865498655986569865798658986599866098661986629866398664986659866698667986689866998670986719867298673986749867598676986779867898679986809868198682986839868498685986869868798688986899869098691986929869398694986959869698697986989869998700987019870298703987049870598706987079870898709987109871198712987139871498715987169871798718987199872098721987229872398724987259872698727987289872998730987319873298733987349873598736987379873898739987409874198742987439874498745987469874798748987499875098751987529875398754987559875698757987589875998760987619876298763987649876598766987679876898769987709877198772987739877498775987769877798778987799878098781987829878398784987859878698787987889878998790987919879298793987949879598796987979879898799988009880198802988039880498805988069880798808988099881098811988129881398814988159881698817988189881998820988219882298823988249882598826988279882898829988309883198832988339883498835988369883798838988399884098841988429884398844988459884698847988489884998850988519885298853988549885598856988579885898859988609886198862988639886498865988669886798868988699887098871988729887398874988759887698877988789887998880988819888298883988849888598886988879888898889988909889198892988939889498895988969889798898988999890098901989029890398904989059890698907989089890998910989119891298913989149891598916989179891898919989209892198922989239892498925989269892798928989299893098931989329893398934989359893698937989389893998940989419894298943989449894598946989479894898949989509895198952989539895498955989569895798958989599896098961989629896398964989659896698967989689896998970989719897298973989749897598976989779897898979989809898198982989839898498985989869898798988989899899098991989929899398994989959899698997989989899999000990019900299003990049900599006990079900899009990109901199012990139901499015990169901799018990199902099021990229902399024990259902699027990289902999030990319903299033990349903599036990379903899039990409904199042990439904499045990469904799048990499905099051990529905399054990559905699057990589905999060990619906299063990649906599066990679906899069990709907199072990739907499075990769907799078990799908099081990829908399084990859908699087990889908999090990919909299093990949909599096990979909899099991009910199102991039910499105991069910799108991099911099111991129911399114991159911699117991189911999120991219912299123991249912599126991279912899129991309913199132991339913499135991369913799138991399914099141991429914399144991459914699147991489914999150991519915299153991549915599156991579915899159991609916199162991639916499165991669916799168991699917099171991729917399174991759917699177991789917999180991819918299183991849918599186991879918899189991909919199192991939919499195991969919799198991999920099201992029920399204992059920699207992089920999210992119921299213992149921599216992179921899219992209922199222992239922499225992269922799228992299923099231992329923399234992359923699237992389923999240992419924299243992449924599246992479924899249992509925199252992539925499255992569925799258992599926099261992629926399264992659926699267992689926999270992719927299273992749927599276992779927899279992809928199282992839928499285992869928799288992899929099291992929929399294992959929699297992989929999300993019930299303993049930599306993079930899309993109931199312993139931499315993169931799318993199932099321993229932399324993259932699327993289932999330993319933299333993349933599336993379933899339993409934199342993439934499345993469934799348993499935099351993529935399354993559935699357993589935999360993619936299363993649936599366993679936899369993709937199372993739937499375993769937799378993799938099381993829938399384993859938699387993889938999390993919939299393993949939599396993979939899399994009940199402994039940499405994069940799408994099941099411994129941399414994159941699417994189941999420994219942299423994249942599426994279942899429994309943199432994339943499435994369943799438994399944099441994429944399444994459944699447994489944999450994519945299453994549945599456994579945899459994609946199462994639946499465994669946799468994699947099471994729947399474994759947699477994789947999480994819948299483994849948599486994879948899489994909949199492994939949499495994969949799498994999950099501995029950399504995059950699507995089950999510995119951299513995149951599516995179951899519995209952199522995239952499525995269952799528995299953099531995329953399534995359953699537995389953999540995419954299543995449954599546995479954899549995509955199552995539955499555995569955799558995599956099561995629956399564995659956699567995689956999570995719957299573995749957599576995779957899579995809958199582995839958499585995869958799588995899959099591995929959399594995959959699597995989959999600996019960299603996049960599606996079960899609996109961199612996139961499615996169961799618996199962099621996229962399624996259962699627996289962999630996319963299633996349963599636996379963899639996409964199642996439964499645996469964799648996499965099651996529965399654996559965699657996589965999660996619966299663996649966599666996679966899669996709967199672996739967499675996769967799678996799968099681996829968399684996859968699687996889968999690996919969299693996949969599696996979969899699997009970199702997039970499705997069970799708997099971099711997129971399714997159971699717997189971999720997219972299723997249972599726997279972899729997309973199732997339973499735997369973799738997399974099741997429974399744997459974699747997489974999750997519975299753997549975599756997579975899759997609976199762997639976499765997669976799768997699977099771997729977399774997759977699777997789977999780997819978299783997849978599786997879978899789997909979199792997939979499795997969979799798997999980099801998029980399804998059980699807998089980999810998119981299813998149981599816998179981899819998209982199822998239982499825998269982799828998299983099831998329983399834998359983699837998389983999840998419984299843998449984599846998479984899849998509985199852998539985499855998569985799858998599986099861998629986399864998659986699867998689986999870998719987299873998749987599876998779987899879998809988199882998839988499885998869988799888998899989099891998929989399894998959989699897998989989999900999019990299903999049990599906999079990899909999109991199912999139991499915999169991799918999199992099921999229992399924999259992699927999289992999930999319993299933999349993599936999379993899939999409994199942999439994499945999469994799948999499995099951999529995399954999559995699957999589995999960999619996299963999649996599966999679996899969999709997199972999739997499975999769997799978999799998099981999829998399984999859998699987999889998999990999919999299993999949999599996999979999899999100000100001100002100003100004100005100006100007100008100009100010100011100012100013100014100015100016100017100018100019100020100021100022100023100024100025100026100027100028100029100030100031100032100033100034100035100036100037100038100039100040100041100042100043100044100045100046100047100048100049100050100051100052100053100054100055100056100057100058100059100060100061100062100063100064100065100066100067100068100069100070100071100072100073100074100075100076100077100078100079100080100081100082100083100084100085100086100087100088100089100090100091100092100093100094100095100096100097100098100099100100100101100102100103100104100105100106100107100108100109100110100111100112100113100114100115100116100117100118100119100120100121100122100123100124100125100126100127100128100129100130100131100132100133100134100135100136100137100138100139100140100141100142100143100144100145100146100147100148100149100150100151100152100153100154100155100156100157100158100159100160100161100162100163100164100165100166100167100168100169100170100171100172100173100174100175100176100177100178100179100180100181100182100183100184100185100186100187100188100189100190100191100192100193100194100195100196100197100198100199100200100201100202100203100204100205100206100207100208100209100210100211100212100213100214100215100216100217100218100219100220100221100222100223100224100225100226100227100228100229100230100231100232100233100234100235100236100237100238100239100240100241100242100243100244100245100246100247100248100249100250100251100252100253100254100255100256100257100258100259100260100261100262100263100264100265100266100267100268100269100270100271100272100273100274100275100276100277100278100279100280100281100282100283100284100285100286100287100288100289100290100291100292100293100294100295100296100297100298100299100300100301100302100303100304100305100306100307100308100309100310100311100312100313100314100315100316100317100318100319100320100321100322100323100324100325100326100327100328100329100330100331100332100333100334100335100336100337100338100339100340100341100342100343100344100345100346100347100348100349100350100351100352100353100354100355100356100357100358100359100360100361100362100363100364100365100366100367100368100369100370100371100372100373100374100375100376100377100378100379100380100381100382100383100384100385100386100387100388100389100390100391100392100393100394100395100396100397100398100399100400100401100402100403100404100405100406100407100408100409100410100411100412100413100414100415100416100417100418100419100420100421100422100423100424100425100426100427100428100429100430100431100432100433100434100435100436100437100438100439100440100441100442100443100444100445100446100447100448100449100450100451100452100453100454100455100456100457100458100459100460100461100462100463100464100465100466100467100468100469100470100471100472100473100474100475100476100477100478100479100480100481100482100483100484100485100486100487100488100489100490100491100492100493100494100495100496100497100498100499100500100501100502100503100504100505100506100507100508100509100510100511100512100513100514100515100516100517100518100519100520100521100522100523100524100525100526100527100528100529100530100531100532100533100534100535100536100537100538100539100540100541100542100543100544100545100546100547100548100549100550100551100552100553100554100555100556100557100558100559100560100561100562100563100564100565100566100567100568100569100570100571100572100573100574100575100576100577100578100579100580100581100582100583100584100585100586100587100588100589100590100591100592100593100594100595100596100597100598100599100600100601100602100603100604100605100606100607100608100609100610100611100612100613100614100615100616100617100618100619100620100621100622100623100624100625100626100627100628100629100630100631100632100633100634100635100636100637100638100639100640100641100642100643100644100645100646100647100648100649100650100651100652100653100654100655100656100657100658100659100660100661100662100663100664100665100666100667100668100669100670100671100672100673100674100675100676100677100678100679100680100681100682100683100684100685100686100687100688100689100690100691100692100693100694100695100696100697100698100699100700100701100702100703100704100705100706100707100708100709100710100711100712100713100714100715100716100717100718100719100720100721100722100723100724100725100726100727100728100729100730100731100732100733100734100735100736100737100738100739100740100741100742100743100744100745100746100747100748100749100750100751100752100753100754100755100756100757100758100759100760100761100762100763100764100765100766100767100768100769100770100771100772100773100774100775100776100777100778100779100780100781100782100783100784100785100786100787100788100789100790100791100792100793100794100795100796100797100798100799100800100801100802100803100804100805100806100807100808100809100810100811100812100813100814100815100816100817100818100819100820100821100822100823100824100825100826100827100828100829100830100831100832100833100834100835100836100837100838100839100840100841100842100843100844100845100846100847100848100849100850100851100852100853100854100855100856100857100858100859100860100861100862100863100864100865100866100867100868100869100870100871100872100873100874100875100876100877100878100879100880100881100882100883100884100885100886100887100888100889100890100891100892100893100894100895100896100897100898100899100900100901100902100903100904100905100906100907100908100909100910100911100912100913100914100915100916100917100918100919100920100921100922100923100924100925100926100927100928100929100930100931100932100933100934100935100936100937100938100939100940100941100942100943100944100945100946100947100948100949100950100951100952100953100954100955100956100957100958100959100960100961100962100963100964100965100966100967100968100969100970100971100972100973100974100975100976100977100978100979100980100981100982100983100984100985100986100987100988100989100990100991100992100993100994100995100996100997100998100999101000101001101002101003101004101005101006101007101008101009101010101011101012101013101014101015101016101017101018101019101020101021101022101023101024101025101026101027101028101029101030101031101032101033101034101035101036101037101038101039101040101041101042101043101044101045101046101047101048101049101050101051101052101053101054101055101056101057101058101059101060101061101062101063101064101065101066101067101068101069101070101071101072101073101074101075101076101077101078101079101080101081101082101083101084101085101086101087101088101089101090101091101092101093101094101095101096101097101098101099101100101101101102101103101104101105101106101107101108101109101110101111101112101113101114101115101116101117101118101119101120101121101122101123101124101125101126101127101128101129101130101131101132101133101134101135101136101137101138101139101140101141101142101143101144101145101146101147101148101149101150101151101152101153101154101155101156101157101158101159101160101161101162101163101164101165101166101167101168101169101170101171101172101173101174101175101176101177101178101179101180101181101182101183101184101185101186101187101188101189101190101191101192101193101194101195101196101197101198101199101200101201101202101203101204101205101206101207101208101209101210101211101212101213101214101215101216101217101218101219101220101221101222101223101224101225101226101227101228101229101230101231101232101233101234101235101236101237101238101239101240101241101242101243101244101245101246101247101248101249101250101251101252101253101254101255101256101257101258101259101260101261101262101263101264101265101266101267101268101269101270101271101272101273101274101275101276101277101278101279101280101281101282101283101284101285101286101287101288101289101290101291101292101293101294101295101296101297101298101299101300101301101302101303101304101305101306101307101308101309101310101311101312101313101314101315101316101317101318101319101320101321101322101323101324101325101326101327101328101329101330101331101332101333101334101335101336101337101338101339101340101341101342101343101344101345101346101347101348101349101350101351101352101353101354101355101356101357101358101359101360101361101362101363101364101365101366101367101368101369101370101371101372101373101374101375101376101377101378101379101380101381101382101383101384101385101386101387101388101389101390101391101392101393101394101395101396101397101398101399101400101401101402101403101404101405101406101407101408101409101410101411101412101413101414101415101416101417101418101419101420101421101422101423101424101425101426101427101428101429101430101431101432101433101434101435101436101437101438101439101440101441101442101443101444101445101446101447101448101449101450101451101452101453101454101455101456101457101458101459101460101461101462101463101464101465101466101467101468101469101470101471101472101473101474101475101476101477101478101479101480101481101482101483101484101485101486101487101488101489101490101491101492101493101494101495101496101497101498101499101500101501101502101503101504101505101506101507101508101509101510101511101512101513101514101515101516101517101518101519101520101521101522101523101524101525101526101527101528101529101530101531101532101533101534101535101536101537101538101539101540101541101542101543101544101545101546101547101548101549101550101551101552101553101554101555101556101557101558101559101560101561101562101563101564101565101566101567101568101569101570101571101572101573101574101575101576101577101578101579101580101581101582101583101584101585101586101587101588101589101590101591101592101593101594101595101596101597101598101599101600101601101602101603101604101605101606101607101608101609101610101611101612101613101614101615101616101617101618101619101620101621101622101623101624101625101626101627101628101629101630101631101632101633101634101635101636101637101638101639101640101641101642101643101644101645101646101647101648101649101650101651101652101653101654101655101656101657101658101659101660101661101662101663101664101665101666101667101668101669101670101671101672101673101674101675101676101677101678101679101680101681101682101683101684101685101686101687101688101689101690101691101692101693101694101695101696101697101698101699101700101701101702101703101704101705101706101707101708101709101710101711101712101713101714101715101716101717101718101719101720101721101722101723101724101725101726101727101728101729101730101731101732101733101734101735101736101737101738101739101740101741101742101743101744101745101746101747101748101749101750101751101752101753101754101755101756101757101758101759101760101761101762101763101764101765101766101767101768101769101770101771101772101773101774101775101776101777101778101779101780101781101782101783101784101785101786101787101788101789101790101791101792101793101794101795101796101797101798101799101800101801101802101803101804101805101806101807101808101809101810101811101812101813101814101815101816101817101818101819101820101821101822101823101824101825101826101827101828101829101830101831101832101833101834101835101836101837101838101839101840101841101842101843101844101845101846101847101848101849101850101851101852101853101854101855101856101857101858101859101860101861101862101863101864101865101866101867101868101869101870101871101872101873101874101875101876101877101878101879101880101881101882101883101884101885101886101887101888101889101890101891101892101893101894101895101896101897101898101899101900101901101902101903101904101905101906101907101908101909101910101911101912101913101914101915101916101917101918101919101920101921101922101923101924101925101926101927101928101929101930101931101932101933101934101935101936101937101938101939101940101941101942101943101944101945101946101947101948101949101950101951101952101953101954101955101956101957101958101959101960101961101962101963101964101965101966101967101968101969101970101971101972101973101974101975101976101977101978101979101980101981101982101983101984101985101986101987101988101989101990101991101992101993101994101995101996101997101998101999102000102001102002102003102004102005102006102007102008102009102010102011102012102013102014102015102016102017102018102019102020102021102022102023102024102025102026102027102028102029102030102031102032102033102034102035102036102037102038102039102040102041102042102043102044102045102046102047102048102049102050102051102052102053102054102055102056102057102058102059102060102061102062102063102064102065102066102067102068102069102070102071102072102073102074102075102076102077102078102079102080102081102082102083102084102085102086102087102088102089102090102091102092102093102094102095102096102097102098102099102100102101102102102103102104102105102106102107102108102109102110102111102112102113102114102115102116102117102118102119102120102121102122102123102124102125102126102127102128102129102130102131102132102133102134102135102136102137102138102139102140102141102142102143102144102145102146102147102148102149102150102151102152102153102154102155102156102157102158102159102160102161102162102163102164102165102166102167102168102169102170102171102172102173102174102175102176102177102178102179102180102181102182102183102184102185102186102187102188102189102190102191102192102193102194102195102196102197102198102199102200102201102202102203102204102205102206102207102208102209102210102211102212102213102214102215102216102217102218102219102220102221102222102223102224102225102226102227102228102229102230102231102232102233102234102235102236102237102238102239102240102241102242102243102244102245102246102247102248102249102250102251102252102253102254102255102256102257102258102259102260102261102262102263102264102265102266102267102268102269102270102271102272102273102274102275102276102277102278102279102280102281102282102283102284102285102286102287102288102289102290102291102292102293102294102295102296102297102298102299102300102301102302102303102304102305102306102307102308102309102310102311102312102313102314102315102316102317102318102319102320102321102322102323102324102325102326102327102328102329102330102331102332102333102334102335102336102337102338102339102340102341102342102343102344102345102346102347102348102349102350102351102352102353102354102355102356102357102358102359102360102361102362102363102364102365102366102367102368102369102370102371102372102373102374102375102376102377102378102379102380102381102382102383102384102385102386102387102388102389102390102391102392102393102394102395102396102397102398102399102400102401102402102403102404102405102406102407102408102409102410102411102412102413102414102415102416102417102418102419102420102421102422102423102424102425102426102427102428102429102430102431102432102433102434102435102436102437102438102439102440102441102442102443102444102445102446102447102448102449102450102451102452102453102454102455102456102457102458102459102460102461102462102463102464102465102466102467102468102469102470102471102472102473102474102475102476102477102478102479102480102481102482102483102484102485102486102487102488102489102490102491102492102493102494102495102496102497102498102499102500102501102502102503102504102505102506102507102508102509102510102511102512102513102514102515102516102517102518102519102520102521102522102523102524102525102526102527102528102529102530102531102532102533102534102535102536102537102538102539102540102541102542102543102544102545102546102547102548102549102550102551102552102553102554102555102556102557102558102559102560102561102562102563102564102565102566102567102568102569102570102571102572102573102574102575102576102577102578102579102580102581102582102583102584102585102586102587102588102589102590102591102592102593102594102595102596102597102598102599102600102601102602102603102604102605102606102607102608102609102610102611102612102613102614102615102616102617102618102619102620102621102622102623102624102625102626102627102628102629102630102631102632102633102634102635102636102637102638102639102640102641102642102643102644102645102646102647102648102649102650102651102652102653102654102655102656102657102658102659102660102661102662102663102664102665102666102667102668102669102670102671102672102673102674102675102676102677102678102679102680102681102682102683102684102685102686102687102688102689102690102691102692102693102694102695102696102697102698102699102700102701102702102703102704102705102706102707102708102709102710102711102712102713102714102715102716102717102718102719102720102721102722102723102724102725102726102727102728102729102730102731102732102733102734102735102736102737102738102739102740102741102742102743102744102745102746102747102748102749102750102751102752102753102754102755102756102757102758102759102760102761102762102763102764102765102766102767102768102769102770102771102772102773102774102775102776102777102778102779102780102781102782102783102784102785102786102787102788102789102790102791102792102793102794102795102796102797102798102799102800102801102802102803102804102805102806102807102808102809102810102811102812102813102814102815102816102817102818102819102820102821102822102823102824102825102826102827102828102829102830102831102832102833102834102835102836102837102838102839102840102841102842102843102844102845102846102847102848102849102850102851102852102853102854102855102856102857102858102859102860102861102862102863102864102865102866102867102868102869102870102871102872102873102874102875102876102877102878102879102880102881102882102883102884102885102886102887102888102889102890102891102892102893102894102895102896102897102898102899102900102901102902102903102904102905102906102907102908102909102910102911102912102913102914102915102916102917102918102919102920102921102922102923102924102925102926102927102928102929102930102931102932102933102934102935102936102937102938102939102940102941102942102943102944102945102946102947102948102949102950102951102952102953102954102955102956102957102958102959102960102961102962102963102964102965102966102967102968102969102970102971102972102973102974102975102976102977102978102979102980102981102982102983102984102985102986102987102988102989102990102991102992102993102994102995102996102997102998102999103000103001103002103003103004103005103006103007103008103009103010103011103012103013103014103015103016103017103018103019103020103021103022103023103024103025103026103027103028103029103030103031103032103033103034103035103036103037103038103039103040103041103042103043103044103045103046103047103048103049103050103051103052103053103054103055103056103057103058103059103060103061103062103063103064103065103066103067103068103069103070103071103072103073103074103075103076103077103078103079103080103081103082103083103084103085103086103087103088103089103090103091103092103093103094103095103096103097103098103099103100103101103102103103103104103105103106103107103108103109103110103111103112103113103114103115103116103117103118103119103120103121103122103123103124103125103126103127103128103129103130103131103132103133103134103135103136103137103138103139103140103141103142103143103144103145103146103147103148103149103150103151103152103153103154103155103156103157103158103159103160103161103162103163103164103165103166103167103168103169103170103171103172103173103174103175103176103177103178103179103180103181103182103183103184103185103186103187103188103189103190103191103192103193103194103195103196103197103198103199103200103201103202103203103204103205103206103207103208103209103210103211103212103213103214103215103216103217103218103219103220103221103222103223103224103225103226103227103228103229103230103231103232103233103234103235103236103237103238103239103240103241103242103243103244103245103246103247103248103249103250103251103252103253103254103255103256103257103258103259103260103261103262103263103264103265103266103267103268103269103270103271103272103273103274103275103276103277103278103279103280103281103282103283103284103285103286103287103288103289103290103291103292103293103294103295103296103297103298103299103300103301103302103303103304103305103306103307103308103309103310103311103312103313103314103315103316103317103318103319103320103321103322103323103324103325103326103327103328103329103330103331103332103333103334103335103336103337103338103339103340103341103342103343103344103345103346103347103348103349103350103351103352103353103354103355103356103357103358103359103360103361103362103363103364103365103366103367103368103369103370103371103372103373103374103375103376103377103378103379103380103381103382103383103384103385103386103387103388103389103390103391103392103393103394103395103396103397103398103399103400103401103402103403103404103405103406103407103408103409103410103411103412103413103414103415103416103417103418103419103420103421103422103423103424103425103426103427103428103429103430103431103432103433103434103435103436103437103438103439103440103441103442103443103444103445103446103447103448103449103450103451103452103453103454103455103456103457103458103459103460103461103462103463103464103465103466103467103468103469103470103471103472103473103474103475103476103477103478103479103480103481103482103483103484103485103486103487103488103489103490103491103492103493103494103495103496103497103498103499103500103501103502103503103504103505103506103507103508103509103510103511103512103513103514103515103516103517103518103519103520103521103522103523103524103525103526103527103528103529103530103531103532103533103534103535103536103537103538103539103540103541103542103543103544103545103546103547103548103549103550103551103552103553103554103555103556103557103558103559103560103561103562103563103564103565103566103567103568103569103570103571103572103573103574103575103576103577103578103579103580103581103582103583103584103585103586103587103588103589103590103591103592103593103594103595103596103597103598103599103600103601103602103603103604103605103606103607103608103609103610103611103612103613103614103615103616103617103618103619103620103621103622103623103624103625103626103627103628103629103630103631103632103633103634103635103636103637103638103639103640103641103642103643103644103645103646103647103648103649103650103651103652103653103654103655103656103657103658103659103660103661103662103663103664103665103666103667103668103669103670103671103672103673103674103675103676103677103678103679103680103681103682103683103684103685103686103687103688103689103690103691103692103693103694103695103696103697103698103699103700103701103702103703103704103705103706103707103708103709103710103711103712103713103714103715103716103717103718103719103720103721103722103723103724103725103726103727103728103729103730103731103732103733103734103735103736103737103738103739103740103741103742103743103744103745103746103747103748103749103750103751103752103753103754103755103756103757103758103759103760103761103762103763103764103765103766103767103768103769103770103771103772103773103774103775103776103777103778103779103780103781103782103783103784103785103786103787103788103789103790103791103792103793103794103795103796103797103798103799103800103801103802103803103804103805103806103807103808103809103810103811103812103813103814103815103816103817103818103819103820103821103822103823103824103825103826103827103828103829103830103831103832103833103834103835103836103837103838103839103840103841103842103843103844103845103846103847103848103849103850103851103852103853103854103855103856103857103858103859103860103861103862103863103864103865103866103867103868103869103870103871103872103873103874103875103876103877103878103879103880103881103882103883103884103885103886103887103888103889103890103891103892103893103894103895103896103897103898103899103900103901103902103903103904103905103906103907103908103909103910103911103912103913103914103915103916103917103918103919103920103921103922103923103924103925103926103927103928103929103930103931103932103933103934103935103936103937103938103939103940103941103942103943103944103945103946103947103948103949103950103951103952103953103954103955103956103957103958103959103960103961103962103963103964103965103966103967103968103969103970103971103972103973103974103975103976103977103978103979103980103981103982103983103984103985103986103987103988103989103990103991103992103993103994103995103996103997103998103999104000104001104002104003104004104005104006104007104008104009104010104011104012104013104014104015104016104017104018104019104020104021104022104023104024104025104026104027104028104029104030104031104032104033104034104035104036104037104038104039104040104041104042104043104044104045104046104047104048104049104050104051104052104053104054104055104056104057104058104059104060104061104062104063104064104065104066104067104068104069104070104071104072104073104074104075104076104077104078104079104080104081104082104083104084104085104086104087104088104089104090104091104092104093104094104095104096104097104098104099104100104101104102104103104104104105104106104107104108104109104110104111104112104113104114104115104116104117104118104119104120104121104122104123104124104125104126104127104128104129104130104131104132104133104134104135104136104137104138104139104140104141104142104143104144104145104146104147104148104149104150104151104152104153104154104155104156104157104158104159104160104161104162104163104164104165104166104167104168104169104170104171104172104173104174104175104176104177104178104179104180104181104182104183104184104185104186104187104188104189104190104191104192104193104194104195104196104197104198104199104200104201104202104203104204104205104206104207104208104209104210104211104212104213104214104215104216104217104218104219104220104221104222104223104224104225104226104227104228104229104230104231104232104233104234104235104236104237104238104239104240104241104242104243104244104245104246104247104248104249104250104251104252104253104254104255104256104257104258104259104260104261104262104263104264104265104266104267104268104269104270104271104272104273104274104275104276104277104278104279104280104281104282104283104284104285104286104287104288104289104290104291104292104293104294104295104296104297104298104299104300104301104302104303104304104305104306104307104308104309104310104311104312104313104314104315104316104317104318104319104320104321104322104323104324104325104326104327104328104329104330104331104332104333104334104335104336104337104338104339104340104341104342104343104344104345104346104347104348104349104350104351104352104353104354104355104356104357104358104359104360104361104362104363104364104365104366104367104368104369104370104371104372104373104374104375104376104377104378104379104380104381104382104383104384104385104386104387104388104389104390104391104392104393104394104395104396104397104398104399104400104401104402104403104404104405104406104407104408104409104410104411104412104413104414104415104416104417104418104419104420104421104422104423104424104425104426104427104428104429104430104431104432104433104434104435104436104437104438104439104440104441104442104443104444104445104446104447104448104449104450104451104452104453104454104455104456104457104458104459104460104461104462104463104464104465104466104467104468104469104470104471104472104473104474104475104476104477104478104479104480104481104482104483104484104485104486104487104488104489104490104491104492104493104494104495104496104497104498104499104500104501104502104503104504104505104506104507104508
  1. diff -Nur linux-3.13.11/arch/arm/configs/bcmrpi_cutdown_defconfig linux-rpi/arch/arm/configs/bcmrpi_cutdown_defconfig
  2. --- linux-3.13.11/arch/arm/configs/bcmrpi_cutdown_defconfig 1970-01-01 01:00:00.000000000 +0100
  3. +++ linux-rpi/arch/arm/configs/bcmrpi_cutdown_defconfig 2014-04-24 15:36:30.902525642 +0200
  4. @@ -0,0 +1,503 @@
  5. +CONFIG_EXPERIMENTAL=y
  6. +# CONFIG_LOCALVERSION_AUTO is not set
  7. +CONFIG_SYSVIPC=y
  8. +CONFIG_POSIX_MQUEUE=y
  9. +CONFIG_IKCONFIG=y
  10. +CONFIG_IKCONFIG_PROC=y
  11. +# CONFIG_UID16 is not set
  12. +# CONFIG_KALLSYMS is not set
  13. +CONFIG_EMBEDDED=y
  14. +# CONFIG_VM_EVENT_COUNTERS is not set
  15. +# CONFIG_COMPAT_BRK is not set
  16. +CONFIG_SLAB=y
  17. +CONFIG_MODULES=y
  18. +CONFIG_MODULE_UNLOAD=y
  19. +CONFIG_MODVERSIONS=y
  20. +CONFIG_MODULE_SRCVERSION_ALL=y
  21. +# CONFIG_BLK_DEV_BSG is not set
  22. +CONFIG_ARCH_BCM2708=y
  23. +CONFIG_NO_HZ=y
  24. +CONFIG_HIGH_RES_TIMERS=y
  25. +CONFIG_AEABI=y
  26. +CONFIG_ZBOOT_ROM_TEXT=0x0
  27. +CONFIG_ZBOOT_ROM_BSS=0x0
  28. +CONFIG_CMDLINE="dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext3 rootwait"
  29. +CONFIG_CPU_IDLE=y
  30. +CONFIG_VFP=y
  31. +CONFIG_BINFMT_MISC=m
  32. +CONFIG_NET=y
  33. +CONFIG_PACKET=y
  34. +CONFIG_UNIX=y
  35. +CONFIG_XFRM_USER=y
  36. +CONFIG_NET_KEY=m
  37. +CONFIG_INET=y
  38. +CONFIG_IP_MULTICAST=y
  39. +CONFIG_IP_PNP=y
  40. +CONFIG_IP_PNP_DHCP=y
  41. +CONFIG_IP_PNP_RARP=y
  42. +CONFIG_SYN_COOKIES=y
  43. +# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
  44. +# CONFIG_INET_XFRM_MODE_TUNNEL is not set
  45. +# CONFIG_INET_XFRM_MODE_BEET is not set
  46. +# CONFIG_INET_LRO is not set
  47. +# CONFIG_INET_DIAG is not set
  48. +# CONFIG_IPV6 is not set
  49. +CONFIG_NET_PKTGEN=m
  50. +CONFIG_IRDA=m
  51. +CONFIG_IRLAN=m
  52. +CONFIG_IRCOMM=m
  53. +CONFIG_IRDA_ULTRA=y
  54. +CONFIG_IRDA_CACHE_LAST_LSAP=y
  55. +CONFIG_IRDA_FAST_RR=y
  56. +CONFIG_IRTTY_SIR=m
  57. +CONFIG_KINGSUN_DONGLE=m
  58. +CONFIG_KSDAZZLE_DONGLE=m
  59. +CONFIG_KS959_DONGLE=m
  60. +CONFIG_USB_IRDA=m
  61. +CONFIG_SIGMATEL_FIR=m
  62. +CONFIG_MCS_FIR=m
  63. +CONFIG_BT=m
  64. +CONFIG_BT_L2CAP=y
  65. +CONFIG_BT_SCO=y
  66. +CONFIG_BT_RFCOMM=m
  67. +CONFIG_BT_RFCOMM_TTY=y
  68. +CONFIG_BT_BNEP=m
  69. +CONFIG_BT_BNEP_MC_FILTER=y
  70. +CONFIG_BT_BNEP_PROTO_FILTER=y
  71. +CONFIG_BT_HIDP=m
  72. +CONFIG_BT_HCIBTUSB=m
  73. +CONFIG_BT_HCIBCM203X=m
  74. +CONFIG_BT_HCIBPA10X=m
  75. +CONFIG_BT_HCIBFUSB=m
  76. +CONFIG_BT_HCIVHCI=m
  77. +CONFIG_BT_MRVL=m
  78. +CONFIG_BT_MRVL_SDIO=m
  79. +CONFIG_BT_ATH3K=m
  80. +CONFIG_CFG80211=m
  81. +CONFIG_MAC80211=m
  82. +CONFIG_MAC80211_RC_PID=y
  83. +CONFIG_MAC80211_MESH=y
  84. +CONFIG_WIMAX=m
  85. +CONFIG_NET_9P=m
  86. +CONFIG_NFC=m
  87. +CONFIG_NFC_PN533=m
  88. +CONFIG_DEVTMPFS=y
  89. +CONFIG_BLK_DEV_LOOP=y
  90. +CONFIG_BLK_DEV_CRYPTOLOOP=m
  91. +CONFIG_BLK_DEV_NBD=m
  92. +CONFIG_BLK_DEV_RAM=y
  93. +CONFIG_CDROM_PKTCDVD=m
  94. +CONFIG_MISC_DEVICES=y
  95. +CONFIG_SCSI=y
  96. +# CONFIG_SCSI_PROC_FS is not set
  97. +CONFIG_BLK_DEV_SD=m
  98. +CONFIG_BLK_DEV_SR=m
  99. +CONFIG_SCSI_MULTI_LUN=y
  100. +# CONFIG_SCSI_LOWLEVEL is not set
  101. +CONFIG_NETDEVICES=y
  102. +CONFIG_TUN=m
  103. +CONFIG_PHYLIB=m
  104. +CONFIG_MDIO_BITBANG=m
  105. +CONFIG_NET_ETHERNET=y
  106. +# CONFIG_NETDEV_1000 is not set
  107. +# CONFIG_NETDEV_10000 is not set
  108. +CONFIG_LIBERTAS_THINFIRM=m
  109. +CONFIG_LIBERTAS_THINFIRM_USB=m
  110. +CONFIG_AT76C50X_USB=m
  111. +CONFIG_USB_ZD1201=m
  112. +CONFIG_USB_NET_RNDIS_WLAN=m
  113. +CONFIG_RTL8187=m
  114. +CONFIG_MAC80211_HWSIM=m
  115. +CONFIG_ATH_COMMON=m
  116. +CONFIG_ATH9K=m
  117. +CONFIG_ATH9K_HTC=m
  118. +CONFIG_CARL9170=m
  119. +CONFIG_B43=m
  120. +CONFIG_B43LEGACY=m
  121. +CONFIG_HOSTAP=m
  122. +CONFIG_IWM=m
  123. +CONFIG_LIBERTAS=m
  124. +CONFIG_LIBERTAS_USB=m
  125. +CONFIG_LIBERTAS_SDIO=m
  126. +CONFIG_P54_COMMON=m
  127. +CONFIG_P54_USB=m
  128. +CONFIG_RT2X00=m
  129. +CONFIG_RT2500USB=m
  130. +CONFIG_RT73USB=m
  131. +CONFIG_RT2800USB=m
  132. +CONFIG_RT2800USB_RT53XX=y
  133. +CONFIG_RTL8192CU=m
  134. +CONFIG_WL1251=m
  135. +CONFIG_WL12XX_MENU=m
  136. +CONFIG_ZD1211RW=m
  137. +CONFIG_MWIFIEX=m
  138. +CONFIG_MWIFIEX_SDIO=m
  139. +CONFIG_WIMAX_I2400M_USB=m
  140. +CONFIG_USB_CATC=m
  141. +CONFIG_USB_KAWETH=m
  142. +CONFIG_USB_PEGASUS=m
  143. +CONFIG_USB_RTL8150=m
  144. +CONFIG_USB_USBNET=y
  145. +CONFIG_USB_NET_AX8817X=m
  146. +CONFIG_USB_NET_CDCETHER=m
  147. +CONFIG_USB_NET_CDC_EEM=m
  148. +CONFIG_USB_NET_DM9601=m
  149. +CONFIG_USB_NET_SMSC75XX=m
  150. +CONFIG_USB_NET_SMSC95XX=y
  151. +CONFIG_USB_NET_GL620A=m
  152. +CONFIG_USB_NET_NET1080=m
  153. +CONFIG_USB_NET_PLUSB=m
  154. +CONFIG_USB_NET_MCS7830=m
  155. +CONFIG_USB_NET_CDC_SUBSET=m
  156. +CONFIG_USB_ALI_M5632=y
  157. +CONFIG_USB_AN2720=y
  158. +CONFIG_USB_KC2190=y
  159. +# CONFIG_USB_NET_ZAURUS is not set
  160. +CONFIG_USB_NET_CX82310_ETH=m
  161. +CONFIG_USB_NET_KALMIA=m
  162. +CONFIG_USB_NET_INT51X1=m
  163. +CONFIG_USB_IPHETH=m
  164. +CONFIG_USB_SIERRA_NET=m
  165. +CONFIG_USB_VL600=m
  166. +CONFIG_PPP=m
  167. +CONFIG_PPP_ASYNC=m
  168. +CONFIG_PPP_SYNC_TTY=m
  169. +CONFIG_PPP_DEFLATE=m
  170. +CONFIG_PPP_BSDCOMP=m
  171. +CONFIG_SLIP=m
  172. +CONFIG_SLIP_COMPRESSED=y
  173. +CONFIG_NETCONSOLE=m
  174. +CONFIG_INPUT_POLLDEV=m
  175. +# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
  176. +CONFIG_INPUT_JOYDEV=m
  177. +CONFIG_INPUT_EVDEV=m
  178. +# CONFIG_INPUT_KEYBOARD is not set
  179. +# CONFIG_INPUT_MOUSE is not set
  180. +CONFIG_INPUT_MISC=y
  181. +CONFIG_INPUT_AD714X=m
  182. +CONFIG_INPUT_ATI_REMOTE=m
  183. +CONFIG_INPUT_ATI_REMOTE2=m
  184. +CONFIG_INPUT_KEYSPAN_REMOTE=m
  185. +CONFIG_INPUT_POWERMATE=m
  186. +CONFIG_INPUT_YEALINK=m
  187. +CONFIG_INPUT_CM109=m
  188. +CONFIG_INPUT_UINPUT=m
  189. +CONFIG_INPUT_GPIO_ROTARY_ENCODER=m
  190. +CONFIG_INPUT_ADXL34X=m
  191. +CONFIG_INPUT_CMA3000=m
  192. +CONFIG_SERIO=m
  193. +CONFIG_SERIO_RAW=m
  194. +CONFIG_GAMEPORT=m
  195. +CONFIG_GAMEPORT_NS558=m
  196. +CONFIG_GAMEPORT_L4=m
  197. +CONFIG_VT_HW_CONSOLE_BINDING=y
  198. +# CONFIG_LEGACY_PTYS is not set
  199. +# CONFIG_DEVKMEM is not set
  200. +CONFIG_SERIAL_AMBA_PL011=y
  201. +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
  202. +# CONFIG_HW_RANDOM is not set
  203. +CONFIG_RAW_DRIVER=y
  204. +CONFIG_GPIO_SYSFS=y
  205. +# CONFIG_HWMON is not set
  206. +CONFIG_WATCHDOG=y
  207. +CONFIG_BCM2708_WDT=m
  208. +# CONFIG_MFD_SUPPORT is not set
  209. +CONFIG_FB=y
  210. +CONFIG_FB_BCM2708=y
  211. +CONFIG_FRAMEBUFFER_CONSOLE=y
  212. +CONFIG_LOGO=y
  213. +# CONFIG_LOGO_LINUX_MONO is not set
  214. +# CONFIG_LOGO_LINUX_VGA16 is not set
  215. +CONFIG_SOUND=y
  216. +CONFIG_SND=m
  217. +CONFIG_SND_SEQUENCER=m
  218. +CONFIG_SND_SEQ_DUMMY=m
  219. +CONFIG_SND_MIXER_OSS=m
  220. +CONFIG_SND_PCM_OSS=m
  221. +CONFIG_SND_SEQUENCER_OSS=y
  222. +CONFIG_SND_HRTIMER=m
  223. +CONFIG_SND_DUMMY=m
  224. +CONFIG_SND_ALOOP=m
  225. +CONFIG_SND_VIRMIDI=m
  226. +CONFIG_SND_MTPAV=m
  227. +CONFIG_SND_SERIAL_U16550=m
  228. +CONFIG_SND_MPU401=m
  229. +CONFIG_SND_BCM2835=m
  230. +CONFIG_SND_USB_AUDIO=m
  231. +CONFIG_SND_USB_UA101=m
  232. +CONFIG_SND_USB_CAIAQ=m
  233. +CONFIG_SND_USB_6FIRE=m
  234. +CONFIG_SOUND_PRIME=m
  235. +CONFIG_HID_PID=y
  236. +CONFIG_USB_HIDDEV=y
  237. +CONFIG_HID_A4TECH=m
  238. +CONFIG_HID_ACRUX=m
  239. +CONFIG_HID_APPLE=m
  240. +CONFIG_HID_BELKIN=m
  241. +CONFIG_HID_CHERRY=m
  242. +CONFIG_HID_CHICONY=m
  243. +CONFIG_HID_CYPRESS=m
  244. +CONFIG_HID_DRAGONRISE=m
  245. +CONFIG_HID_EMS_FF=m
  246. +CONFIG_HID_ELECOM=m
  247. +CONFIG_HID_EZKEY=m
  248. +CONFIG_HID_HOLTEK=m
  249. +CONFIG_HID_KEYTOUCH=m
  250. +CONFIG_HID_KYE=m
  251. +CONFIG_HID_UCLOGIC=m
  252. +CONFIG_HID_WALTOP=m
  253. +CONFIG_HID_GYRATION=m
  254. +CONFIG_HID_TWINHAN=m
  255. +CONFIG_HID_KENSINGTON=m
  256. +CONFIG_HID_LCPOWER=m
  257. +CONFIG_HID_LOGITECH=m
  258. +CONFIG_HID_MAGICMOUSE=m
  259. +CONFIG_HID_MICROSOFT=m
  260. +CONFIG_HID_MONTEREY=m
  261. +CONFIG_HID_MULTITOUCH=m
  262. +CONFIG_HID_NTRIG=m
  263. +CONFIG_HID_ORTEK=m
  264. +CONFIG_HID_PANTHERLORD=m
  265. +CONFIG_HID_PETALYNX=m
  266. +CONFIG_HID_PICOLCD=m
  267. +CONFIG_HID_QUANTA=m
  268. +CONFIG_HID_ROCCAT=m
  269. +CONFIG_HID_SAMSUNG=m
  270. +CONFIG_HID_SONY=m
  271. +CONFIG_HID_SPEEDLINK=m
  272. +CONFIG_HID_SUNPLUS=m
  273. +CONFIG_HID_GREENASIA=m
  274. +CONFIG_HID_SMARTJOYPLUS=m
  275. +CONFIG_HID_TOPSEED=m
  276. +CONFIG_HID_THRUSTMASTER=m
  277. +CONFIG_HID_WACOM=m
  278. +CONFIG_HID_WIIMOTE=m
  279. +CONFIG_HID_ZEROPLUS=m
  280. +CONFIG_HID_ZYDACRON=m
  281. +CONFIG_USB=y
  282. +CONFIG_USB_ANNOUNCE_NEW_DEVICES=y
  283. +CONFIG_USB_MON=m
  284. +CONFIG_USB_DWCOTG=y
  285. +CONFIG_USB_STORAGE=y
  286. +CONFIG_USB_STORAGE_REALTEK=m
  287. +CONFIG_USB_STORAGE_DATAFAB=m
  288. +CONFIG_USB_STORAGE_FREECOM=m
  289. +CONFIG_USB_STORAGE_ISD200=m
  290. +CONFIG_USB_STORAGE_USBAT=m
  291. +CONFIG_USB_STORAGE_SDDR09=m
  292. +CONFIG_USB_STORAGE_SDDR55=m
  293. +CONFIG_USB_STORAGE_JUMPSHOT=m
  294. +CONFIG_USB_STORAGE_ALAUDA=m
  295. +CONFIG_USB_STORAGE_ONETOUCH=m
  296. +CONFIG_USB_STORAGE_KARMA=m
  297. +CONFIG_USB_STORAGE_CYPRESS_ATACB=m
  298. +CONFIG_USB_STORAGE_ENE_UB6250=m
  299. +CONFIG_USB_UAS=m
  300. +CONFIG_USB_LIBUSUAL=y
  301. +CONFIG_USB_MDC800=m
  302. +CONFIG_USB_MICROTEK=m
  303. +CONFIG_USB_SERIAL=m
  304. +CONFIG_USB_SERIAL_GENERIC=y
  305. +CONFIG_USB_SERIAL_AIRCABLE=m
  306. +CONFIG_USB_SERIAL_ARK3116=m
  307. +CONFIG_USB_SERIAL_BELKIN=m
  308. +CONFIG_USB_SERIAL_CH341=m
  309. +CONFIG_USB_SERIAL_WHITEHEAT=m
  310. +CONFIG_USB_SERIAL_DIGI_ACCELEPORT=m
  311. +CONFIG_USB_SERIAL_CP210X=m
  312. +CONFIG_USB_SERIAL_CYPRESS_M8=m
  313. +CONFIG_USB_SERIAL_EMPEG=m
  314. +CONFIG_USB_SERIAL_FTDI_SIO=m
  315. +CONFIG_USB_SERIAL_FUNSOFT=m
  316. +CONFIG_USB_SERIAL_VISOR=m
  317. +CONFIG_USB_SERIAL_IPAQ=m
  318. +CONFIG_USB_SERIAL_IR=m
  319. +CONFIG_USB_SERIAL_EDGEPORT=m
  320. +CONFIG_USB_SERIAL_EDGEPORT_TI=m
  321. +CONFIG_USB_SERIAL_GARMIN=m
  322. +CONFIG_USB_SERIAL_IPW=m
  323. +CONFIG_USB_SERIAL_IUU=m
  324. +CONFIG_USB_SERIAL_KEYSPAN_PDA=m
  325. +CONFIG_USB_SERIAL_KEYSPAN=m
  326. +CONFIG_USB_SERIAL_KLSI=m
  327. +CONFIG_USB_SERIAL_KOBIL_SCT=m
  328. +CONFIG_USB_SERIAL_MCT_U232=m
  329. +CONFIG_USB_SERIAL_MOS7720=m
  330. +CONFIG_USB_SERIAL_MOS7840=m
  331. +CONFIG_USB_SERIAL_MOTOROLA=m
  332. +CONFIG_USB_SERIAL_NAVMAN=m
  333. +CONFIG_USB_SERIAL_PL2303=m
  334. +CONFIG_USB_SERIAL_OTI6858=m
  335. +CONFIG_USB_SERIAL_QCAUX=m
  336. +CONFIG_USB_SERIAL_QUALCOMM=m
  337. +CONFIG_USB_SERIAL_SPCP8X5=m
  338. +CONFIG_USB_SERIAL_HP4X=m
  339. +CONFIG_USB_SERIAL_SAFE=m
  340. +CONFIG_USB_SERIAL_SIEMENS_MPI=m
  341. +CONFIG_USB_SERIAL_SIERRAWIRELESS=m
  342. +CONFIG_USB_SERIAL_SYMBOL=m
  343. +CONFIG_USB_SERIAL_TI=m
  344. +CONFIG_USB_SERIAL_CYBERJACK=m
  345. +CONFIG_USB_SERIAL_XIRCOM=m
  346. +CONFIG_USB_SERIAL_OPTION=m
  347. +CONFIG_USB_SERIAL_OMNINET=m
  348. +CONFIG_USB_SERIAL_OPTICON=m
  349. +CONFIG_USB_SERIAL_VIVOPAY_SERIAL=m
  350. +CONFIG_USB_SERIAL_ZIO=m
  351. +CONFIG_USB_SERIAL_SSU100=m
  352. +CONFIG_USB_SERIAL_DEBUG=m
  353. +CONFIG_USB_EMI62=m
  354. +CONFIG_USB_EMI26=m
  355. +CONFIG_USB_ADUTUX=m
  356. +CONFIG_USB_SEVSEG=m
  357. +CONFIG_USB_RIO500=m
  358. +CONFIG_USB_LEGOTOWER=m
  359. +CONFIG_USB_LCD=m
  360. +CONFIG_USB_LED=m
  361. +CONFIG_USB_CYPRESS_CY7C63=m
  362. +CONFIG_USB_CYTHERM=m
  363. +CONFIG_USB_IDMOUSE=m
  364. +CONFIG_USB_FTDI_ELAN=m
  365. +CONFIG_USB_APPLEDISPLAY=m
  366. +CONFIG_USB_LD=m
  367. +CONFIG_USB_TRANCEVIBRATOR=m
  368. +CONFIG_USB_IOWARRIOR=m
  369. +CONFIG_USB_TEST=m
  370. +CONFIG_USB_ISIGHTFW=m
  371. +CONFIG_USB_YUREX=m
  372. +CONFIG_MMC=y
  373. +CONFIG_MMC_SDHCI=y
  374. +CONFIG_MMC_SDHCI_PLTFM=y
  375. +CONFIG_MMC_SDHCI_BCM2708=y
  376. +CONFIG_MMC_SDHCI_BCM2708_DMA=y
  377. +CONFIG_LEDS_GPIO=y
  378. +CONFIG_LEDS_TRIGGER_TIMER=m
  379. +CONFIG_LEDS_TRIGGER_HEARTBEAT=m
  380. +CONFIG_LEDS_TRIGGER_DEFAULT_ON=m
  381. +CONFIG_UIO=m
  382. +CONFIG_UIO_PDRV=m
  383. +CONFIG_UIO_PDRV_GENIRQ=m
  384. +# CONFIG_IOMMU_SUPPORT is not set
  385. +CONFIG_EXT4_FS=y
  386. +CONFIG_EXT4_FS_POSIX_ACL=y
  387. +CONFIG_EXT4_FS_SECURITY=y
  388. +CONFIG_REISERFS_FS=m
  389. +CONFIG_REISERFS_FS_XATTR=y
  390. +CONFIG_REISERFS_FS_POSIX_ACL=y
  391. +CONFIG_REISERFS_FS_SECURITY=y
  392. +CONFIG_JFS_FS=m
  393. +CONFIG_JFS_POSIX_ACL=y
  394. +CONFIG_JFS_SECURITY=y
  395. +CONFIG_XFS_FS=m
  396. +CONFIG_XFS_QUOTA=y
  397. +CONFIG_XFS_POSIX_ACL=y
  398. +CONFIG_XFS_RT=y
  399. +CONFIG_GFS2_FS=m
  400. +CONFIG_OCFS2_FS=m
  401. +CONFIG_BTRFS_FS=m
  402. +CONFIG_BTRFS_FS_POSIX_ACL=y
  403. +CONFIG_NILFS2_FS=m
  404. +CONFIG_AUTOFS4_FS=y
  405. +CONFIG_FUSE_FS=m
  406. +CONFIG_CUSE=m
  407. +CONFIG_FSCACHE=y
  408. +CONFIG_CACHEFILES=y
  409. +CONFIG_ISO9660_FS=m
  410. +CONFIG_JOLIET=y
  411. +CONFIG_ZISOFS=y
  412. +CONFIG_UDF_FS=m
  413. +CONFIG_MSDOS_FS=y
  414. +CONFIG_VFAT_FS=y
  415. +CONFIG_FAT_DEFAULT_IOCHARSET="ascii"
  416. +CONFIG_NTFS_FS=m
  417. +CONFIG_TMPFS=y
  418. +CONFIG_TMPFS_POSIX_ACL=y
  419. +CONFIG_CONFIGFS_FS=y
  420. +CONFIG_SQUASHFS=m
  421. +CONFIG_SQUASHFS_XATTR=y
  422. +CONFIG_SQUASHFS_LZO=y
  423. +CONFIG_SQUASHFS_XZ=y
  424. +CONFIG_NFS_FS=y
  425. +CONFIG_NFS_V3=y
  426. +CONFIG_NFS_V3_ACL=y
  427. +CONFIG_NFS_V4=y
  428. +CONFIG_ROOT_NFS=y
  429. +CONFIG_NFS_FSCACHE=y
  430. +CONFIG_CIFS=m
  431. +CONFIG_CIFS_WEAK_PW_HASH=y
  432. +CONFIG_CIFS_XATTR=y
  433. +CONFIG_CIFS_POSIX=y
  434. +CONFIG_9P_FS=m
  435. +CONFIG_PARTITION_ADVANCED=y
  436. +CONFIG_MAC_PARTITION=y
  437. +CONFIG_EFI_PARTITION=y
  438. +CONFIG_NLS_DEFAULT="utf8"
  439. +CONFIG_NLS_CODEPAGE_437=y
  440. +CONFIG_NLS_CODEPAGE_737=m
  441. +CONFIG_NLS_CODEPAGE_775=m
  442. +CONFIG_NLS_CODEPAGE_850=m
  443. +CONFIG_NLS_CODEPAGE_852=m
  444. +CONFIG_NLS_CODEPAGE_855=m
  445. +CONFIG_NLS_CODEPAGE_857=m
  446. +CONFIG_NLS_CODEPAGE_860=m
  447. +CONFIG_NLS_CODEPAGE_861=m
  448. +CONFIG_NLS_CODEPAGE_862=m
  449. +CONFIG_NLS_CODEPAGE_863=m
  450. +CONFIG_NLS_CODEPAGE_864=m
  451. +CONFIG_NLS_CODEPAGE_865=m
  452. +CONFIG_NLS_CODEPAGE_866=m
  453. +CONFIG_NLS_CODEPAGE_869=m
  454. +CONFIG_NLS_CODEPAGE_936=m
  455. +CONFIG_NLS_CODEPAGE_950=m
  456. +CONFIG_NLS_CODEPAGE_932=m
  457. +CONFIG_NLS_CODEPAGE_949=m
  458. +CONFIG_NLS_CODEPAGE_874=m
  459. +CONFIG_NLS_ISO8859_8=m
  460. +CONFIG_NLS_CODEPAGE_1250=m
  461. +CONFIG_NLS_CODEPAGE_1251=m
  462. +CONFIG_NLS_ASCII=y
  463. +CONFIG_NLS_ISO8859_1=m
  464. +CONFIG_NLS_ISO8859_2=m
  465. +CONFIG_NLS_ISO8859_3=m
  466. +CONFIG_NLS_ISO8859_4=m
  467. +CONFIG_NLS_ISO8859_5=m
  468. +CONFIG_NLS_ISO8859_6=m
  469. +CONFIG_NLS_ISO8859_7=m
  470. +CONFIG_NLS_ISO8859_9=m
  471. +CONFIG_NLS_ISO8859_13=m
  472. +CONFIG_NLS_ISO8859_14=m
  473. +CONFIG_NLS_ISO8859_15=m
  474. +CONFIG_NLS_KOI8_R=m
  475. +CONFIG_NLS_KOI8_U=m
  476. +CONFIG_NLS_UTF8=m
  477. +# CONFIG_SCHED_DEBUG is not set
  478. +# CONFIG_DEBUG_BUGVERBOSE is not set
  479. +# CONFIG_FTRACE is not set
  480. +# CONFIG_ARM_UNWIND is not set
  481. +CONFIG_CRYPTO_AUTHENC=m
  482. +CONFIG_CRYPTO_SEQIV=m
  483. +CONFIG_CRYPTO_CBC=y
  484. +CONFIG_CRYPTO_HMAC=y
  485. +CONFIG_CRYPTO_XCBC=m
  486. +CONFIG_CRYPTO_MD5=y
  487. +CONFIG_CRYPTO_SHA1=y
  488. +CONFIG_CRYPTO_SHA256=m
  489. +CONFIG_CRYPTO_SHA512=m
  490. +CONFIG_CRYPTO_TGR192=m
  491. +CONFIG_CRYPTO_WP512=m
  492. +CONFIG_CRYPTO_CAST5=m
  493. +CONFIG_CRYPTO_DES=y
  494. +CONFIG_CRYPTO_DEFLATE=m
  495. +# CONFIG_CRYPTO_ANSI_CPRNG is not set
  496. +# CONFIG_CRYPTO_HW is not set
  497. +CONFIG_CRC_ITU_T=y
  498. +CONFIG_LIBCRC32C=y
  499. +CONFIG_I2C=y
  500. +CONFIG_I2C_BOARDINFO=y
  501. +CONFIG_I2C_COMPAT=y
  502. +CONFIG_I2C_CHARDEV=m
  503. +CONFIG_I2C_HELPER_AUTO=y
  504. +CONFIG_I2C_BCM2708=m
  505. +CONFIG_SPI=y
  506. +CONFIG_SPI_MASTER=y
  507. +CONFIG_SPI_BCM2708=m
  508. diff -Nur linux-3.13.11/arch/arm/configs/bcmrpi_defconfig linux-rpi/arch/arm/configs/bcmrpi_defconfig
  509. --- linux-3.13.11/arch/arm/configs/bcmrpi_defconfig 1970-01-01 01:00:00.000000000 +0100
  510. +++ linux-rpi/arch/arm/configs/bcmrpi_defconfig 2014-04-24 15:36:30.902525642 +0200
  511. @@ -0,0 +1,1094 @@
  512. +# CONFIG_ARM_PATCH_PHYS_VIRT is not set
  513. +# CONFIG_LOCALVERSION_AUTO is not set
  514. +CONFIG_SYSVIPC=y
  515. +CONFIG_POSIX_MQUEUE=y
  516. +CONFIG_FHANDLE=y
  517. +CONFIG_AUDIT=y
  518. +CONFIG_NO_HZ=y
  519. +CONFIG_HIGH_RES_TIMERS=y
  520. +CONFIG_BSD_PROCESS_ACCT=y
  521. +CONFIG_BSD_PROCESS_ACCT_V3=y
  522. +CONFIG_TASKSTATS=y
  523. +CONFIG_TASK_DELAY_ACCT=y
  524. +CONFIG_TASK_XACCT=y
  525. +CONFIG_TASK_IO_ACCOUNTING=y
  526. +CONFIG_IKCONFIG=y
  527. +CONFIG_IKCONFIG_PROC=y
  528. +CONFIG_CGROUP_FREEZER=y
  529. +CONFIG_CGROUP_DEVICE=y
  530. +CONFIG_CGROUP_CPUACCT=y
  531. +CONFIG_RESOURCE_COUNTERS=y
  532. +CONFIG_MEMCG=y
  533. +CONFIG_BLK_CGROUP=y
  534. +CONFIG_NAMESPACES=y
  535. +CONFIG_SCHED_AUTOGROUP=y
  536. +CONFIG_RELAY=y
  537. +CONFIG_BLK_DEV_INITRD=y
  538. +CONFIG_EMBEDDED=y
  539. +# CONFIG_COMPAT_BRK is not set
  540. +CONFIG_PROFILING=y
  541. +CONFIG_OPROFILE=m
  542. +CONFIG_KPROBES=y
  543. +CONFIG_JUMP_LABEL=y
  544. +CONFIG_MODULES=y
  545. +CONFIG_MODULE_UNLOAD=y
  546. +CONFIG_MODVERSIONS=y
  547. +CONFIG_MODULE_SRCVERSION_ALL=y
  548. +CONFIG_BLK_DEV_THROTTLING=y
  549. +CONFIG_PARTITION_ADVANCED=y
  550. +CONFIG_MAC_PARTITION=y
  551. +CONFIG_CFQ_GROUP_IOSCHED=y
  552. +CONFIG_ARCH_BCM2708=y
  553. +CONFIG_PREEMPT=y
  554. +CONFIG_AEABI=y
  555. +CONFIG_CLEANCACHE=y
  556. +CONFIG_FRONTSWAP=y
  557. +CONFIG_CMA=y
  558. +CONFIG_UACCESS_WITH_MEMCPY=y
  559. +CONFIG_SECCOMP=y
  560. +CONFIG_CC_STACKPROTECTOR=y
  561. +CONFIG_ZBOOT_ROM_TEXT=0x0
  562. +CONFIG_ZBOOT_ROM_BSS=0x0
  563. +CONFIG_CMDLINE="console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait"
  564. +CONFIG_KEXEC=y
  565. +CONFIG_CPU_FREQ=y
  566. +CONFIG_CPU_FREQ_STAT=m
  567. +CONFIG_CPU_FREQ_STAT_DETAILS=y
  568. +CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE=y
  569. +CONFIG_CPU_FREQ_GOV_PERFORMANCE=y
  570. +CONFIG_CPU_FREQ_GOV_USERSPACE=y
  571. +CONFIG_CPU_FREQ_GOV_ONDEMAND=y
  572. +CONFIG_CPU_FREQ_GOV_CONSERVATIVE=y
  573. +CONFIG_CPU_IDLE=y
  574. +CONFIG_VFP=y
  575. +CONFIG_BINFMT_MISC=m
  576. +CONFIG_NET=y
  577. +CONFIG_PACKET=y
  578. +CONFIG_UNIX=y
  579. +CONFIG_XFRM_USER=y
  580. +CONFIG_NET_KEY=m
  581. +CONFIG_INET=y
  582. +CONFIG_IP_MULTICAST=y
  583. +CONFIG_IP_ADVANCED_ROUTER=y
  584. +CONFIG_IP_MULTIPLE_TABLES=y
  585. +CONFIG_IP_ROUTE_MULTIPATH=y
  586. +CONFIG_IP_ROUTE_VERBOSE=y
  587. +CONFIG_IP_PNP=y
  588. +CONFIG_IP_PNP_DHCP=y
  589. +CONFIG_IP_PNP_RARP=y
  590. +CONFIG_NET_IPIP=m
  591. +CONFIG_NET_IPGRE_DEMUX=m
  592. +CONFIG_NET_IPGRE=m
  593. +CONFIG_IP_MROUTE=y
  594. +CONFIG_IP_MROUTE_MULTIPLE_TABLES=y
  595. +CONFIG_IP_PIMSM_V1=y
  596. +CONFIG_IP_PIMSM_V2=y
  597. +CONFIG_SYN_COOKIES=y
  598. +CONFIG_INET_AH=m
  599. +CONFIG_INET_ESP=m
  600. +CONFIG_INET_IPCOMP=m
  601. +CONFIG_INET_XFRM_MODE_TRANSPORT=m
  602. +CONFIG_INET_XFRM_MODE_TUNNEL=m
  603. +CONFIG_INET_XFRM_MODE_BEET=m
  604. +CONFIG_INET_LRO=m
  605. +CONFIG_INET_DIAG=m
  606. +CONFIG_INET6_AH=m
  607. +CONFIG_INET6_ESP=m
  608. +CONFIG_INET6_IPCOMP=m
  609. +CONFIG_IPV6_TUNNEL=m
  610. +CONFIG_IPV6_MULTIPLE_TABLES=y
  611. +CONFIG_IPV6_MROUTE=y
  612. +CONFIG_IPV6_MROUTE_MULTIPLE_TABLES=y
  613. +CONFIG_IPV6_PIMSM_V2=y
  614. +CONFIG_NETFILTER=y
  615. +CONFIG_NF_CONNTRACK=m
  616. +CONFIG_NF_CONNTRACK_ZONES=y
  617. +CONFIG_NF_CONNTRACK_EVENTS=y
  618. +CONFIG_NF_CONNTRACK_TIMESTAMP=y
  619. +CONFIG_NF_CT_PROTO_DCCP=m
  620. +CONFIG_NF_CT_PROTO_UDPLITE=m
  621. +CONFIG_NF_CONNTRACK_AMANDA=m
  622. +CONFIG_NF_CONNTRACK_FTP=m
  623. +CONFIG_NF_CONNTRACK_H323=m
  624. +CONFIG_NF_CONNTRACK_IRC=m
  625. +CONFIG_NF_CONNTRACK_NETBIOS_NS=m
  626. +CONFIG_NF_CONNTRACK_SNMP=m
  627. +CONFIG_NF_CONNTRACK_PPTP=m
  628. +CONFIG_NF_CONNTRACK_SANE=m
  629. +CONFIG_NF_CONNTRACK_SIP=m
  630. +CONFIG_NF_CONNTRACK_TFTP=m
  631. +CONFIG_NF_CT_NETLINK=m
  632. +CONFIG_NETFILTER_XT_SET=m
  633. +CONFIG_NETFILTER_XT_TARGET_AUDIT=m
  634. +CONFIG_NETFILTER_XT_TARGET_CHECKSUM=m
  635. +CONFIG_NETFILTER_XT_TARGET_CLASSIFY=m
  636. +CONFIG_NETFILTER_XT_TARGET_CONNMARK=m
  637. +CONFIG_NETFILTER_XT_TARGET_DSCP=m
  638. +CONFIG_NETFILTER_XT_TARGET_HMARK=m
  639. +CONFIG_NETFILTER_XT_TARGET_IDLETIMER=m
  640. +CONFIG_NETFILTER_XT_TARGET_LED=m
  641. +CONFIG_NETFILTER_XT_TARGET_LOG=m
  642. +CONFIG_NETFILTER_XT_TARGET_MARK=m
  643. +CONFIG_NETFILTER_XT_TARGET_NFLOG=m
  644. +CONFIG_NETFILTER_XT_TARGET_NFQUEUE=m
  645. +CONFIG_NETFILTER_XT_TARGET_NOTRACK=m
  646. +CONFIG_NETFILTER_XT_TARGET_TEE=m
  647. +CONFIG_NETFILTER_XT_TARGET_TPROXY=m
  648. +CONFIG_NETFILTER_XT_TARGET_TRACE=m
  649. +CONFIG_NETFILTER_XT_TARGET_TCPMSS=m
  650. +CONFIG_NETFILTER_XT_TARGET_TCPOPTSTRIP=m
  651. +CONFIG_NETFILTER_XT_MATCH_ADDRTYPE=m
  652. +CONFIG_NETFILTER_XT_MATCH_BPF=m
  653. +CONFIG_NETFILTER_XT_MATCH_CLUSTER=m
  654. +CONFIG_NETFILTER_XT_MATCH_COMMENT=m
  655. +CONFIG_NETFILTER_XT_MATCH_CONNBYTES=m
  656. +CONFIG_NETFILTER_XT_MATCH_CONNLABEL=m
  657. +CONFIG_NETFILTER_XT_MATCH_CONNLIMIT=m
  658. +CONFIG_NETFILTER_XT_MATCH_CONNMARK=m
  659. +CONFIG_NETFILTER_XT_MATCH_CONNTRACK=m
  660. +CONFIG_NETFILTER_XT_MATCH_CPU=m
  661. +CONFIG_NETFILTER_XT_MATCH_DCCP=m
  662. +CONFIG_NETFILTER_XT_MATCH_DEVGROUP=m
  663. +CONFIG_NETFILTER_XT_MATCH_DSCP=m
  664. +CONFIG_NETFILTER_XT_MATCH_ESP=m
  665. +CONFIG_NETFILTER_XT_MATCH_HASHLIMIT=m
  666. +CONFIG_NETFILTER_XT_MATCH_HELPER=m
  667. +CONFIG_NETFILTER_XT_MATCH_IPRANGE=m
  668. +CONFIG_NETFILTER_XT_MATCH_IPVS=m
  669. +CONFIG_NETFILTER_XT_MATCH_LENGTH=m
  670. +CONFIG_NETFILTER_XT_MATCH_LIMIT=m
  671. +CONFIG_NETFILTER_XT_MATCH_MAC=m
  672. +CONFIG_NETFILTER_XT_MATCH_MARK=m
  673. +CONFIG_NETFILTER_XT_MATCH_MULTIPORT=m
  674. +CONFIG_NETFILTER_XT_MATCH_NFACCT=m
  675. +CONFIG_NETFILTER_XT_MATCH_OSF=m
  676. +CONFIG_NETFILTER_XT_MATCH_OWNER=m
  677. +CONFIG_NETFILTER_XT_MATCH_POLICY=m
  678. +CONFIG_NETFILTER_XT_MATCH_PHYSDEV=m
  679. +CONFIG_NETFILTER_XT_MATCH_PKTTYPE=m
  680. +CONFIG_NETFILTER_XT_MATCH_QUOTA=m
  681. +CONFIG_NETFILTER_XT_MATCH_RATEEST=m
  682. +CONFIG_NETFILTER_XT_MATCH_REALM=m
  683. +CONFIG_NETFILTER_XT_MATCH_RECENT=m
  684. +CONFIG_NETFILTER_XT_MATCH_SOCKET=m
  685. +CONFIG_NETFILTER_XT_MATCH_STATE=m
  686. +CONFIG_NETFILTER_XT_MATCH_STATISTIC=m
  687. +CONFIG_NETFILTER_XT_MATCH_STRING=m
  688. +CONFIG_NETFILTER_XT_MATCH_TCPMSS=m
  689. +CONFIG_NETFILTER_XT_MATCH_TIME=m
  690. +CONFIG_NETFILTER_XT_MATCH_U32=m
  691. +CONFIG_IP_SET=m
  692. +CONFIG_IP_SET_BITMAP_IP=m
  693. +CONFIG_IP_SET_BITMAP_IPMAC=m
  694. +CONFIG_IP_SET_BITMAP_PORT=m
  695. +CONFIG_IP_SET_HASH_IP=m
  696. +CONFIG_IP_SET_HASH_IPPORT=m
  697. +CONFIG_IP_SET_HASH_IPPORTIP=m
  698. +CONFIG_IP_SET_HASH_IPPORTNET=m
  699. +CONFIG_IP_SET_HASH_NET=m
  700. +CONFIG_IP_SET_HASH_NETPORT=m
  701. +CONFIG_IP_SET_HASH_NETIFACE=m
  702. +CONFIG_IP_SET_LIST_SET=m
  703. +CONFIG_IP_VS=m
  704. +CONFIG_IP_VS_PROTO_TCP=y
  705. +CONFIG_IP_VS_PROTO_UDP=y
  706. +CONFIG_IP_VS_PROTO_ESP=y
  707. +CONFIG_IP_VS_PROTO_AH=y
  708. +CONFIG_IP_VS_PROTO_SCTP=y
  709. +CONFIG_IP_VS_RR=m
  710. +CONFIG_IP_VS_WRR=m
  711. +CONFIG_IP_VS_LC=m
  712. +CONFIG_IP_VS_WLC=m
  713. +CONFIG_IP_VS_LBLC=m
  714. +CONFIG_IP_VS_LBLCR=m
  715. +CONFIG_IP_VS_DH=m
  716. +CONFIG_IP_VS_SH=m
  717. +CONFIG_IP_VS_SED=m
  718. +CONFIG_IP_VS_NQ=m
  719. +CONFIG_IP_VS_FTP=m
  720. +CONFIG_IP_VS_PE_SIP=m
  721. +CONFIG_NF_CONNTRACK_IPV4=m
  722. +CONFIG_IP_NF_IPTABLES=m
  723. +CONFIG_IP_NF_MATCH_AH=m
  724. +CONFIG_IP_NF_MATCH_ECN=m
  725. +CONFIG_IP_NF_MATCH_TTL=m
  726. +CONFIG_IP_NF_FILTER=m
  727. +CONFIG_IP_NF_TARGET_REJECT=m
  728. +CONFIG_IP_NF_TARGET_ULOG=m
  729. +CONFIG_NF_NAT_IPV4=m
  730. +CONFIG_IP_NF_TARGET_MASQUERADE=m
  731. +CONFIG_IP_NF_TARGET_NETMAP=m
  732. +CONFIG_IP_NF_TARGET_REDIRECT=m
  733. +CONFIG_IP_NF_MANGLE=m
  734. +CONFIG_IP_NF_TARGET_ECN=m
  735. +CONFIG_IP_NF_TARGET_TTL=m
  736. +CONFIG_IP_NF_RAW=m
  737. +CONFIG_IP_NF_ARPTABLES=m
  738. +CONFIG_IP_NF_ARPFILTER=m
  739. +CONFIG_IP_NF_ARP_MANGLE=m
  740. +CONFIG_NF_CONNTRACK_IPV6=m
  741. +CONFIG_IP6_NF_IPTABLES=m
  742. +CONFIG_IP6_NF_MATCH_AH=m
  743. +CONFIG_IP6_NF_MATCH_EUI64=m
  744. +CONFIG_IP6_NF_MATCH_FRAG=m
  745. +CONFIG_IP6_NF_MATCH_OPTS=m
  746. +CONFIG_IP6_NF_MATCH_HL=m
  747. +CONFIG_IP6_NF_MATCH_IPV6HEADER=m
  748. +CONFIG_IP6_NF_MATCH_MH=m
  749. +CONFIG_IP6_NF_MATCH_RT=m
  750. +CONFIG_IP6_NF_TARGET_HL=m
  751. +CONFIG_IP6_NF_FILTER=m
  752. +CONFIG_IP6_NF_TARGET_REJECT=m
  753. +CONFIG_IP6_NF_MANGLE=m
  754. +CONFIG_IP6_NF_RAW=m
  755. +CONFIG_NF_NAT_IPV6=m
  756. +CONFIG_IP6_NF_TARGET_MASQUERADE=m
  757. +CONFIG_IP6_NF_TARGET_NPT=m
  758. +CONFIG_BRIDGE_NF_EBTABLES=m
  759. +CONFIG_BRIDGE_EBT_BROUTE=m
  760. +CONFIG_BRIDGE_EBT_T_FILTER=m
  761. +CONFIG_BRIDGE_EBT_T_NAT=m
  762. +CONFIG_BRIDGE_EBT_802_3=m
  763. +CONFIG_BRIDGE_EBT_AMONG=m
  764. +CONFIG_BRIDGE_EBT_ARP=m
  765. +CONFIG_BRIDGE_EBT_IP=m
  766. +CONFIG_BRIDGE_EBT_IP6=m
  767. +CONFIG_BRIDGE_EBT_LIMIT=m
  768. +CONFIG_BRIDGE_EBT_MARK=m
  769. +CONFIG_BRIDGE_EBT_PKTTYPE=m
  770. +CONFIG_BRIDGE_EBT_STP=m
  771. +CONFIG_BRIDGE_EBT_VLAN=m
  772. +CONFIG_BRIDGE_EBT_ARPREPLY=m
  773. +CONFIG_BRIDGE_EBT_DNAT=m
  774. +CONFIG_BRIDGE_EBT_MARK_T=m
  775. +CONFIG_BRIDGE_EBT_REDIRECT=m
  776. +CONFIG_BRIDGE_EBT_SNAT=m
  777. +CONFIG_BRIDGE_EBT_LOG=m
  778. +CONFIG_BRIDGE_EBT_ULOG=m
  779. +CONFIG_BRIDGE_EBT_NFLOG=m
  780. +CONFIG_SCTP_COOKIE_HMAC_SHA1=y
  781. +CONFIG_L2TP=m
  782. +CONFIG_L2TP_V3=y
  783. +CONFIG_L2TP_IP=m
  784. +CONFIG_L2TP_ETH=m
  785. +CONFIG_BRIDGE=m
  786. +CONFIG_VLAN_8021Q=m
  787. +CONFIG_VLAN_8021Q_GVRP=y
  788. +CONFIG_ATALK=m
  789. +CONFIG_NET_SCHED=y
  790. +CONFIG_NET_SCH_CBQ=m
  791. +CONFIG_NET_SCH_HTB=m
  792. +CONFIG_NET_SCH_HFSC=m
  793. +CONFIG_NET_SCH_PRIO=m
  794. +CONFIG_NET_SCH_MULTIQ=m
  795. +CONFIG_NET_SCH_RED=m
  796. +CONFIG_NET_SCH_SFB=m
  797. +CONFIG_NET_SCH_SFQ=m
  798. +CONFIG_NET_SCH_TEQL=m
  799. +CONFIG_NET_SCH_TBF=m
  800. +CONFIG_NET_SCH_GRED=m
  801. +CONFIG_NET_SCH_DSMARK=m
  802. +CONFIG_NET_SCH_NETEM=m
  803. +CONFIG_NET_SCH_DRR=m
  804. +CONFIG_NET_SCH_MQPRIO=m
  805. +CONFIG_NET_SCH_CHOKE=m
  806. +CONFIG_NET_SCH_QFQ=m
  807. +CONFIG_NET_SCH_CODEL=m
  808. +CONFIG_NET_SCH_FQ_CODEL=m
  809. +CONFIG_NET_SCH_INGRESS=m
  810. +CONFIG_NET_SCH_PLUG=m
  811. +CONFIG_NET_CLS_BASIC=m
  812. +CONFIG_NET_CLS_TCINDEX=m
  813. +CONFIG_NET_CLS_ROUTE4=m
  814. +CONFIG_NET_CLS_FW=m
  815. +CONFIG_NET_CLS_U32=m
  816. +CONFIG_CLS_U32_MARK=y
  817. +CONFIG_NET_CLS_RSVP=m
  818. +CONFIG_NET_CLS_RSVP6=m
  819. +CONFIG_NET_CLS_FLOW=m
  820. +CONFIG_NET_CLS_CGROUP=m
  821. +CONFIG_NET_EMATCH=y
  822. +CONFIG_NET_EMATCH_CMP=m
  823. +CONFIG_NET_EMATCH_NBYTE=m
  824. +CONFIG_NET_EMATCH_U32=m
  825. +CONFIG_NET_EMATCH_META=m
  826. +CONFIG_NET_EMATCH_TEXT=m
  827. +CONFIG_NET_EMATCH_IPSET=m
  828. +CONFIG_NET_CLS_ACT=y
  829. +CONFIG_NET_ACT_POLICE=m
  830. +CONFIG_NET_ACT_GACT=m
  831. +CONFIG_GACT_PROB=y
  832. +CONFIG_NET_ACT_MIRRED=m
  833. +CONFIG_NET_ACT_IPT=m
  834. +CONFIG_NET_ACT_NAT=m
  835. +CONFIG_NET_ACT_PEDIT=m
  836. +CONFIG_NET_ACT_SIMP=m
  837. +CONFIG_NET_ACT_SKBEDIT=m
  838. +CONFIG_NET_ACT_CSUM=m
  839. +CONFIG_BATMAN_ADV=m
  840. +CONFIG_OPENVSWITCH=m
  841. +CONFIG_NET_PKTGEN=m
  842. +CONFIG_HAMRADIO=y
  843. +CONFIG_AX25=m
  844. +CONFIG_NETROM=m
  845. +CONFIG_ROSE=m
  846. +CONFIG_MKISS=m
  847. +CONFIG_6PACK=m
  848. +CONFIG_BPQETHER=m
  849. +CONFIG_BAYCOM_SER_FDX=m
  850. +CONFIG_BAYCOM_SER_HDX=m
  851. +CONFIG_YAM=m
  852. +CONFIG_IRDA=m
  853. +CONFIG_IRLAN=m
  854. +CONFIG_IRNET=m
  855. +CONFIG_IRCOMM=m
  856. +CONFIG_IRDA_ULTRA=y
  857. +CONFIG_IRDA_CACHE_LAST_LSAP=y
  858. +CONFIG_IRDA_FAST_RR=y
  859. +CONFIG_IRTTY_SIR=m
  860. +CONFIG_KINGSUN_DONGLE=m
  861. +CONFIG_KSDAZZLE_DONGLE=m
  862. +CONFIG_KS959_DONGLE=m
  863. +CONFIG_USB_IRDA=m
  864. +CONFIG_SIGMATEL_FIR=m
  865. +CONFIG_MCS_FIR=m
  866. +CONFIG_BT=m
  867. +CONFIG_BT_RFCOMM=m
  868. +CONFIG_BT_RFCOMM_TTY=y
  869. +CONFIG_BT_BNEP=m
  870. +CONFIG_BT_BNEP_MC_FILTER=y
  871. +CONFIG_BT_BNEP_PROTO_FILTER=y
  872. +CONFIG_BT_HIDP=m
  873. +CONFIG_BT_HCIBTUSB=m
  874. +CONFIG_BT_HCIBCM203X=m
  875. +CONFIG_BT_HCIBPA10X=m
  876. +CONFIG_BT_HCIBFUSB=m
  877. +CONFIG_BT_HCIVHCI=m
  878. +CONFIG_BT_MRVL=m
  879. +CONFIG_BT_MRVL_SDIO=m
  880. +CONFIG_BT_ATH3K=m
  881. +CONFIG_BT_WILINK=m
  882. +CONFIG_CFG80211=m
  883. +CONFIG_CFG80211_WEXT=y
  884. +CONFIG_MAC80211=m
  885. +CONFIG_MAC80211_RC_PID=y
  886. +CONFIG_MAC80211_MESH=y
  887. +CONFIG_WIMAX=m
  888. +CONFIG_RFKILL=m
  889. +CONFIG_RFKILL_INPUT=y
  890. +CONFIG_NET_9P=m
  891. +CONFIG_NFC=m
  892. +CONFIG_NFC_PN533=m
  893. +CONFIG_DEVTMPFS=y
  894. +CONFIG_DEVTMPFS_MOUNT=y
  895. +CONFIG_BLK_DEV_LOOP=y
  896. +CONFIG_BLK_DEV_CRYPTOLOOP=m
  897. +CONFIG_BLK_DEV_DRBD=m
  898. +CONFIG_BLK_DEV_NBD=m
  899. +CONFIG_BLK_DEV_RAM=y
  900. +CONFIG_CDROM_PKTCDVD=m
  901. +CONFIG_SCSI=y
  902. +# CONFIG_SCSI_PROC_FS is not set
  903. +CONFIG_BLK_DEV_SD=y
  904. +CONFIG_CHR_DEV_ST=m
  905. +CONFIG_CHR_DEV_OSST=m
  906. +CONFIG_BLK_DEV_SR=m
  907. +CONFIG_CHR_DEV_SG=m
  908. +CONFIG_SCSI_MULTI_LUN=y
  909. +CONFIG_SCSI_ISCSI_ATTRS=y
  910. +CONFIG_ISCSI_TCP=m
  911. +CONFIG_ISCSI_BOOT_SYSFS=m
  912. +CONFIG_MD=y
  913. +CONFIG_MD_LINEAR=m
  914. +CONFIG_MD_RAID0=m
  915. +CONFIG_BLK_DEV_DM=m
  916. +CONFIG_DM_CRYPT=m
  917. +CONFIG_DM_SNAPSHOT=m
  918. +CONFIG_DM_MIRROR=m
  919. +CONFIG_DM_LOG_USERSPACE=m
  920. +CONFIG_DM_RAID=m
  921. +CONFIG_DM_ZERO=m
  922. +CONFIG_DM_DELAY=m
  923. +CONFIG_NETDEVICES=y
  924. +CONFIG_BONDING=m
  925. +CONFIG_DUMMY=m
  926. +CONFIG_IFB=m
  927. +CONFIG_MACVLAN=m
  928. +CONFIG_NETCONSOLE=m
  929. +CONFIG_TUN=m
  930. +CONFIG_VETH=m
  931. +CONFIG_MDIO_BITBANG=m
  932. +CONFIG_PPP=m
  933. +CONFIG_PPP_BSDCOMP=m
  934. +CONFIG_PPP_DEFLATE=m
  935. +CONFIG_PPP_FILTER=y
  936. +CONFIG_PPP_MPPE=m
  937. +CONFIG_PPP_MULTILINK=y
  938. +CONFIG_PPPOE=m
  939. +CONFIG_PPPOL2TP=m
  940. +CONFIG_PPP_ASYNC=m
  941. +CONFIG_PPP_SYNC_TTY=m
  942. +CONFIG_SLIP=m
  943. +CONFIG_SLIP_COMPRESSED=y
  944. +CONFIG_SLIP_SMART=y
  945. +CONFIG_USB_CATC=m
  946. +CONFIG_USB_KAWETH=m
  947. +CONFIG_USB_PEGASUS=m
  948. +CONFIG_USB_RTL8150=m
  949. +CONFIG_USB_RTL8152=m
  950. +CONFIG_USB_USBNET=y
  951. +CONFIG_USB_NET_AX8817X=m
  952. +CONFIG_USB_NET_AX88179_178A=m
  953. +CONFIG_USB_NET_CDCETHER=m
  954. +CONFIG_USB_NET_CDC_EEM=m
  955. +CONFIG_USB_NET_CDC_NCM=m
  956. +CONFIG_USB_NET_CDC_MBIM=m
  957. +CONFIG_USB_NET_DM9601=m
  958. +CONFIG_USB_NET_SMSC75XX=m
  959. +CONFIG_USB_NET_SMSC95XX=y
  960. +CONFIG_USB_NET_GL620A=m
  961. +CONFIG_USB_NET_NET1080=m
  962. +CONFIG_USB_NET_PLUSB=m
  963. +CONFIG_USB_NET_MCS7830=m
  964. +CONFIG_USB_NET_CDC_SUBSET=m
  965. +CONFIG_USB_ALI_M5632=y
  966. +CONFIG_USB_AN2720=y
  967. +CONFIG_USB_EPSON2888=y
  968. +CONFIG_USB_KC2190=y
  969. +CONFIG_USB_NET_ZAURUS=m
  970. +CONFIG_USB_NET_CX82310_ETH=m
  971. +CONFIG_USB_NET_KALMIA=m
  972. +CONFIG_USB_NET_QMI_WWAN=m
  973. +CONFIG_USB_NET_INT51X1=m
  974. +CONFIG_USB_IPHETH=m
  975. +CONFIG_USB_SIERRA_NET=m
  976. +CONFIG_USB_VL600=m
  977. +CONFIG_LIBERTAS_THINFIRM=m
  978. +CONFIG_LIBERTAS_THINFIRM_USB=m
  979. +CONFIG_AT76C50X_USB=m
  980. +CONFIG_USB_ZD1201=m
  981. +CONFIG_USB_NET_RNDIS_WLAN=m
  982. +CONFIG_RTL8187=m
  983. +CONFIG_MAC80211_HWSIM=m
  984. +CONFIG_ATH_CARDS=m
  985. +CONFIG_ATH9K=m
  986. +CONFIG_ATH9K_HTC=m
  987. +CONFIG_CARL9170=m
  988. +CONFIG_ATH6KL=m
  989. +CONFIG_ATH6KL_USB=m
  990. +CONFIG_AR5523=m
  991. +CONFIG_B43=m
  992. +# CONFIG_B43_PHY_N is not set
  993. +CONFIG_B43LEGACY=m
  994. +CONFIG_HOSTAP=m
  995. +CONFIG_LIBERTAS=m
  996. +CONFIG_LIBERTAS_USB=m
  997. +CONFIG_LIBERTAS_SDIO=m
  998. +CONFIG_P54_COMMON=m
  999. +CONFIG_P54_USB=m
  1000. +CONFIG_RT2X00=m
  1001. +CONFIG_RT2500USB=m
  1002. +CONFIG_RT73USB=m
  1003. +CONFIG_RT2800USB=m
  1004. +CONFIG_RT2800USB_RT3573=y
  1005. +CONFIG_RT2800USB_RT53XX=y
  1006. +CONFIG_RT2800USB_RT55XX=y
  1007. +CONFIG_RT2800USB_UNKNOWN=y
  1008. +CONFIG_RTL8192CU=m
  1009. +CONFIG_ZD1211RW=m
  1010. +CONFIG_MWIFIEX=m
  1011. +CONFIG_MWIFIEX_SDIO=m
  1012. +CONFIG_WIMAX_I2400M_USB=m
  1013. +CONFIG_INPUT_POLLDEV=m
  1014. +# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
  1015. +CONFIG_INPUT_JOYDEV=m
  1016. +CONFIG_INPUT_EVDEV=m
  1017. +# CONFIG_INPUT_KEYBOARD is not set
  1018. +# CONFIG_INPUT_MOUSE is not set
  1019. +CONFIG_INPUT_JOYSTICK=y
  1020. +CONFIG_JOYSTICK_IFORCE=m
  1021. +CONFIG_JOYSTICK_IFORCE_USB=y
  1022. +CONFIG_JOYSTICK_XPAD=m
  1023. +CONFIG_JOYSTICK_XPAD_FF=y
  1024. +CONFIG_INPUT_MISC=y
  1025. +CONFIG_INPUT_AD714X=m
  1026. +CONFIG_INPUT_ATI_REMOTE2=m
  1027. +CONFIG_INPUT_KEYSPAN_REMOTE=m
  1028. +CONFIG_INPUT_POWERMATE=m
  1029. +CONFIG_INPUT_YEALINK=m
  1030. +CONFIG_INPUT_CM109=m
  1031. +CONFIG_INPUT_UINPUT=m
  1032. +CONFIG_INPUT_GPIO_ROTARY_ENCODER=m
  1033. +CONFIG_INPUT_ADXL34X=m
  1034. +CONFIG_INPUT_CMA3000=m
  1035. +CONFIG_SERIO=m
  1036. +CONFIG_SERIO_RAW=m
  1037. +CONFIG_GAMEPORT=m
  1038. +CONFIG_GAMEPORT_NS558=m
  1039. +CONFIG_GAMEPORT_L4=m
  1040. +# CONFIG_LEGACY_PTYS is not set
  1041. +# CONFIG_DEVKMEM is not set
  1042. +CONFIG_SERIAL_AMBA_PL011=y
  1043. +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
  1044. +CONFIG_TTY_PRINTK=y
  1045. +CONFIG_HW_RANDOM=y
  1046. +CONFIG_HW_RANDOM_BCM2708=m
  1047. +CONFIG_RAW_DRIVER=y
  1048. +CONFIG_BRCM_CHAR_DRIVERS=y
  1049. +CONFIG_BCM_VC_CMA=y
  1050. +CONFIG_I2C=y
  1051. +CONFIG_I2C_CHARDEV=m
  1052. +CONFIG_I2C_BCM2708=m
  1053. +CONFIG_SPI=y
  1054. +CONFIG_SPI_BCM2708=m
  1055. +CONFIG_SPI_SPIDEV=y
  1056. +CONFIG_GPIO_SYSFS=y
  1057. +CONFIG_W1=m
  1058. +CONFIG_W1_MASTER_DS2490=m
  1059. +CONFIG_W1_MASTER_DS2482=m
  1060. +CONFIG_W1_MASTER_DS1WM=m
  1061. +CONFIG_W1_MASTER_GPIO=m
  1062. +CONFIG_W1_SLAVE_THERM=m
  1063. +CONFIG_W1_SLAVE_SMEM=m
  1064. +CONFIG_W1_SLAVE_DS2408=m
  1065. +CONFIG_W1_SLAVE_DS2413=m
  1066. +CONFIG_W1_SLAVE_DS2423=m
  1067. +CONFIG_W1_SLAVE_DS2431=m
  1068. +CONFIG_W1_SLAVE_DS2433=m
  1069. +CONFIG_W1_SLAVE_DS2760=m
  1070. +CONFIG_W1_SLAVE_DS2780=m
  1071. +CONFIG_W1_SLAVE_DS2781=m
  1072. +CONFIG_W1_SLAVE_DS28E04=m
  1073. +CONFIG_W1_SLAVE_BQ27000=m
  1074. +CONFIG_BATTERY_DS2760=m
  1075. +# CONFIG_HWMON is not set
  1076. +CONFIG_THERMAL=y
  1077. +CONFIG_THERMAL_BCM2835=y
  1078. +CONFIG_WATCHDOG=y
  1079. +CONFIG_BCM2708_WDT=m
  1080. +CONFIG_MEDIA_SUPPORT=m
  1081. +CONFIG_MEDIA_CAMERA_SUPPORT=y
  1082. +CONFIG_MEDIA_ANALOG_TV_SUPPORT=y
  1083. +CONFIG_MEDIA_DIGITAL_TV_SUPPORT=y
  1084. +CONFIG_MEDIA_RADIO_SUPPORT=y
  1085. +CONFIG_MEDIA_RC_SUPPORT=y
  1086. +CONFIG_MEDIA_CONTROLLER=y
  1087. +CONFIG_LIRC=m
  1088. +CONFIG_RC_DEVICES=y
  1089. +CONFIG_RC_ATI_REMOTE=m
  1090. +CONFIG_IR_IMON=m
  1091. +CONFIG_IR_MCEUSB=m
  1092. +CONFIG_IR_REDRAT3=m
  1093. +CONFIG_IR_STREAMZAP=m
  1094. +CONFIG_IR_IGUANA=m
  1095. +CONFIG_IR_TTUSBIR=m
  1096. +CONFIG_RC_LOOPBACK=m
  1097. +CONFIG_IR_GPIO_CIR=m
  1098. +CONFIG_MEDIA_USB_SUPPORT=y
  1099. +CONFIG_USB_VIDEO_CLASS=m
  1100. +CONFIG_USB_M5602=m
  1101. +CONFIG_USB_STV06XX=m
  1102. +CONFIG_USB_GL860=m
  1103. +CONFIG_USB_GSPCA_BENQ=m
  1104. +CONFIG_USB_GSPCA_CONEX=m
  1105. +CONFIG_USB_GSPCA_CPIA1=m
  1106. +CONFIG_USB_GSPCA_ETOMS=m
  1107. +CONFIG_USB_GSPCA_FINEPIX=m
  1108. +CONFIG_USB_GSPCA_JEILINJ=m
  1109. +CONFIG_USB_GSPCA_JL2005BCD=m
  1110. +CONFIG_USB_GSPCA_KINECT=m
  1111. +CONFIG_USB_GSPCA_KONICA=m
  1112. +CONFIG_USB_GSPCA_MARS=m
  1113. +CONFIG_USB_GSPCA_MR97310A=m
  1114. +CONFIG_USB_GSPCA_NW80X=m
  1115. +CONFIG_USB_GSPCA_OV519=m
  1116. +CONFIG_USB_GSPCA_OV534=m
  1117. +CONFIG_USB_GSPCA_OV534_9=m
  1118. +CONFIG_USB_GSPCA_PAC207=m
  1119. +CONFIG_USB_GSPCA_PAC7302=m
  1120. +CONFIG_USB_GSPCA_PAC7311=m
  1121. +CONFIG_USB_GSPCA_SE401=m
  1122. +CONFIG_USB_GSPCA_SN9C2028=m
  1123. +CONFIG_USB_GSPCA_SN9C20X=m
  1124. +CONFIG_USB_GSPCA_SONIXB=m
  1125. +CONFIG_USB_GSPCA_SONIXJ=m
  1126. +CONFIG_USB_GSPCA_SPCA500=m
  1127. +CONFIG_USB_GSPCA_SPCA501=m
  1128. +CONFIG_USB_GSPCA_SPCA505=m
  1129. +CONFIG_USB_GSPCA_SPCA506=m
  1130. +CONFIG_USB_GSPCA_SPCA508=m
  1131. +CONFIG_USB_GSPCA_SPCA561=m
  1132. +CONFIG_USB_GSPCA_SPCA1528=m
  1133. +CONFIG_USB_GSPCA_SQ905=m
  1134. +CONFIG_USB_GSPCA_SQ905C=m
  1135. +CONFIG_USB_GSPCA_SQ930X=m
  1136. +CONFIG_USB_GSPCA_STK014=m
  1137. +CONFIG_USB_GSPCA_STV0680=m
  1138. +CONFIG_USB_GSPCA_SUNPLUS=m
  1139. +CONFIG_USB_GSPCA_T613=m
  1140. +CONFIG_USB_GSPCA_TOPRO=m
  1141. +CONFIG_USB_GSPCA_TV8532=m
  1142. +CONFIG_USB_GSPCA_VC032X=m
  1143. +CONFIG_USB_GSPCA_VICAM=m
  1144. +CONFIG_USB_GSPCA_XIRLINK_CIT=m
  1145. +CONFIG_USB_GSPCA_ZC3XX=m
  1146. +CONFIG_USB_PWC=m
  1147. +CONFIG_VIDEO_CPIA2=m
  1148. +CONFIG_USB_ZR364XX=m
  1149. +CONFIG_USB_STKWEBCAM=m
  1150. +CONFIG_USB_S2255=m
  1151. +CONFIG_USB_SN9C102=m
  1152. +CONFIG_VIDEO_PVRUSB2=m
  1153. +CONFIG_VIDEO_HDPVR=m
  1154. +CONFIG_VIDEO_TLG2300=m
  1155. +CONFIG_VIDEO_USBVISION=m
  1156. +CONFIG_VIDEO_AU0828=m
  1157. +CONFIG_VIDEO_CX231XX=m
  1158. +CONFIG_VIDEO_CX231XX_ALSA=m
  1159. +CONFIG_VIDEO_CX231XX_DVB=m
  1160. +CONFIG_VIDEO_TM6000=m
  1161. +CONFIG_VIDEO_TM6000_ALSA=m
  1162. +CONFIG_VIDEO_TM6000_DVB=m
  1163. +CONFIG_DVB_USB=m
  1164. +CONFIG_DVB_USB_A800=m
  1165. +CONFIG_DVB_USB_DIBUSB_MB=m
  1166. +CONFIG_DVB_USB_DIBUSB_MB_FAULTY=y
  1167. +CONFIG_DVB_USB_DIBUSB_MC=m
  1168. +CONFIG_DVB_USB_DIB0700=m
  1169. +CONFIG_DVB_USB_UMT_010=m
  1170. +CONFIG_DVB_USB_CXUSB=m
  1171. +CONFIG_DVB_USB_M920X=m
  1172. +CONFIG_DVB_USB_DIGITV=m
  1173. +CONFIG_DVB_USB_VP7045=m
  1174. +CONFIG_DVB_USB_VP702X=m
  1175. +CONFIG_DVB_USB_GP8PSK=m
  1176. +CONFIG_DVB_USB_NOVA_T_USB2=m
  1177. +CONFIG_DVB_USB_TTUSB2=m
  1178. +CONFIG_DVB_USB_DTT200U=m
  1179. +CONFIG_DVB_USB_OPERA1=m
  1180. +CONFIG_DVB_USB_AF9005=m
  1181. +CONFIG_DVB_USB_AF9005_REMOTE=m
  1182. +CONFIG_DVB_USB_PCTV452E=m
  1183. +CONFIG_DVB_USB_DW2102=m
  1184. +CONFIG_DVB_USB_CINERGY_T2=m
  1185. +CONFIG_DVB_USB_DTV5100=m
  1186. +CONFIG_DVB_USB_FRIIO=m
  1187. +CONFIG_DVB_USB_AZ6027=m
  1188. +CONFIG_DVB_USB_TECHNISAT_USB2=m
  1189. +CONFIG_DVB_USB_V2=m
  1190. +CONFIG_DVB_USB_AF9015=m
  1191. +CONFIG_DVB_USB_AF9035=m
  1192. +CONFIG_DVB_USB_ANYSEE=m
  1193. +CONFIG_DVB_USB_AU6610=m
  1194. +CONFIG_DVB_USB_AZ6007=m
  1195. +CONFIG_DVB_USB_CE6230=m
  1196. +CONFIG_DVB_USB_EC168=m
  1197. +CONFIG_DVB_USB_GL861=m
  1198. +CONFIG_DVB_USB_IT913X=m
  1199. +CONFIG_DVB_USB_LME2510=m
  1200. +CONFIG_DVB_USB_MXL111SF=m
  1201. +CONFIG_DVB_USB_RTL28XXU=m
  1202. +CONFIG_SMS_USB_DRV=m
  1203. +CONFIG_DVB_B2C2_FLEXCOP_USB=m
  1204. +CONFIG_VIDEO_EM28XX=m
  1205. +CONFIG_VIDEO_EM28XX_ALSA=m
  1206. +CONFIG_VIDEO_EM28XX_DVB=m
  1207. +CONFIG_V4L_PLATFORM_DRIVERS=y
  1208. +CONFIG_VIDEO_BCM2835=y
  1209. +CONFIG_VIDEO_BCM2835_MMAL=m
  1210. +CONFIG_RADIO_SI470X=y
  1211. +CONFIG_USB_SI470X=m
  1212. +CONFIG_I2C_SI470X=m
  1213. +CONFIG_USB_MR800=m
  1214. +CONFIG_USB_DSBR=m
  1215. +CONFIG_RADIO_SHARK=m
  1216. +CONFIG_RADIO_SHARK2=m
  1217. +CONFIG_RADIO_SI4713=m
  1218. +CONFIG_USB_KEENE=m
  1219. +CONFIG_USB_MA901=m
  1220. +CONFIG_RADIO_TEA5764=m
  1221. +CONFIG_RADIO_SAA7706H=m
  1222. +CONFIG_RADIO_TEF6862=m
  1223. +CONFIG_RADIO_WL1273=m
  1224. +CONFIG_RADIO_WL128X=m
  1225. +CONFIG_FB=y
  1226. +CONFIG_FB_BCM2708=y
  1227. +# CONFIG_BACKLIGHT_GENERIC is not set
  1228. +CONFIG_FRAMEBUFFER_CONSOLE=y
  1229. +CONFIG_LOGO=y
  1230. +# CONFIG_LOGO_LINUX_MONO is not set
  1231. +# CONFIG_LOGO_LINUX_VGA16 is not set
  1232. +CONFIG_SOUND=y
  1233. +CONFIG_SND=m
  1234. +CONFIG_SND_SEQUENCER=m
  1235. +CONFIG_SND_SEQ_DUMMY=m
  1236. +CONFIG_SND_MIXER_OSS=m
  1237. +CONFIG_SND_PCM_OSS=m
  1238. +CONFIG_SND_SEQUENCER_OSS=y
  1239. +CONFIG_SND_HRTIMER=m
  1240. +CONFIG_SND_DUMMY=m
  1241. +CONFIG_SND_ALOOP=m
  1242. +CONFIG_SND_VIRMIDI=m
  1243. +CONFIG_SND_MTPAV=m
  1244. +CONFIG_SND_SERIAL_U16550=m
  1245. +CONFIG_SND_MPU401=m
  1246. +CONFIG_SND_BCM2835=m
  1247. +CONFIG_SND_USB_AUDIO=m
  1248. +CONFIG_SND_USB_UA101=m
  1249. +CONFIG_SND_USB_CAIAQ=m
  1250. +CONFIG_SND_USB_CAIAQ_INPUT=y
  1251. +CONFIG_SND_USB_6FIRE=m
  1252. +CONFIG_SND_SOC=m
  1253. +CONFIG_SND_SOC_DMAENGINE_PCM=y
  1254. +CONFIG_SND_SOC_GENERIC_DMAENGINE_PCM=y
  1255. +CONFIG_SND_SOC_WM8804=m
  1256. +CONFIG_SND_BCM2708_SOC_I2S=m
  1257. +CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC=m
  1258. +CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI=m
  1259. +CONFIG_SND_BCM2708_SOC_RPI_DAC=m
  1260. +CONFIG_SND_SOC_I2C_AND_SPI=m
  1261. +CONFIG_SND_SOC_PCM5102A=m
  1262. +CONFIG_SND_SOC_PCM1794A=m
  1263. +CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC=m
  1264. +CONFIG_SOUND_PRIME=m
  1265. +CONFIG_HIDRAW=y
  1266. +CONFIG_HID_A4TECH=m
  1267. +CONFIG_HID_ACRUX=m
  1268. +CONFIG_HID_APPLE=m
  1269. +CONFIG_HID_BELKIN=m
  1270. +CONFIG_HID_CHERRY=m
  1271. +CONFIG_HID_CHICONY=m
  1272. +CONFIG_HID_CYPRESS=m
  1273. +CONFIG_HID_DRAGONRISE=m
  1274. +CONFIG_HID_EMS_FF=m
  1275. +CONFIG_HID_ELECOM=m
  1276. +CONFIG_HID_EZKEY=m
  1277. +CONFIG_HID_HOLTEK=m
  1278. +CONFIG_HID_KEYTOUCH=m
  1279. +CONFIG_HID_KYE=m
  1280. +CONFIG_HID_UCLOGIC=m
  1281. +CONFIG_HID_WALTOP=m
  1282. +CONFIG_HID_GYRATION=m
  1283. +CONFIG_HID_TWINHAN=m
  1284. +CONFIG_HID_KENSINGTON=m
  1285. +CONFIG_HID_LCPOWER=m
  1286. +CONFIG_HID_LOGITECH=m
  1287. +CONFIG_HID_MAGICMOUSE=m
  1288. +CONFIG_HID_MICROSOFT=m
  1289. +CONFIG_HID_MONTEREY=m
  1290. +CONFIG_HID_MULTITOUCH=m
  1291. +CONFIG_HID_NTRIG=m
  1292. +CONFIG_HID_ORTEK=m
  1293. +CONFIG_HID_PANTHERLORD=m
  1294. +CONFIG_HID_PETALYNX=m
  1295. +CONFIG_HID_PICOLCD=m
  1296. +CONFIG_HID_ROCCAT=m
  1297. +CONFIG_HID_SAMSUNG=m
  1298. +CONFIG_HID_SONY=m
  1299. +CONFIG_HID_SPEEDLINK=m
  1300. +CONFIG_HID_SUNPLUS=m
  1301. +CONFIG_HID_GREENASIA=m
  1302. +CONFIG_HID_SMARTJOYPLUS=m
  1303. +CONFIG_HID_TOPSEED=m
  1304. +CONFIG_HID_THINGM=m
  1305. +CONFIG_HID_THRUSTMASTER=m
  1306. +CONFIG_HID_WACOM=m
  1307. +CONFIG_HID_WIIMOTE=m
  1308. +CONFIG_HID_ZEROPLUS=m
  1309. +CONFIG_HID_ZYDACRON=m
  1310. +CONFIG_HID_PID=y
  1311. +CONFIG_USB_HIDDEV=y
  1312. +CONFIG_USB=y
  1313. +CONFIG_USB_ANNOUNCE_NEW_DEVICES=y
  1314. +CONFIG_USB_MON=m
  1315. +CONFIG_USB_DWCOTG=y
  1316. +CONFIG_USB_PRINTER=m
  1317. +CONFIG_USB_STORAGE=y
  1318. +CONFIG_USB_STORAGE_REALTEK=m
  1319. +CONFIG_USB_STORAGE_DATAFAB=m
  1320. +CONFIG_USB_STORAGE_FREECOM=m
  1321. +CONFIG_USB_STORAGE_ISD200=m
  1322. +CONFIG_USB_STORAGE_USBAT=m
  1323. +CONFIG_USB_STORAGE_SDDR09=m
  1324. +CONFIG_USB_STORAGE_SDDR55=m
  1325. +CONFIG_USB_STORAGE_JUMPSHOT=m
  1326. +CONFIG_USB_STORAGE_ALAUDA=m
  1327. +CONFIG_USB_STORAGE_ONETOUCH=m
  1328. +CONFIG_USB_STORAGE_KARMA=m
  1329. +CONFIG_USB_STORAGE_CYPRESS_ATACB=m
  1330. +CONFIG_USB_STORAGE_ENE_UB6250=m
  1331. +CONFIG_USB_MDC800=m
  1332. +CONFIG_USB_MICROTEK=m
  1333. +CONFIG_USB_SERIAL=m
  1334. +CONFIG_USB_SERIAL_GENERIC=y
  1335. +CONFIG_USB_SERIAL_AIRCABLE=m
  1336. +CONFIG_USB_SERIAL_ARK3116=m
  1337. +CONFIG_USB_SERIAL_BELKIN=m
  1338. +CONFIG_USB_SERIAL_CH341=m
  1339. +CONFIG_USB_SERIAL_WHITEHEAT=m
  1340. +CONFIG_USB_SERIAL_DIGI_ACCELEPORT=m
  1341. +CONFIG_USB_SERIAL_CP210X=m
  1342. +CONFIG_USB_SERIAL_CYPRESS_M8=m
  1343. +CONFIG_USB_SERIAL_EMPEG=m
  1344. +CONFIG_USB_SERIAL_FTDI_SIO=m
  1345. +CONFIG_USB_SERIAL_VISOR=m
  1346. +CONFIG_USB_SERIAL_IPAQ=m
  1347. +CONFIG_USB_SERIAL_IR=m
  1348. +CONFIG_USB_SERIAL_EDGEPORT=m
  1349. +CONFIG_USB_SERIAL_EDGEPORT_TI=m
  1350. +CONFIG_USB_SERIAL_F81232=m
  1351. +CONFIG_USB_SERIAL_GARMIN=m
  1352. +CONFIG_USB_SERIAL_IPW=m
  1353. +CONFIG_USB_SERIAL_IUU=m
  1354. +CONFIG_USB_SERIAL_KEYSPAN_PDA=m
  1355. +CONFIG_USB_SERIAL_KEYSPAN=m
  1356. +CONFIG_USB_SERIAL_KLSI=m
  1357. +CONFIG_USB_SERIAL_KOBIL_SCT=m
  1358. +CONFIG_USB_SERIAL_MCT_U232=m
  1359. +CONFIG_USB_SERIAL_METRO=m
  1360. +CONFIG_USB_SERIAL_MOS7720=m
  1361. +CONFIG_USB_SERIAL_MOS7840=m
  1362. +CONFIG_USB_SERIAL_NAVMAN=m
  1363. +CONFIG_USB_SERIAL_PL2303=m
  1364. +CONFIG_USB_SERIAL_OTI6858=m
  1365. +CONFIG_USB_SERIAL_QCAUX=m
  1366. +CONFIG_USB_SERIAL_QUALCOMM=m
  1367. +CONFIG_USB_SERIAL_SPCP8X5=m
  1368. +CONFIG_USB_SERIAL_SAFE=m
  1369. +CONFIG_USB_SERIAL_SIERRAWIRELESS=m
  1370. +CONFIG_USB_SERIAL_SYMBOL=m
  1371. +CONFIG_USB_SERIAL_TI=m
  1372. +CONFIG_USB_SERIAL_CYBERJACK=m
  1373. +CONFIG_USB_SERIAL_XIRCOM=m
  1374. +CONFIG_USB_SERIAL_OPTION=m
  1375. +CONFIG_USB_SERIAL_OMNINET=m
  1376. +CONFIG_USB_SERIAL_OPTICON=m
  1377. +CONFIG_USB_SERIAL_XSENS_MT=m
  1378. +CONFIG_USB_SERIAL_WISHBONE=m
  1379. +CONFIG_USB_SERIAL_ZTE=m
  1380. +CONFIG_USB_SERIAL_SSU100=m
  1381. +CONFIG_USB_SERIAL_QT2=m
  1382. +CONFIG_USB_SERIAL_DEBUG=m
  1383. +CONFIG_USB_EMI62=m
  1384. +CONFIG_USB_EMI26=m
  1385. +CONFIG_USB_ADUTUX=m
  1386. +CONFIG_USB_SEVSEG=m
  1387. +CONFIG_USB_RIO500=m
  1388. +CONFIG_USB_LEGOTOWER=m
  1389. +CONFIG_USB_LCD=m
  1390. +CONFIG_USB_LED=m
  1391. +CONFIG_USB_CYPRESS_CY7C63=m
  1392. +CONFIG_USB_CYTHERM=m
  1393. +CONFIG_USB_IDMOUSE=m
  1394. +CONFIG_USB_FTDI_ELAN=m
  1395. +CONFIG_USB_APPLEDISPLAY=m
  1396. +CONFIG_USB_LD=m
  1397. +CONFIG_USB_TRANCEVIBRATOR=m
  1398. +CONFIG_USB_IOWARRIOR=m
  1399. +CONFIG_USB_TEST=m
  1400. +CONFIG_USB_ISIGHTFW=m
  1401. +CONFIG_USB_YUREX=m
  1402. +CONFIG_MMC=y
  1403. +CONFIG_MMC_BLOCK_MINORS=32
  1404. +CONFIG_MMC_SDHCI=y
  1405. +CONFIG_MMC_SDHCI_PLTFM=y
  1406. +CONFIG_MMC_SDHCI_BCM2708=y
  1407. +CONFIG_MMC_SDHCI_BCM2708_DMA=y
  1408. +CONFIG_MMC_SPI=m
  1409. +CONFIG_LEDS_GPIO=m
  1410. +CONFIG_LEDS_TRIGGER_TIMER=y
  1411. +CONFIG_LEDS_TRIGGER_ONESHOT=y
  1412. +CONFIG_LEDS_TRIGGER_HEARTBEAT=y
  1413. +CONFIG_LEDS_TRIGGER_BACKLIGHT=y
  1414. +CONFIG_LEDS_TRIGGER_CPU=y
  1415. +CONFIG_LEDS_TRIGGER_GPIO=y
  1416. +CONFIG_LEDS_TRIGGER_DEFAULT_ON=y
  1417. +CONFIG_LEDS_TRIGGER_TRANSIENT=m
  1418. +CONFIG_LEDS_TRIGGER_CAMERA=m
  1419. +CONFIG_RTC_CLASS=y
  1420. +# CONFIG_RTC_HCTOSYS is not set
  1421. +CONFIG_RTC_DRV_DS1307=m
  1422. +CONFIG_RTC_DRV_DS1374=m
  1423. +CONFIG_RTC_DRV_DS1672=m
  1424. +CONFIG_RTC_DRV_DS3232=m
  1425. +CONFIG_RTC_DRV_MAX6900=m
  1426. +CONFIG_RTC_DRV_RS5C372=m
  1427. +CONFIG_RTC_DRV_ISL1208=m
  1428. +CONFIG_RTC_DRV_ISL12022=m
  1429. +CONFIG_RTC_DRV_X1205=m
  1430. +CONFIG_RTC_DRV_PCF8523=m
  1431. +CONFIG_RTC_DRV_PCF8563=m
  1432. +CONFIG_RTC_DRV_PCF8583=m
  1433. +CONFIG_RTC_DRV_M41T80=m
  1434. +CONFIG_RTC_DRV_BQ32K=m
  1435. +CONFIG_RTC_DRV_S35390A=m
  1436. +CONFIG_RTC_DRV_FM3130=m
  1437. +CONFIG_RTC_DRV_RX8581=m
  1438. +CONFIG_RTC_DRV_RX8025=m
  1439. +CONFIG_RTC_DRV_EM3027=m
  1440. +CONFIG_RTC_DRV_RV3029C2=m
  1441. +CONFIG_RTC_DRV_M41T93=m
  1442. +CONFIG_RTC_DRV_M41T94=m
  1443. +CONFIG_RTC_DRV_DS1305=m
  1444. +CONFIG_RTC_DRV_DS1390=m
  1445. +CONFIG_RTC_DRV_MAX6902=m
  1446. +CONFIG_RTC_DRV_R9701=m
  1447. +CONFIG_RTC_DRV_RS5C348=m
  1448. +CONFIG_RTC_DRV_DS3234=m
  1449. +CONFIG_RTC_DRV_PCF2123=m
  1450. +CONFIG_RTC_DRV_RX4581=m
  1451. +CONFIG_DMADEVICES=y
  1452. +CONFIG_DMA_BCM2708=m
  1453. +CONFIG_DMA_ENGINE=y
  1454. +CONFIG_DMA_VIRTUAL_CHANNELS=m
  1455. +CONFIG_UIO=m
  1456. +CONFIG_UIO_PDRV_GENIRQ=m
  1457. +CONFIG_STAGING=y
  1458. +CONFIG_W35UND=m
  1459. +CONFIG_PRISM2_USB=m
  1460. +CONFIG_R8712U=m
  1461. +CONFIG_VT6656=m
  1462. +CONFIG_SPEAKUP=m
  1463. +CONFIG_SPEAKUP_SYNTH_SOFT=m
  1464. +CONFIG_STAGING_MEDIA=y
  1465. +CONFIG_DVB_AS102=m
  1466. +CONFIG_LIRC_STAGING=y
  1467. +CONFIG_LIRC_IGORPLUGUSB=m
  1468. +CONFIG_LIRC_IMON=m
  1469. +CONFIG_LIRC_RPI=m
  1470. +CONFIG_LIRC_SASEM=m
  1471. +CONFIG_LIRC_SERIAL=m
  1472. +# CONFIG_IOMMU_SUPPORT is not set
  1473. +CONFIG_EXT4_FS=y
  1474. +CONFIG_EXT4_FS_POSIX_ACL=y
  1475. +CONFIG_EXT4_FS_SECURITY=y
  1476. +CONFIG_REISERFS_FS=m
  1477. +CONFIG_REISERFS_FS_XATTR=y
  1478. +CONFIG_REISERFS_FS_POSIX_ACL=y
  1479. +CONFIG_REISERFS_FS_SECURITY=y
  1480. +CONFIG_JFS_FS=m
  1481. +CONFIG_JFS_POSIX_ACL=y
  1482. +CONFIG_JFS_SECURITY=y
  1483. +CONFIG_JFS_STATISTICS=y
  1484. +CONFIG_XFS_FS=m
  1485. +CONFIG_XFS_QUOTA=y
  1486. +CONFIG_XFS_POSIX_ACL=y
  1487. +CONFIG_XFS_RT=y
  1488. +CONFIG_GFS2_FS=m
  1489. +CONFIG_OCFS2_FS=m
  1490. +CONFIG_BTRFS_FS=m
  1491. +CONFIG_BTRFS_FS_POSIX_ACL=y
  1492. +CONFIG_NILFS2_FS=m
  1493. +CONFIG_FANOTIFY=y
  1494. +CONFIG_QFMT_V1=m
  1495. +CONFIG_QFMT_V2=m
  1496. +CONFIG_AUTOFS4_FS=y
  1497. +CONFIG_FUSE_FS=m
  1498. +CONFIG_CUSE=m
  1499. +CONFIG_FSCACHE=y
  1500. +CONFIG_FSCACHE_STATS=y
  1501. +CONFIG_FSCACHE_HISTOGRAM=y
  1502. +CONFIG_CACHEFILES=y
  1503. +CONFIG_ISO9660_FS=m
  1504. +CONFIG_JOLIET=y
  1505. +CONFIG_ZISOFS=y
  1506. +CONFIG_UDF_FS=m
  1507. +CONFIG_MSDOS_FS=y
  1508. +CONFIG_VFAT_FS=y
  1509. +CONFIG_FAT_DEFAULT_IOCHARSET="ascii"
  1510. +CONFIG_NTFS_FS=m
  1511. +CONFIG_NTFS_RW=y
  1512. +CONFIG_TMPFS=y
  1513. +CONFIG_TMPFS_POSIX_ACL=y
  1514. +CONFIG_CONFIGFS_FS=y
  1515. +CONFIG_ECRYPT_FS=m
  1516. +CONFIG_HFS_FS=m
  1517. +CONFIG_HFSPLUS_FS=m
  1518. +CONFIG_SQUASHFS=m
  1519. +CONFIG_SQUASHFS_XATTR=y
  1520. +CONFIG_SQUASHFS_LZO=y
  1521. +CONFIG_SQUASHFS_XZ=y
  1522. +CONFIG_F2FS_FS=y
  1523. +CONFIG_NFS_FS=y
  1524. +CONFIG_NFS_V3_ACL=y
  1525. +CONFIG_NFS_V4=y
  1526. +CONFIG_ROOT_NFS=y
  1527. +CONFIG_NFS_FSCACHE=y
  1528. +CONFIG_NFSD=m
  1529. +CONFIG_NFSD_V3_ACL=y
  1530. +CONFIG_NFSD_V4=y
  1531. +CONFIG_CIFS=m
  1532. +CONFIG_CIFS_WEAK_PW_HASH=y
  1533. +CONFIG_CIFS_XATTR=y
  1534. +CONFIG_CIFS_POSIX=y
  1535. +CONFIG_9P_FS=m
  1536. +CONFIG_9P_FS_POSIX_ACL=y
  1537. +CONFIG_NLS_DEFAULT="utf8"
  1538. +CONFIG_NLS_CODEPAGE_437=y
  1539. +CONFIG_NLS_CODEPAGE_737=m
  1540. +CONFIG_NLS_CODEPAGE_775=m
  1541. +CONFIG_NLS_CODEPAGE_850=m
  1542. +CONFIG_NLS_CODEPAGE_852=m
  1543. +CONFIG_NLS_CODEPAGE_855=m
  1544. +CONFIG_NLS_CODEPAGE_857=m
  1545. +CONFIG_NLS_CODEPAGE_860=m
  1546. +CONFIG_NLS_CODEPAGE_861=m
  1547. +CONFIG_NLS_CODEPAGE_862=m
  1548. +CONFIG_NLS_CODEPAGE_863=m
  1549. +CONFIG_NLS_CODEPAGE_864=m
  1550. +CONFIG_NLS_CODEPAGE_865=m
  1551. +CONFIG_NLS_CODEPAGE_866=m
  1552. +CONFIG_NLS_CODEPAGE_869=m
  1553. +CONFIG_NLS_CODEPAGE_936=m
  1554. +CONFIG_NLS_CODEPAGE_950=m
  1555. +CONFIG_NLS_CODEPAGE_932=m
  1556. +CONFIG_NLS_CODEPAGE_949=m
  1557. +CONFIG_NLS_CODEPAGE_874=m
  1558. +CONFIG_NLS_ISO8859_8=m
  1559. +CONFIG_NLS_CODEPAGE_1250=m
  1560. +CONFIG_NLS_CODEPAGE_1251=m
  1561. +CONFIG_NLS_ASCII=y
  1562. +CONFIG_NLS_ISO8859_1=m
  1563. +CONFIG_NLS_ISO8859_2=m
  1564. +CONFIG_NLS_ISO8859_3=m
  1565. +CONFIG_NLS_ISO8859_4=m
  1566. +CONFIG_NLS_ISO8859_5=m
  1567. +CONFIG_NLS_ISO8859_6=m
  1568. +CONFIG_NLS_ISO8859_7=m
  1569. +CONFIG_NLS_ISO8859_9=m
  1570. +CONFIG_NLS_ISO8859_13=m
  1571. +CONFIG_NLS_ISO8859_14=m
  1572. +CONFIG_NLS_ISO8859_15=m
  1573. +CONFIG_NLS_KOI8_R=m
  1574. +CONFIG_NLS_KOI8_U=m
  1575. +CONFIG_DLM=m
  1576. +CONFIG_PRINTK_TIME=y
  1577. +CONFIG_BOOT_PRINTK_DELAY=y
  1578. +CONFIG_DEBUG_FS=y
  1579. +CONFIG_DEBUG_MEMORY_INIT=y
  1580. +CONFIG_DETECT_HUNG_TASK=y
  1581. +CONFIG_TIMER_STATS=y
  1582. +# CONFIG_DEBUG_PREEMPT is not set
  1583. +CONFIG_LATENCYTOP=y
  1584. +# CONFIG_KPROBE_EVENT is not set
  1585. +CONFIG_KGDB=y
  1586. +CONFIG_KGDB_KDB=y
  1587. +CONFIG_KDB_KEYBOARD=y
  1588. +CONFIG_STRICT_DEVMEM=y
  1589. +CONFIG_CRYPTO_USER=m
  1590. +CONFIG_CRYPTO_NULL=m
  1591. +CONFIG_CRYPTO_CRYPTD=m
  1592. +CONFIG_CRYPTO_CBC=y
  1593. +CONFIG_CRYPTO_XTS=m
  1594. +CONFIG_CRYPTO_XCBC=m
  1595. +CONFIG_CRYPTO_SHA1_ARM=m
  1596. +CONFIG_CRYPTO_SHA512=m
  1597. +CONFIG_CRYPTO_TGR192=m
  1598. +CONFIG_CRYPTO_WP512=m
  1599. +CONFIG_CRYPTO_AES_ARM=m
  1600. +CONFIG_CRYPTO_CAST5=m
  1601. +CONFIG_CRYPTO_DES=y
  1602. +# CONFIG_CRYPTO_ANSI_CPRNG is not set
  1603. +# CONFIG_CRYPTO_HW is not set
  1604. +CONFIG_CRC_ITU_T=y
  1605. +CONFIG_LIBCRC32C=y
  1606. diff -Nur linux-3.13.11/arch/arm/configs/bcmrpi_emergency_defconfig linux-rpi/arch/arm/configs/bcmrpi_emergency_defconfig
  1607. --- linux-3.13.11/arch/arm/configs/bcmrpi_emergency_defconfig 1970-01-01 01:00:00.000000000 +0100
  1608. +++ linux-rpi/arch/arm/configs/bcmrpi_emergency_defconfig 2014-04-24 15:36:30.902525642 +0200
  1609. @@ -0,0 +1,532 @@
  1610. +CONFIG_EXPERIMENTAL=y
  1611. +# CONFIG_LOCALVERSION_AUTO is not set
  1612. +CONFIG_SYSVIPC=y
  1613. +CONFIG_POSIX_MQUEUE=y
  1614. +CONFIG_BSD_PROCESS_ACCT=y
  1615. +CONFIG_BSD_PROCESS_ACCT_V3=y
  1616. +CONFIG_FHANDLE=y
  1617. +CONFIG_AUDIT=y
  1618. +CONFIG_IKCONFIG=y
  1619. +CONFIG_IKCONFIG_PROC=y
  1620. +CONFIG_BLK_DEV_INITRD=y
  1621. +CONFIG_INITRAMFS_SOURCE="../target_fs"
  1622. +CONFIG_CGROUP_FREEZER=y
  1623. +CONFIG_CGROUP_DEVICE=y
  1624. +CONFIG_CGROUP_CPUACCT=y
  1625. +CONFIG_RESOURCE_COUNTERS=y
  1626. +CONFIG_BLK_CGROUP=y
  1627. +CONFIG_NAMESPACES=y
  1628. +CONFIG_SCHED_AUTOGROUP=y
  1629. +CONFIG_EMBEDDED=y
  1630. +# CONFIG_COMPAT_BRK is not set
  1631. +CONFIG_SLAB=y
  1632. +CONFIG_PROFILING=y
  1633. +CONFIG_OPROFILE=m
  1634. +CONFIG_KPROBES=y
  1635. +CONFIG_MODULES=y
  1636. +CONFIG_MODULE_UNLOAD=y
  1637. +CONFIG_MODVERSIONS=y
  1638. +CONFIG_MODULE_SRCVERSION_ALL=y
  1639. +# CONFIG_BLK_DEV_BSG is not set
  1640. +CONFIG_BLK_DEV_THROTTLING=y
  1641. +CONFIG_CFQ_GROUP_IOSCHED=y
  1642. +CONFIG_ARCH_BCM2708=y
  1643. +CONFIG_NO_HZ=y
  1644. +CONFIG_HIGH_RES_TIMERS=y
  1645. +CONFIG_AEABI=y
  1646. +CONFIG_SECCOMP=y
  1647. +CONFIG_CC_STACKPROTECTOR=y
  1648. +CONFIG_ZBOOT_ROM_TEXT=0x0
  1649. +CONFIG_ZBOOT_ROM_BSS=0x0
  1650. +CONFIG_CMDLINE="dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext3 rootwait"
  1651. +CONFIG_KEXEC=y
  1652. +CONFIG_CPU_IDLE=y
  1653. +CONFIG_VFP=y
  1654. +CONFIG_BINFMT_MISC=m
  1655. +CONFIG_NET=y
  1656. +CONFIG_PACKET=y
  1657. +CONFIG_UNIX=y
  1658. +CONFIG_XFRM_USER=y
  1659. +CONFIG_NET_KEY=m
  1660. +CONFIG_INET=y
  1661. +CONFIG_IP_MULTICAST=y
  1662. +CONFIG_IP_PNP=y
  1663. +CONFIG_IP_PNP_DHCP=y
  1664. +CONFIG_IP_PNP_RARP=y
  1665. +CONFIG_SYN_COOKIES=y
  1666. +# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
  1667. +# CONFIG_INET_XFRM_MODE_TUNNEL is not set
  1668. +# CONFIG_INET_XFRM_MODE_BEET is not set
  1669. +# CONFIG_INET_LRO is not set
  1670. +# CONFIG_INET_DIAG is not set
  1671. +# CONFIG_IPV6 is not set
  1672. +CONFIG_NET_PKTGEN=m
  1673. +CONFIG_IRDA=m
  1674. +CONFIG_IRLAN=m
  1675. +CONFIG_IRCOMM=m
  1676. +CONFIG_IRDA_ULTRA=y
  1677. +CONFIG_IRDA_CACHE_LAST_LSAP=y
  1678. +CONFIG_IRDA_FAST_RR=y
  1679. +CONFIG_IRTTY_SIR=m
  1680. +CONFIG_KINGSUN_DONGLE=m
  1681. +CONFIG_KSDAZZLE_DONGLE=m
  1682. +CONFIG_KS959_DONGLE=m
  1683. +CONFIG_USB_IRDA=m
  1684. +CONFIG_SIGMATEL_FIR=m
  1685. +CONFIG_MCS_FIR=m
  1686. +CONFIG_BT=m
  1687. +CONFIG_BT_L2CAP=y
  1688. +CONFIG_BT_SCO=y
  1689. +CONFIG_BT_RFCOMM=m
  1690. +CONFIG_BT_RFCOMM_TTY=y
  1691. +CONFIG_BT_BNEP=m
  1692. +CONFIG_BT_BNEP_MC_FILTER=y
  1693. +CONFIG_BT_BNEP_PROTO_FILTER=y
  1694. +CONFIG_BT_HIDP=m
  1695. +CONFIG_BT_HCIBTUSB=m
  1696. +CONFIG_BT_HCIBCM203X=m
  1697. +CONFIG_BT_HCIBPA10X=m
  1698. +CONFIG_BT_HCIBFUSB=m
  1699. +CONFIG_BT_HCIVHCI=m
  1700. +CONFIG_BT_MRVL=m
  1701. +CONFIG_BT_MRVL_SDIO=m
  1702. +CONFIG_BT_ATH3K=m
  1703. +CONFIG_CFG80211=m
  1704. +CONFIG_MAC80211=m
  1705. +CONFIG_MAC80211_RC_PID=y
  1706. +CONFIG_MAC80211_MESH=y
  1707. +CONFIG_WIMAX=m
  1708. +CONFIG_NET_9P=m
  1709. +CONFIG_NFC=m
  1710. +CONFIG_NFC_PN533=m
  1711. +CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
  1712. +CONFIG_BLK_DEV_LOOP=y
  1713. +CONFIG_BLK_DEV_CRYPTOLOOP=m
  1714. +CONFIG_BLK_DEV_NBD=m
  1715. +CONFIG_BLK_DEV_RAM=y
  1716. +CONFIG_CDROM_PKTCDVD=m
  1717. +CONFIG_MISC_DEVICES=y
  1718. +CONFIG_SCSI=y
  1719. +# CONFIG_SCSI_PROC_FS is not set
  1720. +CONFIG_BLK_DEV_SD=y
  1721. +CONFIG_BLK_DEV_SR=m
  1722. +CONFIG_SCSI_MULTI_LUN=y
  1723. +# CONFIG_SCSI_LOWLEVEL is not set
  1724. +CONFIG_MD=y
  1725. +CONFIG_NETDEVICES=y
  1726. +CONFIG_TUN=m
  1727. +CONFIG_PHYLIB=m
  1728. +CONFIG_MDIO_BITBANG=m
  1729. +CONFIG_NET_ETHERNET=y
  1730. +# CONFIG_NETDEV_1000 is not set
  1731. +# CONFIG_NETDEV_10000 is not set
  1732. +CONFIG_LIBERTAS_THINFIRM=m
  1733. +CONFIG_LIBERTAS_THINFIRM_USB=m
  1734. +CONFIG_AT76C50X_USB=m
  1735. +CONFIG_USB_ZD1201=m
  1736. +CONFIG_USB_NET_RNDIS_WLAN=m
  1737. +CONFIG_RTL8187=m
  1738. +CONFIG_MAC80211_HWSIM=m
  1739. +CONFIG_ATH_COMMON=m
  1740. +CONFIG_ATH9K=m
  1741. +CONFIG_ATH9K_HTC=m
  1742. +CONFIG_CARL9170=m
  1743. +CONFIG_B43=m
  1744. +CONFIG_B43LEGACY=m
  1745. +CONFIG_HOSTAP=m
  1746. +CONFIG_IWM=m
  1747. +CONFIG_LIBERTAS=m
  1748. +CONFIG_LIBERTAS_USB=m
  1749. +CONFIG_LIBERTAS_SDIO=m
  1750. +CONFIG_P54_COMMON=m
  1751. +CONFIG_P54_USB=m
  1752. +CONFIG_RT2X00=m
  1753. +CONFIG_RT2500USB=m
  1754. +CONFIG_RT73USB=m
  1755. +CONFIG_RT2800USB=m
  1756. +CONFIG_RT2800USB_RT53XX=y
  1757. +CONFIG_RTL8192CU=m
  1758. +CONFIG_WL1251=m
  1759. +CONFIG_WL12XX_MENU=m
  1760. +CONFIG_ZD1211RW=m
  1761. +CONFIG_MWIFIEX=m
  1762. +CONFIG_MWIFIEX_SDIO=m
  1763. +CONFIG_WIMAX_I2400M_USB=m
  1764. +CONFIG_USB_CATC=m
  1765. +CONFIG_USB_KAWETH=m
  1766. +CONFIG_USB_PEGASUS=m
  1767. +CONFIG_USB_RTL8150=m
  1768. +CONFIG_USB_USBNET=y
  1769. +CONFIG_USB_NET_AX8817X=m
  1770. +CONFIG_USB_NET_CDCETHER=m
  1771. +CONFIG_USB_NET_CDC_EEM=m
  1772. +CONFIG_USB_NET_DM9601=m
  1773. +CONFIG_USB_NET_SMSC75XX=m
  1774. +CONFIG_USB_NET_SMSC95XX=y
  1775. +CONFIG_USB_NET_GL620A=m
  1776. +CONFIG_USB_NET_NET1080=m
  1777. +CONFIG_USB_NET_PLUSB=m
  1778. +CONFIG_USB_NET_MCS7830=m
  1779. +CONFIG_USB_NET_CDC_SUBSET=m
  1780. +CONFIG_USB_ALI_M5632=y
  1781. +CONFIG_USB_AN2720=y
  1782. +CONFIG_USB_KC2190=y
  1783. +# CONFIG_USB_NET_ZAURUS is not set
  1784. +CONFIG_USB_NET_CX82310_ETH=m
  1785. +CONFIG_USB_NET_KALMIA=m
  1786. +CONFIG_USB_NET_INT51X1=m
  1787. +CONFIG_USB_IPHETH=m
  1788. +CONFIG_USB_SIERRA_NET=m
  1789. +CONFIG_USB_VL600=m
  1790. +CONFIG_PPP=m
  1791. +CONFIG_PPP_ASYNC=m
  1792. +CONFIG_PPP_SYNC_TTY=m
  1793. +CONFIG_PPP_DEFLATE=m
  1794. +CONFIG_PPP_BSDCOMP=m
  1795. +CONFIG_SLIP=m
  1796. +CONFIG_SLIP_COMPRESSED=y
  1797. +CONFIG_NETCONSOLE=m
  1798. +CONFIG_INPUT_POLLDEV=m
  1799. +# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
  1800. +CONFIG_INPUT_JOYDEV=m
  1801. +CONFIG_INPUT_EVDEV=m
  1802. +# CONFIG_INPUT_KEYBOARD is not set
  1803. +# CONFIG_INPUT_MOUSE is not set
  1804. +CONFIG_INPUT_MISC=y
  1805. +CONFIG_INPUT_AD714X=m
  1806. +CONFIG_INPUT_ATI_REMOTE=m
  1807. +CONFIG_INPUT_ATI_REMOTE2=m
  1808. +CONFIG_INPUT_KEYSPAN_REMOTE=m
  1809. +CONFIG_INPUT_POWERMATE=m
  1810. +CONFIG_INPUT_YEALINK=m
  1811. +CONFIG_INPUT_CM109=m
  1812. +CONFIG_INPUT_UINPUT=m
  1813. +CONFIG_INPUT_GPIO_ROTARY_ENCODER=m
  1814. +CONFIG_INPUT_ADXL34X=m
  1815. +CONFIG_INPUT_CMA3000=m
  1816. +CONFIG_SERIO=m
  1817. +CONFIG_SERIO_RAW=m
  1818. +CONFIG_GAMEPORT=m
  1819. +CONFIG_GAMEPORT_NS558=m
  1820. +CONFIG_GAMEPORT_L4=m
  1821. +CONFIG_VT_HW_CONSOLE_BINDING=y
  1822. +# CONFIG_LEGACY_PTYS is not set
  1823. +# CONFIG_DEVKMEM is not set
  1824. +CONFIG_SERIAL_AMBA_PL011=y
  1825. +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
  1826. +# CONFIG_HW_RANDOM is not set
  1827. +CONFIG_RAW_DRIVER=y
  1828. +CONFIG_GPIO_SYSFS=y
  1829. +# CONFIG_HWMON is not set
  1830. +CONFIG_WATCHDOG=y
  1831. +CONFIG_BCM2708_WDT=m
  1832. +# CONFIG_MFD_SUPPORT is not set
  1833. +CONFIG_FB=y
  1834. +CONFIG_FB_BCM2708=y
  1835. +CONFIG_FRAMEBUFFER_CONSOLE=y
  1836. +CONFIG_LOGO=y
  1837. +# CONFIG_LOGO_LINUX_MONO is not set
  1838. +# CONFIG_LOGO_LINUX_VGA16 is not set
  1839. +CONFIG_SOUND=y
  1840. +CONFIG_SND=m
  1841. +CONFIG_SND_SEQUENCER=m
  1842. +CONFIG_SND_SEQ_DUMMY=m
  1843. +CONFIG_SND_MIXER_OSS=m
  1844. +CONFIG_SND_PCM_OSS=m
  1845. +CONFIG_SND_SEQUENCER_OSS=y
  1846. +CONFIG_SND_HRTIMER=m
  1847. +CONFIG_SND_DUMMY=m
  1848. +CONFIG_SND_ALOOP=m
  1849. +CONFIG_SND_VIRMIDI=m
  1850. +CONFIG_SND_MTPAV=m
  1851. +CONFIG_SND_SERIAL_U16550=m
  1852. +CONFIG_SND_MPU401=m
  1853. +CONFIG_SND_BCM2835=m
  1854. +CONFIG_SND_USB_AUDIO=m
  1855. +CONFIG_SND_USB_UA101=m
  1856. +CONFIG_SND_USB_CAIAQ=m
  1857. +CONFIG_SND_USB_6FIRE=m
  1858. +CONFIG_SOUND_PRIME=m
  1859. +CONFIG_HID_PID=y
  1860. +CONFIG_USB_HIDDEV=y
  1861. +CONFIG_HID_A4TECH=m
  1862. +CONFIG_HID_ACRUX=m
  1863. +CONFIG_HID_APPLE=m
  1864. +CONFIG_HID_BELKIN=m
  1865. +CONFIG_HID_CHERRY=m
  1866. +CONFIG_HID_CHICONY=m
  1867. +CONFIG_HID_CYPRESS=m
  1868. +CONFIG_HID_DRAGONRISE=m
  1869. +CONFIG_HID_EMS_FF=m
  1870. +CONFIG_HID_ELECOM=m
  1871. +CONFIG_HID_EZKEY=m
  1872. +CONFIG_HID_HOLTEK=m
  1873. +CONFIG_HID_KEYTOUCH=m
  1874. +CONFIG_HID_KYE=m
  1875. +CONFIG_HID_UCLOGIC=m
  1876. +CONFIG_HID_WALTOP=m
  1877. +CONFIG_HID_GYRATION=m
  1878. +CONFIG_HID_TWINHAN=m
  1879. +CONFIG_HID_KENSINGTON=m
  1880. +CONFIG_HID_LCPOWER=m
  1881. +CONFIG_HID_LOGITECH=m
  1882. +CONFIG_HID_MAGICMOUSE=m
  1883. +CONFIG_HID_MICROSOFT=m
  1884. +CONFIG_HID_MONTEREY=m
  1885. +CONFIG_HID_MULTITOUCH=m
  1886. +CONFIG_HID_NTRIG=m
  1887. +CONFIG_HID_ORTEK=m
  1888. +CONFIG_HID_PANTHERLORD=m
  1889. +CONFIG_HID_PETALYNX=m
  1890. +CONFIG_HID_PICOLCD=m
  1891. +CONFIG_HID_QUANTA=m
  1892. +CONFIG_HID_ROCCAT=m
  1893. +CONFIG_HID_SAMSUNG=m
  1894. +CONFIG_HID_SONY=m
  1895. +CONFIG_HID_SPEEDLINK=m
  1896. +CONFIG_HID_SUNPLUS=m
  1897. +CONFIG_HID_GREENASIA=m
  1898. +CONFIG_HID_SMARTJOYPLUS=m
  1899. +CONFIG_HID_TOPSEED=m
  1900. +CONFIG_HID_THRUSTMASTER=m
  1901. +CONFIG_HID_WACOM=m
  1902. +CONFIG_HID_WIIMOTE=m
  1903. +CONFIG_HID_ZEROPLUS=m
  1904. +CONFIG_HID_ZYDACRON=m
  1905. +CONFIG_USB=y
  1906. +CONFIG_USB_ANNOUNCE_NEW_DEVICES=y
  1907. +CONFIG_USB_MON=m
  1908. +CONFIG_USB_DWCOTG=y
  1909. +CONFIG_USB_STORAGE=y
  1910. +CONFIG_USB_STORAGE_REALTEK=m
  1911. +CONFIG_USB_STORAGE_DATAFAB=m
  1912. +CONFIG_USB_STORAGE_FREECOM=m
  1913. +CONFIG_USB_STORAGE_ISD200=m
  1914. +CONFIG_USB_STORAGE_USBAT=m
  1915. +CONFIG_USB_STORAGE_SDDR09=m
  1916. +CONFIG_USB_STORAGE_SDDR55=m
  1917. +CONFIG_USB_STORAGE_JUMPSHOT=m
  1918. +CONFIG_USB_STORAGE_ALAUDA=m
  1919. +CONFIG_USB_STORAGE_ONETOUCH=m
  1920. +CONFIG_USB_STORAGE_KARMA=m
  1921. +CONFIG_USB_STORAGE_CYPRESS_ATACB=m
  1922. +CONFIG_USB_STORAGE_ENE_UB6250=m
  1923. +CONFIG_USB_UAS=y
  1924. +CONFIG_USB_LIBUSUAL=y
  1925. +CONFIG_USB_MDC800=m
  1926. +CONFIG_USB_MICROTEK=m
  1927. +CONFIG_USB_SERIAL=m
  1928. +CONFIG_USB_SERIAL_GENERIC=y
  1929. +CONFIG_USB_SERIAL_AIRCABLE=m
  1930. +CONFIG_USB_SERIAL_ARK3116=m
  1931. +CONFIG_USB_SERIAL_BELKIN=m
  1932. +CONFIG_USB_SERIAL_CH341=m
  1933. +CONFIG_USB_SERIAL_WHITEHEAT=m
  1934. +CONFIG_USB_SERIAL_DIGI_ACCELEPORT=m
  1935. +CONFIG_USB_SERIAL_CP210X=m
  1936. +CONFIG_USB_SERIAL_CYPRESS_M8=m
  1937. +CONFIG_USB_SERIAL_EMPEG=m
  1938. +CONFIG_USB_SERIAL_FTDI_SIO=m
  1939. +CONFIG_USB_SERIAL_FUNSOFT=m
  1940. +CONFIG_USB_SERIAL_VISOR=m
  1941. +CONFIG_USB_SERIAL_IPAQ=m
  1942. +CONFIG_USB_SERIAL_IR=m
  1943. +CONFIG_USB_SERIAL_EDGEPORT=m
  1944. +CONFIG_USB_SERIAL_EDGEPORT_TI=m
  1945. +CONFIG_USB_SERIAL_GARMIN=m
  1946. +CONFIG_USB_SERIAL_IPW=m
  1947. +CONFIG_USB_SERIAL_IUU=m
  1948. +CONFIG_USB_SERIAL_KEYSPAN_PDA=m
  1949. +CONFIG_USB_SERIAL_KEYSPAN=m
  1950. +CONFIG_USB_SERIAL_KLSI=m
  1951. +CONFIG_USB_SERIAL_KOBIL_SCT=m
  1952. +CONFIG_USB_SERIAL_MCT_U232=m
  1953. +CONFIG_USB_SERIAL_MOS7720=m
  1954. +CONFIG_USB_SERIAL_MOS7840=m
  1955. +CONFIG_USB_SERIAL_MOTOROLA=m
  1956. +CONFIG_USB_SERIAL_NAVMAN=m
  1957. +CONFIG_USB_SERIAL_PL2303=m
  1958. +CONFIG_USB_SERIAL_OTI6858=m
  1959. +CONFIG_USB_SERIAL_QCAUX=m
  1960. +CONFIG_USB_SERIAL_QUALCOMM=m
  1961. +CONFIG_USB_SERIAL_SPCP8X5=m
  1962. +CONFIG_USB_SERIAL_HP4X=m
  1963. +CONFIG_USB_SERIAL_SAFE=m
  1964. +CONFIG_USB_SERIAL_SIEMENS_MPI=m
  1965. +CONFIG_USB_SERIAL_SIERRAWIRELESS=m
  1966. +CONFIG_USB_SERIAL_SYMBOL=m
  1967. +CONFIG_USB_SERIAL_TI=m
  1968. +CONFIG_USB_SERIAL_CYBERJACK=m
  1969. +CONFIG_USB_SERIAL_XIRCOM=m
  1970. +CONFIG_USB_SERIAL_OPTION=m
  1971. +CONFIG_USB_SERIAL_OMNINET=m
  1972. +CONFIG_USB_SERIAL_OPTICON=m
  1973. +CONFIG_USB_SERIAL_VIVOPAY_SERIAL=m
  1974. +CONFIG_USB_SERIAL_ZIO=m
  1975. +CONFIG_USB_SERIAL_SSU100=m
  1976. +CONFIG_USB_SERIAL_DEBUG=m
  1977. +CONFIG_USB_EMI62=m
  1978. +CONFIG_USB_EMI26=m
  1979. +CONFIG_USB_ADUTUX=m
  1980. +CONFIG_USB_SEVSEG=m
  1981. +CONFIG_USB_RIO500=m
  1982. +CONFIG_USB_LEGOTOWER=m
  1983. +CONFIG_USB_LCD=m
  1984. +CONFIG_USB_LED=m
  1985. +CONFIG_USB_CYPRESS_CY7C63=m
  1986. +CONFIG_USB_CYTHERM=m
  1987. +CONFIG_USB_IDMOUSE=m
  1988. +CONFIG_USB_FTDI_ELAN=m
  1989. +CONFIG_USB_APPLEDISPLAY=m
  1990. +CONFIG_USB_LD=m
  1991. +CONFIG_USB_TRANCEVIBRATOR=m
  1992. +CONFIG_USB_IOWARRIOR=m
  1993. +CONFIG_USB_TEST=m
  1994. +CONFIG_USB_ISIGHTFW=m
  1995. +CONFIG_USB_YUREX=m
  1996. +CONFIG_MMC=y
  1997. +CONFIG_MMC_SDHCI=y
  1998. +CONFIG_MMC_SDHCI_PLTFM=y
  1999. +CONFIG_MMC_SDHCI_BCM2708=y
  2000. +CONFIG_MMC_SDHCI_BCM2708_DMA=y
  2001. +CONFIG_LEDS_GPIO=y
  2002. +CONFIG_LEDS_TRIGGER_TIMER=m
  2003. +CONFIG_LEDS_TRIGGER_HEARTBEAT=m
  2004. +CONFIG_LEDS_TRIGGER_DEFAULT_ON=m
  2005. +CONFIG_UIO=m
  2006. +CONFIG_UIO_PDRV=m
  2007. +CONFIG_UIO_PDRV_GENIRQ=m
  2008. +# CONFIG_IOMMU_SUPPORT is not set
  2009. +CONFIG_EXT4_FS=y
  2010. +CONFIG_EXT4_FS_POSIX_ACL=y
  2011. +CONFIG_EXT4_FS_SECURITY=y
  2012. +CONFIG_REISERFS_FS=m
  2013. +CONFIG_REISERFS_FS_XATTR=y
  2014. +CONFIG_REISERFS_FS_POSIX_ACL=y
  2015. +CONFIG_REISERFS_FS_SECURITY=y
  2016. +CONFIG_JFS_FS=m
  2017. +CONFIG_JFS_POSIX_ACL=y
  2018. +CONFIG_JFS_SECURITY=y
  2019. +CONFIG_JFS_STATISTICS=y
  2020. +CONFIG_XFS_FS=m
  2021. +CONFIG_XFS_QUOTA=y
  2022. +CONFIG_XFS_POSIX_ACL=y
  2023. +CONFIG_XFS_RT=y
  2024. +CONFIG_GFS2_FS=m
  2025. +CONFIG_OCFS2_FS=m
  2026. +CONFIG_BTRFS_FS=m
  2027. +CONFIG_BTRFS_FS_POSIX_ACL=y
  2028. +CONFIG_NILFS2_FS=m
  2029. +CONFIG_FANOTIFY=y
  2030. +CONFIG_AUTOFS4_FS=y
  2031. +CONFIG_FUSE_FS=m
  2032. +CONFIG_CUSE=m
  2033. +CONFIG_FSCACHE=y
  2034. +CONFIG_FSCACHE_STATS=y
  2035. +CONFIG_FSCACHE_HISTOGRAM=y
  2036. +CONFIG_CACHEFILES=y
  2037. +CONFIG_ISO9660_FS=m
  2038. +CONFIG_JOLIET=y
  2039. +CONFIG_ZISOFS=y
  2040. +CONFIG_UDF_FS=m
  2041. +CONFIG_MSDOS_FS=y
  2042. +CONFIG_VFAT_FS=y
  2043. +CONFIG_FAT_DEFAULT_IOCHARSET="ascii"
  2044. +CONFIG_NTFS_FS=m
  2045. +CONFIG_TMPFS=y
  2046. +CONFIG_TMPFS_POSIX_ACL=y
  2047. +CONFIG_CONFIGFS_FS=y
  2048. +CONFIG_SQUASHFS=m
  2049. +CONFIG_SQUASHFS_XATTR=y
  2050. +CONFIG_SQUASHFS_LZO=y
  2051. +CONFIG_SQUASHFS_XZ=y
  2052. +CONFIG_NFS_FS=y
  2053. +CONFIG_NFS_V3=y
  2054. +CONFIG_NFS_V3_ACL=y
  2055. +CONFIG_NFS_V4=y
  2056. +CONFIG_ROOT_NFS=y
  2057. +CONFIG_NFS_FSCACHE=y
  2058. +CONFIG_CIFS=m
  2059. +CONFIG_CIFS_WEAK_PW_HASH=y
  2060. +CONFIG_CIFS_XATTR=y
  2061. +CONFIG_CIFS_POSIX=y
  2062. +CONFIG_9P_FS=m
  2063. +CONFIG_9P_FS_POSIX_ACL=y
  2064. +CONFIG_PARTITION_ADVANCED=y
  2065. +CONFIG_MAC_PARTITION=y
  2066. +CONFIG_EFI_PARTITION=y
  2067. +CONFIG_NLS_DEFAULT="utf8"
  2068. +CONFIG_NLS_CODEPAGE_437=y
  2069. +CONFIG_NLS_CODEPAGE_737=m
  2070. +CONFIG_NLS_CODEPAGE_775=m
  2071. +CONFIG_NLS_CODEPAGE_850=m
  2072. +CONFIG_NLS_CODEPAGE_852=m
  2073. +CONFIG_NLS_CODEPAGE_855=m
  2074. +CONFIG_NLS_CODEPAGE_857=m
  2075. +CONFIG_NLS_CODEPAGE_860=m
  2076. +CONFIG_NLS_CODEPAGE_861=m
  2077. +CONFIG_NLS_CODEPAGE_862=m
  2078. +CONFIG_NLS_CODEPAGE_863=m
  2079. +CONFIG_NLS_CODEPAGE_864=m
  2080. +CONFIG_NLS_CODEPAGE_865=m
  2081. +CONFIG_NLS_CODEPAGE_866=m
  2082. +CONFIG_NLS_CODEPAGE_869=m
  2083. +CONFIG_NLS_CODEPAGE_936=m
  2084. +CONFIG_NLS_CODEPAGE_950=m
  2085. +CONFIG_NLS_CODEPAGE_932=m
  2086. +CONFIG_NLS_CODEPAGE_949=m
  2087. +CONFIG_NLS_CODEPAGE_874=m
  2088. +CONFIG_NLS_ISO8859_8=m
  2089. +CONFIG_NLS_CODEPAGE_1250=m
  2090. +CONFIG_NLS_CODEPAGE_1251=m
  2091. +CONFIG_NLS_ASCII=y
  2092. +CONFIG_NLS_ISO8859_1=m
  2093. +CONFIG_NLS_ISO8859_2=m
  2094. +CONFIG_NLS_ISO8859_3=m
  2095. +CONFIG_NLS_ISO8859_4=m
  2096. +CONFIG_NLS_ISO8859_5=m
  2097. +CONFIG_NLS_ISO8859_6=m
  2098. +CONFIG_NLS_ISO8859_7=m
  2099. +CONFIG_NLS_ISO8859_9=m
  2100. +CONFIG_NLS_ISO8859_13=m
  2101. +CONFIG_NLS_ISO8859_14=m
  2102. +CONFIG_NLS_ISO8859_15=m
  2103. +CONFIG_NLS_KOI8_R=m
  2104. +CONFIG_NLS_KOI8_U=m
  2105. +CONFIG_NLS_UTF8=m
  2106. +CONFIG_PRINTK_TIME=y
  2107. +CONFIG_DETECT_HUNG_TASK=y
  2108. +CONFIG_TIMER_STATS=y
  2109. +CONFIG_DEBUG_STACK_USAGE=y
  2110. +CONFIG_DEBUG_INFO=y
  2111. +CONFIG_DEBUG_MEMORY_INIT=y
  2112. +CONFIG_BOOT_PRINTK_DELAY=y
  2113. +CONFIG_LATENCYTOP=y
  2114. +CONFIG_SYSCTL_SYSCALL_CHECK=y
  2115. +CONFIG_IRQSOFF_TRACER=y
  2116. +CONFIG_SCHED_TRACER=y
  2117. +CONFIG_STACK_TRACER=y
  2118. +CONFIG_BLK_DEV_IO_TRACE=y
  2119. +CONFIG_FUNCTION_PROFILER=y
  2120. +CONFIG_KGDB=y
  2121. +CONFIG_KGDB_KDB=y
  2122. +CONFIG_KDB_KEYBOARD=y
  2123. +CONFIG_STRICT_DEVMEM=y
  2124. +CONFIG_CRYPTO_AUTHENC=m
  2125. +CONFIG_CRYPTO_SEQIV=m
  2126. +CONFIG_CRYPTO_CBC=y
  2127. +CONFIG_CRYPTO_HMAC=y
  2128. +CONFIG_CRYPTO_XCBC=m
  2129. +CONFIG_CRYPTO_MD5=y
  2130. +CONFIG_CRYPTO_SHA1=y
  2131. +CONFIG_CRYPTO_SHA256=m
  2132. +CONFIG_CRYPTO_SHA512=m
  2133. +CONFIG_CRYPTO_TGR192=m
  2134. +CONFIG_CRYPTO_WP512=m
  2135. +CONFIG_CRYPTO_CAST5=m
  2136. +CONFIG_CRYPTO_DES=y
  2137. +CONFIG_CRYPTO_DEFLATE=m
  2138. +# CONFIG_CRYPTO_ANSI_CPRNG is not set
  2139. +# CONFIG_CRYPTO_HW is not set
  2140. +CONFIG_CRC_ITU_T=y
  2141. +CONFIG_LIBCRC32C=y
  2142. diff -Nur linux-3.13.11/arch/arm/configs/bcmrpi_quick_defconfig linux-rpi/arch/arm/configs/bcmrpi_quick_defconfig
  2143. --- linux-3.13.11/arch/arm/configs/bcmrpi_quick_defconfig 1970-01-01 01:00:00.000000000 +0100
  2144. +++ linux-rpi/arch/arm/configs/bcmrpi_quick_defconfig 2014-04-24 15:35:00.717527267 +0200
  2145. @@ -0,0 +1,197 @@
  2146. +# CONFIG_ARM_PATCH_PHYS_VIRT is not set
  2147. +CONFIG_LOCALVERSION="-quick"
  2148. +# CONFIG_LOCALVERSION_AUTO is not set
  2149. +# CONFIG_SWAP is not set
  2150. +CONFIG_SYSVIPC=y
  2151. +CONFIG_POSIX_MQUEUE=y
  2152. +CONFIG_NO_HZ=y
  2153. +CONFIG_HIGH_RES_TIMERS=y
  2154. +CONFIG_IKCONFIG=y
  2155. +CONFIG_IKCONFIG_PROC=y
  2156. +CONFIG_KALLSYMS_ALL=y
  2157. +CONFIG_EMBEDDED=y
  2158. +CONFIG_PERF_EVENTS=y
  2159. +# CONFIG_COMPAT_BRK is not set
  2160. +CONFIG_SLAB=y
  2161. +CONFIG_MODULES=y
  2162. +CONFIG_MODULE_UNLOAD=y
  2163. +CONFIG_MODVERSIONS=y
  2164. +CONFIG_MODULE_SRCVERSION_ALL=y
  2165. +# CONFIG_BLK_DEV_BSG is not set
  2166. +CONFIG_ARCH_BCM2708=y
  2167. +CONFIG_PREEMPT=y
  2168. +CONFIG_AEABI=y
  2169. +CONFIG_UACCESS_WITH_MEMCPY=y
  2170. +CONFIG_ZBOOT_ROM_TEXT=0x0
  2171. +CONFIG_ZBOOT_ROM_BSS=0x0
  2172. +CONFIG_CMDLINE="dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait"
  2173. +CONFIG_CPU_FREQ=y
  2174. +CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE=y
  2175. +CONFIG_CPU_FREQ_GOV_PERFORMANCE=y
  2176. +CONFIG_CPU_FREQ_GOV_USERSPACE=y
  2177. +CONFIG_CPU_FREQ_GOV_ONDEMAND=y
  2178. +CONFIG_CPU_FREQ_GOV_CONSERVATIVE=y
  2179. +CONFIG_CPU_IDLE=y
  2180. +CONFIG_VFP=y
  2181. +CONFIG_BINFMT_MISC=y
  2182. +CONFIG_NET=y
  2183. +CONFIG_PACKET=y
  2184. +CONFIG_UNIX=y
  2185. +CONFIG_INET=y
  2186. +CONFIG_IP_MULTICAST=y
  2187. +CONFIG_IP_PNP=y
  2188. +CONFIG_IP_PNP_DHCP=y
  2189. +CONFIG_IP_PNP_RARP=y
  2190. +CONFIG_SYN_COOKIES=y
  2191. +# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
  2192. +# CONFIG_INET_XFRM_MODE_TUNNEL is not set
  2193. +# CONFIG_INET_XFRM_MODE_BEET is not set
  2194. +# CONFIG_INET_LRO is not set
  2195. +# CONFIG_INET_DIAG is not set
  2196. +# CONFIG_IPV6 is not set
  2197. +# CONFIG_WIRELESS is not set
  2198. +CONFIG_DEVTMPFS=y
  2199. +CONFIG_DEVTMPFS_MOUNT=y
  2200. +CONFIG_BLK_DEV_LOOP=y
  2201. +CONFIG_BLK_DEV_RAM=y
  2202. +CONFIG_SCSI=y
  2203. +# CONFIG_SCSI_PROC_FS is not set
  2204. +# CONFIG_SCSI_LOWLEVEL is not set
  2205. +CONFIG_NETDEVICES=y
  2206. +# CONFIG_NET_VENDOR_BROADCOM is not set
  2207. +# CONFIG_NET_VENDOR_CIRRUS is not set
  2208. +# CONFIG_NET_VENDOR_FARADAY is not set
  2209. +# CONFIG_NET_VENDOR_INTEL is not set
  2210. +# CONFIG_NET_VENDOR_MARVELL is not set
  2211. +# CONFIG_NET_VENDOR_MICREL is not set
  2212. +# CONFIG_NET_VENDOR_NATSEMI is not set
  2213. +# CONFIG_NET_VENDOR_SEEQ is not set
  2214. +# CONFIG_NET_VENDOR_STMICRO is not set
  2215. +# CONFIG_NET_VENDOR_WIZNET is not set
  2216. +CONFIG_USB_USBNET=y
  2217. +# CONFIG_USB_NET_AX8817X is not set
  2218. +# CONFIG_USB_NET_CDCETHER is not set
  2219. +# CONFIG_USB_NET_CDC_NCM is not set
  2220. +CONFIG_USB_NET_SMSC95XX=y
  2221. +# CONFIG_USB_NET_NET1080 is not set
  2222. +# CONFIG_USB_NET_CDC_SUBSET is not set
  2223. +# CONFIG_USB_NET_ZAURUS is not set
  2224. +# CONFIG_WLAN is not set
  2225. +# CONFIG_INPUT_MOUSEDEV is not set
  2226. +CONFIG_INPUT_EVDEV=y
  2227. +# CONFIG_INPUT_KEYBOARD is not set
  2228. +# CONFIG_INPUT_MOUSE is not set
  2229. +# CONFIG_SERIO is not set
  2230. +CONFIG_VT_HW_CONSOLE_BINDING=y
  2231. +# CONFIG_LEGACY_PTYS is not set
  2232. +# CONFIG_DEVKMEM is not set
  2233. +CONFIG_SERIAL_AMBA_PL011=y
  2234. +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
  2235. +CONFIG_TTY_PRINTK=y
  2236. +CONFIG_HW_RANDOM=y
  2237. +CONFIG_HW_RANDOM_BCM2708=y
  2238. +CONFIG_RAW_DRIVER=y
  2239. +CONFIG_THERMAL=y
  2240. +CONFIG_THERMAL_BCM2835=y
  2241. +CONFIG_WATCHDOG=y
  2242. +CONFIG_BCM2708_WDT=y
  2243. +CONFIG_REGULATOR=y
  2244. +CONFIG_REGULATOR_DEBUG=y
  2245. +CONFIG_REGULATOR_FIXED_VOLTAGE=y
  2246. +CONFIG_REGULATOR_VIRTUAL_CONSUMER=y
  2247. +CONFIG_REGULATOR_USERSPACE_CONSUMER=y
  2248. +CONFIG_FB=y
  2249. +CONFIG_FB_BCM2708=y
  2250. +CONFIG_FRAMEBUFFER_CONSOLE=y
  2251. +CONFIG_LOGO=y
  2252. +# CONFIG_LOGO_LINUX_MONO is not set
  2253. +# CONFIG_LOGO_LINUX_VGA16 is not set
  2254. +CONFIG_SOUND=y
  2255. +CONFIG_SND=y
  2256. +CONFIG_SND_BCM2835=y
  2257. +# CONFIG_SND_USB is not set
  2258. +CONFIG_USB=y
  2259. +CONFIG_USB_ANNOUNCE_NEW_DEVICES=y
  2260. +CONFIG_USB_DWCOTG=y
  2261. +CONFIG_MMC=y
  2262. +CONFIG_MMC_SDHCI=y
  2263. +CONFIG_MMC_SDHCI_PLTFM=y
  2264. +CONFIG_MMC_SDHCI_BCM2708=y
  2265. +CONFIG_MMC_SDHCI_BCM2708_DMA=y
  2266. +CONFIG_NEW_LEDS=y
  2267. +CONFIG_LEDS_CLASS=y
  2268. +CONFIG_LEDS_TRIGGERS=y
  2269. +# CONFIG_IOMMU_SUPPORT is not set
  2270. +CONFIG_EXT4_FS=y
  2271. +CONFIG_EXT4_FS_POSIX_ACL=y
  2272. +CONFIG_EXT4_FS_SECURITY=y
  2273. +CONFIG_AUTOFS4_FS=y
  2274. +CONFIG_FSCACHE=y
  2275. +CONFIG_CACHEFILES=y
  2276. +CONFIG_MSDOS_FS=y
  2277. +CONFIG_VFAT_FS=y
  2278. +CONFIG_FAT_DEFAULT_IOCHARSET="ascii"
  2279. +CONFIG_TMPFS=y
  2280. +CONFIG_TMPFS_POSIX_ACL=y
  2281. +CONFIG_CONFIGFS_FS=y
  2282. +# CONFIG_MISC_FILESYSTEMS is not set
  2283. +CONFIG_NFS_FS=y
  2284. +CONFIG_NFS_V3_ACL=y
  2285. +CONFIG_NFS_V4=y
  2286. +CONFIG_ROOT_NFS=y
  2287. +CONFIG_NFS_FSCACHE=y
  2288. +CONFIG_NLS_DEFAULT="utf8"
  2289. +CONFIG_NLS_CODEPAGE_437=y
  2290. +CONFIG_NLS_CODEPAGE_737=y
  2291. +CONFIG_NLS_CODEPAGE_775=y
  2292. +CONFIG_NLS_CODEPAGE_850=y
  2293. +CONFIG_NLS_CODEPAGE_852=y
  2294. +CONFIG_NLS_CODEPAGE_855=y
  2295. +CONFIG_NLS_CODEPAGE_857=y
  2296. +CONFIG_NLS_CODEPAGE_860=y
  2297. +CONFIG_NLS_CODEPAGE_861=y
  2298. +CONFIG_NLS_CODEPAGE_862=y
  2299. +CONFIG_NLS_CODEPAGE_863=y
  2300. +CONFIG_NLS_CODEPAGE_864=y
  2301. +CONFIG_NLS_CODEPAGE_865=y
  2302. +CONFIG_NLS_CODEPAGE_866=y
  2303. +CONFIG_NLS_CODEPAGE_869=y
  2304. +CONFIG_NLS_CODEPAGE_936=y
  2305. +CONFIG_NLS_CODEPAGE_950=y
  2306. +CONFIG_NLS_CODEPAGE_932=y
  2307. +CONFIG_NLS_CODEPAGE_949=y
  2308. +CONFIG_NLS_CODEPAGE_874=y
  2309. +CONFIG_NLS_ISO8859_8=y
  2310. +CONFIG_NLS_CODEPAGE_1250=y
  2311. +CONFIG_NLS_CODEPAGE_1251=y
  2312. +CONFIG_NLS_ASCII=y
  2313. +CONFIG_NLS_ISO8859_1=y
  2314. +CONFIG_NLS_ISO8859_2=y
  2315. +CONFIG_NLS_ISO8859_3=y
  2316. +CONFIG_NLS_ISO8859_4=y
  2317. +CONFIG_NLS_ISO8859_5=y
  2318. +CONFIG_NLS_ISO8859_6=y
  2319. +CONFIG_NLS_ISO8859_7=y
  2320. +CONFIG_NLS_ISO8859_9=y
  2321. +CONFIG_NLS_ISO8859_13=y
  2322. +CONFIG_NLS_ISO8859_14=y
  2323. +CONFIG_NLS_ISO8859_15=y
  2324. +CONFIG_NLS_UTF8=y
  2325. +CONFIG_PRINTK_TIME=y
  2326. +CONFIG_DEBUG_FS=y
  2327. +CONFIG_DETECT_HUNG_TASK=y
  2328. +# CONFIG_DEBUG_PREEMPT is not set
  2329. +# CONFIG_DEBUG_BUGVERBOSE is not set
  2330. +# CONFIG_FTRACE is not set
  2331. +CONFIG_KGDB=y
  2332. +CONFIG_KGDB_KDB=y
  2333. +# CONFIG_ARM_UNWIND is not set
  2334. +CONFIG_CRYPTO_CBC=y
  2335. +CONFIG_CRYPTO_HMAC=y
  2336. +CONFIG_CRYPTO_MD5=y
  2337. +CONFIG_CRYPTO_SHA1=y
  2338. +CONFIG_CRYPTO_DES=y
  2339. +# CONFIG_CRYPTO_ANSI_CPRNG is not set
  2340. +# CONFIG_CRYPTO_HW is not set
  2341. +CONFIG_CRC_ITU_T=y
  2342. +CONFIG_LIBCRC32C=y
  2343. diff -Nur linux-3.13.11/arch/arm/include/asm/irqflags.h linux-rpi/arch/arm/include/asm/irqflags.h
  2344. --- linux-3.13.11/arch/arm/include/asm/irqflags.h 2014-04-23 01:49:33.000000000 +0200
  2345. +++ linux-rpi/arch/arm/include/asm/irqflags.h 2014-04-24 15:36:30.918525818 +0200
  2346. @@ -145,12 +145,22 @@
  2347. }
  2348. /*
  2349. - * restore saved IRQ & FIQ state
  2350. + * restore saved IRQ state
  2351. */
  2352. static inline void arch_local_irq_restore(unsigned long flags)
  2353. {
  2354. - asm volatile(
  2355. - " msr " IRQMASK_REG_NAME_W ", %0 @ local_irq_restore"
  2356. + unsigned long temp = 0;
  2357. + flags &= ~(1 << 6);
  2358. + asm volatile (
  2359. + " mrs %0, cpsr"
  2360. + : "=r" (temp)
  2361. + :
  2362. + : "memory", "cc");
  2363. + /* Preserve FIQ bit */
  2364. + temp &= (1 << 6);
  2365. + flags = flags | temp;
  2366. + asm volatile (
  2367. + " msr cpsr_c, %0 @ local_irq_restore"
  2368. :
  2369. : "r" (flags)
  2370. : "memory", "cc");
  2371. diff -Nur linux-3.13.11/arch/arm/Kconfig linux-rpi/arch/arm/Kconfig
  2372. --- linux-3.13.11/arch/arm/Kconfig 2014-04-23 01:49:33.000000000 +0200
  2373. +++ linux-rpi/arch/arm/Kconfig 2014-04-24 15:36:30.118517020 +0200
  2374. @@ -373,6 +373,24 @@
  2375. This enables support for systems based on Atmel
  2376. AT91RM9200 and AT91SAM9* processors.
  2377. +config ARCH_BCM2708
  2378. + bool "Broadcom BCM2708 family"
  2379. + select CPU_V6
  2380. + select ARM_AMBA
  2381. + select HAVE_CLK
  2382. + select HAVE_SCHED_CLOCK
  2383. + select NEED_MACH_GPIO_H
  2384. + select NEED_MACH_MEMORY_H
  2385. + select CLKDEV_LOOKUP
  2386. + select ARCH_HAS_CPUFREQ
  2387. + select GENERIC_CLOCKEVENTS
  2388. + select ARM_ERRATA_411920
  2389. + select MACH_BCM2708
  2390. + select VC4
  2391. + select FIQ
  2392. + help
  2393. + This enables support for Broadcom BCM2708 boards.
  2394. +
  2395. config ARCH_CLPS711X
  2396. bool "Cirrus Logic CLPS711x/EP721x/EP731x-based"
  2397. select ARCH_REQUIRE_GPIOLIB
  2398. @@ -1020,6 +1038,7 @@
  2399. source "arch/arm/mach-vt8500/Kconfig"
  2400. source "arch/arm/mach-w90x900/Kconfig"
  2401. +source "arch/arm/mach-bcm2708/Kconfig"
  2402. source "arch/arm/mach-zynq/Kconfig"
  2403. diff -Nur linux-3.13.11/arch/arm/Kconfig.debug linux-rpi/arch/arm/Kconfig.debug
  2404. --- linux-3.13.11/arch/arm/Kconfig.debug 2014-04-23 01:49:33.000000000 +0200
  2405. +++ linux-rpi/arch/arm/Kconfig.debug 2014-04-24 15:36:30.118517020 +0200
  2406. @@ -882,6 +882,14 @@
  2407. options; the platform specific options are deprecated
  2408. and will be soon removed.
  2409. + config DEBUG_BCM2708_UART0
  2410. + bool "Broadcom BCM2708 UART0 (PL011)"
  2411. + depends on MACH_BCM2708
  2412. + help
  2413. + Say Y here if you want the debug print routines to direct
  2414. + their output to UART 0. The port must have been initialised
  2415. + by the boot-loader before use.
  2416. +
  2417. endchoice
  2418. config DEBUG_EXYNOS_UART
  2419. diff -Nur linux-3.13.11/arch/arm/kernel/fiqasm.S linux-rpi/arch/arm/kernel/fiqasm.S
  2420. --- linux-3.13.11/arch/arm/kernel/fiqasm.S 2014-04-23 01:49:33.000000000 +0200
  2421. +++ linux-rpi/arch/arm/kernel/fiqasm.S 2014-04-24 15:36:30.934525994 +0200
  2422. @@ -47,3 +47,7 @@
  2423. mov r0, r0 @ avoid hazard prior to ARMv4
  2424. mov pc, lr
  2425. ENDPROC(__get_fiq_regs)
  2426. +
  2427. +ENTRY(__FIQ_Branch)
  2428. + mov pc, r8
  2429. +ENDPROC(__FIQ_Branch)
  2430. diff -Nur linux-3.13.11/arch/arm/kernel/process.c linux-rpi/arch/arm/kernel/process.c
  2431. --- linux-3.13.11/arch/arm/kernel/process.c 2014-04-23 01:49:33.000000000 +0200
  2432. +++ linux-rpi/arch/arm/kernel/process.c 2014-04-24 15:36:30.934525994 +0200
  2433. @@ -176,6 +176,16 @@
  2434. default_idle();
  2435. }
  2436. +char bcm2708_reboot_mode = 'h';
  2437. +
  2438. +int __init reboot_setup(char *str)
  2439. +{
  2440. + bcm2708_reboot_mode = str[0];
  2441. + return 1;
  2442. +}
  2443. +
  2444. +__setup("reboot=", reboot_setup);
  2445. +
  2446. /*
  2447. * Called by kexec, immediately prior to machine_kexec().
  2448. *
  2449. diff -Nur linux-3.13.11/arch/arm/mach-bcm2708/armctrl.c linux-rpi/arch/arm/mach-bcm2708/armctrl.c
  2450. --- linux-3.13.11/arch/arm/mach-bcm2708/armctrl.c 1970-01-01 01:00:00.000000000 +0100
  2451. +++ linux-rpi/arch/arm/mach-bcm2708/armctrl.c 2014-04-24 15:35:00.773527891 +0200
  2452. @@ -0,0 +1,219 @@
  2453. +/*
  2454. + * linux/arch/arm/mach-bcm2708/armctrl.c
  2455. + *
  2456. + * Copyright (C) 2010 Broadcom
  2457. + *
  2458. + * This program is free software; you can redistribute it and/or modify
  2459. + * it under the terms of the GNU General Public License as published by
  2460. + * the Free Software Foundation; either version 2 of the License, or
  2461. + * (at your option) any later version.
  2462. + *
  2463. + * This program is distributed in the hope that it will be useful,
  2464. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2465. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2466. + * GNU General Public License for more details.
  2467. + *
  2468. + * You should have received a copy of the GNU General Public License
  2469. + * along with this program; if not, write to the Free Software
  2470. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  2471. + */
  2472. +#include <linux/init.h>
  2473. +#include <linux/list.h>
  2474. +#include <linux/io.h>
  2475. +#include <linux/version.h>
  2476. +#include <linux/syscore_ops.h>
  2477. +#include <linux/interrupt.h>
  2478. +
  2479. +#include <asm/mach/irq.h>
  2480. +#include <mach/hardware.h>
  2481. +#include "armctrl.h"
  2482. +
  2483. +/* For support of kernels >= 3.0 assume only one VIC for now*/
  2484. +static unsigned int remap_irqs[(INTERRUPT_ARASANSDIO + 1) - INTERRUPT_JPEG] = {
  2485. + INTERRUPT_VC_JPEG,
  2486. + INTERRUPT_VC_USB,
  2487. + INTERRUPT_VC_3D,
  2488. + INTERRUPT_VC_DMA2,
  2489. + INTERRUPT_VC_DMA3,
  2490. + INTERRUPT_VC_I2C,
  2491. + INTERRUPT_VC_SPI,
  2492. + INTERRUPT_VC_I2SPCM,
  2493. + INTERRUPT_VC_SDIO,
  2494. + INTERRUPT_VC_UART,
  2495. + INTERRUPT_VC_ARASANSDIO
  2496. +};
  2497. +
  2498. +static void armctrl_mask_irq(struct irq_data *d)
  2499. +{
  2500. + static const unsigned int disables[4] = {
  2501. + ARM_IRQ_DIBL1,
  2502. + ARM_IRQ_DIBL2,
  2503. + ARM_IRQ_DIBL3,
  2504. + 0
  2505. + };
  2506. +
  2507. + if (d->irq >= FIQ_START) {
  2508. + writel(0, __io_address(ARM_IRQ_FAST));
  2509. + } else {
  2510. + unsigned int data = (unsigned int)irq_get_chip_data(d->irq);
  2511. + writel(1 << (data & 0x1f), __io_address(disables[(data >> 5) & 0x3]));
  2512. + }
  2513. +}
  2514. +
  2515. +static void armctrl_unmask_irq(struct irq_data *d)
  2516. +{
  2517. + static const unsigned int enables[4] = {
  2518. + ARM_IRQ_ENBL1,
  2519. + ARM_IRQ_ENBL2,
  2520. + ARM_IRQ_ENBL3,
  2521. + 0
  2522. + };
  2523. +
  2524. + if (d->irq >= FIQ_START) {
  2525. + unsigned int data =
  2526. + (unsigned int)irq_get_chip_data(d->irq) - FIQ_START;
  2527. + writel(0x80 | data, __io_address(ARM_IRQ_FAST));
  2528. + } else {
  2529. + unsigned int data = (unsigned int)irq_get_chip_data(d->irq);
  2530. + writel(1 << (data & 0x1f), __io_address(enables[(data >> 5) & 0x3]));
  2531. + }
  2532. +}
  2533. +
  2534. +#if defined(CONFIG_PM)
  2535. +
  2536. +/* for kernels 3.xx use the new syscore_ops apis but for older kernels use the sys dev class */
  2537. +
  2538. +/* Static defines
  2539. + * struct armctrl_device - VIC PM device (< 3.xx)
  2540. + * @sysdev: The system device which is registered. (< 3.xx)
  2541. + * @irq: The IRQ number for the base of the VIC.
  2542. + * @base: The register base for the VIC.
  2543. + * @resume_sources: A bitmask of interrupts for resume.
  2544. + * @resume_irqs: The IRQs enabled for resume.
  2545. + * @int_select: Save for VIC_INT_SELECT.
  2546. + * @int_enable: Save for VIC_INT_ENABLE.
  2547. + * @soft_int: Save for VIC_INT_SOFT.
  2548. + * @protect: Save for VIC_PROTECT.
  2549. + */
  2550. +struct armctrl_info {
  2551. + void __iomem *base;
  2552. + int irq;
  2553. + u32 resume_sources;
  2554. + u32 resume_irqs;
  2555. + u32 int_select;
  2556. + u32 int_enable;
  2557. + u32 soft_int;
  2558. + u32 protect;
  2559. +} armctrl;
  2560. +
  2561. +static int armctrl_suspend(void)
  2562. +{
  2563. + return 0;
  2564. +}
  2565. +
  2566. +static void armctrl_resume(void)
  2567. +{
  2568. + return;
  2569. +}
  2570. +
  2571. +/**
  2572. + * armctrl_pm_register - Register a VIC for later power management control
  2573. + * @base: The base address of the VIC.
  2574. + * @irq: The base IRQ for the VIC.
  2575. + * @resume_sources: bitmask of interrupts allowed for resume sources.
  2576. + *
  2577. + * For older kernels (< 3.xx) do -
  2578. + * Register the VIC with the system device tree so that it can be notified
  2579. + * of suspend and resume requests and ensure that the correct actions are
  2580. + * taken to re-instate the settings on resume.
  2581. + */
  2582. +static void __init armctrl_pm_register(void __iomem * base, unsigned int irq,
  2583. + u32 resume_sources)
  2584. +{
  2585. + armctrl.base = base;
  2586. + armctrl.resume_sources = resume_sources;
  2587. + armctrl.irq = irq;
  2588. +}
  2589. +
  2590. +static int armctrl_set_wake(struct irq_data *d, unsigned int on)
  2591. +{
  2592. + unsigned int off = d->irq & 31;
  2593. + u32 bit = 1 << off;
  2594. +
  2595. + if (!(bit & armctrl.resume_sources))
  2596. + return -EINVAL;
  2597. +
  2598. + if (on)
  2599. + armctrl.resume_irqs |= bit;
  2600. + else
  2601. + armctrl.resume_irqs &= ~bit;
  2602. +
  2603. + return 0;
  2604. +}
  2605. +
  2606. +#else
  2607. +static inline void armctrl_pm_register(void __iomem * base, unsigned int irq,
  2608. + u32 arg1)
  2609. +{
  2610. +}
  2611. +
  2612. +#define armctrl_suspend NULL
  2613. +#define armctrl_resume NULL
  2614. +#define armctrl_set_wake NULL
  2615. +#endif /* CONFIG_PM */
  2616. +
  2617. +static struct syscore_ops armctrl_syscore_ops = {
  2618. + .suspend = armctrl_suspend,
  2619. + .resume = armctrl_resume,
  2620. +};
  2621. +
  2622. +/**
  2623. + * armctrl_syscore_init - initicall to register VIC pm functions
  2624. + *
  2625. + * This is called via late_initcall() to register
  2626. + * the resources for the VICs due to the early
  2627. + * nature of the VIC's registration.
  2628. +*/
  2629. +static int __init armctrl_syscore_init(void)
  2630. +{
  2631. + register_syscore_ops(&armctrl_syscore_ops);
  2632. + return 0;
  2633. +}
  2634. +
  2635. +late_initcall(armctrl_syscore_init);
  2636. +
  2637. +static struct irq_chip armctrl_chip = {
  2638. + .name = "ARMCTRL",
  2639. + .irq_ack = armctrl_mask_irq,
  2640. + .irq_mask = armctrl_mask_irq,
  2641. + .irq_unmask = armctrl_unmask_irq,
  2642. + .irq_set_wake = armctrl_set_wake,
  2643. +};
  2644. +
  2645. +/**
  2646. + * armctrl_init - initialise a vectored interrupt controller
  2647. + * @base: iomem base address
  2648. + * @irq_start: starting interrupt number, must be muliple of 32
  2649. + * @armctrl_sources: bitmask of interrupt sources to allow
  2650. + * @resume_sources: bitmask of interrupt sources to allow for resume
  2651. + */
  2652. +int __init armctrl_init(void __iomem * base, unsigned int irq_start,
  2653. + u32 armctrl_sources, u32 resume_sources)
  2654. +{
  2655. + unsigned int irq;
  2656. +
  2657. + for (irq = 0; irq < NR_IRQS; irq++) {
  2658. + unsigned int data = irq;
  2659. + if (irq >= INTERRUPT_JPEG && irq <= INTERRUPT_ARASANSDIO)
  2660. + data = remap_irqs[irq - INTERRUPT_JPEG];
  2661. +
  2662. + irq_set_chip(irq, &armctrl_chip);
  2663. + irq_set_chip_data(irq, (void *)data);
  2664. + irq_set_handler(irq, handle_level_irq);
  2665. + set_irq_flags(irq, IRQF_VALID | IRQF_PROBE | IRQF_DISABLED);
  2666. + }
  2667. +
  2668. + armctrl_pm_register(base, irq_start, resume_sources);
  2669. + init_FIQ(FIQ_START);
  2670. + return 0;
  2671. +}
  2672. diff -Nur linux-3.13.11/arch/arm/mach-bcm2708/armctrl.h linux-rpi/arch/arm/mach-bcm2708/armctrl.h
  2673. --- linux-3.13.11/arch/arm/mach-bcm2708/armctrl.h 1970-01-01 01:00:00.000000000 +0100
  2674. +++ linux-rpi/arch/arm/mach-bcm2708/armctrl.h 2014-04-24 15:35:00.773527891 +0200
  2675. @@ -0,0 +1,27 @@
  2676. +/*
  2677. + * linux/arch/arm/mach-bcm2708/armctrl.h
  2678. + *
  2679. + * Copyright (C) 2010 Broadcom
  2680. + *
  2681. + * This program is free software; you can redistribute it and/or modify
  2682. + * it under the terms of the GNU General Public License as published by
  2683. + * the Free Software Foundation; either version 2 of the License, or
  2684. + * (at your option) any later version.
  2685. + *
  2686. + * This program is distributed in the hope that it will be useful,
  2687. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2688. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2689. + * GNU General Public License for more details.
  2690. + *
  2691. + * You should have received a copy of the GNU General Public License
  2692. + * along with this program; if not, write to the Free Software
  2693. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  2694. + */
  2695. +
  2696. +#ifndef __BCM2708_ARMCTRL_H
  2697. +#define __BCM2708_ARMCTRL_H
  2698. +
  2699. +extern int __init armctrl_init(void __iomem * base, unsigned int irq_start,
  2700. + u32 armctrl_sources, u32 resume_sources);
  2701. +
  2702. +#endif
  2703. diff -Nur linux-3.13.11/arch/arm/mach-bcm2708/bcm2708.c linux-rpi/arch/arm/mach-bcm2708/bcm2708.c
  2704. --- linux-3.13.11/arch/arm/mach-bcm2708/bcm2708.c 1970-01-01 01:00:00.000000000 +0100
  2705. +++ linux-rpi/arch/arm/mach-bcm2708/bcm2708.c 2014-04-24 15:36:30.950526170 +0200
  2706. @@ -0,0 +1,1017 @@
  2707. +/*
  2708. + * linux/arch/arm/mach-bcm2708/bcm2708.c
  2709. + *
  2710. + * Copyright (C) 2010 Broadcom
  2711. + *
  2712. + * This program is free software; you can redistribute it and/or modify
  2713. + * it under the terms of the GNU General Public License as published by
  2714. + * the Free Software Foundation; either version 2 of the License, or
  2715. + * (at your option) any later version.
  2716. + *
  2717. + * This program is distributed in the hope that it will be useful,
  2718. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2719. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2720. + * GNU General Public License for more details.
  2721. + *
  2722. + * You should have received a copy of the GNU General Public License
  2723. + * along with this program; if not, write to the Free Software
  2724. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  2725. + */
  2726. +
  2727. +#include <linux/init.h>
  2728. +#include <linux/device.h>
  2729. +#include <linux/dma-mapping.h>
  2730. +#include <linux/serial_8250.h>
  2731. +#include <linux/platform_device.h>
  2732. +#include <linux/syscore_ops.h>
  2733. +#include <linux/interrupt.h>
  2734. +#include <linux/amba/bus.h>
  2735. +#include <linux/amba/clcd.h>
  2736. +#include <linux/clockchips.h>
  2737. +#include <linux/cnt32_to_63.h>
  2738. +#include <linux/io.h>
  2739. +#include <linux/module.h>
  2740. +#include <linux/spi/spi.h>
  2741. +#include <linux/w1-gpio.h>
  2742. +
  2743. +#include <linux/version.h>
  2744. +#include <linux/clkdev.h>
  2745. +#include <asm/system.h>
  2746. +#include <mach/hardware.h>
  2747. +#include <asm/irq.h>
  2748. +#include <linux/leds.h>
  2749. +#include <asm/mach-types.h>
  2750. +#include <linux/sched_clock.h>
  2751. +
  2752. +#include <asm/mach/arch.h>
  2753. +#include <asm/mach/flash.h>
  2754. +#include <asm/mach/irq.h>
  2755. +#include <asm/mach/time.h>
  2756. +#include <asm/mach/map.h>
  2757. +
  2758. +#include <mach/timex.h>
  2759. +#include <mach/dma.h>
  2760. +#include <mach/vcio.h>
  2761. +#include <mach/system.h>
  2762. +
  2763. +#include <linux/delay.h>
  2764. +
  2765. +#include "bcm2708.h"
  2766. +#include "armctrl.h"
  2767. +#include "clock.h"
  2768. +
  2769. +#ifdef CONFIG_BCM_VC_CMA
  2770. +#include <linux/broadcom/vc_cma.h>
  2771. +#endif
  2772. +
  2773. +
  2774. +/* Effectively we have an IOMMU (ARM<->VideoCore map) that is set up to
  2775. + * give us IO access only to 64Mbytes of physical memory (26 bits). We could
  2776. + * represent this window by setting our dmamasks to 26 bits but, in fact
  2777. + * we're not going to use addresses outside this range (they're not in real
  2778. + * memory) so we don't bother.
  2779. + *
  2780. + * In the future we might include code to use this IOMMU to remap other
  2781. + * physical addresses onto VideoCore memory then the use of 32-bits would be
  2782. + * more legitimate.
  2783. + */
  2784. +#define DMA_MASK_BITS_COMMON 32
  2785. +
  2786. +// use GPIO 4 for the one-wire GPIO pin, if enabled
  2787. +#define W1_GPIO 4
  2788. +
  2789. +/* command line parameters */
  2790. +static unsigned boardrev, serial;
  2791. +static unsigned uart_clock;
  2792. +static unsigned disk_led_gpio = 16;
  2793. +static unsigned disk_led_active_low = 1;
  2794. +static unsigned reboot_part = 0;
  2795. +static unsigned w1_gpio_pin = W1_GPIO;
  2796. +
  2797. +static void __init bcm2708_init_led(void);
  2798. +
  2799. +void __init bcm2708_init_irq(void)
  2800. +{
  2801. + armctrl_init(__io_address(ARMCTRL_IC_BASE), 0, 0, 0);
  2802. +}
  2803. +
  2804. +static struct map_desc bcm2708_io_desc[] __initdata = {
  2805. + {
  2806. + .virtual = IO_ADDRESS(ARMCTRL_BASE),
  2807. + .pfn = __phys_to_pfn(ARMCTRL_BASE),
  2808. + .length = SZ_4K,
  2809. + .type = MT_DEVICE},
  2810. + {
  2811. + .virtual = IO_ADDRESS(UART0_BASE),
  2812. + .pfn = __phys_to_pfn(UART0_BASE),
  2813. + .length = SZ_4K,
  2814. + .type = MT_DEVICE},
  2815. + {
  2816. + .virtual = IO_ADDRESS(UART1_BASE),
  2817. + .pfn = __phys_to_pfn(UART1_BASE),
  2818. + .length = SZ_4K,
  2819. + .type = MT_DEVICE},
  2820. + {
  2821. + .virtual = IO_ADDRESS(DMA_BASE),
  2822. + .pfn = __phys_to_pfn(DMA_BASE),
  2823. + .length = SZ_4K,
  2824. + .type = MT_DEVICE},
  2825. + {
  2826. + .virtual = IO_ADDRESS(MCORE_BASE),
  2827. + .pfn = __phys_to_pfn(MCORE_BASE),
  2828. + .length = SZ_4K,
  2829. + .type = MT_DEVICE},
  2830. + {
  2831. + .virtual = IO_ADDRESS(ST_BASE),
  2832. + .pfn = __phys_to_pfn(ST_BASE),
  2833. + .length = SZ_4K,
  2834. + .type = MT_DEVICE},
  2835. + {
  2836. + .virtual = IO_ADDRESS(USB_BASE),
  2837. + .pfn = __phys_to_pfn(USB_BASE),
  2838. + .length = SZ_128K,
  2839. + .type = MT_DEVICE},
  2840. + {
  2841. + .virtual = IO_ADDRESS(PM_BASE),
  2842. + .pfn = __phys_to_pfn(PM_BASE),
  2843. + .length = SZ_4K,
  2844. + .type = MT_DEVICE},
  2845. + {
  2846. + .virtual = IO_ADDRESS(GPIO_BASE),
  2847. + .pfn = __phys_to_pfn(GPIO_BASE),
  2848. + .length = SZ_4K,
  2849. + .type = MT_DEVICE}
  2850. +};
  2851. +
  2852. +void __init bcm2708_map_io(void)
  2853. +{
  2854. + iotable_init(bcm2708_io_desc, ARRAY_SIZE(bcm2708_io_desc));
  2855. +}
  2856. +
  2857. +/* The STC is a free running counter that increments at the rate of 1MHz */
  2858. +#define STC_FREQ_HZ 1000000
  2859. +
  2860. +static inline uint32_t timer_read(void)
  2861. +{
  2862. + /* STC: a free running counter that increments at the rate of 1MHz */
  2863. + return readl(__io_address(ST_BASE + 0x04));
  2864. +}
  2865. +
  2866. +static unsigned long bcm2708_read_current_timer(void)
  2867. +{
  2868. + return timer_read();
  2869. +}
  2870. +
  2871. +static u32 notrace bcm2708_read_sched_clock(void)
  2872. +{
  2873. + return timer_read();
  2874. +}
  2875. +
  2876. +static cycle_t clksrc_read(struct clocksource *cs)
  2877. +{
  2878. + return timer_read();
  2879. +}
  2880. +
  2881. +static struct clocksource clocksource_stc = {
  2882. + .name = "stc",
  2883. + .rating = 300,
  2884. + .read = clksrc_read,
  2885. + .mask = CLOCKSOURCE_MASK(32),
  2886. + .flags = CLOCK_SOURCE_IS_CONTINUOUS,
  2887. +};
  2888. +
  2889. +unsigned long frc_clock_ticks32(void)
  2890. +{
  2891. + return timer_read();
  2892. +}
  2893. +
  2894. +static void __init bcm2708_clocksource_init(void)
  2895. +{
  2896. + if (clocksource_register_hz(&clocksource_stc, STC_FREQ_HZ)) {
  2897. + printk(KERN_ERR "timer: failed to initialize clock "
  2898. + "source %s\n", clocksource_stc.name);
  2899. + }
  2900. +}
  2901. +
  2902. +
  2903. +/*
  2904. + * These are fixed clocks.
  2905. + */
  2906. +static struct clk ref24_clk = {
  2907. + .rate = UART0_CLOCK, /* The UART is clocked at 3MHz via APB_CLK */
  2908. +};
  2909. +
  2910. +static struct clk osc_clk = {
  2911. +#ifdef CONFIG_ARCH_BCM2708_CHIPIT
  2912. + .rate = 27000000,
  2913. +#else
  2914. + .rate = 500000000, /* ARM clock is set from the VideoCore booter */
  2915. +#endif
  2916. +};
  2917. +
  2918. +/* warning - the USB needs a clock > 34MHz */
  2919. +
  2920. +static struct clk sdhost_clk = {
  2921. +#ifdef CONFIG_ARCH_BCM2708_CHIPIT
  2922. + .rate = 4000000, /* 4MHz */
  2923. +#else
  2924. + .rate = 250000000, /* 250MHz */
  2925. +#endif
  2926. +};
  2927. +
  2928. +static struct clk_lookup lookups[] = {
  2929. + { /* UART0 */
  2930. + .dev_id = "dev:f1",
  2931. + .clk = &ref24_clk,
  2932. + },
  2933. + { /* USB */
  2934. + .dev_id = "bcm2708_usb",
  2935. + .clk = &osc_clk,
  2936. + }, { /* SPI */
  2937. + .dev_id = "bcm2708_spi.0",
  2938. + .clk = &sdhost_clk,
  2939. + }, { /* BSC0 */
  2940. + .dev_id = "bcm2708_i2c.0",
  2941. + .clk = &sdhost_clk,
  2942. + }, { /* BSC1 */
  2943. + .dev_id = "bcm2708_i2c.1",
  2944. + .clk = &sdhost_clk,
  2945. + }
  2946. +};
  2947. +
  2948. +#define UART0_IRQ { IRQ_UART, 0 /*NO_IRQ*/ }
  2949. +#define UART0_DMA { 15, 14 }
  2950. +
  2951. +AMBA_DEVICE(uart0, "dev:f1", UART0, NULL);
  2952. +
  2953. +static struct amba_device *amba_devs[] __initdata = {
  2954. + &uart0_device,
  2955. +};
  2956. +
  2957. +static struct resource bcm2708_dmaman_resources[] = {
  2958. + {
  2959. + .start = DMA_BASE,
  2960. + .end = DMA_BASE + SZ_4K - 1,
  2961. + .flags = IORESOURCE_MEM,
  2962. + }
  2963. +};
  2964. +
  2965. +static struct platform_device bcm2708_dmaman_device = {
  2966. + .name = BCM_DMAMAN_DRIVER_NAME,
  2967. + .id = 0, /* first bcm2708_dma */
  2968. + .resource = bcm2708_dmaman_resources,
  2969. + .num_resources = ARRAY_SIZE(bcm2708_dmaman_resources),
  2970. +};
  2971. +
  2972. +#if defined(CONFIG_W1_MASTER_GPIO) || defined(CONFIG_W1_MASTER_GPIO_MODULE)
  2973. +static struct w1_gpio_platform_data w1_gpio_pdata = {
  2974. + .pin = W1_GPIO,
  2975. + .is_open_drain = 0,
  2976. +};
  2977. +
  2978. +static struct platform_device w1_device = {
  2979. + .name = "w1-gpio",
  2980. + .id = -1,
  2981. + .dev.platform_data = &w1_gpio_pdata,
  2982. +};
  2983. +#endif
  2984. +
  2985. +static u64 fb_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  2986. +
  2987. +static struct platform_device bcm2708_fb_device = {
  2988. + .name = "bcm2708_fb",
  2989. + .id = -1, /* only one bcm2708_fb */
  2990. + .resource = NULL,
  2991. + .num_resources = 0,
  2992. + .dev = {
  2993. + .dma_mask = &fb_dmamask,
  2994. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  2995. + },
  2996. +};
  2997. +
  2998. +static struct plat_serial8250_port bcm2708_uart1_platform_data[] = {
  2999. + {
  3000. + .mapbase = UART1_BASE + 0x40,
  3001. + .irq = IRQ_AUX,
  3002. + .uartclk = 125000000,
  3003. + .regshift = 2,
  3004. + .iotype = UPIO_MEM,
  3005. + .flags = UPF_FIXED_TYPE | UPF_IOREMAP | UPF_SKIP_TEST,
  3006. + .type = PORT_8250,
  3007. + },
  3008. + {},
  3009. +};
  3010. +
  3011. +static struct platform_device bcm2708_uart1_device = {
  3012. + .name = "serial8250",
  3013. + .id = PLAT8250_DEV_PLATFORM,
  3014. + .dev = {
  3015. + .platform_data = bcm2708_uart1_platform_data,
  3016. + },
  3017. +};
  3018. +
  3019. +static struct resource bcm2708_usb_resources[] = {
  3020. + [0] = {
  3021. + .start = USB_BASE,
  3022. + .end = USB_BASE + SZ_128K - 1,
  3023. + .flags = IORESOURCE_MEM,
  3024. + },
  3025. + [1] = {
  3026. + .start = MPHI_BASE,
  3027. + .end = MPHI_BASE + SZ_4K - 1,
  3028. + .flags = IORESOURCE_MEM,
  3029. + },
  3030. + [2] = {
  3031. + .start = IRQ_HOSTPORT,
  3032. + .end = IRQ_HOSTPORT,
  3033. + .flags = IORESOURCE_IRQ,
  3034. + },
  3035. +};
  3036. +
  3037. +
  3038. +static u64 usb_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  3039. +
  3040. +static struct platform_device bcm2708_usb_device = {
  3041. + .name = "bcm2708_usb",
  3042. + .id = -1, /* only one bcm2708_usb */
  3043. + .resource = bcm2708_usb_resources,
  3044. + .num_resources = ARRAY_SIZE(bcm2708_usb_resources),
  3045. + .dev = {
  3046. + .dma_mask = &usb_dmamask,
  3047. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  3048. + },
  3049. +};
  3050. +
  3051. +static struct resource bcm2708_vcio_resources[] = {
  3052. + [0] = { /* mailbox/semaphore/doorbell access */
  3053. + .start = MCORE_BASE,
  3054. + .end = MCORE_BASE + SZ_4K - 1,
  3055. + .flags = IORESOURCE_MEM,
  3056. + },
  3057. +};
  3058. +
  3059. +static u64 vcio_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  3060. +
  3061. +static struct platform_device bcm2708_vcio_device = {
  3062. + .name = BCM_VCIO_DRIVER_NAME,
  3063. + .id = -1, /* only one VideoCore I/O area */
  3064. + .resource = bcm2708_vcio_resources,
  3065. + .num_resources = ARRAY_SIZE(bcm2708_vcio_resources),
  3066. + .dev = {
  3067. + .dma_mask = &vcio_dmamask,
  3068. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  3069. + },
  3070. +};
  3071. +
  3072. +#ifdef CONFIG_BCM2708_GPIO
  3073. +#define BCM_GPIO_DRIVER_NAME "bcm2708_gpio"
  3074. +
  3075. +static struct resource bcm2708_gpio_resources[] = {
  3076. + [0] = { /* general purpose I/O */
  3077. + .start = GPIO_BASE,
  3078. + .end = GPIO_BASE + SZ_4K - 1,
  3079. + .flags = IORESOURCE_MEM,
  3080. + },
  3081. +};
  3082. +
  3083. +static u64 gpio_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  3084. +
  3085. +static struct platform_device bcm2708_gpio_device = {
  3086. + .name = BCM_GPIO_DRIVER_NAME,
  3087. + .id = -1, /* only one VideoCore I/O area */
  3088. + .resource = bcm2708_gpio_resources,
  3089. + .num_resources = ARRAY_SIZE(bcm2708_gpio_resources),
  3090. + .dev = {
  3091. + .dma_mask = &gpio_dmamask,
  3092. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  3093. + },
  3094. +};
  3095. +#endif
  3096. +
  3097. +static struct resource bcm2708_systemtimer_resources[] = {
  3098. + [0] = { /* system timer access */
  3099. + .start = ST_BASE,
  3100. + .end = ST_BASE + SZ_4K - 1,
  3101. + .flags = IORESOURCE_MEM,
  3102. + },
  3103. + {
  3104. + .start = IRQ_TIMER3,
  3105. + .end = IRQ_TIMER3,
  3106. + .flags = IORESOURCE_IRQ,
  3107. + }
  3108. +
  3109. +};
  3110. +
  3111. +static u64 systemtimer_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  3112. +
  3113. +static struct platform_device bcm2708_systemtimer_device = {
  3114. + .name = "bcm2708_systemtimer",
  3115. + .id = -1, /* only one VideoCore I/O area */
  3116. + .resource = bcm2708_systemtimer_resources,
  3117. + .num_resources = ARRAY_SIZE(bcm2708_systemtimer_resources),
  3118. + .dev = {
  3119. + .dma_mask = &systemtimer_dmamask,
  3120. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  3121. + },
  3122. +};
  3123. +
  3124. +#ifdef CONFIG_MMC_SDHCI_BCM2708 /* Arasan emmc SD */
  3125. +static struct resource bcm2708_emmc_resources[] = {
  3126. + [0] = {
  3127. + .start = EMMC_BASE,
  3128. + .end = EMMC_BASE + SZ_256 - 1, /* we only need this area */
  3129. + /* the memory map actually makes SZ_4K available */
  3130. + .flags = IORESOURCE_MEM,
  3131. + },
  3132. + [1] = {
  3133. + .start = IRQ_ARASANSDIO,
  3134. + .end = IRQ_ARASANSDIO,
  3135. + .flags = IORESOURCE_IRQ,
  3136. + },
  3137. +};
  3138. +
  3139. +static u64 bcm2708_emmc_dmamask = 0xffffffffUL;
  3140. +
  3141. +struct platform_device bcm2708_emmc_device = {
  3142. + .name = "bcm2708_sdhci",
  3143. + .id = 0,
  3144. + .num_resources = ARRAY_SIZE(bcm2708_emmc_resources),
  3145. + .resource = bcm2708_emmc_resources,
  3146. + .dev = {
  3147. + .dma_mask = &bcm2708_emmc_dmamask,
  3148. + .coherent_dma_mask = 0xffffffffUL},
  3149. +};
  3150. +#endif /* CONFIG_MMC_SDHCI_BCM2708 */
  3151. +
  3152. +static struct resource bcm2708_powerman_resources[] = {
  3153. + [0] = {
  3154. + .start = PM_BASE,
  3155. + .end = PM_BASE + SZ_256 - 1,
  3156. + .flags = IORESOURCE_MEM,
  3157. + },
  3158. +};
  3159. +
  3160. +static u64 powerman_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  3161. +
  3162. +struct platform_device bcm2708_powerman_device = {
  3163. + .name = "bcm2708_powerman",
  3164. + .id = 0,
  3165. + .num_resources = ARRAY_SIZE(bcm2708_powerman_resources),
  3166. + .resource = bcm2708_powerman_resources,
  3167. + .dev = {
  3168. + .dma_mask = &powerman_dmamask,
  3169. + .coherent_dma_mask = 0xffffffffUL},
  3170. +};
  3171. +
  3172. +
  3173. +static struct platform_device bcm2708_alsa_devices[] = {
  3174. + [0] = {
  3175. + .name = "bcm2835_AUD0",
  3176. + .id = 0, /* first audio device */
  3177. + .resource = 0,
  3178. + .num_resources = 0,
  3179. + },
  3180. + [1] = {
  3181. + .name = "bcm2835_AUD1",
  3182. + .id = 1, /* second audio device */
  3183. + .resource = 0,
  3184. + .num_resources = 0,
  3185. + },
  3186. + [2] = {
  3187. + .name = "bcm2835_AUD2",
  3188. + .id = 2, /* third audio device */
  3189. + .resource = 0,
  3190. + .num_resources = 0,
  3191. + },
  3192. + [3] = {
  3193. + .name = "bcm2835_AUD3",
  3194. + .id = 3, /* forth audio device */
  3195. + .resource = 0,
  3196. + .num_resources = 0,
  3197. + },
  3198. + [4] = {
  3199. + .name = "bcm2835_AUD4",
  3200. + .id = 4, /* fifth audio device */
  3201. + .resource = 0,
  3202. + .num_resources = 0,
  3203. + },
  3204. + [5] = {
  3205. + .name = "bcm2835_AUD5",
  3206. + .id = 5, /* sixth audio device */
  3207. + .resource = 0,
  3208. + .num_resources = 0,
  3209. + },
  3210. + [6] = {
  3211. + .name = "bcm2835_AUD6",
  3212. + .id = 6, /* seventh audio device */
  3213. + .resource = 0,
  3214. + .num_resources = 0,
  3215. + },
  3216. + [7] = {
  3217. + .name = "bcm2835_AUD7",
  3218. + .id = 7, /* eighth audio device */
  3219. + .resource = 0,
  3220. + .num_resources = 0,
  3221. + },
  3222. +};
  3223. +
  3224. +static struct resource bcm2708_spi_resources[] = {
  3225. + {
  3226. + .start = SPI0_BASE,
  3227. + .end = SPI0_BASE + SZ_256 - 1,
  3228. + .flags = IORESOURCE_MEM,
  3229. + }, {
  3230. + .start = IRQ_SPI,
  3231. + .end = IRQ_SPI,
  3232. + .flags = IORESOURCE_IRQ,
  3233. + }
  3234. +};
  3235. +
  3236. +
  3237. +static u64 bcm2708_spi_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  3238. +static struct platform_device bcm2708_spi_device = {
  3239. + .name = "bcm2708_spi",
  3240. + .id = 0,
  3241. + .num_resources = ARRAY_SIZE(bcm2708_spi_resources),
  3242. + .resource = bcm2708_spi_resources,
  3243. + .dev = {
  3244. + .dma_mask = &bcm2708_spi_dmamask,
  3245. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON)},
  3246. +};
  3247. +
  3248. +#ifdef CONFIG_BCM2708_SPIDEV
  3249. +static struct spi_board_info bcm2708_spi_devices[] = {
  3250. +#ifdef CONFIG_SPI_SPIDEV
  3251. + {
  3252. + .modalias = "spidev",
  3253. + .max_speed_hz = 500000,
  3254. + .bus_num = 0,
  3255. + .chip_select = 0,
  3256. + .mode = SPI_MODE_0,
  3257. + }, {
  3258. + .modalias = "spidev",
  3259. + .max_speed_hz = 500000,
  3260. + .bus_num = 0,
  3261. + .chip_select = 1,
  3262. + .mode = SPI_MODE_0,
  3263. + }
  3264. +#endif
  3265. +};
  3266. +#endif
  3267. +
  3268. +static struct resource bcm2708_bsc0_resources[] = {
  3269. + {
  3270. + .start = BSC0_BASE,
  3271. + .end = BSC0_BASE + SZ_256 - 1,
  3272. + .flags = IORESOURCE_MEM,
  3273. + }, {
  3274. + .start = INTERRUPT_I2C,
  3275. + .end = INTERRUPT_I2C,
  3276. + .flags = IORESOURCE_IRQ,
  3277. + }
  3278. +};
  3279. +
  3280. +static struct platform_device bcm2708_bsc0_device = {
  3281. + .name = "bcm2708_i2c",
  3282. + .id = 0,
  3283. + .num_resources = ARRAY_SIZE(bcm2708_bsc0_resources),
  3284. + .resource = bcm2708_bsc0_resources,
  3285. +};
  3286. +
  3287. +
  3288. +static struct resource bcm2708_bsc1_resources[] = {
  3289. + {
  3290. + .start = BSC1_BASE,
  3291. + .end = BSC1_BASE + SZ_256 - 1,
  3292. + .flags = IORESOURCE_MEM,
  3293. + }, {
  3294. + .start = INTERRUPT_I2C,
  3295. + .end = INTERRUPT_I2C,
  3296. + .flags = IORESOURCE_IRQ,
  3297. + }
  3298. +};
  3299. +
  3300. +static struct platform_device bcm2708_bsc1_device = {
  3301. + .name = "bcm2708_i2c",
  3302. + .id = 1,
  3303. + .num_resources = ARRAY_SIZE(bcm2708_bsc1_resources),
  3304. + .resource = bcm2708_bsc1_resources,
  3305. +};
  3306. +
  3307. +static struct platform_device bcm2835_hwmon_device = {
  3308. + .name = "bcm2835_hwmon",
  3309. +};
  3310. +
  3311. +static struct platform_device bcm2835_thermal_device = {
  3312. + .name = "bcm2835_thermal",
  3313. +};
  3314. +
  3315. +#ifdef CONFIG_SND_BCM2708_SOC_I2S_MODULE
  3316. +static struct resource bcm2708_i2s_resources[] = {
  3317. + {
  3318. + .start = I2S_BASE,
  3319. + .end = I2S_BASE + 0x20,
  3320. + .flags = IORESOURCE_MEM,
  3321. + },
  3322. + {
  3323. + .start = PCM_CLOCK_BASE,
  3324. + .end = PCM_CLOCK_BASE + 0x02,
  3325. + .flags = IORESOURCE_MEM,
  3326. + }
  3327. +};
  3328. +
  3329. +static struct platform_device bcm2708_i2s_device = {
  3330. + .name = "bcm2708-i2s",
  3331. + .id = 0,
  3332. + .num_resources = ARRAY_SIZE(bcm2708_i2s_resources),
  3333. + .resource = bcm2708_i2s_resources,
  3334. +};
  3335. +#endif
  3336. +
  3337. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC_MODULE)
  3338. +static struct platform_device snd_hifiberry_dac_device = {
  3339. + .name = "snd-hifiberry-dac",
  3340. + .id = 0,
  3341. + .num_resources = 0,
  3342. +};
  3343. +
  3344. +static struct platform_device snd_pcm5102a_codec_device = {
  3345. + .name = "pcm5102a-codec",
  3346. + .id = -1,
  3347. + .num_resources = 0,
  3348. +};
  3349. +#endif
  3350. +
  3351. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI_MODULE)
  3352. +static struct platform_device snd_hifiberry_digi_device = {
  3353. + .name = "snd-hifiberry-digi",
  3354. + .id = 0,
  3355. + .num_resources = 0,
  3356. +};
  3357. +
  3358. +static struct i2c_board_info __initdata snd_wm8804_i2c_devices[] = {
  3359. + {
  3360. + I2C_BOARD_INFO("wm8804", 0x3b)
  3361. + },
  3362. +};
  3363. +
  3364. +#endif
  3365. +
  3366. +#if defined(CONFIG_SND_BCM2708_SOC_RPI_DAC) || defined(CONFIG_SND_BCM2708_SOC_RPI_DAC_MODULE)
  3367. +static struct platform_device snd_rpi_dac_device = {
  3368. + .name = "snd-rpi-dac",
  3369. + .id = 0,
  3370. + .num_resources = 0,
  3371. +};
  3372. +
  3373. +static struct platform_device snd_pcm1794a_codec_device = {
  3374. + .name = "pcm1794a-codec",
  3375. + .id = -1,
  3376. + .num_resources = 0,
  3377. +};
  3378. +#endif
  3379. +
  3380. +
  3381. +#if defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) || defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC_MODULE)
  3382. +static struct platform_device snd_rpi_iqaudio_dac_device = {
  3383. + .name = "snd-rpi-iqaudio-dac",
  3384. + .id = 0,
  3385. + .num_resources = 0,
  3386. +};
  3387. +
  3388. +// Use the actual device name rather than generic driver name
  3389. +static struct i2c_board_info __initdata snd_pcm512x_i2c_devices[] = {
  3390. + {
  3391. + I2C_BOARD_INFO("pcm5122", 0x4c)
  3392. + },
  3393. +};
  3394. +#endif
  3395. +
  3396. +int __init bcm_register_device(struct platform_device *pdev)
  3397. +{
  3398. + int ret;
  3399. +
  3400. + ret = platform_device_register(pdev);
  3401. + if (ret)
  3402. + pr_debug("Unable to register platform device '%s': %d\n",
  3403. + pdev->name, ret);
  3404. +
  3405. + return ret;
  3406. +}
  3407. +
  3408. +int calc_rsts(int partition)
  3409. +{
  3410. + return PM_PASSWORD |
  3411. + ((partition & (1 << 0)) << 0) |
  3412. + ((partition & (1 << 1)) << 1) |
  3413. + ((partition & (1 << 2)) << 2) |
  3414. + ((partition & (1 << 3)) << 3) |
  3415. + ((partition & (1 << 4)) << 4) |
  3416. + ((partition & (1 << 5)) << 5);
  3417. +}
  3418. +
  3419. +static void bcm2708_restart(enum reboot_mode mode, const char *cmd)
  3420. +{
  3421. + extern char bcm2708_reboot_mode;
  3422. + uint32_t pm_rstc, pm_wdog;
  3423. + uint32_t timeout = 10;
  3424. + uint32_t pm_rsts = 0;
  3425. +
  3426. + if(bcm2708_reboot_mode == 'q')
  3427. + {
  3428. + // NOOBS < 1.3 booting with reboot=q
  3429. + pm_rsts = readl(__io_address(PM_RSTS));
  3430. + pm_rsts = PM_PASSWORD | pm_rsts | PM_RSTS_HADWRQ_SET;
  3431. + }
  3432. + else if(bcm2708_reboot_mode == 'p')
  3433. + {
  3434. + // NOOBS < 1.3 halting
  3435. + pm_rsts = readl(__io_address(PM_RSTS));
  3436. + pm_rsts = PM_PASSWORD | pm_rsts | PM_RSTS_HADWRH_SET;
  3437. + }
  3438. + else
  3439. + {
  3440. + pm_rsts = calc_rsts(reboot_part);
  3441. + }
  3442. +
  3443. + writel(pm_rsts, __io_address(PM_RSTS));
  3444. +
  3445. + /* Setup watchdog for reset */
  3446. + pm_rstc = readl(__io_address(PM_RSTC));
  3447. +
  3448. + pm_wdog = PM_PASSWORD | (timeout & PM_WDOG_TIME_SET); // watchdog timer = timer clock / 16; need password (31:16) + value (11:0)
  3449. + pm_rstc = PM_PASSWORD | (pm_rstc & PM_RSTC_WRCFG_CLR) | PM_RSTC_WRCFG_FULL_RESET;
  3450. +
  3451. + writel(pm_wdog, __io_address(PM_WDOG));
  3452. + writel(pm_rstc, __io_address(PM_RSTC));
  3453. +}
  3454. +
  3455. +/* 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 */
  3456. +static void bcm2708_power_off(void)
  3457. +{
  3458. + extern char bcm2708_reboot_mode;
  3459. + if(bcm2708_reboot_mode == 'q')
  3460. + {
  3461. + // NOOBS < v1.3
  3462. + bcm2708_restart('p', "");
  3463. + }
  3464. + else
  3465. + {
  3466. + /* partition 63 is special code for HALT the bootloader knows not to boot*/
  3467. + reboot_part = 63;
  3468. + /* continue with normal reset mechanism */
  3469. + bcm2708_restart(0, "");
  3470. + }
  3471. +}
  3472. +
  3473. +void __init bcm2708_init(void)
  3474. +{
  3475. + int i;
  3476. +
  3477. +#if defined(CONFIG_BCM_VC_CMA)
  3478. + vc_cma_early_init();
  3479. +#endif
  3480. + printk("bcm2708.uart_clock = %d\n", uart_clock);
  3481. + pm_power_off = bcm2708_power_off;
  3482. +
  3483. + if (uart_clock)
  3484. + lookups[0].clk->rate = uart_clock;
  3485. +
  3486. + for (i = 0; i < ARRAY_SIZE(lookups); i++)
  3487. + clkdev_add(&lookups[i]);
  3488. +
  3489. + bcm_register_device(&bcm2708_dmaman_device);
  3490. + bcm_register_device(&bcm2708_vcio_device);
  3491. +#ifdef CONFIG_BCM2708_GPIO
  3492. + bcm_register_device(&bcm2708_gpio_device);
  3493. +#endif
  3494. +#if defined(CONFIG_W1_MASTER_GPIO) || defined(CONFIG_W1_MASTER_GPIO_MODULE)
  3495. + w1_gpio_pdata.pin = w1_gpio_pin;
  3496. + platform_device_register(&w1_device);
  3497. +#endif
  3498. + bcm_register_device(&bcm2708_systemtimer_device);
  3499. + bcm_register_device(&bcm2708_fb_device);
  3500. + bcm_register_device(&bcm2708_usb_device);
  3501. + bcm_register_device(&bcm2708_uart1_device);
  3502. + bcm_register_device(&bcm2708_powerman_device);
  3503. +
  3504. +#ifdef CONFIG_MMC_SDHCI_BCM2708
  3505. + bcm_register_device(&bcm2708_emmc_device);
  3506. +#endif
  3507. + bcm2708_init_led();
  3508. + for (i = 0; i < ARRAY_SIZE(bcm2708_alsa_devices); i++)
  3509. + bcm_register_device(&bcm2708_alsa_devices[i]);
  3510. +
  3511. + bcm_register_device(&bcm2708_spi_device);
  3512. + bcm_register_device(&bcm2708_bsc0_device);
  3513. + bcm_register_device(&bcm2708_bsc1_device);
  3514. +
  3515. + bcm_register_device(&bcm2835_hwmon_device);
  3516. + bcm_register_device(&bcm2835_thermal_device);
  3517. +
  3518. +#ifdef CONFIG_SND_BCM2708_SOC_I2S_MODULE
  3519. + bcm_register_device(&bcm2708_i2s_device);
  3520. +#endif
  3521. +
  3522. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC_MODULE)
  3523. + bcm_register_device(&snd_hifiberry_dac_device);
  3524. + bcm_register_device(&snd_pcm5102a_codec_device);
  3525. +#endif
  3526. +
  3527. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI_MODULE)
  3528. + bcm_register_device(&snd_hifiberry_digi_device);
  3529. + i2c_register_board_info(1, snd_wm8804_i2c_devices, ARRAY_SIZE(snd_wm8804_i2c_devices));
  3530. +#endif
  3531. +
  3532. +#if defined(CONFIG_SND_BCM2708_SOC_RPI_DAC) || defined(CONFIG_SND_BCM2708_SOC_RPI_DAC_MODULE)
  3533. + bcm_register_device(&snd_rpi_dac_device);
  3534. + bcm_register_device(&snd_pcm1794a_codec_device);
  3535. +#endif
  3536. +
  3537. +#if defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) || defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC_MODULE)
  3538. + bcm_register_device(&snd_rpi_iqaudio_dac_device);
  3539. + i2c_register_board_info(1, snd_pcm512x_i2c_devices, ARRAY_SIZE(snd_pcm512x_i2c_devices));
  3540. +#endif
  3541. +
  3542. +
  3543. + for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
  3544. + struct amba_device *d = amba_devs[i];
  3545. + amba_device_register(d, &iomem_resource);
  3546. + }
  3547. + system_rev = boardrev;
  3548. + system_serial_low = serial;
  3549. +
  3550. +#ifdef CONFIG_BCM2708_SPIDEV
  3551. + spi_register_board_info(bcm2708_spi_devices,
  3552. + ARRAY_SIZE(bcm2708_spi_devices));
  3553. +#endif
  3554. +}
  3555. +
  3556. +static void timer_set_mode(enum clock_event_mode mode,
  3557. + struct clock_event_device *clk)
  3558. +{
  3559. + switch (mode) {
  3560. + case CLOCK_EVT_MODE_ONESHOT: /* Leave the timer disabled, .set_next_event will enable it */
  3561. + case CLOCK_EVT_MODE_SHUTDOWN:
  3562. + break;
  3563. + case CLOCK_EVT_MODE_PERIODIC:
  3564. +
  3565. + case CLOCK_EVT_MODE_UNUSED:
  3566. + case CLOCK_EVT_MODE_RESUME:
  3567. +
  3568. + default:
  3569. + printk(KERN_ERR "timer_set_mode: unhandled mode:%d\n",
  3570. + (int)mode);
  3571. + break;
  3572. + }
  3573. +
  3574. +}
  3575. +
  3576. +static int timer_set_next_event(unsigned long cycles,
  3577. + struct clock_event_device *unused)
  3578. +{
  3579. + unsigned long stc;
  3580. +
  3581. + stc = readl(__io_address(ST_BASE + 0x04));
  3582. + writel(stc + cycles, __io_address(ST_BASE + 0x18)); /* stc3 */
  3583. + return 0;
  3584. +}
  3585. +
  3586. +static struct clock_event_device timer0_clockevent = {
  3587. + .name = "timer0",
  3588. + .shift = 32,
  3589. + .features = CLOCK_EVT_FEAT_ONESHOT,
  3590. + .set_mode = timer_set_mode,
  3591. + .set_next_event = timer_set_next_event,
  3592. +};
  3593. +
  3594. +/*
  3595. + * IRQ handler for the timer
  3596. + */
  3597. +static irqreturn_t bcm2708_timer_interrupt(int irq, void *dev_id)
  3598. +{
  3599. + struct clock_event_device *evt = &timer0_clockevent;
  3600. +
  3601. + writel(1 << 3, __io_address(ST_BASE + 0x00)); /* stcs clear timer int */
  3602. +
  3603. + evt->event_handler(evt);
  3604. +
  3605. + return IRQ_HANDLED;
  3606. +}
  3607. +
  3608. +static struct irqaction bcm2708_timer_irq = {
  3609. + .name = "BCM2708 Timer Tick",
  3610. + .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
  3611. + .handler = bcm2708_timer_interrupt,
  3612. +};
  3613. +
  3614. +/*
  3615. + * Set up timer interrupt, and return the current time in seconds.
  3616. + */
  3617. +
  3618. +static struct delay_timer bcm2708_delay_timer = {
  3619. + .read_current_timer = bcm2708_read_current_timer,
  3620. + .freq = STC_FREQ_HZ,
  3621. +};
  3622. +
  3623. +static void __init bcm2708_timer_init(void)
  3624. +{
  3625. + /* init high res timer */
  3626. + bcm2708_clocksource_init();
  3627. +
  3628. + /*
  3629. + * Initialise to a known state (all timers off)
  3630. + */
  3631. + writel(0, __io_address(ARM_T_CONTROL));
  3632. + /*
  3633. + * Make irqs happen for the system timer
  3634. + */
  3635. + setup_irq(IRQ_TIMER3, &bcm2708_timer_irq);
  3636. +
  3637. + setup_sched_clock(bcm2708_read_sched_clock, 32, STC_FREQ_HZ);
  3638. +
  3639. + timer0_clockevent.mult =
  3640. + div_sc(STC_FREQ_HZ, NSEC_PER_SEC, timer0_clockevent.shift);
  3641. + timer0_clockevent.max_delta_ns =
  3642. + clockevent_delta2ns(0xffffffff, &timer0_clockevent);
  3643. + timer0_clockevent.min_delta_ns =
  3644. + clockevent_delta2ns(0xf, &timer0_clockevent);
  3645. +
  3646. + timer0_clockevent.cpumask = cpumask_of(0);
  3647. + clockevents_register_device(&timer0_clockevent);
  3648. +
  3649. + register_current_timer_delay(&bcm2708_delay_timer);
  3650. +}
  3651. +
  3652. +#if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
  3653. +#include <linux/leds.h>
  3654. +
  3655. +static struct gpio_led bcm2708_leds[] = {
  3656. + [0] = {
  3657. + .gpio = 16,
  3658. + .name = "led0",
  3659. + .default_trigger = "mmc0",
  3660. + .active_low = 1,
  3661. + },
  3662. +};
  3663. +
  3664. +static struct gpio_led_platform_data bcm2708_led_pdata = {
  3665. + .num_leds = ARRAY_SIZE(bcm2708_leds),
  3666. + .leds = bcm2708_leds,
  3667. +};
  3668. +
  3669. +static struct platform_device bcm2708_led_device = {
  3670. + .name = "leds-gpio",
  3671. + .id = -1,
  3672. + .dev = {
  3673. + .platform_data = &bcm2708_led_pdata,
  3674. + },
  3675. +};
  3676. +
  3677. +static void __init bcm2708_init_led(void)
  3678. +{
  3679. + bcm2708_leds[0].gpio = disk_led_gpio;
  3680. + bcm2708_leds[0].active_low = disk_led_active_low;
  3681. + platform_device_register(&bcm2708_led_device);
  3682. +}
  3683. +#else
  3684. +static inline void bcm2708_init_led(void)
  3685. +{
  3686. +}
  3687. +#endif
  3688. +
  3689. +void __init bcm2708_init_early(void)
  3690. +{
  3691. + /*
  3692. + * Some devices allocate their coherent buffers from atomic
  3693. + * context. Increase size of atomic coherent pool to make sure such
  3694. + * the allocations won't fail.
  3695. + */
  3696. + init_dma_coherent_pool_size(SZ_4M);
  3697. +}
  3698. +
  3699. +static void __init board_reserve(void)
  3700. +{
  3701. +#if defined(CONFIG_BCM_VC_CMA)
  3702. + vc_cma_reserve();
  3703. +#endif
  3704. +}
  3705. +
  3706. +MACHINE_START(BCM2708, "BCM2708")
  3707. + /* Maintainer: Broadcom Europe Ltd. */
  3708. + .map_io = bcm2708_map_io,
  3709. + .init_irq = bcm2708_init_irq,
  3710. + .init_time = bcm2708_timer_init,
  3711. + .init_machine = bcm2708_init,
  3712. + .init_early = bcm2708_init_early,
  3713. + .reserve = board_reserve,
  3714. + .restart = bcm2708_restart,
  3715. +MACHINE_END
  3716. +
  3717. +module_param(boardrev, uint, 0644);
  3718. +module_param(serial, uint, 0644);
  3719. +module_param(uart_clock, uint, 0644);
  3720. +module_param(disk_led_gpio, uint, 0644);
  3721. +module_param(disk_led_active_low, uint, 0644);
  3722. +module_param(reboot_part, uint, 0644);
  3723. +module_param(w1_gpio_pin, uint, 0644);
  3724. diff -Nur linux-3.13.11/arch/arm/mach-bcm2708/bcm2708_gpio.c linux-rpi/arch/arm/mach-bcm2708/bcm2708_gpio.c
  3725. --- linux-3.13.11/arch/arm/mach-bcm2708/bcm2708_gpio.c 1970-01-01 01:00:00.000000000 +0100
  3726. +++ linux-rpi/arch/arm/mach-bcm2708/bcm2708_gpio.c 2014-04-24 15:35:00.773527891 +0200
  3727. @@ -0,0 +1,361 @@
  3728. +/*
  3729. + * linux/arch/arm/mach-bcm2708/bcm2708_gpio.c
  3730. + *
  3731. + * Copyright (C) 2010 Broadcom
  3732. + *
  3733. + * This program is free software; you can redistribute it and/or modify
  3734. + * it under the terms of the GNU General Public License version 2 as
  3735. + * published by the Free Software Foundation.
  3736. + *
  3737. + */
  3738. +
  3739. +#include <linux/spinlock.h>
  3740. +#include <linux/module.h>
  3741. +#include <linux/list.h>
  3742. +#include <linux/io.h>
  3743. +#include <linux/irq.h>
  3744. +#include <linux/interrupt.h>
  3745. +#include <linux/slab.h>
  3746. +#include <mach/gpio.h>
  3747. +#include <linux/gpio.h>
  3748. +#include <linux/platform_device.h>
  3749. +#include <mach/platform.h>
  3750. +
  3751. +#define BCM_GPIO_DRIVER_NAME "bcm2708_gpio"
  3752. +#define DRIVER_NAME BCM_GPIO_DRIVER_NAME
  3753. +#define BCM_GPIO_USE_IRQ 1
  3754. +
  3755. +#define GPIOFSEL(x) (0x00+(x)*4)
  3756. +#define GPIOSET(x) (0x1c+(x)*4)
  3757. +#define GPIOCLR(x) (0x28+(x)*4)
  3758. +#define GPIOLEV(x) (0x34+(x)*4)
  3759. +#define GPIOEDS(x) (0x40+(x)*4)
  3760. +#define GPIOREN(x) (0x4c+(x)*4)
  3761. +#define GPIOFEN(x) (0x58+(x)*4)
  3762. +#define GPIOHEN(x) (0x64+(x)*4)
  3763. +#define GPIOLEN(x) (0x70+(x)*4)
  3764. +#define GPIOAREN(x) (0x7c+(x)*4)
  3765. +#define GPIOAFEN(x) (0x88+(x)*4)
  3766. +#define GPIOUD(x) (0x94+(x)*4)
  3767. +#define GPIOUDCLK(x) (0x98+(x)*4)
  3768. +
  3769. +enum { GPIO_FSEL_INPUT, GPIO_FSEL_OUTPUT,
  3770. + GPIO_FSEL_ALT5, GPIO_FSEL_ALT_4,
  3771. + GPIO_FSEL_ALT0, GPIO_FSEL_ALT1,
  3772. + GPIO_FSEL_ALT2, GPIO_FSEL_ALT3,
  3773. +};
  3774. +
  3775. + /* Each of the two spinlocks protects a different set of hardware
  3776. + * regiters and data structurs. This decouples the code of the IRQ from
  3777. + * the GPIO code. This also makes the case of a GPIO routine call from
  3778. + * the IRQ code simpler.
  3779. + */
  3780. +static DEFINE_SPINLOCK(lock); /* GPIO registers */
  3781. +
  3782. +struct bcm2708_gpio {
  3783. + struct list_head list;
  3784. + void __iomem *base;
  3785. + struct gpio_chip gc;
  3786. + unsigned long rising;
  3787. + unsigned long falling;
  3788. + unsigned long high;
  3789. + unsigned long low;
  3790. +};
  3791. +
  3792. +static int bcm2708_set_function(struct gpio_chip *gc, unsigned offset,
  3793. + int function)
  3794. +{
  3795. + struct bcm2708_gpio *gpio = container_of(gc, struct bcm2708_gpio, gc);
  3796. + unsigned long flags;
  3797. + unsigned gpiodir;
  3798. + unsigned gpio_bank = offset / 10;
  3799. + unsigned gpio_field_offset = (offset - 10 * gpio_bank) * 3;
  3800. +
  3801. +//printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_set_function %p (%d,%d)\n", gc, offset, function);
  3802. + if (offset >= ARCH_NR_GPIOS)
  3803. + return -EINVAL;
  3804. +
  3805. + spin_lock_irqsave(&lock, flags);
  3806. +
  3807. + gpiodir = readl(gpio->base + GPIOFSEL(gpio_bank));
  3808. + gpiodir &= ~(7 << gpio_field_offset);
  3809. + gpiodir |= function << gpio_field_offset;
  3810. + writel(gpiodir, gpio->base + GPIOFSEL(gpio_bank));
  3811. + spin_unlock_irqrestore(&lock, flags);
  3812. + gpiodir = readl(gpio->base + GPIOFSEL(gpio_bank));
  3813. +
  3814. + return 0;
  3815. +}
  3816. +
  3817. +static int bcm2708_gpio_dir_in(struct gpio_chip *gc, unsigned offset)
  3818. +{
  3819. + return bcm2708_set_function(gc, offset, GPIO_FSEL_INPUT);
  3820. +}
  3821. +
  3822. +static void bcm2708_gpio_set(struct gpio_chip *gc, unsigned offset, int value);
  3823. +static int bcm2708_gpio_dir_out(struct gpio_chip *gc, unsigned offset,
  3824. + int value)
  3825. +{
  3826. + int ret;
  3827. + ret = bcm2708_set_function(gc, offset, GPIO_FSEL_OUTPUT);
  3828. + if (ret >= 0)
  3829. + bcm2708_gpio_set(gc, offset, value);
  3830. + return ret;
  3831. +}
  3832. +
  3833. +static int bcm2708_gpio_get(struct gpio_chip *gc, unsigned offset)
  3834. +{
  3835. + struct bcm2708_gpio *gpio = container_of(gc, struct bcm2708_gpio, gc);
  3836. + unsigned gpio_bank = offset / 32;
  3837. + unsigned gpio_field_offset = (offset - 32 * gpio_bank);
  3838. + unsigned lev;
  3839. +
  3840. + if (offset >= ARCH_NR_GPIOS)
  3841. + return 0;
  3842. + lev = readl(gpio->base + GPIOLEV(gpio_bank));
  3843. +//printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_get %p (%d)=%d\n", gc, offset, 0x1 & (lev>>gpio_field_offset));
  3844. + return 0x1 & (lev >> gpio_field_offset);
  3845. +}
  3846. +
  3847. +static void bcm2708_gpio_set(struct gpio_chip *gc, unsigned offset, int value)
  3848. +{
  3849. + struct bcm2708_gpio *gpio = container_of(gc, struct bcm2708_gpio, gc);
  3850. + unsigned gpio_bank = offset / 32;
  3851. + unsigned gpio_field_offset = (offset - 32 * gpio_bank);
  3852. +//printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_set %p (%d=%d)\n", gc, offset, value);
  3853. + if (offset >= ARCH_NR_GPIOS)
  3854. + return;
  3855. + if (value)
  3856. + writel(1 << gpio_field_offset, gpio->base + GPIOSET(gpio_bank));
  3857. + else
  3858. + writel(1 << gpio_field_offset, gpio->base + GPIOCLR(gpio_bank));
  3859. +}
  3860. +
  3861. +/*************************************************************************************************************************
  3862. + * bcm2708 GPIO IRQ
  3863. + */
  3864. +
  3865. +#if BCM_GPIO_USE_IRQ
  3866. +
  3867. +static int bcm2708_gpio_to_irq(struct gpio_chip *chip, unsigned gpio)
  3868. +{
  3869. + return gpio_to_irq(gpio);
  3870. +}
  3871. +
  3872. +static int bcm2708_gpio_irq_set_type(struct irq_data *d, unsigned type)
  3873. +{
  3874. + unsigned irq = d->irq;
  3875. + struct bcm2708_gpio *gpio = irq_get_chip_data(irq);
  3876. +
  3877. + gpio->rising &= ~(1 << irq_to_gpio(irq));
  3878. + gpio->falling &= ~(1 << irq_to_gpio(irq));
  3879. + gpio->high &= ~(1 << irq_to_gpio(irq));
  3880. + gpio->low &= ~(1 << irq_to_gpio(irq));
  3881. +
  3882. + if (type & ~(IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING | IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
  3883. + return -EINVAL;
  3884. +
  3885. + if (type & IRQ_TYPE_EDGE_RISING)
  3886. + gpio->rising |= (1 << irq_to_gpio(irq));
  3887. + if (type & IRQ_TYPE_EDGE_FALLING)
  3888. + gpio->falling |= (1 << irq_to_gpio(irq));
  3889. + if (type & IRQ_TYPE_LEVEL_HIGH)
  3890. + gpio->high |= (1 << irq_to_gpio(irq));
  3891. + if (type & IRQ_TYPE_LEVEL_LOW)
  3892. + gpio->low |= (1 << irq_to_gpio(irq));
  3893. + return 0;
  3894. +}
  3895. +
  3896. +static void bcm2708_gpio_irq_mask(struct irq_data *d)
  3897. +{
  3898. + unsigned irq = d->irq;
  3899. + struct bcm2708_gpio *gpio = irq_get_chip_data(irq);
  3900. + unsigned gn = irq_to_gpio(irq);
  3901. + unsigned gb = gn / 32;
  3902. + unsigned long rising = readl(gpio->base + GPIOREN(gb));
  3903. + unsigned long falling = readl(gpio->base + GPIOFEN(gb));
  3904. + unsigned long high = readl(gpio->base + GPIOHEN(gb));
  3905. + unsigned long low = readl(gpio->base + GPIOLEN(gb));
  3906. +
  3907. + gn = gn % 32;
  3908. +
  3909. + writel(rising & ~(1 << gn), gpio->base + GPIOREN(gb));
  3910. + writel(falling & ~(1 << gn), gpio->base + GPIOFEN(gb));
  3911. + writel(high & ~(1 << gn), gpio->base + GPIOHEN(gb));
  3912. + writel(low & ~(1 << gn), gpio->base + GPIOLEN(gb));
  3913. +}
  3914. +
  3915. +static void bcm2708_gpio_irq_unmask(struct irq_data *d)
  3916. +{
  3917. + unsigned irq = d->irq;
  3918. + struct bcm2708_gpio *gpio = irq_get_chip_data(irq);
  3919. + unsigned gn = irq_to_gpio(irq);
  3920. + unsigned gb = gn / 32;
  3921. + unsigned long rising = readl(gpio->base + GPIOREN(gb));
  3922. + unsigned long falling = readl(gpio->base + GPIOFEN(gb));
  3923. + unsigned long high = readl(gpio->base + GPIOHEN(gb));
  3924. + unsigned long low = readl(gpio->base + GPIOLEN(gb));
  3925. +
  3926. + gn = gn % 32;
  3927. +
  3928. + writel(1 << gn, gpio->base + GPIOEDS(gb));
  3929. +
  3930. + if (gpio->rising & (1 << gn)) {
  3931. + writel(rising | (1 << gn), gpio->base + GPIOREN(gb));
  3932. + } else {
  3933. + writel(rising & ~(1 << gn), gpio->base + GPIOREN(gb));
  3934. + }
  3935. +
  3936. + if (gpio->falling & (1 << gn)) {
  3937. + writel(falling | (1 << gn), gpio->base + GPIOFEN(gb));
  3938. + } else {
  3939. + writel(falling & ~(1 << gn), gpio->base + GPIOFEN(gb));
  3940. + }
  3941. +
  3942. + if (gpio->high & (1 << gn)) {
  3943. + writel(high | (1 << gn), gpio->base + GPIOHEN(gb));
  3944. + } else {
  3945. + writel(high & ~(1 << gn), gpio->base + GPIOHEN(gb));
  3946. + }
  3947. +
  3948. + if (gpio->low & (1 << gn)) {
  3949. + writel(low | (1 << gn), gpio->base + GPIOLEN(gb));
  3950. + } else {
  3951. + writel(low & ~(1 << gn), gpio->base + GPIOLEN(gb));
  3952. + }
  3953. +}
  3954. +
  3955. +static struct irq_chip bcm2708_irqchip = {
  3956. + .name = "GPIO",
  3957. + .irq_enable = bcm2708_gpio_irq_unmask,
  3958. + .irq_disable = bcm2708_gpio_irq_mask,
  3959. + .irq_unmask = bcm2708_gpio_irq_unmask,
  3960. + .irq_mask = bcm2708_gpio_irq_mask,
  3961. + .irq_set_type = bcm2708_gpio_irq_set_type,
  3962. +};
  3963. +
  3964. +static irqreturn_t bcm2708_gpio_interrupt(int irq, void *dev_id)
  3965. +{
  3966. + unsigned long edsr;
  3967. + unsigned bank;
  3968. + int i;
  3969. + unsigned gpio;
  3970. + for (bank = 0; bank <= 1; bank++) {
  3971. + edsr = readl(__io_address(GPIO_BASE) + GPIOEDS(bank));
  3972. + for_each_set_bit(i, &edsr, 32) {
  3973. + gpio = i + bank * 32;
  3974. + generic_handle_irq(gpio_to_irq(gpio));
  3975. + }
  3976. + writel(0xffffffff, __io_address(GPIO_BASE) + GPIOEDS(bank));
  3977. + }
  3978. + return IRQ_HANDLED;
  3979. +}
  3980. +
  3981. +static struct irqaction bcm2708_gpio_irq = {
  3982. + .name = "BCM2708 GPIO catchall handler",
  3983. + .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
  3984. + .handler = bcm2708_gpio_interrupt,
  3985. +};
  3986. +
  3987. +static void bcm2708_gpio_irq_init(struct bcm2708_gpio *ucb)
  3988. +{
  3989. + unsigned irq;
  3990. +
  3991. + ucb->gc.to_irq = bcm2708_gpio_to_irq;
  3992. +
  3993. + for (irq = GPIO_IRQ_START; irq < (GPIO_IRQ_START + GPIO_IRQS); irq++) {
  3994. + irq_set_chip_data(irq, ucb);
  3995. + irq_set_chip(irq, &bcm2708_irqchip);
  3996. + set_irq_flags(irq, IRQF_VALID);
  3997. + }
  3998. + setup_irq(IRQ_GPIO3, &bcm2708_gpio_irq);
  3999. +}
  4000. +
  4001. +#else
  4002. +
  4003. +static void bcm2708_gpio_irq_init(struct bcm2708_gpio *ucb)
  4004. +{
  4005. +}
  4006. +
  4007. +#endif /* #if BCM_GPIO_USE_IRQ ***************************************************************************************************************** */
  4008. +
  4009. +static int bcm2708_gpio_probe(struct platform_device *dev)
  4010. +{
  4011. + struct bcm2708_gpio *ucb;
  4012. + struct resource *res;
  4013. + int err = 0;
  4014. +
  4015. + printk(KERN_INFO DRIVER_NAME ": bcm2708_gpio_probe %p\n", dev);
  4016. +
  4017. + ucb = kzalloc(sizeof(*ucb), GFP_KERNEL);
  4018. + if (NULL == ucb) {
  4019. + printk(KERN_ERR DRIVER_NAME ": failed to allocate "
  4020. + "mailbox memory\n");
  4021. + err = -ENOMEM;
  4022. + goto err;
  4023. + }
  4024. +
  4025. + res = platform_get_resource(dev, IORESOURCE_MEM, 0);
  4026. +
  4027. + platform_set_drvdata(dev, ucb);
  4028. + ucb->base = __io_address(GPIO_BASE);
  4029. +
  4030. + ucb->gc.label = "bcm2708_gpio";
  4031. + ucb->gc.base = 0;
  4032. + ucb->gc.ngpio = ARCH_NR_GPIOS;
  4033. + ucb->gc.owner = THIS_MODULE;
  4034. +
  4035. + ucb->gc.direction_input = bcm2708_gpio_dir_in;
  4036. + ucb->gc.direction_output = bcm2708_gpio_dir_out;
  4037. + ucb->gc.get = bcm2708_gpio_get;
  4038. + ucb->gc.set = bcm2708_gpio_set;
  4039. + ucb->gc.can_sleep = 0;
  4040. +
  4041. + bcm2708_gpio_irq_init(ucb);
  4042. +
  4043. + err = gpiochip_add(&ucb->gc);
  4044. + if (err)
  4045. + goto err;
  4046. +
  4047. +err:
  4048. + return err;
  4049. +
  4050. +}
  4051. +
  4052. +static int bcm2708_gpio_remove(struct platform_device *dev)
  4053. +{
  4054. + int err = 0;
  4055. + struct bcm2708_gpio *ucb = platform_get_drvdata(dev);
  4056. +
  4057. + printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_remove %p\n", dev);
  4058. +
  4059. + err = gpiochip_remove(&ucb->gc);
  4060. +
  4061. + platform_set_drvdata(dev, NULL);
  4062. + kfree(ucb);
  4063. +
  4064. + return err;
  4065. +}
  4066. +
  4067. +static struct platform_driver bcm2708_gpio_driver = {
  4068. + .probe = bcm2708_gpio_probe,
  4069. + .remove = bcm2708_gpio_remove,
  4070. + .driver = {
  4071. + .name = "bcm2708_gpio"},
  4072. +};
  4073. +
  4074. +static int __init bcm2708_gpio_init(void)
  4075. +{
  4076. + return platform_driver_register(&bcm2708_gpio_driver);
  4077. +}
  4078. +
  4079. +static void __exit bcm2708_gpio_exit(void)
  4080. +{
  4081. + platform_driver_unregister(&bcm2708_gpio_driver);
  4082. +}
  4083. +
  4084. +module_init(bcm2708_gpio_init);
  4085. +module_exit(bcm2708_gpio_exit);
  4086. +
  4087. +MODULE_DESCRIPTION("Broadcom BCM2708 GPIO driver");
  4088. +MODULE_LICENSE("GPL");
  4089. diff -Nur linux-3.13.11/arch/arm/mach-bcm2708/bcm2708.h linux-rpi/arch/arm/mach-bcm2708/bcm2708.h
  4090. --- linux-3.13.11/arch/arm/mach-bcm2708/bcm2708.h 1970-01-01 01:00:00.000000000 +0100
  4091. +++ linux-rpi/arch/arm/mach-bcm2708/bcm2708.h 2014-04-24 15:36:30.950526170 +0200
  4092. @@ -0,0 +1,49 @@
  4093. +/*
  4094. + * linux/arch/arm/mach-bcm2708/bcm2708.h
  4095. + *
  4096. + * BCM2708 machine support header
  4097. + *
  4098. + * Copyright (C) 2010 Broadcom
  4099. + *
  4100. + * This program is free software; you can redistribute it and/or modify
  4101. + * it under the terms of the GNU General Public License as published by
  4102. + * the Free Software Foundation; either version 2 of the License, or
  4103. + * (at your option) any later version.
  4104. + *
  4105. + * This program is distributed in the hope that it will be useful,
  4106. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  4107. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4108. + * GNU General Public License for more details.
  4109. + *
  4110. + * You should have received a copy of the GNU General Public License
  4111. + * along with this program; if not, write to the Free Software
  4112. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  4113. + */
  4114. +
  4115. +#ifndef __BCM2708_BCM2708_H
  4116. +#define __BCM2708_BCM2708_H
  4117. +
  4118. +#include <linux/amba/bus.h>
  4119. +
  4120. +extern void __init bcm2708_init(void);
  4121. +extern void __init bcm2708_init_irq(void);
  4122. +extern void __init bcm2708_map_io(void);
  4123. +extern struct sys_timer bcm2708_timer;
  4124. +extern unsigned int mmc_status(struct device *dev);
  4125. +
  4126. +#define AMBA_DEVICE(name, busid, base, plat) \
  4127. +static struct amba_device name##_device = { \
  4128. + .dev = { \
  4129. + .coherent_dma_mask = ~0, \
  4130. + .init_name = busid, \
  4131. + .platform_data = plat, \
  4132. + }, \
  4133. + .res = { \
  4134. + .start = base##_BASE, \
  4135. + .end = (base##_BASE) + SZ_4K - 1,\
  4136. + .flags = IORESOURCE_MEM, \
  4137. + }, \
  4138. + .irq = base##_IRQ, \
  4139. +}
  4140. +
  4141. +#endif
  4142. diff -Nur linux-3.13.11/arch/arm/mach-bcm2708/clock.c linux-rpi/arch/arm/mach-bcm2708/clock.c
  4143. --- linux-3.13.11/arch/arm/mach-bcm2708/clock.c 1970-01-01 01:00:00.000000000 +0100
  4144. +++ linux-rpi/arch/arm/mach-bcm2708/clock.c 2014-04-24 15:35:00.773527891 +0200
  4145. @@ -0,0 +1,61 @@
  4146. +/*
  4147. + * linux/arch/arm/mach-bcm2708/clock.c
  4148. + *
  4149. + * Copyright (C) 2010 Broadcom
  4150. + *
  4151. + * This program is free software; you can redistribute it and/or modify
  4152. + * it under the terms of the GNU General Public License as published by
  4153. + * the Free Software Foundation; either version 2 of the License, or
  4154. + * (at your option) any later version.
  4155. + *
  4156. + * This program is distributed in the hope that it will be useful,
  4157. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  4158. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4159. + * GNU General Public License for more details.
  4160. + *
  4161. + * You should have received a copy of the GNU General Public License
  4162. + * along with this program; if not, write to the Free Software
  4163. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  4164. + */
  4165. +#include <linux/module.h>
  4166. +#include <linux/kernel.h>
  4167. +#include <linux/device.h>
  4168. +#include <linux/list.h>
  4169. +#include <linux/errno.h>
  4170. +#include <linux/err.h>
  4171. +#include <linux/string.h>
  4172. +#include <linux/clk.h>
  4173. +#include <linux/mutex.h>
  4174. +
  4175. +#include <asm/clkdev.h>
  4176. +
  4177. +#include "clock.h"
  4178. +
  4179. +int clk_enable(struct clk *clk)
  4180. +{
  4181. + return 0;
  4182. +}
  4183. +EXPORT_SYMBOL(clk_enable);
  4184. +
  4185. +void clk_disable(struct clk *clk)
  4186. +{
  4187. +}
  4188. +EXPORT_SYMBOL(clk_disable);
  4189. +
  4190. +unsigned long clk_get_rate(struct clk *clk)
  4191. +{
  4192. + return clk->rate;
  4193. +}
  4194. +EXPORT_SYMBOL(clk_get_rate);
  4195. +
  4196. +long clk_round_rate(struct clk *clk, unsigned long rate)
  4197. +{
  4198. + return clk->rate;
  4199. +}
  4200. +EXPORT_SYMBOL(clk_round_rate);
  4201. +
  4202. +int clk_set_rate(struct clk *clk, unsigned long rate)
  4203. +{
  4204. + return -EIO;
  4205. +}
  4206. +EXPORT_SYMBOL(clk_set_rate);
  4207. diff -Nur linux-3.13.11/arch/arm/mach-bcm2708/clock.h linux-rpi/arch/arm/mach-bcm2708/clock.h
  4208. --- linux-3.13.11/arch/arm/mach-bcm2708/clock.h 1970-01-01 01:00:00.000000000 +0100
  4209. +++ linux-rpi/arch/arm/mach-bcm2708/clock.h 2014-04-24 15:35:00.773527891 +0200
  4210. @@ -0,0 +1,24 @@
  4211. +/*
  4212. + * linux/arch/arm/mach-bcm2708/clock.h
  4213. + *
  4214. + * Copyright (C) 2010 Broadcom
  4215. + *
  4216. + * This program is free software; you can redistribute it and/or modify
  4217. + * it under the terms of the GNU General Public License as published by
  4218. + * the Free Software Foundation; either version 2 of the License, or
  4219. + * (at your option) any later version.
  4220. + *
  4221. + * This program is distributed in the hope that it will be useful,
  4222. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  4223. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4224. + * GNU General Public License for more details.
  4225. + *
  4226. + * You should have received a copy of the GNU General Public License
  4227. + * along with this program; if not, write to the Free Software
  4228. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  4229. + */
  4230. +struct module;
  4231. +
  4232. +struct clk {
  4233. + unsigned long rate;
  4234. +};
  4235. diff -Nur linux-3.13.11/arch/arm/mach-bcm2708/dma.c linux-rpi/arch/arm/mach-bcm2708/dma.c
  4236. --- linux-3.13.11/arch/arm/mach-bcm2708/dma.c 1970-01-01 01:00:00.000000000 +0100
  4237. +++ linux-rpi/arch/arm/mach-bcm2708/dma.c 2014-04-24 15:35:00.773527891 +0200
  4238. @@ -0,0 +1,407 @@
  4239. +/*
  4240. + * linux/arch/arm/mach-bcm2708/dma.c
  4241. + *
  4242. + * Copyright (C) 2010 Broadcom
  4243. + *
  4244. + * This program is free software; you can redistribute it and/or modify
  4245. + * it under the terms of the GNU General Public License version 2 as
  4246. + * published by the Free Software Foundation.
  4247. + */
  4248. +
  4249. +#include <linux/slab.h>
  4250. +#include <linux/device.h>
  4251. +#include <linux/platform_device.h>
  4252. +#include <linux/module.h>
  4253. +#include <linux/scatterlist.h>
  4254. +
  4255. +#include <mach/dma.h>
  4256. +#include <mach/irqs.h>
  4257. +
  4258. +/*****************************************************************************\
  4259. + * *
  4260. + * Configuration *
  4261. + * *
  4262. +\*****************************************************************************/
  4263. +
  4264. +#define CACHE_LINE_MASK 31
  4265. +#define DRIVER_NAME BCM_DMAMAN_DRIVER_NAME
  4266. +#define DEFAULT_DMACHAN_BITMAP 0x10 /* channel 4 only */
  4267. +
  4268. +/* valid only for channels 0 - 14, 15 has its own base address */
  4269. +#define BCM2708_DMA_CHAN(n) ((n)<<8) /* base address */
  4270. +#define BCM2708_DMA_CHANIO(dma_base, n) \
  4271. + ((void __iomem *)((char *)(dma_base)+BCM2708_DMA_CHAN(n)))
  4272. +
  4273. +
  4274. +/*****************************************************************************\
  4275. + * *
  4276. + * DMA Auxilliary Functions *
  4277. + * *
  4278. +\*****************************************************************************/
  4279. +
  4280. +/* A DMA buffer on an arbitrary boundary may separate a cache line into a
  4281. + section inside the DMA buffer and another section outside it.
  4282. + Even if we flush DMA buffers from the cache there is always the chance that
  4283. + during a DMA someone will access the part of a cache line that is outside
  4284. + the DMA buffer - which will then bring in unwelcome data.
  4285. + Without being able to dictate our own buffer pools we must insist that
  4286. + DMA buffers consist of a whole number of cache lines.
  4287. +*/
  4288. +
  4289. +extern int
  4290. +bcm_sg_suitable_for_dma(struct scatterlist *sg_ptr, int sg_len)
  4291. +{
  4292. + int i;
  4293. +
  4294. + for (i = 0; i < sg_len; i++) {
  4295. + if (sg_ptr[i].offset & CACHE_LINE_MASK ||
  4296. + sg_ptr[i].length & CACHE_LINE_MASK)
  4297. + return 0;
  4298. + }
  4299. +
  4300. + return 1;
  4301. +}
  4302. +EXPORT_SYMBOL_GPL(bcm_sg_suitable_for_dma);
  4303. +
  4304. +extern void
  4305. +bcm_dma_start(void __iomem *dma_chan_base, dma_addr_t control_block)
  4306. +{
  4307. + dsb(); /* ARM data synchronization (push) operation */
  4308. +
  4309. + writel(control_block, dma_chan_base + BCM2708_DMA_ADDR);
  4310. + writel(BCM2708_DMA_ACTIVE, dma_chan_base + BCM2708_DMA_CS);
  4311. +}
  4312. +
  4313. +extern void bcm_dma_wait_idle(void __iomem *dma_chan_base)
  4314. +{
  4315. + dsb();
  4316. +
  4317. + /* ugly busy wait only option for now */
  4318. + while (readl(dma_chan_base + BCM2708_DMA_CS) & BCM2708_DMA_ACTIVE)
  4319. + cpu_relax();
  4320. +}
  4321. +
  4322. +EXPORT_SYMBOL_GPL(bcm_dma_start);
  4323. +
  4324. +extern bool bcm_dma_is_busy(void __iomem *dma_chan_base)
  4325. +{
  4326. + dsb();
  4327. +
  4328. + return readl(dma_chan_base + BCM2708_DMA_CS) & BCM2708_DMA_ACTIVE;
  4329. +}
  4330. +EXPORT_SYMBOL_GPL(bcm_dma_is_busy);
  4331. +
  4332. +/* Complete an ongoing DMA (assuming its results are to be ignored)
  4333. + Does nothing if there is no DMA in progress.
  4334. + This routine waits for the current AXI transfer to complete before
  4335. + terminating the current DMA. If the current transfer is hung on a DREQ used
  4336. + by an uncooperative peripheral the AXI transfer may never complete. In this
  4337. + case the routine times out and return a non-zero error code.
  4338. + Use of this routine doesn't guarantee that the ongoing or aborted DMA
  4339. + does not produce an interrupt.
  4340. +*/
  4341. +extern int
  4342. +bcm_dma_abort(void __iomem *dma_chan_base)
  4343. +{
  4344. + unsigned long int cs;
  4345. + int rc = 0;
  4346. +
  4347. + cs = readl(dma_chan_base + BCM2708_DMA_CS);
  4348. +
  4349. + if (BCM2708_DMA_ACTIVE & cs) {
  4350. + long int timeout = 10000;
  4351. +
  4352. + /* write 0 to the active bit - pause the DMA */
  4353. + writel(0, dma_chan_base + BCM2708_DMA_CS);
  4354. +
  4355. + /* wait for any current AXI transfer to complete */
  4356. + while (0 != (cs & BCM2708_DMA_ISPAUSED) && --timeout >= 0)
  4357. + cs = readl(dma_chan_base + BCM2708_DMA_CS);
  4358. +
  4359. + if (0 != (cs & BCM2708_DMA_ISPAUSED)) {
  4360. + /* we'll un-pause when we set of our next DMA */
  4361. + rc = -ETIMEDOUT;
  4362. +
  4363. + } else if (BCM2708_DMA_ACTIVE & cs) {
  4364. + /* terminate the control block chain */
  4365. + writel(0, dma_chan_base + BCM2708_DMA_NEXTCB);
  4366. +
  4367. + /* abort the whole DMA */
  4368. + writel(BCM2708_DMA_ABORT | BCM2708_DMA_ACTIVE,
  4369. + dma_chan_base + BCM2708_DMA_CS);
  4370. + }
  4371. + }
  4372. +
  4373. + return rc;
  4374. +}
  4375. +EXPORT_SYMBOL_GPL(bcm_dma_abort);
  4376. +
  4377. +
  4378. +/***************************************************************************** \
  4379. + * *
  4380. + * DMA Manager Device Methods *
  4381. + * *
  4382. +\*****************************************************************************/
  4383. +
  4384. +struct vc_dmaman {
  4385. + void __iomem *dma_base;
  4386. + u32 chan_available; /* bitmap of available channels */
  4387. + u32 has_feature[BCM_DMA_FEATURE_COUNT]; /* bitmap of feature presence */
  4388. +};
  4389. +
  4390. +static void vc_dmaman_init(struct vc_dmaman *dmaman, void __iomem *dma_base,
  4391. + u32 chans_available)
  4392. +{
  4393. + dmaman->dma_base = dma_base;
  4394. + dmaman->chan_available = chans_available;
  4395. + dmaman->has_feature[BCM_DMA_FEATURE_FAST_ORD] = 0x0c; /* chans 2 & 3 */
  4396. + dmaman->has_feature[BCM_DMA_FEATURE_BULK_ORD] = 0x01; /* chan 0 */
  4397. +}
  4398. +
  4399. +static int vc_dmaman_chan_alloc(struct vc_dmaman *dmaman,
  4400. + unsigned preferred_feature_set)
  4401. +{
  4402. + u32 chans;
  4403. + int feature;
  4404. +
  4405. + chans = dmaman->chan_available;
  4406. + for (feature = 0; feature < BCM_DMA_FEATURE_COUNT; feature++)
  4407. + /* select the subset of available channels with the desired
  4408. + feature so long as some of the candidate channels have that
  4409. + feature */
  4410. + if ((preferred_feature_set & (1 << feature)) &&
  4411. + (chans & dmaman->has_feature[feature]))
  4412. + chans &= dmaman->has_feature[feature];
  4413. +
  4414. + if (chans) {
  4415. + int chan = 0;
  4416. + /* return the ordinal of the first channel in the bitmap */
  4417. + while (chans != 0 && (chans & 1) == 0) {
  4418. + chans >>= 1;
  4419. + chan++;
  4420. + }
  4421. + /* claim the channel */
  4422. + dmaman->chan_available &= ~(1 << chan);
  4423. + return chan;
  4424. + } else
  4425. + return -ENOMEM;
  4426. +}
  4427. +
  4428. +static int vc_dmaman_chan_free(struct vc_dmaman *dmaman, int chan)
  4429. +{
  4430. + if (chan < 0)
  4431. + return -EINVAL;
  4432. + else if ((1 << chan) & dmaman->chan_available)
  4433. + return -EIDRM;
  4434. + else {
  4435. + dmaman->chan_available |= (1 << chan);
  4436. + return 0;
  4437. + }
  4438. +}
  4439. +
  4440. +/*****************************************************************************\
  4441. + * *
  4442. + * DMA IRQs *
  4443. + * *
  4444. +\*****************************************************************************/
  4445. +
  4446. +static unsigned char bcm_dma_irqs[] = {
  4447. + IRQ_DMA0,
  4448. + IRQ_DMA1,
  4449. + IRQ_DMA2,
  4450. + IRQ_DMA3,
  4451. + IRQ_DMA4,
  4452. + IRQ_DMA5,
  4453. + IRQ_DMA6,
  4454. + IRQ_DMA7,
  4455. + IRQ_DMA8,
  4456. + IRQ_DMA9,
  4457. + IRQ_DMA10,
  4458. + IRQ_DMA11,
  4459. + IRQ_DMA12
  4460. +};
  4461. +
  4462. +
  4463. +/***************************************************************************** \
  4464. + * *
  4465. + * DMA Manager Monitor *
  4466. + * *
  4467. +\*****************************************************************************/
  4468. +
  4469. +static struct device *dmaman_dev; /* we assume there's only one! */
  4470. +
  4471. +extern int bcm_dma_chan_alloc(unsigned preferred_feature_set,
  4472. + void __iomem **out_dma_base, int *out_dma_irq)
  4473. +{
  4474. + if (!dmaman_dev)
  4475. + return -ENODEV;
  4476. + else {
  4477. + struct vc_dmaman *dmaman = dev_get_drvdata(dmaman_dev);
  4478. + int rc;
  4479. +
  4480. + device_lock(dmaman_dev);
  4481. + rc = vc_dmaman_chan_alloc(dmaman, preferred_feature_set);
  4482. + if (rc >= 0) {
  4483. + *out_dma_base = BCM2708_DMA_CHANIO(dmaman->dma_base,
  4484. + rc);
  4485. + *out_dma_irq = bcm_dma_irqs[rc];
  4486. + }
  4487. + device_unlock(dmaman_dev);
  4488. +
  4489. + return rc;
  4490. + }
  4491. +}
  4492. +EXPORT_SYMBOL_GPL(bcm_dma_chan_alloc);
  4493. +
  4494. +extern int bcm_dma_chan_free(int channel)
  4495. +{
  4496. + if (dmaman_dev) {
  4497. + struct vc_dmaman *dmaman = dev_get_drvdata(dmaman_dev);
  4498. + int rc;
  4499. +
  4500. + device_lock(dmaman_dev);
  4501. + rc = vc_dmaman_chan_free(dmaman, channel);
  4502. + device_unlock(dmaman_dev);
  4503. +
  4504. + return rc;
  4505. + } else
  4506. + return -ENODEV;
  4507. +}
  4508. +EXPORT_SYMBOL_GPL(bcm_dma_chan_free);
  4509. +
  4510. +static int dev_dmaman_register(const char *dev_name, struct device *dev)
  4511. +{
  4512. + int rc = dmaman_dev ? -EINVAL : 0;
  4513. + dmaman_dev = dev;
  4514. + return rc;
  4515. +}
  4516. +
  4517. +static void dev_dmaman_deregister(const char *dev_name, struct device *dev)
  4518. +{
  4519. + dmaman_dev = NULL;
  4520. +}
  4521. +
  4522. +/*****************************************************************************\
  4523. + * *
  4524. + * DMA Device *
  4525. + * *
  4526. +\*****************************************************************************/
  4527. +
  4528. +static int dmachans = -1; /* module parameter */
  4529. +
  4530. +static int bcm_dmaman_probe(struct platform_device *pdev)
  4531. +{
  4532. + int ret = 0;
  4533. + struct vc_dmaman *dmaman;
  4534. + struct resource *dma_res = NULL;
  4535. + void __iomem *dma_base = NULL;
  4536. + int have_dma_region = 0;
  4537. +
  4538. + dmaman = kzalloc(sizeof(*dmaman), GFP_KERNEL);
  4539. + if (NULL == dmaman) {
  4540. + printk(KERN_ERR DRIVER_NAME ": failed to allocate "
  4541. + "DMA management memory\n");
  4542. + ret = -ENOMEM;
  4543. + } else {
  4544. +
  4545. + dma_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  4546. + if (dma_res == NULL) {
  4547. + printk(KERN_ERR DRIVER_NAME ": failed to obtain memory "
  4548. + "resource\n");
  4549. + ret = -ENODEV;
  4550. + } else if (!request_mem_region(dma_res->start,
  4551. + resource_size(dma_res),
  4552. + DRIVER_NAME)) {
  4553. + dev_err(&pdev->dev, "cannot obtain DMA region\n");
  4554. + ret = -EBUSY;
  4555. + } else {
  4556. + have_dma_region = 1;
  4557. + dma_base = ioremap(dma_res->start,
  4558. + resource_size(dma_res));
  4559. + if (!dma_base) {
  4560. + dev_err(&pdev->dev, "cannot map DMA region\n");
  4561. + ret = -ENOMEM;
  4562. + } else {
  4563. + /* use module parameter if one was provided */
  4564. + if (dmachans > 0)
  4565. + vc_dmaman_init(dmaman, dma_base,
  4566. + dmachans);
  4567. + else
  4568. + vc_dmaman_init(dmaman, dma_base,
  4569. + DEFAULT_DMACHAN_BITMAP);
  4570. +
  4571. + platform_set_drvdata(pdev, dmaman);
  4572. + dev_dmaman_register(DRIVER_NAME, &pdev->dev);
  4573. +
  4574. + printk(KERN_INFO DRIVER_NAME ": DMA manager "
  4575. + "at %p\n", dma_base);
  4576. + }
  4577. + }
  4578. + }
  4579. + if (ret != 0) {
  4580. + if (dma_base)
  4581. + iounmap(dma_base);
  4582. + if (dma_res && have_dma_region)
  4583. + release_mem_region(dma_res->start,
  4584. + resource_size(dma_res));
  4585. + if (dmaman)
  4586. + kfree(dmaman);
  4587. + }
  4588. + return ret;
  4589. +}
  4590. +
  4591. +static int bcm_dmaman_remove(struct platform_device *pdev)
  4592. +{
  4593. + struct vc_dmaman *dmaman = platform_get_drvdata(pdev);
  4594. +
  4595. + platform_set_drvdata(pdev, NULL);
  4596. + dev_dmaman_deregister(DRIVER_NAME, &pdev->dev);
  4597. + kfree(dmaman);
  4598. +
  4599. + return 0;
  4600. +}
  4601. +
  4602. +static struct platform_driver bcm_dmaman_driver = {
  4603. + .probe = bcm_dmaman_probe,
  4604. + .remove = bcm_dmaman_remove,
  4605. +
  4606. + .driver = {
  4607. + .name = DRIVER_NAME,
  4608. + .owner = THIS_MODULE,
  4609. + },
  4610. +};
  4611. +
  4612. +/*****************************************************************************\
  4613. + * *
  4614. + * Driver init/exit *
  4615. + * *
  4616. +\*****************************************************************************/
  4617. +
  4618. +static int __init bcm_dmaman_drv_init(void)
  4619. +{
  4620. + int ret;
  4621. +
  4622. + ret = platform_driver_register(&bcm_dmaman_driver);
  4623. + if (ret != 0) {
  4624. + printk(KERN_ERR DRIVER_NAME ": failed to register "
  4625. + "on platform\n");
  4626. + }
  4627. +
  4628. + return ret;
  4629. +}
  4630. +
  4631. +static void __exit bcm_dmaman_drv_exit(void)
  4632. +{
  4633. + platform_driver_unregister(&bcm_dmaman_driver);
  4634. +}
  4635. +
  4636. +module_init(bcm_dmaman_drv_init);
  4637. +module_exit(bcm_dmaman_drv_exit);
  4638. +
  4639. +module_param(dmachans, int, 0644);
  4640. +
  4641. +MODULE_AUTHOR("Gray Girling <grayg@broadcom.com>");
  4642. +MODULE_DESCRIPTION("DMA channel manager driver");
  4643. +MODULE_LICENSE("GPL");
  4644. +
  4645. +MODULE_PARM_DESC(dmachans, "Bitmap of DMA channels available to the ARM");
  4646. diff -Nur linux-3.13.11/arch/arm/mach-bcm2708/include/mach/arm_control.h linux-rpi/arch/arm/mach-bcm2708/include/mach/arm_control.h
  4647. --- linux-3.13.11/arch/arm/mach-bcm2708/include/mach/arm_control.h 1970-01-01 01:00:00.000000000 +0100
  4648. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/arm_control.h 2014-04-24 15:35:00.777527936 +0200
  4649. @@ -0,0 +1,419 @@
  4650. +/*
  4651. + * linux/arch/arm/mach-bcm2708/arm_control.h
  4652. + *
  4653. + * Copyright (C) 2010 Broadcom
  4654. + *
  4655. + * This program is free software; you can redistribute it and/or modify
  4656. + * it under the terms of the GNU General Public License as published by
  4657. + * the Free Software Foundation; either version 2 of the License, or
  4658. + * (at your option) any later version.
  4659. + *
  4660. + * This program is distributed in the hope that it will be useful,
  4661. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  4662. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4663. + * GNU General Public License for more details.
  4664. + *
  4665. + * You should have received a copy of the GNU General Public License
  4666. + * along with this program; if not, write to the Free Software
  4667. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  4668. + */
  4669. +
  4670. +#ifndef __BCM2708_ARM_CONTROL_H
  4671. +#define __BCM2708_ARM_CONTROL_H
  4672. +
  4673. +/*
  4674. + * Definitions and addresses for the ARM CONTROL logic
  4675. + * This file is manually generated.
  4676. + */
  4677. +
  4678. +#define ARM_BASE 0x7E00B000
  4679. +
  4680. +/* Basic configuration */
  4681. +#define ARM_CONTROL0 HW_REGISTER_RW(ARM_BASE+0x000)
  4682. +#define ARM_C0_SIZ128M 0x00000000
  4683. +#define ARM_C0_SIZ256M 0x00000001
  4684. +#define ARM_C0_SIZ512M 0x00000002
  4685. +#define ARM_C0_SIZ1G 0x00000003
  4686. +#define ARM_C0_BRESP0 0x00000000
  4687. +#define ARM_C0_BRESP1 0x00000004
  4688. +#define ARM_C0_BRESP2 0x00000008
  4689. +#define ARM_C0_BOOTHI 0x00000010
  4690. +#define ARM_C0_UNUSED05 0x00000020 /* free */
  4691. +#define ARM_C0_FULLPERI 0x00000040
  4692. +#define ARM_C0_UNUSED78 0x00000180 /* free */
  4693. +#define ARM_C0_JTAGMASK 0x00000E00
  4694. +#define ARM_C0_JTAGOFF 0x00000000
  4695. +#define ARM_C0_JTAGBASH 0x00000800 /* Debug on GPIO off */
  4696. +#define ARM_C0_JTAGGPIO 0x00000C00 /* Debug on GPIO on */
  4697. +#define ARM_C0_APROTMSK 0x0000F000
  4698. +#define ARM_C0_DBG0SYNC 0x00010000 /* VPU0 halt sync */
  4699. +#define ARM_C0_DBG1SYNC 0x00020000 /* VPU1 halt sync */
  4700. +#define ARM_C0_SWDBGREQ 0x00040000 /* HW debug request */
  4701. +#define ARM_C0_PASSHALT 0x00080000 /* ARM halt passed to debugger */
  4702. +#define ARM_C0_PRIO_PER 0x00F00000 /* per priority mask */
  4703. +#define ARM_C0_PRIO_L2 0x0F000000
  4704. +#define ARM_C0_PRIO_UC 0xF0000000
  4705. +
  4706. +#define ARM_C0_APROTPASS 0x0000A000 /* Translate 1:1 */
  4707. +#define ARM_C0_APROTUSER 0x00000000 /* Only user mode */
  4708. +#define ARM_C0_APROTSYST 0x0000F000 /* Only system mode */
  4709. +
  4710. +
  4711. +#define ARM_CONTROL1 HW_REGISTER_RW(ARM_BASE+0x440)
  4712. +#define ARM_C1_TIMER 0x00000001 /* re-route timer IRQ to VC */
  4713. +#define ARM_C1_MAIL 0x00000002 /* re-route Mail IRQ to VC */
  4714. +#define ARM_C1_BELL0 0x00000004 /* re-route Doorbell 0 to VC */
  4715. +#define ARM_C1_BELL1 0x00000008 /* re-route Doorbell 1 to VC */
  4716. +#define ARM_C1_PERSON 0x00000100 /* peripherals on */
  4717. +#define ARM_C1_REQSTOP 0x00000200 /* ASYNC bridge request stop */
  4718. +
  4719. +#define ARM_STATUS HW_REGISTER_RW(ARM_BASE+0x444)
  4720. +#define ARM_S_ACKSTOP 0x80000000 /* Bridge stopped */
  4721. +#define ARM_S_READPEND 0x000003FF /* pending reads counter */
  4722. +#define ARM_S_WRITPEND 0x000FFC00 /* pending writes counter */
  4723. +
  4724. +#define ARM_ERRHALT HW_REGISTER_RW(ARM_BASE+0x448)
  4725. +#define ARM_EH_PERIBURST 0x00000001 /* Burst write seen on peri bus */
  4726. +#define ARM_EH_ILLADDRS1 0x00000002 /* Address bits 25-27 error */
  4727. +#define ARM_EH_ILLADDRS2 0x00000004 /* Address bits 31-28 error */
  4728. +#define ARM_EH_VPU0HALT 0x00000008 /* VPU0 halted & in debug mode */
  4729. +#define ARM_EH_VPU1HALT 0x00000010 /* VPU1 halted & in debug mode */
  4730. +#define ARM_EH_ARMHALT 0x00000020 /* ARM in halted debug mode */
  4731. +
  4732. +#define ARM_ID_SECURE HW_REGISTER_RW(ARM_BASE+0x00C)
  4733. +#define ARM_ID HW_REGISTER_RW(ARM_BASE+0x44C)
  4734. +#define ARM_IDVAL 0x364D5241
  4735. +
  4736. +/* Translation memory */
  4737. +#define ARM_TRANSLATE HW_REGISTER_RW(ARM_BASE+0x100)
  4738. +/* 32 locations: 0x100.. 0x17F */
  4739. +/* 32 spare means we CAN go to 64 pages.... */
  4740. +
  4741. +
  4742. +/* Interrupts */
  4743. +#define ARM_IRQ_PEND0 HW_REGISTER_RW(ARM_BASE+0x200) /* Top IRQ bits */
  4744. +#define ARM_I0_TIMER 0x00000001 /* timer IRQ */
  4745. +#define ARM_I0_MAIL 0x00000002 /* Mail IRQ */
  4746. +#define ARM_I0_BELL0 0x00000004 /* Doorbell 0 */
  4747. +#define ARM_I0_BELL1 0x00000008 /* Doorbell 1 */
  4748. +#define ARM_I0_BANK1 0x00000100 /* Bank1 IRQ */
  4749. +#define ARM_I0_BANK2 0x00000200 /* Bank2 IRQ */
  4750. +
  4751. +#define ARM_IRQ_PEND1 HW_REGISTER_RW(ARM_BASE+0x204) /* All bank1 IRQ bits */
  4752. +/* todo: all I1_interrupt sources */
  4753. +#define ARM_IRQ_PEND2 HW_REGISTER_RW(ARM_BASE+0x208) /* All bank2 IRQ bits */
  4754. +/* todo: all I2_interrupt sources */
  4755. +
  4756. +#define ARM_IRQ_FAST HW_REGISTER_RW(ARM_BASE+0x20C) /* FIQ control */
  4757. +#define ARM_IF_INDEX 0x0000007F /* FIQ select */
  4758. +#define ARM_IF_ENABLE 0x00000080 /* FIQ enable */
  4759. +#define ARM_IF_VCMASK 0x0000003F /* FIQ = (index from VC source) */
  4760. +#define ARM_IF_TIMER 0x00000040 /* FIQ = ARM timer */
  4761. +#define ARM_IF_MAIL 0x00000041 /* FIQ = ARM Mail */
  4762. +#define ARM_IF_BELL0 0x00000042 /* FIQ = ARM Doorbell 0 */
  4763. +#define ARM_IF_BELL1 0x00000043 /* FIQ = ARM Doorbell 1 */
  4764. +#define ARM_IF_VP0HALT 0x00000044 /* FIQ = VPU0 Halt seen */
  4765. +#define ARM_IF_VP1HALT 0x00000045 /* FIQ = VPU1 Halt seen */
  4766. +#define ARM_IF_ILLEGAL 0x00000046 /* FIQ = Illegal access seen */
  4767. +
  4768. +#define ARM_IRQ_ENBL1 HW_REGISTER_RW(ARM_BASE+0x210) /* Bank1 enable bits */
  4769. +#define ARM_IRQ_ENBL2 HW_REGISTER_RW(ARM_BASE+0x214) /* Bank2 enable bits */
  4770. +#define ARM_IRQ_ENBL3 HW_REGISTER_RW(ARM_BASE+0x218) /* ARM irqs enable bits */
  4771. +#define ARM_IRQ_DIBL1 HW_REGISTER_RW(ARM_BASE+0x21C) /* Bank1 disable bits */
  4772. +#define ARM_IRQ_DIBL2 HW_REGISTER_RW(ARM_BASE+0x220) /* Bank2 disable bits */
  4773. +#define ARM_IRQ_DIBL3 HW_REGISTER_RW(ARM_BASE+0x224) /* ARM irqs disable bits */
  4774. +#define ARM_IE_TIMER 0x00000001 /* Timer IRQ */
  4775. +#define ARM_IE_MAIL 0x00000002 /* Mail IRQ */
  4776. +#define ARM_IE_BELL0 0x00000004 /* Doorbell 0 */
  4777. +#define ARM_IE_BELL1 0x00000008 /* Doorbell 1 */
  4778. +#define ARM_IE_VP0HALT 0x00000010 /* VPU0 Halt */
  4779. +#define ARM_IE_VP1HALT 0x00000020 /* VPU1 Halt */
  4780. +#define ARM_IE_ILLEGAL 0x00000040 /* Illegal access seen */
  4781. +
  4782. +/* Timer */
  4783. +/* For reg. fields see sp804 spec. */
  4784. +#define ARM_T_LOAD HW_REGISTER_RW(ARM_BASE+0x400)
  4785. +#define ARM_T_VALUE HW_REGISTER_RW(ARM_BASE+0x404)
  4786. +#define ARM_T_CONTROL HW_REGISTER_RW(ARM_BASE+0x408)
  4787. +#define ARM_T_IRQCNTL HW_REGISTER_RW(ARM_BASE+0x40C)
  4788. +#define ARM_T_RAWIRQ HW_REGISTER_RW(ARM_BASE+0x410)
  4789. +#define ARM_T_MSKIRQ HW_REGISTER_RW(ARM_BASE+0x414)
  4790. +#define ARM_T_RELOAD HW_REGISTER_RW(ARM_BASE+0x418)
  4791. +#define ARM_T_PREDIV HW_REGISTER_RW(ARM_BASE+0x41c)
  4792. +#define ARM_T_FREECNT HW_REGISTER_RW(ARM_BASE+0x420)
  4793. +
  4794. +#define TIMER_CTRL_ONESHOT (1 << 0)
  4795. +#define TIMER_CTRL_32BIT (1 << 1)
  4796. +#define TIMER_CTRL_DIV1 (0 << 2)
  4797. +#define TIMER_CTRL_DIV16 (1 << 2)
  4798. +#define TIMER_CTRL_DIV256 (2 << 2)
  4799. +#define TIMER_CTRL_IE (1 << 5)
  4800. +#define TIMER_CTRL_PERIODIC (1 << 6)
  4801. +#define TIMER_CTRL_ENABLE (1 << 7)
  4802. +#define TIMER_CTRL_DBGHALT (1 << 8)
  4803. +#define TIMER_CTRL_ENAFREE (1 << 9)
  4804. +#define TIMER_CTRL_FREEDIV_SHIFT 16)
  4805. +#define TIMER_CTRL_FREEDIV_MASK 0xff
  4806. +
  4807. +/* Semaphores, Doorbells, Mailboxes */
  4808. +#define ARM_SBM_OWN0 (ARM_BASE+0x800)
  4809. +#define ARM_SBM_OWN1 (ARM_BASE+0x900)
  4810. +#define ARM_SBM_OWN2 (ARM_BASE+0xA00)
  4811. +#define ARM_SBM_OWN3 (ARM_BASE+0xB00)
  4812. +
  4813. +/* MAILBOXES
  4814. + * Register flags are common across all
  4815. + * owner registers. See end of this section
  4816. + *
  4817. + * Semaphores, Doorbells, Mailboxes Owner 0
  4818. + *
  4819. + */
  4820. +
  4821. +#define ARM_0_SEMS HW_REGISTER_RW(ARM_SBM_OWN0+0x00)
  4822. +#define ARM_0_SEM0 HW_REGISTER_RW(ARM_SBM_OWN0+0x00)
  4823. +#define ARM_0_SEM1 HW_REGISTER_RW(ARM_SBM_OWN0+0x04)
  4824. +#define ARM_0_SEM2 HW_REGISTER_RW(ARM_SBM_OWN0+0x08)
  4825. +#define ARM_0_SEM3 HW_REGISTER_RW(ARM_SBM_OWN0+0x0C)
  4826. +#define ARM_0_SEM4 HW_REGISTER_RW(ARM_SBM_OWN0+0x10)
  4827. +#define ARM_0_SEM5 HW_REGISTER_RW(ARM_SBM_OWN0+0x14)
  4828. +#define ARM_0_SEM6 HW_REGISTER_RW(ARM_SBM_OWN0+0x18)
  4829. +#define ARM_0_SEM7 HW_REGISTER_RW(ARM_SBM_OWN0+0x1C)
  4830. +#define ARM_0_BELL0 HW_REGISTER_RW(ARM_SBM_OWN0+0x40)
  4831. +#define ARM_0_BELL1 HW_REGISTER_RW(ARM_SBM_OWN0+0x44)
  4832. +#define ARM_0_BELL2 HW_REGISTER_RW(ARM_SBM_OWN0+0x48)
  4833. +#define ARM_0_BELL3 HW_REGISTER_RW(ARM_SBM_OWN0+0x4C)
  4834. +/* MAILBOX 0 access in Owner 0 area */
  4835. +/* Some addresses should ONLY be used by owner 0 */
  4836. +#define ARM_0_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN0+0x80) /* .. 0x8C (4 locations) */
  4837. +#define ARM_0_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN0+0x80) /* .. 0x8C (4 locations) Normal read */
  4838. +#define ARM_0_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN0+0x90) /* none-pop read */
  4839. +#define ARM_0_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN0+0x94) /* Sender read (only LS 2 bits) */
  4840. +#define ARM_0_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN0+0x98) /* Status read */
  4841. +#define ARM_0_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN0+0x9C) /* Config read/write */
  4842. +/* MAILBOX 1 access in Owner 0 area */
  4843. +/* Owner 0 should only WRITE to this mailbox */
  4844. +#define ARM_0_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN0+0xA0) /* .. 0xAC (4 locations) */
  4845. +/*#define ARM_0_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN0+0xA0) */ /* DO NOT USE THIS !!!!! */
  4846. +/*#define ARM_0_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN0+0xB0) */ /* DO NOT USE THIS !!!!! */
  4847. +/*#define ARM_0_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN0+0xB4) */ /* DO NOT USE THIS !!!!! */
  4848. +#define ARM_0_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN0+0xB8) /* Status read */
  4849. +/*#define ARM_0_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN0+0xBC) */ /* DO NOT USE THIS !!!!! */
  4850. +/* General SEM, BELL, MAIL config/status */
  4851. +#define ARM_0_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN0+0xE0) /* semaphore clear/debug register */
  4852. +#define ARM_0_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN0+0xE4) /* Doorbells clear/debug register */
  4853. +#define ARM_0_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN0+0xF8) /* ALL interrupts */
  4854. +#define ARM_0_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN0+0xFC) /* IRQS pending for owner 0 */
  4855. +
  4856. +/* Semaphores, Doorbells, Mailboxes Owner 1 */
  4857. +#define ARM_1_SEMS HW_REGISTER_RW(ARM_SBM_OWN1+0x00)
  4858. +#define ARM_1_SEM0 HW_REGISTER_RW(ARM_SBM_OWN1+0x00)
  4859. +#define ARM_1_SEM1 HW_REGISTER_RW(ARM_SBM_OWN1+0x04)
  4860. +#define ARM_1_SEM2 HW_REGISTER_RW(ARM_SBM_OWN1+0x08)
  4861. +#define ARM_1_SEM3 HW_REGISTER_RW(ARM_SBM_OWN1+0x0C)
  4862. +#define ARM_1_SEM4 HW_REGISTER_RW(ARM_SBM_OWN1+0x10)
  4863. +#define ARM_1_SEM5 HW_REGISTER_RW(ARM_SBM_OWN1+0x14)
  4864. +#define ARM_1_SEM6 HW_REGISTER_RW(ARM_SBM_OWN1+0x18)
  4865. +#define ARM_1_SEM7 HW_REGISTER_RW(ARM_SBM_OWN1+0x1C)
  4866. +#define ARM_1_BELL0 HW_REGISTER_RW(ARM_SBM_OWN1+0x40)
  4867. +#define ARM_1_BELL1 HW_REGISTER_RW(ARM_SBM_OWN1+0x44)
  4868. +#define ARM_1_BELL2 HW_REGISTER_RW(ARM_SBM_OWN1+0x48)
  4869. +#define ARM_1_BELL3 HW_REGISTER_RW(ARM_SBM_OWN1+0x4C)
  4870. +/* MAILBOX 0 access in Owner 0 area */
  4871. +/* Owner 1 should only WRITE to this mailbox */
  4872. +#define ARM_1_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN1+0x80) /* .. 0x8C (4 locations) */
  4873. +/*#define ARM_1_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN1+0x80) */ /* DO NOT USE THIS !!!!! */
  4874. +/*#define ARM_1_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN1+0x90) */ /* DO NOT USE THIS !!!!! */
  4875. +/*#define ARM_1_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN1+0x94) */ /* DO NOT USE THIS !!!!! */
  4876. +#define ARM_1_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN1+0x98) /* Status read */
  4877. +/*#define ARM_1_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN1+0x9C) */ /* DO NOT USE THIS !!!!! */
  4878. +/* MAILBOX 1 access in Owner 0 area */
  4879. +#define ARM_1_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN1+0xA0) /* .. 0xAC (4 locations) */
  4880. +#define ARM_1_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN1+0xA0) /* .. 0xAC (4 locations) Normal read */
  4881. +#define ARM_1_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN1+0xB0) /* none-pop read */
  4882. +#define ARM_1_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN1+0xB4) /* Sender read (only LS 2 bits) */
  4883. +#define ARM_1_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN1+0xB8) /* Status read */
  4884. +#define ARM_1_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN1+0xBC)
  4885. +/* General SEM, BELL, MAIL config/status */
  4886. +#define ARM_1_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN1+0xE0) /* semaphore clear/debug register */
  4887. +#define ARM_1_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN1+0xE4) /* Doorbells clear/debug register */
  4888. +#define ARM_1_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN1+0xFC) /* IRQS pending for owner 1 */
  4889. +#define ARM_1_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN1+0xF8) /* ALL interrupts */
  4890. +
  4891. +/* Semaphores, Doorbells, Mailboxes Owner 2 */
  4892. +#define ARM_2_SEMS HW_REGISTER_RW(ARM_SBM_OWN2+0x00)
  4893. +#define ARM_2_SEM0 HW_REGISTER_RW(ARM_SBM_OWN2+0x00)
  4894. +#define ARM_2_SEM1 HW_REGISTER_RW(ARM_SBM_OWN2+0x04)
  4895. +#define ARM_2_SEM2 HW_REGISTER_RW(ARM_SBM_OWN2+0x08)
  4896. +#define ARM_2_SEM3 HW_REGISTER_RW(ARM_SBM_OWN2+0x0C)
  4897. +#define ARM_2_SEM4 HW_REGISTER_RW(ARM_SBM_OWN2+0x10)
  4898. +#define ARM_2_SEM5 HW_REGISTER_RW(ARM_SBM_OWN2+0x14)
  4899. +#define ARM_2_SEM6 HW_REGISTER_RW(ARM_SBM_OWN2+0x18)
  4900. +#define ARM_2_SEM7 HW_REGISTER_RW(ARM_SBM_OWN2+0x1C)
  4901. +#define ARM_2_BELL0 HW_REGISTER_RW(ARM_SBM_OWN2+0x40)
  4902. +#define ARM_2_BELL1 HW_REGISTER_RW(ARM_SBM_OWN2+0x44)
  4903. +#define ARM_2_BELL2 HW_REGISTER_RW(ARM_SBM_OWN2+0x48)
  4904. +#define ARM_2_BELL3 HW_REGISTER_RW(ARM_SBM_OWN2+0x4C)
  4905. +/* MAILBOX 0 access in Owner 2 area */
  4906. +/* Owner 2 should only WRITE to this mailbox */
  4907. +#define ARM_2_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN2+0x80) /* .. 0x8C (4 locations) */
  4908. +/*#define ARM_2_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN2+0x80) */ /* DO NOT USE THIS !!!!! */
  4909. +/*#define ARM_2_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN2+0x90) */ /* DO NOT USE THIS !!!!! */
  4910. +/*#define ARM_2_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN2+0x94) */ /* DO NOT USE THIS !!!!! */
  4911. +#define ARM_2_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN2+0x98) /* Status read */
  4912. +/*#define ARM_2_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN2+0x9C) */ /* DO NOT USE THIS !!!!! */
  4913. +/* MAILBOX 1 access in Owner 2 area */
  4914. +/* Owner 2 should only WRITE to this mailbox */
  4915. +#define ARM_2_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN2+0xA0) /* .. 0xAC (4 locations) */
  4916. +/*#define ARM_2_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN2+0xA0) */ /* DO NOT USE THIS !!!!! */
  4917. +/*#define ARM_2_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN2+0xB0) */ /* DO NOT USE THIS !!!!! */
  4918. +/*#define ARM_2_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN2+0xB4) */ /* DO NOT USE THIS !!!!! */
  4919. +#define ARM_2_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN2+0xB8) /* Status read */
  4920. +/*#define ARM_2_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN2+0xBC) */ /* DO NOT USE THIS !!!!! */
  4921. +/* General SEM, BELL, MAIL config/status */
  4922. +#define ARM_2_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN2+0xE0) /* semaphore clear/debug register */
  4923. +#define ARM_2_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN2+0xE4) /* Doorbells clear/debug register */
  4924. +#define ARM_2_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN2+0xFC) /* IRQS pending for owner 2 */
  4925. +#define ARM_2_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN2+0xF8) /* ALL interrupts */
  4926. +
  4927. +/* Semaphores, Doorbells, Mailboxes Owner 3 */
  4928. +#define ARM_3_SEMS HW_REGISTER_RW(ARM_SBM_OWN3+0x00)
  4929. +#define ARM_3_SEM0 HW_REGISTER_RW(ARM_SBM_OWN3+0x00)
  4930. +#define ARM_3_SEM1 HW_REGISTER_RW(ARM_SBM_OWN3+0x04)
  4931. +#define ARM_3_SEM2 HW_REGISTER_RW(ARM_SBM_OWN3+0x08)
  4932. +#define ARM_3_SEM3 HW_REGISTER_RW(ARM_SBM_OWN3+0x0C)
  4933. +#define ARM_3_SEM4 HW_REGISTER_RW(ARM_SBM_OWN3+0x10)
  4934. +#define ARM_3_SEM5 HW_REGISTER_RW(ARM_SBM_OWN3+0x14)
  4935. +#define ARM_3_SEM6 HW_REGISTER_RW(ARM_SBM_OWN3+0x18)
  4936. +#define ARM_3_SEM7 HW_REGISTER_RW(ARM_SBM_OWN3+0x1C)
  4937. +#define ARM_3_BELL0 HW_REGISTER_RW(ARM_SBM_OWN3+0x40)
  4938. +#define ARM_3_BELL1 HW_REGISTER_RW(ARM_SBM_OWN3+0x44)
  4939. +#define ARM_3_BELL2 HW_REGISTER_RW(ARM_SBM_OWN3+0x48)
  4940. +#define ARM_3_BELL3 HW_REGISTER_RW(ARM_SBM_OWN3+0x4C)
  4941. +/* MAILBOX 0 access in Owner 3 area */
  4942. +/* Owner 3 should only WRITE to this mailbox */
  4943. +#define ARM_3_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN3+0x80) /* .. 0x8C (4 locations) */
  4944. +/*#define ARM_3_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN3+0x80) */ /* DO NOT USE THIS !!!!! */
  4945. +/*#define ARM_3_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN3+0x90) */ /* DO NOT USE THIS !!!!! */
  4946. +/*#define ARM_3_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN3+0x94) */ /* DO NOT USE THIS !!!!! */
  4947. +#define ARM_3_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN3+0x98) /* Status read */
  4948. +/*#define ARM_3_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN3+0x9C) */ /* DO NOT USE THIS !!!!! */
  4949. +/* MAILBOX 1 access in Owner 3 area */
  4950. +/* Owner 3 should only WRITE to this mailbox */
  4951. +#define ARM_3_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN3+0xA0) /* .. 0xAC (4 locations) */
  4952. +/*#define ARM_3_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN3+0xA0) */ /* DO NOT USE THIS !!!!! */
  4953. +/*#define ARM_3_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN3+0xB0) */ /* DO NOT USE THIS !!!!! */
  4954. +/*#define ARM_3_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN3+0xB4) */ /* DO NOT USE THIS !!!!! */
  4955. +#define ARM_3_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN3+0xB8) /* Status read */
  4956. +/*#define ARM_3_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN3+0xBC) */ /* DO NOT USE THIS !!!!! */
  4957. +/* General SEM, BELL, MAIL config/status */
  4958. +#define ARM_3_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN3+0xE0) /* semaphore clear/debug register */
  4959. +#define ARM_3_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN3+0xE4) /* Doorbells clear/debug register */
  4960. +#define ARM_3_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN3+0xFC) /* IRQS pending for owner 3 */
  4961. +#define ARM_3_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN3+0xF8) /* ALL interrupts */
  4962. +
  4963. +
  4964. +
  4965. +/* Mailbox flags. Valid for all owners */
  4966. +
  4967. +/* Mailbox status register (...0x98) */
  4968. +#define ARM_MS_FULL 0x80000000
  4969. +#define ARM_MS_EMPTY 0x40000000
  4970. +#define ARM_MS_LEVEL 0x400000FF /* Max. value depdnds on mailbox depth parameter */
  4971. +
  4972. +/* MAILBOX config/status register (...0x9C) */
  4973. +/* ANY write to this register clears the error bits! */
  4974. +#define ARM_MC_IHAVEDATAIRQEN 0x00000001 /* mailbox irq enable: has data */
  4975. +#define ARM_MC_IHAVESPACEIRQEN 0x00000002 /* mailbox irq enable: has space */
  4976. +#define ARM_MC_OPPISEMPTYIRQEN 0x00000004 /* mailbox irq enable: Opp. is empty */
  4977. +#define ARM_MC_MAIL_CLEAR 0x00000008 /* mailbox clear write 1, then 0 */
  4978. +#define ARM_MC_IHAVEDATAIRQPEND 0x00000010 /* mailbox irq pending: has space */
  4979. +#define ARM_MC_IHAVESPACEIRQPEND 0x00000020 /* mailbox irq pending: Opp. is empty */
  4980. +#define ARM_MC_OPPISEMPTYIRQPEND 0x00000040 /* mailbox irq pending */
  4981. +/* Bit 7 is unused */
  4982. +#define ARM_MC_ERRNOOWN 0x00000100 /* error : none owner read from mailbox */
  4983. +#define ARM_MC_ERROVERFLW 0x00000200 /* error : write to fill mailbox */
  4984. +#define ARM_MC_ERRUNDRFLW 0x00000400 /* error : read from empty mailbox */
  4985. +
  4986. +/* Semaphore clear/debug register (...0xE0) */
  4987. +#define ARM_SD_OWN0 0x00000003 /* Owner of sem 0 */
  4988. +#define ARM_SD_OWN1 0x0000000C /* Owner of sem 1 */
  4989. +#define ARM_SD_OWN2 0x00000030 /* Owner of sem 2 */
  4990. +#define ARM_SD_OWN3 0x000000C0 /* Owner of sem 3 */
  4991. +#define ARM_SD_OWN4 0x00000300 /* Owner of sem 4 */
  4992. +#define ARM_SD_OWN5 0x00000C00 /* Owner of sem 5 */
  4993. +#define ARM_SD_OWN6 0x00003000 /* Owner of sem 6 */
  4994. +#define ARM_SD_OWN7 0x0000C000 /* Owner of sem 7 */
  4995. +#define ARM_SD_SEM0 0x00010000 /* Status of sem 0 */
  4996. +#define ARM_SD_SEM1 0x00020000 /* Status of sem 1 */
  4997. +#define ARM_SD_SEM2 0x00040000 /* Status of sem 2 */
  4998. +#define ARM_SD_SEM3 0x00080000 /* Status of sem 3 */
  4999. +#define ARM_SD_SEM4 0x00100000 /* Status of sem 4 */
  5000. +#define ARM_SD_SEM5 0x00200000 /* Status of sem 5 */
  5001. +#define ARM_SD_SEM6 0x00400000 /* Status of sem 6 */
  5002. +#define ARM_SD_SEM7 0x00800000 /* Status of sem 7 */
  5003. +
  5004. +/* Doorbells clear/debug register (...0xE4) */
  5005. +#define ARM_BD_OWN0 0x00000003 /* Owner of doorbell 0 */
  5006. +#define ARM_BD_OWN1 0x0000000C /* Owner of doorbell 1 */
  5007. +#define ARM_BD_OWN2 0x00000030 /* Owner of doorbell 2 */
  5008. +#define ARM_BD_OWN3 0x000000C0 /* Owner of doorbell 3 */
  5009. +#define ARM_BD_BELL0 0x00000100 /* Status of doorbell 0 */
  5010. +#define ARM_BD_BELL1 0x00000200 /* Status of doorbell 1 */
  5011. +#define ARM_BD_BELL2 0x00000400 /* Status of doorbell 2 */
  5012. +#define ARM_BD_BELL3 0x00000800 /* Status of doorbell 3 */
  5013. +
  5014. +/* MY IRQS register (...0xF8) */
  5015. +#define ARM_MYIRQ_BELL 0x00000001 /* This owner has a doorbell IRQ */
  5016. +#define ARM_MYIRQ_MAIL 0x00000002 /* This owner has a mailbox IRQ */
  5017. +
  5018. +/* ALL IRQS register (...0xF8) */
  5019. +#define ARM_AIS_BELL0 0x00000001 /* Doorbell 0 IRQ pending */
  5020. +#define ARM_AIS_BELL1 0x00000002 /* Doorbell 1 IRQ pending */
  5021. +#define ARM_AIS_BELL2 0x00000004 /* Doorbell 2 IRQ pending */
  5022. +#define ARM_AIS_BELL3 0x00000008 /* Doorbell 3 IRQ pending */
  5023. +#define ARM_AIS0_HAVEDATA 0x00000010 /* MAIL 0 has data IRQ pending */
  5024. +#define ARM_AIS0_HAVESPAC 0x00000020 /* MAIL 0 has space IRQ pending */
  5025. +#define ARM_AIS0_OPPEMPTY 0x00000040 /* MAIL 0 opposite is empty IRQ */
  5026. +#define ARM_AIS1_HAVEDATA 0x00000080 /* MAIL 1 has data IRQ pending */
  5027. +#define ARM_AIS1_HAVESPAC 0x00000100 /* MAIL 1 has space IRQ pending */
  5028. +#define ARM_AIS1_OPPEMPTY 0x00000200 /* MAIL 1 opposite is empty IRQ */
  5029. +/* Note that bell-0, bell-1 and MAIL0 IRQ go only to the ARM */
  5030. +/* Whilst that bell-2, bell-3 and MAIL1 IRQ go only to the VC */
  5031. +/* */
  5032. +/* ARM JTAG BASH */
  5033. +/* */
  5034. +#define AJB_BASE 0x7e2000c0
  5035. +
  5036. +#define AJBCONF HW_REGISTER_RW(AJB_BASE+0x00)
  5037. +#define AJB_BITS0 0x000000
  5038. +#define AJB_BITS4 0x000004
  5039. +#define AJB_BITS8 0x000008
  5040. +#define AJB_BITS12 0x00000C
  5041. +#define AJB_BITS16 0x000010
  5042. +#define AJB_BITS20 0x000014
  5043. +#define AJB_BITS24 0x000018
  5044. +#define AJB_BITS28 0x00001C
  5045. +#define AJB_BITS32 0x000020
  5046. +#define AJB_BITS34 0x000022
  5047. +#define AJB_OUT_MS 0x000040
  5048. +#define AJB_OUT_LS 0x000000
  5049. +#define AJB_INV_CLK 0x000080
  5050. +#define AJB_D0_RISE 0x000100
  5051. +#define AJB_D0_FALL 0x000000
  5052. +#define AJB_D1_RISE 0x000200
  5053. +#define AJB_D1_FALL 0x000000
  5054. +#define AJB_IN_RISE 0x000400
  5055. +#define AJB_IN_FALL 0x000000
  5056. +#define AJB_ENABLE 0x000800
  5057. +#define AJB_HOLD0 0x000000
  5058. +#define AJB_HOLD1 0x001000
  5059. +#define AJB_HOLD2 0x002000
  5060. +#define AJB_HOLD3 0x003000
  5061. +#define AJB_RESETN 0x004000
  5062. +#define AJB_CLKSHFT 16
  5063. +#define AJB_BUSY 0x80000000
  5064. +#define AJBTMS HW_REGISTER_RW(AJB_BASE+0x04)
  5065. +#define AJBTDI HW_REGISTER_RW(AJB_BASE+0x08)
  5066. +#define AJBTDO HW_REGISTER_RW(AJB_BASE+0x0c)
  5067. +
  5068. +#endif
  5069. diff -Nur linux-3.13.11/arch/arm/mach-bcm2708/include/mach/arm_power.h linux-rpi/arch/arm/mach-bcm2708/include/mach/arm_power.h
  5070. --- linux-3.13.11/arch/arm/mach-bcm2708/include/mach/arm_power.h 1970-01-01 01:00:00.000000000 +0100
  5071. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/arm_power.h 2014-04-24 15:35:00.777527936 +0200
  5072. @@ -0,0 +1,60 @@
  5073. +/*
  5074. + * linux/arch/arm/mach-bcm2708/include/mach/arm_power.h
  5075. + *
  5076. + * Copyright (C) 2010 Broadcom
  5077. + *
  5078. + * This program is free software; you can redistribute it and/or modify
  5079. + * it under the terms of the GNU General Public License as published by
  5080. + * the Free Software Foundation; either version 2 of the License, or
  5081. + * (at your option) any later version.
  5082. + *
  5083. + * This program is distributed in the hope that it will be useful,
  5084. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5085. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5086. + * GNU General Public License for more details.
  5087. + *
  5088. + * You should have received a copy of the GNU General Public License
  5089. + * along with this program; if not, write to the Free Software
  5090. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  5091. + */
  5092. +
  5093. +#ifndef _ARM_POWER_H
  5094. +#define _ARM_POWER_H
  5095. +
  5096. +/* Use meaningful names on each side */
  5097. +#ifdef __VIDEOCORE__
  5098. +#define PREFIX(x) ARM_##x
  5099. +#else
  5100. +#define PREFIX(x) BCM_##x
  5101. +#endif
  5102. +
  5103. +enum {
  5104. + PREFIX(POWER_SDCARD_BIT),
  5105. + PREFIX(POWER_UART_BIT),
  5106. + PREFIX(POWER_MINIUART_BIT),
  5107. + PREFIX(POWER_USB_BIT),
  5108. + PREFIX(POWER_I2C0_BIT),
  5109. + PREFIX(POWER_I2C1_BIT),
  5110. + PREFIX(POWER_I2C2_BIT),
  5111. + PREFIX(POWER_SPI_BIT),
  5112. + PREFIX(POWER_CCP2TX_BIT),
  5113. +
  5114. + PREFIX(POWER_MAX)
  5115. +};
  5116. +
  5117. +enum {
  5118. + PREFIX(POWER_SDCARD) = (1 << PREFIX(POWER_SDCARD_BIT)),
  5119. + PREFIX(POWER_UART) = (1 << PREFIX(POWER_UART_BIT)),
  5120. + PREFIX(POWER_MINIUART) = (1 << PREFIX(POWER_MINIUART_BIT)),
  5121. + PREFIX(POWER_USB) = (1 << PREFIX(POWER_USB_BIT)),
  5122. + PREFIX(POWER_I2C0) = (1 << PREFIX(POWER_I2C0_BIT)),
  5123. + PREFIX(POWER_I2C1_MASK) = (1 << PREFIX(POWER_I2C1_BIT)),
  5124. + PREFIX(POWER_I2C2_MASK) = (1 << PREFIX(POWER_I2C2_BIT)),
  5125. + PREFIX(POWER_SPI_MASK) = (1 << PREFIX(POWER_SPI_BIT)),
  5126. + PREFIX(POWER_CCP2TX_MASK) = (1 << PREFIX(POWER_CCP2TX_BIT)),
  5127. +
  5128. + PREFIX(POWER_MASK) = (1 << PREFIX(POWER_MAX)) - 1,
  5129. + PREFIX(POWER_NONE) = 0
  5130. +};
  5131. +
  5132. +#endif
  5133. diff -Nur linux-3.13.11/arch/arm/mach-bcm2708/include/mach/clkdev.h linux-rpi/arch/arm/mach-bcm2708/include/mach/clkdev.h
  5134. --- linux-3.13.11/arch/arm/mach-bcm2708/include/mach/clkdev.h 1970-01-01 01:00:00.000000000 +0100
  5135. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/clkdev.h 2014-04-24 15:35:00.777527936 +0200
  5136. @@ -0,0 +1,7 @@
  5137. +#ifndef __ASM_MACH_CLKDEV_H
  5138. +#define __ASM_MACH_CLKDEV_H
  5139. +
  5140. +#define __clk_get(clk) ({ 1; })
  5141. +#define __clk_put(clk) do { } while (0)
  5142. +
  5143. +#endif
  5144. diff -Nur linux-3.13.11/arch/arm/mach-bcm2708/include/mach/debug-macro.S linux-rpi/arch/arm/mach-bcm2708/include/mach/debug-macro.S
  5145. --- linux-3.13.11/arch/arm/mach-bcm2708/include/mach/debug-macro.S 1970-01-01 01:00:00.000000000 +0100
  5146. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/debug-macro.S 2014-04-24 15:36:30.950526170 +0200
  5147. @@ -0,0 +1,22 @@
  5148. +/* arch/arm/mach-bcm2708/include/mach/debug-macro.S
  5149. + *
  5150. + * Debugging macro include header
  5151. + *
  5152. + * Copyright (C) 2010 Broadcom
  5153. + * Copyright (C) 1994-1999 Russell King
  5154. + * Moved from linux/arch/arm/kernel/debug.S by Ben Dooks
  5155. + *
  5156. + * This program is free software; you can redistribute it and/or modify
  5157. + * it under the terms of the GNU General Public License version 2 as
  5158. + * published by the Free Software Foundation.
  5159. + *
  5160. +*/
  5161. +
  5162. +#include <mach/platform.h>
  5163. +
  5164. + .macro addruart, rp, rv, tmp
  5165. + ldr \rp, =UART0_BASE
  5166. + ldr \rv, =IO_ADDRESS(UART0_BASE)
  5167. + .endm
  5168. +
  5169. +#include <debug/pl01x.S>
  5170. diff -Nur linux-3.13.11/arch/arm/mach-bcm2708/include/mach/dma.h linux-rpi/arch/arm/mach-bcm2708/include/mach/dma.h
  5171. --- linux-3.13.11/arch/arm/mach-bcm2708/include/mach/dma.h 1970-01-01 01:00:00.000000000 +0100
  5172. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/dma.h 2014-04-24 15:35:00.777527936 +0200
  5173. @@ -0,0 +1,90 @@
  5174. +/*
  5175. + * linux/arch/arm/mach-bcm2708/include/mach/dma.h
  5176. + *
  5177. + * Copyright (C) 2010 Broadcom
  5178. + *
  5179. + * This program is free software; you can redistribute it and/or modify
  5180. + * it under the terms of the GNU General Public License version 2 as
  5181. + * published by the Free Software Foundation.
  5182. + */
  5183. +
  5184. +
  5185. +#ifndef _MACH_BCM2708_DMA_H
  5186. +#define _MACH_BCM2708_DMA_H
  5187. +
  5188. +#define BCM_DMAMAN_DRIVER_NAME "bcm2708_dma"
  5189. +
  5190. +/* DMA CS Control and Status bits */
  5191. +#define BCM2708_DMA_ACTIVE (1 << 0)
  5192. +#define BCM2708_DMA_INT (1 << 2)
  5193. +#define BCM2708_DMA_ISPAUSED (1 << 4) /* Pause requested or not active */
  5194. +#define BCM2708_DMA_ISHELD (1 << 5) /* Is held by DREQ flow control */
  5195. +#define BCM2708_DMA_ERR (1 << 8)
  5196. +#define BCM2708_DMA_ABORT (1 << 30) /* stop current CB, go to next, WO */
  5197. +#define BCM2708_DMA_RESET (1 << 31) /* WO, self clearing */
  5198. +
  5199. +/* DMA control block "info" field bits */
  5200. +#define BCM2708_DMA_INT_EN (1 << 0)
  5201. +#define BCM2708_DMA_TDMODE (1 << 1)
  5202. +#define BCM2708_DMA_WAIT_RESP (1 << 3)
  5203. +#define BCM2708_DMA_D_INC (1 << 4)
  5204. +#define BCM2708_DMA_D_WIDTH (1 << 5)
  5205. +#define BCM2708_DMA_D_DREQ (1 << 6)
  5206. +#define BCM2708_DMA_S_INC (1 << 8)
  5207. +#define BCM2708_DMA_S_WIDTH (1 << 9)
  5208. +#define BCM2708_DMA_S_DREQ (1 << 10)
  5209. +
  5210. +#define BCM2708_DMA_BURST(x) (((x)&0xf) << 12)
  5211. +#define BCM2708_DMA_PER_MAP(x) ((x) << 16)
  5212. +#define BCM2708_DMA_WAITS(x) (((x)&0x1f) << 21)
  5213. +
  5214. +#define BCM2708_DMA_DREQ_EMMC 11
  5215. +#define BCM2708_DMA_DREQ_SDHOST 13
  5216. +
  5217. +#define BCM2708_DMA_CS 0x00 /* Control and Status */
  5218. +#define BCM2708_DMA_ADDR 0x04
  5219. +/* the current control block appears in the following registers - read only */
  5220. +#define BCM2708_DMA_INFO 0x08
  5221. +#define BCM2708_DMA_SOURCE_AD 0x0c
  5222. +#define BCM2708_DMA_DEST_AD 0x10
  5223. +#define BCM2708_DMA_NEXTCB 0x1C
  5224. +#define BCM2708_DMA_DEBUG 0x20
  5225. +
  5226. +#define BCM2708_DMA4_CS (BCM2708_DMA_CHAN(4)+BCM2708_DMA_CS)
  5227. +#define BCM2708_DMA4_ADDR (BCM2708_DMA_CHAN(4)+BCM2708_DMA_ADDR)
  5228. +
  5229. +#define BCM2708_DMA_TDMODE_LEN(w, h) ((h) << 16 | (w))
  5230. +
  5231. +struct bcm2708_dma_cb {
  5232. + unsigned long info;
  5233. + unsigned long src;
  5234. + unsigned long dst;
  5235. + unsigned long length;
  5236. + unsigned long stride;
  5237. + unsigned long next;
  5238. + unsigned long pad[2];
  5239. +};
  5240. +struct scatterlist;
  5241. +
  5242. +extern int bcm_sg_suitable_for_dma(struct scatterlist *sg_ptr, int sg_len);
  5243. +extern void bcm_dma_start(void __iomem *dma_chan_base,
  5244. + dma_addr_t control_block);
  5245. +extern void bcm_dma_wait_idle(void __iomem *dma_chan_base);
  5246. +extern bool bcm_dma_is_busy(void __iomem *dma_chan_base);
  5247. +extern int /*rc*/ bcm_dma_abort(void __iomem *dma_chan_base);
  5248. +
  5249. +/* When listing features we can ask for when allocating DMA channels give
  5250. + those with higher priority smaller ordinal numbers */
  5251. +#define BCM_DMA_FEATURE_FAST_ORD 0
  5252. +#define BCM_DMA_FEATURE_BULK_ORD 1
  5253. +#define BCM_DMA_FEATURE_FAST (1<<BCM_DMA_FEATURE_FAST_ORD)
  5254. +#define BCM_DMA_FEATURE_BULK (1<<BCM_DMA_FEATURE_BULK_ORD)
  5255. +#define BCM_DMA_FEATURE_COUNT 2
  5256. +
  5257. +/* return channel no or -ve error */
  5258. +extern int bcm_dma_chan_alloc(unsigned preferred_feature_set,
  5259. + void __iomem **out_dma_base, int *out_dma_irq);
  5260. +extern int bcm_dma_chan_free(int channel);
  5261. +
  5262. +
  5263. +#endif /* _MACH_BCM2708_DMA_H */
  5264. diff -Nur linux-3.13.11/arch/arm/mach-bcm2708/include/mach/entry-macro.S linux-rpi/arch/arm/mach-bcm2708/include/mach/entry-macro.S
  5265. --- linux-3.13.11/arch/arm/mach-bcm2708/include/mach/entry-macro.S 1970-01-01 01:00:00.000000000 +0100
  5266. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/entry-macro.S 2014-04-24 15:35:00.777527936 +0200
  5267. @@ -0,0 +1,69 @@
  5268. +/*
  5269. + * arch/arm/mach-bcm2708/include/mach/entry-macro.S
  5270. + *
  5271. + * Low-level IRQ helper macros for BCM2708 platforms
  5272. + *
  5273. + * Copyright (C) 2010 Broadcom
  5274. + *
  5275. + * This program is free software; you can redistribute it and/or modify
  5276. + * it under the terms of the GNU General Public License as published by
  5277. + * the Free Software Foundation; either version 2 of the License, or
  5278. + * (at your option) any later version.
  5279. + *
  5280. + * This program is distributed in the hope that it will be useful,
  5281. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5282. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5283. + * GNU General Public License for more details.
  5284. + *
  5285. + * You should have received a copy of the GNU General Public License
  5286. + * along with this program; if not, write to the Free Software
  5287. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  5288. + */
  5289. +#include <mach/hardware.h>
  5290. +
  5291. + .macro disable_fiq
  5292. + .endm
  5293. +
  5294. + .macro get_irqnr_preamble, base, tmp
  5295. + ldr \base, =IO_ADDRESS(ARMCTRL_IC_BASE)
  5296. + .endm
  5297. +
  5298. + .macro arch_ret_to_user, tmp1, tmp2
  5299. + .endm
  5300. +
  5301. + .macro get_irqnr_and_base, irqnr, irqstat, base, tmp
  5302. + /* get masked status */
  5303. + ldr \irqstat, [\base, #(ARM_IRQ_PEND0 - ARMCTRL_IC_BASE)]
  5304. + mov \irqnr, #(ARM_IRQ0_BASE + 31)
  5305. + and \tmp, \irqstat, #0x300 @ save bits 8 and 9
  5306. + /* clear bits 8 and 9, and test */
  5307. + bics \irqstat, \irqstat, #0x300
  5308. + bne 1010f
  5309. +
  5310. + tst \tmp, #0x100
  5311. + ldrne \irqstat, [\base, #(ARM_IRQ_PEND1 - ARMCTRL_IC_BASE)]
  5312. + movne \irqnr, #(ARM_IRQ1_BASE + 31)
  5313. + @ Mask out the interrupts also present in PEND0 - see SW-5809
  5314. + bicne \irqstat, #((1<<7) | (1<<9) | (1<<10))
  5315. + bicne \irqstat, #((1<<18) | (1<<19))
  5316. + bne 1010f
  5317. +
  5318. + tst \tmp, #0x200
  5319. + ldrne \irqstat, [\base, #(ARM_IRQ_PEND2 - ARMCTRL_IC_BASE)]
  5320. + movne \irqnr, #(ARM_IRQ2_BASE + 31)
  5321. + @ Mask out the interrupts also present in PEND0 - see SW-5809
  5322. + bicne \irqstat, #((1<<21) | (1<<22) | (1<<23) | (1<<24) | (1<<25))
  5323. + bicne \irqstat, #((1<<30))
  5324. + beq 1020f
  5325. +
  5326. +1010:
  5327. + @ For non-zero x, LSB(x) = 31 - CLZ(x^(x-1))
  5328. + @ N.B. CLZ is an ARM5 instruction.
  5329. + sub \tmp, \irqstat, #1
  5330. + eor \irqstat, \irqstat, \tmp
  5331. + clz \tmp, \irqstat
  5332. + sub \irqnr, \tmp
  5333. +
  5334. +1020: @ EQ will be set if no irqs pending
  5335. +
  5336. + .endm
  5337. diff -Nur linux-3.13.11/arch/arm/mach-bcm2708/include/mach/frc.h linux-rpi/arch/arm/mach-bcm2708/include/mach/frc.h
  5338. --- linux-3.13.11/arch/arm/mach-bcm2708/include/mach/frc.h 1970-01-01 01:00:00.000000000 +0100
  5339. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/frc.h 2014-04-24 15:35:00.777527936 +0200
  5340. @@ -0,0 +1,38 @@
  5341. +/*
  5342. + * arch/arm/mach-bcm2708/include/mach/timex.h
  5343. + *
  5344. + * BCM2708 free running counter (timer)
  5345. + *
  5346. + * Copyright (C) 2010 Broadcom
  5347. + *
  5348. + * This program is free software; you can redistribute it and/or modify
  5349. + * it under the terms of the GNU General Public License as published by
  5350. + * the Free Software Foundation; either version 2 of the License, or
  5351. + * (at your option) any later version.
  5352. + *
  5353. + * This program is distributed in the hope that it will be useful,
  5354. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5355. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5356. + * GNU General Public License for more details.
  5357. + *
  5358. + * You should have received a copy of the GNU General Public License
  5359. + * along with this program; if not, write to the Free Software
  5360. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  5361. + */
  5362. +
  5363. +#ifndef _MACH_FRC_H
  5364. +#define _MACH_FRC_H
  5365. +
  5366. +#define FRC_TICK_RATE (1000000)
  5367. +
  5368. +/*! Free running counter incrementing at the CLOCK_TICK_RATE
  5369. + (slightly faster than frc_clock_ticks63()
  5370. + */
  5371. +extern unsigned long frc_clock_ticks32(void);
  5372. +
  5373. +/*! Free running counter incrementing at the CLOCK_TICK_RATE
  5374. + * Note - top bit should be ignored (see cnt32_to_63)
  5375. + */
  5376. +extern unsigned long long frc_clock_ticks63(void);
  5377. +
  5378. +#endif
  5379. diff -Nur linux-3.13.11/arch/arm/mach-bcm2708/include/mach/gpio.h linux-rpi/arch/arm/mach-bcm2708/include/mach/gpio.h
  5380. --- linux-3.13.11/arch/arm/mach-bcm2708/include/mach/gpio.h 1970-01-01 01:00:00.000000000 +0100
  5381. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/gpio.h 2014-04-24 15:36:30.950526170 +0200
  5382. @@ -0,0 +1,17 @@
  5383. +/*
  5384. + * arch/arm/mach-bcm2708/include/mach/gpio.h
  5385. + *
  5386. + * This file is licensed under the terms of the GNU General Public
  5387. + * License version 2. This program is licensed "as is" without any
  5388. + * warranty of any kind, whether express or implied.
  5389. + */
  5390. +
  5391. +#ifndef __ASM_ARCH_GPIO_H
  5392. +#define __ASM_ARCH_GPIO_H
  5393. +
  5394. +#define ARCH_NR_GPIOS 54 // number of gpio lines
  5395. +
  5396. +#define gpio_to_irq(x) ((x) + GPIO_IRQ_START)
  5397. +#define irq_to_gpio(x) ((x) - GPIO_IRQ_START)
  5398. +
  5399. +#endif
  5400. diff -Nur linux-3.13.11/arch/arm/mach-bcm2708/include/mach/hardware.h linux-rpi/arch/arm/mach-bcm2708/include/mach/hardware.h
  5401. --- linux-3.13.11/arch/arm/mach-bcm2708/include/mach/hardware.h 1970-01-01 01:00:00.000000000 +0100
  5402. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/hardware.h 2014-04-24 15:35:00.777527936 +0200
  5403. @@ -0,0 +1,28 @@
  5404. +/*
  5405. + * arch/arm/mach-bcm2708/include/mach/hardware.h
  5406. + *
  5407. + * This file contains the hardware definitions of the BCM2708 devices.
  5408. + *
  5409. + * Copyright (C) 2010 Broadcom
  5410. + *
  5411. + * This program is free software; you can redistribute it and/or modify
  5412. + * it under the terms of the GNU General Public License as published by
  5413. + * the Free Software Foundation; either version 2 of the License, or
  5414. + * (at your option) any later version.
  5415. + *
  5416. + * This program is distributed in the hope that it will be useful,
  5417. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5418. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5419. + * GNU General Public License for more details.
  5420. + *
  5421. + * You should have received a copy of the GNU General Public License
  5422. + * along with this program; if not, write to the Free Software
  5423. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  5424. + */
  5425. +#ifndef __ASM_ARCH_HARDWARE_H
  5426. +#define __ASM_ARCH_HARDWARE_H
  5427. +
  5428. +#include <asm/sizes.h>
  5429. +#include <mach/platform.h>
  5430. +
  5431. +#endif
  5432. diff -Nur linux-3.13.11/arch/arm/mach-bcm2708/include/mach/io.h linux-rpi/arch/arm/mach-bcm2708/include/mach/io.h
  5433. --- linux-3.13.11/arch/arm/mach-bcm2708/include/mach/io.h 1970-01-01 01:00:00.000000000 +0100
  5434. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/io.h 2014-04-24 15:35:00.777527936 +0200
  5435. @@ -0,0 +1,27 @@
  5436. +/*
  5437. + * arch/arm/mach-bcm2708/include/mach/io.h
  5438. + *
  5439. + * Copyright (C) 2003 ARM Limited
  5440. + *
  5441. + * This program is free software; you can redistribute it and/or modify
  5442. + * it under the terms of the GNU General Public License as published by
  5443. + * the Free Software Foundation; either version 2 of the License, or
  5444. + * (at your option) any later version.
  5445. + *
  5446. + * This program is distributed in the hope that it will be useful,
  5447. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5448. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5449. + * GNU General Public License for more details.
  5450. + *
  5451. + * You should have received a copy of the GNU General Public License
  5452. + * along with this program; if not, write to the Free Software
  5453. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  5454. + */
  5455. +#ifndef __ASM_ARM_ARCH_IO_H
  5456. +#define __ASM_ARM_ARCH_IO_H
  5457. +
  5458. +#define IO_SPACE_LIMIT 0xffffffff
  5459. +
  5460. +#define __io(a) __typesafe_io(a)
  5461. +
  5462. +#endif
  5463. diff -Nur linux-3.13.11/arch/arm/mach-bcm2708/include/mach/irqs.h linux-rpi/arch/arm/mach-bcm2708/include/mach/irqs.h
  5464. --- linux-3.13.11/arch/arm/mach-bcm2708/include/mach/irqs.h 1970-01-01 01:00:00.000000000 +0100
  5465. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/irqs.h 2014-04-24 15:35:00.777527936 +0200
  5466. @@ -0,0 +1,199 @@
  5467. +/*
  5468. + * arch/arm/mach-bcm2708/include/mach/irqs.h
  5469. + *
  5470. + * Copyright (C) 2010 Broadcom
  5471. + * Copyright (C) 2003 ARM Limited
  5472. + * Copyright (C) 2000 Deep Blue Solutions Ltd.
  5473. + *
  5474. + * This program is free software; you can redistribute it and/or modify
  5475. + * it under the terms of the GNU General Public License as published by
  5476. + * the Free Software Foundation; either version 2 of the License, or
  5477. + * (at your option) any later version.
  5478. + *
  5479. + * This program is distributed in the hope that it will be useful,
  5480. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5481. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5482. + * GNU General Public License for more details.
  5483. + *
  5484. + * You should have received a copy of the GNU General Public License
  5485. + * along with this program; if not, write to the Free Software
  5486. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  5487. + */
  5488. +
  5489. +#ifndef _BCM2708_IRQS_H_
  5490. +#define _BCM2708_IRQS_H_
  5491. +
  5492. +#include <mach/platform.h>
  5493. +
  5494. +/*
  5495. + * IRQ interrupts definitions are the same as the INT definitions
  5496. + * held within platform.h
  5497. + */
  5498. +#define IRQ_ARMCTRL_START 0
  5499. +#define IRQ_TIMER0 (IRQ_ARMCTRL_START + INTERRUPT_TIMER0)
  5500. +#define IRQ_TIMER1 (IRQ_ARMCTRL_START + INTERRUPT_TIMER1)
  5501. +#define IRQ_TIMER2 (IRQ_ARMCTRL_START + INTERRUPT_TIMER2)
  5502. +#define IRQ_TIMER3 (IRQ_ARMCTRL_START + INTERRUPT_TIMER3)
  5503. +#define IRQ_CODEC0 (IRQ_ARMCTRL_START + INTERRUPT_CODEC0)
  5504. +#define IRQ_CODEC1 (IRQ_ARMCTRL_START + INTERRUPT_CODEC1)
  5505. +#define IRQ_CODEC2 (IRQ_ARMCTRL_START + INTERRUPT_CODEC2)
  5506. +#define IRQ_JPEG (IRQ_ARMCTRL_START + INTERRUPT_JPEG)
  5507. +#define IRQ_ISP (IRQ_ARMCTRL_START + INTERRUPT_ISP)
  5508. +#define IRQ_USB (IRQ_ARMCTRL_START + INTERRUPT_USB)
  5509. +#define IRQ_3D (IRQ_ARMCTRL_START + INTERRUPT_3D)
  5510. +#define IRQ_TRANSPOSER (IRQ_ARMCTRL_START + INTERRUPT_TRANSPOSER)
  5511. +#define IRQ_MULTICORESYNC0 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC0)
  5512. +#define IRQ_MULTICORESYNC1 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC1)
  5513. +#define IRQ_MULTICORESYNC2 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC2)
  5514. +#define IRQ_MULTICORESYNC3 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC3)
  5515. +#define IRQ_DMA0 (IRQ_ARMCTRL_START + INTERRUPT_DMA0)
  5516. +#define IRQ_DMA1 (IRQ_ARMCTRL_START + INTERRUPT_DMA1)
  5517. +#define IRQ_DMA2 (IRQ_ARMCTRL_START + INTERRUPT_DMA2)
  5518. +#define IRQ_DMA3 (IRQ_ARMCTRL_START + INTERRUPT_DMA3)
  5519. +#define IRQ_DMA4 (IRQ_ARMCTRL_START + INTERRUPT_DMA4)
  5520. +#define IRQ_DMA5 (IRQ_ARMCTRL_START + INTERRUPT_DMA5)
  5521. +#define IRQ_DMA6 (IRQ_ARMCTRL_START + INTERRUPT_DMA6)
  5522. +#define IRQ_DMA7 (IRQ_ARMCTRL_START + INTERRUPT_DMA7)
  5523. +#define IRQ_DMA8 (IRQ_ARMCTRL_START + INTERRUPT_DMA8)
  5524. +#define IRQ_DMA9 (IRQ_ARMCTRL_START + INTERRUPT_DMA9)
  5525. +#define IRQ_DMA10 (IRQ_ARMCTRL_START + INTERRUPT_DMA10)
  5526. +#define IRQ_DMA11 (IRQ_ARMCTRL_START + INTERRUPT_DMA11)
  5527. +#define IRQ_DMA12 (IRQ_ARMCTRL_START + INTERRUPT_DMA12)
  5528. +#define IRQ_AUX (IRQ_ARMCTRL_START + INTERRUPT_AUX)
  5529. +#define IRQ_ARM (IRQ_ARMCTRL_START + INTERRUPT_ARM)
  5530. +#define IRQ_VPUDMA (IRQ_ARMCTRL_START + INTERRUPT_VPUDMA)
  5531. +#define IRQ_HOSTPORT (IRQ_ARMCTRL_START + INTERRUPT_HOSTPORT)
  5532. +#define IRQ_VIDEOSCALER (IRQ_ARMCTRL_START + INTERRUPT_VIDEOSCALER)
  5533. +#define IRQ_CCP2TX (IRQ_ARMCTRL_START + INTERRUPT_CCP2TX)
  5534. +#define IRQ_SDC (IRQ_ARMCTRL_START + INTERRUPT_SDC)
  5535. +#define IRQ_DSI0 (IRQ_ARMCTRL_START + INTERRUPT_DSI0)
  5536. +#define IRQ_AVE (IRQ_ARMCTRL_START + INTERRUPT_AVE)
  5537. +#define IRQ_CAM0 (IRQ_ARMCTRL_START + INTERRUPT_CAM0)
  5538. +#define IRQ_CAM1 (IRQ_ARMCTRL_START + INTERRUPT_CAM1)
  5539. +#define IRQ_HDMI0 (IRQ_ARMCTRL_START + INTERRUPT_HDMI0)
  5540. +#define IRQ_HDMI1 (IRQ_ARMCTRL_START + INTERRUPT_HDMI1)
  5541. +#define IRQ_PIXELVALVE1 (IRQ_ARMCTRL_START + INTERRUPT_PIXELVALVE1)
  5542. +#define IRQ_I2CSPISLV (IRQ_ARMCTRL_START + INTERRUPT_I2CSPISLV)
  5543. +#define IRQ_DSI1 (IRQ_ARMCTRL_START + INTERRUPT_DSI1)
  5544. +#define IRQ_PWA0 (IRQ_ARMCTRL_START + INTERRUPT_PWA0)
  5545. +#define IRQ_PWA1 (IRQ_ARMCTRL_START + INTERRUPT_PWA1)
  5546. +#define IRQ_CPR (IRQ_ARMCTRL_START + INTERRUPT_CPR)
  5547. +#define IRQ_SMI (IRQ_ARMCTRL_START + INTERRUPT_SMI)
  5548. +#define IRQ_GPIO0 (IRQ_ARMCTRL_START + INTERRUPT_GPIO0)
  5549. +#define IRQ_GPIO1 (IRQ_ARMCTRL_START + INTERRUPT_GPIO1)
  5550. +#define IRQ_GPIO2 (IRQ_ARMCTRL_START + INTERRUPT_GPIO2)
  5551. +#define IRQ_GPIO3 (IRQ_ARMCTRL_START + INTERRUPT_GPIO3)
  5552. +#define IRQ_I2C (IRQ_ARMCTRL_START + INTERRUPT_I2C)
  5553. +#define IRQ_SPI (IRQ_ARMCTRL_START + INTERRUPT_SPI)
  5554. +#define IRQ_I2SPCM (IRQ_ARMCTRL_START + INTERRUPT_I2SPCM)
  5555. +#define IRQ_SDIO (IRQ_ARMCTRL_START + INTERRUPT_SDIO)
  5556. +#define IRQ_UART (IRQ_ARMCTRL_START + INTERRUPT_UART)
  5557. +#define IRQ_SLIMBUS (IRQ_ARMCTRL_START + INTERRUPT_SLIMBUS)
  5558. +#define IRQ_VEC (IRQ_ARMCTRL_START + INTERRUPT_VEC)
  5559. +#define IRQ_CPG (IRQ_ARMCTRL_START + INTERRUPT_CPG)
  5560. +#define IRQ_RNG (IRQ_ARMCTRL_START + INTERRUPT_RNG)
  5561. +#define IRQ_ARASANSDIO (IRQ_ARMCTRL_START + INTERRUPT_ARASANSDIO)
  5562. +#define IRQ_AVSPMON (IRQ_ARMCTRL_START + INTERRUPT_AVSPMON)
  5563. +
  5564. +#define IRQ_ARM_TIMER (IRQ_ARMCTRL_START + INTERRUPT_ARM_TIMER)
  5565. +#define IRQ_ARM_MAILBOX (IRQ_ARMCTRL_START + INTERRUPT_ARM_MAILBOX)
  5566. +#define IRQ_ARM_DOORBELL_0 (IRQ_ARMCTRL_START + INTERRUPT_ARM_DOORBELL_0)
  5567. +#define IRQ_ARM_DOORBELL_1 (IRQ_ARMCTRL_START + INTERRUPT_ARM_DOORBELL_1)
  5568. +#define IRQ_VPU0_HALTED (IRQ_ARMCTRL_START + INTERRUPT_VPU0_HALTED)
  5569. +#define IRQ_VPU1_HALTED (IRQ_ARMCTRL_START + INTERRUPT_VPU1_HALTED)
  5570. +#define IRQ_ILLEGAL_TYPE0 (IRQ_ARMCTRL_START + INTERRUPT_ILLEGAL_TYPE0)
  5571. +#define IRQ_ILLEGAL_TYPE1 (IRQ_ARMCTRL_START + INTERRUPT_ILLEGAL_TYPE1)
  5572. +#define IRQ_PENDING1 (IRQ_ARMCTRL_START + INTERRUPT_PENDING1)
  5573. +#define IRQ_PENDING2 (IRQ_ARMCTRL_START + INTERRUPT_PENDING2)
  5574. +
  5575. +#define FIQ_START HARD_IRQS
  5576. +
  5577. +/*
  5578. + * FIQ interrupts definitions are the same as the INT definitions.
  5579. + */
  5580. +#define FIQ_TIMER0 (FIQ_START+INTERRUPT_TIMER0)
  5581. +#define FIQ_TIMER1 (FIQ_START+INTERRUPT_TIMER1)
  5582. +#define FIQ_TIMER2 (FIQ_START+INTERRUPT_TIMER2)
  5583. +#define FIQ_TIMER3 (FIQ_START+INTERRUPT_TIMER3)
  5584. +#define FIQ_CODEC0 (FIQ_START+INTERRUPT_CODEC0)
  5585. +#define FIQ_CODEC1 (FIQ_START+INTERRUPT_CODEC1)
  5586. +#define FIQ_CODEC2 (FIQ_START+INTERRUPT_CODEC2)
  5587. +#define FIQ_JPEG (FIQ_START+INTERRUPT_JPEG)
  5588. +#define FIQ_ISP (FIQ_START+INTERRUPT_ISP)
  5589. +#define FIQ_USB (FIQ_START+INTERRUPT_USB)
  5590. +#define FIQ_3D (FIQ_START+INTERRUPT_3D)
  5591. +#define FIQ_TRANSPOSER (FIQ_START+INTERRUPT_TRANSPOSER)
  5592. +#define FIQ_MULTICORESYNC0 (FIQ_START+INTERRUPT_MULTICORESYNC0)
  5593. +#define FIQ_MULTICORESYNC1 (FIQ_START+INTERRUPT_MULTICORESYNC1)
  5594. +#define FIQ_MULTICORESYNC2 (FIQ_START+INTERRUPT_MULTICORESYNC2)
  5595. +#define FIQ_MULTICORESYNC3 (FIQ_START+INTERRUPT_MULTICORESYNC3)
  5596. +#define FIQ_DMA0 (FIQ_START+INTERRUPT_DMA0)
  5597. +#define FIQ_DMA1 (FIQ_START+INTERRUPT_DMA1)
  5598. +#define FIQ_DMA2 (FIQ_START+INTERRUPT_DMA2)
  5599. +#define FIQ_DMA3 (FIQ_START+INTERRUPT_DMA3)
  5600. +#define FIQ_DMA4 (FIQ_START+INTERRUPT_DMA4)
  5601. +#define FIQ_DMA5 (FIQ_START+INTERRUPT_DMA5)
  5602. +#define FIQ_DMA6 (FIQ_START+INTERRUPT_DMA6)
  5603. +#define FIQ_DMA7 (FIQ_START+INTERRUPT_DMA7)
  5604. +#define FIQ_DMA8 (FIQ_START+INTERRUPT_DMA8)
  5605. +#define FIQ_DMA9 (FIQ_START+INTERRUPT_DMA9)
  5606. +#define FIQ_DMA10 (FIQ_START+INTERRUPT_DMA10)
  5607. +#define FIQ_DMA11 (FIQ_START+INTERRUPT_DMA11)
  5608. +#define FIQ_DMA12 (FIQ_START+INTERRUPT_DMA12)
  5609. +#define FIQ_AUX (FIQ_START+INTERRUPT_AUX)
  5610. +#define FIQ_ARM (FIQ_START+INTERRUPT_ARM)
  5611. +#define FIQ_VPUDMA (FIQ_START+INTERRUPT_VPUDMA)
  5612. +#define FIQ_HOSTPORT (FIQ_START+INTERRUPT_HOSTPORT)
  5613. +#define FIQ_VIDEOSCALER (FIQ_START+INTERRUPT_VIDEOSCALER)
  5614. +#define FIQ_CCP2TX (FIQ_START+INTERRUPT_CCP2TX)
  5615. +#define FIQ_SDC (FIQ_START+INTERRUPT_SDC)
  5616. +#define FIQ_DSI0 (FIQ_START+INTERRUPT_DSI0)
  5617. +#define FIQ_AVE (FIQ_START+INTERRUPT_AVE)
  5618. +#define FIQ_CAM0 (FIQ_START+INTERRUPT_CAM0)
  5619. +#define FIQ_CAM1 (FIQ_START+INTERRUPT_CAM1)
  5620. +#define FIQ_HDMI0 (FIQ_START+INTERRUPT_HDMI0)
  5621. +#define FIQ_HDMI1 (FIQ_START+INTERRUPT_HDMI1)
  5622. +#define FIQ_PIXELVALVE1 (FIQ_START+INTERRUPT_PIXELVALVE1)
  5623. +#define FIQ_I2CSPISLV (FIQ_START+INTERRUPT_I2CSPISLV)
  5624. +#define FIQ_DSI1 (FIQ_START+INTERRUPT_DSI1)
  5625. +#define FIQ_PWA0 (FIQ_START+INTERRUPT_PWA0)
  5626. +#define FIQ_PWA1 (FIQ_START+INTERRUPT_PWA1)
  5627. +#define FIQ_CPR (FIQ_START+INTERRUPT_CPR)
  5628. +#define FIQ_SMI (FIQ_START+INTERRUPT_SMI)
  5629. +#define FIQ_GPIO0 (FIQ_START+INTERRUPT_GPIO0)
  5630. +#define FIQ_GPIO1 (FIQ_START+INTERRUPT_GPIO1)
  5631. +#define FIQ_GPIO2 (FIQ_START+INTERRUPT_GPIO2)
  5632. +#define FIQ_GPIO3 (FIQ_START+INTERRUPT_GPIO3)
  5633. +#define FIQ_I2C (FIQ_START+INTERRUPT_I2C)
  5634. +#define FIQ_SPI (FIQ_START+INTERRUPT_SPI)
  5635. +#define FIQ_I2SPCM (FIQ_START+INTERRUPT_I2SPCM)
  5636. +#define FIQ_SDIO (FIQ_START+INTERRUPT_SDIO)
  5637. +#define FIQ_UART (FIQ_START+INTERRUPT_UART)
  5638. +#define FIQ_SLIMBUS (FIQ_START+INTERRUPT_SLIMBUS)
  5639. +#define FIQ_VEC (FIQ_START+INTERRUPT_VEC)
  5640. +#define FIQ_CPG (FIQ_START+INTERRUPT_CPG)
  5641. +#define FIQ_RNG (FIQ_START+INTERRUPT_RNG)
  5642. +#define FIQ_ARASANSDIO (FIQ_START+INTERRUPT_ARASANSDIO)
  5643. +#define FIQ_AVSPMON (FIQ_START+INTERRUPT_AVSPMON)
  5644. +
  5645. +#define FIQ_ARM_TIMER (FIQ_START+INTERRUPT_ARM_TIMER)
  5646. +#define FIQ_ARM_MAILBOX (FIQ_START+INTERRUPT_ARM_MAILBOX)
  5647. +#define FIQ_ARM_DOORBELL_0 (FIQ_START+INTERRUPT_ARM_DOORBELL_0)
  5648. +#define FIQ_ARM_DOORBELL_1 (FIQ_START+INTERRUPT_ARM_DOORBELL_1)
  5649. +#define FIQ_VPU0_HALTED (FIQ_START+INTERRUPT_VPU0_HALTED)
  5650. +#define FIQ_VPU1_HALTED (FIQ_START+INTERRUPT_VPU1_HALTED)
  5651. +#define FIQ_ILLEGAL_TYPE0 (FIQ_START+INTERRUPT_ILLEGAL_TYPE0)
  5652. +#define FIQ_ILLEGAL_TYPE1 (FIQ_START+INTERRUPT_ILLEGAL_TYPE1)
  5653. +#define FIQ_PENDING1 (FIQ_START+INTERRUPT_PENDING1)
  5654. +#define FIQ_PENDING2 (FIQ_START+INTERRUPT_PENDING2)
  5655. +
  5656. +#define GPIO_IRQ_START (HARD_IRQS + FIQ_IRQS)
  5657. +
  5658. +#define HARD_IRQS (64 + 21)
  5659. +#define FIQ_IRQS (64 + 21)
  5660. +#define GPIO_IRQS (32*5)
  5661. +
  5662. +#define NR_IRQS HARD_IRQS+FIQ_IRQS+GPIO_IRQS
  5663. +
  5664. +
  5665. +#endif /* _BCM2708_IRQS_H_ */
  5666. diff -Nur linux-3.13.11/arch/arm/mach-bcm2708/include/mach/memory.h linux-rpi/arch/arm/mach-bcm2708/include/mach/memory.h
  5667. --- linux-3.13.11/arch/arm/mach-bcm2708/include/mach/memory.h 1970-01-01 01:00:00.000000000 +0100
  5668. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/memory.h 2014-04-24 15:35:00.777527936 +0200
  5669. @@ -0,0 +1,57 @@
  5670. +/*
  5671. + * arch/arm/mach-bcm2708/include/mach/memory.h
  5672. + *
  5673. + * Copyright (C) 2010 Broadcom
  5674. + *
  5675. + * This program is free software; you can redistribute it and/or modify
  5676. + * it under the terms of the GNU General Public License as published by
  5677. + * the Free Software Foundation; either version 2 of the License, or
  5678. + * (at your option) any later version.
  5679. + *
  5680. + * This program is distributed in the hope that it will be useful,
  5681. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5682. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5683. + * GNU General Public License for more details.
  5684. + *
  5685. + * You should have received a copy of the GNU General Public License
  5686. + * along with this program; if not, write to the Free Software
  5687. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  5688. + */
  5689. +#ifndef __ASM_ARCH_MEMORY_H
  5690. +#define __ASM_ARCH_MEMORY_H
  5691. +
  5692. +/* Memory overview:
  5693. +
  5694. + [ARMcore] <--virtual addr-->
  5695. + [ARMmmu] <--physical addr-->
  5696. + [GERTmap] <--bus add-->
  5697. + [VCperiph]
  5698. +
  5699. +*/
  5700. +
  5701. +/*
  5702. + * Physical DRAM offset.
  5703. + */
  5704. +#define PLAT_PHYS_OFFSET UL(0x00000000)
  5705. +#define VC_ARMMEM_OFFSET UL(0x00000000) /* offset in VC of ARM memory */
  5706. +
  5707. +#ifdef CONFIG_BCM2708_NOL2CACHE
  5708. + #define _REAL_BUS_OFFSET UL(0xC0000000) /* don't use L1 or L2 caches */
  5709. +#else
  5710. + #define _REAL_BUS_OFFSET UL(0x40000000) /* use L2 cache */
  5711. +#endif
  5712. +
  5713. +/* We're using the memory at 64M in the VideoCore for Linux - this adjustment
  5714. + * will provide the offset into this area as well as setting the bits that
  5715. + * stop the L1 and L2 cache from being used
  5716. + *
  5717. + * WARNING: this only works because the ARM is given memory at a fixed location
  5718. + * (ARMMEM_OFFSET)
  5719. + */
  5720. +#define BUS_OFFSET (VC_ARMMEM_OFFSET + _REAL_BUS_OFFSET)
  5721. +#define __virt_to_bus(x) ((x) + (BUS_OFFSET - PAGE_OFFSET))
  5722. +#define __bus_to_virt(x) ((x) - (BUS_OFFSET - PAGE_OFFSET))
  5723. +#define __pfn_to_bus(x) (__pfn_to_phys(x) + (BUS_OFFSET - PLAT_PHYS_OFFSET))
  5724. +#define __bus_to_pfn(x) __phys_to_pfn((x) - (BUS_OFFSET - PLAT_PHYS_OFFSET))
  5725. +
  5726. +#endif
  5727. diff -Nur linux-3.13.11/arch/arm/mach-bcm2708/include/mach/platform.h linux-rpi/arch/arm/mach-bcm2708/include/mach/platform.h
  5728. --- linux-3.13.11/arch/arm/mach-bcm2708/include/mach/platform.h 1970-01-01 01:00:00.000000000 +0100
  5729. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/platform.h 2014-04-24 15:35:00.777527936 +0200
  5730. @@ -0,0 +1,228 @@
  5731. +/*
  5732. + * arch/arm/mach-bcm2708/include/mach/platform.h
  5733. + *
  5734. + * Copyright (C) 2010 Broadcom
  5735. + *
  5736. + * This program is free software; you can redistribute it and/or modify
  5737. + * it under the terms of the GNU General Public License as published by
  5738. + * the Free Software Foundation; either version 2 of the License, or
  5739. + * (at your option) any later version.
  5740. + *
  5741. + * This program is distributed in the hope that it will be useful,
  5742. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5743. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5744. + * GNU General Public License for more details.
  5745. + *
  5746. + * You should have received a copy of the GNU General Public License
  5747. + * along with this program; if not, write to the Free Software
  5748. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  5749. + */
  5750. +
  5751. +#ifndef _BCM2708_PLATFORM_H
  5752. +#define _BCM2708_PLATFORM_H
  5753. +
  5754. +
  5755. +/* macros to get at IO space when running virtually */
  5756. +#define IO_ADDRESS(x) (((x) & 0x0fffffff) + (((x) >> 4) & 0x0f000000) + 0xf0000000)
  5757. +
  5758. +#define __io_address(n) IOMEM(IO_ADDRESS(n))
  5759. +
  5760. +
  5761. +/*
  5762. + * SDRAM
  5763. + */
  5764. +#define BCM2708_SDRAM_BASE 0x00000000
  5765. +
  5766. +/*
  5767. + * Logic expansion modules
  5768. + *
  5769. + */
  5770. +
  5771. +
  5772. +/* ------------------------------------------------------------------------
  5773. + * BCM2708 ARMCTRL Registers
  5774. + * ------------------------------------------------------------------------
  5775. + */
  5776. +
  5777. +#define HW_REGISTER_RW(addr) (addr)
  5778. +#define HW_REGISTER_RO(addr) (addr)
  5779. +
  5780. +#include "arm_control.h"
  5781. +#undef ARM_BASE
  5782. +
  5783. +/*
  5784. + * Definitions and addresses for the ARM CONTROL logic
  5785. + * This file is manually generated.
  5786. + */
  5787. +
  5788. +#define BCM2708_PERI_BASE 0x20000000
  5789. +#define IC0_BASE (BCM2708_PERI_BASE + 0x2000)
  5790. +#define ST_BASE (BCM2708_PERI_BASE + 0x3000) /* System Timer */
  5791. +#define MPHI_BASE (BCM2708_PERI_BASE + 0x6000) /* Message -based Parallel Host Interface */
  5792. +#define DMA_BASE (BCM2708_PERI_BASE + 0x7000) /* DMA controller */
  5793. +#define ARM_BASE (BCM2708_PERI_BASE + 0xB000) /* BCM2708 ARM control block */
  5794. +#define PM_BASE (BCM2708_PERI_BASE + 0x100000) /* Power Management, Reset controller and Watchdog registers */
  5795. +#define PCM_CLOCK_BASE (BCM2708_PERI_BASE + 0x101098) /* PCM Clock */
  5796. +#define RNG_BASE (BCM2708_PERI_BASE + 0x104000) /* Hardware RNG */
  5797. +#define GPIO_BASE (BCM2708_PERI_BASE + 0x200000) /* GPIO */
  5798. +#define UART0_BASE (BCM2708_PERI_BASE + 0x201000) /* Uart 0 */
  5799. +#define MMCI0_BASE (BCM2708_PERI_BASE + 0x202000) /* MMC interface */
  5800. +#define I2S_BASE (BCM2708_PERI_BASE + 0x203000) /* I2S */
  5801. +#define SPI0_BASE (BCM2708_PERI_BASE + 0x204000) /* SPI0 */
  5802. +#define BSC0_BASE (BCM2708_PERI_BASE + 0x205000) /* BSC0 I2C/TWI */
  5803. +#define UART1_BASE (BCM2708_PERI_BASE + 0x215000) /* Uart 1 */
  5804. +#define EMMC_BASE (BCM2708_PERI_BASE + 0x300000) /* eMMC interface */
  5805. +#define SMI_BASE (BCM2708_PERI_BASE + 0x600000) /* SMI */
  5806. +#define BSC1_BASE (BCM2708_PERI_BASE + 0x804000) /* BSC1 I2C/TWI */
  5807. +#define USB_BASE (BCM2708_PERI_BASE + 0x980000) /* DTC_OTG USB controller */
  5808. +#define MCORE_BASE (BCM2708_PERI_BASE + 0x0000) /* Fake frame buffer device (actually the multicore sync block*/
  5809. +
  5810. +#define ARMCTRL_BASE (ARM_BASE + 0x000)
  5811. +#define ARMCTRL_IC_BASE (ARM_BASE + 0x200) /* ARM interrupt controller */
  5812. +#define ARMCTRL_TIMER0_1_BASE (ARM_BASE + 0x400) /* Timer 0 and 1 */
  5813. +#define ARMCTRL_0_SBM_BASE (ARM_BASE + 0x800) /* User 0 (ARM)'s Semaphores Doorbells and Mailboxes */
  5814. +
  5815. +
  5816. +/*
  5817. + * Interrupt assignments
  5818. + */
  5819. +
  5820. +#define ARM_IRQ1_BASE 0
  5821. +#define INTERRUPT_TIMER0 (ARM_IRQ1_BASE + 0)
  5822. +#define INTERRUPT_TIMER1 (ARM_IRQ1_BASE + 1)
  5823. +#define INTERRUPT_TIMER2 (ARM_IRQ1_BASE + 2)
  5824. +#define INTERRUPT_TIMER3 (ARM_IRQ1_BASE + 3)
  5825. +#define INTERRUPT_CODEC0 (ARM_IRQ1_BASE + 4)
  5826. +#define INTERRUPT_CODEC1 (ARM_IRQ1_BASE + 5)
  5827. +#define INTERRUPT_CODEC2 (ARM_IRQ1_BASE + 6)
  5828. +#define INTERRUPT_VC_JPEG (ARM_IRQ1_BASE + 7)
  5829. +#define INTERRUPT_ISP (ARM_IRQ1_BASE + 8)
  5830. +#define INTERRUPT_VC_USB (ARM_IRQ1_BASE + 9)
  5831. +#define INTERRUPT_VC_3D (ARM_IRQ1_BASE + 10)
  5832. +#define INTERRUPT_TRANSPOSER (ARM_IRQ1_BASE + 11)
  5833. +#define INTERRUPT_MULTICORESYNC0 (ARM_IRQ1_BASE + 12)
  5834. +#define INTERRUPT_MULTICORESYNC1 (ARM_IRQ1_BASE + 13)
  5835. +#define INTERRUPT_MULTICORESYNC2 (ARM_IRQ1_BASE + 14)
  5836. +#define INTERRUPT_MULTICORESYNC3 (ARM_IRQ1_BASE + 15)
  5837. +#define INTERRUPT_DMA0 (ARM_IRQ1_BASE + 16)
  5838. +#define INTERRUPT_DMA1 (ARM_IRQ1_BASE + 17)
  5839. +#define INTERRUPT_VC_DMA2 (ARM_IRQ1_BASE + 18)
  5840. +#define INTERRUPT_VC_DMA3 (ARM_IRQ1_BASE + 19)
  5841. +#define INTERRUPT_DMA4 (ARM_IRQ1_BASE + 20)
  5842. +#define INTERRUPT_DMA5 (ARM_IRQ1_BASE + 21)
  5843. +#define INTERRUPT_DMA6 (ARM_IRQ1_BASE + 22)
  5844. +#define INTERRUPT_DMA7 (ARM_IRQ1_BASE + 23)
  5845. +#define INTERRUPT_DMA8 (ARM_IRQ1_BASE + 24)
  5846. +#define INTERRUPT_DMA9 (ARM_IRQ1_BASE + 25)
  5847. +#define INTERRUPT_DMA10 (ARM_IRQ1_BASE + 26)
  5848. +#define INTERRUPT_DMA11 (ARM_IRQ1_BASE + 27)
  5849. +#define INTERRUPT_DMA12 (ARM_IRQ1_BASE + 28)
  5850. +#define INTERRUPT_AUX (ARM_IRQ1_BASE + 29)
  5851. +#define INTERRUPT_ARM (ARM_IRQ1_BASE + 30)
  5852. +#define INTERRUPT_VPUDMA (ARM_IRQ1_BASE + 31)
  5853. +
  5854. +#define ARM_IRQ2_BASE 32
  5855. +#define INTERRUPT_HOSTPORT (ARM_IRQ2_BASE + 0)
  5856. +#define INTERRUPT_VIDEOSCALER (ARM_IRQ2_BASE + 1)
  5857. +#define INTERRUPT_CCP2TX (ARM_IRQ2_BASE + 2)
  5858. +#define INTERRUPT_SDC (ARM_IRQ2_BASE + 3)
  5859. +#define INTERRUPT_DSI0 (ARM_IRQ2_BASE + 4)
  5860. +#define INTERRUPT_AVE (ARM_IRQ2_BASE + 5)
  5861. +#define INTERRUPT_CAM0 (ARM_IRQ2_BASE + 6)
  5862. +#define INTERRUPT_CAM1 (ARM_IRQ2_BASE + 7)
  5863. +#define INTERRUPT_HDMI0 (ARM_IRQ2_BASE + 8)
  5864. +#define INTERRUPT_HDMI1 (ARM_IRQ2_BASE + 9)
  5865. +#define INTERRUPT_PIXELVALVE1 (ARM_IRQ2_BASE + 10)
  5866. +#define INTERRUPT_I2CSPISLV (ARM_IRQ2_BASE + 11)
  5867. +#define INTERRUPT_DSI1 (ARM_IRQ2_BASE + 12)
  5868. +#define INTERRUPT_PWA0 (ARM_IRQ2_BASE + 13)
  5869. +#define INTERRUPT_PWA1 (ARM_IRQ2_BASE + 14)
  5870. +#define INTERRUPT_CPR (ARM_IRQ2_BASE + 15)
  5871. +#define INTERRUPT_SMI (ARM_IRQ2_BASE + 16)
  5872. +#define INTERRUPT_GPIO0 (ARM_IRQ2_BASE + 17)
  5873. +#define INTERRUPT_GPIO1 (ARM_IRQ2_BASE + 18)
  5874. +#define INTERRUPT_GPIO2 (ARM_IRQ2_BASE + 19)
  5875. +#define INTERRUPT_GPIO3 (ARM_IRQ2_BASE + 20)
  5876. +#define INTERRUPT_VC_I2C (ARM_IRQ2_BASE + 21)
  5877. +#define INTERRUPT_VC_SPI (ARM_IRQ2_BASE + 22)
  5878. +#define INTERRUPT_VC_I2SPCM (ARM_IRQ2_BASE + 23)
  5879. +#define INTERRUPT_VC_SDIO (ARM_IRQ2_BASE + 24)
  5880. +#define INTERRUPT_VC_UART (ARM_IRQ2_BASE + 25)
  5881. +#define INTERRUPT_SLIMBUS (ARM_IRQ2_BASE + 26)
  5882. +#define INTERRUPT_VEC (ARM_IRQ2_BASE + 27)
  5883. +#define INTERRUPT_CPG (ARM_IRQ2_BASE + 28)
  5884. +#define INTERRUPT_RNG (ARM_IRQ2_BASE + 29)
  5885. +#define INTERRUPT_VC_ARASANSDIO (ARM_IRQ2_BASE + 30)
  5886. +#define INTERRUPT_AVSPMON (ARM_IRQ2_BASE + 31)
  5887. +
  5888. +#define ARM_IRQ0_BASE 64
  5889. +#define INTERRUPT_ARM_TIMER (ARM_IRQ0_BASE + 0)
  5890. +#define INTERRUPT_ARM_MAILBOX (ARM_IRQ0_BASE + 1)
  5891. +#define INTERRUPT_ARM_DOORBELL_0 (ARM_IRQ0_BASE + 2)
  5892. +#define INTERRUPT_ARM_DOORBELL_1 (ARM_IRQ0_BASE + 3)
  5893. +#define INTERRUPT_VPU0_HALTED (ARM_IRQ0_BASE + 4)
  5894. +#define INTERRUPT_VPU1_HALTED (ARM_IRQ0_BASE + 5)
  5895. +#define INTERRUPT_ILLEGAL_TYPE0 (ARM_IRQ0_BASE + 6)
  5896. +#define INTERRUPT_ILLEGAL_TYPE1 (ARM_IRQ0_BASE + 7)
  5897. +#define INTERRUPT_PENDING1 (ARM_IRQ0_BASE + 8)
  5898. +#define INTERRUPT_PENDING2 (ARM_IRQ0_BASE + 9)
  5899. +#define INTERRUPT_JPEG (ARM_IRQ0_BASE + 10)
  5900. +#define INTERRUPT_USB (ARM_IRQ0_BASE + 11)
  5901. +#define INTERRUPT_3D (ARM_IRQ0_BASE + 12)
  5902. +#define INTERRUPT_DMA2 (ARM_IRQ0_BASE + 13)
  5903. +#define INTERRUPT_DMA3 (ARM_IRQ0_BASE + 14)
  5904. +#define INTERRUPT_I2C (ARM_IRQ0_BASE + 15)
  5905. +#define INTERRUPT_SPI (ARM_IRQ0_BASE + 16)
  5906. +#define INTERRUPT_I2SPCM (ARM_IRQ0_BASE + 17)
  5907. +#define INTERRUPT_SDIO (ARM_IRQ0_BASE + 18)
  5908. +#define INTERRUPT_UART (ARM_IRQ0_BASE + 19)
  5909. +#define INTERRUPT_ARASANSDIO (ARM_IRQ0_BASE + 20)
  5910. +
  5911. +#define MAXIRQNUM (32 + 32 + 20)
  5912. +#define MAXFIQNUM (32 + 32 + 20)
  5913. +
  5914. +#define MAX_TIMER 2
  5915. +#define MAX_PERIOD 699050
  5916. +#define TICKS_PER_uSEC 1
  5917. +
  5918. +/*
  5919. + * These are useconds NOT ticks.
  5920. + *
  5921. + */
  5922. +#define mSEC_1 1000
  5923. +#define mSEC_5 (mSEC_1 * 5)
  5924. +#define mSEC_10 (mSEC_1 * 10)
  5925. +#define mSEC_25 (mSEC_1 * 25)
  5926. +#define SEC_1 (mSEC_1 * 1000)
  5927. +
  5928. +/*
  5929. + * Watchdog
  5930. + */
  5931. +#define PM_RSTC (PM_BASE+0x1c)
  5932. +#define PM_RSTS (PM_BASE+0x20)
  5933. +#define PM_WDOG (PM_BASE+0x24)
  5934. +
  5935. +#define PM_WDOG_RESET 0000000000
  5936. +#define PM_PASSWORD 0x5a000000
  5937. +#define PM_WDOG_TIME_SET 0x000fffff
  5938. +#define PM_RSTC_WRCFG_CLR 0xffffffcf
  5939. +#define PM_RSTC_WRCFG_SET 0x00000030
  5940. +#define PM_RSTC_WRCFG_FULL_RESET 0x00000020
  5941. +#define PM_RSTC_RESET 0x00000102
  5942. +
  5943. +#define PM_RSTS_HADPOR_SET 0x00001000
  5944. +#define PM_RSTS_HADSRH_SET 0x00000400
  5945. +#define PM_RSTS_HADSRF_SET 0x00000200
  5946. +#define PM_RSTS_HADSRQ_SET 0x00000100
  5947. +#define PM_RSTS_HADWRH_SET 0x00000040
  5948. +#define PM_RSTS_HADWRF_SET 0x00000020
  5949. +#define PM_RSTS_HADWRQ_SET 0x00000010
  5950. +#define PM_RSTS_HADDRH_SET 0x00000004
  5951. +#define PM_RSTS_HADDRF_SET 0x00000002
  5952. +#define PM_RSTS_HADDRQ_SET 0x00000001
  5953. +
  5954. +#define UART0_CLOCK 3000000
  5955. +
  5956. +#endif
  5957. +
  5958. +/* END */
  5959. diff -Nur linux-3.13.11/arch/arm/mach-bcm2708/include/mach/power.h linux-rpi/arch/arm/mach-bcm2708/include/mach/power.h
  5960. --- linux-3.13.11/arch/arm/mach-bcm2708/include/mach/power.h 1970-01-01 01:00:00.000000000 +0100
  5961. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/power.h 2014-04-24 15:35:00.777527936 +0200
  5962. @@ -0,0 +1,26 @@
  5963. +/*
  5964. + * linux/arch/arm/mach-bcm2708/power.h
  5965. + *
  5966. + * Copyright (C) 2010 Broadcom
  5967. + *
  5968. + * This program is free software; you can redistribute it and/or modify
  5969. + * it under the terms of the GNU General Public License version 2 as
  5970. + * published by the Free Software Foundation.
  5971. + *
  5972. + * This device provides a shared mechanism for controlling the power to
  5973. + * VideoCore subsystems.
  5974. + */
  5975. +
  5976. +#ifndef _MACH_BCM2708_POWER_H
  5977. +#define _MACH_BCM2708_POWER_H
  5978. +
  5979. +#include <linux/types.h>
  5980. +#include <mach/arm_power.h>
  5981. +
  5982. +typedef unsigned int BCM_POWER_HANDLE_T;
  5983. +
  5984. +extern int bcm_power_open(BCM_POWER_HANDLE_T *handle);
  5985. +extern int bcm_power_request(BCM_POWER_HANDLE_T handle, uint32_t request);
  5986. +extern int bcm_power_close(BCM_POWER_HANDLE_T handle);
  5987. +
  5988. +#endif
  5989. diff -Nur linux-3.13.11/arch/arm/mach-bcm2708/include/mach/system.h linux-rpi/arch/arm/mach-bcm2708/include/mach/system.h
  5990. --- linux-3.13.11/arch/arm/mach-bcm2708/include/mach/system.h 1970-01-01 01:00:00.000000000 +0100
  5991. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/system.h 2014-04-24 15:35:00.777527936 +0200
  5992. @@ -0,0 +1,38 @@
  5993. +/*
  5994. + * arch/arm/mach-bcm2708/include/mach/system.h
  5995. + *
  5996. + * Copyright (C) 2010 Broadcom
  5997. + * Copyright (C) 2003 ARM Limited
  5998. + * Copyright (C) 2000 Deep Blue Solutions Ltd
  5999. + *
  6000. + * This program is free software; you can redistribute it and/or modify
  6001. + * it under the terms of the GNU General Public License as published by
  6002. + * the Free Software Foundation; either version 2 of the License, or
  6003. + * (at your option) any later version.
  6004. + *
  6005. + * This program is distributed in the hope that it will be useful,
  6006. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6007. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6008. + * GNU General Public License for more details.
  6009. + *
  6010. + * You should have received a copy of the GNU General Public License
  6011. + * along with this program; if not, write to the Free Software
  6012. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6013. + */
  6014. +#ifndef __ASM_ARCH_SYSTEM_H
  6015. +#define __ASM_ARCH_SYSTEM_H
  6016. +
  6017. +#include <linux/io.h>
  6018. +#include <mach/hardware.h>
  6019. +#include <mach/platform.h>
  6020. +
  6021. +static inline void arch_idle(void)
  6022. +{
  6023. + /*
  6024. + * This should do all the clock switching
  6025. + * and wait for interrupt tricks
  6026. + */
  6027. + cpu_do_idle();
  6028. +}
  6029. +
  6030. +#endif
  6031. diff -Nur linux-3.13.11/arch/arm/mach-bcm2708/include/mach/timex.h linux-rpi/arch/arm/mach-bcm2708/include/mach/timex.h
  6032. --- linux-3.13.11/arch/arm/mach-bcm2708/include/mach/timex.h 1970-01-01 01:00:00.000000000 +0100
  6033. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/timex.h 2014-04-24 15:35:00.777527936 +0200
  6034. @@ -0,0 +1,23 @@
  6035. +/*
  6036. + * arch/arm/mach-bcm2708/include/mach/timex.h
  6037. + *
  6038. + * BCM2708 sysem clock frequency
  6039. + *
  6040. + * Copyright (C) 2010 Broadcom
  6041. + *
  6042. + * This program is free software; you can redistribute it and/or modify
  6043. + * it under the terms of the GNU General Public License as published by
  6044. + * the Free Software Foundation; either version 2 of the License, or
  6045. + * (at your option) any later version.
  6046. + *
  6047. + * This program is distributed in the hope that it will be useful,
  6048. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6049. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6050. + * GNU General Public License for more details.
  6051. + *
  6052. + * You should have received a copy of the GNU General Public License
  6053. + * along with this program; if not, write to the Free Software
  6054. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6055. + */
  6056. +
  6057. +#define CLOCK_TICK_RATE (1000000)
  6058. diff -Nur linux-3.13.11/arch/arm/mach-bcm2708/include/mach/uncompress.h linux-rpi/arch/arm/mach-bcm2708/include/mach/uncompress.h
  6059. --- linux-3.13.11/arch/arm/mach-bcm2708/include/mach/uncompress.h 1970-01-01 01:00:00.000000000 +0100
  6060. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/uncompress.h 2014-04-24 15:36:30.950526170 +0200
  6061. @@ -0,0 +1,84 @@
  6062. +/*
  6063. + * arch/arm/mach-bcn2708/include/mach/uncompress.h
  6064. + *
  6065. + * Copyright (C) 2010 Broadcom
  6066. + * Copyright (C) 2003 ARM Limited
  6067. + *
  6068. + * This program is free software; you can redistribute it and/or modify
  6069. + * it under the terms of the GNU General Public License as published by
  6070. + * the Free Software Foundation; either version 2 of the License, or
  6071. + * (at your option) any later version.
  6072. + *
  6073. + * This program is distributed in the hope that it will be useful,
  6074. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6075. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6076. + * GNU General Public License for more details.
  6077. + *
  6078. + * You should have received a copy of the GNU General Public License
  6079. + * along with this program; if not, write to the Free Software
  6080. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6081. + */
  6082. +
  6083. +#include <linux/io.h>
  6084. +#include <linux/amba/serial.h>
  6085. +#include <mach/hardware.h>
  6086. +
  6087. +#define UART_BAUD 115200
  6088. +
  6089. +#define BCM2708_UART_DR __io(UART0_BASE + UART01x_DR)
  6090. +#define BCM2708_UART_FR __io(UART0_BASE + UART01x_FR)
  6091. +#define BCM2708_UART_IBRD __io(UART0_BASE + UART011_IBRD)
  6092. +#define BCM2708_UART_FBRD __io(UART0_BASE + UART011_FBRD)
  6093. +#define BCM2708_UART_LCRH __io(UART0_BASE + UART011_LCRH)
  6094. +#define BCM2708_UART_CR __io(UART0_BASE + UART011_CR)
  6095. +
  6096. +/*
  6097. + * This does not append a newline
  6098. + */
  6099. +static inline void putc(int c)
  6100. +{
  6101. + while (__raw_readl(BCM2708_UART_FR) & UART01x_FR_TXFF)
  6102. + barrier();
  6103. +
  6104. + __raw_writel(c, BCM2708_UART_DR);
  6105. +}
  6106. +
  6107. +static inline void flush(void)
  6108. +{
  6109. + int fr;
  6110. +
  6111. + do {
  6112. + fr = __raw_readl(BCM2708_UART_FR);
  6113. + barrier();
  6114. + } while ((fr & (UART011_FR_TXFE | UART01x_FR_BUSY)) != UART011_FR_TXFE);
  6115. +}
  6116. +
  6117. +static inline void arch_decomp_setup(void)
  6118. +{
  6119. + int temp, div, rem, frac;
  6120. +
  6121. + temp = 16 * UART_BAUD;
  6122. + div = UART0_CLOCK / temp;
  6123. + rem = UART0_CLOCK % temp;
  6124. + temp = (8 * rem) / UART_BAUD;
  6125. + frac = (temp >> 1) + (temp & 1);
  6126. +
  6127. + /* Make sure the UART is disabled before we start */
  6128. + __raw_writel(0, BCM2708_UART_CR);
  6129. +
  6130. + /* Set the baud rate */
  6131. + __raw_writel(div, BCM2708_UART_IBRD);
  6132. + __raw_writel(frac, BCM2708_UART_FBRD);
  6133. +
  6134. + /* Set the UART to 8n1, FIFO enabled */
  6135. + __raw_writel(UART01x_LCRH_WLEN_8 | UART01x_LCRH_FEN, BCM2708_UART_LCRH);
  6136. +
  6137. + /* Enable the UART */
  6138. + __raw_writel(UART01x_CR_UARTEN | UART011_CR_TXE | UART011_CR_RXE,
  6139. + BCM2708_UART_CR);
  6140. +}
  6141. +
  6142. +/*
  6143. + * nothing to do
  6144. + */
  6145. +#define arch_decomp_wdog()
  6146. diff -Nur linux-3.13.11/arch/arm/mach-bcm2708/include/mach/vcio.h linux-rpi/arch/arm/mach-bcm2708/include/mach/vcio.h
  6147. --- linux-3.13.11/arch/arm/mach-bcm2708/include/mach/vcio.h 1970-01-01 01:00:00.000000000 +0100
  6148. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/vcio.h 2014-04-24 15:36:30.950526170 +0200
  6149. @@ -0,0 +1,141 @@
  6150. +/*
  6151. + * arch/arm/mach-bcm2708/include/mach/vcio.h
  6152. + *
  6153. + * Copyright (C) 2010 Broadcom
  6154. + *
  6155. + * This program is free software; you can redistribute it and/or modify
  6156. + * it under the terms of the GNU General Public License as published by
  6157. + * the Free Software Foundation; either version 2 of the License, or
  6158. + * (at your option) any later version.
  6159. + *
  6160. + * This program is distributed in the hope that it will be useful,
  6161. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6162. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6163. + * GNU General Public License for more details.
  6164. + *
  6165. + * You should have received a copy of the GNU General Public License
  6166. + * along with this program; if not, write to the Free Software
  6167. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6168. + */
  6169. +#ifndef _MACH_BCM2708_VCIO_H
  6170. +#define _MACH_BCM2708_VCIO_H
  6171. +
  6172. +/* Routines to handle I/O via the VideoCore "ARM control" registers
  6173. + * (semaphores, doorbells, mailboxes)
  6174. + */
  6175. +
  6176. +#define BCM_VCIO_DRIVER_NAME "bcm2708_vcio"
  6177. +
  6178. +/* Constants shared with the ARM identifying separate mailbox channels */
  6179. +#define MBOX_CHAN_POWER 0 /* for use by the power management interface */
  6180. +#define MBOX_CHAN_FB 1 /* for use by the frame buffer */
  6181. +#define MBOX_CHAN_VCHIQ 3 /* for use by the VCHIQ interface */
  6182. +#define MBOX_CHAN_PROPERTY 8 /* for use by the property channel */
  6183. +#define MBOX_CHAN_COUNT 9
  6184. +
  6185. +/* Mailbox property tags */
  6186. +enum {
  6187. + VCMSG_PROPERTY_END = 0x00000000,
  6188. + VCMSG_GET_FIRMWARE_REVISION = 0x00000001,
  6189. + VCMSG_GET_BOARD_MODEL = 0x00010001,
  6190. + VCMSG_GET_BOARD_REVISION = 0x00020002,
  6191. + VCMSG_GET_BOARD_MAC_ADDRESS = 0x00020003,
  6192. + VCMSG_GET_BOARD_SERIAL = 0x00020004,
  6193. + VCMSG_GET_ARM_MEMORY = 0x00020005,
  6194. + VCMSG_GET_VC_MEMORY = 0x00020006,
  6195. + VCMSG_GET_CLOCKS = 0x00020007,
  6196. + VCMSG_GET_COMMAND_LINE = 0x00050001,
  6197. + VCMSG_GET_DMA_CHANNELS = 0x00060001,
  6198. + VCMSG_GET_POWER_STATE = 0x00020001,
  6199. + VCMSG_GET_TIMING = 0x00020002,
  6200. + VCMSG_SET_POWER_STATE = 0x00028001,
  6201. + VCMSG_GET_CLOCK_STATE = 0x00030001,
  6202. + VCMSG_SET_CLOCK_STATE = 0x00038001,
  6203. + VCMSG_GET_CLOCK_RATE = 0x00030002,
  6204. + VCMSG_SET_CLOCK_RATE = 0x00038002,
  6205. + VCMSG_GET_VOLTAGE = 0x00030003,
  6206. + VCMSG_SET_VOLTAGE = 0x00038003,
  6207. + VCMSG_GET_MAX_CLOCK = 0x00030004,
  6208. + VCMSG_GET_MAX_VOLTAGE = 0x00030005,
  6209. + VCMSG_GET_TEMPERATURE = 0x00030006,
  6210. + VCMSG_GET_MIN_CLOCK = 0x00030007,
  6211. + VCMSG_GET_MIN_VOLTAGE = 0x00030008,
  6212. + VCMSG_GET_TURBO = 0x00030009,
  6213. + VCMSG_SET_TURBO = 0x00038009,
  6214. + VCMSG_SET_ALLOCATE_BUFFER = 0x00040001,
  6215. + VCMSG_SET_RELEASE_BUFFER = 0x00048001,
  6216. + VCMSG_SET_BLANK_SCREEN = 0x00040002,
  6217. + VCMSG_TST_BLANK_SCREEN = 0x00044002,
  6218. + VCMSG_GET_PHYSICAL_WIDTH_HEIGHT = 0x00040003,
  6219. + VCMSG_TST_PHYSICAL_WIDTH_HEIGHT = 0x00044003,
  6220. + VCMSG_SET_PHYSICAL_WIDTH_HEIGHT = 0x00048003,
  6221. + VCMSG_GET_VIRTUAL_WIDTH_HEIGHT = 0x00040004,
  6222. + VCMSG_TST_VIRTUAL_WIDTH_HEIGHT = 0x00044004,
  6223. + VCMSG_SET_VIRTUAL_WIDTH_HEIGHT = 0x00048004,
  6224. + VCMSG_GET_DEPTH = 0x00040005,
  6225. + VCMSG_TST_DEPTH = 0x00044005,
  6226. + VCMSG_SET_DEPTH = 0x00048005,
  6227. + VCMSG_GET_PIXEL_ORDER = 0x00040006,
  6228. + VCMSG_TST_PIXEL_ORDER = 0x00044006,
  6229. + VCMSG_SET_PIXEL_ORDER = 0x00048006,
  6230. + VCMSG_GET_ALPHA_MODE = 0x00040007,
  6231. + VCMSG_TST_ALPHA_MODE = 0x00044007,
  6232. + VCMSG_SET_ALPHA_MODE = 0x00048007,
  6233. + VCMSG_GET_PITCH = 0x00040008,
  6234. + VCMSG_TST_PITCH = 0x00044008,
  6235. + VCMSG_SET_PITCH = 0x00048008,
  6236. + VCMSG_GET_VIRTUAL_OFFSET = 0x00040009,
  6237. + VCMSG_TST_VIRTUAL_OFFSET = 0x00044009,
  6238. + VCMSG_SET_VIRTUAL_OFFSET = 0x00048009,
  6239. + VCMSG_GET_OVERSCAN = 0x0004000a,
  6240. + VCMSG_TST_OVERSCAN = 0x0004400a,
  6241. + VCMSG_SET_OVERSCAN = 0x0004800a,
  6242. + VCMSG_GET_PALETTE = 0x0004000b,
  6243. + VCMSG_TST_PALETTE = 0x0004400b,
  6244. + VCMSG_SET_PALETTE = 0x0004800b,
  6245. + VCMSG_GET_LAYER = 0x0004000c,
  6246. + VCMSG_TST_LAYER = 0x0004400c,
  6247. + VCMSG_SET_LAYER = 0x0004800c,
  6248. + VCMSG_GET_TRANSFORM = 0x0004000d,
  6249. + VCMSG_TST_TRANSFORM = 0x0004400d,
  6250. + VCMSG_SET_TRANSFORM = 0x0004800d,
  6251. +};
  6252. +
  6253. +extern int /*rc*/ bcm_mailbox_read(unsigned chan, uint32_t *data28);
  6254. +extern int /*rc*/ bcm_mailbox_write(unsigned chan, uint32_t data28);
  6255. +extern int /*rc*/ bcm_mailbox_property(void *data, int size);
  6256. +
  6257. +#include <linux/ioctl.h>
  6258. +
  6259. +/*
  6260. + * The major device number. We can't rely on dynamic
  6261. + * registration any more, because ioctls need to know
  6262. + * it.
  6263. + */
  6264. +#define MAJOR_NUM 100
  6265. +
  6266. +/*
  6267. + * Set the message of the device driver
  6268. + */
  6269. +#define IOCTL_MBOX_PROPERTY _IOWR(MAJOR_NUM, 0, char *)
  6270. +/*
  6271. + * _IOWR means that we're creating an ioctl command
  6272. + * number for passing information from a user process
  6273. + * to the kernel module and from the kernel module to user process
  6274. + *
  6275. + * The first arguments, MAJOR_NUM, is the major device
  6276. + * number we're using.
  6277. + *
  6278. + * The second argument is the number of the command
  6279. + * (there could be several with different meanings).
  6280. + *
  6281. + * The third argument is the type we want to get from
  6282. + * the process to the kernel.
  6283. + */
  6284. +
  6285. +/*
  6286. + * The name of the device file
  6287. + */
  6288. +#define DEVICE_FILE_NAME "char_dev"
  6289. +
  6290. +#endif
  6291. diff -Nur linux-3.13.11/arch/arm/mach-bcm2708/include/mach/vc_mem.h linux-rpi/arch/arm/mach-bcm2708/include/mach/vc_mem.h
  6292. --- linux-3.13.11/arch/arm/mach-bcm2708/include/mach/vc_mem.h 1970-01-01 01:00:00.000000000 +0100
  6293. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/vc_mem.h 2014-04-24 15:36:30.950526170 +0200
  6294. @@ -0,0 +1,35 @@
  6295. +/*****************************************************************************
  6296. +* Copyright 2010 - 2011 Broadcom Corporation. All rights reserved.
  6297. +*
  6298. +* Unless you and Broadcom execute a separate written software license
  6299. +* agreement governing use of this software, this software is licensed to you
  6300. +* under the terms of the GNU General Public License version 2, available at
  6301. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  6302. +*
  6303. +* Notwithstanding the above, under no circumstances may you combine this
  6304. +* software in any way with any other Broadcom software provided under a
  6305. +* license other than the GPL, without Broadcom's express prior written
  6306. +* consent.
  6307. +*****************************************************************************/
  6308. +
  6309. +#if !defined( VC_MEM_H )
  6310. +#define VC_MEM_H
  6311. +
  6312. +#include <linux/ioctl.h>
  6313. +
  6314. +#define VC_MEM_IOC_MAGIC 'v'
  6315. +
  6316. +#define VC_MEM_IOC_MEM_PHYS_ADDR _IOR( VC_MEM_IOC_MAGIC, 0, unsigned long )
  6317. +#define VC_MEM_IOC_MEM_SIZE _IOR( VC_MEM_IOC_MAGIC, 1, unsigned int )
  6318. +#define VC_MEM_IOC_MEM_BASE _IOR( VC_MEM_IOC_MAGIC, 2, unsigned int )
  6319. +#define VC_MEM_IOC_MEM_LOAD _IOR( VC_MEM_IOC_MAGIC, 3, unsigned int )
  6320. +
  6321. +#if defined( __KERNEL__ )
  6322. +#define VC_MEM_TO_ARM_ADDR_MASK 0x3FFFFFFF
  6323. +
  6324. +extern unsigned long mm_vc_mem_phys_addr;
  6325. +extern unsigned int mm_vc_mem_size;
  6326. +extern int vc_mem_get_current_size( void );
  6327. +#endif
  6328. +
  6329. +#endif /* VC_MEM_H */
  6330. diff -Nur linux-3.13.11/arch/arm/mach-bcm2708/include/mach/vmalloc.h linux-rpi/arch/arm/mach-bcm2708/include/mach/vmalloc.h
  6331. --- linux-3.13.11/arch/arm/mach-bcm2708/include/mach/vmalloc.h 1970-01-01 01:00:00.000000000 +0100
  6332. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/vmalloc.h 2014-04-24 15:35:00.777527936 +0200
  6333. @@ -0,0 +1,20 @@
  6334. +/*
  6335. + * arch/arm/mach-bcm2708/include/mach/vmalloc.h
  6336. + *
  6337. + * Copyright (C) 2010 Broadcom
  6338. + *
  6339. + * This program is free software; you can redistribute it and/or modify
  6340. + * it under the terms of the GNU General Public License as published by
  6341. + * the Free Software Foundation; either version 2 of the License, or
  6342. + * (at your option) any later version.
  6343. + *
  6344. + * This program is distributed in the hope that it will be useful,
  6345. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6346. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6347. + * GNU General Public License for more details.
  6348. + *
  6349. + * You should have received a copy of the GNU General Public License
  6350. + * along with this program; if not, write to the Free Software
  6351. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6352. + */
  6353. +#define VMALLOC_END (0xe8000000)
  6354. diff -Nur linux-3.13.11/arch/arm/mach-bcm2708/Kconfig linux-rpi/arch/arm/mach-bcm2708/Kconfig
  6355. --- linux-3.13.11/arch/arm/mach-bcm2708/Kconfig 1970-01-01 01:00:00.000000000 +0100
  6356. +++ linux-rpi/arch/arm/mach-bcm2708/Kconfig 2014-04-24 15:36:30.950526170 +0200
  6357. @@ -0,0 +1,41 @@
  6358. +menu "Broadcom BCM2708 Implementations"
  6359. + depends on ARCH_BCM2708
  6360. +
  6361. +config MACH_BCM2708
  6362. + bool "Broadcom BCM2708 Development Platform"
  6363. + select NEED_MACH_MEMORY_H
  6364. + select NEED_MACH_IO_H
  6365. + select CPU_V6
  6366. + help
  6367. + Include support for the Broadcom(R) BCM2708 platform.
  6368. +
  6369. +config BCM2708_GPIO
  6370. + bool "BCM2708 gpio support"
  6371. + depends on MACH_BCM2708
  6372. + select ARCH_REQUIRE_GPIOLIB
  6373. + default y
  6374. + help
  6375. + Include support for the Broadcom(R) BCM2708 gpio.
  6376. +
  6377. +config BCM2708_VCMEM
  6378. + bool "Videocore Memory"
  6379. + depends on MACH_BCM2708
  6380. + default y
  6381. + help
  6382. + Helper for videocore memory access and total size allocation.
  6383. +
  6384. +config BCM2708_NOL2CACHE
  6385. + bool "Videocore L2 cache disable"
  6386. + depends on MACH_BCM2708
  6387. + default n
  6388. + help
  6389. + Do not allow ARM to use GPU's L2 cache. Requires disable_l2cache in config.txt.
  6390. +
  6391. +config BCM2708_SPIDEV
  6392. + bool "Bind spidev to SPI0 master"
  6393. + depends on MACH_BCM2708
  6394. + depends on SPI
  6395. + default y
  6396. + help
  6397. + Binds spidev driver to the SPI0 master
  6398. +endmenu
  6399. diff -Nur linux-3.13.11/arch/arm/mach-bcm2708/Makefile linux-rpi/arch/arm/mach-bcm2708/Makefile
  6400. --- linux-3.13.11/arch/arm/mach-bcm2708/Makefile 1970-01-01 01:00:00.000000000 +0100
  6401. +++ linux-rpi/arch/arm/mach-bcm2708/Makefile 2014-04-24 15:36:30.950526170 +0200
  6402. @@ -0,0 +1,7 @@
  6403. +#
  6404. +# Makefile for the linux kernel.
  6405. +#
  6406. +
  6407. +obj-$(CONFIG_MACH_BCM2708) += clock.o bcm2708.o armctrl.o vcio.o power.o dma.o
  6408. +obj-$(CONFIG_BCM2708_GPIO) += bcm2708_gpio.o
  6409. +obj-$(CONFIG_BCM2708_VCMEM) += vc_mem.o
  6410. diff -Nur linux-3.13.11/arch/arm/mach-bcm2708/Makefile.boot linux-rpi/arch/arm/mach-bcm2708/Makefile.boot
  6411. --- linux-3.13.11/arch/arm/mach-bcm2708/Makefile.boot 1970-01-01 01:00:00.000000000 +0100
  6412. +++ linux-rpi/arch/arm/mach-bcm2708/Makefile.boot 2014-04-24 15:35:00.773527891 +0200
  6413. @@ -0,0 +1,3 @@
  6414. + zreladdr-y := 0x00008000
  6415. +params_phys-y := 0x00000100
  6416. +initrd_phys-y := 0x00800000
  6417. diff -Nur linux-3.13.11/arch/arm/mach-bcm2708/power.c linux-rpi/arch/arm/mach-bcm2708/power.c
  6418. --- linux-3.13.11/arch/arm/mach-bcm2708/power.c 1970-01-01 01:00:00.000000000 +0100
  6419. +++ linux-rpi/arch/arm/mach-bcm2708/power.c 2014-04-24 15:35:00.777527936 +0200
  6420. @@ -0,0 +1,194 @@
  6421. +/*
  6422. + * linux/arch/arm/mach-bcm2708/power.c
  6423. + *
  6424. + * Copyright (C) 2010 Broadcom
  6425. + *
  6426. + * This program is free software; you can redistribute it and/or modify
  6427. + * it under the terms of the GNU General Public License version 2 as
  6428. + * published by the Free Software Foundation.
  6429. + *
  6430. + * This device provides a shared mechanism for controlling the power to
  6431. + * VideoCore subsystems.
  6432. + */
  6433. +
  6434. +#include <linux/module.h>
  6435. +#include <linux/semaphore.h>
  6436. +#include <linux/bug.h>
  6437. +#include <mach/power.h>
  6438. +#include <mach/vcio.h>
  6439. +#include <mach/arm_power.h>
  6440. +
  6441. +#define DRIVER_NAME "bcm2708_power"
  6442. +
  6443. +#define BCM_POWER_MAXCLIENTS 4
  6444. +#define BCM_POWER_NOCLIENT (1<<31)
  6445. +
  6446. +/* Some drivers expect there devices to be permanently powered */
  6447. +#define BCM_POWER_ALWAYS_ON (BCM_POWER_USB)
  6448. +
  6449. +#if 1
  6450. +#define DPRINTK printk
  6451. +#else
  6452. +#define DPRINTK if (0) printk
  6453. +#endif
  6454. +
  6455. +struct state_struct {
  6456. + uint32_t global_request;
  6457. + uint32_t client_request[BCM_POWER_MAXCLIENTS];
  6458. + struct semaphore client_mutex;
  6459. + struct semaphore mutex;
  6460. +} g_state;
  6461. +
  6462. +int bcm_power_open(BCM_POWER_HANDLE_T *handle)
  6463. +{
  6464. + BCM_POWER_HANDLE_T i;
  6465. + int ret = -EBUSY;
  6466. +
  6467. + down(&g_state.client_mutex);
  6468. +
  6469. + for (i = 0; i < BCM_POWER_MAXCLIENTS; i++) {
  6470. + if (g_state.client_request[i] == BCM_POWER_NOCLIENT) {
  6471. + g_state.client_request[i] = BCM_POWER_NONE;
  6472. + *handle = i;
  6473. + ret = 0;
  6474. + break;
  6475. + }
  6476. + }
  6477. +
  6478. + up(&g_state.client_mutex);
  6479. +
  6480. + DPRINTK("bcm_power_open() -> %d\n", *handle);
  6481. +
  6482. + return ret;
  6483. +}
  6484. +EXPORT_SYMBOL_GPL(bcm_power_open);
  6485. +
  6486. +int bcm_power_request(BCM_POWER_HANDLE_T handle, uint32_t request)
  6487. +{
  6488. + int rc = 0;
  6489. +
  6490. + DPRINTK("bcm_power_request(%d, %x)\n", handle, request);
  6491. +
  6492. + if ((handle < BCM_POWER_MAXCLIENTS) &&
  6493. + (g_state.client_request[handle] != BCM_POWER_NOCLIENT)) {
  6494. + if (down_interruptible(&g_state.mutex) != 0) {
  6495. + DPRINTK("bcm_power_request -> interrupted\n");
  6496. + return -EINTR;
  6497. + }
  6498. +
  6499. + if (request != g_state.client_request[handle]) {
  6500. + uint32_t others_request = 0;
  6501. + uint32_t global_request;
  6502. + BCM_POWER_HANDLE_T i;
  6503. +
  6504. + for (i = 0; i < BCM_POWER_MAXCLIENTS; i++) {
  6505. + if (i != handle)
  6506. + others_request |=
  6507. + g_state.client_request[i];
  6508. + }
  6509. + others_request &= ~BCM_POWER_NOCLIENT;
  6510. +
  6511. + global_request = request | others_request;
  6512. + if (global_request != g_state.global_request) {
  6513. + uint32_t actual;
  6514. +
  6515. + /* Send a request to VideoCore */
  6516. + bcm_mailbox_write(MBOX_CHAN_POWER,
  6517. + global_request << 4);
  6518. +
  6519. + /* Wait for a response during power-up */
  6520. + if (global_request & ~g_state.global_request) {
  6521. + rc = bcm_mailbox_read(MBOX_CHAN_POWER,
  6522. + &actual);
  6523. + DPRINTK
  6524. + ("bcm_mailbox_read -> %08x, %d\n",
  6525. + actual, rc);
  6526. + actual >>= 4;
  6527. + } else {
  6528. + rc = 0;
  6529. + actual = global_request;
  6530. + }
  6531. +
  6532. + if (rc == 0) {
  6533. + if (actual != global_request) {
  6534. + printk(KERN_ERR
  6535. + "%s: prev global %x, new global %x, actual %x, request %x, others_request %x\n",
  6536. + __func__,
  6537. + g_state.global_request,
  6538. + global_request, actual, request, others_request);
  6539. + /* A failure */
  6540. + BUG_ON((others_request & actual)
  6541. + != others_request);
  6542. + request &= actual;
  6543. + rc = -EIO;
  6544. + }
  6545. +
  6546. + g_state.global_request = actual;
  6547. + g_state.client_request[handle] =
  6548. + request;
  6549. + }
  6550. + }
  6551. + }
  6552. + up(&g_state.mutex);
  6553. + } else {
  6554. + rc = -EINVAL;
  6555. + }
  6556. + DPRINTK("bcm_power_request -> %d\n", rc);
  6557. + return rc;
  6558. +}
  6559. +EXPORT_SYMBOL_GPL(bcm_power_request);
  6560. +
  6561. +int bcm_power_close(BCM_POWER_HANDLE_T handle)
  6562. +{
  6563. + int rc;
  6564. +
  6565. + DPRINTK("bcm_power_close(%d)\n", handle);
  6566. +
  6567. + rc = bcm_power_request(handle, BCM_POWER_NONE);
  6568. + if (rc == 0)
  6569. + g_state.client_request[handle] = BCM_POWER_NOCLIENT;
  6570. +
  6571. + return rc;
  6572. +}
  6573. +EXPORT_SYMBOL_GPL(bcm_power_close);
  6574. +
  6575. +static int __init bcm_power_init(void)
  6576. +{
  6577. +#if defined(BCM_POWER_ALWAYS_ON)
  6578. + BCM_POWER_HANDLE_T always_on_handle;
  6579. +#endif
  6580. + int rc = 0;
  6581. + int i;
  6582. +
  6583. + printk(KERN_INFO "bcm_power: Broadcom power driver\n");
  6584. + bcm_mailbox_write(MBOX_CHAN_POWER, 0);
  6585. +
  6586. + for (i = 0; i < BCM_POWER_MAXCLIENTS; i++)
  6587. + g_state.client_request[i] = BCM_POWER_NOCLIENT;
  6588. +
  6589. + sema_init(&g_state.client_mutex, 1);
  6590. + sema_init(&g_state.mutex, 1);
  6591. +
  6592. + g_state.global_request = 0;
  6593. +
  6594. +#if defined(BCM_POWER_ALWAYS_ON)
  6595. + if (BCM_POWER_ALWAYS_ON) {
  6596. + bcm_power_open(&always_on_handle);
  6597. + bcm_power_request(always_on_handle, BCM_POWER_ALWAYS_ON);
  6598. + }
  6599. +#endif
  6600. +
  6601. + return rc;
  6602. +}
  6603. +
  6604. +static void __exit bcm_power_exit(void)
  6605. +{
  6606. + bcm_mailbox_write(MBOX_CHAN_POWER, 0);
  6607. +}
  6608. +
  6609. +arch_initcall(bcm_power_init); /* Initialize early */
  6610. +module_exit(bcm_power_exit);
  6611. +
  6612. +MODULE_AUTHOR("Phil Elwell");
  6613. +MODULE_DESCRIPTION("Interface to BCM2708 power management");
  6614. +MODULE_LICENSE("GPL");
  6615. diff -Nur linux-3.13.11/arch/arm/mach-bcm2708/vcio.c linux-rpi/arch/arm/mach-bcm2708/vcio.c
  6616. --- linux-3.13.11/arch/arm/mach-bcm2708/vcio.c 1970-01-01 01:00:00.000000000 +0100
  6617. +++ linux-rpi/arch/arm/mach-bcm2708/vcio.c 2014-04-24 15:36:30.950526170 +0200
  6618. @@ -0,0 +1,474 @@
  6619. +/*
  6620. + * linux/arch/arm/mach-bcm2708/vcio.c
  6621. + *
  6622. + * Copyright (C) 2010 Broadcom
  6623. + *
  6624. + * This program is free software; you can redistribute it and/or modify
  6625. + * it under the terms of the GNU General Public License version 2 as
  6626. + * published by the Free Software Foundation.
  6627. + *
  6628. + * This device provides a shared mechanism for writing to the mailboxes,
  6629. + * semaphores, doorbells etc. that are shared between the ARM and the
  6630. + * VideoCore processor
  6631. + */
  6632. +
  6633. +#if defined(CONFIG_SERIAL_BCM_MBOX_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
  6634. +#define SUPPORT_SYSRQ
  6635. +#endif
  6636. +
  6637. +#include <linux/module.h>
  6638. +#include <linux/console.h>
  6639. +#include <linux/serial_core.h>
  6640. +#include <linux/serial.h>
  6641. +#include <linux/errno.h>
  6642. +#include <linux/device.h>
  6643. +#include <linux/init.h>
  6644. +#include <linux/mm.h>
  6645. +#include <linux/dma-mapping.h>
  6646. +#include <linux/platform_device.h>
  6647. +#include <linux/sysrq.h>
  6648. +#include <linux/delay.h>
  6649. +#include <linux/slab.h>
  6650. +#include <linux/interrupt.h>
  6651. +#include <linux/irq.h>
  6652. +
  6653. +#include <linux/io.h>
  6654. +
  6655. +#include <mach/vcio.h>
  6656. +#include <mach/platform.h>
  6657. +
  6658. +#include <asm/uaccess.h>
  6659. +
  6660. +
  6661. +#define DRIVER_NAME BCM_VCIO_DRIVER_NAME
  6662. +
  6663. +/* ----------------------------------------------------------------------
  6664. + * Mailbox
  6665. + * -------------------------------------------------------------------- */
  6666. +
  6667. +/* offsets from a mail box base address */
  6668. +#define MAIL_WRT 0x00 /* write - and next 4 words */
  6669. +#define MAIL_RD 0x00 /* read - and next 4 words */
  6670. +#define MAIL_POL 0x10 /* read without popping the fifo */
  6671. +#define MAIL_SND 0x14 /* sender ID (bottom two bits) */
  6672. +#define MAIL_STA 0x18 /* status */
  6673. +#define MAIL_CNF 0x1C /* configuration */
  6674. +
  6675. +#define MBOX_MSG(chan, data28) (((data28) & ~0xf) | ((chan) & 0xf))
  6676. +#define MBOX_MSG_LSB(chan, data28) (((data28) << 4) | ((chan) & 0xf))
  6677. +#define MBOX_CHAN(msg) ((msg) & 0xf)
  6678. +#define MBOX_DATA28(msg) ((msg) & ~0xf)
  6679. +#define MBOX_DATA28_LSB(msg) (((uint32_t)msg) >> 4)
  6680. +
  6681. +#define MBOX_MAGIC 0xd0d0c0de
  6682. +
  6683. +struct vc_mailbox {
  6684. + struct device *dev; /* parent device */
  6685. + void __iomem *status;
  6686. + void __iomem *config;
  6687. + void __iomem *read;
  6688. + void __iomem *write;
  6689. + uint32_t msg[MBOX_CHAN_COUNT];
  6690. + struct semaphore sema[MBOX_CHAN_COUNT];
  6691. + uint32_t magic;
  6692. +};
  6693. +
  6694. +static void mbox_init(struct vc_mailbox *mbox_out, struct device *dev,
  6695. + uint32_t addr_mbox)
  6696. +{
  6697. + int i;
  6698. +
  6699. + mbox_out->dev = dev;
  6700. + mbox_out->status = __io_address(addr_mbox + MAIL_STA);
  6701. + mbox_out->config = __io_address(addr_mbox + MAIL_CNF);
  6702. + mbox_out->read = __io_address(addr_mbox + MAIL_RD);
  6703. + /* Write to the other mailbox */
  6704. + mbox_out->write =
  6705. + __io_address((addr_mbox ^ ARM_0_MAIL0_WRT ^ ARM_0_MAIL1_WRT) +
  6706. + MAIL_WRT);
  6707. +
  6708. + for (i = 0; i < MBOX_CHAN_COUNT; i++) {
  6709. + mbox_out->msg[i] = 0;
  6710. + sema_init(&mbox_out->sema[i], 0);
  6711. + }
  6712. +
  6713. + /* Enable the interrupt on data reception */
  6714. + writel(ARM_MC_IHAVEDATAIRQEN, mbox_out->config);
  6715. +
  6716. + mbox_out->magic = MBOX_MAGIC;
  6717. +}
  6718. +
  6719. +static int mbox_write(struct vc_mailbox *mbox, unsigned chan, uint32_t data28)
  6720. +{
  6721. + int rc;
  6722. +
  6723. + if (mbox->magic != MBOX_MAGIC)
  6724. + rc = -EINVAL;
  6725. + else {
  6726. + /* wait for the mailbox FIFO to have some space in it */
  6727. + while (0 != (readl(mbox->status) & ARM_MS_FULL))
  6728. + cpu_relax();
  6729. +
  6730. + writel(MBOX_MSG(chan, data28), mbox->write);
  6731. + rc = 0;
  6732. + }
  6733. + return rc;
  6734. +}
  6735. +
  6736. +static int mbox_read(struct vc_mailbox *mbox, unsigned chan, uint32_t *data28)
  6737. +{
  6738. + int rc;
  6739. +
  6740. + if (mbox->magic != MBOX_MAGIC)
  6741. + rc = -EINVAL;
  6742. + else {
  6743. + down(&mbox->sema[chan]);
  6744. + *data28 = MBOX_DATA28(mbox->msg[chan]);
  6745. + mbox->msg[chan] = 0;
  6746. + rc = 0;
  6747. + }
  6748. + return rc;
  6749. +}
  6750. +
  6751. +static irqreturn_t mbox_irq(int irq, void *dev_id)
  6752. +{
  6753. + /* wait for the mailbox FIFO to have some data in it */
  6754. + struct vc_mailbox *mbox = (struct vc_mailbox *) dev_id;
  6755. + int status = readl(mbox->status);
  6756. + int ret = IRQ_NONE;
  6757. +
  6758. + while (!(status & ARM_MS_EMPTY)) {
  6759. + uint32_t msg = readl(mbox->read);
  6760. + int chan = MBOX_CHAN(msg);
  6761. + if (chan < MBOX_CHAN_COUNT) {
  6762. + if (mbox->msg[chan]) {
  6763. + /* Overflow */
  6764. + printk(KERN_ERR DRIVER_NAME
  6765. + ": mbox chan %d overflow - drop %08x\n",
  6766. + chan, msg);
  6767. + } else {
  6768. + mbox->msg[chan] = (msg | 0xf);
  6769. + up(&mbox->sema[chan]);
  6770. + }
  6771. + } else {
  6772. + printk(KERN_ERR DRIVER_NAME
  6773. + ": invalid channel selector (msg %08x)\n", msg);
  6774. + }
  6775. + ret = IRQ_HANDLED;
  6776. + status = readl(mbox->status);
  6777. + }
  6778. + return ret;
  6779. +}
  6780. +
  6781. +static struct irqaction mbox_irqaction = {
  6782. + .name = "ARM Mailbox IRQ",
  6783. + .flags = IRQF_DISABLED | IRQF_IRQPOLL,
  6784. + .handler = mbox_irq,
  6785. +};
  6786. +
  6787. +/* ----------------------------------------------------------------------
  6788. + * Mailbox Methods
  6789. + * -------------------------------------------------------------------- */
  6790. +
  6791. +static struct device *mbox_dev; /* we assume there's only one! */
  6792. +
  6793. +static int dev_mbox_write(struct device *dev, unsigned chan, uint32_t data28)
  6794. +{
  6795. + int rc;
  6796. +
  6797. + struct vc_mailbox *mailbox = dev_get_drvdata(dev);
  6798. + device_lock(dev);
  6799. + rc = mbox_write(mailbox, chan, data28);
  6800. + device_unlock(dev);
  6801. +
  6802. + return rc;
  6803. +}
  6804. +
  6805. +static int dev_mbox_read(struct device *dev, unsigned chan, uint32_t *data28)
  6806. +{
  6807. + int rc;
  6808. +
  6809. + struct vc_mailbox *mailbox = dev_get_drvdata(dev);
  6810. + device_lock(dev);
  6811. + rc = mbox_read(mailbox, chan, data28);
  6812. + device_unlock(dev);
  6813. +
  6814. + return rc;
  6815. +}
  6816. +
  6817. +extern int bcm_mailbox_write(unsigned chan, uint32_t data28)
  6818. +{
  6819. + if (mbox_dev)
  6820. + return dev_mbox_write(mbox_dev, chan, data28);
  6821. + else
  6822. + return -ENODEV;
  6823. +}
  6824. +EXPORT_SYMBOL_GPL(bcm_mailbox_write);
  6825. +
  6826. +extern int bcm_mailbox_read(unsigned chan, uint32_t *data28)
  6827. +{
  6828. + if (mbox_dev)
  6829. + return dev_mbox_read(mbox_dev, chan, data28);
  6830. + else
  6831. + return -ENODEV;
  6832. +}
  6833. +EXPORT_SYMBOL_GPL(bcm_mailbox_read);
  6834. +
  6835. +static void dev_mbox_register(const char *dev_name, struct device *dev)
  6836. +{
  6837. + mbox_dev = dev;
  6838. +}
  6839. +
  6840. +static int mbox_copy_from_user(void *dst, const void *src, int size)
  6841. +{
  6842. + if ( (uint32_t)src < TASK_SIZE)
  6843. + {
  6844. + return copy_from_user(dst, src, size);
  6845. + }
  6846. + else
  6847. + {
  6848. + memcpy( dst, src, size );
  6849. + return 0;
  6850. + }
  6851. +}
  6852. +
  6853. +static int mbox_copy_to_user(void *dst, const void *src, int size)
  6854. +{
  6855. + if ( (uint32_t)dst < TASK_SIZE)
  6856. + {
  6857. + return copy_to_user(dst, src, size);
  6858. + }
  6859. + else
  6860. + {
  6861. + memcpy( dst, src, size );
  6862. + return 0;
  6863. + }
  6864. +}
  6865. +
  6866. +static DEFINE_MUTEX(mailbox_lock);
  6867. +extern int bcm_mailbox_property(void *data, int size)
  6868. +{
  6869. + uint32_t success;
  6870. + dma_addr_t mem_bus; /* the memory address accessed from videocore */
  6871. + void *mem_kern; /* the memory address accessed from driver */
  6872. + int s = 0;
  6873. +
  6874. + mutex_lock(&mailbox_lock);
  6875. + /* allocate some memory for the messages communicating with GPU */
  6876. + mem_kern = dma_alloc_coherent(NULL, PAGE_ALIGN(size), &mem_bus, GFP_ATOMIC);
  6877. + if (mem_kern) {
  6878. + /* create the message */
  6879. + mbox_copy_from_user(mem_kern, data, size);
  6880. +
  6881. + /* send the message */
  6882. + wmb();
  6883. + s = bcm_mailbox_write(MBOX_CHAN_PROPERTY, (uint32_t)mem_bus);
  6884. + if (s == 0) {
  6885. + s = bcm_mailbox_read(MBOX_CHAN_PROPERTY, &success);
  6886. + }
  6887. + if (s == 0) {
  6888. + /* copy the response */
  6889. + rmb();
  6890. + mbox_copy_to_user(data, mem_kern, size);
  6891. + }
  6892. + dma_free_coherent(NULL, PAGE_ALIGN(size), mem_kern, mem_bus);
  6893. + } else {
  6894. + s = -ENOMEM;
  6895. + }
  6896. + if (s != 0)
  6897. + printk(KERN_ERR DRIVER_NAME ": %s failed (%d)\n", __func__, s);
  6898. +
  6899. + mutex_unlock(&mailbox_lock);
  6900. + return s;
  6901. +}
  6902. +EXPORT_SYMBOL_GPL(bcm_mailbox_property);
  6903. +
  6904. +/* ----------------------------------------------------------------------
  6905. + * Platform Device for Mailbox
  6906. + * -------------------------------------------------------------------- */
  6907. +
  6908. +/*
  6909. + * Is the device open right now? Used to prevent
  6910. + * concurent access into the same device
  6911. + */
  6912. +static int Device_Open = 0;
  6913. +
  6914. +/*
  6915. + * This is called whenever a process attempts to open the device file
  6916. + */
  6917. +static int device_open(struct inode *inode, struct file *file)
  6918. +{
  6919. + /*
  6920. + * We don't want to talk to two processes at the same time
  6921. + */
  6922. + if (Device_Open)
  6923. + return -EBUSY;
  6924. +
  6925. + Device_Open++;
  6926. + /*
  6927. + * Initialize the message
  6928. + */
  6929. + try_module_get(THIS_MODULE);
  6930. + return 0;
  6931. +}
  6932. +
  6933. +static int device_release(struct inode *inode, struct file *file)
  6934. +{
  6935. + /*
  6936. + * We're now ready for our next caller
  6937. + */
  6938. + Device_Open--;
  6939. +
  6940. + module_put(THIS_MODULE);
  6941. + return 0;
  6942. +}
  6943. +
  6944. +/*
  6945. + * This function is called whenever a process tries to do an ioctl on our
  6946. + * device file. We get two extra parameters (additional to the inode and file
  6947. + * structures, which all device functions get): the number of the ioctl called
  6948. + * and the parameter given to the ioctl function.
  6949. + *
  6950. + * If the ioctl is write or read/write (meaning output is returned to the
  6951. + * calling process), the ioctl call returns the output of this function.
  6952. + *
  6953. + */
  6954. +static long device_ioctl(struct file *file, /* see include/linux/fs.h */
  6955. + unsigned int ioctl_num, /* number and param for ioctl */
  6956. + unsigned long ioctl_param)
  6957. +{
  6958. + unsigned size;
  6959. + /*
  6960. + * Switch according to the ioctl called
  6961. + */
  6962. + switch (ioctl_num) {
  6963. + case IOCTL_MBOX_PROPERTY:
  6964. + /*
  6965. + * Receive a pointer to a message (in user space) and set that
  6966. + * to be the device's message. Get the parameter given to
  6967. + * ioctl by the process.
  6968. + */
  6969. + mbox_copy_from_user(&size, (void *)ioctl_param, sizeof size);
  6970. + return bcm_mailbox_property((void *)ioctl_param, size);
  6971. + break;
  6972. + default:
  6973. + printk(KERN_ERR DRIVER_NAME "unknown ioctl: %d\n", ioctl_num);
  6974. + return -EINVAL;
  6975. + }
  6976. +
  6977. + return 0;
  6978. +}
  6979. +
  6980. +/* Module Declarations */
  6981. +
  6982. +/*
  6983. + * This structure will hold the functions to be called
  6984. + * when a process does something to the device we
  6985. + * created. Since a pointer to this structure is kept in
  6986. + * the devices table, it can't be local to
  6987. + * init_module. NULL is for unimplemented functios.
  6988. + */
  6989. +struct file_operations fops = {
  6990. + .unlocked_ioctl = device_ioctl,
  6991. + .open = device_open,
  6992. + .release = device_release, /* a.k.a. close */
  6993. +};
  6994. +
  6995. +static int bcm_vcio_probe(struct platform_device *pdev)
  6996. +{
  6997. + int ret = 0;
  6998. + struct vc_mailbox *mailbox;
  6999. +
  7000. + mailbox = kzalloc(sizeof(*mailbox), GFP_KERNEL);
  7001. + if (NULL == mailbox) {
  7002. + printk(KERN_ERR DRIVER_NAME ": failed to allocate "
  7003. + "mailbox memory\n");
  7004. + ret = -ENOMEM;
  7005. + } else {
  7006. + struct resource *res;
  7007. +
  7008. + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  7009. + if (res == NULL) {
  7010. + printk(KERN_ERR DRIVER_NAME ": failed to obtain memory "
  7011. + "resource\n");
  7012. + ret = -ENODEV;
  7013. + kfree(mailbox);
  7014. + } else {
  7015. + /* should be based on the registers from res really */
  7016. + mbox_init(mailbox, &pdev->dev, ARM_0_MAIL0_RD);
  7017. +
  7018. + platform_set_drvdata(pdev, mailbox);
  7019. + dev_mbox_register(DRIVER_NAME, &pdev->dev);
  7020. +
  7021. + mbox_irqaction.dev_id = mailbox;
  7022. + setup_irq(IRQ_ARM_MAILBOX, &mbox_irqaction);
  7023. + printk(KERN_INFO DRIVER_NAME ": mailbox at %p\n",
  7024. + __io_address(ARM_0_MAIL0_RD));
  7025. + }
  7026. + }
  7027. +
  7028. + if (ret == 0) {
  7029. + /*
  7030. + * Register the character device
  7031. + */
  7032. + ret = register_chrdev(MAJOR_NUM, DEVICE_FILE_NAME, &fops);
  7033. +
  7034. + /*
  7035. + * Negative values signify an error
  7036. + */
  7037. + if (ret < 0) {
  7038. + printk(KERN_ERR DRIVER_NAME
  7039. + "Failed registering the character device %d\n", ret);
  7040. + return ret;
  7041. + }
  7042. + }
  7043. + return ret;
  7044. +}
  7045. +
  7046. +static int bcm_vcio_remove(struct platform_device *pdev)
  7047. +{
  7048. + struct vc_mailbox *mailbox = platform_get_drvdata(pdev);
  7049. +
  7050. + platform_set_drvdata(pdev, NULL);
  7051. + kfree(mailbox);
  7052. +
  7053. + return 0;
  7054. +}
  7055. +
  7056. +static struct platform_driver bcm_mbox_driver = {
  7057. + .probe = bcm_vcio_probe,
  7058. + .remove = bcm_vcio_remove,
  7059. +
  7060. + .driver = {
  7061. + .name = DRIVER_NAME,
  7062. + .owner = THIS_MODULE,
  7063. + },
  7064. +};
  7065. +
  7066. +static int __init bcm_mbox_init(void)
  7067. +{
  7068. + int ret;
  7069. +
  7070. + printk(KERN_INFO "mailbox: Broadcom VideoCore Mailbox driver\n");
  7071. +
  7072. + ret = platform_driver_register(&bcm_mbox_driver);
  7073. + if (ret != 0) {
  7074. + printk(KERN_ERR DRIVER_NAME ": failed to register "
  7075. + "on platform\n");
  7076. + }
  7077. +
  7078. + return ret;
  7079. +}
  7080. +
  7081. +static void __exit bcm_mbox_exit(void)
  7082. +{
  7083. + platform_driver_unregister(&bcm_mbox_driver);
  7084. +}
  7085. +
  7086. +arch_initcall(bcm_mbox_init); /* Initialize early */
  7087. +module_exit(bcm_mbox_exit);
  7088. +
  7089. +MODULE_AUTHOR("Gray Girling");
  7090. +MODULE_DESCRIPTION("ARM I/O to VideoCore processor");
  7091. +MODULE_LICENSE("GPL");
  7092. +MODULE_ALIAS("platform:bcm-mbox");
  7093. diff -Nur linux-3.13.11/arch/arm/mach-bcm2708/vc_mem.c linux-rpi/arch/arm/mach-bcm2708/vc_mem.c
  7094. --- linux-3.13.11/arch/arm/mach-bcm2708/vc_mem.c 1970-01-01 01:00:00.000000000 +0100
  7095. +++ linux-rpi/arch/arm/mach-bcm2708/vc_mem.c 2014-04-24 15:35:00.777527936 +0200
  7096. @@ -0,0 +1,432 @@
  7097. +/*****************************************************************************
  7098. +* Copyright 2010 - 2011 Broadcom Corporation. All rights reserved.
  7099. +*
  7100. +* Unless you and Broadcom execute a separate written software license
  7101. +* agreement governing use of this software, this software is licensed to you
  7102. +* under the terms of the GNU General Public License version 2, available at
  7103. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  7104. +*
  7105. +* Notwithstanding the above, under no circumstances may you combine this
  7106. +* software in any way with any other Broadcom software provided under a
  7107. +* license other than the GPL, without Broadcom's express prior written
  7108. +* consent.
  7109. +*****************************************************************************/
  7110. +
  7111. +#include <linux/kernel.h>
  7112. +#include <linux/module.h>
  7113. +#include <linux/fs.h>
  7114. +#include <linux/device.h>
  7115. +#include <linux/cdev.h>
  7116. +#include <linux/mm.h>
  7117. +#include <linux/slab.h>
  7118. +#include <linux/debugfs.h>
  7119. +#include <asm/uaccess.h>
  7120. +#include <linux/dma-mapping.h>
  7121. +
  7122. +#ifdef CONFIG_ARCH_KONA
  7123. +#include <chal/chal_ipc.h>
  7124. +#elif CONFIG_ARCH_BCM2708
  7125. +#else
  7126. +#include <csp/chal_ipc.h>
  7127. +#endif
  7128. +
  7129. +#include "mach/vc_mem.h"
  7130. +#include <mach/vcio.h>
  7131. +
  7132. +#define DRIVER_NAME "vc-mem"
  7133. +
  7134. +// Device (/dev) related variables
  7135. +static dev_t vc_mem_devnum = 0;
  7136. +static struct class *vc_mem_class = NULL;
  7137. +static struct cdev vc_mem_cdev;
  7138. +static int vc_mem_inited = 0;
  7139. +
  7140. +#ifdef CONFIG_DEBUG_FS
  7141. +static struct dentry *vc_mem_debugfs_entry;
  7142. +#endif
  7143. +
  7144. +/*
  7145. + * Videocore memory addresses and size
  7146. + *
  7147. + * Drivers that wish to know the videocore memory addresses and sizes should
  7148. + * use these variables instead of the MM_IO_BASE and MM_ADDR_IO defines in
  7149. + * headers. This allows the other drivers to not be tied down to a a certain
  7150. + * address/size at compile time.
  7151. + *
  7152. + * In the future, the goal is to have the videocore memory virtual address and
  7153. + * size be calculated at boot time rather than at compile time. The decision of
  7154. + * where the videocore memory resides and its size would be in the hands of the
  7155. + * bootloader (and/or kernel). When that happens, the values of these variables
  7156. + * would be calculated and assigned in the init function.
  7157. + */
  7158. +// in the 2835 VC in mapped above ARM, but ARM has full access to VC space
  7159. +unsigned long mm_vc_mem_phys_addr = 0x00000000;
  7160. +unsigned int mm_vc_mem_size = 0;
  7161. +unsigned int mm_vc_mem_base = 0;
  7162. +
  7163. +EXPORT_SYMBOL(mm_vc_mem_phys_addr);
  7164. +EXPORT_SYMBOL(mm_vc_mem_size);
  7165. +EXPORT_SYMBOL(mm_vc_mem_base);
  7166. +
  7167. +static uint phys_addr = 0;
  7168. +static uint mem_size = 0;
  7169. +static uint mem_base = 0;
  7170. +
  7171. +
  7172. +/****************************************************************************
  7173. +*
  7174. +* vc_mem_open
  7175. +*
  7176. +***************************************************************************/
  7177. +
  7178. +static int
  7179. +vc_mem_open(struct inode *inode, struct file *file)
  7180. +{
  7181. + (void) inode;
  7182. + (void) file;
  7183. +
  7184. + pr_debug("%s: called file = 0x%p\n", __func__, file);
  7185. +
  7186. + return 0;
  7187. +}
  7188. +
  7189. +/****************************************************************************
  7190. +*
  7191. +* vc_mem_release
  7192. +*
  7193. +***************************************************************************/
  7194. +
  7195. +static int
  7196. +vc_mem_release(struct inode *inode, struct file *file)
  7197. +{
  7198. + (void) inode;
  7199. + (void) file;
  7200. +
  7201. + pr_debug("%s: called file = 0x%p\n", __func__, file);
  7202. +
  7203. + return 0;
  7204. +}
  7205. +
  7206. +/****************************************************************************
  7207. +*
  7208. +* vc_mem_get_size
  7209. +*
  7210. +***************************************************************************/
  7211. +
  7212. +static void
  7213. +vc_mem_get_size(void)
  7214. +{
  7215. +}
  7216. +
  7217. +/****************************************************************************
  7218. +*
  7219. +* vc_mem_get_base
  7220. +*
  7221. +***************************************************************************/
  7222. +
  7223. +static void
  7224. +vc_mem_get_base(void)
  7225. +{
  7226. +}
  7227. +
  7228. +/****************************************************************************
  7229. +*
  7230. +* vc_mem_get_current_size
  7231. +*
  7232. +***************************************************************************/
  7233. +
  7234. +int
  7235. +vc_mem_get_current_size(void)
  7236. +{
  7237. + return mm_vc_mem_size;
  7238. +}
  7239. +
  7240. +EXPORT_SYMBOL_GPL(vc_mem_get_current_size);
  7241. +
  7242. +/****************************************************************************
  7243. +*
  7244. +* vc_mem_ioctl
  7245. +*
  7246. +***************************************************************************/
  7247. +
  7248. +static long
  7249. +vc_mem_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  7250. +{
  7251. + int rc = 0;
  7252. +
  7253. + (void) cmd;
  7254. + (void) arg;
  7255. +
  7256. + pr_debug("%s: called file = 0x%p\n", __func__, file);
  7257. +
  7258. + switch (cmd) {
  7259. + case VC_MEM_IOC_MEM_PHYS_ADDR:
  7260. + {
  7261. + pr_debug("%s: VC_MEM_IOC_MEM_PHYS_ADDR=0x%p\n",
  7262. + __func__, (void *) mm_vc_mem_phys_addr);
  7263. +
  7264. + if (copy_to_user((void *) arg, &mm_vc_mem_phys_addr,
  7265. + sizeof (mm_vc_mem_phys_addr)) != 0) {
  7266. + rc = -EFAULT;
  7267. + }
  7268. + break;
  7269. + }
  7270. + case VC_MEM_IOC_MEM_SIZE:
  7271. + {
  7272. + // Get the videocore memory size first
  7273. + vc_mem_get_size();
  7274. +
  7275. + pr_debug("%s: VC_MEM_IOC_MEM_SIZE=%u\n", __func__,
  7276. + mm_vc_mem_size);
  7277. +
  7278. + if (copy_to_user((void *) arg, &mm_vc_mem_size,
  7279. + sizeof (mm_vc_mem_size)) != 0) {
  7280. + rc = -EFAULT;
  7281. + }
  7282. + break;
  7283. + }
  7284. + case VC_MEM_IOC_MEM_BASE:
  7285. + {
  7286. + // Get the videocore memory base
  7287. + vc_mem_get_base();
  7288. +
  7289. + pr_debug("%s: VC_MEM_IOC_MEM_BASE=%u\n", __func__,
  7290. + mm_vc_mem_base);
  7291. +
  7292. + if (copy_to_user((void *) arg, &mm_vc_mem_base,
  7293. + sizeof (mm_vc_mem_base)) != 0) {
  7294. + rc = -EFAULT;
  7295. + }
  7296. + break;
  7297. + }
  7298. + case VC_MEM_IOC_MEM_LOAD:
  7299. + {
  7300. + // Get the videocore memory base
  7301. + vc_mem_get_base();
  7302. +
  7303. + pr_debug("%s: VC_MEM_IOC_MEM_LOAD=%u\n", __func__,
  7304. + mm_vc_mem_base);
  7305. +
  7306. + if (copy_to_user((void *) arg, &mm_vc_mem_base,
  7307. + sizeof (mm_vc_mem_base)) != 0) {
  7308. + rc = -EFAULT;
  7309. + }
  7310. + break;
  7311. + }
  7312. + default:
  7313. + {
  7314. + return -ENOTTY;
  7315. + }
  7316. + }
  7317. + pr_debug("%s: file = 0x%p returning %d\n", __func__, file, rc);
  7318. +
  7319. + return rc;
  7320. +}
  7321. +
  7322. +/****************************************************************************
  7323. +*
  7324. +* vc_mem_mmap
  7325. +*
  7326. +***************************************************************************/
  7327. +
  7328. +static int
  7329. +vc_mem_mmap(struct file *filp, struct vm_area_struct *vma)
  7330. +{
  7331. + int rc = 0;
  7332. + unsigned long length = vma->vm_end - vma->vm_start;
  7333. + unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
  7334. +
  7335. + pr_debug("%s: vm_start = 0x%08lx vm_end = 0x%08lx vm_pgoff = 0x%08lx\n",
  7336. + __func__, (long) vma->vm_start, (long) vma->vm_end,
  7337. + (long) vma->vm_pgoff);
  7338. +
  7339. + if (offset + length > mm_vc_mem_size) {
  7340. + pr_err("%s: length %ld is too big\n", __func__, length);
  7341. + return -EINVAL;
  7342. + }
  7343. + // Do not cache the memory map
  7344. + vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
  7345. +
  7346. + rc = remap_pfn_range(vma, vma->vm_start,
  7347. + (mm_vc_mem_phys_addr >> PAGE_SHIFT) +
  7348. + vma->vm_pgoff, length, vma->vm_page_prot);
  7349. + if (rc != 0) {
  7350. + pr_err("%s: remap_pfn_range failed (rc=%d)\n", __func__, rc);
  7351. + }
  7352. +
  7353. + return rc;
  7354. +}
  7355. +
  7356. +/****************************************************************************
  7357. +*
  7358. +* File Operations for the driver.
  7359. +*
  7360. +***************************************************************************/
  7361. +
  7362. +static const struct file_operations vc_mem_fops = {
  7363. + .owner = THIS_MODULE,
  7364. + .open = vc_mem_open,
  7365. + .release = vc_mem_release,
  7366. + .unlocked_ioctl = vc_mem_ioctl,
  7367. + .mmap = vc_mem_mmap,
  7368. +};
  7369. +
  7370. +#ifdef CONFIG_DEBUG_FS
  7371. +static void vc_mem_debugfs_deinit(void)
  7372. +{
  7373. + debugfs_remove_recursive(vc_mem_debugfs_entry);
  7374. + vc_mem_debugfs_entry = NULL;
  7375. +}
  7376. +
  7377. +
  7378. +static int vc_mem_debugfs_init(
  7379. + struct device *dev)
  7380. +{
  7381. + vc_mem_debugfs_entry = debugfs_create_dir(DRIVER_NAME, NULL);
  7382. + if (!vc_mem_debugfs_entry) {
  7383. + dev_warn(dev, "could not create debugfs entry\n");
  7384. + return -EFAULT;
  7385. + }
  7386. +
  7387. + if (!debugfs_create_x32("vc_mem_phys_addr",
  7388. + 0444,
  7389. + vc_mem_debugfs_entry,
  7390. + (u32 *)&mm_vc_mem_phys_addr)) {
  7391. + dev_warn(dev, "%s:could not create vc_mem_phys entry\n",
  7392. + __func__);
  7393. + goto fail;
  7394. + }
  7395. +
  7396. + if (!debugfs_create_x32("vc_mem_size",
  7397. + 0444,
  7398. + vc_mem_debugfs_entry,
  7399. + (u32 *)&mm_vc_mem_size)) {
  7400. + dev_warn(dev, "%s:could not create vc_mem_size entry\n",
  7401. + __func__);
  7402. + goto fail;
  7403. + }
  7404. +
  7405. + if (!debugfs_create_x32("vc_mem_base",
  7406. + 0444,
  7407. + vc_mem_debugfs_entry,
  7408. + (u32 *)&mm_vc_mem_base)) {
  7409. + dev_warn(dev, "%s:could not create vc_mem_base entry\n",
  7410. + __func__);
  7411. + goto fail;
  7412. + }
  7413. +
  7414. + return 0;
  7415. +
  7416. +fail:
  7417. + vc_mem_debugfs_deinit();
  7418. + return -EFAULT;
  7419. +}
  7420. +
  7421. +#endif /* CONFIG_DEBUG_FS */
  7422. +
  7423. +
  7424. +/****************************************************************************
  7425. +*
  7426. +* vc_mem_init
  7427. +*
  7428. +***************************************************************************/
  7429. +
  7430. +static int __init
  7431. +vc_mem_init(void)
  7432. +{
  7433. + int rc = -EFAULT;
  7434. + struct device *dev;
  7435. +
  7436. + pr_debug("%s: called\n", __func__);
  7437. +
  7438. + mm_vc_mem_phys_addr = phys_addr;
  7439. + mm_vc_mem_size = mem_size;
  7440. + mm_vc_mem_base = mem_base;
  7441. +
  7442. + vc_mem_get_size();
  7443. +
  7444. + pr_info("vc-mem: phys_addr:0x%08lx mem_base=0x%08x mem_size:0x%08x(%u MiB)\n",
  7445. + mm_vc_mem_phys_addr, mm_vc_mem_base, mm_vc_mem_size, mm_vc_mem_size / (1024 * 1024));
  7446. +
  7447. + if ((rc = alloc_chrdev_region(&vc_mem_devnum, 0, 1, DRIVER_NAME)) < 0) {
  7448. + pr_err("%s: alloc_chrdev_region failed (rc=%d)\n",
  7449. + __func__, rc);
  7450. + goto out_err;
  7451. + }
  7452. +
  7453. + cdev_init(&vc_mem_cdev, &vc_mem_fops);
  7454. + if ((rc = cdev_add(&vc_mem_cdev, vc_mem_devnum, 1)) != 0) {
  7455. + pr_err("%s: cdev_add failed (rc=%d)\n", __func__, rc);
  7456. + goto out_unregister;
  7457. + }
  7458. +
  7459. + vc_mem_class = class_create(THIS_MODULE, DRIVER_NAME);
  7460. + if (IS_ERR(vc_mem_class)) {
  7461. + rc = PTR_ERR(vc_mem_class);
  7462. + pr_err("%s: class_create failed (rc=%d)\n", __func__, rc);
  7463. + goto out_cdev_del;
  7464. + }
  7465. +
  7466. + dev = device_create(vc_mem_class, NULL, vc_mem_devnum, NULL,
  7467. + DRIVER_NAME);
  7468. + if (IS_ERR(dev)) {
  7469. + rc = PTR_ERR(dev);
  7470. + pr_err("%s: device_create failed (rc=%d)\n", __func__, rc);
  7471. + goto out_class_destroy;
  7472. + }
  7473. +
  7474. +#ifdef CONFIG_DEBUG_FS
  7475. + /* don't fail if the debug entries cannot be created */
  7476. + vc_mem_debugfs_init(dev);
  7477. +#endif
  7478. +
  7479. + vc_mem_inited = 1;
  7480. + return 0;
  7481. +
  7482. + device_destroy(vc_mem_class, vc_mem_devnum);
  7483. +
  7484. + out_class_destroy:
  7485. + class_destroy(vc_mem_class);
  7486. + vc_mem_class = NULL;
  7487. +
  7488. + out_cdev_del:
  7489. + cdev_del(&vc_mem_cdev);
  7490. +
  7491. + out_unregister:
  7492. + unregister_chrdev_region(vc_mem_devnum, 1);
  7493. +
  7494. + out_err:
  7495. + return -1;
  7496. +}
  7497. +
  7498. +/****************************************************************************
  7499. +*
  7500. +* vc_mem_exit
  7501. +*
  7502. +***************************************************************************/
  7503. +
  7504. +static void __exit
  7505. +vc_mem_exit(void)
  7506. +{
  7507. + pr_debug("%s: called\n", __func__);
  7508. +
  7509. + if (vc_mem_inited) {
  7510. +#if CONFIG_DEBUG_FS
  7511. + vc_mem_debugfs_deinit();
  7512. +#endif
  7513. + device_destroy(vc_mem_class, vc_mem_devnum);
  7514. + class_destroy(vc_mem_class);
  7515. + cdev_del(&vc_mem_cdev);
  7516. + unregister_chrdev_region(vc_mem_devnum, 1);
  7517. + }
  7518. +}
  7519. +
  7520. +module_init(vc_mem_init);
  7521. +module_exit(vc_mem_exit);
  7522. +MODULE_LICENSE("GPL");
  7523. +MODULE_AUTHOR("Broadcom Corporation");
  7524. +
  7525. +module_param(phys_addr, uint, 0644);
  7526. +module_param(mem_size, uint, 0644);
  7527. +module_param(mem_base, uint, 0644);
  7528. +
  7529. diff -Nur linux-3.13.11/arch/arm/Makefile linux-rpi/arch/arm/Makefile
  7530. --- linux-3.13.11/arch/arm/Makefile 2014-04-23 01:49:33.000000000 +0200
  7531. +++ linux-rpi/arch/arm/Makefile 2014-04-24 15:36:30.118517020 +0200
  7532. @@ -147,6 +147,7 @@
  7533. # by CONFIG_* macro name.
  7534. machine-$(CONFIG_ARCH_AT91) += at91
  7535. machine-$(CONFIG_ARCH_BCM) += bcm
  7536. +machine-$(CONFIG_ARCH_BCM2708) += bcm2708
  7537. machine-$(CONFIG_ARCH_BCM2835) += bcm2835
  7538. machine-$(CONFIG_ARCH_CLPS711X) += clps711x
  7539. machine-$(CONFIG_ARCH_CNS3XXX) += cns3xxx
  7540. diff -Nur linux-3.13.11/arch/arm/mm/Kconfig linux-rpi/arch/arm/mm/Kconfig
  7541. --- linux-3.13.11/arch/arm/mm/Kconfig 2014-04-23 01:49:33.000000000 +0200
  7542. +++ linux-rpi/arch/arm/mm/Kconfig 2014-04-24 15:36:32.638544728 +0200
  7543. @@ -358,7 +358,7 @@
  7544. # ARMv6
  7545. config CPU_V6
  7546. - bool "Support ARM V6 processor" if ARCH_INTEGRATOR || MACH_REALVIEW_EB || MACH_REALVIEW_PBX
  7547. + bool "Support ARM V6 processor" if ARCH_INTEGRATOR || MACH_REALVIEW_EB || MACH_REALVIEW_PBX || MACH_BCM2708
  7548. select CPU_32v6
  7549. select CPU_ABRT_EV6
  7550. select CPU_CACHE_V6
  7551. diff -Nur linux-3.13.11/arch/arm/mm/proc-v6.S linux-rpi/arch/arm/mm/proc-v6.S
  7552. --- linux-3.13.11/arch/arm/mm/proc-v6.S 2014-04-23 01:49:33.000000000 +0200
  7553. +++ linux-rpi/arch/arm/mm/proc-v6.S 2014-04-24 15:36:32.646544816 +0200
  7554. @@ -73,10 +73,19 @@
  7555. *
  7556. * IRQs are already disabled.
  7557. */
  7558. +
  7559. +/* See jira SW-5991 for details of this workaround */
  7560. ENTRY(cpu_v6_do_idle)
  7561. - mov r1, #0
  7562. - mcr p15, 0, r1, c7, c10, 4 @ DWB - WFI may enter a low-power mode
  7563. - mcr p15, 0, r1, c7, c0, 4 @ wait for interrupt
  7564. + .align 5
  7565. + mov r1, #2
  7566. +1: subs r1, #1
  7567. + nop
  7568. + mcreq p15, 0, r1, c7, c10, 4 @ DWB - WFI may enter a low-power mode
  7569. + mcreq p15, 0, r1, c7, c0, 4 @ wait for interrupt
  7570. + nop
  7571. + nop
  7572. + nop
  7573. + bne 1b
  7574. mov pc, lr
  7575. ENTRY(cpu_v6_dcache_clean_area)
  7576. diff -Nur linux-3.13.11/arch/arm/tools/mach-types linux-rpi/arch/arm/tools/mach-types
  7577. --- linux-3.13.11/arch/arm/tools/mach-types 2014-04-23 01:49:33.000000000 +0200
  7578. +++ linux-rpi/arch/arm/tools/mach-types 2014-04-24 15:35:00.985530254 +0200
  7579. @@ -522,6 +522,7 @@
  7580. prima2_evb MACH_PRIMA2_EVB PRIMA2_EVB 3103
  7581. paz00 MACH_PAZ00 PAZ00 3128
  7582. acmenetusfoxg20 MACH_ACMENETUSFOXG20 ACMENETUSFOXG20 3129
  7583. +bcm2708 MACH_BCM2708 BCM2708 3138
  7584. ag5evm MACH_AG5EVM AG5EVM 3189
  7585. ics_if_voip MACH_ICS_IF_VOIP ICS_IF_VOIP 3206
  7586. wlf_cragg_6410 MACH_WLF_CRAGG_6410 WLF_CRAGG_6410 3207
  7587. diff -Nur linux-3.13.11/arch/sparc/Kconfig linux-rpi/arch/sparc/Kconfig
  7588. --- linux-3.13.11/arch/sparc/Kconfig 2014-04-23 01:49:33.000000000 +0200
  7589. +++ linux-rpi/arch/sparc/Kconfig 2014-04-24 15:36:44.622676352 +0200
  7590. @@ -26,7 +26,7 @@
  7591. select RTC_DRV_M48T59
  7592. select HAVE_DMA_ATTRS
  7593. select HAVE_DMA_API_DEBUG
  7594. - select HAVE_ARCH_JUMP_LABEL if SPARC64
  7595. + select HAVE_ARCH_JUMP_LABEL
  7596. select GENERIC_IRQ_SHOW
  7597. select ARCH_WANT_IPC_PARSE_VERSION
  7598. select GENERIC_PCI_IOMAP
  7599. diff -Nur linux-3.13.11/arch/sparc/kernel/process_64.c linux-rpi/arch/sparc/kernel/process_64.c
  7600. --- linux-3.13.11/arch/sparc/kernel/process_64.c 2014-04-23 01:49:33.000000000 +0200
  7601. +++ linux-rpi/arch/sparc/kernel/process_64.c 2014-04-24 15:36:44.626676396 +0200
  7602. @@ -58,12 +58,9 @@
  7603. {
  7604. if (tlb_type != hypervisor) {
  7605. touch_nmi_watchdog();
  7606. - local_irq_enable();
  7607. } else {
  7608. unsigned long pstate;
  7609. - local_irq_enable();
  7610. -
  7611. /* The sun4v sleeping code requires that we have PSTATE.IE cleared over
  7612. * the cpu sleep hypervisor call.
  7613. */
  7614. @@ -85,6 +82,7 @@
  7615. : "=&r" (pstate)
  7616. : "i" (PSTATE_IE));
  7617. }
  7618. + local_irq_enable();
  7619. }
  7620. #ifdef CONFIG_HOTPLUG_CPU
  7621. diff -Nur linux-3.13.11/arch/sparc/kernel/syscalls.S linux-rpi/arch/sparc/kernel/syscalls.S
  7622. --- linux-3.13.11/arch/sparc/kernel/syscalls.S 2014-04-23 01:49:33.000000000 +0200
  7623. +++ linux-rpi/arch/sparc/kernel/syscalls.S 2014-04-24 15:36:44.630676440 +0200
  7624. @@ -189,8 +189,7 @@
  7625. mov %i0, %l5 ! IEU1
  7626. 5: call %l7 ! CTI Group brk forced
  7627. srl %i5, 0, %o5 ! IEU1
  7628. - ba,pt %xcc, 3f
  7629. - sra %o0, 0, %o0
  7630. + ba,a,pt %xcc, 3f
  7631. /* Linux native system calls enter here... */
  7632. .align 32
  7633. @@ -218,6 +217,7 @@
  7634. 3: stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
  7635. ret_sys_call:
  7636. ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %g3
  7637. + sra %o0, 0, %o0
  7638. mov %ulo(TSTATE_XCARRY | TSTATE_ICARRY), %g2
  7639. sllx %g2, 32, %g2
  7640. diff -Nur linux-3.13.11/arch/x86/kernel/cpu/mshyperv.c linux-rpi/arch/x86/kernel/cpu/mshyperv.c
  7641. --- linux-3.13.11/arch/x86/kernel/cpu/mshyperv.c 2014-04-23 01:49:33.000000000 +0200
  7642. +++ linux-rpi/arch/x86/kernel/cpu/mshyperv.c 2014-04-24 15:36:44.726677493 +0200
  7643. @@ -26,7 +26,6 @@
  7644. #include <asm/irq_regs.h>
  7645. #include <asm/i8259.h>
  7646. #include <asm/apic.h>
  7647. -#include <asm/timer.h>
  7648. struct ms_hyperv_info ms_hyperv;
  7649. EXPORT_SYMBOL_GPL(ms_hyperv);
  7650. @@ -106,11 +105,6 @@
  7651. if (ms_hyperv.features & HV_X64_MSR_TIME_REF_COUNT_AVAILABLE)
  7652. clocksource_register_hz(&hyperv_cs, NSEC_PER_SEC/100);
  7653. -
  7654. -#ifdef CONFIG_X86_IO_APIC
  7655. - no_timer_check = 1;
  7656. -#endif
  7657. -
  7658. }
  7659. const __refconst struct hypervisor_x86 x86_hyper_ms_hyperv = {
  7660. diff -Nur linux-3.13.11/arch/x86/kernel/early-quirks.c linux-rpi/arch/x86/kernel/early-quirks.c
  7661. --- linux-3.13.11/arch/x86/kernel/early-quirks.c 2014-04-23 01:49:33.000000000 +0200
  7662. +++ linux-rpi/arch/x86/kernel/early-quirks.c 2014-04-24 15:36:44.730677537 +0200
  7663. @@ -203,15 +203,18 @@
  7664. revision = read_pci_config_byte(num, slot, func, PCI_REVISION_ID);
  7665. /*
  7666. - * Revision <= 13 of all triggering devices id in this quirk
  7667. - * have a problem draining interrupts when irq remapping is
  7668. - * enabled, and should be flagged as broken. Additionally
  7669. - * revision 0x22 of device id 0x3405 has this problem.
  7670. + * Revision 13 of all triggering devices id in this quirk have
  7671. + * a problem draining interrupts when irq remapping is enabled,
  7672. + * and should be flagged as broken. Additionally revisions 0x12
  7673. + * and 0x22 of device id 0x3405 has this problem.
  7674. */
  7675. - if (revision <= 0x13)
  7676. + if (revision == 0x13)
  7677. set_irq_remapping_broken();
  7678. - else if (device == 0x3405 && revision == 0x22)
  7679. + else if ((device == 0x3405) &&
  7680. + ((revision == 0x12) ||
  7681. + (revision == 0x22)))
  7682. set_irq_remapping_broken();
  7683. +
  7684. }
  7685. /*
  7686. diff -Nur linux-3.13.11/Documentation/video4linux/bcm2835-v4l2.txt linux-rpi/Documentation/video4linux/bcm2835-v4l2.txt
  7687. --- linux-3.13.11/Documentation/video4linux/bcm2835-v4l2.txt 1970-01-01 01:00:00.000000000 +0100
  7688. +++ linux-rpi/Documentation/video4linux/bcm2835-v4l2.txt 2014-04-24 15:35:00.565525573 +0200
  7689. @@ -0,0 +1,60 @@
  7690. +
  7691. +BCM2835 (aka Raspberry Pi) V4L2 driver
  7692. +======================================
  7693. +
  7694. +1. Copyright
  7695. +============
  7696. +
  7697. +Copyright © 2013 Raspberry Pi (Trading) Ltd.
  7698. +
  7699. +2. License
  7700. +==========
  7701. +
  7702. +This program is free software; you can redistribute it and/or modify
  7703. +it under the terms of the GNU General Public License as published by
  7704. +the Free Software Foundation; either version 2 of the License, or
  7705. +(at your option) any later version.
  7706. +
  7707. +This program is distributed in the hope that it will be useful,
  7708. +but WITHOUT ANY WARRANTY; without even the implied warranty of
  7709. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  7710. +GNU General Public License for more details.
  7711. +
  7712. +You should have received a copy of the GNU General Public License
  7713. +along with this program; if not, write to the Free Software
  7714. +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  7715. +
  7716. +3. Quick Start
  7717. +==============
  7718. +
  7719. +You need a version 1.0 or later of v4l2-ctl, available from:
  7720. + git://git.linuxtv.org/v4l-utils.git
  7721. +
  7722. +$ sudo modprobe bcm2835-v4l2
  7723. +
  7724. +Turn on the overlay:
  7725. +
  7726. +$ v4l2-ctl --overlay=1
  7727. +
  7728. +Turn off the overlay:
  7729. +
  7730. +$ v4l2-ctl --overlay=0
  7731. +
  7732. +Set the capture format for video:
  7733. +
  7734. +$ v4l2-ctl --set-fmt-video=width=1920,height=1088,pixelformat=4
  7735. +
  7736. +(Note: 1088 not 1080).
  7737. +
  7738. +Capture:
  7739. +
  7740. +$ v4l2-ctl --stream-mmap=3 --stream-count=100 --stream-to=somefile.h264
  7741. +
  7742. +Stills capture:
  7743. +
  7744. +$ v4l2-ctl --set-fmt-video=width=2592,height=1944,pixelformat=3
  7745. +$ v4l2-ctl --stream-mmap=3 --stream-count=1 --stream-to=somefile.jpg
  7746. +
  7747. +List of available formats:
  7748. +
  7749. +$ v4l2-ctl --list-formats
  7750. diff -Nur linux-3.13.11/drivers/acpi/button.c linux-rpi/drivers/acpi/button.c
  7751. --- linux-3.13.11/drivers/acpi/button.c 2014-04-23 01:49:33.000000000 +0200
  7752. +++ linux-rpi/drivers/acpi/button.c 2014-04-24 15:36:45.410684999 +0200
  7753. @@ -302,10 +302,6 @@
  7754. input_sync(input);
  7755. pm_wakeup_event(&device->dev, 0);
  7756. - acpi_bus_generate_netlink_event(
  7757. - device->pnp.device_class,
  7758. - dev_name(&device->dev),
  7759. - event, ++button->pushed);
  7760. }
  7761. break;
  7762. default:
  7763. diff -Nur linux-3.13.11/drivers/char/broadcom/Kconfig linux-rpi/drivers/char/broadcom/Kconfig
  7764. --- linux-3.13.11/drivers/char/broadcom/Kconfig 1970-01-01 01:00:00.000000000 +0100
  7765. +++ linux-rpi/drivers/char/broadcom/Kconfig 2014-04-24 15:36:45.506686052 +0200
  7766. @@ -0,0 +1,16 @@
  7767. +#
  7768. +# Broadcom char driver config
  7769. +#
  7770. +
  7771. +menuconfig BRCM_CHAR_DRIVERS
  7772. + bool "Broadcom Char Drivers"
  7773. + help
  7774. + Broadcom's char drivers
  7775. +
  7776. +config BCM_VC_CMA
  7777. + bool "Videocore CMA"
  7778. + depends on CMA && BRCM_CHAR_DRIVERS && BCM2708_VCHIQ
  7779. + default n
  7780. + help
  7781. + Helper for videocore CMA access.
  7782. +
  7783. diff -Nur linux-3.13.11/drivers/char/broadcom/Makefile linux-rpi/drivers/char/broadcom/Makefile
  7784. --- linux-3.13.11/drivers/char/broadcom/Makefile 1970-01-01 01:00:00.000000000 +0100
  7785. +++ linux-rpi/drivers/char/broadcom/Makefile 2014-04-24 15:36:45.506686052 +0200
  7786. @@ -0,0 +1 @@
  7787. +obj-$(CONFIG_BCM_VC_CMA) += vc_cma/
  7788. diff -Nur linux-3.13.11/drivers/char/broadcom/vc_cma/Makefile linux-rpi/drivers/char/broadcom/vc_cma/Makefile
  7789. --- linux-3.13.11/drivers/char/broadcom/vc_cma/Makefile 1970-01-01 01:00:00.000000000 +0100
  7790. +++ linux-rpi/drivers/char/broadcom/vc_cma/Makefile 2014-04-24 15:36:45.506686052 +0200
  7791. @@ -0,0 +1,14 @@
  7792. +ccflags-y += -Wall -Wstrict-prototypes -Wno-trigraphs
  7793. +ccflags-y += -Werror
  7794. +ccflags-y += -Iinclude/linux/broadcom
  7795. +ccflags-y += -Idrivers/misc/vc04_services
  7796. +ccflags-y += -Idrivers/misc/vc04_services/interface/vchi
  7797. +ccflags-y += -Idrivers/misc/vc04_services/interface/vchiq_arm
  7798. +
  7799. +ccflags-y += -D__KERNEL__
  7800. +ccflags-y += -D__linux__
  7801. +ccflags-y += -Werror
  7802. +
  7803. +obj-$(CONFIG_BCM_VC_CMA) += vc-cma.o
  7804. +
  7805. +vc-cma-objs := vc_cma.o
  7806. diff -Nur linux-3.13.11/drivers/char/broadcom/vc_cma/vc_cma.c linux-rpi/drivers/char/broadcom/vc_cma/vc_cma.c
  7807. --- linux-3.13.11/drivers/char/broadcom/vc_cma/vc_cma.c 1970-01-01 01:00:00.000000000 +0100
  7808. +++ linux-rpi/drivers/char/broadcom/vc_cma/vc_cma.c 2014-04-24 15:36:45.506686052 +0200
  7809. @@ -0,0 +1,1143 @@
  7810. +/**
  7811. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  7812. + *
  7813. + * Redistribution and use in source and binary forms, with or without
  7814. + * modification, are permitted provided that the following conditions
  7815. + * are met:
  7816. + * 1. Redistributions of source code must retain the above copyright
  7817. + * notice, this list of conditions, and the following disclaimer,
  7818. + * without modification.
  7819. + * 2. Redistributions in binary form must reproduce the above copyright
  7820. + * notice, this list of conditions and the following disclaimer in the
  7821. + * documentation and/or other materials provided with the distribution.
  7822. + * 3. The names of the above-listed copyright holders may not be used
  7823. + * to endorse or promote products derived from this software without
  7824. + * specific prior written permission.
  7825. + *
  7826. + * ALTERNATIVELY, this software may be distributed under the terms of the
  7827. + * GNU General Public License ("GPL") version 2, as published by the Free
  7828. + * Software Foundation.
  7829. + *
  7830. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  7831. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  7832. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  7833. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  7834. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  7835. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  7836. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  7837. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  7838. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  7839. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  7840. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  7841. + */
  7842. +
  7843. +#include <linux/kernel.h>
  7844. +#include <linux/module.h>
  7845. +#include <linux/kthread.h>
  7846. +#include <linux/fs.h>
  7847. +#include <linux/device.h>
  7848. +#include <linux/cdev.h>
  7849. +#include <linux/mm.h>
  7850. +#include <linux/proc_fs.h>
  7851. +#include <linux/seq_file.h>
  7852. +#include <linux/dma-mapping.h>
  7853. +#include <linux/dma-contiguous.h>
  7854. +#include <linux/platform_device.h>
  7855. +#include <linux/uaccess.h>
  7856. +#include <asm/cacheflush.h>
  7857. +
  7858. +#include "vc_cma.h"
  7859. +
  7860. +#include "vchiq_util.h"
  7861. +#include "vchiq_connected.h"
  7862. +//#include "debug_sym.h"
  7863. +//#include "vc_mem.h"
  7864. +
  7865. +#define DRIVER_NAME "vc-cma"
  7866. +
  7867. +#define LOG_DBG(fmt, ...) \
  7868. + if (vc_cma_debug) \
  7869. + printk(KERN_INFO fmt "\n", ##__VA_ARGS__)
  7870. +#define LOG_ERR(fmt, ...) \
  7871. + printk(KERN_ERR fmt "\n", ##__VA_ARGS__)
  7872. +
  7873. +#define VC_CMA_FOURCC VCHIQ_MAKE_FOURCC('C', 'M', 'A', ' ')
  7874. +#define VC_CMA_VERSION 2
  7875. +
  7876. +#define VC_CMA_CHUNK_ORDER 6 /* 256K */
  7877. +#define VC_CMA_CHUNK_SIZE (4096 << VC_CMA_CHUNK_ORDER)
  7878. +#define VC_CMA_MAX_PARAMS_PER_MSG \
  7879. + ((VCHIQ_MAX_MSG_SIZE - sizeof(unsigned short))/sizeof(unsigned short))
  7880. +#define VC_CMA_RESERVE_COUNT_MAX 16
  7881. +
  7882. +#define PAGES_PER_CHUNK (VC_CMA_CHUNK_SIZE / PAGE_SIZE)
  7883. +
  7884. +#define VCADDR_TO_PHYSADDR(vcaddr) (mm_vc_mem_phys_addr + vcaddr)
  7885. +
  7886. +#define loud_error(...) \
  7887. + LOG_ERR("===== " __VA_ARGS__)
  7888. +
  7889. +enum {
  7890. + VC_CMA_MSG_QUIT,
  7891. + VC_CMA_MSG_OPEN,
  7892. + VC_CMA_MSG_TICK,
  7893. + VC_CMA_MSG_ALLOC, /* chunk count */
  7894. + VC_CMA_MSG_FREE, /* chunk, chunk, ... */
  7895. + VC_CMA_MSG_ALLOCATED, /* chunk, chunk, ... */
  7896. + VC_CMA_MSG_REQUEST_ALLOC, /* chunk count */
  7897. + VC_CMA_MSG_REQUEST_FREE, /* chunk count */
  7898. + VC_CMA_MSG_RESERVE, /* bytes lo, bytes hi */
  7899. + VC_CMA_MSG_UPDATE_RESERVE,
  7900. + VC_CMA_MSG_MAX
  7901. +};
  7902. +
  7903. +struct cma_msg {
  7904. + unsigned short type;
  7905. + unsigned short params[VC_CMA_MAX_PARAMS_PER_MSG];
  7906. +};
  7907. +
  7908. +struct vc_cma_reserve_user {
  7909. + unsigned int pid;
  7910. + unsigned int reserve;
  7911. +};
  7912. +
  7913. +/* Device (/dev) related variables */
  7914. +static dev_t vc_cma_devnum;
  7915. +static struct class *vc_cma_class;
  7916. +static struct cdev vc_cma_cdev;
  7917. +static int vc_cma_inited;
  7918. +static int vc_cma_debug;
  7919. +
  7920. +/* Proc entry */
  7921. +static struct proc_dir_entry *vc_cma_proc_entry;
  7922. +
  7923. +phys_addr_t vc_cma_base;
  7924. +struct page *vc_cma_base_page;
  7925. +unsigned int vc_cma_size;
  7926. +EXPORT_SYMBOL(vc_cma_size);
  7927. +unsigned int vc_cma_initial;
  7928. +unsigned int vc_cma_chunks;
  7929. +unsigned int vc_cma_chunks_used;
  7930. +unsigned int vc_cma_chunks_reserved;
  7931. +
  7932. +static int in_loud_error;
  7933. +
  7934. +unsigned int vc_cma_reserve_total;
  7935. +unsigned int vc_cma_reserve_count;
  7936. +struct vc_cma_reserve_user vc_cma_reserve_users[VC_CMA_RESERVE_COUNT_MAX];
  7937. +static DEFINE_SEMAPHORE(vc_cma_reserve_mutex);
  7938. +static DEFINE_SEMAPHORE(vc_cma_worker_queue_push_mutex);
  7939. +
  7940. +static u64 vc_cma_dma_mask = DMA_BIT_MASK(32);
  7941. +static struct platform_device vc_cma_device = {
  7942. + .name = "vc-cma",
  7943. + .id = 0,
  7944. + .dev = {
  7945. + .dma_mask = &vc_cma_dma_mask,
  7946. + .coherent_dma_mask = DMA_BIT_MASK(32),
  7947. + },
  7948. +};
  7949. +
  7950. +static VCHIQ_INSTANCE_T cma_instance;
  7951. +static VCHIQ_SERVICE_HANDLE_T cma_service;
  7952. +static VCHIU_QUEUE_T cma_msg_queue;
  7953. +static struct task_struct *cma_worker;
  7954. +
  7955. +static int vc_cma_set_reserve(unsigned int reserve, unsigned int pid);
  7956. +static int vc_cma_alloc_chunks(int num_chunks, struct cma_msg *reply);
  7957. +static VCHIQ_STATUS_T cma_service_callback(VCHIQ_REASON_T reason,
  7958. + VCHIQ_HEADER_T * header,
  7959. + VCHIQ_SERVICE_HANDLE_T service,
  7960. + void *bulk_userdata);
  7961. +static void send_vc_msg(unsigned short type,
  7962. + unsigned short param1, unsigned short param2);
  7963. +static bool send_worker_msg(VCHIQ_HEADER_T * msg);
  7964. +
  7965. +static int early_vc_cma_mem(char *p)
  7966. +{
  7967. + unsigned int new_size;
  7968. + printk(KERN_NOTICE "early_vc_cma_mem(%s)", p);
  7969. + vc_cma_size = memparse(p, &p);
  7970. + vc_cma_initial = vc_cma_size;
  7971. + if (*p == '/')
  7972. + vc_cma_size = memparse(p + 1, &p);
  7973. + if (*p == '@')
  7974. + vc_cma_base = memparse(p + 1, &p);
  7975. +
  7976. + new_size = (vc_cma_size - ((-vc_cma_base) & (VC_CMA_CHUNK_SIZE - 1)))
  7977. + & ~(VC_CMA_CHUNK_SIZE - 1);
  7978. + if (new_size > vc_cma_size)
  7979. + vc_cma_size = 0;
  7980. + vc_cma_initial = (vc_cma_initial + VC_CMA_CHUNK_SIZE - 1)
  7981. + & ~(VC_CMA_CHUNK_SIZE - 1);
  7982. + if (vc_cma_initial > vc_cma_size)
  7983. + vc_cma_initial = vc_cma_size;
  7984. + vc_cma_base = (vc_cma_base + VC_CMA_CHUNK_SIZE - 1)
  7985. + & ~(VC_CMA_CHUNK_SIZE - 1);
  7986. +
  7987. + printk(KERN_NOTICE " -> initial %x, size %x, base %x", vc_cma_initial,
  7988. + vc_cma_size, (unsigned int)vc_cma_base);
  7989. +
  7990. + return 0;
  7991. +}
  7992. +
  7993. +early_param("vc-cma-mem", early_vc_cma_mem);
  7994. +
  7995. +void vc_cma_early_init(void)
  7996. +{
  7997. + LOG_DBG("vc_cma_early_init - vc_cma_chunks = %d", vc_cma_chunks);
  7998. + if (vc_cma_size) {
  7999. + int rc = platform_device_register(&vc_cma_device);
  8000. + LOG_DBG("platform_device_register -> %d", rc);
  8001. + }
  8002. +}
  8003. +
  8004. +void vc_cma_reserve(void)
  8005. +{
  8006. + /* if vc_cma_size is set, then declare vc CMA area of the same
  8007. + * size from the end of memory
  8008. + */
  8009. + if (vc_cma_size) {
  8010. + if (dma_declare_contiguous(NULL /*&vc_cma_device.dev*/, vc_cma_size,
  8011. + vc_cma_base, 0) == 0) {
  8012. + } else {
  8013. + LOG_ERR("vc_cma: dma_declare_contiguous(%x,%x) failed",
  8014. + vc_cma_size, (unsigned int)vc_cma_base);
  8015. + vc_cma_size = 0;
  8016. + }
  8017. + }
  8018. + vc_cma_chunks = vc_cma_size / VC_CMA_CHUNK_SIZE;
  8019. +}
  8020. +
  8021. +/****************************************************************************
  8022. +*
  8023. +* vc_cma_open
  8024. +*
  8025. +***************************************************************************/
  8026. +
  8027. +static int vc_cma_open(struct inode *inode, struct file *file)
  8028. +{
  8029. + (void)inode;
  8030. + (void)file;
  8031. +
  8032. + return 0;
  8033. +}
  8034. +
  8035. +/****************************************************************************
  8036. +*
  8037. +* vc_cma_release
  8038. +*
  8039. +***************************************************************************/
  8040. +
  8041. +static int vc_cma_release(struct inode *inode, struct file *file)
  8042. +{
  8043. + (void)inode;
  8044. + (void)file;
  8045. +
  8046. + vc_cma_set_reserve(0, current->tgid);
  8047. +
  8048. + return 0;
  8049. +}
  8050. +
  8051. +/****************************************************************************
  8052. +*
  8053. +* vc_cma_ioctl
  8054. +*
  8055. +***************************************************************************/
  8056. +
  8057. +static long vc_cma_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  8058. +{
  8059. + int rc = 0;
  8060. +
  8061. + (void)cmd;
  8062. + (void)arg;
  8063. +
  8064. + switch (cmd) {
  8065. + case VC_CMA_IOC_RESERVE:
  8066. + rc = vc_cma_set_reserve((unsigned int)arg, current->tgid);
  8067. + if (rc >= 0)
  8068. + rc = 0;
  8069. + break;
  8070. + default:
  8071. + LOG_ERR("vc-cma: Unknown ioctl %x", cmd);
  8072. + return -ENOTTY;
  8073. + }
  8074. +
  8075. + return rc;
  8076. +}
  8077. +
  8078. +/****************************************************************************
  8079. +*
  8080. +* File Operations for the driver.
  8081. +*
  8082. +***************************************************************************/
  8083. +
  8084. +static const struct file_operations vc_cma_fops = {
  8085. + .owner = THIS_MODULE,
  8086. + .open = vc_cma_open,
  8087. + .release = vc_cma_release,
  8088. + .unlocked_ioctl = vc_cma_ioctl,
  8089. +};
  8090. +
  8091. +/****************************************************************************
  8092. +*
  8093. +* vc_cma_proc_open
  8094. +*
  8095. +***************************************************************************/
  8096. +
  8097. +static int vc_cma_show_info(struct seq_file *m, void *v)
  8098. +{
  8099. + int i;
  8100. +
  8101. + seq_printf(m, "Videocore CMA:\n");
  8102. + seq_printf(m, " Base : %08x\n", (unsigned int)vc_cma_base);
  8103. + seq_printf(m, " Length : %08x\n", vc_cma_size);
  8104. + seq_printf(m, " Initial : %08x\n", vc_cma_initial);
  8105. + seq_printf(m, " Chunk size : %08x\n", VC_CMA_CHUNK_SIZE);
  8106. + seq_printf(m, " Chunks : %4d (%d bytes)\n",
  8107. + (int)vc_cma_chunks,
  8108. + (int)(vc_cma_chunks * VC_CMA_CHUNK_SIZE));
  8109. + seq_printf(m, " Used : %4d (%d bytes)\n",
  8110. + (int)vc_cma_chunks_used,
  8111. + (int)(vc_cma_chunks_used * VC_CMA_CHUNK_SIZE));
  8112. + seq_printf(m, " Reserved : %4d (%d bytes)\n",
  8113. + (unsigned int)vc_cma_chunks_reserved,
  8114. + (int)(vc_cma_chunks_reserved * VC_CMA_CHUNK_SIZE));
  8115. +
  8116. + for (i = 0; i < vc_cma_reserve_count; i++) {
  8117. + struct vc_cma_reserve_user *user = &vc_cma_reserve_users[i];
  8118. + seq_printf(m, " PID %5d: %d bytes\n", user->pid,
  8119. + user->reserve);
  8120. + }
  8121. +
  8122. + seq_printf(m, "\n");
  8123. +
  8124. + return 0;
  8125. +}
  8126. +
  8127. +static int vc_cma_proc_open(struct inode *inode, struct file *file)
  8128. +{
  8129. + return single_open(file, vc_cma_show_info, NULL);
  8130. +}
  8131. +
  8132. +/****************************************************************************
  8133. +*
  8134. +* vc_cma_proc_write
  8135. +*
  8136. +***************************************************************************/
  8137. +
  8138. +static int vc_cma_proc_write(struct file *file,
  8139. + const char __user *buffer,
  8140. + size_t size, loff_t *ppos)
  8141. +{
  8142. + int rc = -EFAULT;
  8143. + char input_str[20];
  8144. +
  8145. + memset(input_str, 0, sizeof(input_str));
  8146. +
  8147. + if (size > sizeof(input_str)) {
  8148. + LOG_ERR("%s: input string length too long", __func__);
  8149. + goto out;
  8150. + }
  8151. +
  8152. + if (copy_from_user(input_str, buffer, size - 1)) {
  8153. + LOG_ERR("%s: failed to get input string", __func__);
  8154. + goto out;
  8155. + }
  8156. +#define ALLOC_STR "alloc"
  8157. +#define FREE_STR "free"
  8158. +#define DEBUG_STR "debug"
  8159. +#define RESERVE_STR "reserve"
  8160. + if (strncmp(input_str, ALLOC_STR, strlen(ALLOC_STR)) == 0) {
  8161. + int size;
  8162. + char *p = input_str + strlen(ALLOC_STR);
  8163. +
  8164. + while (*p == ' ')
  8165. + p++;
  8166. + size = memparse(p, NULL);
  8167. + LOG_ERR("/proc/vc-cma: alloc %d", size);
  8168. + if (size)
  8169. + send_vc_msg(VC_CMA_MSG_REQUEST_FREE,
  8170. + size / VC_CMA_CHUNK_SIZE, 0);
  8171. + else
  8172. + LOG_ERR("invalid size '%s'", p);
  8173. + rc = size;
  8174. + } else if (strncmp(input_str, FREE_STR, strlen(FREE_STR)) == 0) {
  8175. + int size;
  8176. + char *p = input_str + strlen(FREE_STR);
  8177. +
  8178. + while (*p == ' ')
  8179. + p++;
  8180. + size = memparse(p, NULL);
  8181. + LOG_ERR("/proc/vc-cma: free %d", size);
  8182. + if (size)
  8183. + send_vc_msg(VC_CMA_MSG_REQUEST_ALLOC,
  8184. + size / VC_CMA_CHUNK_SIZE, 0);
  8185. + else
  8186. + LOG_ERR("invalid size '%s'", p);
  8187. + rc = size;
  8188. + } else if (strncmp(input_str, DEBUG_STR, strlen(DEBUG_STR)) == 0) {
  8189. + char *p = input_str + strlen(DEBUG_STR);
  8190. + while (*p == ' ')
  8191. + p++;
  8192. + if ((strcmp(p, "on") == 0) || (strcmp(p, "1") == 0))
  8193. + vc_cma_debug = 1;
  8194. + else if ((strcmp(p, "off") == 0) || (strcmp(p, "0") == 0))
  8195. + vc_cma_debug = 0;
  8196. + LOG_ERR("/proc/vc-cma: debug %s", vc_cma_debug ? "on" : "off");
  8197. + rc = size;
  8198. + } else if (strncmp(input_str, RESERVE_STR, strlen(RESERVE_STR)) == 0) {
  8199. + int size;
  8200. + int reserved;
  8201. + char *p = input_str + strlen(RESERVE_STR);
  8202. + while (*p == ' ')
  8203. + p++;
  8204. + size = memparse(p, NULL);
  8205. +
  8206. + reserved = vc_cma_set_reserve(size, current->tgid);
  8207. + rc = (reserved >= 0) ? size : reserved;
  8208. + }
  8209. +
  8210. +out:
  8211. + return rc;
  8212. +}
  8213. +
  8214. +/****************************************************************************
  8215. +*
  8216. +* File Operations for /proc interface.
  8217. +*
  8218. +***************************************************************************/
  8219. +
  8220. +static const struct file_operations vc_cma_proc_fops = {
  8221. + .open = vc_cma_proc_open,
  8222. + .read = seq_read,
  8223. + .write = vc_cma_proc_write,
  8224. + .llseek = seq_lseek,
  8225. + .release = single_release
  8226. +};
  8227. +
  8228. +static int vc_cma_set_reserve(unsigned int reserve, unsigned int pid)
  8229. +{
  8230. + struct vc_cma_reserve_user *user = NULL;
  8231. + int delta = 0;
  8232. + int i;
  8233. +
  8234. + if (down_interruptible(&vc_cma_reserve_mutex))
  8235. + return -ERESTARTSYS;
  8236. +
  8237. + for (i = 0; i < vc_cma_reserve_count; i++) {
  8238. + if (pid == vc_cma_reserve_users[i].pid) {
  8239. + user = &vc_cma_reserve_users[i];
  8240. + delta = reserve - user->reserve;
  8241. + if (reserve)
  8242. + user->reserve = reserve;
  8243. + else {
  8244. + /* Remove this entry by copying downwards */
  8245. + while ((i + 1) < vc_cma_reserve_count) {
  8246. + user[0].pid = user[1].pid;
  8247. + user[0].reserve = user[1].reserve;
  8248. + user++;
  8249. + i++;
  8250. + }
  8251. + vc_cma_reserve_count--;
  8252. + user = NULL;
  8253. + }
  8254. + break;
  8255. + }
  8256. + }
  8257. +
  8258. + if (reserve && !user) {
  8259. + if (vc_cma_reserve_count == VC_CMA_RESERVE_COUNT_MAX) {
  8260. + LOG_ERR("vc-cma: Too many reservations - "
  8261. + "increase CMA_RESERVE_COUNT_MAX");
  8262. + up(&vc_cma_reserve_mutex);
  8263. + return -EBUSY;
  8264. + }
  8265. + user = &vc_cma_reserve_users[vc_cma_reserve_count];
  8266. + user->pid = pid;
  8267. + user->reserve = reserve;
  8268. + delta = reserve;
  8269. + vc_cma_reserve_count++;
  8270. + }
  8271. +
  8272. + vc_cma_reserve_total += delta;
  8273. +
  8274. + send_vc_msg(VC_CMA_MSG_RESERVE,
  8275. + vc_cma_reserve_total & 0xffff, vc_cma_reserve_total >> 16);
  8276. +
  8277. + send_worker_msg((VCHIQ_HEADER_T *) VC_CMA_MSG_UPDATE_RESERVE);
  8278. +
  8279. + LOG_DBG("/proc/vc-cma: reserve %d (PID %d) - total %u",
  8280. + reserve, pid, vc_cma_reserve_total);
  8281. +
  8282. + up(&vc_cma_reserve_mutex);
  8283. +
  8284. + return vc_cma_reserve_total;
  8285. +}
  8286. +
  8287. +static VCHIQ_STATUS_T cma_service_callback(VCHIQ_REASON_T reason,
  8288. + VCHIQ_HEADER_T * header,
  8289. + VCHIQ_SERVICE_HANDLE_T service,
  8290. + void *bulk_userdata)
  8291. +{
  8292. + switch (reason) {
  8293. + case VCHIQ_MESSAGE_AVAILABLE:
  8294. + if (!send_worker_msg(header))
  8295. + return VCHIQ_RETRY;
  8296. + break;
  8297. + case VCHIQ_SERVICE_CLOSED:
  8298. + LOG_DBG("CMA service closed");
  8299. + break;
  8300. + default:
  8301. + LOG_ERR("Unexpected CMA callback reason %d", reason);
  8302. + break;
  8303. + }
  8304. + return VCHIQ_SUCCESS;
  8305. +}
  8306. +
  8307. +static void send_vc_msg(unsigned short type,
  8308. + unsigned short param1, unsigned short param2)
  8309. +{
  8310. + unsigned short msg[] = { type, param1, param2 };
  8311. + VCHIQ_ELEMENT_T elem = { &msg, sizeof(msg) };
  8312. + VCHIQ_STATUS_T ret;
  8313. + vchiq_use_service(cma_service);
  8314. + ret = vchiq_queue_message(cma_service, &elem, 1);
  8315. + vchiq_release_service(cma_service);
  8316. + if (ret != VCHIQ_SUCCESS)
  8317. + LOG_ERR("vchiq_queue_message returned %x", ret);
  8318. +}
  8319. +
  8320. +static bool send_worker_msg(VCHIQ_HEADER_T * msg)
  8321. +{
  8322. + if (down_interruptible(&vc_cma_worker_queue_push_mutex))
  8323. + return false;
  8324. + vchiu_queue_push(&cma_msg_queue, msg);
  8325. + up(&vc_cma_worker_queue_push_mutex);
  8326. + return true;
  8327. +}
  8328. +
  8329. +static int vc_cma_alloc_chunks(int num_chunks, struct cma_msg *reply)
  8330. +{
  8331. + int i;
  8332. + for (i = 0; i < num_chunks; i++) {
  8333. + struct page *chunk;
  8334. + unsigned int chunk_num;
  8335. + uint8_t *chunk_addr;
  8336. + size_t chunk_size = PAGES_PER_CHUNK << PAGE_SHIFT;
  8337. +
  8338. + chunk = dma_alloc_from_contiguous(NULL /*&vc_cma_device.dev*/,
  8339. + PAGES_PER_CHUNK,
  8340. + VC_CMA_CHUNK_ORDER);
  8341. + if (!chunk)
  8342. + break;
  8343. +
  8344. + chunk_addr = page_address(chunk);
  8345. + dmac_flush_range(chunk_addr, chunk_addr + chunk_size);
  8346. + outer_inv_range(__pa(chunk_addr), __pa(chunk_addr) +
  8347. + chunk_size);
  8348. +
  8349. + chunk_num =
  8350. + (page_to_phys(chunk) - vc_cma_base) / VC_CMA_CHUNK_SIZE;
  8351. + BUG_ON(((page_to_phys(chunk) - vc_cma_base) %
  8352. + VC_CMA_CHUNK_SIZE) != 0);
  8353. + if (chunk_num >= vc_cma_chunks) {
  8354. + LOG_ERR("%s: ===============================",
  8355. + __func__);
  8356. + LOG_ERR("%s: chunk phys %x, vc_cma %x-%x - "
  8357. + "bad SPARSEMEM configuration?",
  8358. + __func__, (unsigned int)page_to_phys(chunk),
  8359. + vc_cma_base, vc_cma_base + vc_cma_size - 1);
  8360. + LOG_ERR("%s: dev->cma_area = %p\n", __func__,
  8361. + (void*)0/*vc_cma_device.dev.cma_area*/);
  8362. + LOG_ERR("%s: ===============================",
  8363. + __func__);
  8364. + break;
  8365. + }
  8366. + reply->params[i] = chunk_num;
  8367. + vc_cma_chunks_used++;
  8368. + }
  8369. +
  8370. + if (i < num_chunks) {
  8371. + LOG_ERR("%s: dma_alloc_from_contiguous failed "
  8372. + "for %x bytes (alloc %d of %d, %d free)",
  8373. + __func__, VC_CMA_CHUNK_SIZE, i,
  8374. + num_chunks, vc_cma_chunks - vc_cma_chunks_used);
  8375. + num_chunks = i;
  8376. + }
  8377. +
  8378. + LOG_DBG("CMA allocated %d chunks -> %d used",
  8379. + num_chunks, vc_cma_chunks_used);
  8380. + reply->type = VC_CMA_MSG_ALLOCATED;
  8381. +
  8382. + {
  8383. + VCHIQ_ELEMENT_T elem = {
  8384. + reply,
  8385. + offsetof(struct cma_msg, params[0]) +
  8386. + num_chunks * sizeof(reply->params[0])
  8387. + };
  8388. + VCHIQ_STATUS_T ret;
  8389. + vchiq_use_service(cma_service);
  8390. + ret = vchiq_queue_message(cma_service, &elem, 1);
  8391. + vchiq_release_service(cma_service);
  8392. + if (ret != VCHIQ_SUCCESS)
  8393. + LOG_ERR("vchiq_queue_message return " "%x", ret);
  8394. + }
  8395. +
  8396. + return num_chunks;
  8397. +}
  8398. +
  8399. +static int cma_worker_proc(void *param)
  8400. +{
  8401. + static struct cma_msg reply;
  8402. + (void)param;
  8403. +
  8404. + while (1) {
  8405. + VCHIQ_HEADER_T *msg;
  8406. + static struct cma_msg msg_copy;
  8407. + struct cma_msg *cma_msg = &msg_copy;
  8408. + int type, msg_size;
  8409. +
  8410. + msg = vchiu_queue_pop(&cma_msg_queue);
  8411. + if ((unsigned int)msg >= VC_CMA_MSG_MAX) {
  8412. + msg_size = msg->size;
  8413. + memcpy(&msg_copy, msg->data, msg_size);
  8414. + type = cma_msg->type;
  8415. + vchiq_release_message(cma_service, msg);
  8416. + } else {
  8417. + msg_size = 0;
  8418. + type = (int)msg;
  8419. + if (type == VC_CMA_MSG_QUIT)
  8420. + break;
  8421. + else if (type == VC_CMA_MSG_UPDATE_RESERVE) {
  8422. + msg = NULL;
  8423. + cma_msg = NULL;
  8424. + } else {
  8425. + BUG();
  8426. + continue;
  8427. + }
  8428. + }
  8429. +
  8430. + switch (type) {
  8431. + case VC_CMA_MSG_ALLOC:{
  8432. + int num_chunks, free_chunks;
  8433. + num_chunks = cma_msg->params[0];
  8434. + free_chunks =
  8435. + vc_cma_chunks - vc_cma_chunks_used;
  8436. + LOG_DBG("CMA_MSG_ALLOC(%d chunks)", num_chunks);
  8437. + if (num_chunks > VC_CMA_MAX_PARAMS_PER_MSG) {
  8438. + LOG_ERR
  8439. + ("CMA_MSG_ALLOC - chunk count (%d) "
  8440. + "exceeds VC_CMA_MAX_PARAMS_PER_MSG (%d)",
  8441. + num_chunks,
  8442. + VC_CMA_MAX_PARAMS_PER_MSG);
  8443. + num_chunks = VC_CMA_MAX_PARAMS_PER_MSG;
  8444. + }
  8445. +
  8446. + if (num_chunks > free_chunks) {
  8447. + LOG_ERR
  8448. + ("CMA_MSG_ALLOC - chunk count (%d) "
  8449. + "exceeds free chunks (%d)",
  8450. + num_chunks, free_chunks);
  8451. + num_chunks = free_chunks;
  8452. + }
  8453. +
  8454. + vc_cma_alloc_chunks(num_chunks, &reply);
  8455. + }
  8456. + break;
  8457. +
  8458. + case VC_CMA_MSG_FREE:{
  8459. + int chunk_count =
  8460. + (msg_size -
  8461. + offsetof(struct cma_msg,
  8462. + params)) /
  8463. + sizeof(cma_msg->params[0]);
  8464. + int i;
  8465. + BUG_ON(chunk_count <= 0);
  8466. +
  8467. + LOG_DBG("CMA_MSG_FREE(%d chunks - %x, ...)",
  8468. + chunk_count, cma_msg->params[0]);
  8469. + for (i = 0; i < chunk_count; i++) {
  8470. + int chunk_num = cma_msg->params[i];
  8471. + struct page *page = vc_cma_base_page +
  8472. + chunk_num * PAGES_PER_CHUNK;
  8473. + if (chunk_num >= vc_cma_chunks) {
  8474. + LOG_ERR
  8475. + ("CMA_MSG_FREE - chunk %d of %d"
  8476. + " (value %x) exceeds maximum "
  8477. + "(%x)", i, chunk_count,
  8478. + chunk_num,
  8479. + vc_cma_chunks - 1);
  8480. + break;
  8481. + }
  8482. +
  8483. + if (!dma_release_from_contiguous
  8484. + (NULL /*&vc_cma_device.dev*/, page,
  8485. + PAGES_PER_CHUNK)) {
  8486. + LOG_ERR
  8487. + ("CMA_MSG_FREE - failed to "
  8488. + "release chunk %d (phys %x, "
  8489. + "page %x)", chunk_num,
  8490. + page_to_phys(page),
  8491. + (unsigned int)page);
  8492. + }
  8493. + vc_cma_chunks_used--;
  8494. + }
  8495. + LOG_DBG("CMA released %d chunks -> %d used",
  8496. + i, vc_cma_chunks_used);
  8497. + }
  8498. + break;
  8499. +
  8500. + case VC_CMA_MSG_UPDATE_RESERVE:{
  8501. + int chunks_needed =
  8502. + ((vc_cma_reserve_total + VC_CMA_CHUNK_SIZE -
  8503. + 1)
  8504. + / VC_CMA_CHUNK_SIZE) -
  8505. + vc_cma_chunks_reserved;
  8506. +
  8507. + LOG_DBG
  8508. + ("CMA_MSG_UPDATE_RESERVE(%d chunks needed)",
  8509. + chunks_needed);
  8510. +
  8511. + /* Cap the reservations to what is available */
  8512. + if (chunks_needed > 0) {
  8513. + if (chunks_needed >
  8514. + (vc_cma_chunks -
  8515. + vc_cma_chunks_used))
  8516. + chunks_needed =
  8517. + (vc_cma_chunks -
  8518. + vc_cma_chunks_used);
  8519. +
  8520. + chunks_needed =
  8521. + vc_cma_alloc_chunks(chunks_needed,
  8522. + &reply);
  8523. + }
  8524. +
  8525. + LOG_DBG
  8526. + ("CMA_MSG_UPDATE_RESERVE(%d chunks allocated)",
  8527. + chunks_needed);
  8528. + vc_cma_chunks_reserved += chunks_needed;
  8529. + }
  8530. + break;
  8531. +
  8532. + default:
  8533. + LOG_ERR("unexpected msg type %d", type);
  8534. + break;
  8535. + }
  8536. + }
  8537. +
  8538. + LOG_DBG("quitting...");
  8539. + return 0;
  8540. +}
  8541. +
  8542. +/****************************************************************************
  8543. +*
  8544. +* vc_cma_connected_init
  8545. +*
  8546. +* This function is called once the videocore has been connected.
  8547. +*
  8548. +***************************************************************************/
  8549. +
  8550. +static void vc_cma_connected_init(void)
  8551. +{
  8552. + VCHIQ_SERVICE_PARAMS_T service_params;
  8553. +
  8554. + LOG_DBG("vc_cma_connected_init");
  8555. +
  8556. + if (!vchiu_queue_init(&cma_msg_queue, 16)) {
  8557. + LOG_ERR("could not create CMA msg queue");
  8558. + goto fail_queue;
  8559. + }
  8560. +
  8561. + if (vchiq_initialise(&cma_instance) != VCHIQ_SUCCESS)
  8562. + goto fail_vchiq_init;
  8563. +
  8564. + vchiq_connect(cma_instance);
  8565. +
  8566. + service_params.fourcc = VC_CMA_FOURCC;
  8567. + service_params.callback = cma_service_callback;
  8568. + service_params.userdata = NULL;
  8569. + service_params.version = VC_CMA_VERSION;
  8570. + service_params.version_min = VC_CMA_VERSION;
  8571. +
  8572. + if (vchiq_open_service(cma_instance, &service_params,
  8573. + &cma_service) != VCHIQ_SUCCESS) {
  8574. + LOG_ERR("failed to open service - already in use?");
  8575. + goto fail_vchiq_open;
  8576. + }
  8577. +
  8578. + vchiq_release_service(cma_service);
  8579. +
  8580. + cma_worker = kthread_create(cma_worker_proc, NULL, "cma_worker");
  8581. + if (!cma_worker) {
  8582. + LOG_ERR("could not create CMA worker thread");
  8583. + goto fail_worker;
  8584. + }
  8585. + set_user_nice(cma_worker, -20);
  8586. + wake_up_process(cma_worker);
  8587. +
  8588. + return;
  8589. +
  8590. +fail_worker:
  8591. + vchiq_close_service(cma_service);
  8592. +fail_vchiq_open:
  8593. + vchiq_shutdown(cma_instance);
  8594. +fail_vchiq_init:
  8595. + vchiu_queue_delete(&cma_msg_queue);
  8596. +fail_queue:
  8597. + return;
  8598. +}
  8599. +
  8600. +void
  8601. +loud_error_header(void)
  8602. +{
  8603. + if (in_loud_error)
  8604. + return;
  8605. +
  8606. + LOG_ERR("============================================================"
  8607. + "================");
  8608. + LOG_ERR("============================================================"
  8609. + "================");
  8610. + LOG_ERR("=====");
  8611. +
  8612. + in_loud_error = 1;
  8613. +}
  8614. +
  8615. +void
  8616. +loud_error_footer(void)
  8617. +{
  8618. + if (!in_loud_error)
  8619. + return;
  8620. +
  8621. + LOG_ERR("=====");
  8622. + LOG_ERR("============================================================"
  8623. + "================");
  8624. + LOG_ERR("============================================================"
  8625. + "================");
  8626. +
  8627. + in_loud_error = 0;
  8628. +}
  8629. +
  8630. +#if 1
  8631. +static int check_cma_config(void) { return 1; }
  8632. +#else
  8633. +static int
  8634. +read_vc_debug_var(VC_MEM_ACCESS_HANDLE_T handle,
  8635. + const char *symbol,
  8636. + void *buf, size_t bufsize)
  8637. +{
  8638. + VC_MEM_ADDR_T vcMemAddr;
  8639. + size_t vcMemSize;
  8640. + uint8_t *mapAddr;
  8641. + off_t vcMapAddr;
  8642. +
  8643. + if (!LookupVideoCoreSymbol(handle, symbol,
  8644. + &vcMemAddr,
  8645. + &vcMemSize)) {
  8646. + loud_error_header();
  8647. + loud_error(
  8648. + "failed to find VC symbol \"%s\".",
  8649. + symbol);
  8650. + loud_error_footer();
  8651. + return 0;
  8652. + }
  8653. +
  8654. + if (vcMemSize != bufsize) {
  8655. + loud_error_header();
  8656. + loud_error(
  8657. + "VC symbol \"%s\" is the wrong size.",
  8658. + symbol);
  8659. + loud_error_footer();
  8660. + return 0;
  8661. + }
  8662. +
  8663. + vcMapAddr = (off_t)vcMemAddr & VC_MEM_TO_ARM_ADDR_MASK;
  8664. + vcMapAddr += mm_vc_mem_phys_addr;
  8665. + mapAddr = ioremap_nocache(vcMapAddr, vcMemSize);
  8666. + if (mapAddr == 0) {
  8667. + loud_error_header();
  8668. + loud_error(
  8669. + "failed to ioremap \"%s\" @ 0x%x "
  8670. + "(phys: 0x%x, size: %u).",
  8671. + symbol,
  8672. + (unsigned int)vcMapAddr,
  8673. + (unsigned int)vcMemAddr,
  8674. + (unsigned int)vcMemSize);
  8675. + loud_error_footer();
  8676. + return 0;
  8677. + }
  8678. +
  8679. + memcpy(buf, mapAddr, bufsize);
  8680. + iounmap(mapAddr);
  8681. +
  8682. + return 1;
  8683. +}
  8684. +
  8685. +
  8686. +static int
  8687. +check_cma_config(void)
  8688. +{
  8689. + VC_MEM_ACCESS_HANDLE_T mem_hndl;
  8690. + VC_MEM_ADDR_T mempool_start;
  8691. + VC_MEM_ADDR_T mempool_end;
  8692. + VC_MEM_ADDR_T mempool_offline_start;
  8693. + VC_MEM_ADDR_T mempool_offline_end;
  8694. + VC_MEM_ADDR_T cam_alloc_base;
  8695. + VC_MEM_ADDR_T cam_alloc_size;
  8696. + VC_MEM_ADDR_T cam_alloc_end;
  8697. + int success = 0;
  8698. +
  8699. + if (OpenVideoCoreMemory(&mem_hndl) != 0)
  8700. + goto out;
  8701. +
  8702. + /* Read the relevant VideoCore variables */
  8703. + if (!read_vc_debug_var(mem_hndl, "__MEMPOOL_START",
  8704. + &mempool_start,
  8705. + sizeof(mempool_start)))
  8706. + goto close;
  8707. +
  8708. + if (!read_vc_debug_var(mem_hndl, "__MEMPOOL_END",
  8709. + &mempool_end,
  8710. + sizeof(mempool_end)))
  8711. + goto close;
  8712. +
  8713. + if (!read_vc_debug_var(mem_hndl, "__MEMPOOL_OFFLINE_START",
  8714. + &mempool_offline_start,
  8715. + sizeof(mempool_offline_start)))
  8716. + goto close;
  8717. +
  8718. + if (!read_vc_debug_var(mem_hndl, "__MEMPOOL_OFFLINE_END",
  8719. + &mempool_offline_end,
  8720. + sizeof(mempool_offline_end)))
  8721. + goto close;
  8722. +
  8723. + if (!read_vc_debug_var(mem_hndl, "cam_alloc_base",
  8724. + &cam_alloc_base,
  8725. + sizeof(cam_alloc_base)))
  8726. + goto close;
  8727. +
  8728. + if (!read_vc_debug_var(mem_hndl, "cam_alloc_size",
  8729. + &cam_alloc_size,
  8730. + sizeof(cam_alloc_size)))
  8731. + goto close;
  8732. +
  8733. + cam_alloc_end = cam_alloc_base + cam_alloc_size;
  8734. +
  8735. + success = 1;
  8736. +
  8737. + /* Now the sanity checks */
  8738. + if (!mempool_offline_start)
  8739. + mempool_offline_start = mempool_start;
  8740. + if (!mempool_offline_end)
  8741. + mempool_offline_end = mempool_end;
  8742. +
  8743. + if (VCADDR_TO_PHYSADDR(mempool_offline_start) != vc_cma_base) {
  8744. + loud_error_header();
  8745. + loud_error(
  8746. + "__MEMPOOL_OFFLINE_START(%x -> %lx) doesn't match "
  8747. + "vc_cma_base(%x)",
  8748. + mempool_offline_start,
  8749. + VCADDR_TO_PHYSADDR(mempool_offline_start),
  8750. + vc_cma_base);
  8751. + success = 0;
  8752. + }
  8753. +
  8754. + if (VCADDR_TO_PHYSADDR(mempool_offline_end) !=
  8755. + (vc_cma_base + vc_cma_size)) {
  8756. + loud_error_header();
  8757. + loud_error(
  8758. + "__MEMPOOL_OFFLINE_END(%x -> %lx) doesn't match "
  8759. + "vc_cma_base(%x) + vc_cma_size(%x) = %x",
  8760. + mempool_offline_start,
  8761. + VCADDR_TO_PHYSADDR(mempool_offline_end),
  8762. + vc_cma_base, vc_cma_size, vc_cma_base + vc_cma_size);
  8763. + success = 0;
  8764. + }
  8765. +
  8766. + if (mempool_end < mempool_start) {
  8767. + loud_error_header();
  8768. + loud_error(
  8769. + "__MEMPOOL_END(%x) must not be before "
  8770. + "__MEMPOOL_START(%x)",
  8771. + mempool_end,
  8772. + mempool_start);
  8773. + success = 0;
  8774. + }
  8775. +
  8776. + if (mempool_offline_end < mempool_offline_start) {
  8777. + loud_error_header();
  8778. + loud_error(
  8779. + "__MEMPOOL_OFFLINE_END(%x) must not be before "
  8780. + "__MEMPOOL_OFFLINE_START(%x)",
  8781. + mempool_offline_end,
  8782. + mempool_offline_start);
  8783. + success = 0;
  8784. + }
  8785. +
  8786. + if (mempool_offline_start < mempool_start) {
  8787. + loud_error_header();
  8788. + loud_error(
  8789. + "__MEMPOOL_OFFLINE_START(%x) must not be before "
  8790. + "__MEMPOOL_START(%x)",
  8791. + mempool_offline_start,
  8792. + mempool_start);
  8793. + success = 0;
  8794. + }
  8795. +
  8796. + if (mempool_offline_end > mempool_end) {
  8797. + loud_error_header();
  8798. + loud_error(
  8799. + "__MEMPOOL_OFFLINE_END(%x) must not be after "
  8800. + "__MEMPOOL_END(%x)",
  8801. + mempool_offline_end,
  8802. + mempool_end);
  8803. + success = 0;
  8804. + }
  8805. +
  8806. + if ((cam_alloc_base < mempool_end) &&
  8807. + (cam_alloc_end > mempool_start)) {
  8808. + loud_error_header();
  8809. + loud_error(
  8810. + "cam_alloc pool(%x-%x) overlaps "
  8811. + "mempool(%x-%x)",
  8812. + cam_alloc_base, cam_alloc_end,
  8813. + mempool_start, mempool_end);
  8814. + success = 0;
  8815. + }
  8816. +
  8817. + loud_error_footer();
  8818. +
  8819. +close:
  8820. + CloseVideoCoreMemory(mem_hndl);
  8821. +
  8822. +out:
  8823. + return success;
  8824. +}
  8825. +#endif
  8826. +
  8827. +static int vc_cma_init(void)
  8828. +{
  8829. + int rc = -EFAULT;
  8830. + struct device *dev;
  8831. +
  8832. + if (!check_cma_config())
  8833. + goto out_release;
  8834. +
  8835. + printk(KERN_INFO "vc-cma: Videocore CMA driver\n");
  8836. + printk(KERN_INFO "vc-cma: vc_cma_base = 0x%08x\n", vc_cma_base);
  8837. + printk(KERN_INFO "vc-cma: vc_cma_size = 0x%08x (%u MiB)\n",
  8838. + vc_cma_size, vc_cma_size / (1024 * 1024));
  8839. + printk(KERN_INFO "vc-cma: vc_cma_initial = 0x%08x (%u MiB)\n",
  8840. + vc_cma_initial, vc_cma_initial / (1024 * 1024));
  8841. +
  8842. + vc_cma_base_page = phys_to_page(vc_cma_base);
  8843. +
  8844. + if (vc_cma_chunks) {
  8845. + int chunks_needed = vc_cma_initial / VC_CMA_CHUNK_SIZE;
  8846. +
  8847. + for (vc_cma_chunks_used = 0;
  8848. + vc_cma_chunks_used < chunks_needed; vc_cma_chunks_used++) {
  8849. + struct page *chunk;
  8850. + chunk = dma_alloc_from_contiguous(NULL /*&vc_cma_device.dev*/,
  8851. + PAGES_PER_CHUNK,
  8852. + VC_CMA_CHUNK_ORDER);
  8853. + if (!chunk)
  8854. + break;
  8855. + BUG_ON(((page_to_phys(chunk) - vc_cma_base) %
  8856. + VC_CMA_CHUNK_SIZE) != 0);
  8857. + }
  8858. + if (vc_cma_chunks_used != chunks_needed) {
  8859. + LOG_ERR("%s: dma_alloc_from_contiguous failed (%d "
  8860. + "bytes, allocation %d of %d)",
  8861. + __func__, VC_CMA_CHUNK_SIZE,
  8862. + vc_cma_chunks_used, chunks_needed);
  8863. + goto out_release;
  8864. + }
  8865. +
  8866. + vchiq_add_connected_callback(vc_cma_connected_init);
  8867. + }
  8868. +
  8869. + rc = alloc_chrdev_region(&vc_cma_devnum, 0, 1, DRIVER_NAME);
  8870. + if (rc < 0) {
  8871. + LOG_ERR("%s: alloc_chrdev_region failed (rc=%d)", __func__, rc);
  8872. + goto out_release;
  8873. + }
  8874. +
  8875. + cdev_init(&vc_cma_cdev, &vc_cma_fops);
  8876. + rc = cdev_add(&vc_cma_cdev, vc_cma_devnum, 1);
  8877. + if (rc != 0) {
  8878. + LOG_ERR("%s: cdev_add failed (rc=%d)", __func__, rc);
  8879. + goto out_unregister;
  8880. + }
  8881. +
  8882. + vc_cma_class = class_create(THIS_MODULE, DRIVER_NAME);
  8883. + if (IS_ERR(vc_cma_class)) {
  8884. + rc = PTR_ERR(vc_cma_class);
  8885. + LOG_ERR("%s: class_create failed (rc=%d)", __func__, rc);
  8886. + goto out_cdev_del;
  8887. + }
  8888. +
  8889. + dev = device_create(vc_cma_class, NULL, vc_cma_devnum, NULL,
  8890. + DRIVER_NAME);
  8891. + if (IS_ERR(dev)) {
  8892. + rc = PTR_ERR(dev);
  8893. + LOG_ERR("%s: device_create failed (rc=%d)", __func__, rc);
  8894. + goto out_class_destroy;
  8895. + }
  8896. +
  8897. + vc_cma_proc_entry = proc_create(DRIVER_NAME, 0444, NULL, &vc_cma_proc_fops);
  8898. + if (vc_cma_proc_entry == NULL) {
  8899. + rc = -EFAULT;
  8900. + LOG_ERR("%s: proc_create failed", __func__);
  8901. + goto out_device_destroy;
  8902. + }
  8903. +
  8904. + vc_cma_inited = 1;
  8905. + return 0;
  8906. +
  8907. +out_device_destroy:
  8908. + device_destroy(vc_cma_class, vc_cma_devnum);
  8909. +
  8910. +out_class_destroy:
  8911. + class_destroy(vc_cma_class);
  8912. + vc_cma_class = NULL;
  8913. +
  8914. +out_cdev_del:
  8915. + cdev_del(&vc_cma_cdev);
  8916. +
  8917. +out_unregister:
  8918. + unregister_chrdev_region(vc_cma_devnum, 1);
  8919. +
  8920. +out_release:
  8921. + /* It is tempting to try to clean up by calling
  8922. + dma_release_from_contiguous for all allocated chunks, but it isn't
  8923. + a very safe thing to do. If vc_cma_initial is non-zero it is because
  8924. + VideoCore is already using that memory, so giving it back to Linux
  8925. + is likely to be fatal.
  8926. + */
  8927. + return -1;
  8928. +}
  8929. +
  8930. +/****************************************************************************
  8931. +*
  8932. +* vc_cma_exit
  8933. +*
  8934. +***************************************************************************/
  8935. +
  8936. +static void __exit vc_cma_exit(void)
  8937. +{
  8938. + LOG_DBG("%s: called", __func__);
  8939. +
  8940. + if (vc_cma_inited) {
  8941. + remove_proc_entry(DRIVER_NAME, NULL);
  8942. + device_destroy(vc_cma_class, vc_cma_devnum);
  8943. + class_destroy(vc_cma_class);
  8944. + cdev_del(&vc_cma_cdev);
  8945. + unregister_chrdev_region(vc_cma_devnum, 1);
  8946. + }
  8947. +}
  8948. +
  8949. +module_init(vc_cma_init);
  8950. +module_exit(vc_cma_exit);
  8951. +MODULE_LICENSE("GPL");
  8952. +MODULE_AUTHOR("Broadcom Corporation");
  8953. diff -Nur linux-3.13.11/drivers/char/hw_random/bcm2708-rng.c linux-rpi/drivers/char/hw_random/bcm2708-rng.c
  8954. --- linux-3.13.11/drivers/char/hw_random/bcm2708-rng.c 1970-01-01 01:00:00.000000000 +0100
  8955. +++ linux-rpi/drivers/char/hw_random/bcm2708-rng.c 2014-04-24 15:35:02.101542691 +0200
  8956. @@ -0,0 +1,117 @@
  8957. +/**
  8958. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  8959. + *
  8960. + * Redistribution and use in source and binary forms, with or without
  8961. + * modification, are permitted provided that the following conditions
  8962. + * are met:
  8963. + * 1. Redistributions of source code must retain the above copyright
  8964. + * notice, this list of conditions, and the following disclaimer,
  8965. + * without modification.
  8966. + * 2. Redistributions in binary form must reproduce the above copyright
  8967. + * notice, this list of conditions and the following disclaimer in the
  8968. + * documentation and/or other materials provided with the distribution.
  8969. + * 3. The names of the above-listed copyright holders may not be used
  8970. + * to endorse or promote products derived from this software without
  8971. + * specific prior written permission.
  8972. + *
  8973. + * ALTERNATIVELY, this software may be distributed under the terms of the
  8974. + * GNU General Public License ("GPL") version 2, as published by the Free
  8975. + * Software Foundation.
  8976. + *
  8977. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  8978. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  8979. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  8980. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  8981. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  8982. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  8983. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  8984. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  8985. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  8986. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  8987. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  8988. + */
  8989. +
  8990. +#include <linux/kernel.h>
  8991. +#include <linux/module.h>
  8992. +#include <linux/init.h>
  8993. +#include <linux/hw_random.h>
  8994. +#include <linux/printk.h>
  8995. +
  8996. +#include <asm/io.h>
  8997. +#include <mach/hardware.h>
  8998. +#include <mach/platform.h>
  8999. +
  9000. +#define RNG_CTRL (0x0)
  9001. +#define RNG_STATUS (0x4)
  9002. +#define RNG_DATA (0x8)
  9003. +#define RNG_FF_THRESHOLD (0xc)
  9004. +
  9005. +/* enable rng */
  9006. +#define RNG_RBGEN 0x1
  9007. +/* double speed, less random mode */
  9008. +#define RNG_RBG2X 0x2
  9009. +
  9010. +/* the initial numbers generated are "less random" so will be discarded */
  9011. +#define RNG_WARMUP_COUNT 0x40000
  9012. +
  9013. +static int bcm2708_rng_data_read(struct hwrng *rng, u32 *buffer)
  9014. +{
  9015. + void __iomem *rng_base = (void __iomem *)rng->priv;
  9016. + unsigned words;
  9017. + /* wait for a random number to be in fifo */
  9018. + do {
  9019. + words = __raw_readl(rng_base + RNG_STATUS)>>24;
  9020. + }
  9021. + while (words == 0);
  9022. + /* read the random number */
  9023. + *buffer = __raw_readl(rng_base + RNG_DATA);
  9024. + return 4;
  9025. +}
  9026. +
  9027. +static struct hwrng bcm2708_rng_ops = {
  9028. + .name = "bcm2708",
  9029. + .data_read = bcm2708_rng_data_read,
  9030. +};
  9031. +
  9032. +static int __init bcm2708_rng_init(void)
  9033. +{
  9034. + void __iomem *rng_base;
  9035. + int err;
  9036. +
  9037. + /* map peripheral */
  9038. + rng_base = ioremap(RNG_BASE, 0x10);
  9039. + pr_info("bcm2708_rng_init=%p\n", rng_base);
  9040. + if (!rng_base) {
  9041. + pr_err("bcm2708_rng_init failed to ioremap\n");
  9042. + return -ENOMEM;
  9043. + }
  9044. + bcm2708_rng_ops.priv = (unsigned long)rng_base;
  9045. + /* register driver */
  9046. + err = hwrng_register(&bcm2708_rng_ops);
  9047. + if (err) {
  9048. + pr_err("bcm2708_rng_init hwrng_register()=%d\n", err);
  9049. + iounmap(rng_base);
  9050. + } else {
  9051. + /* set warm-up count & enable */
  9052. + __raw_writel(RNG_WARMUP_COUNT, rng_base + RNG_STATUS);
  9053. + __raw_writel(RNG_RBGEN, rng_base + RNG_CTRL);
  9054. + }
  9055. + return err;
  9056. +}
  9057. +
  9058. +static void __exit bcm2708_rng_exit(void)
  9059. +{
  9060. + void __iomem *rng_base = (void __iomem *)bcm2708_rng_ops.priv;
  9061. + pr_info("bcm2708_rng_exit\n");
  9062. + /* disable rng hardware */
  9063. + __raw_writel(0, rng_base + RNG_CTRL);
  9064. + /* unregister driver */
  9065. + hwrng_unregister(&bcm2708_rng_ops);
  9066. + iounmap(rng_base);
  9067. +}
  9068. +
  9069. +module_init(bcm2708_rng_init);
  9070. +module_exit(bcm2708_rng_exit);
  9071. +
  9072. +MODULE_DESCRIPTION("BCM2708 H/W Random Number Generator (RNG) driver");
  9073. +MODULE_LICENSE("GPL and additional rights");
  9074. diff -Nur linux-3.13.11/drivers/char/hw_random/Kconfig linux-rpi/drivers/char/hw_random/Kconfig
  9075. --- linux-3.13.11/drivers/char/hw_random/Kconfig 2014-04-23 01:49:33.000000000 +0200
  9076. +++ linux-rpi/drivers/char/hw_random/Kconfig 2014-04-24 15:36:45.506686052 +0200
  9077. @@ -341,6 +341,17 @@
  9078. If unsure, say Y.
  9079. +config HW_RANDOM_BCM2708
  9080. + tristate "BCM2708 generic true random number generator support"
  9081. + depends on HW_RANDOM && ARCH_BCM2708
  9082. + ---help---
  9083. + This driver provides the kernel-side support for the BCM2708 hardware.
  9084. +
  9085. + To compile this driver as a module, choose M here: the
  9086. + module will be called bcm2708-rng.
  9087. +
  9088. + If unsure, say N.
  9089. +
  9090. config HW_RANDOM_MSM
  9091. tristate "Qualcomm MSM Random Number Generator support"
  9092. depends on HW_RANDOM && ARCH_MSM
  9093. diff -Nur linux-3.13.11/drivers/char/hw_random/Makefile linux-rpi/drivers/char/hw_random/Makefile
  9094. --- linux-3.13.11/drivers/char/hw_random/Makefile 2014-04-23 01:49:33.000000000 +0200
  9095. +++ linux-rpi/drivers/char/hw_random/Makefile 2014-04-24 15:36:45.506686052 +0200
  9096. @@ -29,4 +29,5 @@
  9097. obj-$(CONFIG_HW_RANDOM_EXYNOS) += exynos-rng.o
  9098. obj-$(CONFIG_HW_RANDOM_TPM) += tpm-rng.o
  9099. obj-$(CONFIG_HW_RANDOM_BCM2835) += bcm2835-rng.o
  9100. +obj-$(CONFIG_HW_RANDOM_BCM2708) += bcm2708-rng.o
  9101. obj-$(CONFIG_HW_RANDOM_MSM) += msm-rng.o
  9102. diff -Nur linux-3.13.11/drivers/char/ipmi/ipmi_bt_sm.c linux-rpi/drivers/char/ipmi/ipmi_bt_sm.c
  9103. --- linux-3.13.11/drivers/char/ipmi/ipmi_bt_sm.c 2014-04-23 01:49:33.000000000 +0200
  9104. +++ linux-rpi/drivers/char/ipmi/ipmi_bt_sm.c 2014-04-24 15:35:02.105542736 +0200
  9105. @@ -352,7 +352,7 @@
  9106. static inline int read_all_bytes(struct si_sm_data *bt)
  9107. {
  9108. - unsigned int i;
  9109. + unsigned char i;
  9110. /*
  9111. * length is "framing info", minimum = 4: NetFn, Seq, Cmd, cCode.
  9112. diff -Nur linux-3.13.11/drivers/char/Kconfig linux-rpi/drivers/char/Kconfig
  9113. --- linux-3.13.11/drivers/char/Kconfig 2014-04-23 01:49:33.000000000 +0200
  9114. +++ linux-rpi/drivers/char/Kconfig 2014-04-24 15:36:45.506686052 +0200
  9115. @@ -580,6 +580,8 @@
  9116. source "drivers/s390/char/Kconfig"
  9117. +source "drivers/char/broadcom/Kconfig"
  9118. +
  9119. config MSM_SMD_PKT
  9120. bool "Enable device interface for some SMD packet ports"
  9121. default n
  9122. diff -Nur linux-3.13.11/drivers/char/Makefile linux-rpi/drivers/char/Makefile
  9123. --- linux-3.13.11/drivers/char/Makefile 2014-04-23 01:49:33.000000000 +0200
  9124. +++ linux-rpi/drivers/char/Makefile 2014-04-24 15:36:45.506686052 +0200
  9125. @@ -62,3 +62,5 @@
  9126. js-rtc-y = rtc.o
  9127. obj-$(CONFIG_TILE_SROM) += tile-srom.o
  9128. +
  9129. +obj-$(CONFIG_BRCM_CHAR_DRIVERS) += broadcom/
  9130. diff -Nur linux-3.13.11/drivers/cpufreq/bcm2835-cpufreq.c linux-rpi/drivers/cpufreq/bcm2835-cpufreq.c
  9131. --- linux-3.13.11/drivers/cpufreq/bcm2835-cpufreq.c 1970-01-01 01:00:00.000000000 +0100
  9132. +++ linux-rpi/drivers/cpufreq/bcm2835-cpufreq.c 2014-04-24 15:36:46.506697023 +0200
  9133. @@ -0,0 +1,239 @@
  9134. +/*****************************************************************************
  9135. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  9136. +*
  9137. +* Unless you and Broadcom execute a separate written software license
  9138. +* agreement governing use of this software, this software is licensed to you
  9139. +* under the terms of the GNU General Public License version 2, available at
  9140. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  9141. +*
  9142. +* Notwithstanding the above, under no circumstances may you combine this
  9143. +* software in any way with any other Broadcom software provided under a
  9144. +* license other than the GPL, without Broadcom's express prior written
  9145. +* consent.
  9146. +*****************************************************************************/
  9147. +
  9148. +/*****************************************************************************
  9149. +* FILENAME: bcm2835-cpufreq.h
  9150. +* DESCRIPTION: This driver dynamically manages the CPU Frequency of the ARM
  9151. +* processor. Messages are sent to Videocore either setting or requesting the
  9152. +* frequency of the ARM in order to match an appropiate frequency to the current
  9153. +* usage of the processor. The policy which selects the frequency to use is
  9154. +* defined in the kernel .config file, but can be changed during runtime.
  9155. +*****************************************************************************/
  9156. +
  9157. +/* ---------- INCLUDES ---------- */
  9158. +#include <linux/kernel.h>
  9159. +#include <linux/init.h>
  9160. +#include <linux/module.h>
  9161. +#include <linux/cpufreq.h>
  9162. +#include <mach/vcio.h>
  9163. +
  9164. +/* ---------- DEFINES ---------- */
  9165. +/*#define CPUFREQ_DEBUG_ENABLE*/ /* enable debugging */
  9166. +#define MODULE_NAME "bcm2835-cpufreq"
  9167. +
  9168. +#define VCMSG_ID_ARM_CLOCK 0x000000003 /* Clock/Voltage ID's */
  9169. +
  9170. +/* debug printk macros */
  9171. +#ifdef CPUFREQ_DEBUG_ENABLE
  9172. +#define print_debug(fmt,...) pr_debug("%s:%s:%d: "fmt, MODULE_NAME, __func__, __LINE__, ##__VA_ARGS__)
  9173. +#else
  9174. +#define print_debug(fmt,...)
  9175. +#endif
  9176. +#define print_err(fmt,...) pr_err("%s:%s:%d: "fmt, MODULE_NAME, __func__,__LINE__, ##__VA_ARGS__)
  9177. +#define print_info(fmt,...) pr_info("%s: "fmt, MODULE_NAME, ##__VA_ARGS__)
  9178. +
  9179. +/* tag part of the message */
  9180. +struct vc_msg_tag {
  9181. + uint32_t tag_id; /* the message id */
  9182. + uint32_t buffer_size; /* size of the buffer (which in this case is always 8 bytes) */
  9183. + uint32_t data_size; /* amount of data being sent or received */
  9184. + uint32_t dev_id; /* the ID of the clock/voltage to get or set */
  9185. + uint32_t val; /* the value (e.g. rate (in Hz)) to set */
  9186. +};
  9187. +
  9188. +/* message structure to be sent to videocore */
  9189. +struct vc_msg {
  9190. + uint32_t msg_size; /* simply, sizeof(struct vc_msg) */
  9191. + uint32_t request_code; /* holds various information like the success and number of bytes returned (refer to mailboxes wiki) */
  9192. + struct vc_msg_tag tag; /* the tag structure above to make */
  9193. + uint32_t end_tag; /* an end identifier, should be set to NULL */
  9194. +};
  9195. +
  9196. +/* ---------- GLOBALS ---------- */
  9197. +static struct cpufreq_driver bcm2835_cpufreq_driver; /* the cpufreq driver global */
  9198. +
  9199. +/*
  9200. + ===============================================
  9201. + clk_rate either gets or sets the clock rates.
  9202. + ===============================================
  9203. +*/
  9204. +static uint32_t bcm2835_cpufreq_set_clock(int cur_rate, int arm_rate)
  9205. +{
  9206. + int s, actual_rate=0;
  9207. + struct vc_msg msg;
  9208. +
  9209. + /* wipe all previous message data */
  9210. + memset(&msg, 0, sizeof msg);
  9211. +
  9212. + msg.msg_size = sizeof msg;
  9213. +
  9214. + msg.tag.tag_id = VCMSG_SET_CLOCK_RATE;
  9215. + msg.tag.buffer_size = 8;
  9216. + msg.tag.data_size = 8; /* we're sending the clock ID and the new rates which is a total of 2 words */
  9217. + msg.tag.dev_id = VCMSG_ID_ARM_CLOCK;
  9218. + msg.tag.val = arm_rate * 1000;
  9219. +
  9220. + /* send the message */
  9221. + s = bcm_mailbox_property(&msg, sizeof msg);
  9222. +
  9223. + /* check if it was all ok and return the rate in KHz */
  9224. + if (s == 0 && (msg.request_code & 0x80000000))
  9225. + actual_rate = msg.tag.val/1000;
  9226. +
  9227. + print_debug("Setting new frequency = %d -> %d (actual %d)\n", cur_rate, arm_rate, actual_rate);
  9228. + return actual_rate;
  9229. +}
  9230. +
  9231. +static uint32_t bcm2835_cpufreq_get_clock(int tag)
  9232. +{
  9233. + int s;
  9234. + int arm_rate = 0;
  9235. + struct vc_msg msg;
  9236. +
  9237. + /* wipe all previous message data */
  9238. + memset(&msg, 0, sizeof msg);
  9239. +
  9240. + msg.msg_size = sizeof msg;
  9241. + msg.tag.tag_id = tag;
  9242. + msg.tag.buffer_size = 8;
  9243. + msg.tag.data_size = 4; /* we're just sending the clock ID which is one word long */
  9244. + msg.tag.dev_id = VCMSG_ID_ARM_CLOCK;
  9245. +
  9246. + /* send the message */
  9247. + s = bcm_mailbox_property(&msg, sizeof msg);
  9248. +
  9249. + /* check if it was all ok and return the rate in KHz */
  9250. + if (s == 0 && (msg.request_code & 0x80000000))
  9251. + arm_rate = msg.tag.val/1000;
  9252. +
  9253. + print_debug("%s frequency = %d\n",
  9254. + tag == VCMSG_GET_CLOCK_RATE ? "Current":
  9255. + tag == VCMSG_GET_MIN_CLOCK ? "Min":
  9256. + tag == VCMSG_GET_MAX_CLOCK ? "Max":
  9257. + "Unexpected", arm_rate);
  9258. +
  9259. + return arm_rate;
  9260. +}
  9261. +
  9262. +/*
  9263. + ====================================================
  9264. + Module Initialisation registers the cpufreq driver
  9265. + ====================================================
  9266. +*/
  9267. +static int __init bcm2835_cpufreq_module_init(void)
  9268. +{
  9269. + print_debug("IN\n");
  9270. + return cpufreq_register_driver(&bcm2835_cpufreq_driver);
  9271. +}
  9272. +
  9273. +/*
  9274. + =============
  9275. + Module exit
  9276. + =============
  9277. +*/
  9278. +static void __exit bcm2835_cpufreq_module_exit(void)
  9279. +{
  9280. + print_debug("IN\n");
  9281. + cpufreq_unregister_driver(&bcm2835_cpufreq_driver);
  9282. + return;
  9283. +}
  9284. +
  9285. +/*
  9286. + ==============================================================
  9287. + Initialisation function sets up the CPU policy for first use
  9288. + ==============================================================
  9289. +*/
  9290. +static int bcm2835_cpufreq_driver_init(struct cpufreq_policy *policy)
  9291. +{
  9292. + /* measured value of how long it takes to change frequency */
  9293. + policy->cpuinfo.transition_latency = 355000; /* ns */
  9294. +
  9295. + /* now find out what the maximum and minimum frequencies are */
  9296. + policy->min = policy->cpuinfo.min_freq = bcm2835_cpufreq_get_clock(VCMSG_GET_MIN_CLOCK);
  9297. + policy->max = policy->cpuinfo.max_freq = bcm2835_cpufreq_get_clock(VCMSG_GET_MAX_CLOCK);
  9298. + policy->cur = bcm2835_cpufreq_get_clock(VCMSG_GET_CLOCK_RATE);
  9299. +
  9300. + print_info("min=%d max=%d cur=%d\n", policy->min, policy->max, policy->cur);
  9301. + return 0;
  9302. +}
  9303. +
  9304. +/*
  9305. + =================================================================================
  9306. + Target function chooses the most appropriate frequency from the table to enable
  9307. + =================================================================================
  9308. +*/
  9309. +
  9310. +static int bcm2835_cpufreq_driver_target(struct cpufreq_policy *policy, unsigned int target_freq, unsigned int relation)
  9311. +{
  9312. + unsigned int target = target_freq;
  9313. +#ifdef CPUFREQ_DEBUG_ENABLE
  9314. + unsigned int cur = policy->cur;
  9315. +#endif
  9316. + print_debug("%s: min=%d max=%d cur=%d target=%d\n",policy->governor->name,policy->min,policy->max,policy->cur,target_freq);
  9317. +
  9318. + /* if we are above min and using ondemand, then just use max */
  9319. + if (strcmp("ondemand", policy->governor->name)==0 && target > policy->min)
  9320. + target = policy->max;
  9321. + /* if the frequency is the same, just quit */
  9322. + if (target == policy->cur)
  9323. + return 0;
  9324. +
  9325. + /* otherwise were good to set the clock frequency */
  9326. + policy->cur = bcm2835_cpufreq_set_clock(policy->cur, target);
  9327. +
  9328. + if (!policy->cur)
  9329. + {
  9330. + print_err("Error occurred setting a new frequency (%d)!\n", target);
  9331. + policy->cur = bcm2835_cpufreq_get_clock(VCMSG_GET_CLOCK_RATE);
  9332. + return -EINVAL;
  9333. + }
  9334. + print_debug("Freq %d->%d (min=%d max=%d target=%d request=%d)\n", cur, policy->cur, policy->min, policy->max, target_freq, target);
  9335. + return 0;
  9336. +}
  9337. +
  9338. +static unsigned int bcm2835_cpufreq_driver_get(unsigned int cpu)
  9339. +{
  9340. + unsigned int actual_rate = bcm2835_cpufreq_get_clock(VCMSG_GET_CLOCK_RATE);
  9341. + print_debug("cpu=%d\n", actual_rate);
  9342. + return actual_rate;
  9343. +}
  9344. +
  9345. +/*
  9346. + =================================================================================
  9347. + Verify ensures that when a policy is changed, it is suitable for the CPU to use
  9348. + =================================================================================
  9349. +*/
  9350. +
  9351. +static int bcm2835_cpufreq_driver_verify(struct cpufreq_policy *policy)
  9352. +{
  9353. + print_info("switching to governor %s\n", policy->governor->name);
  9354. + return 0;
  9355. +}
  9356. +
  9357. +
  9358. +/* the CPUFreq driver */
  9359. +static struct cpufreq_driver bcm2835_cpufreq_driver = {
  9360. + .name = "BCM2835 CPUFreq",
  9361. + .init = bcm2835_cpufreq_driver_init,
  9362. + .verify = bcm2835_cpufreq_driver_verify,
  9363. + .target = bcm2835_cpufreq_driver_target,
  9364. + .get = bcm2835_cpufreq_driver_get
  9365. +};
  9366. +
  9367. +MODULE_AUTHOR("Dorian Peake and Dom Cobley");
  9368. +MODULE_DESCRIPTION("CPU frequency driver for BCM2835 chip");
  9369. +MODULE_LICENSE("GPL");
  9370. +
  9371. +module_init(bcm2835_cpufreq_module_init);
  9372. +module_exit(bcm2835_cpufreq_module_exit);
  9373. diff -Nur linux-3.13.11/drivers/cpufreq/Kconfig.arm linux-rpi/drivers/cpufreq/Kconfig.arm
  9374. --- linux-3.13.11/drivers/cpufreq/Kconfig.arm 2014-04-23 01:49:33.000000000 +0200
  9375. +++ linux-rpi/drivers/cpufreq/Kconfig.arm 2014-04-24 15:36:46.506697023 +0200
  9376. @@ -218,6 +218,14 @@
  9377. help
  9378. This adds the CPUFreq driver support for SPEAr SOCs.
  9379. +config ARM_BCM2835_CPUFREQ
  9380. + bool "BCM2835 Driver"
  9381. + default y
  9382. + help
  9383. + This adds the CPUFreq driver for BCM2835
  9384. +
  9385. + If in doubt, say N.
  9386. +
  9387. config ARM_TEGRA_CPUFREQ
  9388. bool "TEGRA CPUFreq support"
  9389. depends on ARCH_TEGRA
  9390. diff -Nur linux-3.13.11/drivers/cpufreq/Makefile linux-rpi/drivers/cpufreq/Makefile
  9391. --- linux-3.13.11/drivers/cpufreq/Makefile 2014-04-23 01:49:33.000000000 +0200
  9392. +++ linux-rpi/drivers/cpufreq/Makefile 2014-04-24 15:36:46.506697023 +0200
  9393. @@ -73,6 +73,7 @@
  9394. obj-$(CONFIG_ARM_SA1100_CPUFREQ) += sa1100-cpufreq.o
  9395. obj-$(CONFIG_ARM_SA1110_CPUFREQ) += sa1110-cpufreq.o
  9396. obj-$(CONFIG_ARM_SPEAR_CPUFREQ) += spear-cpufreq.o
  9397. +obj-$(CONFIG_ARM_BCM2835_CPUFREQ) += bcm2835-cpufreq.o
  9398. obj-$(CONFIG_ARM_TEGRA_CPUFREQ) += tegra-cpufreq.o
  9399. obj-$(CONFIG_ARM_VEXPRESS_SPC_CPUFREQ) += vexpress-spc-cpufreq.o
  9400. diff -Nur linux-3.13.11/drivers/dma/bcm2708-dmaengine.c linux-rpi/drivers/dma/bcm2708-dmaengine.c
  9401. --- linux-3.13.11/drivers/dma/bcm2708-dmaengine.c 1970-01-01 01:00:00.000000000 +0100
  9402. +++ linux-rpi/drivers/dma/bcm2708-dmaengine.c 2014-04-24 15:36:46.822700490 +0200
  9403. @@ -0,0 +1,588 @@
  9404. +/*
  9405. + * BCM2708 DMA engine support
  9406. + *
  9407. + * This driver only supports cyclic DMA transfers
  9408. + * as needed for the I2S module.
  9409. + *
  9410. + * Author: Florian Meier <florian.meier@koalo.de>
  9411. + * Copyright 2013
  9412. + *
  9413. + * Based on
  9414. + * OMAP DMAengine support by Russell King
  9415. + *
  9416. + * BCM2708 DMA Driver
  9417. + * Copyright (C) 2010 Broadcom
  9418. + *
  9419. + * Raspberry Pi PCM I2S ALSA Driver
  9420. + * Copyright (c) by Phil Poole 2013
  9421. + *
  9422. + * MARVELL MMP Peripheral DMA Driver
  9423. + * Copyright 2012 Marvell International Ltd.
  9424. + *
  9425. + * This program is free software; you can redistribute it and/or modify
  9426. + * it under the terms of the GNU General Public License as published by
  9427. + * the Free Software Foundation; either version 2 of the License, or
  9428. + * (at your option) any later version.
  9429. + *
  9430. + * This program is distributed in the hope that it will be useful,
  9431. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9432. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9433. + * GNU General Public License for more details.
  9434. + */
  9435. +#include <linux/dmaengine.h>
  9436. +#include <linux/dma-mapping.h>
  9437. +#include <linux/err.h>
  9438. +#include <linux/init.h>
  9439. +#include <linux/interrupt.h>
  9440. +#include <linux/list.h>
  9441. +#include <linux/module.h>
  9442. +#include <linux/platform_device.h>
  9443. +#include <linux/slab.h>
  9444. +#include <linux/io.h>
  9445. +#include <linux/spinlock.h>
  9446. +#include <linux/irq.h>
  9447. +
  9448. +#include "virt-dma.h"
  9449. +
  9450. +#include <mach/dma.h>
  9451. +#include <mach/irqs.h>
  9452. +
  9453. +struct bcm2708_dmadev {
  9454. + struct dma_device ddev;
  9455. + spinlock_t lock;
  9456. + void __iomem *base;
  9457. + struct device_dma_parameters dma_parms;
  9458. +};
  9459. +
  9460. +struct bcm2708_chan {
  9461. + struct virt_dma_chan vc;
  9462. + struct list_head node;
  9463. +
  9464. + struct dma_slave_config cfg;
  9465. + bool cyclic;
  9466. +
  9467. + int ch;
  9468. + struct bcm2708_desc *desc;
  9469. +
  9470. + void __iomem *chan_base;
  9471. + int irq_number;
  9472. +};
  9473. +
  9474. +struct bcm2708_desc {
  9475. + struct virt_dma_desc vd;
  9476. + enum dma_transfer_direction dir;
  9477. +
  9478. + unsigned int control_block_size;
  9479. + struct bcm2708_dma_cb *control_block_base;
  9480. + dma_addr_t control_block_base_phys;
  9481. +
  9482. + unsigned frames;
  9483. + size_t size;
  9484. +};
  9485. +
  9486. +#define BCM2708_DMA_DATA_TYPE_S8 1
  9487. +#define BCM2708_DMA_DATA_TYPE_S16 2
  9488. +#define BCM2708_DMA_DATA_TYPE_S32 4
  9489. +#define BCM2708_DMA_DATA_TYPE_S128 16
  9490. +
  9491. +static inline struct bcm2708_dmadev *to_bcm2708_dma_dev(struct dma_device *d)
  9492. +{
  9493. + return container_of(d, struct bcm2708_dmadev, ddev);
  9494. +}
  9495. +
  9496. +static inline struct bcm2708_chan *to_bcm2708_dma_chan(struct dma_chan *c)
  9497. +{
  9498. + return container_of(c, struct bcm2708_chan, vc.chan);
  9499. +}
  9500. +
  9501. +static inline struct bcm2708_desc *to_bcm2708_dma_desc(
  9502. + struct dma_async_tx_descriptor *t)
  9503. +{
  9504. + return container_of(t, struct bcm2708_desc, vd.tx);
  9505. +}
  9506. +
  9507. +static void bcm2708_dma_desc_free(struct virt_dma_desc *vd)
  9508. +{
  9509. + struct bcm2708_desc *desc = container_of(vd, struct bcm2708_desc, vd);
  9510. + dma_free_coherent(desc->vd.tx.chan->device->dev,
  9511. + desc->control_block_size,
  9512. + desc->control_block_base,
  9513. + desc->control_block_base_phys);
  9514. + kfree(desc);
  9515. +}
  9516. +
  9517. +static void bcm2708_dma_start_desc(struct bcm2708_chan *c)
  9518. +{
  9519. + struct virt_dma_desc *vd = vchan_next_desc(&c->vc);
  9520. + struct bcm2708_desc *d;
  9521. +
  9522. + if (!vd) {
  9523. + c->desc = NULL;
  9524. + return;
  9525. + }
  9526. +
  9527. + list_del(&vd->node);
  9528. +
  9529. + c->desc = d = to_bcm2708_dma_desc(&vd->tx);
  9530. +
  9531. + bcm_dma_start(c->chan_base, d->control_block_base_phys);
  9532. +}
  9533. +
  9534. +static irqreturn_t bcm2708_dma_callback(int irq, void *data)
  9535. +{
  9536. + struct bcm2708_chan *c = data;
  9537. + struct bcm2708_desc *d;
  9538. + unsigned long flags;
  9539. +
  9540. + spin_lock_irqsave(&c->vc.lock, flags);
  9541. +
  9542. + /* Acknowledge interrupt */
  9543. + writel(BCM2708_DMA_INT, c->chan_base + BCM2708_DMA_CS);
  9544. +
  9545. + d = c->desc;
  9546. +
  9547. + if (d) {
  9548. + /* TODO Only works for cyclic DMA */
  9549. + vchan_cyclic_callback(&d->vd);
  9550. + }
  9551. +
  9552. + /* Keep the DMA engine running */
  9553. + dsb(); /* ARM synchronization barrier */
  9554. + writel(BCM2708_DMA_ACTIVE, c->chan_base + BCM2708_DMA_CS);
  9555. +
  9556. + spin_unlock_irqrestore(&c->vc.lock, flags);
  9557. +
  9558. + return IRQ_HANDLED;
  9559. +}
  9560. +
  9561. +static int bcm2708_dma_alloc_chan_resources(struct dma_chan *chan)
  9562. +{
  9563. + struct bcm2708_chan *c = to_bcm2708_dma_chan(chan);
  9564. +
  9565. + return request_irq(c->irq_number,
  9566. + bcm2708_dma_callback, 0, "DMA IRQ", c);
  9567. +}
  9568. +
  9569. +static void bcm2708_dma_free_chan_resources(struct dma_chan *chan)
  9570. +{
  9571. + struct bcm2708_chan *c = to_bcm2708_dma_chan(chan);
  9572. +
  9573. + vchan_free_chan_resources(&c->vc);
  9574. + free_irq(c->irq_number, c);
  9575. +
  9576. + dev_dbg(c->vc.chan.device->dev, "Freeing DMA channel %u\n", c->ch);
  9577. +}
  9578. +
  9579. +static size_t bcm2708_dma_desc_size(struct bcm2708_desc *d)
  9580. +{
  9581. + return d->size;
  9582. +}
  9583. +
  9584. +static size_t bcm2708_dma_desc_size_pos(struct bcm2708_desc *d, dma_addr_t addr)
  9585. +{
  9586. + unsigned i;
  9587. + size_t size;
  9588. +
  9589. + for (size = i = 0; i < d->frames; i++) {
  9590. + struct bcm2708_dma_cb *control_block =
  9591. + &d->control_block_base[i];
  9592. + size_t this_size = control_block->length;
  9593. + dma_addr_t dma;
  9594. +
  9595. + if (d->dir == DMA_DEV_TO_MEM)
  9596. + dma = control_block->dst;
  9597. + else
  9598. + dma = control_block->src;
  9599. +
  9600. + if (size)
  9601. + size += this_size;
  9602. + else if (addr >= dma && addr < dma + this_size)
  9603. + size += dma + this_size - addr;
  9604. + }
  9605. +
  9606. + return size;
  9607. +}
  9608. +
  9609. +static enum dma_status bcm2708_dma_tx_status(struct dma_chan *chan,
  9610. + dma_cookie_t cookie, struct dma_tx_state *txstate)
  9611. +{
  9612. + struct bcm2708_chan *c = to_bcm2708_dma_chan(chan);
  9613. + struct virt_dma_desc *vd;
  9614. + enum dma_status ret;
  9615. + unsigned long flags;
  9616. +
  9617. + ret = dma_cookie_status(chan, cookie, txstate);
  9618. + if (ret == DMA_COMPLETE || !txstate)
  9619. + return ret;
  9620. +
  9621. + spin_lock_irqsave(&c->vc.lock, flags);
  9622. + vd = vchan_find_desc(&c->vc, cookie);
  9623. + if (vd) {
  9624. + txstate->residue =
  9625. + bcm2708_dma_desc_size(to_bcm2708_dma_desc(&vd->tx));
  9626. + } else if (c->desc && c->desc->vd.tx.cookie == cookie) {
  9627. + struct bcm2708_desc *d = c->desc;
  9628. + dma_addr_t pos;
  9629. +
  9630. + if (d->dir == DMA_MEM_TO_DEV)
  9631. + pos = readl(c->chan_base + BCM2708_DMA_SOURCE_AD);
  9632. + else if (d->dir == DMA_DEV_TO_MEM)
  9633. + pos = readl(c->chan_base + BCM2708_DMA_DEST_AD);
  9634. + else
  9635. + pos = 0;
  9636. +
  9637. + txstate->residue = bcm2708_dma_desc_size_pos(d, pos);
  9638. + } else {
  9639. + txstate->residue = 0;
  9640. + }
  9641. +
  9642. + spin_unlock_irqrestore(&c->vc.lock, flags);
  9643. +
  9644. + return ret;
  9645. +}
  9646. +
  9647. +static void bcm2708_dma_issue_pending(struct dma_chan *chan)
  9648. +{
  9649. + struct bcm2708_chan *c = to_bcm2708_dma_chan(chan);
  9650. + unsigned long flags;
  9651. +
  9652. + c->cyclic = true; /* Nothing else is implemented */
  9653. +
  9654. + spin_lock_irqsave(&c->vc.lock, flags);
  9655. + if (vchan_issue_pending(&c->vc) && !c->desc)
  9656. + bcm2708_dma_start_desc(c);
  9657. +
  9658. + spin_unlock_irqrestore(&c->vc.lock, flags);
  9659. +}
  9660. +
  9661. +static struct dma_async_tx_descriptor *bcm2708_dma_prep_dma_cyclic(
  9662. + struct dma_chan *chan, dma_addr_t buf_addr, size_t buf_len,
  9663. + size_t period_len, enum dma_transfer_direction direction,
  9664. + unsigned long flags, void *context)
  9665. +{
  9666. + struct bcm2708_chan *c = to_bcm2708_dma_chan(chan);
  9667. + enum dma_slave_buswidth dev_width;
  9668. + struct bcm2708_desc *d;
  9669. + dma_addr_t dev_addr;
  9670. + unsigned es, sync_type;
  9671. + unsigned frame;
  9672. +
  9673. + /* Grab configuration */
  9674. + if (direction == DMA_DEV_TO_MEM) {
  9675. + dev_addr = c->cfg.src_addr;
  9676. + dev_width = c->cfg.src_addr_width;
  9677. + sync_type = BCM2708_DMA_S_DREQ;
  9678. + } else if (direction == DMA_MEM_TO_DEV) {
  9679. + dev_addr = c->cfg.dst_addr;
  9680. + dev_width = c->cfg.dst_addr_width;
  9681. + sync_type = BCM2708_DMA_D_DREQ;
  9682. + } else {
  9683. + dev_err(chan->device->dev, "%s: bad direction?\n", __func__);
  9684. + return NULL;
  9685. + }
  9686. +
  9687. + /* Bus width translates to the element size (ES) */
  9688. + switch (dev_width) {
  9689. + case DMA_SLAVE_BUSWIDTH_4_BYTES:
  9690. + es = BCM2708_DMA_DATA_TYPE_S32;
  9691. + break;
  9692. + default:
  9693. + return NULL;
  9694. + }
  9695. +
  9696. + /* Now allocate and setup the descriptor. */
  9697. + d = kzalloc(sizeof(*d), GFP_NOWAIT);
  9698. + if (!d)
  9699. + return NULL;
  9700. +
  9701. + d->dir = direction;
  9702. + d->frames = buf_len / period_len;
  9703. +
  9704. + /* Allocate memory for control blocks */
  9705. + d->control_block_size = d->frames * sizeof(struct bcm2708_dma_cb);
  9706. + d->control_block_base = dma_zalloc_coherent(chan->device->dev,
  9707. + d->control_block_size, &d->control_block_base_phys,
  9708. + GFP_NOWAIT);
  9709. +
  9710. + if (!d->control_block_base) {
  9711. + kfree(d);
  9712. + return NULL;
  9713. + }
  9714. +
  9715. + /*
  9716. + * Iterate over all frames, create a control block
  9717. + * for each frame and link them together.
  9718. + */
  9719. + for (frame = 0; frame < d->frames; frame++) {
  9720. + struct bcm2708_dma_cb *control_block =
  9721. + &d->control_block_base[frame];
  9722. +
  9723. + /* Setup adresses */
  9724. + if (d->dir == DMA_DEV_TO_MEM) {
  9725. + control_block->info = BCM2708_DMA_D_INC;
  9726. + control_block->src = dev_addr;
  9727. + control_block->dst = buf_addr + frame * period_len;
  9728. + } else {
  9729. + control_block->info = BCM2708_DMA_S_INC;
  9730. + control_block->src = buf_addr + frame * period_len;
  9731. + control_block->dst = dev_addr;
  9732. + }
  9733. +
  9734. + /* Enable interrupt */
  9735. + control_block->info |= BCM2708_DMA_INT_EN;
  9736. +
  9737. + /* Setup synchronization */
  9738. + if (sync_type != 0)
  9739. + control_block->info |= sync_type;
  9740. +
  9741. + /* Setup DREQ channel */
  9742. + if (c->cfg.slave_id != 0)
  9743. + control_block->info |=
  9744. + BCM2708_DMA_PER_MAP(c->cfg.slave_id);
  9745. +
  9746. + /* Length of a frame */
  9747. + control_block->length = period_len;
  9748. + d->size += control_block->length;
  9749. +
  9750. + /*
  9751. + * Next block is the next frame.
  9752. + * This DMA engine driver currently only supports cyclic DMA.
  9753. + * Therefore, wrap around at number of frames.
  9754. + */
  9755. + control_block->next = d->control_block_base_phys +
  9756. + sizeof(struct bcm2708_dma_cb)
  9757. + * ((frame + 1) % d->frames);
  9758. + }
  9759. +
  9760. + return vchan_tx_prep(&c->vc, &d->vd, flags);
  9761. +}
  9762. +
  9763. +static int bcm2708_dma_slave_config(struct bcm2708_chan *c,
  9764. + struct dma_slave_config *cfg)
  9765. +{
  9766. + if ((cfg->direction == DMA_DEV_TO_MEM &&
  9767. + cfg->src_addr_width != DMA_SLAVE_BUSWIDTH_4_BYTES) ||
  9768. + (cfg->direction == DMA_MEM_TO_DEV &&
  9769. + cfg->dst_addr_width != DMA_SLAVE_BUSWIDTH_4_BYTES) ||
  9770. + !is_slave_direction(cfg->direction)) {
  9771. + return -EINVAL;
  9772. + }
  9773. +
  9774. + c->cfg = *cfg;
  9775. +
  9776. + return 0;
  9777. +}
  9778. +
  9779. +static int bcm2708_dma_terminate_all(struct bcm2708_chan *c)
  9780. +{
  9781. + struct bcm2708_dmadev *d = to_bcm2708_dma_dev(c->vc.chan.device);
  9782. + unsigned long flags;
  9783. + int timeout = 10000;
  9784. + LIST_HEAD(head);
  9785. +
  9786. + spin_lock_irqsave(&c->vc.lock, flags);
  9787. +
  9788. + /* Prevent this channel being scheduled */
  9789. + spin_lock(&d->lock);
  9790. + list_del_init(&c->node);
  9791. + spin_unlock(&d->lock);
  9792. +
  9793. + /*
  9794. + * Stop DMA activity: we assume the callback will not be called
  9795. + * after bcm_dma_abort() returns (even if it does, it will see
  9796. + * c->desc is NULL and exit.)
  9797. + */
  9798. + if (c->desc) {
  9799. + c->desc = NULL;
  9800. + bcm_dma_abort(c->chan_base);
  9801. +
  9802. + /* Wait for stopping */
  9803. + while (timeout > 0) {
  9804. + timeout--;
  9805. + if (!(readl(c->chan_base + BCM2708_DMA_CS) &
  9806. + BCM2708_DMA_ACTIVE))
  9807. + break;
  9808. +
  9809. + cpu_relax();
  9810. + }
  9811. +
  9812. + if (timeout <= 0)
  9813. + dev_err(d->ddev.dev, "DMA transfer could not be terminated\n");
  9814. + }
  9815. +
  9816. + vchan_get_all_descriptors(&c->vc, &head);
  9817. + spin_unlock_irqrestore(&c->vc.lock, flags);
  9818. + vchan_dma_desc_free_list(&c->vc, &head);
  9819. +
  9820. + return 0;
  9821. +}
  9822. +
  9823. +static int bcm2708_dma_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
  9824. + unsigned long arg)
  9825. +{
  9826. + struct bcm2708_chan *c = to_bcm2708_dma_chan(chan);
  9827. +
  9828. + switch (cmd) {
  9829. + case DMA_SLAVE_CONFIG:
  9830. + return bcm2708_dma_slave_config(c,
  9831. + (struct dma_slave_config *)arg);
  9832. +
  9833. + case DMA_TERMINATE_ALL:
  9834. + return bcm2708_dma_terminate_all(c);
  9835. +
  9836. + default:
  9837. + return -ENXIO;
  9838. + }
  9839. +}
  9840. +
  9841. +static int bcm2708_dma_chan_init(struct bcm2708_dmadev *d, void __iomem* chan_base,
  9842. + int chan_id, int irq)
  9843. +{
  9844. + struct bcm2708_chan *c;
  9845. +
  9846. + c = devm_kzalloc(d->ddev.dev, sizeof(*c), GFP_KERNEL);
  9847. + if (!c)
  9848. + return -ENOMEM;
  9849. +
  9850. + c->vc.desc_free = bcm2708_dma_desc_free;
  9851. + vchan_init(&c->vc, &d->ddev);
  9852. + INIT_LIST_HEAD(&c->node);
  9853. +
  9854. + d->ddev.chancnt++;
  9855. +
  9856. + c->chan_base = chan_base;
  9857. + c->ch = chan_id;
  9858. + c->irq_number = irq;
  9859. +
  9860. + return 0;
  9861. +}
  9862. +
  9863. +static void bcm2708_dma_free(struct bcm2708_dmadev *od)
  9864. +{
  9865. + while (!list_empty(&od->ddev.channels)) {
  9866. + struct bcm2708_chan *c = list_first_entry(&od->ddev.channels,
  9867. + struct bcm2708_chan, vc.chan.device_node);
  9868. +
  9869. + list_del(&c->vc.chan.device_node);
  9870. + tasklet_kill(&c->vc.task);
  9871. + }
  9872. +}
  9873. +
  9874. +static int bcm2708_dma_probe(struct platform_device *pdev)
  9875. +{
  9876. + struct bcm2708_dmadev *od;
  9877. + int rc, i;
  9878. +
  9879. + if (!pdev->dev.dma_mask)
  9880. + pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
  9881. +
  9882. + rc = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
  9883. + if (rc)
  9884. + return rc;
  9885. + dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
  9886. +
  9887. + od = devm_kzalloc(&pdev->dev, sizeof(*od), GFP_KERNEL);
  9888. + if (!od)
  9889. + return -ENOMEM;
  9890. +
  9891. + pdev->dev.dma_parms = &od->dma_parms;
  9892. + dma_set_max_seg_size(&pdev->dev, 0x3FFFFFFF);
  9893. +
  9894. + dma_cap_set(DMA_SLAVE, od->ddev.cap_mask);
  9895. + dma_cap_set(DMA_CYCLIC, od->ddev.cap_mask);
  9896. + od->ddev.device_alloc_chan_resources = bcm2708_dma_alloc_chan_resources;
  9897. + od->ddev.device_free_chan_resources = bcm2708_dma_free_chan_resources;
  9898. + od->ddev.device_tx_status = bcm2708_dma_tx_status;
  9899. + od->ddev.device_issue_pending = bcm2708_dma_issue_pending;
  9900. + od->ddev.device_prep_dma_cyclic = bcm2708_dma_prep_dma_cyclic;
  9901. + od->ddev.device_control = bcm2708_dma_control;
  9902. + od->ddev.dev = &pdev->dev;
  9903. + INIT_LIST_HEAD(&od->ddev.channels);
  9904. + spin_lock_init(&od->lock);
  9905. +
  9906. + platform_set_drvdata(pdev, od);
  9907. +
  9908. + for (i = 0; i < 16; i++) {
  9909. + void __iomem* chan_base;
  9910. + int chan_id, irq;
  9911. +
  9912. + chan_id = bcm_dma_chan_alloc(BCM_DMA_FEATURE_FAST,
  9913. + &chan_base,
  9914. + &irq);
  9915. +
  9916. + if (chan_id < 0)
  9917. + break;
  9918. +
  9919. + rc = bcm2708_dma_chan_init(od, chan_base, chan_id, irq);
  9920. + if (rc) {
  9921. + bcm2708_dma_free(od);
  9922. + return rc;
  9923. + }
  9924. + }
  9925. +
  9926. + rc = dma_async_device_register(&od->ddev);
  9927. + if (rc) {
  9928. + dev_err(&pdev->dev,
  9929. + "Failed to register slave DMA engine device: %d\n", rc);
  9930. + bcm2708_dma_free(od);
  9931. + return rc;
  9932. + }
  9933. +
  9934. + dev_dbg(&pdev->dev, "Load BCM2708 DMA engine driver\n");
  9935. +
  9936. + return rc;
  9937. +}
  9938. +
  9939. +static int bcm2708_dma_remove(struct platform_device *pdev)
  9940. +{
  9941. + struct bcm2708_dmadev *od = platform_get_drvdata(pdev);
  9942. +
  9943. + dma_async_device_unregister(&od->ddev);
  9944. + bcm2708_dma_free(od);
  9945. +
  9946. + return 0;
  9947. +}
  9948. +
  9949. +static struct platform_driver bcm2708_dma_driver = {
  9950. + .probe = bcm2708_dma_probe,
  9951. + .remove = bcm2708_dma_remove,
  9952. + .driver = {
  9953. + .name = "bcm2708-dmaengine",
  9954. + .owner = THIS_MODULE,
  9955. + },
  9956. +};
  9957. +
  9958. +static struct platform_device *pdev;
  9959. +
  9960. +static const struct platform_device_info bcm2708_dma_dev_info = {
  9961. + .name = "bcm2708-dmaengine",
  9962. + .id = -1,
  9963. +};
  9964. +
  9965. +static int bcm2708_dma_init(void)
  9966. +{
  9967. + int rc = platform_driver_register(&bcm2708_dma_driver);
  9968. +
  9969. + if (rc == 0) {
  9970. + pdev = platform_device_register_full(&bcm2708_dma_dev_info);
  9971. + if (IS_ERR(pdev)) {
  9972. + platform_driver_unregister(&bcm2708_dma_driver);
  9973. + rc = PTR_ERR(pdev);
  9974. + }
  9975. + }
  9976. +
  9977. + return rc;
  9978. +}
  9979. +subsys_initcall(bcm2708_dma_init);
  9980. +
  9981. +static void __exit bcm2708_dma_exit(void)
  9982. +{
  9983. + platform_device_unregister(pdev);
  9984. + platform_driver_unregister(&bcm2708_dma_driver);
  9985. +}
  9986. +module_exit(bcm2708_dma_exit);
  9987. +
  9988. +MODULE_ALIAS("platform:bcm2708-dma");
  9989. +MODULE_DESCRIPTION("BCM2708 DMA engine driver");
  9990. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  9991. +MODULE_LICENSE("GPL v2");
  9992. diff -Nur linux-3.13.11/drivers/dma/Kconfig linux-rpi/drivers/dma/Kconfig
  9993. --- linux-3.13.11/drivers/dma/Kconfig 2014-04-23 01:49:33.000000000 +0200
  9994. +++ linux-rpi/drivers/dma/Kconfig 2014-04-24 15:36:46.818700446 +0200
  9995. @@ -304,6 +304,12 @@
  9996. select DMA_ENGINE
  9997. select DMA_VIRTUAL_CHANNELS
  9998. +config DMA_BCM2708
  9999. + tristate "BCM2708 DMA engine support"
  10000. + depends on MACH_BCM2708
  10001. + select DMA_ENGINE
  10002. + select DMA_VIRTUAL_CHANNELS
  10003. +
  10004. config TI_CPPI41
  10005. tristate "AM33xx CPPI41 DMA support"
  10006. depends on ARCH_OMAP
  10007. diff -Nur linux-3.13.11/drivers/dma/Makefile linux-rpi/drivers/dma/Makefile
  10008. --- linux-3.13.11/drivers/dma/Makefile 2014-04-23 01:49:33.000000000 +0200
  10009. +++ linux-rpi/drivers/dma/Makefile 2014-04-24 15:36:46.818700446 +0200
  10010. @@ -38,6 +38,7 @@
  10011. obj-$(CONFIG_DMA_SA11X0) += sa11x0-dma.o
  10012. obj-$(CONFIG_MMP_TDMA) += mmp_tdma.o
  10013. obj-$(CONFIG_DMA_OMAP) += omap-dma.o
  10014. +obj-$(CONFIG_DMA_BCM2708) += bcm2708-dmaengine.o
  10015. obj-$(CONFIG_MMP_PDMA) += mmp_pdma.o
  10016. obj-$(CONFIG_DMA_JZ4740) += dma-jz4740.o
  10017. obj-$(CONFIG_TI_CPPI41) += cppi41.o
  10018. diff -Nur linux-3.13.11/drivers/hwmon/bcm2835-hwmon.c linux-rpi/drivers/hwmon/bcm2835-hwmon.c
  10019. --- linux-3.13.11/drivers/hwmon/bcm2835-hwmon.c 1970-01-01 01:00:00.000000000 +0100
  10020. +++ linux-rpi/drivers/hwmon/bcm2835-hwmon.c 2014-04-24 15:35:02.349545454 +0200
  10021. @@ -0,0 +1,219 @@
  10022. +/*****************************************************************************
  10023. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  10024. +*
  10025. +* Unless you and Broadcom execute a separate written software license
  10026. +* agreement governing use of this software, this software is licensed to you
  10027. +* under the terms of the GNU General Public License version 2, available at
  10028. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  10029. +*
  10030. +* Notwithstanding the above, under no circumstances may you combine this
  10031. +* software in any way with any other Broadcom software provided under a
  10032. +* license other than the GPL, without Broadcom's express prior written
  10033. +* consent.
  10034. +*****************************************************************************/
  10035. +
  10036. +#include <linux/kernel.h>
  10037. +#include <linux/module.h>
  10038. +#include <linux/init.h>
  10039. +#include <linux/hwmon.h>
  10040. +#include <linux/hwmon-sysfs.h>
  10041. +#include <linux/platform_device.h>
  10042. +#include <linux/sysfs.h>
  10043. +#include <mach/vcio.h>
  10044. +#include <linux/slab.h>
  10045. +#include <linux/err.h>
  10046. +
  10047. +#define MODULE_NAME "bcm2835_hwmon"
  10048. +
  10049. +/*#define HWMON_DEBUG_ENABLE*/
  10050. +
  10051. +#ifdef HWMON_DEBUG_ENABLE
  10052. +#define print_debug(fmt,...) printk(KERN_INFO "%s:%s:%d: "fmt"\n", MODULE_NAME, __func__, __LINE__, ##__VA_ARGS__)
  10053. +#else
  10054. +#define print_debug(fmt,...)
  10055. +#endif
  10056. +#define print_err(fmt,...) printk(KERN_ERR "%s:%s:%d: "fmt"\n", MODULE_NAME, __func__,__LINE__, ##__VA_ARGS__)
  10057. +#define print_info(fmt,...) printk(KERN_INFO "%s: "fmt"\n", MODULE_NAME, ##__VA_ARGS__)
  10058. +
  10059. +#define VC_TAG_GET_TEMP 0x00030006
  10060. +#define VC_TAG_GET_MAX_TEMP 0x0003000A
  10061. +
  10062. +/* --- STRUCTS --- */
  10063. +struct bcm2835_hwmon_data {
  10064. + struct device *hwmon_dev;
  10065. +};
  10066. +
  10067. +/* tag part of the message */
  10068. +struct vc_msg_tag {
  10069. + uint32_t tag_id; /* the tag ID for the temperature */
  10070. + uint32_t buffer_size; /* size of the buffer (should be 8) */
  10071. + uint32_t request_code; /* identifies message as a request (should be 0) */
  10072. + uint32_t id; /* extra ID field (should be 0) */
  10073. + uint32_t val; /* returned value of the temperature */
  10074. +};
  10075. +
  10076. +/* message structure to be sent to videocore */
  10077. +struct vc_msg {
  10078. + uint32_t msg_size; /* simply, sizeof(struct vc_msg) */
  10079. + uint32_t request_code; /* holds various information like the success and number of bytes returned (refer to mailboxes wiki) */
  10080. + struct vc_msg_tag tag; /* the tag structure above to make */
  10081. + uint32_t end_tag; /* an end identifier, should be set to NULL */
  10082. +};
  10083. +
  10084. +typedef enum {
  10085. + TEMP,
  10086. + MAX_TEMP,
  10087. +} temp_type;
  10088. +
  10089. +/* --- PROTOTYPES --- */
  10090. +static ssize_t bcm2835_get_temp(struct device *dev, struct device_attribute *attr, char *buf);
  10091. +static ssize_t bcm2835_get_name(struct device *dev, struct device_attribute *attr, char *buf);
  10092. +
  10093. +/* --- GLOBALS --- */
  10094. +
  10095. +static struct bcm2835_hwmon_data *bcm2835_data;
  10096. +static struct platform_driver bcm2835_hwmon_driver;
  10097. +
  10098. +static SENSOR_DEVICE_ATTR(name, S_IRUGO,bcm2835_get_name,NULL,0);
  10099. +static SENSOR_DEVICE_ATTR(temp1_input,S_IRUGO,bcm2835_get_temp,NULL,TEMP);
  10100. +static SENSOR_DEVICE_ATTR(temp1_max,S_IRUGO,bcm2835_get_temp,NULL,MAX_TEMP);
  10101. +
  10102. +static struct attribute* bcm2835_attributes[] = {
  10103. + &sensor_dev_attr_name.dev_attr.attr,
  10104. + &sensor_dev_attr_temp1_input.dev_attr.attr,
  10105. + &sensor_dev_attr_temp1_max.dev_attr.attr,
  10106. + NULL,
  10107. +};
  10108. +
  10109. +static struct attribute_group bcm2835_attr_group = {
  10110. + .attrs = bcm2835_attributes,
  10111. +};
  10112. +
  10113. +/* --- FUNCTIONS --- */
  10114. +
  10115. +static ssize_t bcm2835_get_name(struct device *dev, struct device_attribute *attr, char *buf)
  10116. +{
  10117. + return sprintf(buf,"bcm2835_hwmon\n");
  10118. +}
  10119. +
  10120. +static ssize_t bcm2835_get_temp(struct device *dev, struct device_attribute *attr, char *buf)
  10121. +{
  10122. + struct vc_msg msg;
  10123. + int result;
  10124. + uint temp = 0;
  10125. + int index = ((struct sensor_device_attribute*)to_sensor_dev_attr(attr))->index;
  10126. +
  10127. + print_debug("IN");
  10128. +
  10129. + /* wipe all previous message data */
  10130. + memset(&msg, 0, sizeof msg);
  10131. +
  10132. + /* determine the message type */
  10133. + if(index == TEMP)
  10134. + msg.tag.tag_id = VC_TAG_GET_TEMP;
  10135. + else if (index == MAX_TEMP)
  10136. + msg.tag.tag_id = VC_TAG_GET_MAX_TEMP;
  10137. + else
  10138. + {
  10139. + print_debug("Unknown temperature message!");
  10140. + return -EINVAL;
  10141. + }
  10142. +
  10143. + msg.msg_size = sizeof msg;
  10144. + msg.tag.buffer_size = 8;
  10145. +
  10146. + /* send the message */
  10147. + result = bcm_mailbox_property(&msg, sizeof msg);
  10148. +
  10149. + /* check if it was all ok and return the rate in milli degrees C */
  10150. + if (result == 0 && (msg.request_code & 0x80000000))
  10151. + temp = (uint)msg.tag.val;
  10152. + #ifdef HWMON_DEBUG_ENABLE
  10153. + else
  10154. + print_debug("Failed to get temperature!");
  10155. + #endif
  10156. + print_debug("Got temperature as %u",temp);
  10157. + print_debug("OUT");
  10158. + return sprintf(buf, "%u\n", temp);
  10159. +}
  10160. +
  10161. +
  10162. +static int bcm2835_hwmon_probe(struct platform_device *pdev)
  10163. +{
  10164. + int err;
  10165. +
  10166. + print_debug("IN");
  10167. + print_debug("HWMON Driver has been probed!");
  10168. +
  10169. + /* check that the device isn't null!*/
  10170. + if(pdev == NULL)
  10171. + {
  10172. + print_debug("Platform device is empty!");
  10173. + return -ENODEV;
  10174. + }
  10175. +
  10176. + /* allocate memory for neccessary data */
  10177. + bcm2835_data = kzalloc(sizeof(struct bcm2835_hwmon_data),GFP_KERNEL);
  10178. + if(!bcm2835_data)
  10179. + {
  10180. + print_debug("Unable to allocate memory for hwmon data!");
  10181. + err = -ENOMEM;
  10182. + goto kzalloc_error;
  10183. + }
  10184. +
  10185. + /* create the sysfs files */
  10186. + if(sysfs_create_group(&pdev->dev.kobj, &bcm2835_attr_group))
  10187. + {
  10188. + print_debug("Unable to create sysfs files!");
  10189. + err = -EFAULT;
  10190. + goto sysfs_error;
  10191. + }
  10192. +
  10193. + /* register the hwmon device */
  10194. + bcm2835_data->hwmon_dev = hwmon_device_register(&pdev->dev);
  10195. + if (IS_ERR(bcm2835_data->hwmon_dev))
  10196. + {
  10197. + err = PTR_ERR(bcm2835_data->hwmon_dev);
  10198. + goto hwmon_error;
  10199. + }
  10200. + print_debug("OUT");
  10201. + return 0;
  10202. +
  10203. + /* error goto's */
  10204. + hwmon_error:
  10205. + sysfs_remove_group(&pdev->dev.kobj, &bcm2835_attr_group);
  10206. +
  10207. + sysfs_error:
  10208. + kfree(bcm2835_data);
  10209. +
  10210. + kzalloc_error:
  10211. +
  10212. + return err;
  10213. +
  10214. +}
  10215. +
  10216. +static int bcm2835_hwmon_remove(struct platform_device *pdev)
  10217. +{
  10218. + print_debug("IN");
  10219. + hwmon_device_unregister(bcm2835_data->hwmon_dev);
  10220. +
  10221. + sysfs_remove_group(&pdev->dev.kobj, &bcm2835_attr_group);
  10222. + print_debug("OUT");
  10223. + return 0;
  10224. +}
  10225. +
  10226. +/* Hwmon Driver */
  10227. +static struct platform_driver bcm2835_hwmon_driver = {
  10228. + .probe = bcm2835_hwmon_probe,
  10229. + .remove = bcm2835_hwmon_remove,
  10230. + .driver = {
  10231. + .name = "bcm2835_hwmon",
  10232. + .owner = THIS_MODULE,
  10233. + },
  10234. +};
  10235. +
  10236. +MODULE_LICENSE("GPL");
  10237. +MODULE_AUTHOR("Dorian Peake");
  10238. +MODULE_DESCRIPTION("HW Monitor driver for bcm2835 chip");
  10239. +
  10240. +module_platform_driver(bcm2835_hwmon_driver);
  10241. diff -Nur linux-3.13.11/drivers/hwmon/Kconfig linux-rpi/drivers/hwmon/Kconfig
  10242. --- linux-3.13.11/drivers/hwmon/Kconfig 2014-04-23 01:49:33.000000000 +0200
  10243. +++ linux-rpi/drivers/hwmon/Kconfig 2014-04-24 15:36:48.186715451 +0200
  10244. @@ -1554,6 +1554,16 @@
  10245. help
  10246. Support for the A/D converter on MC13783 and MC13892 PMIC.
  10247. +config SENSORS_BCM2835
  10248. + depends on THERMAL_BCM2835=n
  10249. + tristate "Broadcom BCM2835 HWMON Driver"
  10250. + help
  10251. + If you say yes here you get support for the hardware
  10252. + monitoring features of the BCM2835 Chip
  10253. +
  10254. + This driver can also be built as a module. If so, the module
  10255. + will be called bcm2835-hwmon.
  10256. +
  10257. if ACPI
  10258. comment "ACPI drivers"
  10259. diff -Nur linux-3.13.11/drivers/hwmon/Makefile linux-rpi/drivers/hwmon/Makefile
  10260. --- linux-3.13.11/drivers/hwmon/Makefile 2014-04-23 01:49:33.000000000 +0200
  10261. +++ linux-rpi/drivers/hwmon/Makefile 2014-04-24 15:36:48.186715451 +0200
  10262. @@ -142,6 +142,7 @@
  10263. obj-$(CONFIG_SENSORS_W83L786NG) += w83l786ng.o
  10264. obj-$(CONFIG_SENSORS_WM831X) += wm831x-hwmon.o
  10265. obj-$(CONFIG_SENSORS_WM8350) += wm8350-hwmon.o
  10266. +obj-$(CONFIG_SENSORS_BCM2835) += bcm2835-hwmon.o
  10267. obj-$(CONFIG_PMBUS) += pmbus/
  10268. diff -Nur linux-3.13.11/drivers/i2c/busses/i2c-bcm2708.c linux-rpi/drivers/i2c/busses/i2c-bcm2708.c
  10269. --- linux-3.13.11/drivers/i2c/busses/i2c-bcm2708.c 1970-01-01 01:00:00.000000000 +0100
  10270. +++ linux-rpi/drivers/i2c/busses/i2c-bcm2708.c 2014-04-24 15:36:48.222715846 +0200
  10271. @@ -0,0 +1,408 @@
  10272. +/*
  10273. + * Driver for Broadcom BCM2708 BSC Controllers
  10274. + *
  10275. + * Copyright (C) 2012 Chris Boot & Frank Buss
  10276. + *
  10277. + * This driver is inspired by:
  10278. + * i2c-ocores.c, by Peter Korsgaard <jacmet@sunsite.dk>
  10279. + *
  10280. + * This program is free software; you can redistribute it and/or modify
  10281. + * it under the terms of the GNU General Public License as published by
  10282. + * the Free Software Foundation; either version 2 of the License, or
  10283. + * (at your option) any later version.
  10284. + *
  10285. + * This program is distributed in the hope that it will be useful,
  10286. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10287. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10288. + * GNU General Public License for more details.
  10289. + *
  10290. + * You should have received a copy of the GNU General Public License
  10291. + * along with this program; if not, write to the Free Software
  10292. + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  10293. + */
  10294. +
  10295. +#include <linux/kernel.h>
  10296. +#include <linux/module.h>
  10297. +#include <linux/spinlock.h>
  10298. +#include <linux/clk.h>
  10299. +#include <linux/err.h>
  10300. +#include <linux/platform_device.h>
  10301. +#include <linux/io.h>
  10302. +#include <linux/slab.h>
  10303. +#include <linux/i2c.h>
  10304. +#include <linux/interrupt.h>
  10305. +#include <linux/sched.h>
  10306. +#include <linux/wait.h>
  10307. +
  10308. +/* BSC register offsets */
  10309. +#define BSC_C 0x00
  10310. +#define BSC_S 0x04
  10311. +#define BSC_DLEN 0x08
  10312. +#define BSC_A 0x0c
  10313. +#define BSC_FIFO 0x10
  10314. +#define BSC_DIV 0x14
  10315. +#define BSC_DEL 0x18
  10316. +#define BSC_CLKT 0x1c
  10317. +
  10318. +/* Bitfields in BSC_C */
  10319. +#define BSC_C_I2CEN 0x00008000
  10320. +#define BSC_C_INTR 0x00000400
  10321. +#define BSC_C_INTT 0x00000200
  10322. +#define BSC_C_INTD 0x00000100
  10323. +#define BSC_C_ST 0x00000080
  10324. +#define BSC_C_CLEAR_1 0x00000020
  10325. +#define BSC_C_CLEAR_2 0x00000010
  10326. +#define BSC_C_READ 0x00000001
  10327. +
  10328. +/* Bitfields in BSC_S */
  10329. +#define BSC_S_CLKT 0x00000200
  10330. +#define BSC_S_ERR 0x00000100
  10331. +#define BSC_S_RXF 0x00000080
  10332. +#define BSC_S_TXE 0x00000040
  10333. +#define BSC_S_RXD 0x00000020
  10334. +#define BSC_S_TXD 0x00000010
  10335. +#define BSC_S_RXR 0x00000008
  10336. +#define BSC_S_TXW 0x00000004
  10337. +#define BSC_S_DONE 0x00000002
  10338. +#define BSC_S_TA 0x00000001
  10339. +
  10340. +#define I2C_TIMEOUT_MS 150
  10341. +
  10342. +#define DRV_NAME "bcm2708_i2c"
  10343. +
  10344. +static unsigned int baudrate = CONFIG_I2C_BCM2708_BAUDRATE;
  10345. +module_param(baudrate, uint, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
  10346. +MODULE_PARM_DESC(baudrate, "The I2C baudrate");
  10347. +
  10348. +
  10349. +struct bcm2708_i2c {
  10350. + struct i2c_adapter adapter;
  10351. +
  10352. + spinlock_t lock;
  10353. + void __iomem *base;
  10354. + int irq;
  10355. + struct clk *clk;
  10356. +
  10357. + struct completion done;
  10358. +
  10359. + struct i2c_msg *msg;
  10360. + int pos;
  10361. + int nmsgs;
  10362. + bool error;
  10363. +};
  10364. +
  10365. +/*
  10366. + * This function sets the ALT mode on the I2C pins so that we can use them with
  10367. + * the BSC hardware.
  10368. + *
  10369. + * FIXME: This is a hack. Use pinmux / pinctrl.
  10370. + */
  10371. +static void bcm2708_i2c_init_pinmode(int id)
  10372. +{
  10373. +#define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3))
  10374. +#define SET_GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3))
  10375. +
  10376. + int pin;
  10377. + u32 *gpio = ioremap(0x20200000, SZ_16K);
  10378. +
  10379. + BUG_ON(id != 0 && id != 1);
  10380. + /* BSC0 is on GPIO 0 & 1, BSC1 is on GPIO 2 & 3 */
  10381. + for (pin = id*2+0; pin <= id*2+1; pin++) {
  10382. +printk("bcm2708_i2c_init_pinmode(%d,%d)\n", id, pin);
  10383. + INP_GPIO(pin); /* set mode to GPIO input first */
  10384. + SET_GPIO_ALT(pin, 0); /* set mode to ALT 0 */
  10385. + }
  10386. +
  10387. + iounmap(gpio);
  10388. +
  10389. +#undef INP_GPIO
  10390. +#undef SET_GPIO_ALT
  10391. +}
  10392. +
  10393. +static inline u32 bcm2708_rd(struct bcm2708_i2c *bi, unsigned reg)
  10394. +{
  10395. + return readl(bi->base + reg);
  10396. +}
  10397. +
  10398. +static inline void bcm2708_wr(struct bcm2708_i2c *bi, unsigned reg, u32 val)
  10399. +{
  10400. + writel(val, bi->base + reg);
  10401. +}
  10402. +
  10403. +static inline void bcm2708_bsc_reset(struct bcm2708_i2c *bi)
  10404. +{
  10405. + bcm2708_wr(bi, BSC_C, 0);
  10406. + bcm2708_wr(bi, BSC_S, BSC_S_CLKT | BSC_S_ERR | BSC_S_DONE);
  10407. +}
  10408. +
  10409. +static inline void bcm2708_bsc_fifo_drain(struct bcm2708_i2c *bi)
  10410. +{
  10411. + while ((bcm2708_rd(bi, BSC_S) & BSC_S_RXD) && (bi->pos < bi->msg->len))
  10412. + bi->msg->buf[bi->pos++] = bcm2708_rd(bi, BSC_FIFO);
  10413. +}
  10414. +
  10415. +static inline void bcm2708_bsc_fifo_fill(struct bcm2708_i2c *bi)
  10416. +{
  10417. + while ((bcm2708_rd(bi, BSC_S) & BSC_S_TXD) && (bi->pos < bi->msg->len))
  10418. + bcm2708_wr(bi, BSC_FIFO, bi->msg->buf[bi->pos++]);
  10419. +}
  10420. +
  10421. +static inline void bcm2708_bsc_setup(struct bcm2708_i2c *bi)
  10422. +{
  10423. + unsigned long bus_hz;
  10424. + u32 cdiv;
  10425. + u32 c = BSC_C_I2CEN | BSC_C_INTD | BSC_C_ST | BSC_C_CLEAR_1;
  10426. +
  10427. + bus_hz = clk_get_rate(bi->clk);
  10428. + cdiv = bus_hz / baudrate;
  10429. +
  10430. + if (bi->msg->flags & I2C_M_RD)
  10431. + c |= BSC_C_INTR | BSC_C_READ;
  10432. + else
  10433. + c |= BSC_C_INTT;
  10434. +
  10435. + bcm2708_wr(bi, BSC_DIV, cdiv);
  10436. + bcm2708_wr(bi, BSC_A, bi->msg->addr);
  10437. + bcm2708_wr(bi, BSC_DLEN, bi->msg->len);
  10438. + bcm2708_wr(bi, BSC_C, c);
  10439. +}
  10440. +
  10441. +static irqreturn_t bcm2708_i2c_interrupt(int irq, void *dev_id)
  10442. +{
  10443. + struct bcm2708_i2c *bi = dev_id;
  10444. + bool handled = true;
  10445. + u32 s;
  10446. +
  10447. + spin_lock(&bi->lock);
  10448. +
  10449. + /* we may see camera interrupts on the "other" I2C channel
  10450. + Just return if we've not sent anything */
  10451. + if (!bi->nmsgs || !bi->msg )
  10452. + goto early_exit;
  10453. +
  10454. + s = bcm2708_rd(bi, BSC_S);
  10455. +
  10456. + if (s & (BSC_S_CLKT | BSC_S_ERR)) {
  10457. + bcm2708_bsc_reset(bi);
  10458. + bi->error = true;
  10459. +
  10460. + /* wake up our bh */
  10461. + complete(&bi->done);
  10462. + } else if (s & BSC_S_DONE) {
  10463. + bi->nmsgs--;
  10464. +
  10465. + if (bi->msg->flags & I2C_M_RD)
  10466. + bcm2708_bsc_fifo_drain(bi);
  10467. +
  10468. + bcm2708_bsc_reset(bi);
  10469. +
  10470. + if (bi->nmsgs) {
  10471. + /* advance to next message */
  10472. + bi->msg++;
  10473. + bi->pos = 0;
  10474. + bcm2708_bsc_setup(bi);
  10475. + } else {
  10476. + /* wake up our bh */
  10477. + complete(&bi->done);
  10478. + }
  10479. + } else if (s & BSC_S_TXW) {
  10480. + bcm2708_bsc_fifo_fill(bi);
  10481. + } else if (s & BSC_S_RXR) {
  10482. + bcm2708_bsc_fifo_drain(bi);
  10483. + } else {
  10484. + handled = false;
  10485. + }
  10486. +
  10487. +early_exit:
  10488. + spin_unlock(&bi->lock);
  10489. +
  10490. + return handled ? IRQ_HANDLED : IRQ_NONE;
  10491. +}
  10492. +
  10493. +static int bcm2708_i2c_master_xfer(struct i2c_adapter *adap,
  10494. + struct i2c_msg *msgs, int num)
  10495. +{
  10496. + struct bcm2708_i2c *bi = adap->algo_data;
  10497. + unsigned long flags;
  10498. + int ret;
  10499. +
  10500. + spin_lock_irqsave(&bi->lock, flags);
  10501. +
  10502. + reinit_completion(&bi->done);
  10503. + bi->msg = msgs;
  10504. + bi->pos = 0;
  10505. + bi->nmsgs = num;
  10506. + bi->error = false;
  10507. +
  10508. + spin_unlock_irqrestore(&bi->lock, flags);
  10509. +
  10510. + bcm2708_bsc_setup(bi);
  10511. +
  10512. + ret = wait_for_completion_timeout(&bi->done,
  10513. + msecs_to_jiffies(I2C_TIMEOUT_MS));
  10514. + if (ret == 0) {
  10515. + dev_err(&adap->dev, "transfer timed out\n");
  10516. + spin_lock_irqsave(&bi->lock, flags);
  10517. + bcm2708_bsc_reset(bi);
  10518. + spin_unlock_irqrestore(&bi->lock, flags);
  10519. + return -ETIMEDOUT;
  10520. + }
  10521. +
  10522. + return bi->error ? -EIO : num;
  10523. +}
  10524. +
  10525. +static u32 bcm2708_i2c_functionality(struct i2c_adapter *adap)
  10526. +{
  10527. + return I2C_FUNC_I2C | /*I2C_FUNC_10BIT_ADDR |*/ I2C_FUNC_SMBUS_EMUL;
  10528. +}
  10529. +
  10530. +static struct i2c_algorithm bcm2708_i2c_algorithm = {
  10531. + .master_xfer = bcm2708_i2c_master_xfer,
  10532. + .functionality = bcm2708_i2c_functionality,
  10533. +};
  10534. +
  10535. +static int bcm2708_i2c_probe(struct platform_device *pdev)
  10536. +{
  10537. + struct resource *regs;
  10538. + int irq, err = -ENOMEM;
  10539. + struct clk *clk;
  10540. + struct bcm2708_i2c *bi;
  10541. + struct i2c_adapter *adap;
  10542. +
  10543. + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  10544. + if (!regs) {
  10545. + dev_err(&pdev->dev, "could not get IO memory\n");
  10546. + return -ENXIO;
  10547. + }
  10548. +
  10549. + irq = platform_get_irq(pdev, 0);
  10550. + if (irq < 0) {
  10551. + dev_err(&pdev->dev, "could not get IRQ\n");
  10552. + return irq;
  10553. + }
  10554. +
  10555. + clk = clk_get(&pdev->dev, NULL);
  10556. + if (IS_ERR(clk)) {
  10557. + dev_err(&pdev->dev, "could not find clk: %ld\n", PTR_ERR(clk));
  10558. + return PTR_ERR(clk);
  10559. + }
  10560. +
  10561. + bcm2708_i2c_init_pinmode(pdev->id);
  10562. +
  10563. + bi = kzalloc(sizeof(*bi), GFP_KERNEL);
  10564. + if (!bi)
  10565. + goto out_clk_put;
  10566. +
  10567. + platform_set_drvdata(pdev, bi);
  10568. +
  10569. + adap = &bi->adapter;
  10570. + adap->class = I2C_CLASS_HWMON | I2C_CLASS_DDC;
  10571. + adap->algo = &bcm2708_i2c_algorithm;
  10572. + adap->algo_data = bi;
  10573. + adap->dev.parent = &pdev->dev;
  10574. + adap->nr = pdev->id;
  10575. + strlcpy(adap->name, dev_name(&pdev->dev), sizeof(adap->name));
  10576. +
  10577. + switch (pdev->id) {
  10578. + case 0:
  10579. + adap->class = I2C_CLASS_HWMON;
  10580. + break;
  10581. + case 1:
  10582. + adap->class = I2C_CLASS_DDC;
  10583. + break;
  10584. + default:
  10585. + dev_err(&pdev->dev, "can only bind to BSC 0 or 1\n");
  10586. + err = -ENXIO;
  10587. + goto out_free_bi;
  10588. + }
  10589. +
  10590. + spin_lock_init(&bi->lock);
  10591. + init_completion(&bi->done);
  10592. +
  10593. + bi->base = ioremap(regs->start, resource_size(regs));
  10594. + if (!bi->base) {
  10595. + dev_err(&pdev->dev, "could not remap memory\n");
  10596. + goto out_free_bi;
  10597. + }
  10598. +
  10599. + bi->irq = irq;
  10600. + bi->clk = clk;
  10601. +
  10602. + err = request_irq(irq, bcm2708_i2c_interrupt, IRQF_SHARED,
  10603. + dev_name(&pdev->dev), bi);
  10604. + if (err) {
  10605. + dev_err(&pdev->dev, "could not request IRQ: %d\n", err);
  10606. + goto out_iounmap;
  10607. + }
  10608. +
  10609. + bcm2708_bsc_reset(bi);
  10610. +
  10611. + err = i2c_add_numbered_adapter(adap);
  10612. + if (err < 0) {
  10613. + dev_err(&pdev->dev, "could not add I2C adapter: %d\n", err);
  10614. + goto out_free_irq;
  10615. + }
  10616. +
  10617. + dev_info(&pdev->dev, "BSC%d Controller at 0x%08lx (irq %d) (baudrate %dk)\n",
  10618. + pdev->id, (unsigned long)regs->start, irq, baudrate/1000);
  10619. +
  10620. + return 0;
  10621. +
  10622. +out_free_irq:
  10623. + free_irq(bi->irq, bi);
  10624. +out_iounmap:
  10625. + iounmap(bi->base);
  10626. +out_free_bi:
  10627. + kfree(bi);
  10628. +out_clk_put:
  10629. + clk_put(clk);
  10630. + return err;
  10631. +}
  10632. +
  10633. +static int bcm2708_i2c_remove(struct platform_device *pdev)
  10634. +{
  10635. + struct bcm2708_i2c *bi = platform_get_drvdata(pdev);
  10636. +
  10637. + platform_set_drvdata(pdev, NULL);
  10638. +
  10639. + i2c_del_adapter(&bi->adapter);
  10640. + free_irq(bi->irq, bi);
  10641. + iounmap(bi->base);
  10642. + clk_disable(bi->clk);
  10643. + clk_put(bi->clk);
  10644. + kfree(bi);
  10645. +
  10646. + return 0;
  10647. +}
  10648. +
  10649. +static struct platform_driver bcm2708_i2c_driver = {
  10650. + .driver = {
  10651. + .name = DRV_NAME,
  10652. + .owner = THIS_MODULE,
  10653. + },
  10654. + .probe = bcm2708_i2c_probe,
  10655. + .remove = bcm2708_i2c_remove,
  10656. +};
  10657. +
  10658. +// module_platform_driver(bcm2708_i2c_driver);
  10659. +
  10660. +
  10661. +static int __init bcm2708_i2c_init(void)
  10662. +{
  10663. + return platform_driver_register(&bcm2708_i2c_driver);
  10664. +}
  10665. +
  10666. +static void __exit bcm2708_i2c_exit(void)
  10667. +{
  10668. + platform_driver_unregister(&bcm2708_i2c_driver);
  10669. +}
  10670. +
  10671. +module_init(bcm2708_i2c_init);
  10672. +module_exit(bcm2708_i2c_exit);
  10673. +
  10674. +
  10675. +
  10676. +MODULE_DESCRIPTION("BSC controller driver for Broadcom BCM2708");
  10677. +MODULE_AUTHOR("Chris Boot <bootc@bootc.net>");
  10678. +MODULE_LICENSE("GPL v2");
  10679. +MODULE_ALIAS("platform:" DRV_NAME);
  10680. diff -Nur linux-3.13.11/drivers/i2c/busses/Kconfig linux-rpi/drivers/i2c/busses/Kconfig
  10681. --- linux-3.13.11/drivers/i2c/busses/Kconfig 2014-04-23 01:49:33.000000000 +0200
  10682. +++ linux-rpi/drivers/i2c/busses/Kconfig 2014-04-24 15:36:48.222715846 +0200
  10683. @@ -347,6 +347,25 @@
  10684. This support is also available as a module. If so, the module
  10685. will be called i2c-bcm2835.
  10686. +config I2C_BCM2708
  10687. + tristate "BCM2708 BSC"
  10688. + depends on MACH_BCM2708
  10689. + help
  10690. + Enabling this option will add BSC (Broadcom Serial Controller)
  10691. + support for the BCM2708. BSC is a Broadcom proprietary bus compatible
  10692. + with I2C/TWI/SMBus.
  10693. +
  10694. +config I2C_BCM2708_BAUDRATE
  10695. + prompt "BCM2708 I2C baudrate"
  10696. + depends on I2C_BCM2708
  10697. + int
  10698. + default 100000
  10699. + help
  10700. + Set the I2C baudrate. This will alter the default value. A
  10701. + different baudrate can be set by using a module parameter as well. If
  10702. + no parameter is provided when loading, this is the value that will be
  10703. + used.
  10704. +
  10705. config I2C_BCM_KONA
  10706. tristate "BCM Kona I2C adapter"
  10707. depends on ARCH_BCM_MOBILE
  10708. diff -Nur linux-3.13.11/drivers/i2c/busses/Makefile linux-rpi/drivers/i2c/busses/Makefile
  10709. --- linux-3.13.11/drivers/i2c/busses/Makefile 2014-04-23 01:49:33.000000000 +0200
  10710. +++ linux-rpi/drivers/i2c/busses/Makefile 2014-04-24 15:36:48.222715846 +0200
  10711. @@ -32,6 +32,7 @@
  10712. obj-$(CONFIG_I2C_AT91) += i2c-at91.o
  10713. obj-$(CONFIG_I2C_AU1550) += i2c-au1550.o
  10714. obj-$(CONFIG_I2C_BCM2835) += i2c-bcm2835.o
  10715. +obj-$(CONFIG_I2C_BCM2708) += i2c-bcm2708.o
  10716. obj-$(CONFIG_I2C_BLACKFIN_TWI) += i2c-bfin-twi.o
  10717. obj-$(CONFIG_I2C_CBUS_GPIO) += i2c-cbus-gpio.o
  10718. obj-$(CONFIG_I2C_CPM) += i2c-cpm.o
  10719. diff -Nur linux-3.13.11/drivers/media/platform/bcm2835/bcm2835-camera.c linux-rpi/drivers/media/platform/bcm2835/bcm2835-camera.c
  10720. --- linux-3.13.11/drivers/media/platform/bcm2835/bcm2835-camera.c 1970-01-01 01:00:00.000000000 +0100
  10721. +++ linux-rpi/drivers/media/platform/bcm2835/bcm2835-camera.c 2014-04-24 15:36:50.070736112 +0200
  10722. @@ -0,0 +1,1695 @@
  10723. +/*
  10724. + * Broadcom BM2835 V4L2 driver
  10725. + *
  10726. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  10727. + *
  10728. + * This file is subject to the terms and conditions of the GNU General Public
  10729. + * License. See the file COPYING in the main directory of this archive
  10730. + * for more details.
  10731. + *
  10732. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  10733. + * Dave Stevenson <dsteve@broadcom.com>
  10734. + * Simon Mellor <simellor@broadcom.com>
  10735. + * Luke Diamand <luked@broadcom.com>
  10736. + */
  10737. +
  10738. +#include <linux/errno.h>
  10739. +#include <linux/kernel.h>
  10740. +#include <linux/module.h>
  10741. +#include <linux/slab.h>
  10742. +#include <media/videobuf2-vmalloc.h>
  10743. +#include <media/videobuf2-dma-contig.h>
  10744. +#include <media/v4l2-device.h>
  10745. +#include <media/v4l2-ioctl.h>
  10746. +#include <media/v4l2-ctrls.h>
  10747. +#include <media/v4l2-fh.h>
  10748. +#include <media/v4l2-event.h>
  10749. +#include <media/v4l2-common.h>
  10750. +#include <linux/delay.h>
  10751. +
  10752. +#include "mmal-common.h"
  10753. +#include "mmal-encodings.h"
  10754. +#include "mmal-vchiq.h"
  10755. +#include "mmal-msg.h"
  10756. +#include "mmal-parameters.h"
  10757. +#include "bcm2835-camera.h"
  10758. +
  10759. +#define BM2835_MMAL_VERSION "0.0.2"
  10760. +#define BM2835_MMAL_MODULE_NAME "bcm2835-v4l2"
  10761. +#define MIN_WIDTH 16
  10762. +#define MIN_HEIGHT 16
  10763. +#define MAX_WIDTH 2592
  10764. +#define MAX_HEIGHT 1944
  10765. +#define MIN_BUFFER_SIZE (80*1024)
  10766. +
  10767. +#define MAX_VIDEO_MODE_WIDTH 1280
  10768. +#define MAX_VIDEO_MODE_HEIGHT 720
  10769. +
  10770. +MODULE_DESCRIPTION("Broadcom 2835 MMAL video capture");
  10771. +MODULE_AUTHOR("Vincent Sanders");
  10772. +MODULE_LICENSE("GPL");
  10773. +MODULE_VERSION(BM2835_MMAL_VERSION);
  10774. +
  10775. +int bcm2835_v4l2_debug;
  10776. +module_param_named(debug, bcm2835_v4l2_debug, int, 0644);
  10777. +MODULE_PARM_DESC(bcm2835_v4l2_debug, "Debug level 0-2");
  10778. +
  10779. +static struct bm2835_mmal_dev *gdev; /* global device data */
  10780. +
  10781. +#define FPS_MIN 1
  10782. +#define FPS_MAX 90
  10783. +
  10784. +/* timeperframe: min/max and default */
  10785. +static const struct v4l2_fract
  10786. + tpf_min = {.numerator = 1, .denominator = FPS_MAX},
  10787. + tpf_max = {.numerator = 1, .denominator = FPS_MIN},
  10788. + tpf_default = {.numerator = 1000, .denominator = 30000};
  10789. +
  10790. +/* video formats */
  10791. +static struct mmal_fmt formats[] = {
  10792. + {
  10793. + .name = "4:2:0, packed YUV",
  10794. + .fourcc = V4L2_PIX_FMT_YUV420,
  10795. + .flags = 0,
  10796. + .mmal = MMAL_ENCODING_I420,
  10797. + .depth = 12,
  10798. + .mmal_component = MMAL_COMPONENT_CAMERA,
  10799. + },
  10800. + {
  10801. + .name = "4:2:2, packed, YUYV",
  10802. + .fourcc = V4L2_PIX_FMT_YUYV,
  10803. + .flags = 0,
  10804. + .mmal = MMAL_ENCODING_YUYV,
  10805. + .depth = 16,
  10806. + .mmal_component = MMAL_COMPONENT_CAMERA,
  10807. + },
  10808. + {
  10809. + .name = "RGB24 (LE)",
  10810. + .fourcc = V4L2_PIX_FMT_RGB24,
  10811. + .flags = 0,
  10812. + .mmal = MMAL_ENCODING_BGR24,
  10813. + .depth = 24,
  10814. + .mmal_component = MMAL_COMPONENT_CAMERA,
  10815. + },
  10816. + {
  10817. + .name = "JPEG",
  10818. + .fourcc = V4L2_PIX_FMT_JPEG,
  10819. + .flags = V4L2_FMT_FLAG_COMPRESSED,
  10820. + .mmal = MMAL_ENCODING_JPEG,
  10821. + .depth = 8,
  10822. + .mmal_component = MMAL_COMPONENT_IMAGE_ENCODE,
  10823. + },
  10824. + {
  10825. + .name = "H264",
  10826. + .fourcc = V4L2_PIX_FMT_H264,
  10827. + .flags = V4L2_FMT_FLAG_COMPRESSED,
  10828. + .mmal = MMAL_ENCODING_H264,
  10829. + .depth = 8,
  10830. + .mmal_component = MMAL_COMPONENT_VIDEO_ENCODE,
  10831. + },
  10832. + {
  10833. + .name = "MJPEG",
  10834. + .fourcc = V4L2_PIX_FMT_MJPEG,
  10835. + .flags = V4L2_FMT_FLAG_COMPRESSED,
  10836. + .mmal = MMAL_ENCODING_MJPEG,
  10837. + .depth = 8,
  10838. + .mmal_component = MMAL_COMPONENT_VIDEO_ENCODE,
  10839. + },
  10840. + {
  10841. + .name = "4:2:2, packed, YVYU",
  10842. + .fourcc = V4L2_PIX_FMT_YVYU,
  10843. + .flags = 0,
  10844. + .mmal = MMAL_ENCODING_YVYU,
  10845. + .depth = 16,
  10846. + .mmal_component = MMAL_COMPONENT_CAMERA,
  10847. + },
  10848. + {
  10849. + .name = "4:2:2, packed, VYUY",
  10850. + .fourcc = V4L2_PIX_FMT_VYUY,
  10851. + .flags = 0,
  10852. + .mmal = MMAL_ENCODING_VYUY,
  10853. + .depth = 16,
  10854. + .mmal_component = MMAL_COMPONENT_CAMERA,
  10855. + },
  10856. + {
  10857. + .name = "4:2:2, packed, UYVY",
  10858. + .fourcc = V4L2_PIX_FMT_UYVY,
  10859. + .flags = 0,
  10860. + .mmal = MMAL_ENCODING_UYVY,
  10861. + .depth = 16,
  10862. + .mmal_component = MMAL_COMPONENT_CAMERA,
  10863. + },
  10864. + {
  10865. + .name = "4:2:0, packed, NV12",
  10866. + .fourcc = V4L2_PIX_FMT_NV12,
  10867. + .flags = 0,
  10868. + .mmal = MMAL_ENCODING_NV12,
  10869. + .depth = 12,
  10870. + .mmal_component = MMAL_COMPONENT_CAMERA,
  10871. + },
  10872. +};
  10873. +
  10874. +static struct mmal_fmt *get_format(struct v4l2_format *f)
  10875. +{
  10876. + struct mmal_fmt *fmt;
  10877. + unsigned int k;
  10878. +
  10879. + for (k = 0; k < ARRAY_SIZE(formats); k++) {
  10880. + fmt = &formats[k];
  10881. + if (fmt->fourcc == f->fmt.pix.pixelformat)
  10882. + break;
  10883. + }
  10884. +
  10885. + if (k == ARRAY_SIZE(formats))
  10886. + return NULL;
  10887. +
  10888. + return &formats[k];
  10889. +}
  10890. +
  10891. +/* ------------------------------------------------------------------
  10892. + Videobuf queue operations
  10893. + ------------------------------------------------------------------*/
  10894. +
  10895. +static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
  10896. + unsigned int *nbuffers, unsigned int *nplanes,
  10897. + unsigned int sizes[], void *alloc_ctxs[])
  10898. +{
  10899. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  10900. + unsigned long size;
  10901. +
  10902. + /* refuse queue setup if port is not configured */
  10903. + if (dev->capture.port == NULL) {
  10904. + v4l2_err(&dev->v4l2_dev,
  10905. + "%s: capture port not configured\n", __func__);
  10906. + return -EINVAL;
  10907. + }
  10908. +
  10909. + size = dev->capture.port->current_buffer.size;
  10910. + if (size == 0) {
  10911. + v4l2_err(&dev->v4l2_dev,
  10912. + "%s: capture port buffer size is zero\n", __func__);
  10913. + return -EINVAL;
  10914. + }
  10915. +
  10916. + if (*nbuffers < (dev->capture.port->current_buffer.num + 2))
  10917. + *nbuffers = (dev->capture.port->current_buffer.num + 2);
  10918. +
  10919. + *nplanes = 1;
  10920. +
  10921. + sizes[0] = size;
  10922. +
  10923. + /*
  10924. + * videobuf2-vmalloc allocator is context-less so no need to set
  10925. + * alloc_ctxs array.
  10926. + */
  10927. +
  10928. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
  10929. + __func__, dev);
  10930. +
  10931. + return 0;
  10932. +}
  10933. +
  10934. +static int buffer_prepare(struct vb2_buffer *vb)
  10935. +{
  10936. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
  10937. + unsigned long size;
  10938. +
  10939. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
  10940. + __func__, dev);
  10941. +
  10942. + BUG_ON(dev->capture.port == NULL);
  10943. + BUG_ON(dev->capture.fmt == NULL);
  10944. +
  10945. + size = dev->capture.stride * dev->capture.height;
  10946. + if (vb2_plane_size(vb, 0) < size) {
  10947. + v4l2_err(&dev->v4l2_dev,
  10948. + "%s data will not fit into plane (%lu < %lu)\n",
  10949. + __func__, vb2_plane_size(vb, 0), size);
  10950. + return -EINVAL;
  10951. + }
  10952. +
  10953. + return 0;
  10954. +}
  10955. +
  10956. +static inline bool is_capturing(struct bm2835_mmal_dev *dev)
  10957. +{
  10958. + return dev->capture.camera_port ==
  10959. + &dev->
  10960. + component[MMAL_COMPONENT_CAMERA]->output[MMAL_CAMERA_PORT_CAPTURE];
  10961. +}
  10962. +
  10963. +static void buffer_cb(struct vchiq_mmal_instance *instance,
  10964. + struct vchiq_mmal_port *port,
  10965. + int status,
  10966. + struct mmal_buffer *buf,
  10967. + unsigned long length, u32 mmal_flags, s64 dts, s64 pts)
  10968. +{
  10969. + struct bm2835_mmal_dev *dev = port->cb_ctx;
  10970. +
  10971. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  10972. + "%s: status:%d, buf:%p, length:%lu, flags %u, pts %lld\n",
  10973. + __func__, status, buf, length, mmal_flags, pts);
  10974. +
  10975. + if (status != 0) {
  10976. + /* error in transfer */
  10977. + if (buf != NULL) {
  10978. + /* there was a buffer with the error so return it */
  10979. + vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
  10980. + }
  10981. + return;
  10982. + } else if (length == 0) {
  10983. + /* stream ended */
  10984. + if (buf != NULL) {
  10985. + /* this should only ever happen if the port is
  10986. + * disabled and there are buffers still queued
  10987. + */
  10988. + vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
  10989. + pr_debug("Empty buffer");
  10990. + } else if (dev->capture.frame_count) {
  10991. + /* grab another frame */
  10992. + if (is_capturing(dev)) {
  10993. + pr_debug("Grab another frame");
  10994. + vchiq_mmal_port_parameter_set(
  10995. + instance,
  10996. + dev->capture.
  10997. + camera_port,
  10998. + MMAL_PARAMETER_CAPTURE,
  10999. + &dev->capture.
  11000. + frame_count,
  11001. + sizeof(dev->capture.frame_count));
  11002. + }
  11003. + } else {
  11004. + /* signal frame completion */
  11005. + complete(&dev->capture.frame_cmplt);
  11006. + }
  11007. + } else {
  11008. + if (dev->capture.frame_count) {
  11009. + if (dev->capture.vc_start_timestamp != -1 &&
  11010. + pts != 0) {
  11011. + s64 runtime_us = pts -
  11012. + dev->capture.vc_start_timestamp;
  11013. + u32 div = 0;
  11014. + u32 rem = 0;
  11015. +
  11016. + div =
  11017. + div_u64_rem(runtime_us, USEC_PER_SEC, &rem);
  11018. + buf->vb.v4l2_buf.timestamp.tv_sec =
  11019. + dev->capture.kernel_start_ts.tv_sec - 1 +
  11020. + div;
  11021. + buf->vb.v4l2_buf.timestamp.tv_usec =
  11022. + dev->capture.kernel_start_ts.tv_usec + rem;
  11023. +
  11024. + if (buf->vb.v4l2_buf.timestamp.tv_usec >=
  11025. + USEC_PER_SEC) {
  11026. + buf->vb.v4l2_buf.timestamp.tv_sec++;
  11027. + buf->vb.v4l2_buf.timestamp.tv_usec -=
  11028. + USEC_PER_SEC;
  11029. + }
  11030. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11031. + "Convert start time %d.%06d and %llu "
  11032. + "with offset %llu to %d.%06d\n",
  11033. + (int)dev->capture.kernel_start_ts.
  11034. + tv_sec,
  11035. + (int)dev->capture.kernel_start_ts.
  11036. + tv_usec,
  11037. + dev->capture.vc_start_timestamp, pts,
  11038. + (int)buf->vb.v4l2_buf.timestamp.tv_sec,
  11039. + (int)buf->vb.v4l2_buf.timestamp.
  11040. + tv_usec);
  11041. + } else {
  11042. + v4l2_get_timestamp(&buf->vb.v4l2_buf.timestamp);
  11043. + }
  11044. +
  11045. + vb2_set_plane_payload(&buf->vb, 0, length);
  11046. + vb2_buffer_done(&buf->vb, VB2_BUF_STATE_DONE);
  11047. +
  11048. + if (mmal_flags & MMAL_BUFFER_HEADER_FLAG_EOS &&
  11049. + is_capturing(dev)) {
  11050. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11051. + "Grab another frame as buffer has EOS");
  11052. + vchiq_mmal_port_parameter_set(
  11053. + instance,
  11054. + dev->capture.
  11055. + camera_port,
  11056. + MMAL_PARAMETER_CAPTURE,
  11057. + &dev->capture.
  11058. + frame_count,
  11059. + sizeof(dev->capture.frame_count));
  11060. + }
  11061. + } else {
  11062. + /* signal frame completion */
  11063. + complete(&dev->capture.frame_cmplt);
  11064. + }
  11065. + }
  11066. +}
  11067. +
  11068. +static int enable_camera(struct bm2835_mmal_dev *dev)
  11069. +{
  11070. + int ret;
  11071. + if (!dev->camera_use_count) {
  11072. + ret = vchiq_mmal_component_enable(
  11073. + dev->instance,
  11074. + dev->component[MMAL_COMPONENT_CAMERA]);
  11075. + if (ret < 0) {
  11076. + v4l2_err(&dev->v4l2_dev,
  11077. + "Failed enabling camera, ret %d\n", ret);
  11078. + return -EINVAL;
  11079. + }
  11080. + }
  11081. + dev->camera_use_count++;
  11082. + v4l2_dbg(1, bcm2835_v4l2_debug,
  11083. + &dev->v4l2_dev, "enabled camera (refcount %d)\n",
  11084. + dev->camera_use_count);
  11085. + return 0;
  11086. +}
  11087. +
  11088. +static int disable_camera(struct bm2835_mmal_dev *dev)
  11089. +{
  11090. + int ret;
  11091. + if (!dev->camera_use_count) {
  11092. + v4l2_err(&dev->v4l2_dev,
  11093. + "Disabled the camera when already disabled\n");
  11094. + return -EINVAL;
  11095. + }
  11096. + dev->camera_use_count--;
  11097. + if (!dev->camera_use_count) {
  11098. + unsigned int i = 0xFFFFFFFF;
  11099. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11100. + "Disabling camera\n");
  11101. + ret =
  11102. + vchiq_mmal_component_disable(
  11103. + dev->instance,
  11104. + dev->component[MMAL_COMPONENT_CAMERA]);
  11105. + if (ret < 0) {
  11106. + v4l2_err(&dev->v4l2_dev,
  11107. + "Failed disabling camera, ret %d\n", ret);
  11108. + return -EINVAL;
  11109. + }
  11110. + vchiq_mmal_port_parameter_set(
  11111. + dev->instance,
  11112. + &dev->component[MMAL_COMPONENT_CAMERA]->control,
  11113. + MMAL_PARAMETER_CAMERA_NUM, &i,
  11114. + sizeof(i));
  11115. + }
  11116. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11117. + "Camera refcount now %d\n", dev->camera_use_count);
  11118. + return 0;
  11119. +}
  11120. +
  11121. +static void buffer_queue(struct vb2_buffer *vb)
  11122. +{
  11123. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
  11124. + struct mmal_buffer *buf = container_of(vb, struct mmal_buffer, vb);
  11125. + int ret;
  11126. +
  11127. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11128. + "%s: dev:%p buf:%p\n", __func__, dev, buf);
  11129. +
  11130. + buf->buffer = vb2_plane_vaddr(&buf->vb, 0);
  11131. + buf->buffer_size = vb2_plane_size(&buf->vb, 0);
  11132. +
  11133. + ret = vchiq_mmal_submit_buffer(dev->instance, dev->capture.port, buf);
  11134. + if (ret < 0)
  11135. + v4l2_err(&dev->v4l2_dev, "%s: error submitting buffer\n",
  11136. + __func__);
  11137. +}
  11138. +
  11139. +static int start_streaming(struct vb2_queue *vq, unsigned int count)
  11140. +{
  11141. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  11142. + int ret;
  11143. + int parameter_size;
  11144. +
  11145. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
  11146. + __func__, dev);
  11147. +
  11148. + /* ensure a format has actually been set */
  11149. + if (dev->capture.port == NULL)
  11150. + return -EINVAL;
  11151. +
  11152. + if (enable_camera(dev) < 0) {
  11153. + v4l2_err(&dev->v4l2_dev, "Failed to enable camera\n");
  11154. + return -EINVAL;
  11155. + }
  11156. +
  11157. + /*init_completion(&dev->capture.frame_cmplt); */
  11158. +
  11159. + /* enable frame capture */
  11160. + dev->capture.frame_count = 1;
  11161. +
  11162. + /* if the preview is not already running, wait for a few frames for AGC
  11163. + * to settle down.
  11164. + */
  11165. + if (!dev->component[MMAL_COMPONENT_PREVIEW]->enabled)
  11166. + msleep(300);
  11167. +
  11168. + /* enable the connection from camera to encoder (if applicable) */
  11169. + if (dev->capture.camera_port != dev->capture.port
  11170. + && dev->capture.camera_port) {
  11171. + ret = vchiq_mmal_port_enable(dev->instance,
  11172. + dev->capture.camera_port, NULL);
  11173. + if (ret) {
  11174. + v4l2_err(&dev->v4l2_dev,
  11175. + "Failed to enable encode tunnel - error %d\n",
  11176. + ret);
  11177. + return -1;
  11178. + }
  11179. + }
  11180. +
  11181. + /* Get VC timestamp at this point in time */
  11182. + parameter_size = sizeof(dev->capture.vc_start_timestamp);
  11183. + if (vchiq_mmal_port_parameter_get(dev->instance,
  11184. + dev->capture.camera_port,
  11185. + MMAL_PARAMETER_SYSTEM_TIME,
  11186. + &dev->capture.vc_start_timestamp,
  11187. + &parameter_size)) {
  11188. + v4l2_err(&dev->v4l2_dev,
  11189. + "Failed to get VC start time - update your VC f/w\n");
  11190. +
  11191. + /* Flag to indicate just to rely on kernel timestamps */
  11192. + dev->capture.vc_start_timestamp = -1;
  11193. + } else
  11194. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11195. + "Start time %lld size %d\n",
  11196. + dev->capture.vc_start_timestamp, parameter_size);
  11197. +
  11198. + v4l2_get_timestamp(&dev->capture.kernel_start_ts);
  11199. +
  11200. + /* enable the camera port */
  11201. + dev->capture.port->cb_ctx = dev;
  11202. + ret =
  11203. + vchiq_mmal_port_enable(dev->instance, dev->capture.port, buffer_cb);
  11204. + if (ret) {
  11205. + v4l2_err(&dev->v4l2_dev,
  11206. + "Failed to enable capture port - error %d. "
  11207. + "Disabling camera port again\n", ret);
  11208. +
  11209. + vchiq_mmal_port_disable(dev->instance,
  11210. + dev->capture.camera_port);
  11211. + if (disable_camera(dev) < 0) {
  11212. + v4l2_err(&dev->v4l2_dev, "Failed to disable camera");
  11213. + return -EINVAL;
  11214. + }
  11215. + return -1;
  11216. + }
  11217. +
  11218. + /* capture the first frame */
  11219. + vchiq_mmal_port_parameter_set(dev->instance,
  11220. + dev->capture.camera_port,
  11221. + MMAL_PARAMETER_CAPTURE,
  11222. + &dev->capture.frame_count,
  11223. + sizeof(dev->capture.frame_count));
  11224. + return 0;
  11225. +}
  11226. +
  11227. +/* abort streaming and wait for last buffer */
  11228. +static int stop_streaming(struct vb2_queue *vq)
  11229. +{
  11230. + int ret;
  11231. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  11232. +
  11233. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
  11234. + __func__, dev);
  11235. +
  11236. + init_completion(&dev->capture.frame_cmplt);
  11237. + dev->capture.frame_count = 0;
  11238. +
  11239. + /* ensure a format has actually been set */
  11240. + if (dev->capture.port == NULL)
  11241. + return -EINVAL;
  11242. +
  11243. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "stopping capturing\n");
  11244. +
  11245. + /* stop capturing frames */
  11246. + vchiq_mmal_port_parameter_set(dev->instance,
  11247. + dev->capture.camera_port,
  11248. + MMAL_PARAMETER_CAPTURE,
  11249. + &dev->capture.frame_count,
  11250. + sizeof(dev->capture.frame_count));
  11251. +
  11252. + /* wait for last frame to complete */
  11253. + ret = wait_for_completion_timeout(&dev->capture.frame_cmplt, HZ);
  11254. + if (ret <= 0)
  11255. + v4l2_err(&dev->v4l2_dev,
  11256. + "error %d waiting for frame completion\n", ret);
  11257. +
  11258. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11259. + "disabling connection\n");
  11260. +
  11261. + /* disable the connection from camera to encoder */
  11262. + ret = vchiq_mmal_port_disable(dev->instance, dev->capture.camera_port);
  11263. + if (!ret && dev->capture.camera_port != dev->capture.port) {
  11264. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11265. + "disabling port\n");
  11266. + ret = vchiq_mmal_port_disable(dev->instance, dev->capture.port);
  11267. + } else if (dev->capture.camera_port != dev->capture.port) {
  11268. + v4l2_err(&dev->v4l2_dev, "port_disable failed, error %d\n",
  11269. + ret);
  11270. + }
  11271. +
  11272. + if (disable_camera(dev) < 0) {
  11273. + v4l2_err(&dev->v4l2_dev, "Failed to disable camera");
  11274. + return -EINVAL;
  11275. + }
  11276. +
  11277. + return ret;
  11278. +}
  11279. +
  11280. +static void bm2835_mmal_lock(struct vb2_queue *vq)
  11281. +{
  11282. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  11283. + mutex_lock(&dev->mutex);
  11284. +}
  11285. +
  11286. +static void bm2835_mmal_unlock(struct vb2_queue *vq)
  11287. +{
  11288. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  11289. + mutex_unlock(&dev->mutex);
  11290. +}
  11291. +
  11292. +static struct vb2_ops bm2835_mmal_video_qops = {
  11293. + .queue_setup = queue_setup,
  11294. + .buf_prepare = buffer_prepare,
  11295. + .buf_queue = buffer_queue,
  11296. + .start_streaming = start_streaming,
  11297. + .stop_streaming = stop_streaming,
  11298. + .wait_prepare = bm2835_mmal_unlock,
  11299. + .wait_finish = bm2835_mmal_lock,
  11300. +};
  11301. +
  11302. +/* ------------------------------------------------------------------
  11303. + IOCTL operations
  11304. + ------------------------------------------------------------------*/
  11305. +
  11306. +/* overlay ioctl */
  11307. +static int vidioc_enum_fmt_vid_overlay(struct file *file, void *priv,
  11308. + struct v4l2_fmtdesc *f)
  11309. +{
  11310. + struct mmal_fmt *fmt;
  11311. +
  11312. + if (f->index >= ARRAY_SIZE(formats))
  11313. + return -EINVAL;
  11314. +
  11315. + fmt = &formats[f->index];
  11316. +
  11317. + strlcpy(f->description, fmt->name, sizeof(f->description));
  11318. + f->pixelformat = fmt->fourcc;
  11319. + f->flags = fmt->flags;
  11320. +
  11321. + return 0;
  11322. +}
  11323. +
  11324. +static int vidioc_g_fmt_vid_overlay(struct file *file, void *priv,
  11325. + struct v4l2_format *f)
  11326. +{
  11327. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  11328. +
  11329. + f->fmt.win = dev->overlay;
  11330. +
  11331. + return 0;
  11332. +}
  11333. +
  11334. +static int vidioc_try_fmt_vid_overlay(struct file *file, void *priv,
  11335. + struct v4l2_format *f)
  11336. +{
  11337. + /* Only support one format so get the current one. */
  11338. + vidioc_g_fmt_vid_overlay(file, priv, f);
  11339. +
  11340. + /* todo: allow the size and/or offset to be changed. */
  11341. + return 0;
  11342. +}
  11343. +
  11344. +static int vidioc_s_fmt_vid_overlay(struct file *file, void *priv,
  11345. + struct v4l2_format *f)
  11346. +{
  11347. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  11348. +
  11349. + vidioc_try_fmt_vid_overlay(file, priv, f);
  11350. +
  11351. + dev->overlay = f->fmt.win;
  11352. +
  11353. + /* todo: program the preview port parameters */
  11354. + return 0;
  11355. +}
  11356. +
  11357. +static int vidioc_overlay(struct file *file, void *f, unsigned int on)
  11358. +{
  11359. + int ret;
  11360. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  11361. + struct vchiq_mmal_port *src;
  11362. + struct vchiq_mmal_port *dst;
  11363. + struct mmal_parameter_displayregion prev_config = {
  11364. + .set = MMAL_DISPLAY_SET_LAYER | MMAL_DISPLAY_SET_ALPHA |
  11365. + MMAL_DISPLAY_SET_DEST_RECT | MMAL_DISPLAY_SET_FULLSCREEN,
  11366. + .layer = PREVIEW_LAYER,
  11367. + .alpha = 255,
  11368. + .fullscreen = 0,
  11369. + .dest_rect = {
  11370. + .x = dev->overlay.w.left,
  11371. + .y = dev->overlay.w.top,
  11372. + .width = dev->overlay.w.width,
  11373. + .height = dev->overlay.w.height,
  11374. + },
  11375. + };
  11376. +
  11377. + if ((on && dev->component[MMAL_COMPONENT_PREVIEW]->enabled) ||
  11378. + (!on && !dev->component[MMAL_COMPONENT_PREVIEW]->enabled))
  11379. + return 0; /* already in requested state */
  11380. +
  11381. + src =
  11382. + &dev->component[MMAL_COMPONENT_CAMERA]->
  11383. + output[MMAL_CAMERA_PORT_PREVIEW];
  11384. +
  11385. + if (!on) {
  11386. + /* disconnect preview ports and disable component */
  11387. + ret = vchiq_mmal_port_disable(dev->instance, src);
  11388. + if (!ret)
  11389. + ret =
  11390. + vchiq_mmal_port_connect_tunnel(dev->instance, src,
  11391. + NULL);
  11392. + if (ret >= 0)
  11393. + ret = vchiq_mmal_component_disable(
  11394. + dev->instance,
  11395. + dev->component[MMAL_COMPONENT_PREVIEW]);
  11396. +
  11397. + disable_camera(dev);
  11398. + return ret;
  11399. + }
  11400. +
  11401. + /* set preview port format and connect it to output */
  11402. + dst = &dev->component[MMAL_COMPONENT_PREVIEW]->input[0];
  11403. +
  11404. + ret = vchiq_mmal_port_set_format(dev->instance, src);
  11405. + if (ret < 0)
  11406. + goto error;
  11407. +
  11408. + ret = vchiq_mmal_port_parameter_set(dev->instance, dst,
  11409. + MMAL_PARAMETER_DISPLAYREGION,
  11410. + &prev_config, sizeof(prev_config));
  11411. + if (ret < 0)
  11412. + goto error;
  11413. +
  11414. + if (enable_camera(dev) < 0)
  11415. + goto error;
  11416. +
  11417. + ret = vchiq_mmal_component_enable(
  11418. + dev->instance,
  11419. + dev->component[MMAL_COMPONENT_PREVIEW]);
  11420. + if (ret < 0)
  11421. + goto error;
  11422. +
  11423. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "connecting %p to %p\n",
  11424. + src, dst);
  11425. + ret = vchiq_mmal_port_connect_tunnel(dev->instance, src, dst);
  11426. + if (!ret)
  11427. + ret = vchiq_mmal_port_enable(dev->instance, src, NULL);
  11428. +error:
  11429. + return ret;
  11430. +}
  11431. +
  11432. +static int vidioc_g_fbuf(struct file *file, void *fh,
  11433. + struct v4l2_framebuffer *a)
  11434. +{
  11435. + /* The video overlay must stay within the framebuffer and can't be
  11436. + positioned independently. */
  11437. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  11438. + struct vchiq_mmal_port *preview_port =
  11439. + &dev->component[MMAL_COMPONENT_CAMERA]->
  11440. + output[MMAL_CAMERA_PORT_PREVIEW];
  11441. + a->flags = V4L2_FBUF_FLAG_OVERLAY;
  11442. + a->fmt.width = preview_port->es.video.width;
  11443. + a->fmt.height = preview_port->es.video.height;
  11444. + a->fmt.pixelformat = V4L2_PIX_FMT_YUV420;
  11445. + a->fmt.bytesperline = (preview_port->es.video.width * 3)>>1;
  11446. + a->fmt.sizeimage = (preview_port->es.video.width *
  11447. + preview_port->es.video.height * 3)>>1;
  11448. + a->fmt.colorspace = V4L2_COLORSPACE_JPEG;
  11449. +
  11450. + return 0;
  11451. +}
  11452. +
  11453. +/* input ioctls */
  11454. +static int vidioc_enum_input(struct file *file, void *priv,
  11455. + struct v4l2_input *inp)
  11456. +{
  11457. + /* only a single camera input */
  11458. + if (inp->index != 0)
  11459. + return -EINVAL;
  11460. +
  11461. + inp->type = V4L2_INPUT_TYPE_CAMERA;
  11462. + sprintf(inp->name, "Camera %u", inp->index);
  11463. + return 0;
  11464. +}
  11465. +
  11466. +static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
  11467. +{
  11468. + *i = 0;
  11469. + return 0;
  11470. +}
  11471. +
  11472. +static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
  11473. +{
  11474. + if (i != 0)
  11475. + return -EINVAL;
  11476. +
  11477. + return 0;
  11478. +}
  11479. +
  11480. +/* capture ioctls */
  11481. +static int vidioc_querycap(struct file *file, void *priv,
  11482. + struct v4l2_capability *cap)
  11483. +{
  11484. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  11485. + u32 major;
  11486. + u32 minor;
  11487. +
  11488. + vchiq_mmal_version(dev->instance, &major, &minor);
  11489. +
  11490. + strcpy(cap->driver, "bm2835 mmal");
  11491. + snprintf(cap->card, sizeof(cap->card), "mmal service %d.%d",
  11492. + major, minor);
  11493. +
  11494. + snprintf(cap->bus_info, sizeof(cap->bus_info),
  11495. + "platform:%s", dev->v4l2_dev.name);
  11496. + cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_OVERLAY |
  11497. + V4L2_CAP_STREAMING | V4L2_CAP_READWRITE;
  11498. + cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
  11499. +
  11500. + return 0;
  11501. +}
  11502. +
  11503. +static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
  11504. + struct v4l2_fmtdesc *f)
  11505. +{
  11506. + struct mmal_fmt *fmt;
  11507. +
  11508. + if (f->index >= ARRAY_SIZE(formats))
  11509. + return -EINVAL;
  11510. +
  11511. + fmt = &formats[f->index];
  11512. +
  11513. + strlcpy(f->description, fmt->name, sizeof(f->description));
  11514. + f->pixelformat = fmt->fourcc;
  11515. + f->flags = fmt->flags;
  11516. +
  11517. + return 0;
  11518. +}
  11519. +
  11520. +static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
  11521. + struct v4l2_format *f)
  11522. +{
  11523. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  11524. +
  11525. + f->fmt.pix.width = dev->capture.width;
  11526. + f->fmt.pix.height = dev->capture.height;
  11527. + f->fmt.pix.field = V4L2_FIELD_NONE;
  11528. + f->fmt.pix.pixelformat = dev->capture.fmt->fourcc;
  11529. + f->fmt.pix.bytesperline =
  11530. + (f->fmt.pix.width * dev->capture.fmt->depth) >> 3;
  11531. + f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline;
  11532. + if (dev->capture.fmt->fourcc == V4L2_PIX_FMT_JPEG
  11533. + && f->fmt.pix.sizeimage < (100 << 10)) {
  11534. + /* Need a minimum size for JPEG to account for EXIF. */
  11535. + f->fmt.pix.sizeimage = (100 << 10);
  11536. + }
  11537. +
  11538. + if (dev->capture.fmt->fourcc == V4L2_PIX_FMT_YUYV ||
  11539. + dev->capture.fmt->fourcc == V4L2_PIX_FMT_UYVY)
  11540. + f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
  11541. + else
  11542. + f->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
  11543. + f->fmt.pix.priv = 0;
  11544. +
  11545. + v4l2_dump_pix_format(1, bcm2835_v4l2_debug, &dev->v4l2_dev, &f->fmt.pix,
  11546. + __func__);
  11547. + return 0;
  11548. +}
  11549. +
  11550. +static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
  11551. + struct v4l2_format *f)
  11552. +{
  11553. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  11554. + struct mmal_fmt *mfmt;
  11555. +
  11556. + mfmt = get_format(f);
  11557. + if (!mfmt) {
  11558. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11559. + "Fourcc format (0x%08x) unknown.\n",
  11560. + f->fmt.pix.pixelformat);
  11561. + f->fmt.pix.pixelformat = formats[0].fourcc;
  11562. + mfmt = get_format(f);
  11563. + }
  11564. +
  11565. + f->fmt.pix.field = V4L2_FIELD_NONE;
  11566. + /* image must be a multiple of 32 pixels wide and 16 lines high */
  11567. + v4l_bound_align_image(&f->fmt.pix.width, 48, MAX_WIDTH, 5,
  11568. + &f->fmt.pix.height, 32, MAX_HEIGHT, 4, 0);
  11569. + f->fmt.pix.bytesperline = (f->fmt.pix.width * mfmt->depth) >> 3;
  11570. + f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline;
  11571. + if (f->fmt.pix.sizeimage < MIN_BUFFER_SIZE)
  11572. + f->fmt.pix.sizeimage = MIN_BUFFER_SIZE;
  11573. +
  11574. + if (mfmt->fourcc == V4L2_PIX_FMT_YUYV ||
  11575. + mfmt->fourcc == V4L2_PIX_FMT_UYVY)
  11576. + f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
  11577. + else
  11578. + f->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
  11579. + f->fmt.pix.priv = 0;
  11580. +
  11581. + v4l2_dump_pix_format(1, bcm2835_v4l2_debug, &dev->v4l2_dev, &f->fmt.pix,
  11582. + __func__);
  11583. + return 0;
  11584. +}
  11585. +
  11586. +static int mmal_setup_components(struct bm2835_mmal_dev *dev,
  11587. + struct v4l2_format *f)
  11588. +{
  11589. + int ret;
  11590. + struct vchiq_mmal_port *port = NULL, *camera_port = NULL;
  11591. + struct vchiq_mmal_component *encode_component = NULL;
  11592. + struct mmal_fmt *mfmt = get_format(f);
  11593. +
  11594. + BUG_ON(!mfmt);
  11595. +
  11596. + if (dev->capture.encode_component) {
  11597. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11598. + "vid_cap - disconnect previous tunnel\n");
  11599. +
  11600. + /* Disconnect any previous connection */
  11601. + vchiq_mmal_port_connect_tunnel(dev->instance,
  11602. + dev->capture.camera_port, NULL);
  11603. + dev->capture.camera_port = NULL;
  11604. + ret = vchiq_mmal_component_disable(dev->instance,
  11605. + dev->capture.
  11606. + encode_component);
  11607. + if (ret)
  11608. + v4l2_err(&dev->v4l2_dev,
  11609. + "Failed to disable encode component %d\n",
  11610. + ret);
  11611. +
  11612. + dev->capture.encode_component = NULL;
  11613. + }
  11614. + /* format dependant port setup */
  11615. + switch (mfmt->mmal_component) {
  11616. + case MMAL_COMPONENT_CAMERA:
  11617. + /* Make a further decision on port based on resolution */
  11618. + if (f->fmt.pix.width <= MAX_VIDEO_MODE_WIDTH
  11619. + && f->fmt.pix.height <= MAX_VIDEO_MODE_HEIGHT)
  11620. + camera_port = port =
  11621. + &dev->component[MMAL_COMPONENT_CAMERA]->
  11622. + output[MMAL_CAMERA_PORT_VIDEO];
  11623. + else
  11624. + camera_port = port =
  11625. + &dev->component[MMAL_COMPONENT_CAMERA]->
  11626. + output[MMAL_CAMERA_PORT_CAPTURE];
  11627. + break;
  11628. + case MMAL_COMPONENT_IMAGE_ENCODE:
  11629. + encode_component = dev->component[MMAL_COMPONENT_IMAGE_ENCODE];
  11630. + port = &dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->output[0];
  11631. + camera_port =
  11632. + &dev->component[MMAL_COMPONENT_CAMERA]->
  11633. + output[MMAL_CAMERA_PORT_CAPTURE];
  11634. + break;
  11635. + case MMAL_COMPONENT_VIDEO_ENCODE:
  11636. + encode_component = dev->component[MMAL_COMPONENT_VIDEO_ENCODE];
  11637. + port = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  11638. + camera_port =
  11639. + &dev->component[MMAL_COMPONENT_CAMERA]->
  11640. + output[MMAL_CAMERA_PORT_VIDEO];
  11641. + break;
  11642. + default:
  11643. + break;
  11644. + }
  11645. +
  11646. + if (!port)
  11647. + return -EINVAL;
  11648. +
  11649. + if (encode_component)
  11650. + camera_port->format.encoding = MMAL_ENCODING_OPAQUE;
  11651. + else
  11652. + camera_port->format.encoding = mfmt->mmal;
  11653. +
  11654. + camera_port->format.encoding_variant = 0;
  11655. + camera_port->es.video.width = f->fmt.pix.width;
  11656. + camera_port->es.video.height = f->fmt.pix.height;
  11657. + camera_port->es.video.crop.x = 0;
  11658. + camera_port->es.video.crop.y = 0;
  11659. + camera_port->es.video.crop.width = f->fmt.pix.width;
  11660. + camera_port->es.video.crop.height = f->fmt.pix.height;
  11661. + camera_port->es.video.frame_rate.num = 0;
  11662. + camera_port->es.video.frame_rate.den = 1;
  11663. +
  11664. + ret = vchiq_mmal_port_set_format(dev->instance, camera_port);
  11665. +
  11666. + if (!ret
  11667. + && camera_port ==
  11668. + &dev->component[MMAL_COMPONENT_CAMERA]->
  11669. + output[MMAL_CAMERA_PORT_VIDEO]) {
  11670. + bool overlay_enabled =
  11671. + !!dev->component[MMAL_COMPONENT_PREVIEW]->enabled;
  11672. + struct vchiq_mmal_port *preview_port =
  11673. + &dev->component[MMAL_COMPONENT_CAMERA]->
  11674. + output[MMAL_CAMERA_PORT_PREVIEW];
  11675. + /* Preview and encode ports need to match on resolution */
  11676. + if (overlay_enabled) {
  11677. + /* Need to disable the overlay before we can update
  11678. + * the resolution
  11679. + */
  11680. + ret =
  11681. + vchiq_mmal_port_disable(dev->instance,
  11682. + preview_port);
  11683. + if (!ret)
  11684. + ret =
  11685. + vchiq_mmal_port_connect_tunnel(
  11686. + dev->instance,
  11687. + preview_port,
  11688. + NULL);
  11689. + }
  11690. + preview_port->es.video.width = f->fmt.pix.width;
  11691. + preview_port->es.video.height = f->fmt.pix.height;
  11692. + preview_port->es.video.crop.x = 0;
  11693. + preview_port->es.video.crop.y = 0;
  11694. + preview_port->es.video.crop.width = f->fmt.pix.width;
  11695. + preview_port->es.video.crop.height = f->fmt.pix.height;
  11696. + preview_port->es.video.frame_rate.num =
  11697. + dev->capture.timeperframe.denominator;
  11698. + preview_port->es.video.frame_rate.den =
  11699. + dev->capture.timeperframe.numerator;
  11700. + ret = vchiq_mmal_port_set_format(dev->instance, preview_port);
  11701. + if (overlay_enabled) {
  11702. + ret = vchiq_mmal_port_connect_tunnel(
  11703. + dev->instance,
  11704. + preview_port,
  11705. + &dev->component[MMAL_COMPONENT_PREVIEW]->input[0]);
  11706. + if (!ret)
  11707. + ret = vchiq_mmal_port_enable(dev->instance,
  11708. + preview_port,
  11709. + NULL);
  11710. + }
  11711. + }
  11712. +
  11713. + if (ret) {
  11714. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11715. + "%s failed to set format\n", __func__);
  11716. + /* ensure capture is not going to be tried */
  11717. + dev->capture.port = NULL;
  11718. + } else {
  11719. + if (encode_component) {
  11720. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11721. + "vid_cap - set up encode comp\n");
  11722. +
  11723. + /* configure buffering */
  11724. + camera_port->current_buffer.size =
  11725. + camera_port->recommended_buffer.size;
  11726. + camera_port->current_buffer.num =
  11727. + camera_port->recommended_buffer.num;
  11728. +
  11729. + ret =
  11730. + vchiq_mmal_port_connect_tunnel(
  11731. + dev->instance,
  11732. + camera_port,
  11733. + &encode_component->input[0]);
  11734. + if (ret) {
  11735. + v4l2_dbg(1, bcm2835_v4l2_debug,
  11736. + &dev->v4l2_dev,
  11737. + "%s failed to create connection\n",
  11738. + __func__);
  11739. + /* ensure capture is not going to be tried */
  11740. + dev->capture.port = NULL;
  11741. + } else {
  11742. + port->es.video.width = f->fmt.pix.width;
  11743. + port->es.video.height = f->fmt.pix.height;
  11744. + port->es.video.crop.x = 0;
  11745. + port->es.video.crop.y = 0;
  11746. + port->es.video.crop.width = f->fmt.pix.width;
  11747. + port->es.video.crop.height = f->fmt.pix.height;
  11748. + port->es.video.frame_rate.num =
  11749. + dev->capture.timeperframe.denominator;
  11750. + port->es.video.frame_rate.den =
  11751. + dev->capture.timeperframe.numerator;
  11752. +
  11753. + port->format.encoding = mfmt->mmal;
  11754. + port->format.encoding_variant = 0;
  11755. + /* Set any encoding specific parameters */
  11756. + switch (mfmt->mmal_component) {
  11757. + case MMAL_COMPONENT_VIDEO_ENCODE:
  11758. + port->format.bitrate =
  11759. + dev->capture.encode_bitrate;
  11760. + break;
  11761. + case MMAL_COMPONENT_IMAGE_ENCODE:
  11762. + /* Could set EXIF parameters here */
  11763. + break;
  11764. + default:
  11765. + break;
  11766. + }
  11767. + ret = vchiq_mmal_port_set_format(dev->instance,
  11768. + port);
  11769. + if (ret)
  11770. + v4l2_dbg(1, bcm2835_v4l2_debug,
  11771. + &dev->v4l2_dev,
  11772. + "%s failed to set format\n",
  11773. + __func__);
  11774. + }
  11775. +
  11776. + if (!ret) {
  11777. + ret = vchiq_mmal_component_enable(
  11778. + dev->instance,
  11779. + encode_component);
  11780. + if (ret) {
  11781. + v4l2_dbg(1, bcm2835_v4l2_debug,
  11782. + &dev->v4l2_dev,
  11783. + "%s Failed to enable encode components\n",
  11784. + __func__);
  11785. + }
  11786. + }
  11787. + if (!ret) {
  11788. + /* configure buffering */
  11789. + port->current_buffer.num = 1;
  11790. + port->current_buffer.size =
  11791. + f->fmt.pix.sizeimage;
  11792. + if (port->format.encoding ==
  11793. + MMAL_ENCODING_JPEG) {
  11794. + v4l2_dbg(1, bcm2835_v4l2_debug,
  11795. + &dev->v4l2_dev,
  11796. + "JPG - buf size now %d was %d\n",
  11797. + f->fmt.pix.sizeimage,
  11798. + port->current_buffer.size);
  11799. + port->current_buffer.size =
  11800. + (f->fmt.pix.sizeimage <
  11801. + (100 << 10))
  11802. + ? (100 << 10) : f->fmt.pix.
  11803. + sizeimage;
  11804. + }
  11805. + v4l2_dbg(1, bcm2835_v4l2_debug,
  11806. + &dev->v4l2_dev,
  11807. + "vid_cap - cur_buf.size set to %d\n",
  11808. + f->fmt.pix.sizeimage);
  11809. + port->current_buffer.alignment = 0;
  11810. + }
  11811. + } else {
  11812. + /* configure buffering */
  11813. + camera_port->current_buffer.num = 1;
  11814. + camera_port->current_buffer.size = f->fmt.pix.sizeimage;
  11815. + camera_port->current_buffer.alignment = 0;
  11816. + }
  11817. +
  11818. + if (!ret) {
  11819. + dev->capture.fmt = mfmt;
  11820. + dev->capture.stride = f->fmt.pix.bytesperline;
  11821. + dev->capture.width = camera_port->es.video.crop.width;
  11822. + dev->capture.height = camera_port->es.video.crop.height;
  11823. +
  11824. + /* select port for capture */
  11825. + dev->capture.port = port;
  11826. + dev->capture.camera_port = camera_port;
  11827. + dev->capture.encode_component = encode_component;
  11828. + v4l2_dbg(1, bcm2835_v4l2_debug,
  11829. + &dev->v4l2_dev,
  11830. + "Set dev->capture.fmt %08X, %dx%d, stride %d",
  11831. + port->format.encoding,
  11832. + dev->capture.width, dev->capture.height,
  11833. + dev->capture.stride);
  11834. + }
  11835. + }
  11836. +
  11837. + /* todo: Need to convert the vchiq/mmal error into a v4l2 error. */
  11838. + return ret;
  11839. +}
  11840. +
  11841. +static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
  11842. + struct v4l2_format *f)
  11843. +{
  11844. + int ret;
  11845. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  11846. + struct mmal_fmt *mfmt;
  11847. +
  11848. + /* try the format to set valid parameters */
  11849. + ret = vidioc_try_fmt_vid_cap(file, priv, f);
  11850. + if (ret) {
  11851. + v4l2_err(&dev->v4l2_dev,
  11852. + "vid_cap - vidioc_try_fmt_vid_cap failed\n");
  11853. + return ret;
  11854. + }
  11855. +
  11856. + /* if a capture is running refuse to set format */
  11857. + if (vb2_is_busy(&dev->capture.vb_vidq)) {
  11858. + v4l2_info(&dev->v4l2_dev, "%s device busy\n", __func__);
  11859. + return -EBUSY;
  11860. + }
  11861. +
  11862. + /* If the format is unsupported v4l2 says we should switch to
  11863. + * a supported one and not return an error. */
  11864. + mfmt = get_format(f);
  11865. + if (!mfmt) {
  11866. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11867. + "Fourcc format (0x%08x) unknown.\n",
  11868. + f->fmt.pix.pixelformat);
  11869. + f->fmt.pix.pixelformat = formats[0].fourcc;
  11870. + mfmt = get_format(f);
  11871. + }
  11872. +
  11873. + ret = mmal_setup_components(dev, f);
  11874. + if (ret != 0) {
  11875. + v4l2_err(&dev->v4l2_dev,
  11876. + "%s: failed to setup mmal components: %d\n",
  11877. + __func__, ret);
  11878. + ret = -EINVAL;
  11879. + }
  11880. +
  11881. + return ret;
  11882. +}
  11883. +
  11884. +int vidioc_enum_framesizes(struct file *file, void *fh,
  11885. + struct v4l2_frmsizeenum *fsize)
  11886. +{
  11887. + static const struct v4l2_frmsize_stepwise sizes = {
  11888. + MIN_WIDTH, MAX_WIDTH, 2,
  11889. + MIN_HEIGHT, MAX_HEIGHT, 2
  11890. + };
  11891. + int i;
  11892. +
  11893. + if (fsize->index)
  11894. + return -EINVAL;
  11895. + for (i = 0; i < ARRAY_SIZE(formats); i++)
  11896. + if (formats[i].fourcc == fsize->pixel_format)
  11897. + break;
  11898. + if (i == ARRAY_SIZE(formats))
  11899. + return -EINVAL;
  11900. + fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE;
  11901. + fsize->stepwise = sizes;
  11902. + return 0;
  11903. +}
  11904. +
  11905. +/* timeperframe is arbitrary and continous */
  11906. +static int vidioc_enum_frameintervals(struct file *file, void *priv,
  11907. + struct v4l2_frmivalenum *fival)
  11908. +{
  11909. + int i;
  11910. +
  11911. + if (fival->index)
  11912. + return -EINVAL;
  11913. +
  11914. + for (i = 0; i < ARRAY_SIZE(formats); i++)
  11915. + if (formats[i].fourcc == fival->pixel_format)
  11916. + break;
  11917. + if (i == ARRAY_SIZE(formats))
  11918. + return -EINVAL;
  11919. +
  11920. + /* regarding width & height - we support any within range */
  11921. + if (fival->width < MIN_WIDTH || fival->width > MAX_WIDTH ||
  11922. + fival->height < MIN_HEIGHT || fival->height > MAX_HEIGHT)
  11923. + return -EINVAL;
  11924. +
  11925. + fival->type = V4L2_FRMIVAL_TYPE_CONTINUOUS;
  11926. +
  11927. + /* fill in stepwise (step=1.0 is requred by V4L2 spec) */
  11928. + fival->stepwise.min = tpf_min;
  11929. + fival->stepwise.max = tpf_max;
  11930. + fival->stepwise.step = (struct v4l2_fract) {1, 1};
  11931. +
  11932. + return 0;
  11933. +}
  11934. +
  11935. +static int vidioc_g_parm(struct file *file, void *priv,
  11936. + struct v4l2_streamparm *parm)
  11937. +{
  11938. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  11939. +
  11940. + if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  11941. + return -EINVAL;
  11942. +
  11943. + parm->parm.capture.capability = V4L2_CAP_TIMEPERFRAME;
  11944. + parm->parm.capture.timeperframe = dev->capture.timeperframe;
  11945. + parm->parm.capture.readbuffers = 1;
  11946. + return 0;
  11947. +}
  11948. +
  11949. +#define FRACT_CMP(a, OP, b) \
  11950. + ((u64)(a).numerator * (b).denominator OP \
  11951. + (u64)(b).numerator * (a).denominator)
  11952. +
  11953. +static int vidioc_s_parm(struct file *file, void *priv,
  11954. + struct v4l2_streamparm *parm)
  11955. +{
  11956. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  11957. + struct v4l2_fract tpf;
  11958. + struct mmal_parameter_rational fps_param;
  11959. +
  11960. + if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  11961. + return -EINVAL;
  11962. +
  11963. + tpf = parm->parm.capture.timeperframe;
  11964. +
  11965. + /* tpf: {*, 0} resets timing; clip to [min, max]*/
  11966. + tpf = tpf.denominator ? tpf : tpf_default;
  11967. + tpf = FRACT_CMP(tpf, <, tpf_min) ? tpf_min : tpf;
  11968. + tpf = FRACT_CMP(tpf, >, tpf_max) ? tpf_max : tpf;
  11969. +
  11970. + dev->capture.timeperframe = tpf;
  11971. + parm->parm.capture.timeperframe = tpf;
  11972. + parm->parm.capture.readbuffers = 1;
  11973. +
  11974. + fps_param.num = 0; /* Select variable fps, and then use
  11975. + * FPS_RANGE to select the actual limits.
  11976. + */
  11977. + fps_param.den = 1;
  11978. + set_framerate_params(dev);
  11979. +
  11980. + return 0;
  11981. +}
  11982. +
  11983. +static const struct v4l2_ioctl_ops camera0_ioctl_ops = {
  11984. + /* overlay */
  11985. + .vidioc_enum_fmt_vid_overlay = vidioc_enum_fmt_vid_overlay,
  11986. + .vidioc_g_fmt_vid_overlay = vidioc_g_fmt_vid_overlay,
  11987. + .vidioc_try_fmt_vid_overlay = vidioc_try_fmt_vid_overlay,
  11988. + .vidioc_s_fmt_vid_overlay = vidioc_s_fmt_vid_overlay,
  11989. + .vidioc_overlay = vidioc_overlay,
  11990. + .vidioc_g_fbuf = vidioc_g_fbuf,
  11991. +
  11992. + /* inputs */
  11993. + .vidioc_enum_input = vidioc_enum_input,
  11994. + .vidioc_g_input = vidioc_g_input,
  11995. + .vidioc_s_input = vidioc_s_input,
  11996. +
  11997. + /* capture */
  11998. + .vidioc_querycap = vidioc_querycap,
  11999. + .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
  12000. + .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
  12001. + .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
  12002. + .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
  12003. +
  12004. + /* buffer management */
  12005. + .vidioc_reqbufs = vb2_ioctl_reqbufs,
  12006. + .vidioc_create_bufs = vb2_ioctl_create_bufs,
  12007. + .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
  12008. + .vidioc_querybuf = vb2_ioctl_querybuf,
  12009. + .vidioc_qbuf = vb2_ioctl_qbuf,
  12010. + .vidioc_dqbuf = vb2_ioctl_dqbuf,
  12011. + .vidioc_enum_framesizes = vidioc_enum_framesizes,
  12012. + .vidioc_enum_frameintervals = vidioc_enum_frameintervals,
  12013. + .vidioc_g_parm = vidioc_g_parm,
  12014. + .vidioc_s_parm = vidioc_s_parm,
  12015. + .vidioc_streamon = vb2_ioctl_streamon,
  12016. + .vidioc_streamoff = vb2_ioctl_streamoff,
  12017. +
  12018. + .vidioc_log_status = v4l2_ctrl_log_status,
  12019. + .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
  12020. + .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
  12021. +};
  12022. +
  12023. +/* ------------------------------------------------------------------
  12024. + Driver init/finalise
  12025. + ------------------------------------------------------------------*/
  12026. +
  12027. +static const struct v4l2_file_operations camera0_fops = {
  12028. + .owner = THIS_MODULE,
  12029. + .open = v4l2_fh_open,
  12030. + .release = vb2_fop_release,
  12031. + .read = vb2_fop_read,
  12032. + .poll = vb2_fop_poll,
  12033. + .unlocked_ioctl = video_ioctl2, /* V4L2 ioctl handler */
  12034. + .mmap = vb2_fop_mmap,
  12035. +};
  12036. +
  12037. +static struct video_device vdev_template = {
  12038. + .name = "camera0",
  12039. + .fops = &camera0_fops,
  12040. + .ioctl_ops = &camera0_ioctl_ops,
  12041. + .release = video_device_release_empty,
  12042. +};
  12043. +
  12044. +static int set_camera_parameters(struct vchiq_mmal_instance *instance,
  12045. + struct vchiq_mmal_component *camera)
  12046. +{
  12047. + int ret;
  12048. + struct mmal_parameter_camera_config cam_config = {
  12049. + .max_stills_w = MAX_WIDTH,
  12050. + .max_stills_h = MAX_HEIGHT,
  12051. + .stills_yuv422 = 1,
  12052. + .one_shot_stills = 1,
  12053. + .max_preview_video_w = 1920,
  12054. + .max_preview_video_h = 1088,
  12055. + .num_preview_video_frames = 3,
  12056. + .stills_capture_circular_buffer_height = 0,
  12057. + .fast_preview_resume = 0,
  12058. + .use_stc_timestamp = MMAL_PARAM_TIMESTAMP_MODE_RAW_STC
  12059. + };
  12060. +
  12061. + ret = vchiq_mmal_port_parameter_set(instance, &camera->control,
  12062. + MMAL_PARAMETER_CAMERA_CONFIG,
  12063. + &cam_config, sizeof(cam_config));
  12064. + return ret;
  12065. +}
  12066. +
  12067. +/* MMAL instance and component init */
  12068. +static int __init mmal_init(struct bm2835_mmal_dev *dev)
  12069. +{
  12070. + int ret;
  12071. + struct mmal_es_format *format;
  12072. +
  12073. + ret = vchiq_mmal_init(&dev->instance);
  12074. + if (ret < 0)
  12075. + return ret;
  12076. +
  12077. + /* get the camera component ready */
  12078. + ret = vchiq_mmal_component_init(dev->instance, "ril.camera",
  12079. + &dev->component[MMAL_COMPONENT_CAMERA]);
  12080. + if (ret < 0)
  12081. + goto unreg_mmal;
  12082. +
  12083. + if (dev->component[MMAL_COMPONENT_CAMERA]->outputs <
  12084. + MMAL_CAMERA_PORT_COUNT) {
  12085. + ret = -EINVAL;
  12086. + goto unreg_camera;
  12087. + }
  12088. +
  12089. + ret = set_camera_parameters(dev->instance,
  12090. + dev->component[MMAL_COMPONENT_CAMERA]);
  12091. + if (ret < 0)
  12092. + goto unreg_camera;
  12093. +
  12094. + format =
  12095. + &dev->component[MMAL_COMPONENT_CAMERA]->
  12096. + output[MMAL_CAMERA_PORT_PREVIEW].format;
  12097. +
  12098. + format->encoding = MMAL_ENCODING_OPAQUE;
  12099. + format->encoding_variant = MMAL_ENCODING_I420;
  12100. +
  12101. + format->es->video.width = 1024;
  12102. + format->es->video.height = 768;
  12103. + format->es->video.crop.x = 0;
  12104. + format->es->video.crop.y = 0;
  12105. + format->es->video.crop.width = 1024;
  12106. + format->es->video.crop.height = 768;
  12107. + format->es->video.frame_rate.num = 0; /* Rely on fps_range */
  12108. + format->es->video.frame_rate.den = 1;
  12109. +
  12110. + format =
  12111. + &dev->component[MMAL_COMPONENT_CAMERA]->
  12112. + output[MMAL_CAMERA_PORT_VIDEO].format;
  12113. +
  12114. + format->encoding = MMAL_ENCODING_OPAQUE;
  12115. + format->encoding_variant = MMAL_ENCODING_I420;
  12116. +
  12117. + format->es->video.width = 1024;
  12118. + format->es->video.height = 768;
  12119. + format->es->video.crop.x = 0;
  12120. + format->es->video.crop.y = 0;
  12121. + format->es->video.crop.width = 1024;
  12122. + format->es->video.crop.height = 768;
  12123. + format->es->video.frame_rate.num = 0; /* Rely on fps_range */
  12124. + format->es->video.frame_rate.den = 1;
  12125. +
  12126. + format =
  12127. + &dev->component[MMAL_COMPONENT_CAMERA]->
  12128. + output[MMAL_CAMERA_PORT_CAPTURE].format;
  12129. +
  12130. + format->encoding = MMAL_ENCODING_OPAQUE;
  12131. +
  12132. + format->es->video.width = 2592;
  12133. + format->es->video.height = 1944;
  12134. + format->es->video.crop.x = 0;
  12135. + format->es->video.crop.y = 0;
  12136. + format->es->video.crop.width = 2592;
  12137. + format->es->video.crop.height = 1944;
  12138. + format->es->video.frame_rate.num = 0; /* Rely on fps_range */
  12139. + format->es->video.frame_rate.den = 1;
  12140. +
  12141. + dev->capture.width = format->es->video.width;
  12142. + dev->capture.height = format->es->video.height;
  12143. + dev->capture.fmt = &formats[0];
  12144. + dev->capture.encode_component = NULL;
  12145. + dev->capture.timeperframe = tpf_default;
  12146. + dev->capture.enc_profile = V4L2_MPEG_VIDEO_H264_PROFILE_HIGH;
  12147. + dev->capture.enc_level = V4L2_MPEG_VIDEO_H264_LEVEL_4_0;
  12148. +
  12149. + /* get the preview component ready */
  12150. + ret = vchiq_mmal_component_init(
  12151. + dev->instance, "ril.video_render",
  12152. + &dev->component[MMAL_COMPONENT_PREVIEW]);
  12153. + if (ret < 0)
  12154. + goto unreg_camera;
  12155. +
  12156. + if (dev->component[MMAL_COMPONENT_PREVIEW]->inputs < 1) {
  12157. + ret = -EINVAL;
  12158. + pr_debug("too few input ports %d needed %d\n",
  12159. + dev->component[MMAL_COMPONENT_PREVIEW]->inputs, 1);
  12160. + goto unreg_preview;
  12161. + }
  12162. +
  12163. + /* get the image encoder component ready */
  12164. + ret = vchiq_mmal_component_init(
  12165. + dev->instance, "ril.image_encode",
  12166. + &dev->component[MMAL_COMPONENT_IMAGE_ENCODE]);
  12167. + if (ret < 0)
  12168. + goto unreg_preview;
  12169. +
  12170. + if (dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->inputs < 1) {
  12171. + ret = -EINVAL;
  12172. + v4l2_err(&dev->v4l2_dev, "too few input ports %d needed %d\n",
  12173. + dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->inputs,
  12174. + 1);
  12175. + goto unreg_image_encoder;
  12176. + }
  12177. +
  12178. + /* get the video encoder component ready */
  12179. + ret = vchiq_mmal_component_init(dev->instance, "ril.video_encode",
  12180. + &dev->
  12181. + component[MMAL_COMPONENT_VIDEO_ENCODE]);
  12182. + if (ret < 0)
  12183. + goto unreg_image_encoder;
  12184. +
  12185. + if (dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->inputs < 1) {
  12186. + ret = -EINVAL;
  12187. + v4l2_err(&dev->v4l2_dev, "too few input ports %d needed %d\n",
  12188. + dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->inputs,
  12189. + 1);
  12190. + goto unreg_vid_encoder;
  12191. + }
  12192. +
  12193. + {
  12194. + struct vchiq_mmal_port *encoder_port =
  12195. + &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  12196. + encoder_port->format.encoding = MMAL_ENCODING_H264;
  12197. + ret = vchiq_mmal_port_set_format(dev->instance,
  12198. + encoder_port);
  12199. + }
  12200. +
  12201. + {
  12202. + unsigned int enable = 1;
  12203. + vchiq_mmal_port_parameter_set(
  12204. + dev->instance,
  12205. + &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->control,
  12206. + MMAL_PARAMETER_VIDEO_IMMUTABLE_INPUT,
  12207. + &enable, sizeof(enable));
  12208. +
  12209. + vchiq_mmal_port_parameter_set(dev->instance,
  12210. + &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->control,
  12211. + MMAL_PARAMETER_MINIMISE_FRAGMENTATION,
  12212. + &enable,
  12213. + sizeof(enable));
  12214. + }
  12215. + ret = bm2835_mmal_set_all_camera_controls(dev);
  12216. + if (ret < 0)
  12217. + goto unreg_vid_encoder;
  12218. +
  12219. + return 0;
  12220. +
  12221. +unreg_vid_encoder:
  12222. + pr_err("Cleanup: Destroy video encoder\n");
  12223. + vchiq_mmal_component_finalise(
  12224. + dev->instance,
  12225. + dev->component[MMAL_COMPONENT_VIDEO_ENCODE]);
  12226. +
  12227. +unreg_image_encoder:
  12228. + pr_err("Cleanup: Destroy image encoder\n");
  12229. + vchiq_mmal_component_finalise(
  12230. + dev->instance,
  12231. + dev->component[MMAL_COMPONENT_IMAGE_ENCODE]);
  12232. +
  12233. +unreg_preview:
  12234. + pr_err("Cleanup: Destroy video render\n");
  12235. + vchiq_mmal_component_finalise(dev->instance,
  12236. + dev->component[MMAL_COMPONENT_PREVIEW]);
  12237. +
  12238. +unreg_camera:
  12239. + pr_err("Cleanup: Destroy camera\n");
  12240. + vchiq_mmal_component_finalise(dev->instance,
  12241. + dev->component[MMAL_COMPONENT_CAMERA]);
  12242. +
  12243. +unreg_mmal:
  12244. + vchiq_mmal_finalise(dev->instance);
  12245. + return ret;
  12246. +}
  12247. +
  12248. +static int __init bm2835_mmal_init_device(struct bm2835_mmal_dev *dev,
  12249. + struct video_device *vfd)
  12250. +{
  12251. + int ret;
  12252. +
  12253. + *vfd = vdev_template;
  12254. +
  12255. + vfd->v4l2_dev = &dev->v4l2_dev;
  12256. +
  12257. + vfd->lock = &dev->mutex;
  12258. +
  12259. + vfd->queue = &dev->capture.vb_vidq;
  12260. +
  12261. + set_bit(V4L2_FL_USE_FH_PRIO, &vfd->flags);
  12262. +
  12263. + /* video device needs to be able to access instance data */
  12264. + video_set_drvdata(vfd, dev);
  12265. +
  12266. + ret = video_register_device(vfd, VFL_TYPE_GRABBER, -1);
  12267. + if (ret < 0)
  12268. + return ret;
  12269. +
  12270. + v4l2_info(vfd->v4l2_dev, "V4L2 device registered as %s\n",
  12271. + video_device_node_name(vfd));
  12272. +
  12273. + return 0;
  12274. +}
  12275. +
  12276. +static struct v4l2_format default_v4l2_format = {
  12277. + .fmt.pix.pixelformat = V4L2_PIX_FMT_JPEG,
  12278. + .fmt.pix.width = 1024,
  12279. + .fmt.pix.bytesperline = 1024 * 3 / 2,
  12280. + .fmt.pix.height = 768,
  12281. + .fmt.pix.sizeimage = 1<<18,
  12282. +};
  12283. +
  12284. +static int __init bm2835_mmal_init(void)
  12285. +{
  12286. + int ret;
  12287. + struct bm2835_mmal_dev *dev;
  12288. + struct vb2_queue *q;
  12289. +
  12290. + dev = kzalloc(sizeof(*gdev), GFP_KERNEL);
  12291. + if (!dev)
  12292. + return -ENOMEM;
  12293. +
  12294. + /* setup device defaults */
  12295. + dev->overlay.w.left = 150;
  12296. + dev->overlay.w.top = 50;
  12297. + dev->overlay.w.width = 1024;
  12298. + dev->overlay.w.height = 768;
  12299. + dev->overlay.clipcount = 0;
  12300. + dev->overlay.field = V4L2_FIELD_NONE;
  12301. +
  12302. + dev->capture.fmt = &formats[3]; /* JPEG */
  12303. +
  12304. + /* v4l device registration */
  12305. + snprintf(dev->v4l2_dev.name, sizeof(dev->v4l2_dev.name),
  12306. + "%s", BM2835_MMAL_MODULE_NAME);
  12307. + ret = v4l2_device_register(NULL, &dev->v4l2_dev);
  12308. + if (ret)
  12309. + goto free_dev;
  12310. +
  12311. + /* setup v4l controls */
  12312. + ret = bm2835_mmal_init_controls(dev, &dev->ctrl_handler);
  12313. + if (ret < 0)
  12314. + goto unreg_dev;
  12315. + dev->v4l2_dev.ctrl_handler = &dev->ctrl_handler;
  12316. +
  12317. + /* mmal init */
  12318. + ret = mmal_init(dev);
  12319. + if (ret < 0)
  12320. + goto unreg_dev;
  12321. +
  12322. + /* initialize queue */
  12323. + q = &dev->capture.vb_vidq;
  12324. + memset(q, 0, sizeof(*q));
  12325. + q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  12326. + q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_READ;
  12327. + q->drv_priv = dev;
  12328. + q->buf_struct_size = sizeof(struct mmal_buffer);
  12329. + q->ops = &bm2835_mmal_video_qops;
  12330. + q->mem_ops = &vb2_vmalloc_memops;
  12331. + q->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
  12332. + ret = vb2_queue_init(q);
  12333. + if (ret < 0)
  12334. + goto unreg_dev;
  12335. +
  12336. + /* v4l2 core mutex used to protect all fops and v4l2 ioctls. */
  12337. + mutex_init(&dev->mutex);
  12338. +
  12339. + /* initialise video devices */
  12340. + ret = bm2835_mmal_init_device(dev, &dev->vdev);
  12341. + if (ret < 0)
  12342. + goto unreg_dev;
  12343. +
  12344. + ret = mmal_setup_components(dev, &default_v4l2_format);
  12345. + if (ret < 0) {
  12346. + v4l2_err(&dev->v4l2_dev,
  12347. + "%s: could not setup components\n", __func__);
  12348. + goto unreg_dev;
  12349. + }
  12350. +
  12351. + v4l2_info(&dev->v4l2_dev,
  12352. + "Broadcom 2835 MMAL video capture ver %s loaded.\n",
  12353. + BM2835_MMAL_VERSION);
  12354. +
  12355. + gdev = dev;
  12356. + return 0;
  12357. +
  12358. +unreg_dev:
  12359. + v4l2_ctrl_handler_free(&dev->ctrl_handler);
  12360. + v4l2_device_unregister(&dev->v4l2_dev);
  12361. +
  12362. +free_dev:
  12363. + kfree(dev);
  12364. +
  12365. + v4l2_err(&dev->v4l2_dev,
  12366. + "%s: error %d while loading driver\n",
  12367. + BM2835_MMAL_MODULE_NAME, ret);
  12368. +
  12369. + return ret;
  12370. +}
  12371. +
  12372. +static void __exit bm2835_mmal_exit(void)
  12373. +{
  12374. + if (!gdev)
  12375. + return;
  12376. +
  12377. + v4l2_info(&gdev->v4l2_dev, "unregistering %s\n",
  12378. + video_device_node_name(&gdev->vdev));
  12379. +
  12380. + video_unregister_device(&gdev->vdev);
  12381. +
  12382. + if (gdev->capture.encode_component) {
  12383. + v4l2_dbg(1, bcm2835_v4l2_debug, &gdev->v4l2_dev,
  12384. + "mmal_exit - disconnect tunnel\n");
  12385. + vchiq_mmal_port_connect_tunnel(gdev->instance,
  12386. + gdev->capture.camera_port, NULL);
  12387. + vchiq_mmal_component_disable(gdev->instance,
  12388. + gdev->capture.encode_component);
  12389. + }
  12390. + vchiq_mmal_component_disable(gdev->instance,
  12391. + gdev->component[MMAL_COMPONENT_CAMERA]);
  12392. +
  12393. + vchiq_mmal_component_finalise(gdev->instance,
  12394. + gdev->
  12395. + component[MMAL_COMPONENT_VIDEO_ENCODE]);
  12396. +
  12397. + vchiq_mmal_component_finalise(gdev->instance,
  12398. + gdev->
  12399. + component[MMAL_COMPONENT_IMAGE_ENCODE]);
  12400. +
  12401. + vchiq_mmal_component_finalise(gdev->instance,
  12402. + gdev->component[MMAL_COMPONENT_PREVIEW]);
  12403. +
  12404. + vchiq_mmal_component_finalise(gdev->instance,
  12405. + gdev->component[MMAL_COMPONENT_CAMERA]);
  12406. +
  12407. + vchiq_mmal_finalise(gdev->instance);
  12408. +
  12409. + v4l2_ctrl_handler_free(&gdev->ctrl_handler);
  12410. +
  12411. + v4l2_device_unregister(&gdev->v4l2_dev);
  12412. +
  12413. + kfree(gdev);
  12414. +}
  12415. +
  12416. +module_init(bm2835_mmal_init);
  12417. +module_exit(bm2835_mmal_exit);
  12418. diff -Nur linux-3.13.11/drivers/media/platform/bcm2835/bcm2835-camera.h linux-rpi/drivers/media/platform/bcm2835/bcm2835-camera.h
  12419. --- linux-3.13.11/drivers/media/platform/bcm2835/bcm2835-camera.h 1970-01-01 01:00:00.000000000 +0100
  12420. +++ linux-rpi/drivers/media/platform/bcm2835/bcm2835-camera.h 2014-04-24 15:35:02.713549510 +0200
  12421. @@ -0,0 +1,125 @@
  12422. +/*
  12423. + * Broadcom BM2835 V4L2 driver
  12424. + *
  12425. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  12426. + *
  12427. + * This file is subject to the terms and conditions of the GNU General Public
  12428. + * License. See the file COPYING in the main directory of this archive
  12429. + * for more details.
  12430. + *
  12431. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  12432. + * Dave Stevenson <dsteve@broadcom.com>
  12433. + * Simon Mellor <simellor@broadcom.com>
  12434. + * Luke Diamand <luked@broadcom.com>
  12435. + *
  12436. + * core driver device
  12437. + */
  12438. +
  12439. +#define V4L2_CTRL_COUNT 27 /* number of v4l controls */
  12440. +
  12441. +enum {
  12442. + MMAL_COMPONENT_CAMERA = 0,
  12443. + MMAL_COMPONENT_PREVIEW,
  12444. + MMAL_COMPONENT_IMAGE_ENCODE,
  12445. + MMAL_COMPONENT_VIDEO_ENCODE,
  12446. + MMAL_COMPONENT_COUNT
  12447. +};
  12448. +
  12449. +enum {
  12450. + MMAL_CAMERA_PORT_PREVIEW = 0,
  12451. + MMAL_CAMERA_PORT_VIDEO,
  12452. + MMAL_CAMERA_PORT_CAPTURE,
  12453. + MMAL_CAMERA_PORT_COUNT
  12454. +};
  12455. +
  12456. +#define PREVIEW_LAYER 2
  12457. +
  12458. +extern int bcm2835_v4l2_debug;
  12459. +
  12460. +struct bm2835_mmal_dev {
  12461. + /* v4l2 devices */
  12462. + struct v4l2_device v4l2_dev;
  12463. + struct video_device vdev;
  12464. + struct mutex mutex;
  12465. +
  12466. + /* controls */
  12467. + struct v4l2_ctrl_handler ctrl_handler;
  12468. + struct v4l2_ctrl *ctrls[V4L2_CTRL_COUNT];
  12469. + enum v4l2_scene_mode scene_mode;
  12470. + struct mmal_colourfx colourfx;
  12471. + int hflip;
  12472. + int vflip;
  12473. + int red_gain;
  12474. + int blue_gain;
  12475. + enum mmal_parameter_exposuremode exposure_mode_user;
  12476. + enum v4l2_exposure_auto_type exposure_mode_v4l2_user;
  12477. + /* active exposure mode may differ if selected via a scene mode */
  12478. + enum mmal_parameter_exposuremode exposure_mode_active;
  12479. + enum mmal_parameter_exposuremeteringmode metering_mode;
  12480. + unsigned int manual_shutter_speed;
  12481. + bool exp_auto_priority;
  12482. +
  12483. + /* allocated mmal instance and components */
  12484. + struct vchiq_mmal_instance *instance;
  12485. + struct vchiq_mmal_component *component[MMAL_COMPONENT_COUNT];
  12486. + int camera_use_count;
  12487. +
  12488. + struct v4l2_window overlay;
  12489. +
  12490. + struct {
  12491. + unsigned int width; /* width */
  12492. + unsigned int height; /* height */
  12493. + unsigned int stride; /* stride */
  12494. + struct mmal_fmt *fmt;
  12495. + struct v4l2_fract timeperframe;
  12496. +
  12497. + /* H264 encode bitrate */
  12498. + int encode_bitrate;
  12499. + /* H264 bitrate mode. CBR/VBR */
  12500. + int encode_bitrate_mode;
  12501. + /* H264 profile */
  12502. + enum v4l2_mpeg_video_h264_profile enc_profile;
  12503. + /* H264 level */
  12504. + enum v4l2_mpeg_video_h264_level enc_level;
  12505. + /* JPEG Q-factor */
  12506. + int q_factor;
  12507. +
  12508. + struct vb2_queue vb_vidq;
  12509. +
  12510. + /* VC start timestamp for streaming */
  12511. + s64 vc_start_timestamp;
  12512. + /* Kernel start timestamp for streaming */
  12513. + struct timeval kernel_start_ts;
  12514. +
  12515. + struct vchiq_mmal_port *port; /* port being used for capture */
  12516. + /* camera port being used for capture */
  12517. + struct vchiq_mmal_port *camera_port;
  12518. + /* component being used for encode */
  12519. + struct vchiq_mmal_component *encode_component;
  12520. + /* number of frames remaining which driver should capture */
  12521. + unsigned int frame_count;
  12522. + /* last frame completion */
  12523. + struct completion frame_cmplt;
  12524. +
  12525. + } capture;
  12526. +
  12527. +};
  12528. +
  12529. +int bm2835_mmal_init_controls(
  12530. + struct bm2835_mmal_dev *dev,
  12531. + struct v4l2_ctrl_handler *hdl);
  12532. +
  12533. +int bm2835_mmal_set_all_camera_controls(struct bm2835_mmal_dev *dev);
  12534. +int set_framerate_params(struct bm2835_mmal_dev *dev);
  12535. +
  12536. +/* Debug helpers */
  12537. +
  12538. +#define v4l2_dump_pix_format(level, debug, dev, pix_fmt, desc) \
  12539. +{ \
  12540. + v4l2_dbg(level, debug, dev, \
  12541. +"%s: w %u h %u field %u pfmt 0x%x bpl %u sz_img %u colorspace 0x%x priv %u\n", \
  12542. + desc == NULL ? "" : desc, \
  12543. + (pix_fmt)->width, (pix_fmt)->height, (pix_fmt)->field, \
  12544. + (pix_fmt)->pixelformat, (pix_fmt)->bytesperline, \
  12545. + (pix_fmt)->sizeimage, (pix_fmt)->colorspace, (pix_fmt)->priv); \
  12546. +}
  12547. diff -Nur linux-3.13.11/drivers/media/platform/bcm2835/controls.c linux-rpi/drivers/media/platform/bcm2835/controls.c
  12548. --- linux-3.13.11/drivers/media/platform/bcm2835/controls.c 1970-01-01 01:00:00.000000000 +0100
  12549. +++ linux-rpi/drivers/media/platform/bcm2835/controls.c 2014-04-24 15:35:02.713549510 +0200
  12550. @@ -0,0 +1,1315 @@
  12551. +/*
  12552. + * Broadcom BM2835 V4L2 driver
  12553. + *
  12554. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  12555. + *
  12556. + * This file is subject to the terms and conditions of the GNU General Public
  12557. + * License. See the file COPYING in the main directory of this archive
  12558. + * for more details.
  12559. + *
  12560. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  12561. + * Dave Stevenson <dsteve@broadcom.com>
  12562. + * Simon Mellor <simellor@broadcom.com>
  12563. + * Luke Diamand <luked@broadcom.com>
  12564. + */
  12565. +
  12566. +#include <linux/errno.h>
  12567. +#include <linux/kernel.h>
  12568. +#include <linux/module.h>
  12569. +#include <linux/slab.h>
  12570. +#include <media/videobuf2-vmalloc.h>
  12571. +#include <media/v4l2-device.h>
  12572. +#include <media/v4l2-ioctl.h>
  12573. +#include <media/v4l2-ctrls.h>
  12574. +#include <media/v4l2-fh.h>
  12575. +#include <media/v4l2-event.h>
  12576. +#include <media/v4l2-common.h>
  12577. +
  12578. +#include "mmal-common.h"
  12579. +#include "mmal-vchiq.h"
  12580. +#include "mmal-parameters.h"
  12581. +#include "bcm2835-camera.h"
  12582. +
  12583. +/* The supported V4L2_CID_AUTO_EXPOSURE_BIAS values are from -4.0 to +4.0.
  12584. + * MMAL values are in 1/6th increments so the MMAL range is -24 to +24.
  12585. + * V4L2 docs say value "is expressed in terms of EV, drivers should interpret
  12586. + * the values as 0.001 EV units, where the value 1000 stands for +1 EV."
  12587. + * V4L2 is limited to a max of 32 values in a menu, so count in 1/3rds from
  12588. + * -4 to +4
  12589. + */
  12590. +static const s64 ev_bias_qmenu[] = {
  12591. + -4000, -3667, -3333,
  12592. + -3000, -2667, -2333,
  12593. + -2000, -1667, -1333,
  12594. + -1000, -667, -333,
  12595. + 0, 333, 667,
  12596. + 1000, 1333, 1667,
  12597. + 2000, 2333, 2667,
  12598. + 3000, 3333, 3667,
  12599. + 4000
  12600. +};
  12601. +
  12602. +/* Supported ISO values
  12603. + * ISOO = auto ISO
  12604. + */
  12605. +static const s64 iso_qmenu[] = {
  12606. + 0, 100, 200, 400, 800,
  12607. +};
  12608. +
  12609. +static const s64 mains_freq_qmenu[] = {
  12610. + V4L2_CID_POWER_LINE_FREQUENCY_DISABLED,
  12611. + V4L2_CID_POWER_LINE_FREQUENCY_50HZ,
  12612. + V4L2_CID_POWER_LINE_FREQUENCY_60HZ,
  12613. + V4L2_CID_POWER_LINE_FREQUENCY_AUTO
  12614. +};
  12615. +
  12616. +/* Supported video encode modes */
  12617. +static const s64 bitrate_mode_qmenu[] = {
  12618. + (s64)V4L2_MPEG_VIDEO_BITRATE_MODE_VBR,
  12619. + (s64)V4L2_MPEG_VIDEO_BITRATE_MODE_CBR,
  12620. +};
  12621. +
  12622. +enum bm2835_mmal_ctrl_type {
  12623. + MMAL_CONTROL_TYPE_STD,
  12624. + MMAL_CONTROL_TYPE_STD_MENU,
  12625. + MMAL_CONTROL_TYPE_INT_MENU,
  12626. + MMAL_CONTROL_TYPE_CLUSTER, /* special cluster entry */
  12627. +};
  12628. +
  12629. +struct bm2835_mmal_v4l2_ctrl;
  12630. +
  12631. +typedef int(bm2835_mmal_v4l2_ctrl_cb)(
  12632. + struct bm2835_mmal_dev *dev,
  12633. + struct v4l2_ctrl *ctrl,
  12634. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl);
  12635. +
  12636. +struct bm2835_mmal_v4l2_ctrl {
  12637. + u32 id; /* v4l2 control identifier */
  12638. + enum bm2835_mmal_ctrl_type type;
  12639. + /* control minimum value or
  12640. + * mask for MMAL_CONTROL_TYPE_STD_MENU */
  12641. + s32 min;
  12642. + s32 max; /* maximum value of control */
  12643. + s32 def; /* default value of control */
  12644. + s32 step; /* step size of the control */
  12645. + const s64 *imenu; /* integer menu array */
  12646. + u32 mmal_id; /* mmal parameter id */
  12647. + bm2835_mmal_v4l2_ctrl_cb *setter;
  12648. + bool ignore_errors;
  12649. +};
  12650. +
  12651. +struct v4l2_to_mmal_effects_setting {
  12652. + u32 v4l2_effect;
  12653. + u32 mmal_effect;
  12654. + s32 col_fx_enable;
  12655. + s32 col_fx_fixed_cbcr;
  12656. + u32 u;
  12657. + u32 v;
  12658. + u32 num_effect_params;
  12659. + u32 effect_params[MMAL_MAX_IMAGEFX_PARAMETERS];
  12660. +};
  12661. +
  12662. +static const struct v4l2_to_mmal_effects_setting
  12663. + v4l2_to_mmal_effects_values[] = {
  12664. + { V4L2_COLORFX_NONE, MMAL_PARAM_IMAGEFX_NONE,
  12665. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  12666. + { V4L2_COLORFX_BW, MMAL_PARAM_IMAGEFX_NONE,
  12667. + 1, 0, 128, 128, 0, {0, 0, 0, 0, 0} },
  12668. + { V4L2_COLORFX_SEPIA, MMAL_PARAM_IMAGEFX_NONE,
  12669. + 1, 0, 87, 151, 0, {0, 0, 0, 0, 0} },
  12670. + { V4L2_COLORFX_NEGATIVE, MMAL_PARAM_IMAGEFX_NEGATIVE,
  12671. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  12672. + { V4L2_COLORFX_EMBOSS, MMAL_PARAM_IMAGEFX_EMBOSS,
  12673. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  12674. + { V4L2_COLORFX_SKETCH, MMAL_PARAM_IMAGEFX_SKETCH,
  12675. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  12676. + { V4L2_COLORFX_SKY_BLUE, MMAL_PARAM_IMAGEFX_PASTEL,
  12677. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  12678. + { V4L2_COLORFX_GRASS_GREEN, MMAL_PARAM_IMAGEFX_WATERCOLOUR,
  12679. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  12680. + { V4L2_COLORFX_SKIN_WHITEN, MMAL_PARAM_IMAGEFX_WASHEDOUT,
  12681. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  12682. + { V4L2_COLORFX_VIVID, MMAL_PARAM_IMAGEFX_SATURATION,
  12683. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  12684. + { V4L2_COLORFX_AQUA, MMAL_PARAM_IMAGEFX_NONE,
  12685. + 1, 0, 171, 121, 0, {0, 0, 0, 0, 0} },
  12686. + { V4L2_COLORFX_ART_FREEZE, MMAL_PARAM_IMAGEFX_HATCH,
  12687. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  12688. + { V4L2_COLORFX_SILHOUETTE, MMAL_PARAM_IMAGEFX_FILM,
  12689. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  12690. + { V4L2_COLORFX_SOLARIZATION, MMAL_PARAM_IMAGEFX_SOLARIZE,
  12691. + 0, 0, 0, 0, 5, {1, 128, 160, 160, 48} },
  12692. + { V4L2_COLORFX_ANTIQUE, MMAL_PARAM_IMAGEFX_COLOURBALANCE,
  12693. + 0, 0, 0, 0, 3, {108, 274, 238, 0, 0} },
  12694. + { V4L2_COLORFX_SET_CBCR, MMAL_PARAM_IMAGEFX_NONE,
  12695. + 1, 1, 0, 0, 0, {0, 0, 0, 0, 0} }
  12696. +};
  12697. +
  12698. +struct v4l2_mmal_scene_config {
  12699. + enum v4l2_scene_mode v4l2_scene;
  12700. + enum mmal_parameter_exposuremode exposure_mode;
  12701. + enum mmal_parameter_exposuremeteringmode metering_mode;
  12702. +};
  12703. +
  12704. +static const struct v4l2_mmal_scene_config scene_configs[] = {
  12705. + /* V4L2_SCENE_MODE_NONE automatically added */
  12706. + {
  12707. + V4L2_SCENE_MODE_NIGHT,
  12708. + MMAL_PARAM_EXPOSUREMODE_NIGHT,
  12709. + MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE
  12710. + },
  12711. + {
  12712. + V4L2_SCENE_MODE_SPORTS,
  12713. + MMAL_PARAM_EXPOSUREMODE_SPORTS,
  12714. + MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE
  12715. + },
  12716. +};
  12717. +
  12718. +/* control handlers*/
  12719. +
  12720. +static int ctrl_set_rational(struct bm2835_mmal_dev *dev,
  12721. + struct v4l2_ctrl *ctrl,
  12722. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  12723. +{
  12724. + struct mmal_parameter_rational rational_value;
  12725. + struct vchiq_mmal_port *control;
  12726. +
  12727. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  12728. +
  12729. + rational_value.num = ctrl->val;
  12730. + rational_value.den = 100;
  12731. +
  12732. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  12733. + mmal_ctrl->mmal_id,
  12734. + &rational_value,
  12735. + sizeof(rational_value));
  12736. +}
  12737. +
  12738. +static int ctrl_set_value(struct bm2835_mmal_dev *dev,
  12739. + struct v4l2_ctrl *ctrl,
  12740. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  12741. +{
  12742. + u32 u32_value;
  12743. + struct vchiq_mmal_port *control;
  12744. +
  12745. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  12746. +
  12747. + u32_value = ctrl->val;
  12748. +
  12749. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  12750. + mmal_ctrl->mmal_id,
  12751. + &u32_value, sizeof(u32_value));
  12752. +}
  12753. +
  12754. +static int ctrl_set_value_menu(struct bm2835_mmal_dev *dev,
  12755. + struct v4l2_ctrl *ctrl,
  12756. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  12757. +{
  12758. + u32 u32_value;
  12759. + struct vchiq_mmal_port *control;
  12760. +
  12761. + if (ctrl->val > mmal_ctrl->max || ctrl->val < mmal_ctrl->min)
  12762. + return 1;
  12763. +
  12764. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  12765. +
  12766. + u32_value = mmal_ctrl->imenu[ctrl->val];
  12767. +
  12768. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  12769. + mmal_ctrl->mmal_id,
  12770. + &u32_value, sizeof(u32_value));
  12771. +}
  12772. +
  12773. +static int ctrl_set_value_ev(struct bm2835_mmal_dev *dev,
  12774. + struct v4l2_ctrl *ctrl,
  12775. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  12776. +{
  12777. + s32 s32_value;
  12778. + struct vchiq_mmal_port *control;
  12779. +
  12780. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  12781. +
  12782. + s32_value = (ctrl->val-12)*2; /* Convert from index to 1/6ths */
  12783. +
  12784. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  12785. + mmal_ctrl->mmal_id,
  12786. + &s32_value, sizeof(s32_value));
  12787. +}
  12788. +
  12789. +static int ctrl_set_rotate(struct bm2835_mmal_dev *dev,
  12790. + struct v4l2_ctrl *ctrl,
  12791. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  12792. +{
  12793. + int ret;
  12794. + u32 u32_value;
  12795. + struct vchiq_mmal_component *camera;
  12796. +
  12797. + camera = dev->component[MMAL_COMPONENT_CAMERA];
  12798. +
  12799. + u32_value = ((ctrl->val % 360) / 90) * 90;
  12800. +
  12801. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[0],
  12802. + mmal_ctrl->mmal_id,
  12803. + &u32_value, sizeof(u32_value));
  12804. + if (ret < 0)
  12805. + return ret;
  12806. +
  12807. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[1],
  12808. + mmal_ctrl->mmal_id,
  12809. + &u32_value, sizeof(u32_value));
  12810. + if (ret < 0)
  12811. + return ret;
  12812. +
  12813. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[2],
  12814. + mmal_ctrl->mmal_id,
  12815. + &u32_value, sizeof(u32_value));
  12816. +
  12817. + return ret;
  12818. +}
  12819. +
  12820. +static int ctrl_set_flip(struct bm2835_mmal_dev *dev,
  12821. + struct v4l2_ctrl *ctrl,
  12822. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  12823. +{
  12824. + int ret;
  12825. + u32 u32_value;
  12826. + struct vchiq_mmal_component *camera;
  12827. +
  12828. + if (ctrl->id == V4L2_CID_HFLIP)
  12829. + dev->hflip = ctrl->val;
  12830. + else
  12831. + dev->vflip = ctrl->val;
  12832. +
  12833. + camera = dev->component[MMAL_COMPONENT_CAMERA];
  12834. +
  12835. + if (dev->hflip && dev->vflip)
  12836. + u32_value = MMAL_PARAM_MIRROR_BOTH;
  12837. + else if (dev->hflip)
  12838. + u32_value = MMAL_PARAM_MIRROR_HORIZONTAL;
  12839. + else if (dev->vflip)
  12840. + u32_value = MMAL_PARAM_MIRROR_VERTICAL;
  12841. + else
  12842. + u32_value = MMAL_PARAM_MIRROR_NONE;
  12843. +
  12844. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[0],
  12845. + mmal_ctrl->mmal_id,
  12846. + &u32_value, sizeof(u32_value));
  12847. + if (ret < 0)
  12848. + return ret;
  12849. +
  12850. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[1],
  12851. + mmal_ctrl->mmal_id,
  12852. + &u32_value, sizeof(u32_value));
  12853. + if (ret < 0)
  12854. + return ret;
  12855. +
  12856. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[2],
  12857. + mmal_ctrl->mmal_id,
  12858. + &u32_value, sizeof(u32_value));
  12859. +
  12860. + return ret;
  12861. +
  12862. +}
  12863. +
  12864. +static int ctrl_set_exposure(struct bm2835_mmal_dev *dev,
  12865. + struct v4l2_ctrl *ctrl,
  12866. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  12867. +{
  12868. + enum mmal_parameter_exposuremode exp_mode = dev->exposure_mode_user;
  12869. + u32 shutter_speed = 0;
  12870. + struct vchiq_mmal_port *control;
  12871. + int ret = 0;
  12872. +
  12873. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  12874. +
  12875. + if (mmal_ctrl->mmal_id == MMAL_PARAMETER_SHUTTER_SPEED) {
  12876. + /* V4L2 is in 100usec increments.
  12877. + * MMAL is 1usec.
  12878. + */
  12879. + dev->manual_shutter_speed = ctrl->val * 100;
  12880. + } else if (mmal_ctrl->mmal_id == MMAL_PARAMETER_EXPOSURE_MODE) {
  12881. + switch (ctrl->val) {
  12882. + case V4L2_EXPOSURE_AUTO:
  12883. + exp_mode = MMAL_PARAM_EXPOSUREMODE_AUTO;
  12884. + break;
  12885. +
  12886. + case V4L2_EXPOSURE_MANUAL:
  12887. + exp_mode = MMAL_PARAM_EXPOSUREMODE_OFF;
  12888. + break;
  12889. + }
  12890. + dev->exposure_mode_user = exp_mode;
  12891. + dev->exposure_mode_v4l2_user = ctrl->val;
  12892. + } else if (mmal_ctrl->id == V4L2_CID_EXPOSURE_AUTO_PRIORITY) {
  12893. + dev->exp_auto_priority = ctrl->val;
  12894. + }
  12895. +
  12896. + if (dev->scene_mode == V4L2_SCENE_MODE_NONE) {
  12897. + if (exp_mode == MMAL_PARAM_EXPOSUREMODE_OFF)
  12898. + shutter_speed = dev->manual_shutter_speed;
  12899. +
  12900. + ret = vchiq_mmal_port_parameter_set(dev->instance,
  12901. + control,
  12902. + MMAL_PARAMETER_SHUTTER_SPEED,
  12903. + &shutter_speed,
  12904. + sizeof(shutter_speed));
  12905. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  12906. + control,
  12907. + MMAL_PARAMETER_EXPOSURE_MODE,
  12908. + &exp_mode,
  12909. + sizeof(u32));
  12910. + dev->exposure_mode_active = exp_mode;
  12911. + }
  12912. + /* exposure_dynamic_framerate (V4L2_CID_EXPOSURE_AUTO_PRIORITY) should
  12913. + * always apply irrespective of scene mode.
  12914. + */
  12915. + ret += set_framerate_params(dev);
  12916. +
  12917. + return ret;
  12918. +}
  12919. +
  12920. +static int ctrl_set_metering_mode(struct bm2835_mmal_dev *dev,
  12921. + struct v4l2_ctrl *ctrl,
  12922. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  12923. +{
  12924. + switch (ctrl->val) {
  12925. + case V4L2_EXPOSURE_METERING_AVERAGE:
  12926. + dev->metering_mode = MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE;
  12927. + break;
  12928. +
  12929. + case V4L2_EXPOSURE_METERING_CENTER_WEIGHTED:
  12930. + dev->metering_mode = MMAL_PARAM_EXPOSUREMETERINGMODE_BACKLIT;
  12931. + break;
  12932. +
  12933. + case V4L2_EXPOSURE_METERING_SPOT:
  12934. + dev->metering_mode = MMAL_PARAM_EXPOSUREMETERINGMODE_SPOT;
  12935. + break;
  12936. +
  12937. + /* todo matrix weighting not added to Linux API till 3.9
  12938. + case V4L2_EXPOSURE_METERING_MATRIX:
  12939. + dev->metering_mode = MMAL_PARAM_EXPOSUREMETERINGMODE_MATRIX;
  12940. + break;
  12941. + */
  12942. +
  12943. + }
  12944. +
  12945. + if (dev->scene_mode == V4L2_SCENE_MODE_NONE) {
  12946. + struct vchiq_mmal_port *control;
  12947. + u32 u32_value = dev->metering_mode;
  12948. +
  12949. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  12950. +
  12951. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  12952. + mmal_ctrl->mmal_id,
  12953. + &u32_value, sizeof(u32_value));
  12954. + } else
  12955. + return 0;
  12956. +}
  12957. +
  12958. +static int ctrl_set_flicker_avoidance(struct bm2835_mmal_dev *dev,
  12959. + struct v4l2_ctrl *ctrl,
  12960. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  12961. +{
  12962. + u32 u32_value;
  12963. + struct vchiq_mmal_port *control;
  12964. +
  12965. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  12966. +
  12967. + switch (ctrl->val) {
  12968. + case V4L2_CID_POWER_LINE_FREQUENCY_DISABLED:
  12969. + u32_value = MMAL_PARAM_FLICKERAVOID_OFF;
  12970. + break;
  12971. + case V4L2_CID_POWER_LINE_FREQUENCY_50HZ:
  12972. + u32_value = MMAL_PARAM_FLICKERAVOID_50HZ;
  12973. + break;
  12974. + case V4L2_CID_POWER_LINE_FREQUENCY_60HZ:
  12975. + u32_value = MMAL_PARAM_FLICKERAVOID_60HZ;
  12976. + break;
  12977. + case V4L2_CID_POWER_LINE_FREQUENCY_AUTO:
  12978. + u32_value = MMAL_PARAM_FLICKERAVOID_AUTO;
  12979. + break;
  12980. + }
  12981. +
  12982. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  12983. + mmal_ctrl->mmal_id,
  12984. + &u32_value, sizeof(u32_value));
  12985. +}
  12986. +
  12987. +static int ctrl_set_awb_mode(struct bm2835_mmal_dev *dev,
  12988. + struct v4l2_ctrl *ctrl,
  12989. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  12990. +{
  12991. + u32 u32_value;
  12992. + struct vchiq_mmal_port *control;
  12993. +
  12994. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  12995. +
  12996. + switch (ctrl->val) {
  12997. + case V4L2_WHITE_BALANCE_MANUAL:
  12998. + u32_value = MMAL_PARAM_AWBMODE_OFF;
  12999. + break;
  13000. +
  13001. + case V4L2_WHITE_BALANCE_AUTO:
  13002. + u32_value = MMAL_PARAM_AWBMODE_AUTO;
  13003. + break;
  13004. +
  13005. + case V4L2_WHITE_BALANCE_INCANDESCENT:
  13006. + u32_value = MMAL_PARAM_AWBMODE_INCANDESCENT;
  13007. + break;
  13008. +
  13009. + case V4L2_WHITE_BALANCE_FLUORESCENT:
  13010. + u32_value = MMAL_PARAM_AWBMODE_FLUORESCENT;
  13011. + break;
  13012. +
  13013. + case V4L2_WHITE_BALANCE_FLUORESCENT_H:
  13014. + u32_value = MMAL_PARAM_AWBMODE_TUNGSTEN;
  13015. + break;
  13016. +
  13017. + case V4L2_WHITE_BALANCE_HORIZON:
  13018. + u32_value = MMAL_PARAM_AWBMODE_HORIZON;
  13019. + break;
  13020. +
  13021. + case V4L2_WHITE_BALANCE_DAYLIGHT:
  13022. + u32_value = MMAL_PARAM_AWBMODE_SUNLIGHT;
  13023. + break;
  13024. +
  13025. + case V4L2_WHITE_BALANCE_FLASH:
  13026. + u32_value = MMAL_PARAM_AWBMODE_FLASH;
  13027. + break;
  13028. +
  13029. + case V4L2_WHITE_BALANCE_CLOUDY:
  13030. + u32_value = MMAL_PARAM_AWBMODE_CLOUDY;
  13031. + break;
  13032. +
  13033. + case V4L2_WHITE_BALANCE_SHADE:
  13034. + u32_value = MMAL_PARAM_AWBMODE_SHADE;
  13035. + break;
  13036. +
  13037. + }
  13038. +
  13039. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  13040. + mmal_ctrl->mmal_id,
  13041. + &u32_value, sizeof(u32_value));
  13042. +}
  13043. +
  13044. +static int ctrl_set_awb_gains(struct bm2835_mmal_dev *dev,
  13045. + struct v4l2_ctrl *ctrl,
  13046. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13047. +{
  13048. + struct vchiq_mmal_port *control;
  13049. + struct mmal_parameter_awbgains gains;
  13050. +
  13051. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  13052. +
  13053. + if (ctrl->id == V4L2_CID_RED_BALANCE)
  13054. + dev->red_gain = ctrl->val;
  13055. + else if (ctrl->id == V4L2_CID_BLUE_BALANCE)
  13056. + dev->blue_gain = ctrl->val;
  13057. +
  13058. + gains.r_gain.num = dev->red_gain;
  13059. + gains.b_gain.num = dev->blue_gain;
  13060. + gains.r_gain.den = gains.b_gain.den = 1000;
  13061. +
  13062. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  13063. + mmal_ctrl->mmal_id,
  13064. + &gains, sizeof(gains));
  13065. +}
  13066. +
  13067. +static int ctrl_set_image_effect(struct bm2835_mmal_dev *dev,
  13068. + struct v4l2_ctrl *ctrl,
  13069. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13070. +{
  13071. + int ret = -EINVAL;
  13072. + int i, j;
  13073. + struct vchiq_mmal_port *control;
  13074. + struct mmal_parameter_imagefx_parameters imagefx;
  13075. +
  13076. + for (i = 0; i < ARRAY_SIZE(v4l2_to_mmal_effects_values); i++) {
  13077. + if (ctrl->val == v4l2_to_mmal_effects_values[i].v4l2_effect) {
  13078. +
  13079. + imagefx.effect =
  13080. + v4l2_to_mmal_effects_values[i].mmal_effect;
  13081. + imagefx.num_effect_params =
  13082. + v4l2_to_mmal_effects_values[i].num_effect_params;
  13083. +
  13084. + if (imagefx.num_effect_params > MMAL_MAX_IMAGEFX_PARAMETERS)
  13085. + imagefx.num_effect_params = MMAL_MAX_IMAGEFX_PARAMETERS;
  13086. +
  13087. + for (j = 0; j < imagefx.num_effect_params; j++)
  13088. + imagefx.effect_parameter[j] =
  13089. + v4l2_to_mmal_effects_values[i].effect_params[j];
  13090. +
  13091. + dev->colourfx.enable =
  13092. + v4l2_to_mmal_effects_values[i].col_fx_enable;
  13093. + if (!v4l2_to_mmal_effects_values[i].col_fx_fixed_cbcr) {
  13094. + dev->colourfx.u =
  13095. + v4l2_to_mmal_effects_values[i].u;
  13096. + dev->colourfx.v =
  13097. + v4l2_to_mmal_effects_values[i].v;
  13098. + }
  13099. +
  13100. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  13101. +
  13102. + ret = vchiq_mmal_port_parameter_set(
  13103. + dev->instance, control,
  13104. + MMAL_PARAMETER_IMAGE_EFFECT_PARAMETERS,
  13105. + &imagefx, sizeof(imagefx));
  13106. + if (ret)
  13107. + goto exit;
  13108. +
  13109. + ret = vchiq_mmal_port_parameter_set(
  13110. + dev->instance, control,
  13111. + MMAL_PARAMETER_COLOUR_EFFECT,
  13112. + &dev->colourfx, sizeof(dev->colourfx));
  13113. + }
  13114. + }
  13115. +
  13116. +exit:
  13117. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  13118. + "mmal_ctrl:%p ctrl id:0x%x ctrl val:%d imagefx:0x%x color_effect:%s u:%d v:%d ret %d(%d)\n",
  13119. + mmal_ctrl, ctrl->id, ctrl->val, imagefx.effect,
  13120. + dev->colourfx.enable ? "true" : "false",
  13121. + dev->colourfx.u, dev->colourfx.v,
  13122. + ret, (ret == 0 ? 0 : -EINVAL));
  13123. + return (ret == 0 ? 0 : EINVAL);
  13124. +}
  13125. +
  13126. +static int ctrl_set_colfx(struct bm2835_mmal_dev *dev,
  13127. + struct v4l2_ctrl *ctrl,
  13128. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13129. +{
  13130. + int ret = -EINVAL;
  13131. + struct vchiq_mmal_port *control;
  13132. +
  13133. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  13134. +
  13135. + dev->colourfx.enable = (ctrl->val & 0xff00) >> 8;
  13136. + dev->colourfx.enable = ctrl->val & 0xff;
  13137. +
  13138. + ret = vchiq_mmal_port_parameter_set(dev->instance, control,
  13139. + MMAL_PARAMETER_COLOUR_EFFECT,
  13140. + &dev->colourfx, sizeof(dev->colourfx));
  13141. +
  13142. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  13143. + "%s: After: mmal_ctrl:%p ctrl id:0x%x ctrl val:%d ret %d(%d)\n",
  13144. + __func__, mmal_ctrl, ctrl->id, ctrl->val, ret,
  13145. + (ret == 0 ? 0 : -EINVAL));
  13146. + return (ret == 0 ? 0 : EINVAL);
  13147. +}
  13148. +
  13149. +static int ctrl_set_bitrate(struct bm2835_mmal_dev *dev,
  13150. + struct v4l2_ctrl *ctrl,
  13151. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13152. +{
  13153. + int ret;
  13154. + struct vchiq_mmal_port *encoder_out;
  13155. +
  13156. + dev->capture.encode_bitrate = ctrl->val;
  13157. +
  13158. + encoder_out = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  13159. +
  13160. + ret = vchiq_mmal_port_parameter_set(dev->instance, encoder_out,
  13161. + mmal_ctrl->mmal_id,
  13162. + &ctrl->val, sizeof(ctrl->val));
  13163. + ret = 0;
  13164. + return ret;
  13165. +}
  13166. +
  13167. +static int ctrl_set_bitrate_mode(struct bm2835_mmal_dev *dev,
  13168. + struct v4l2_ctrl *ctrl,
  13169. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13170. +{
  13171. + u32 bitrate_mode;
  13172. + struct vchiq_mmal_port *encoder_out;
  13173. +
  13174. + encoder_out = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  13175. +
  13176. + dev->capture.encode_bitrate_mode = ctrl->val;
  13177. + switch (ctrl->val) {
  13178. + default:
  13179. + case V4L2_MPEG_VIDEO_BITRATE_MODE_VBR:
  13180. + bitrate_mode = MMAL_VIDEO_RATECONTROL_VARIABLE;
  13181. + break;
  13182. + case V4L2_MPEG_VIDEO_BITRATE_MODE_CBR:
  13183. + bitrate_mode = MMAL_VIDEO_RATECONTROL_CONSTANT;
  13184. + break;
  13185. + }
  13186. +
  13187. + vchiq_mmal_port_parameter_set(dev->instance, encoder_out,
  13188. + mmal_ctrl->mmal_id,
  13189. + &bitrate_mode,
  13190. + sizeof(bitrate_mode));
  13191. + return 0;
  13192. +}
  13193. +
  13194. +static int ctrl_set_image_encode_output(struct bm2835_mmal_dev *dev,
  13195. + struct v4l2_ctrl *ctrl,
  13196. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13197. +{
  13198. + u32 u32_value;
  13199. + struct vchiq_mmal_port *jpeg_out;
  13200. +
  13201. + jpeg_out = &dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->output[0];
  13202. +
  13203. + u32_value = ctrl->val;
  13204. +
  13205. + return vchiq_mmal_port_parameter_set(dev->instance, jpeg_out,
  13206. + mmal_ctrl->mmal_id,
  13207. + &u32_value, sizeof(u32_value));
  13208. +}
  13209. +
  13210. +static int ctrl_set_video_encode_param_output(struct bm2835_mmal_dev *dev,
  13211. + struct v4l2_ctrl *ctrl,
  13212. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13213. +{
  13214. + u32 u32_value;
  13215. + struct vchiq_mmal_port *vid_enc_ctl;
  13216. +
  13217. + vid_enc_ctl = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  13218. +
  13219. + u32_value = ctrl->val;
  13220. +
  13221. + return vchiq_mmal_port_parameter_set(dev->instance, vid_enc_ctl,
  13222. + mmal_ctrl->mmal_id,
  13223. + &u32_value, sizeof(u32_value));
  13224. +}
  13225. +
  13226. +static int ctrl_set_video_encode_profile_level(struct bm2835_mmal_dev *dev,
  13227. + struct v4l2_ctrl *ctrl,
  13228. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13229. +{
  13230. + struct mmal_parameter_video_profile param;
  13231. + int ret = 0;
  13232. +
  13233. + if (ctrl->id == V4L2_CID_MPEG_VIDEO_H264_PROFILE) {
  13234. + switch (ctrl->val) {
  13235. + case V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE:
  13236. + case V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE:
  13237. + case V4L2_MPEG_VIDEO_H264_PROFILE_MAIN:
  13238. + case V4L2_MPEG_VIDEO_H264_PROFILE_HIGH:
  13239. + dev->capture.enc_profile = ctrl->val;
  13240. + break;
  13241. + default:
  13242. + ret = -EINVAL;
  13243. + break;
  13244. + }
  13245. + } else if (ctrl->id == V4L2_CID_MPEG_VIDEO_H264_LEVEL) {
  13246. + switch (ctrl->val) {
  13247. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_0:
  13248. + case V4L2_MPEG_VIDEO_H264_LEVEL_1B:
  13249. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_1:
  13250. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_2:
  13251. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_3:
  13252. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_0:
  13253. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_1:
  13254. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_2:
  13255. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_0:
  13256. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_1:
  13257. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_2:
  13258. + case V4L2_MPEG_VIDEO_H264_LEVEL_4_0:
  13259. + dev->capture.enc_level = ctrl->val;
  13260. + break;
  13261. + default:
  13262. + ret = -EINVAL;
  13263. + break;
  13264. + }
  13265. + }
  13266. +
  13267. + if (!ret) {
  13268. + switch (dev->capture.enc_profile) {
  13269. + case V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE:
  13270. + param.profile = MMAL_VIDEO_PROFILE_H264_BASELINE;
  13271. + break;
  13272. + case V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE:
  13273. + param.profile =
  13274. + MMAL_VIDEO_PROFILE_H264_CONSTRAINED_BASELINE;
  13275. + break;
  13276. + case V4L2_MPEG_VIDEO_H264_PROFILE_MAIN:
  13277. + param.profile = MMAL_VIDEO_PROFILE_H264_MAIN;
  13278. + break;
  13279. + case V4L2_MPEG_VIDEO_H264_PROFILE_HIGH:
  13280. + param.profile = MMAL_VIDEO_PROFILE_H264_HIGH;
  13281. + break;
  13282. + default:
  13283. + /* Should never get here */
  13284. + break;
  13285. + }
  13286. +
  13287. + switch (dev->capture.enc_level) {
  13288. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_0:
  13289. + param.level = MMAL_VIDEO_LEVEL_H264_1;
  13290. + break;
  13291. + case V4L2_MPEG_VIDEO_H264_LEVEL_1B:
  13292. + param.level = MMAL_VIDEO_LEVEL_H264_1b;
  13293. + break;
  13294. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_1:
  13295. + param.level = MMAL_VIDEO_LEVEL_H264_11;
  13296. + break;
  13297. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_2:
  13298. + param.level = MMAL_VIDEO_LEVEL_H264_12;
  13299. + break;
  13300. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_3:
  13301. + param.level = MMAL_VIDEO_LEVEL_H264_13;
  13302. + break;
  13303. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_0:
  13304. + param.level = MMAL_VIDEO_LEVEL_H264_2;
  13305. + break;
  13306. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_1:
  13307. + param.level = MMAL_VIDEO_LEVEL_H264_21;
  13308. + break;
  13309. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_2:
  13310. + param.level = MMAL_VIDEO_LEVEL_H264_22;
  13311. + break;
  13312. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_0:
  13313. + param.level = MMAL_VIDEO_LEVEL_H264_3;
  13314. + break;
  13315. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_1:
  13316. + param.level = MMAL_VIDEO_LEVEL_H264_31;
  13317. + break;
  13318. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_2:
  13319. + param.level = MMAL_VIDEO_LEVEL_H264_32;
  13320. + break;
  13321. + case V4L2_MPEG_VIDEO_H264_LEVEL_4_0:
  13322. + param.level = MMAL_VIDEO_LEVEL_H264_4;
  13323. + break;
  13324. + default:
  13325. + /* Should never get here */
  13326. + break;
  13327. + }
  13328. +
  13329. + ret = vchiq_mmal_port_parameter_set(dev->instance,
  13330. + &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0],
  13331. + mmal_ctrl->mmal_id,
  13332. + &param, sizeof(param));
  13333. + }
  13334. + return ret;
  13335. +}
  13336. +
  13337. +static int ctrl_set_scene_mode(struct bm2835_mmal_dev *dev,
  13338. + struct v4l2_ctrl *ctrl,
  13339. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13340. +{
  13341. + int ret = 0;
  13342. + int shutter_speed;
  13343. + struct vchiq_mmal_port *control;
  13344. +
  13345. + v4l2_dbg(0, bcm2835_v4l2_debug, &dev->v4l2_dev,
  13346. + "scene mode selected %d, was %d\n", ctrl->val,
  13347. + dev->scene_mode);
  13348. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  13349. +
  13350. + if (ctrl->val == dev->scene_mode)
  13351. + return 0;
  13352. +
  13353. + if (ctrl->val == V4L2_SCENE_MODE_NONE) {
  13354. + /* Restore all user selections */
  13355. + dev->scene_mode = V4L2_SCENE_MODE_NONE;
  13356. +
  13357. + if (dev->exposure_mode_user == MMAL_PARAM_EXPOSUREMODE_OFF)
  13358. + shutter_speed = dev->manual_shutter_speed;
  13359. + else
  13360. + shutter_speed = 0;
  13361. +
  13362. + v4l2_dbg(0, bcm2835_v4l2_debug, &dev->v4l2_dev,
  13363. + "%s: scene mode none: shut_speed %d, exp_mode %d, metering %d\n",
  13364. + __func__, shutter_speed, dev->exposure_mode_user,
  13365. + dev->metering_mode);
  13366. + ret = vchiq_mmal_port_parameter_set(dev->instance,
  13367. + control,
  13368. + MMAL_PARAMETER_SHUTTER_SPEED,
  13369. + &shutter_speed,
  13370. + sizeof(shutter_speed));
  13371. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  13372. + control,
  13373. + MMAL_PARAMETER_EXPOSURE_MODE,
  13374. + &dev->exposure_mode_user,
  13375. + sizeof(u32));
  13376. + dev->exposure_mode_active = dev->exposure_mode_user;
  13377. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  13378. + control,
  13379. + MMAL_PARAMETER_EXP_METERING_MODE,
  13380. + &dev->metering_mode,
  13381. + sizeof(u32));
  13382. + ret += set_framerate_params(dev);
  13383. + } else {
  13384. + /* Set up scene mode */
  13385. + int i;
  13386. + const struct v4l2_mmal_scene_config *scene = NULL;
  13387. + int shutter_speed;
  13388. + enum mmal_parameter_exposuremode exposure_mode;
  13389. + enum mmal_parameter_exposuremeteringmode metering_mode;
  13390. +
  13391. + for (i = 0; i < ARRAY_SIZE(scene_configs); i++) {
  13392. + if (scene_configs[i].v4l2_scene ==
  13393. + ctrl->val) {
  13394. + scene = &scene_configs[i];
  13395. + break;
  13396. + }
  13397. + }
  13398. + if (i >= ARRAY_SIZE(scene_configs))
  13399. + return -EINVAL;
  13400. +
  13401. + /* Set all the values */
  13402. + dev->scene_mode = ctrl->val;
  13403. +
  13404. + if (scene->exposure_mode == MMAL_PARAM_EXPOSUREMODE_OFF)
  13405. + shutter_speed = dev->manual_shutter_speed;
  13406. + else
  13407. + shutter_speed = 0;
  13408. + exposure_mode = scene->exposure_mode;
  13409. + metering_mode = scene->metering_mode;
  13410. +
  13411. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  13412. + "%s: scene mode none: shut_speed %d, exp_mode %d, metering %d\n",
  13413. + __func__, shutter_speed, exposure_mode, metering_mode);
  13414. +
  13415. + ret = vchiq_mmal_port_parameter_set(dev->instance, control,
  13416. + MMAL_PARAMETER_SHUTTER_SPEED,
  13417. + &shutter_speed,
  13418. + sizeof(shutter_speed));
  13419. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  13420. + control,
  13421. + MMAL_PARAMETER_EXPOSURE_MODE,
  13422. + &exposure_mode,
  13423. + sizeof(u32));
  13424. + dev->exposure_mode_active = exposure_mode;
  13425. + ret += vchiq_mmal_port_parameter_set(dev->instance, control,
  13426. + MMAL_PARAMETER_EXPOSURE_MODE,
  13427. + &exposure_mode,
  13428. + sizeof(u32));
  13429. + ret += vchiq_mmal_port_parameter_set(dev->instance, control,
  13430. + MMAL_PARAMETER_EXP_METERING_MODE,
  13431. + &metering_mode,
  13432. + sizeof(u32));
  13433. + ret += set_framerate_params(dev);
  13434. + }
  13435. + if (ret) {
  13436. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  13437. + "%s: Setting scene to %d, ret=%d\n",
  13438. + __func__, ctrl->val, ret);
  13439. + ret = -EINVAL;
  13440. + }
  13441. + return 0;
  13442. +}
  13443. +
  13444. +static int bm2835_mmal_s_ctrl(struct v4l2_ctrl *ctrl)
  13445. +{
  13446. + struct bm2835_mmal_dev *dev =
  13447. + container_of(ctrl->handler, struct bm2835_mmal_dev,
  13448. + ctrl_handler);
  13449. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl = ctrl->priv;
  13450. + int ret;
  13451. +
  13452. + if ((mmal_ctrl == NULL) ||
  13453. + (mmal_ctrl->id != ctrl->id) ||
  13454. + (mmal_ctrl->setter == NULL)) {
  13455. + pr_warn("mmal_ctrl:%p ctrl id:%d\n", mmal_ctrl, ctrl->id);
  13456. + return -EINVAL;
  13457. + }
  13458. +
  13459. + ret = mmal_ctrl->setter(dev, ctrl, mmal_ctrl);
  13460. + if (ret)
  13461. + pr_warn("ctrl id:%d/MMAL param %08X- returned ret %d\n",
  13462. + ctrl->id, mmal_ctrl->mmal_id, ret);
  13463. + if (mmal_ctrl->ignore_errors)
  13464. + ret = 0;
  13465. + return ret;
  13466. +}
  13467. +
  13468. +static const struct v4l2_ctrl_ops bm2835_mmal_ctrl_ops = {
  13469. + .s_ctrl = bm2835_mmal_s_ctrl,
  13470. +};
  13471. +
  13472. +
  13473. +
  13474. +static const struct bm2835_mmal_v4l2_ctrl v4l2_ctrls[V4L2_CTRL_COUNT] = {
  13475. + {
  13476. + V4L2_CID_SATURATION, MMAL_CONTROL_TYPE_STD,
  13477. + -100, 100, 0, 1, NULL,
  13478. + MMAL_PARAMETER_SATURATION,
  13479. + &ctrl_set_rational,
  13480. + false
  13481. + },
  13482. + {
  13483. + V4L2_CID_SHARPNESS, MMAL_CONTROL_TYPE_STD,
  13484. + -100, 100, 0, 1, NULL,
  13485. + MMAL_PARAMETER_SHARPNESS,
  13486. + &ctrl_set_rational,
  13487. + false
  13488. + },
  13489. + {
  13490. + V4L2_CID_CONTRAST, MMAL_CONTROL_TYPE_STD,
  13491. + -100, 100, 0, 1, NULL,
  13492. + MMAL_PARAMETER_CONTRAST,
  13493. + &ctrl_set_rational,
  13494. + false
  13495. + },
  13496. + {
  13497. + V4L2_CID_BRIGHTNESS, MMAL_CONTROL_TYPE_STD,
  13498. + 0, 100, 50, 1, NULL,
  13499. + MMAL_PARAMETER_BRIGHTNESS,
  13500. + &ctrl_set_rational,
  13501. + false
  13502. + },
  13503. + {
  13504. + V4L2_CID_ISO_SENSITIVITY, MMAL_CONTROL_TYPE_INT_MENU,
  13505. + 0, ARRAY_SIZE(iso_qmenu) - 1, 0, 1, iso_qmenu,
  13506. + MMAL_PARAMETER_ISO,
  13507. + &ctrl_set_value_menu,
  13508. + false
  13509. + },
  13510. + {
  13511. + V4L2_CID_IMAGE_STABILIZATION, MMAL_CONTROL_TYPE_STD,
  13512. + 0, 1, 0, 1, NULL,
  13513. + MMAL_PARAMETER_VIDEO_STABILISATION,
  13514. + &ctrl_set_value,
  13515. + false
  13516. + },
  13517. +/* {
  13518. + 0, MMAL_CONTROL_TYPE_CLUSTER, 3, 1, 0, NULL, 0, NULL
  13519. + },
  13520. +*/ {
  13521. + V4L2_CID_EXPOSURE_AUTO, MMAL_CONTROL_TYPE_STD_MENU,
  13522. + ~0x03, 3, V4L2_EXPOSURE_AUTO, 0, NULL,
  13523. + MMAL_PARAMETER_EXPOSURE_MODE,
  13524. + &ctrl_set_exposure,
  13525. + false
  13526. + },
  13527. +/* todo this needs mixing in with set exposure
  13528. + {
  13529. + V4L2_CID_SCENE_MODE, MMAL_CONTROL_TYPE_STD_MENU,
  13530. + },
  13531. + */
  13532. + {
  13533. + V4L2_CID_EXPOSURE_ABSOLUTE, MMAL_CONTROL_TYPE_STD,
  13534. + /* Units of 100usecs */
  13535. + 1, 1*1000*10, 100*10, 1, NULL,
  13536. + MMAL_PARAMETER_SHUTTER_SPEED,
  13537. + &ctrl_set_exposure,
  13538. + false
  13539. + },
  13540. + {
  13541. + V4L2_CID_AUTO_EXPOSURE_BIAS, MMAL_CONTROL_TYPE_INT_MENU,
  13542. + 0, ARRAY_SIZE(ev_bias_qmenu) - 1,
  13543. + (ARRAY_SIZE(ev_bias_qmenu)+1)/2 - 1, 0, ev_bias_qmenu,
  13544. + MMAL_PARAMETER_EXPOSURE_COMP,
  13545. + &ctrl_set_value_ev,
  13546. + false
  13547. + },
  13548. + {
  13549. + V4L2_CID_EXPOSURE_AUTO_PRIORITY, MMAL_CONTROL_TYPE_STD,
  13550. + 0, 1,
  13551. + 0, 1, NULL,
  13552. + 0, /* Dummy MMAL ID as it gets mapped into FPS range*/
  13553. + &ctrl_set_exposure,
  13554. + false
  13555. + },
  13556. + {
  13557. + V4L2_CID_EXPOSURE_METERING,
  13558. + MMAL_CONTROL_TYPE_STD_MENU,
  13559. + ~0x7, 2, V4L2_EXPOSURE_METERING_AVERAGE, 0, NULL,
  13560. + MMAL_PARAMETER_EXP_METERING_MODE,
  13561. + &ctrl_set_metering_mode,
  13562. + false
  13563. + },
  13564. + {
  13565. + V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE,
  13566. + MMAL_CONTROL_TYPE_STD_MENU,
  13567. + ~0x3ff, 9, V4L2_WHITE_BALANCE_AUTO, 0, NULL,
  13568. + MMAL_PARAMETER_AWB_MODE,
  13569. + &ctrl_set_awb_mode,
  13570. + false
  13571. + },
  13572. + {
  13573. + V4L2_CID_RED_BALANCE, MMAL_CONTROL_TYPE_STD,
  13574. + 1, 7999, 1000, 1, NULL,
  13575. + MMAL_PARAMETER_CUSTOM_AWB_GAINS,
  13576. + &ctrl_set_awb_gains,
  13577. + false
  13578. + },
  13579. + {
  13580. + V4L2_CID_BLUE_BALANCE, MMAL_CONTROL_TYPE_STD,
  13581. + 1, 7999, 1000, 1, NULL,
  13582. + MMAL_PARAMETER_CUSTOM_AWB_GAINS,
  13583. + &ctrl_set_awb_gains,
  13584. + false
  13585. + },
  13586. + {
  13587. + V4L2_CID_COLORFX, MMAL_CONTROL_TYPE_STD_MENU,
  13588. + 0, 15, V4L2_COLORFX_NONE, 0, NULL,
  13589. + MMAL_PARAMETER_IMAGE_EFFECT,
  13590. + &ctrl_set_image_effect,
  13591. + false
  13592. + },
  13593. + {
  13594. + V4L2_CID_COLORFX_CBCR, MMAL_CONTROL_TYPE_STD,
  13595. + 0, 0xffff, 0x8080, 1, NULL,
  13596. + MMAL_PARAMETER_COLOUR_EFFECT,
  13597. + &ctrl_set_colfx,
  13598. + false
  13599. + },
  13600. + {
  13601. + V4L2_CID_ROTATE, MMAL_CONTROL_TYPE_STD,
  13602. + 0, 360, 0, 90, NULL,
  13603. + MMAL_PARAMETER_ROTATION,
  13604. + &ctrl_set_rotate,
  13605. + false
  13606. + },
  13607. + {
  13608. + V4L2_CID_HFLIP, MMAL_CONTROL_TYPE_STD,
  13609. + 0, 1, 0, 1, NULL,
  13610. + MMAL_PARAMETER_MIRROR,
  13611. + &ctrl_set_flip,
  13612. + false
  13613. + },
  13614. + {
  13615. + V4L2_CID_VFLIP, MMAL_CONTROL_TYPE_STD,
  13616. + 0, 1, 0, 1, NULL,
  13617. + MMAL_PARAMETER_MIRROR,
  13618. + &ctrl_set_flip,
  13619. + false
  13620. + },
  13621. + {
  13622. + V4L2_CID_MPEG_VIDEO_BITRATE_MODE, MMAL_CONTROL_TYPE_STD_MENU,
  13623. + 0, ARRAY_SIZE(bitrate_mode_qmenu) - 1,
  13624. + 0, 0, bitrate_mode_qmenu,
  13625. + MMAL_PARAMETER_RATECONTROL,
  13626. + &ctrl_set_bitrate_mode,
  13627. + false
  13628. + },
  13629. + {
  13630. + V4L2_CID_MPEG_VIDEO_BITRATE, MMAL_CONTROL_TYPE_STD,
  13631. + 25*1000, 25*1000*1000, 10*1000*1000, 25*1000, NULL,
  13632. + MMAL_PARAMETER_VIDEO_BIT_RATE,
  13633. + &ctrl_set_bitrate,
  13634. + false
  13635. + },
  13636. + {
  13637. + V4L2_CID_JPEG_COMPRESSION_QUALITY, MMAL_CONTROL_TYPE_STD,
  13638. + 1, 100,
  13639. + 30, 1, NULL,
  13640. + MMAL_PARAMETER_JPEG_Q_FACTOR,
  13641. + &ctrl_set_image_encode_output,
  13642. + false
  13643. + },
  13644. + {
  13645. + V4L2_CID_POWER_LINE_FREQUENCY, MMAL_CONTROL_TYPE_STD_MENU,
  13646. + 0, ARRAY_SIZE(mains_freq_qmenu) - 1,
  13647. + 1, 1, NULL,
  13648. + MMAL_PARAMETER_FLICKER_AVOID,
  13649. + &ctrl_set_flicker_avoidance,
  13650. + false
  13651. + },
  13652. + {
  13653. + V4L2_CID_MPEG_VIDEO_REPEAT_SEQ_HEADER, MMAL_CONTROL_TYPE_STD,
  13654. + 0, 1,
  13655. + 0, 1, NULL,
  13656. + MMAL_PARAMETER_VIDEO_ENCODE_INLINE_HEADER,
  13657. + &ctrl_set_video_encode_param_output,
  13658. + true /* Errors ignored as requires latest firmware to work */
  13659. + },
  13660. + {
  13661. + V4L2_CID_MPEG_VIDEO_H264_PROFILE,
  13662. + MMAL_CONTROL_TYPE_STD_MENU,
  13663. + ~((1<<V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE) |
  13664. + (1<<V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE) |
  13665. + (1<<V4L2_MPEG_VIDEO_H264_PROFILE_MAIN) |
  13666. + (1<<V4L2_MPEG_VIDEO_H264_PROFILE_HIGH)),
  13667. + V4L2_MPEG_VIDEO_H264_PROFILE_HIGH,
  13668. + V4L2_MPEG_VIDEO_H264_PROFILE_HIGH, 1, NULL,
  13669. + MMAL_PARAMETER_PROFILE,
  13670. + &ctrl_set_video_encode_profile_level,
  13671. + false
  13672. + },
  13673. + {
  13674. + V4L2_CID_MPEG_VIDEO_H264_LEVEL, MMAL_CONTROL_TYPE_STD_MENU,
  13675. + ~((1<<V4L2_MPEG_VIDEO_H264_LEVEL_1_0) |
  13676. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_1B) |
  13677. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_1_1) |
  13678. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_1_2) |
  13679. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_1_3) |
  13680. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_2_0) |
  13681. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_2_1) |
  13682. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_2_2) |
  13683. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_3_0) |
  13684. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_3_1) |
  13685. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_3_2) |
  13686. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_4_0)),
  13687. + V4L2_MPEG_VIDEO_H264_LEVEL_4_0,
  13688. + V4L2_MPEG_VIDEO_H264_LEVEL_4_0, 1, NULL,
  13689. + MMAL_PARAMETER_PROFILE,
  13690. + &ctrl_set_video_encode_profile_level,
  13691. + false
  13692. + },
  13693. + {
  13694. + V4L2_CID_SCENE_MODE, MMAL_CONTROL_TYPE_STD_MENU,
  13695. + -1, /* Min is computed at runtime */
  13696. + V4L2_SCENE_MODE_TEXT,
  13697. + V4L2_SCENE_MODE_NONE, 1, NULL,
  13698. + MMAL_PARAMETER_PROFILE,
  13699. + &ctrl_set_scene_mode,
  13700. + false
  13701. + },
  13702. +};
  13703. +
  13704. +int bm2835_mmal_set_all_camera_controls(struct bm2835_mmal_dev *dev)
  13705. +{
  13706. + int c;
  13707. + int ret = 0;
  13708. +
  13709. + for (c = 0; c < V4L2_CTRL_COUNT; c++) {
  13710. + if ((dev->ctrls[c]) && (v4l2_ctrls[c].setter)) {
  13711. + ret = v4l2_ctrls[c].setter(dev, dev->ctrls[c],
  13712. + &v4l2_ctrls[c]);
  13713. + if (!v4l2_ctrls[c].ignore_errors && ret) {
  13714. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  13715. + "Failed when setting default values for ctrl %d\n",
  13716. + c);
  13717. + break;
  13718. + }
  13719. + }
  13720. + }
  13721. + return ret;
  13722. +}
  13723. +
  13724. +int set_framerate_params(struct bm2835_mmal_dev *dev)
  13725. +{
  13726. + struct mmal_parameter_fps_range fps_range;
  13727. + int ret;
  13728. +
  13729. + if ((dev->exposure_mode_active != MMAL_PARAM_EXPOSUREMODE_OFF) &&
  13730. + (dev->exp_auto_priority)) {
  13731. + /* Variable FPS. Define min FPS as 1fps.
  13732. + * Max as max defined FPS.
  13733. + */
  13734. + fps_range.fps_low.num = 1;
  13735. + fps_range.fps_low.den = 1;
  13736. + fps_range.fps_high.num = dev->capture.timeperframe.denominator;
  13737. + fps_range.fps_high.den = dev->capture.timeperframe.numerator;
  13738. + } else {
  13739. + /* Fixed FPS - set min and max to be the same */
  13740. + fps_range.fps_low.num = fps_range.fps_high.num =
  13741. + dev->capture.timeperframe.denominator;
  13742. + fps_range.fps_low.den = fps_range.fps_high.den =
  13743. + dev->capture.timeperframe.numerator;
  13744. + }
  13745. +
  13746. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  13747. + "Set fps range to %d/%d to %d/%d\n",
  13748. + fps_range.fps_low.num,
  13749. + fps_range.fps_low.den,
  13750. + fps_range.fps_high.num,
  13751. + fps_range.fps_high.den
  13752. + );
  13753. +
  13754. + ret = vchiq_mmal_port_parameter_set(dev->instance,
  13755. + &dev->component[MMAL_COMPONENT_CAMERA]->
  13756. + output[MMAL_CAMERA_PORT_PREVIEW],
  13757. + MMAL_PARAMETER_FPS_RANGE,
  13758. + &fps_range, sizeof(fps_range));
  13759. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  13760. + &dev->component[MMAL_COMPONENT_CAMERA]->
  13761. + output[MMAL_CAMERA_PORT_VIDEO],
  13762. + MMAL_PARAMETER_FPS_RANGE,
  13763. + &fps_range, sizeof(fps_range));
  13764. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  13765. + &dev->component[MMAL_COMPONENT_CAMERA]->
  13766. + output[MMAL_CAMERA_PORT_CAPTURE],
  13767. + MMAL_PARAMETER_FPS_RANGE,
  13768. + &fps_range, sizeof(fps_range));
  13769. + if (ret)
  13770. + v4l2_dbg(0, bcm2835_v4l2_debug, &dev->v4l2_dev,
  13771. + "Failed to set fps ret %d\n",
  13772. + ret);
  13773. +
  13774. + return ret;
  13775. +
  13776. +}
  13777. +
  13778. +int bm2835_mmal_init_controls(struct bm2835_mmal_dev *dev,
  13779. + struct v4l2_ctrl_handler *hdl)
  13780. +{
  13781. + int c;
  13782. + const struct bm2835_mmal_v4l2_ctrl *ctrl;
  13783. +
  13784. + v4l2_ctrl_handler_init(hdl, V4L2_CTRL_COUNT);
  13785. +
  13786. + for (c = 0; c < V4L2_CTRL_COUNT; c++) {
  13787. + ctrl = &v4l2_ctrls[c];
  13788. +
  13789. + switch (ctrl->type) {
  13790. + case MMAL_CONTROL_TYPE_STD:
  13791. + dev->ctrls[c] = v4l2_ctrl_new_std(hdl,
  13792. + &bm2835_mmal_ctrl_ops, ctrl->id,
  13793. + ctrl->min, ctrl->max, ctrl->step, ctrl->def);
  13794. + break;
  13795. +
  13796. + case MMAL_CONTROL_TYPE_STD_MENU:
  13797. + {
  13798. + int mask = ctrl->min;
  13799. +
  13800. + if (ctrl->id == V4L2_CID_SCENE_MODE) {
  13801. + /* Special handling to work out the mask
  13802. + * value based on the scene_configs array
  13803. + * at runtime. Reduces the chance of
  13804. + * mismatches.
  13805. + */
  13806. + int i;
  13807. + mask = 1<<V4L2_SCENE_MODE_NONE;
  13808. + for (i = 0;
  13809. + i < ARRAY_SIZE(scene_configs);
  13810. + i++) {
  13811. + mask |= 1<<scene_configs[i].v4l2_scene;
  13812. + }
  13813. + mask = ~mask;
  13814. + }
  13815. +
  13816. + dev->ctrls[c] = v4l2_ctrl_new_std_menu(hdl,
  13817. + &bm2835_mmal_ctrl_ops, ctrl->id,
  13818. + ctrl->max, mask, ctrl->def);
  13819. + break;
  13820. + }
  13821. +
  13822. + case MMAL_CONTROL_TYPE_INT_MENU:
  13823. + dev->ctrls[c] = v4l2_ctrl_new_int_menu(hdl,
  13824. + &bm2835_mmal_ctrl_ops, ctrl->id,
  13825. + ctrl->max, ctrl->def, ctrl->imenu);
  13826. + break;
  13827. +
  13828. + case MMAL_CONTROL_TYPE_CLUSTER:
  13829. + /* skip this entry when constructing controls */
  13830. + continue;
  13831. + }
  13832. +
  13833. + if (hdl->error)
  13834. + break;
  13835. +
  13836. + dev->ctrls[c]->priv = (void *)ctrl;
  13837. + }
  13838. +
  13839. + if (hdl->error) {
  13840. + pr_err("error adding control %d/%d id 0x%x\n", c,
  13841. + V4L2_CTRL_COUNT, ctrl->id);
  13842. + return hdl->error;
  13843. + }
  13844. +
  13845. + for (c = 0; c < V4L2_CTRL_COUNT; c++) {
  13846. + ctrl = &v4l2_ctrls[c];
  13847. +
  13848. + switch (ctrl->type) {
  13849. + case MMAL_CONTROL_TYPE_CLUSTER:
  13850. + v4l2_ctrl_auto_cluster(ctrl->min,
  13851. + &dev->ctrls[c+1],
  13852. + ctrl->max,
  13853. + ctrl->def);
  13854. + break;
  13855. +
  13856. + case MMAL_CONTROL_TYPE_STD:
  13857. + case MMAL_CONTROL_TYPE_STD_MENU:
  13858. + case MMAL_CONTROL_TYPE_INT_MENU:
  13859. + break;
  13860. + }
  13861. +
  13862. + }
  13863. +
  13864. + return 0;
  13865. +}
  13866. diff -Nur linux-3.13.11/drivers/media/platform/bcm2835/Kconfig linux-rpi/drivers/media/platform/bcm2835/Kconfig
  13867. --- linux-3.13.11/drivers/media/platform/bcm2835/Kconfig 1970-01-01 01:00:00.000000000 +0100
  13868. +++ linux-rpi/drivers/media/platform/bcm2835/Kconfig 2014-04-24 15:35:02.713549510 +0200
  13869. @@ -0,0 +1,25 @@
  13870. +# Broadcom VideoCore IV v4l2 camera support
  13871. +
  13872. +config VIDEO_BCM2835
  13873. + bool "Broadcom BCM2835 camera interface driver"
  13874. + depends on VIDEO_V4L2 && ARCH_BCM2708
  13875. + ---help---
  13876. + Say Y here to enable camera host interface devices for
  13877. + Broadcom BCM2835 SoC. This operates over the VCHIQ interface
  13878. + to a service running on VideoCore.
  13879. +
  13880. +
  13881. +if VIDEO_BCM2835
  13882. +
  13883. +config VIDEO_BCM2835_MMAL
  13884. + tristate "Broadcom BM2835 MMAL camera interface driver"
  13885. + depends on BCM2708_VCHIQ
  13886. + select VIDEOBUF2_VMALLOC
  13887. + ---help---
  13888. + This is a V4L2 driver for the Broadcom BCM2835 MMAL camera host interface
  13889. +
  13890. + To compile this driver as a module, choose M here: the
  13891. + module will be called bcm2835-v4l2.o
  13892. +
  13893. +
  13894. +endif # VIDEO_BM2835
  13895. diff -Nur linux-3.13.11/drivers/media/platform/bcm2835/Makefile linux-rpi/drivers/media/platform/bcm2835/Makefile
  13896. --- linux-3.13.11/drivers/media/platform/bcm2835/Makefile 1970-01-01 01:00:00.000000000 +0100
  13897. +++ linux-rpi/drivers/media/platform/bcm2835/Makefile 2014-04-24 15:35:02.713549510 +0200
  13898. @@ -0,0 +1,5 @@
  13899. +bcm2835-v4l2-objs := bcm2835-camera.o controls.o mmal-vchiq.o
  13900. +
  13901. +obj-$(CONFIG_VIDEO_BCM2835_MMAL) += bcm2835-v4l2.o
  13902. +
  13903. +ccflags-$(CONFIG_VIDEO_BCM2835) += -Idrivers/misc/vc04_services -Idrivers/misc/vc04_services/interface/vcos/linuxkernel -D__VCCOREVER__=0x04000000
  13904. diff -Nur linux-3.13.11/drivers/media/platform/bcm2835/mmal-common.h linux-rpi/drivers/media/platform/bcm2835/mmal-common.h
  13905. --- linux-3.13.11/drivers/media/platform/bcm2835/mmal-common.h 1970-01-01 01:00:00.000000000 +0100
  13906. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-common.h 2014-04-24 15:35:02.713549510 +0200
  13907. @@ -0,0 +1,53 @@
  13908. +/*
  13909. + * Broadcom BM2835 V4L2 driver
  13910. + *
  13911. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  13912. + *
  13913. + * This file is subject to the terms and conditions of the GNU General Public
  13914. + * License. See the file COPYING in the main directory of this archive
  13915. + * for more details.
  13916. + *
  13917. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  13918. + * Dave Stevenson <dsteve@broadcom.com>
  13919. + * Simon Mellor <simellor@broadcom.com>
  13920. + * Luke Diamand <luked@broadcom.com>
  13921. + *
  13922. + * MMAL structures
  13923. + *
  13924. + */
  13925. +
  13926. +#define MMAL_FOURCC(a, b, c, d) ((a) | (b << 8) | (c << 16) | (d << 24))
  13927. +#define MMAL_MAGIC MMAL_FOURCC('m', 'm', 'a', 'l')
  13928. +
  13929. +/** Special value signalling that time is not known */
  13930. +#define MMAL_TIME_UNKNOWN (1LL<<63)
  13931. +
  13932. +/* mapping between v4l and mmal video modes */
  13933. +struct mmal_fmt {
  13934. + char *name;
  13935. + u32 fourcc; /* v4l2 format id */
  13936. + int flags; /* v4l2 flags field */
  13937. + u32 mmal;
  13938. + int depth;
  13939. + u32 mmal_component; /* MMAL component index to be used to encode */
  13940. +};
  13941. +
  13942. +/* buffer for one video frame */
  13943. +struct mmal_buffer {
  13944. + /* v4l buffer data -- must be first */
  13945. + struct vb2_buffer vb;
  13946. +
  13947. + /* list of buffers available */
  13948. + struct list_head list;
  13949. +
  13950. + void *buffer; /* buffer pointer */
  13951. + unsigned long buffer_size; /* size of allocated buffer */
  13952. +};
  13953. +
  13954. +/* */
  13955. +struct mmal_colourfx {
  13956. + s32 enable;
  13957. + u32 u;
  13958. + u32 v;
  13959. +};
  13960. +
  13961. diff -Nur linux-3.13.11/drivers/media/platform/bcm2835/mmal-encodings.h linux-rpi/drivers/media/platform/bcm2835/mmal-encodings.h
  13962. --- linux-3.13.11/drivers/media/platform/bcm2835/mmal-encodings.h 1970-01-01 01:00:00.000000000 +0100
  13963. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-encodings.h 2014-04-24 15:35:02.713549510 +0200
  13964. @@ -0,0 +1,94 @@
  13965. +/*
  13966. + * Broadcom BM2835 V4L2 driver
  13967. + *
  13968. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  13969. + *
  13970. + * This file is subject to the terms and conditions of the GNU General Public
  13971. + * License. See the file COPYING in the main directory of this archive
  13972. + * for more details.
  13973. + *
  13974. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  13975. + * Dave Stevenson <dsteve@broadcom.com>
  13976. + * Simon Mellor <simellor@broadcom.com>
  13977. + * Luke Diamand <luked@broadcom.com>
  13978. + */
  13979. +
  13980. +#define MMAL_ENCODING_H264 MMAL_FOURCC('H', '2', '6', '4')
  13981. +#define MMAL_ENCODING_H263 MMAL_FOURCC('H', '2', '6', '3')
  13982. +#define MMAL_ENCODING_MP4V MMAL_FOURCC('M', 'P', '4', 'V')
  13983. +#define MMAL_ENCODING_MP2V MMAL_FOURCC('M', 'P', '2', 'V')
  13984. +#define MMAL_ENCODING_MP1V MMAL_FOURCC('M', 'P', '1', 'V')
  13985. +#define MMAL_ENCODING_WMV3 MMAL_FOURCC('W', 'M', 'V', '3')
  13986. +#define MMAL_ENCODING_WMV2 MMAL_FOURCC('W', 'M', 'V', '2')
  13987. +#define MMAL_ENCODING_WMV1 MMAL_FOURCC('W', 'M', 'V', '1')
  13988. +#define MMAL_ENCODING_WVC1 MMAL_FOURCC('W', 'V', 'C', '1')
  13989. +#define MMAL_ENCODING_VP8 MMAL_FOURCC('V', 'P', '8', ' ')
  13990. +#define MMAL_ENCODING_VP7 MMAL_FOURCC('V', 'P', '7', ' ')
  13991. +#define MMAL_ENCODING_VP6 MMAL_FOURCC('V', 'P', '6', ' ')
  13992. +#define MMAL_ENCODING_THEORA MMAL_FOURCC('T', 'H', 'E', 'O')
  13993. +#define MMAL_ENCODING_SPARK MMAL_FOURCC('S', 'P', 'R', 'K')
  13994. +#define MMAL_ENCODING_MJPEG MMAL_FOURCC('M', 'J', 'P', 'G')
  13995. +
  13996. +#define MMAL_ENCODING_JPEG MMAL_FOURCC('J', 'P', 'E', 'G')
  13997. +#define MMAL_ENCODING_GIF MMAL_FOURCC('G', 'I', 'F', ' ')
  13998. +#define MMAL_ENCODING_PNG MMAL_FOURCC('P', 'N', 'G', ' ')
  13999. +#define MMAL_ENCODING_PPM MMAL_FOURCC('P', 'P', 'M', ' ')
  14000. +#define MMAL_ENCODING_TGA MMAL_FOURCC('T', 'G', 'A', ' ')
  14001. +#define MMAL_ENCODING_BMP MMAL_FOURCC('B', 'M', 'P', ' ')
  14002. +
  14003. +#define MMAL_ENCODING_I420 MMAL_FOURCC('I', '4', '2', '0')
  14004. +#define MMAL_ENCODING_I420_SLICE MMAL_FOURCC('S', '4', '2', '0')
  14005. +#define MMAL_ENCODING_YV12 MMAL_FOURCC('Y', 'V', '1', '2')
  14006. +#define MMAL_ENCODING_I422 MMAL_FOURCC('I', '4', '2', '2')
  14007. +#define MMAL_ENCODING_I422_SLICE MMAL_FOURCC('S', '4', '2', '2')
  14008. +#define MMAL_ENCODING_YUYV MMAL_FOURCC('Y', 'U', 'Y', 'V')
  14009. +#define MMAL_ENCODING_YVYU MMAL_FOURCC('Y', 'V', 'Y', 'U')
  14010. +#define MMAL_ENCODING_UYVY MMAL_FOURCC('U', 'Y', 'V', 'Y')
  14011. +#define MMAL_ENCODING_VYUY MMAL_FOURCC('V', 'Y', 'U', 'Y')
  14012. +#define MMAL_ENCODING_NV12 MMAL_FOURCC('N', 'V', '1', '2')
  14013. +#define MMAL_ENCODING_NV21 MMAL_FOURCC('N', 'V', '2', '1')
  14014. +#define MMAL_ENCODING_ARGB MMAL_FOURCC('A', 'R', 'G', 'B')
  14015. +#define MMAL_ENCODING_RGBA MMAL_FOURCC('R', 'G', 'B', 'A')
  14016. +#define MMAL_ENCODING_ABGR MMAL_FOURCC('A', 'B', 'G', 'R')
  14017. +#define MMAL_ENCODING_BGRA MMAL_FOURCC('B', 'G', 'R', 'A')
  14018. +#define MMAL_ENCODING_RGB16 MMAL_FOURCC('R', 'G', 'B', '2')
  14019. +#define MMAL_ENCODING_RGB24 MMAL_FOURCC('R', 'G', 'B', '3')
  14020. +#define MMAL_ENCODING_RGB32 MMAL_FOURCC('R', 'G', 'B', '4')
  14021. +#define MMAL_ENCODING_BGR16 MMAL_FOURCC('B', 'G', 'R', '2')
  14022. +#define MMAL_ENCODING_BGR24 MMAL_FOURCC('B', 'G', 'R', '3')
  14023. +#define MMAL_ENCODING_BGR32 MMAL_FOURCC('B', 'G', 'R', '4')
  14024. +
  14025. +/** SAND Video (YUVUV128) format, native format understood by VideoCore.
  14026. + * This format is *not* opaque - if requested you will receive full frames
  14027. + * of YUV_UV video.
  14028. + */
  14029. +#define MMAL_ENCODING_YUVUV128 MMAL_FOURCC('S', 'A', 'N', 'D')
  14030. +
  14031. +/** VideoCore opaque image format, image handles are returned to
  14032. + * the host but not the actual image data.
  14033. + */
  14034. +#define MMAL_ENCODING_OPAQUE MMAL_FOURCC('O', 'P', 'Q', 'V')
  14035. +
  14036. +/** An EGL image handle
  14037. + */
  14038. +#define MMAL_ENCODING_EGL_IMAGE MMAL_FOURCC('E', 'G', 'L', 'I')
  14039. +
  14040. +/* }@ */
  14041. +
  14042. +/** \name Pre-defined audio encodings */
  14043. +/* @{ */
  14044. +#define MMAL_ENCODING_PCM_UNSIGNED_BE MMAL_FOURCC('P', 'C', 'M', 'U')
  14045. +#define MMAL_ENCODING_PCM_UNSIGNED_LE MMAL_FOURCC('p', 'c', 'm', 'u')
  14046. +#define MMAL_ENCODING_PCM_SIGNED_BE MMAL_FOURCC('P', 'C', 'M', 'S')
  14047. +#define MMAL_ENCODING_PCM_SIGNED_LE MMAL_FOURCC('p', 'c', 'm', 's')
  14048. +#define MMAL_ENCODING_PCM_FLOAT_BE MMAL_FOURCC('P', 'C', 'M', 'F')
  14049. +#define MMAL_ENCODING_PCM_FLOAT_LE MMAL_FOURCC('p', 'c', 'm', 'f')
  14050. +
  14051. +/* Pre-defined H264 encoding variants */
  14052. +
  14053. +/** ISO 14496-10 Annex B byte stream format */
  14054. +#define MMAL_ENCODING_VARIANT_H264_DEFAULT 0
  14055. +/** ISO 14496-15 AVC stream format */
  14056. +#define MMAL_ENCODING_VARIANT_H264_AVC1 MMAL_FOURCC('A', 'V', 'C', '1')
  14057. +/** Implicitly delineated NAL units without emulation prevention */
  14058. +#define MMAL_ENCODING_VARIANT_H264_RAW MMAL_FOURCC('R', 'A', 'W', ' ')
  14059. diff -Nur linux-3.13.11/drivers/media/platform/bcm2835/mmal-msg-common.h linux-rpi/drivers/media/platform/bcm2835/mmal-msg-common.h
  14060. --- linux-3.13.11/drivers/media/platform/bcm2835/mmal-msg-common.h 1970-01-01 01:00:00.000000000 +0100
  14061. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-msg-common.h 2014-04-24 15:35:02.713549510 +0200
  14062. @@ -0,0 +1,50 @@
  14063. +/*
  14064. + * Broadcom BM2835 V4L2 driver
  14065. + *
  14066. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  14067. + *
  14068. + * This file is subject to the terms and conditions of the GNU General Public
  14069. + * License. See the file COPYING in the main directory of this archive
  14070. + * for more details.
  14071. + *
  14072. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  14073. + * Dave Stevenson <dsteve@broadcom.com>
  14074. + * Simon Mellor <simellor@broadcom.com>
  14075. + * Luke Diamand <luked@broadcom.com>
  14076. + */
  14077. +
  14078. +#ifndef MMAL_MSG_COMMON_H
  14079. +#define MMAL_MSG_COMMON_H
  14080. +
  14081. +enum mmal_msg_status {
  14082. + MMAL_MSG_STATUS_SUCCESS = 0, /**< Success */
  14083. + MMAL_MSG_STATUS_ENOMEM, /**< Out of memory */
  14084. + MMAL_MSG_STATUS_ENOSPC, /**< Out of resources other than memory */
  14085. + MMAL_MSG_STATUS_EINVAL, /**< Argument is invalid */
  14086. + MMAL_MSG_STATUS_ENOSYS, /**< Function not implemented */
  14087. + MMAL_MSG_STATUS_ENOENT, /**< No such file or directory */
  14088. + MMAL_MSG_STATUS_ENXIO, /**< No such device or address */
  14089. + MMAL_MSG_STATUS_EIO, /**< I/O error */
  14090. + MMAL_MSG_STATUS_ESPIPE, /**< Illegal seek */
  14091. + MMAL_MSG_STATUS_ECORRUPT, /**< Data is corrupt \attention */
  14092. + MMAL_MSG_STATUS_ENOTREADY, /**< Component is not ready */
  14093. + MMAL_MSG_STATUS_ECONFIG, /**< Component is not configured */
  14094. + MMAL_MSG_STATUS_EISCONN, /**< Port is already connected */
  14095. + MMAL_MSG_STATUS_ENOTCONN, /**< Port is disconnected */
  14096. + MMAL_MSG_STATUS_EAGAIN, /**< Resource temporarily unavailable. */
  14097. + MMAL_MSG_STATUS_EFAULT, /**< Bad address */
  14098. +};
  14099. +
  14100. +struct mmal_rect {
  14101. + s32 x; /**< x coordinate (from left) */
  14102. + s32 y; /**< y coordinate (from top) */
  14103. + s32 width; /**< width */
  14104. + s32 height; /**< height */
  14105. +};
  14106. +
  14107. +struct mmal_rational {
  14108. + s32 num; /**< Numerator */
  14109. + s32 den; /**< Denominator */
  14110. +};
  14111. +
  14112. +#endif /* MMAL_MSG_COMMON_H */
  14113. diff -Nur linux-3.13.11/drivers/media/platform/bcm2835/mmal-msg-format.h linux-rpi/drivers/media/platform/bcm2835/mmal-msg-format.h
  14114. --- linux-3.13.11/drivers/media/platform/bcm2835/mmal-msg-format.h 1970-01-01 01:00:00.000000000 +0100
  14115. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-msg-format.h 2014-04-24 15:35:02.713549510 +0200
  14116. @@ -0,0 +1,81 @@
  14117. +/*
  14118. + * Broadcom BM2835 V4L2 driver
  14119. + *
  14120. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  14121. + *
  14122. + * This file is subject to the terms and conditions of the GNU General Public
  14123. + * License. See the file COPYING in the main directory of this archive
  14124. + * for more details.
  14125. + *
  14126. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  14127. + * Dave Stevenson <dsteve@broadcom.com>
  14128. + * Simon Mellor <simellor@broadcom.com>
  14129. + * Luke Diamand <luked@broadcom.com>
  14130. + */
  14131. +
  14132. +#ifndef MMAL_MSG_FORMAT_H
  14133. +#define MMAL_MSG_FORMAT_H
  14134. +
  14135. +#include "mmal-msg-common.h"
  14136. +
  14137. +/* MMAL_ES_FORMAT_T */
  14138. +
  14139. +
  14140. +struct mmal_audio_format {
  14141. + u32 channels; /**< Number of audio channels */
  14142. + u32 sample_rate; /**< Sample rate */
  14143. +
  14144. + u32 bits_per_sample; /**< Bits per sample */
  14145. + u32 block_align; /**< Size of a block of data */
  14146. +};
  14147. +
  14148. +struct mmal_video_format {
  14149. + u32 width; /**< Width of frame in pixels */
  14150. + u32 height; /**< Height of frame in rows of pixels */
  14151. + struct mmal_rect crop; /**< Visible region of the frame */
  14152. + struct mmal_rational frame_rate; /**< Frame rate */
  14153. + struct mmal_rational par; /**< Pixel aspect ratio */
  14154. +
  14155. + /* FourCC specifying the color space of the video stream. See the
  14156. + * \ref MmalColorSpace "pre-defined color spaces" for some examples.
  14157. + */
  14158. + u32 color_space;
  14159. +};
  14160. +
  14161. +struct mmal_subpicture_format {
  14162. + u32 x_offset;
  14163. + u32 y_offset;
  14164. +};
  14165. +
  14166. +union mmal_es_specific_format {
  14167. + struct mmal_audio_format audio;
  14168. + struct mmal_video_format video;
  14169. + struct mmal_subpicture_format subpicture;
  14170. +};
  14171. +
  14172. +/** Definition of an elementary stream format (MMAL_ES_FORMAT_T) */
  14173. +struct mmal_es_format {
  14174. + u32 type; /* enum mmal_es_type */
  14175. +
  14176. + u32 encoding; /* FourCC specifying encoding of the elementary stream.*/
  14177. + u32 encoding_variant; /* FourCC specifying the specific
  14178. + * encoding variant of the elementary
  14179. + * stream.
  14180. + */
  14181. +
  14182. + union mmal_es_specific_format *es; /* TODO: pointers in
  14183. + * message serialisation?!?
  14184. + */
  14185. + /* Type specific
  14186. + * information for the
  14187. + * elementary stream
  14188. + */
  14189. +
  14190. + u32 bitrate; /**< Bitrate in bits per second */
  14191. + u32 flags; /**< Flags describing properties of the elementary stream. */
  14192. +
  14193. + u32 extradata_size; /**< Size of the codec specific data */
  14194. + u8 *extradata; /**< Codec specific data */
  14195. +};
  14196. +
  14197. +#endif /* MMAL_MSG_FORMAT_H */
  14198. diff -Nur linux-3.13.11/drivers/media/platform/bcm2835/mmal-msg.h linux-rpi/drivers/media/platform/bcm2835/mmal-msg.h
  14199. --- linux-3.13.11/drivers/media/platform/bcm2835/mmal-msg.h 1970-01-01 01:00:00.000000000 +0100
  14200. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-msg.h 2014-04-24 15:35:02.713549510 +0200
  14201. @@ -0,0 +1,404 @@
  14202. +/*
  14203. + * Broadcom BM2835 V4L2 driver
  14204. + *
  14205. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  14206. + *
  14207. + * This file is subject to the terms and conditions of the GNU General Public
  14208. + * License. See the file COPYING in the main directory of this archive
  14209. + * for more details.
  14210. + *
  14211. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  14212. + * Dave Stevenson <dsteve@broadcom.com>
  14213. + * Simon Mellor <simellor@broadcom.com>
  14214. + * Luke Diamand <luked@broadcom.com>
  14215. + */
  14216. +
  14217. +/* all the data structures which serialise the MMAL protocol. note
  14218. + * these are directly mapped onto the recived message data.
  14219. + *
  14220. + * BEWARE: They seem to *assume* pointers are u32 and that there is no
  14221. + * structure padding!
  14222. + *
  14223. + * NOTE: this implementation uses kernel types to ensure sizes. Rather
  14224. + * than assigning values to enums to force their size the
  14225. + * implementation uses fixed size types and not the enums (though the
  14226. + * comments have the actual enum type
  14227. + */
  14228. +
  14229. +#define VC_MMAL_VER 15
  14230. +#define VC_MMAL_MIN_VER 10
  14231. +#define VC_MMAL_SERVER_NAME MAKE_FOURCC("mmal")
  14232. +
  14233. +/* max total message size is 512 bytes */
  14234. +#define MMAL_MSG_MAX_SIZE 512
  14235. +/* with six 32bit header elements max payload is therefore 488 bytes */
  14236. +#define MMAL_MSG_MAX_PAYLOAD 488
  14237. +
  14238. +#include "mmal-msg-common.h"
  14239. +#include "mmal-msg-format.h"
  14240. +#include "mmal-msg-port.h"
  14241. +
  14242. +enum mmal_msg_type {
  14243. + MMAL_MSG_TYPE_QUIT = 1,
  14244. + MMAL_MSG_TYPE_SERVICE_CLOSED,
  14245. + MMAL_MSG_TYPE_GET_VERSION,
  14246. + MMAL_MSG_TYPE_COMPONENT_CREATE,
  14247. + MMAL_MSG_TYPE_COMPONENT_DESTROY, /* 5 */
  14248. + MMAL_MSG_TYPE_COMPONENT_ENABLE,
  14249. + MMAL_MSG_TYPE_COMPONENT_DISABLE,
  14250. + MMAL_MSG_TYPE_PORT_INFO_GET,
  14251. + MMAL_MSG_TYPE_PORT_INFO_SET,
  14252. + MMAL_MSG_TYPE_PORT_ACTION, /* 10 */
  14253. + MMAL_MSG_TYPE_BUFFER_FROM_HOST,
  14254. + MMAL_MSG_TYPE_BUFFER_TO_HOST,
  14255. + MMAL_MSG_TYPE_GET_STATS,
  14256. + MMAL_MSG_TYPE_PORT_PARAMETER_SET,
  14257. + MMAL_MSG_TYPE_PORT_PARAMETER_GET, /* 15 */
  14258. + MMAL_MSG_TYPE_EVENT_TO_HOST,
  14259. + MMAL_MSG_TYPE_GET_CORE_STATS_FOR_PORT,
  14260. + MMAL_MSG_TYPE_OPAQUE_ALLOCATOR,
  14261. + MMAL_MSG_TYPE_CONSUME_MEM,
  14262. + MMAL_MSG_TYPE_LMK, /* 20 */
  14263. + MMAL_MSG_TYPE_OPAQUE_ALLOCATOR_DESC,
  14264. + MMAL_MSG_TYPE_DRM_GET_LHS32,
  14265. + MMAL_MSG_TYPE_DRM_GET_TIME,
  14266. + MMAL_MSG_TYPE_BUFFER_FROM_HOST_ZEROLEN,
  14267. + MMAL_MSG_TYPE_PORT_FLUSH, /* 25 */
  14268. + MMAL_MSG_TYPE_HOST_LOG,
  14269. + MMAL_MSG_TYPE_MSG_LAST
  14270. +};
  14271. +
  14272. +/* port action request messages differ depending on the action type */
  14273. +enum mmal_msg_port_action_type {
  14274. + MMAL_MSG_PORT_ACTION_TYPE_UNKNOWN = 0, /* Unkown action */
  14275. + MMAL_MSG_PORT_ACTION_TYPE_ENABLE, /* Enable a port */
  14276. + MMAL_MSG_PORT_ACTION_TYPE_DISABLE, /* Disable a port */
  14277. + MMAL_MSG_PORT_ACTION_TYPE_FLUSH, /* Flush a port */
  14278. + MMAL_MSG_PORT_ACTION_TYPE_CONNECT, /* Connect ports */
  14279. + MMAL_MSG_PORT_ACTION_TYPE_DISCONNECT, /* Disconnect ports */
  14280. + MMAL_MSG_PORT_ACTION_TYPE_SET_REQUIREMENTS, /* Set buffer requirements*/
  14281. +};
  14282. +
  14283. +struct mmal_msg_header {
  14284. + u32 magic;
  14285. + u32 type; /** enum mmal_msg_type */
  14286. +
  14287. + /* Opaque handle to the control service */
  14288. + struct mmal_control_service *control_service;
  14289. +
  14290. + struct mmal_msg_context *context; /** a u32 per message context */
  14291. + u32 status; /** The status of the vchiq operation */
  14292. + u32 padding;
  14293. +};
  14294. +
  14295. +/* Send from VC to host to report version */
  14296. +struct mmal_msg_version {
  14297. + u32 flags;
  14298. + u32 major;
  14299. + u32 minor;
  14300. + u32 minimum;
  14301. +};
  14302. +
  14303. +/* request to VC to create component */
  14304. +struct mmal_msg_component_create {
  14305. + void *client_component; /* component context */
  14306. + char name[128];
  14307. + u32 pid; /* For debug */
  14308. +};
  14309. +
  14310. +/* reply from VC to component creation request */
  14311. +struct mmal_msg_component_create_reply {
  14312. + u32 status; /** enum mmal_msg_status - how does this differ to
  14313. + * the one in the header?
  14314. + */
  14315. + u32 component_handle; /* VideoCore handle for component */
  14316. + u32 input_num; /* Number of input ports */
  14317. + u32 output_num; /* Number of output ports */
  14318. + u32 clock_num; /* Number of clock ports */
  14319. +};
  14320. +
  14321. +/* request to VC to destroy a component */
  14322. +struct mmal_msg_component_destroy {
  14323. + u32 component_handle;
  14324. +};
  14325. +
  14326. +struct mmal_msg_component_destroy_reply {
  14327. + u32 status; /** The component destruction status */
  14328. +};
  14329. +
  14330. +
  14331. +/* request and reply to VC to enable a component */
  14332. +struct mmal_msg_component_enable {
  14333. + u32 component_handle;
  14334. +};
  14335. +
  14336. +struct mmal_msg_component_enable_reply {
  14337. + u32 status; /** The component enable status */
  14338. +};
  14339. +
  14340. +
  14341. +/* request and reply to VC to disable a component */
  14342. +struct mmal_msg_component_disable {
  14343. + u32 component_handle;
  14344. +};
  14345. +
  14346. +struct mmal_msg_component_disable_reply {
  14347. + u32 status; /** The component disable status */
  14348. +};
  14349. +
  14350. +/* request to VC to get port information */
  14351. +struct mmal_msg_port_info_get {
  14352. + u32 component_handle; /* component handle port is associated with */
  14353. + u32 port_type; /* enum mmal_msg_port_type */
  14354. + u32 index; /* port index to query */
  14355. +};
  14356. +
  14357. +/* reply from VC to get port info request */
  14358. +struct mmal_msg_port_info_get_reply {
  14359. + u32 status; /** enum mmal_msg_status */
  14360. + u32 component_handle; /* component handle port is associated with */
  14361. + u32 port_type; /* enum mmal_msg_port_type */
  14362. + u32 port_index; /* port indexed in query */
  14363. + s32 found; /* unused */
  14364. + u32 port_handle; /**< Handle to use for this port */
  14365. + struct mmal_port port;
  14366. + struct mmal_es_format format; /* elementry stream format */
  14367. + union mmal_es_specific_format es; /* es type specific data */
  14368. + u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE]; /* es extra data */
  14369. +};
  14370. +
  14371. +/* request to VC to set port information */
  14372. +struct mmal_msg_port_info_set {
  14373. + u32 component_handle;
  14374. + u32 port_type; /* enum mmal_msg_port_type */
  14375. + u32 port_index; /* port indexed in query */
  14376. + struct mmal_port port;
  14377. + struct mmal_es_format format;
  14378. + union mmal_es_specific_format es;
  14379. + u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE];
  14380. +};
  14381. +
  14382. +/* reply from VC to port info set request */
  14383. +struct mmal_msg_port_info_set_reply {
  14384. + u32 status;
  14385. + u32 component_handle; /* component handle port is associated with */
  14386. + u32 port_type; /* enum mmal_msg_port_type */
  14387. + u32 index; /* port indexed in query */
  14388. + s32 found; /* unused */
  14389. + u32 port_handle; /**< Handle to use for this port */
  14390. + struct mmal_port port;
  14391. + struct mmal_es_format format;
  14392. + union mmal_es_specific_format es;
  14393. + u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE];
  14394. +};
  14395. +
  14396. +
  14397. +/* port action requests that take a mmal_port as a parameter */
  14398. +struct mmal_msg_port_action_port {
  14399. + u32 component_handle;
  14400. + u32 port_handle;
  14401. + u32 action; /* enum mmal_msg_port_action_type */
  14402. + struct mmal_port port;
  14403. +};
  14404. +
  14405. +/* port action requests that take handles as a parameter */
  14406. +struct mmal_msg_port_action_handle {
  14407. + u32 component_handle;
  14408. + u32 port_handle;
  14409. + u32 action; /* enum mmal_msg_port_action_type */
  14410. + u32 connect_component_handle;
  14411. + u32 connect_port_handle;
  14412. +};
  14413. +
  14414. +struct mmal_msg_port_action_reply {
  14415. + u32 status; /** The port action operation status */
  14416. +};
  14417. +
  14418. +
  14419. +
  14420. +
  14421. +/* MMAL buffer transfer */
  14422. +
  14423. +/** Size of space reserved in a buffer message for short messages. */
  14424. +#define MMAL_VC_SHORT_DATA 128
  14425. +
  14426. +/** Signals that the current payload is the end of the stream of data */
  14427. +#define MMAL_BUFFER_HEADER_FLAG_EOS (1<<0)
  14428. +/** Signals that the start of the current payload starts a frame */
  14429. +#define MMAL_BUFFER_HEADER_FLAG_FRAME_START (1<<1)
  14430. +/** Signals that the end of the current payload ends a frame */
  14431. +#define MMAL_BUFFER_HEADER_FLAG_FRAME_END (1<<2)
  14432. +/** Signals that the current payload contains only complete frames (>1) */
  14433. +#define MMAL_BUFFER_HEADER_FLAG_FRAME \
  14434. + (MMAL_BUFFER_HEADER_FLAG_FRAME_START|MMAL_BUFFER_HEADER_FLAG_FRAME_END)
  14435. +/** Signals that the current payload is a keyframe (i.e. self decodable) */
  14436. +#define MMAL_BUFFER_HEADER_FLAG_KEYFRAME (1<<3)
  14437. +/** Signals a discontinuity in the stream of data (e.g. after a seek).
  14438. + * Can be used for instance by a decoder to reset its state */
  14439. +#define MMAL_BUFFER_HEADER_FLAG_DISCONTINUITY (1<<4)
  14440. +/** Signals a buffer containing some kind of config data for the component
  14441. + * (e.g. codec config data) */
  14442. +#define MMAL_BUFFER_HEADER_FLAG_CONFIG (1<<5)
  14443. +/** Signals an encrypted payload */
  14444. +#define MMAL_BUFFER_HEADER_FLAG_ENCRYPTED (1<<6)
  14445. +/** Signals a buffer containing side information */
  14446. +#define MMAL_BUFFER_HEADER_FLAG_CODECSIDEINFO (1<<7)
  14447. +/** Signals a buffer which is the snapshot/postview image from a stills
  14448. + * capture
  14449. + */
  14450. +#define MMAL_BUFFER_HEADER_FLAGS_SNAPSHOT (1<<8)
  14451. +/** Signals a buffer which contains data known to be corrupted */
  14452. +#define MMAL_BUFFER_HEADER_FLAG_CORRUPTED (1<<9)
  14453. +/** Signals that a buffer failed to be transmitted */
  14454. +#define MMAL_BUFFER_HEADER_FLAG_TRANSMISSION_FAILED (1<<10)
  14455. +
  14456. +struct mmal_driver_buffer {
  14457. + u32 magic;
  14458. + u32 component_handle;
  14459. + u32 port_handle;
  14460. + void *client_context;
  14461. +};
  14462. +
  14463. +/* buffer header */
  14464. +struct mmal_buffer_header {
  14465. + struct mmal_buffer_header *next; /* next header */
  14466. + void *priv; /* framework private data */
  14467. + u32 cmd;
  14468. + void *data;
  14469. + u32 alloc_size;
  14470. + u32 length;
  14471. + u32 offset;
  14472. + u32 flags;
  14473. + s64 pts;
  14474. + s64 dts;
  14475. + void *type;
  14476. + void *user_data;
  14477. +};
  14478. +
  14479. +struct mmal_buffer_header_type_specific {
  14480. + union {
  14481. + struct {
  14482. + u32 planes;
  14483. + u32 offset[4];
  14484. + u32 pitch[4];
  14485. + u32 flags;
  14486. + } video;
  14487. + } u;
  14488. +};
  14489. +
  14490. +struct mmal_msg_buffer_from_host {
  14491. + /* The front 32 bytes of the buffer header are copied
  14492. + * back to us in the reply to allow for context. This
  14493. + * area is used to store two mmal_driver_buffer structures to
  14494. + * allow for multiple concurrent service users.
  14495. + */
  14496. + /* control data */
  14497. + struct mmal_driver_buffer drvbuf;
  14498. +
  14499. + /* referenced control data for passthrough buffer management */
  14500. + struct mmal_driver_buffer drvbuf_ref;
  14501. + struct mmal_buffer_header buffer_header; /* buffer header itself */
  14502. + struct mmal_buffer_header_type_specific buffer_header_type_specific;
  14503. + s32 is_zero_copy;
  14504. + s32 has_reference;
  14505. +
  14506. + /** allows short data to be xfered in control message */
  14507. + u32 payload_in_message;
  14508. + u8 short_data[MMAL_VC_SHORT_DATA];
  14509. +};
  14510. +
  14511. +
  14512. +/* port parameter setting */
  14513. +
  14514. +#define MMAL_WORKER_PORT_PARAMETER_SPACE 96
  14515. +
  14516. +struct mmal_msg_port_parameter_set {
  14517. + u32 component_handle; /* component */
  14518. + u32 port_handle; /* port */
  14519. + u32 id; /* Parameter ID */
  14520. + u32 size; /* Parameter size */
  14521. + uint32_t value[MMAL_WORKER_PORT_PARAMETER_SPACE];
  14522. +};
  14523. +
  14524. +struct mmal_msg_port_parameter_set_reply {
  14525. + u32 status; /** enum mmal_msg_status todo: how does this
  14526. + * differ to the one in the header?
  14527. + */
  14528. +};
  14529. +
  14530. +/* port parameter getting */
  14531. +
  14532. +struct mmal_msg_port_parameter_get {
  14533. + u32 component_handle; /* component */
  14534. + u32 port_handle; /* port */
  14535. + u32 id; /* Parameter ID */
  14536. + u32 size; /* Parameter size */
  14537. +};
  14538. +
  14539. +struct mmal_msg_port_parameter_get_reply {
  14540. + u32 status; /* Status of mmal_port_parameter_get call */
  14541. + u32 id; /* Parameter ID */
  14542. + u32 size; /* Parameter size */
  14543. + uint32_t value[MMAL_WORKER_PORT_PARAMETER_SPACE];
  14544. +};
  14545. +
  14546. +/* event messages */
  14547. +#define MMAL_WORKER_EVENT_SPACE 256
  14548. +
  14549. +struct mmal_msg_event_to_host {
  14550. + void *client_component; /* component context */
  14551. +
  14552. + u32 port_type;
  14553. + u32 port_num;
  14554. +
  14555. + u32 cmd;
  14556. + u32 length;
  14557. + u8 data[MMAL_WORKER_EVENT_SPACE];
  14558. + struct mmal_buffer_header *delayed_buffer;
  14559. +};
  14560. +
  14561. +/* all mmal messages are serialised through this structure */
  14562. +struct mmal_msg {
  14563. + /* header */
  14564. + struct mmal_msg_header h;
  14565. + /* payload */
  14566. + union {
  14567. + struct mmal_msg_version version;
  14568. +
  14569. + struct mmal_msg_component_create component_create;
  14570. + struct mmal_msg_component_create_reply component_create_reply;
  14571. +
  14572. + struct mmal_msg_component_destroy component_destroy;
  14573. + struct mmal_msg_component_destroy_reply component_destroy_reply;
  14574. +
  14575. + struct mmal_msg_component_enable component_enable;
  14576. + struct mmal_msg_component_enable_reply component_enable_reply;
  14577. +
  14578. + struct mmal_msg_component_disable component_disable;
  14579. + struct mmal_msg_component_disable_reply component_disable_reply;
  14580. +
  14581. + struct mmal_msg_port_info_get port_info_get;
  14582. + struct mmal_msg_port_info_get_reply port_info_get_reply;
  14583. +
  14584. + struct mmal_msg_port_info_set port_info_set;
  14585. + struct mmal_msg_port_info_set_reply port_info_set_reply;
  14586. +
  14587. + struct mmal_msg_port_action_port port_action_port;
  14588. + struct mmal_msg_port_action_handle port_action_handle;
  14589. + struct mmal_msg_port_action_reply port_action_reply;
  14590. +
  14591. + struct mmal_msg_buffer_from_host buffer_from_host;
  14592. +
  14593. + struct mmal_msg_port_parameter_set port_parameter_set;
  14594. + struct mmal_msg_port_parameter_set_reply
  14595. + port_parameter_set_reply;
  14596. + struct mmal_msg_port_parameter_get
  14597. + port_parameter_get;
  14598. + struct mmal_msg_port_parameter_get_reply
  14599. + port_parameter_get_reply;
  14600. +
  14601. + struct mmal_msg_event_to_host event_to_host;
  14602. +
  14603. + u8 payload[MMAL_MSG_MAX_PAYLOAD];
  14604. + } u;
  14605. +};
  14606. diff -Nur linux-3.13.11/drivers/media/platform/bcm2835/mmal-msg-port.h linux-rpi/drivers/media/platform/bcm2835/mmal-msg-port.h
  14607. --- linux-3.13.11/drivers/media/platform/bcm2835/mmal-msg-port.h 1970-01-01 01:00:00.000000000 +0100
  14608. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-msg-port.h 2014-04-24 15:35:02.713549510 +0200
  14609. @@ -0,0 +1,107 @@
  14610. +/*
  14611. + * Broadcom BM2835 V4L2 driver
  14612. + *
  14613. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  14614. + *
  14615. + * This file is subject to the terms and conditions of the GNU General Public
  14616. + * License. See the file COPYING in the main directory of this archive
  14617. + * for more details.
  14618. + *
  14619. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  14620. + * Dave Stevenson <dsteve@broadcom.com>
  14621. + * Simon Mellor <simellor@broadcom.com>
  14622. + * Luke Diamand <luked@broadcom.com>
  14623. + */
  14624. +
  14625. +/* MMAL_PORT_TYPE_T */
  14626. +enum mmal_port_type {
  14627. + MMAL_PORT_TYPE_UNKNOWN = 0, /**< Unknown port type */
  14628. + MMAL_PORT_TYPE_CONTROL, /**< Control port */
  14629. + MMAL_PORT_TYPE_INPUT, /**< Input port */
  14630. + MMAL_PORT_TYPE_OUTPUT, /**< Output port */
  14631. + MMAL_PORT_TYPE_CLOCK, /**< Clock port */
  14632. +};
  14633. +
  14634. +/** The port is pass-through and doesn't need buffer headers allocated */
  14635. +#define MMAL_PORT_CAPABILITY_PASSTHROUGH 0x01
  14636. +/** The port wants to allocate the buffer payloads.
  14637. + * This signals a preference that payload allocation should be done
  14638. + * on this port for efficiency reasons. */
  14639. +#define MMAL_PORT_CAPABILITY_ALLOCATION 0x02
  14640. +/** The port supports format change events.
  14641. + * This applies to input ports and is used to let the client know
  14642. + * whether the port supports being reconfigured via a format
  14643. + * change event (i.e. without having to disable the port). */
  14644. +#define MMAL_PORT_CAPABILITY_SUPPORTS_EVENT_FORMAT_CHANGE 0x04
  14645. +
  14646. +/* mmal port structure (MMAL_PORT_T)
  14647. + *
  14648. + * most elements are informational only, the pointer values for
  14649. + * interogation messages are generally provided as additional
  14650. + * strucures within the message. When used to set values only teh
  14651. + * buffer_num, buffer_size and userdata parameters are writable.
  14652. + */
  14653. +struct mmal_port {
  14654. + void *priv; /* Private member used by the framework */
  14655. + const char *name; /* Port name. Used for debugging purposes (RO) */
  14656. +
  14657. + u32 type; /* Type of the port (RO) enum mmal_port_type */
  14658. + u16 index; /* Index of the port in its type list (RO) */
  14659. + u16 index_all; /* Index of the port in the list of all ports (RO) */
  14660. +
  14661. + u32 is_enabled; /* Indicates whether the port is enabled or not (RO) */
  14662. + struct mmal_es_format *format; /* Format of the elementary stream */
  14663. +
  14664. + u32 buffer_num_min; /* Minimum number of buffers the port
  14665. + * requires (RO). This is set by the
  14666. + * component.
  14667. + */
  14668. +
  14669. + u32 buffer_size_min; /* Minimum size of buffers the port
  14670. + * requires (RO). This is set by the
  14671. + * component.
  14672. + */
  14673. +
  14674. + u32 buffer_alignment_min; /* Minimum alignment requirement for
  14675. + * the buffers (RO). A value of
  14676. + * zero means no special alignment
  14677. + * requirements. This is set by the
  14678. + * component.
  14679. + */
  14680. +
  14681. + u32 buffer_num_recommended; /* Number of buffers the port
  14682. + * recommends for optimal
  14683. + * performance (RO). A value of
  14684. + * zero means no special
  14685. + * recommendation. This is set
  14686. + * by the component.
  14687. + */
  14688. +
  14689. + u32 buffer_size_recommended; /* Size of buffers the port
  14690. + * recommends for optimal
  14691. + * performance (RO). A value of
  14692. + * zero means no special
  14693. + * recommendation. This is set
  14694. + * by the component.
  14695. + */
  14696. +
  14697. + u32 buffer_num; /* Actual number of buffers the port will use.
  14698. + * This is set by the client.
  14699. + */
  14700. +
  14701. + u32 buffer_size; /* Actual maximum size of the buffers that
  14702. + * will be sent to the port. This is set by
  14703. + * the client.
  14704. + */
  14705. +
  14706. + void *component; /* Component this port belongs to (Read Only) */
  14707. +
  14708. + void *userdata; /* Field reserved for use by the client */
  14709. +
  14710. + u32 capabilities; /* Flags describing the capabilities of a
  14711. + * port (RO). Bitwise combination of \ref
  14712. + * portcapabilities "Port capabilities"
  14713. + * values.
  14714. + */
  14715. +
  14716. +};
  14717. diff -Nur linux-3.13.11/drivers/media/platform/bcm2835/mmal-parameters.h linux-rpi/drivers/media/platform/bcm2835/mmal-parameters.h
  14718. --- linux-3.13.11/drivers/media/platform/bcm2835/mmal-parameters.h 1970-01-01 01:00:00.000000000 +0100
  14719. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-parameters.h 2014-04-24 15:35:02.713549510 +0200
  14720. @@ -0,0 +1,655 @@
  14721. +/*
  14722. + * Broadcom BM2835 V4L2 driver
  14723. + *
  14724. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  14725. + *
  14726. + * This file is subject to the terms and conditions of the GNU General Public
  14727. + * License. See the file COPYING in the main directory of this archive
  14728. + * for more details.
  14729. + *
  14730. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  14731. + * Dave Stevenson <dsteve@broadcom.com>
  14732. + * Simon Mellor <simellor@broadcom.com>
  14733. + * Luke Diamand <luked@broadcom.com>
  14734. + */
  14735. +
  14736. +/* common parameters */
  14737. +
  14738. +/** @name Parameter groups
  14739. + * Parameters are divided into groups, and then allocated sequentially within
  14740. + * a group using an enum.
  14741. + * @{
  14742. + */
  14743. +
  14744. +/** Common parameter ID group, used with many types of component. */
  14745. +#define MMAL_PARAMETER_GROUP_COMMON (0<<16)
  14746. +/** Camera-specific parameter ID group. */
  14747. +#define MMAL_PARAMETER_GROUP_CAMERA (1<<16)
  14748. +/** Video-specific parameter ID group. */
  14749. +#define MMAL_PARAMETER_GROUP_VIDEO (2<<16)
  14750. +/** Audio-specific parameter ID group. */
  14751. +#define MMAL_PARAMETER_GROUP_AUDIO (3<<16)
  14752. +/** Clock-specific parameter ID group. */
  14753. +#define MMAL_PARAMETER_GROUP_CLOCK (4<<16)
  14754. +/** Miracast-specific parameter ID group. */
  14755. +#define MMAL_PARAMETER_GROUP_MIRACAST (5<<16)
  14756. +
  14757. +/* Common parameters */
  14758. +enum mmal_parameter_common_type {
  14759. + MMAL_PARAMETER_UNUSED /**< Never a valid parameter ID */
  14760. + = MMAL_PARAMETER_GROUP_COMMON,
  14761. + MMAL_PARAMETER_SUPPORTED_ENCODINGS, /**< MMAL_PARAMETER_ENCODING_T */
  14762. + MMAL_PARAMETER_URI, /**< MMAL_PARAMETER_URI_T */
  14763. +
  14764. + /** MMAL_PARAMETER_CHANGE_EVENT_REQUEST_T */
  14765. + MMAL_PARAMETER_CHANGE_EVENT_REQUEST,
  14766. +
  14767. + /** MMAL_PARAMETER_BOOLEAN_T */
  14768. + MMAL_PARAMETER_ZERO_COPY,
  14769. +
  14770. + /**< MMAL_PARAMETER_BUFFER_REQUIREMENTS_T */
  14771. + MMAL_PARAMETER_BUFFER_REQUIREMENTS,
  14772. +
  14773. + MMAL_PARAMETER_STATISTICS, /**< MMAL_PARAMETER_STATISTICS_T */
  14774. + MMAL_PARAMETER_CORE_STATISTICS, /**< MMAL_PARAMETER_CORE_STATISTICS_T */
  14775. + MMAL_PARAMETER_MEM_USAGE, /**< MMAL_PARAMETER_MEM_USAGE_T */
  14776. + MMAL_PARAMETER_BUFFER_FLAG_FILTER, /**< MMAL_PARAMETER_UINT32_T */
  14777. + MMAL_PARAMETER_SEEK, /**< MMAL_PARAMETER_SEEK_T */
  14778. + MMAL_PARAMETER_POWERMON_ENABLE, /**< MMAL_PARAMETER_BOOLEAN_T */
  14779. + MMAL_PARAMETER_LOGGING, /**< MMAL_PARAMETER_LOGGING_T */
  14780. + MMAL_PARAMETER_SYSTEM_TIME /**< MMAL_PARAMETER_UINT64_T */
  14781. +};
  14782. +
  14783. +/* camera parameters */
  14784. +
  14785. +enum mmal_parameter_camera_type {
  14786. + /* 0 */
  14787. + /** @ref MMAL_PARAMETER_THUMBNAIL_CONFIG_T */
  14788. + MMAL_PARAMETER_THUMBNAIL_CONFIGURATION
  14789. + = MMAL_PARAMETER_GROUP_CAMERA,
  14790. + MMAL_PARAMETER_CAPTURE_QUALITY, /**< Unused? */
  14791. + MMAL_PARAMETER_ROTATION, /**< @ref MMAL_PARAMETER_INT32_T */
  14792. + MMAL_PARAMETER_EXIF_DISABLE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  14793. + MMAL_PARAMETER_EXIF, /**< @ref MMAL_PARAMETER_EXIF_T */
  14794. + MMAL_PARAMETER_AWB_MODE, /**< @ref MMAL_PARAM_AWBMODE_T */
  14795. + MMAL_PARAMETER_IMAGE_EFFECT, /**< @ref MMAL_PARAMETER_IMAGEFX_T */
  14796. + MMAL_PARAMETER_COLOUR_EFFECT, /**< @ref MMAL_PARAMETER_COLOURFX_T */
  14797. + MMAL_PARAMETER_FLICKER_AVOID, /**< @ref MMAL_PARAMETER_FLICKERAVOID_T */
  14798. + MMAL_PARAMETER_FLASH, /**< @ref MMAL_PARAMETER_FLASH_T */
  14799. + MMAL_PARAMETER_REDEYE, /**< @ref MMAL_PARAMETER_REDEYE_T */
  14800. + MMAL_PARAMETER_FOCUS, /**< @ref MMAL_PARAMETER_FOCUS_T */
  14801. + MMAL_PARAMETER_FOCAL_LENGTHS, /**< Unused? */
  14802. + MMAL_PARAMETER_EXPOSURE_COMP, /**< @ref MMAL_PARAMETER_INT32_T */
  14803. + MMAL_PARAMETER_ZOOM, /**< @ref MMAL_PARAMETER_SCALEFACTOR_T */
  14804. + MMAL_PARAMETER_MIRROR, /**< @ref MMAL_PARAMETER_MIRROR_T */
  14805. +
  14806. + /* 0x10 */
  14807. + MMAL_PARAMETER_CAMERA_NUM, /**< @ref MMAL_PARAMETER_UINT32_T */
  14808. + MMAL_PARAMETER_CAPTURE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  14809. + MMAL_PARAMETER_EXPOSURE_MODE, /**< @ref MMAL_PARAMETER_EXPOSUREMODE_T */
  14810. + MMAL_PARAMETER_EXP_METERING_MODE, /**< @ref MMAL_PARAMETER_EXPOSUREMETERINGMODE_T */
  14811. + MMAL_PARAMETER_FOCUS_STATUS, /**< @ref MMAL_PARAMETER_FOCUS_STATUS_T */
  14812. + MMAL_PARAMETER_CAMERA_CONFIG, /**< @ref MMAL_PARAMETER_CAMERA_CONFIG_T */
  14813. + MMAL_PARAMETER_CAPTURE_STATUS, /**< @ref MMAL_PARAMETER_CAPTURE_STATUS_T */
  14814. + MMAL_PARAMETER_FACE_TRACK, /**< @ref MMAL_PARAMETER_FACE_TRACK_T */
  14815. + MMAL_PARAMETER_DRAW_BOX_FACES_AND_FOCUS, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  14816. + MMAL_PARAMETER_JPEG_Q_FACTOR, /**< @ref MMAL_PARAMETER_UINT32_T */
  14817. + MMAL_PARAMETER_FRAME_RATE, /**< @ref MMAL_PARAMETER_FRAME_RATE_T */
  14818. + MMAL_PARAMETER_USE_STC, /**< @ref MMAL_PARAMETER_CAMERA_STC_MODE_T */
  14819. + MMAL_PARAMETER_CAMERA_INFO, /**< @ref MMAL_PARAMETER_CAMERA_INFO_T */
  14820. + MMAL_PARAMETER_VIDEO_STABILISATION, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  14821. + MMAL_PARAMETER_FACE_TRACK_RESULTS, /**< @ref MMAL_PARAMETER_FACE_TRACK_RESULTS_T */
  14822. + MMAL_PARAMETER_ENABLE_RAW_CAPTURE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  14823. +
  14824. + /* 0x20 */
  14825. + MMAL_PARAMETER_DPF_FILE, /**< @ref MMAL_PARAMETER_URI_T */
  14826. + MMAL_PARAMETER_ENABLE_DPF_FILE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  14827. + MMAL_PARAMETER_DPF_FAIL_IS_FATAL, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  14828. + MMAL_PARAMETER_CAPTURE_MODE, /**< @ref MMAL_PARAMETER_CAPTUREMODE_T */
  14829. + MMAL_PARAMETER_FOCUS_REGIONS, /**< @ref MMAL_PARAMETER_FOCUS_REGIONS_T */
  14830. + MMAL_PARAMETER_INPUT_CROP, /**< @ref MMAL_PARAMETER_INPUT_CROP_T */
  14831. + MMAL_PARAMETER_SENSOR_INFORMATION, /**< @ref MMAL_PARAMETER_SENSOR_INFORMATION_T */
  14832. + MMAL_PARAMETER_FLASH_SELECT, /**< @ref MMAL_PARAMETER_FLASH_SELECT_T */
  14833. + MMAL_PARAMETER_FIELD_OF_VIEW, /**< @ref MMAL_PARAMETER_FIELD_OF_VIEW_T */
  14834. + MMAL_PARAMETER_HIGH_DYNAMIC_RANGE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  14835. + MMAL_PARAMETER_DYNAMIC_RANGE_COMPRESSION, /**< @ref MMAL_PARAMETER_DRC_T */
  14836. + MMAL_PARAMETER_ALGORITHM_CONTROL, /**< @ref MMAL_PARAMETER_ALGORITHM_CONTROL_T */
  14837. + MMAL_PARAMETER_SHARPNESS, /**< @ref MMAL_PARAMETER_RATIONAL_T */
  14838. + MMAL_PARAMETER_CONTRAST, /**< @ref MMAL_PARAMETER_RATIONAL_T */
  14839. + MMAL_PARAMETER_BRIGHTNESS, /**< @ref MMAL_PARAMETER_RATIONAL_T */
  14840. + MMAL_PARAMETER_SATURATION, /**< @ref MMAL_PARAMETER_RATIONAL_T */
  14841. +
  14842. + /* 0x30 */
  14843. + MMAL_PARAMETER_ISO, /**< @ref MMAL_PARAMETER_UINT32_T */
  14844. + MMAL_PARAMETER_ANTISHAKE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  14845. +
  14846. + /** @ref MMAL_PARAMETER_IMAGEFX_PARAMETERS_T */
  14847. + MMAL_PARAMETER_IMAGE_EFFECT_PARAMETERS,
  14848. +
  14849. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  14850. + MMAL_PARAMETER_CAMERA_BURST_CAPTURE,
  14851. +
  14852. + /** @ref MMAL_PARAMETER_UINT32_T */
  14853. + MMAL_PARAMETER_CAMERA_MIN_ISO,
  14854. +
  14855. + /** @ref MMAL_PARAMETER_CAMERA_USE_CASE_T */
  14856. + MMAL_PARAMETER_CAMERA_USE_CASE,
  14857. +
  14858. + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  14859. + MMAL_PARAMETER_CAPTURE_STATS_PASS,
  14860. +
  14861. + /** @ref MMAL_PARAMETER_UINT32_T */
  14862. + MMAL_PARAMETER_CAMERA_CUSTOM_SENSOR_CONFIG,
  14863. +
  14864. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  14865. + MMAL_PARAMETER_ENABLE_REGISTER_FILE,
  14866. +
  14867. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  14868. + MMAL_PARAMETER_REGISTER_FAIL_IS_FATAL,
  14869. +
  14870. + /** @ref MMAL_PARAMETER_CONFIGFILE_T */
  14871. + MMAL_PARAMETER_CONFIGFILE_REGISTERS,
  14872. +
  14873. + /** @ref MMAL_PARAMETER_CONFIGFILE_CHUNK_T */
  14874. + MMAL_PARAMETER_CONFIGFILE_CHUNK_REGISTERS,
  14875. + MMAL_PARAMETER_JPEG_ATTACH_LOG, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  14876. + MMAL_PARAMETER_ZERO_SHUTTER_LAG, /**< @ref MMAL_PARAMETER_ZEROSHUTTERLAG_T */
  14877. + MMAL_PARAMETER_FPS_RANGE, /**< @ref MMAL_PARAMETER_FPS_RANGE_T */
  14878. + MMAL_PARAMETER_CAPTURE_EXPOSURE_COMP, /**< @ref MMAL_PARAMETER_INT32_T */
  14879. +
  14880. + /* 0x40 */
  14881. + MMAL_PARAMETER_SW_SHARPEN_DISABLE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  14882. + MMAL_PARAMETER_FLASH_REQUIRED, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  14883. + MMAL_PARAMETER_SW_SATURATION_DISABLE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  14884. + MMAL_PARAMETER_SHUTTER_SPEED, /**< Takes a @ref MMAL_PARAMETER_UINT32_T */
  14885. + MMAL_PARAMETER_CUSTOM_AWB_GAINS, /**< Takes a @ref MMAL_PARAMETER_AWB_GAINS_T */
  14886. +};
  14887. +
  14888. +struct mmal_parameter_rational {
  14889. + s32 num; /**< Numerator */
  14890. + s32 den; /**< Denominator */
  14891. +};
  14892. +
  14893. +enum mmal_parameter_camera_config_timestamp_mode {
  14894. + MMAL_PARAM_TIMESTAMP_MODE_ZERO = 0, /* Always timestamp frames as 0 */
  14895. + MMAL_PARAM_TIMESTAMP_MODE_RAW_STC, /* Use the raw STC value
  14896. + * for the frame timestamp
  14897. + */
  14898. + MMAL_PARAM_TIMESTAMP_MODE_RESET_STC, /* Use the STC timestamp
  14899. + * but subtract the
  14900. + * timestamp of the first
  14901. + * frame sent to give a
  14902. + * zero based timestamp.
  14903. + */
  14904. +};
  14905. +
  14906. +struct mmal_parameter_fps_range {
  14907. + /**< Low end of the permitted framerate range */
  14908. + struct mmal_parameter_rational fps_low;
  14909. + /**< High end of the permitted framerate range */
  14910. + struct mmal_parameter_rational fps_high;
  14911. +};
  14912. +
  14913. +
  14914. +/* camera configuration parameter */
  14915. +struct mmal_parameter_camera_config {
  14916. + /* Parameters for setting up the image pools */
  14917. + u32 max_stills_w; /* Max size of stills capture */
  14918. + u32 max_stills_h;
  14919. + u32 stills_yuv422; /* Allow YUV422 stills capture */
  14920. + u32 one_shot_stills; /* Continuous or one shot stills captures. */
  14921. +
  14922. + u32 max_preview_video_w; /* Max size of the preview or video
  14923. + * capture frames
  14924. + */
  14925. + u32 max_preview_video_h;
  14926. + u32 num_preview_video_frames;
  14927. +
  14928. + /** Sets the height of the circular buffer for stills capture. */
  14929. + u32 stills_capture_circular_buffer_height;
  14930. +
  14931. + /** Allows preview/encode to resume as fast as possible after the stills
  14932. + * input frame has been received, and then processes the still frame in
  14933. + * the background whilst preview/encode has resumed.
  14934. + * Actual mode is controlled by MMAL_PARAMETER_CAPTURE_MODE.
  14935. + */
  14936. + u32 fast_preview_resume;
  14937. +
  14938. + /** Selects algorithm for timestamping frames if
  14939. + * there is no clock component connected.
  14940. + * enum mmal_parameter_camera_config_timestamp_mode
  14941. + */
  14942. + s32 use_stc_timestamp;
  14943. +};
  14944. +
  14945. +
  14946. +enum mmal_parameter_exposuremode {
  14947. + MMAL_PARAM_EXPOSUREMODE_OFF,
  14948. + MMAL_PARAM_EXPOSUREMODE_AUTO,
  14949. + MMAL_PARAM_EXPOSUREMODE_NIGHT,
  14950. + MMAL_PARAM_EXPOSUREMODE_NIGHTPREVIEW,
  14951. + MMAL_PARAM_EXPOSUREMODE_BACKLIGHT,
  14952. + MMAL_PARAM_EXPOSUREMODE_SPOTLIGHT,
  14953. + MMAL_PARAM_EXPOSUREMODE_SPORTS,
  14954. + MMAL_PARAM_EXPOSUREMODE_SNOW,
  14955. + MMAL_PARAM_EXPOSUREMODE_BEACH,
  14956. + MMAL_PARAM_EXPOSUREMODE_VERYLONG,
  14957. + MMAL_PARAM_EXPOSUREMODE_FIXEDFPS,
  14958. + MMAL_PARAM_EXPOSUREMODE_ANTISHAKE,
  14959. + MMAL_PARAM_EXPOSUREMODE_FIREWORKS,
  14960. +};
  14961. +
  14962. +enum mmal_parameter_exposuremeteringmode {
  14963. + MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE,
  14964. + MMAL_PARAM_EXPOSUREMETERINGMODE_SPOT,
  14965. + MMAL_PARAM_EXPOSUREMETERINGMODE_BACKLIT,
  14966. + MMAL_PARAM_EXPOSUREMETERINGMODE_MATRIX,
  14967. +};
  14968. +
  14969. +enum mmal_parameter_awbmode {
  14970. + MMAL_PARAM_AWBMODE_OFF,
  14971. + MMAL_PARAM_AWBMODE_AUTO,
  14972. + MMAL_PARAM_AWBMODE_SUNLIGHT,
  14973. + MMAL_PARAM_AWBMODE_CLOUDY,
  14974. + MMAL_PARAM_AWBMODE_SHADE,
  14975. + MMAL_PARAM_AWBMODE_TUNGSTEN,
  14976. + MMAL_PARAM_AWBMODE_FLUORESCENT,
  14977. + MMAL_PARAM_AWBMODE_INCANDESCENT,
  14978. + MMAL_PARAM_AWBMODE_FLASH,
  14979. + MMAL_PARAM_AWBMODE_HORIZON,
  14980. +};
  14981. +
  14982. +enum mmal_parameter_imagefx {
  14983. + MMAL_PARAM_IMAGEFX_NONE,
  14984. + MMAL_PARAM_IMAGEFX_NEGATIVE,
  14985. + MMAL_PARAM_IMAGEFX_SOLARIZE,
  14986. + MMAL_PARAM_IMAGEFX_POSTERIZE,
  14987. + MMAL_PARAM_IMAGEFX_WHITEBOARD,
  14988. + MMAL_PARAM_IMAGEFX_BLACKBOARD,
  14989. + MMAL_PARAM_IMAGEFX_SKETCH,
  14990. + MMAL_PARAM_IMAGEFX_DENOISE,
  14991. + MMAL_PARAM_IMAGEFX_EMBOSS,
  14992. + MMAL_PARAM_IMAGEFX_OILPAINT,
  14993. + MMAL_PARAM_IMAGEFX_HATCH,
  14994. + MMAL_PARAM_IMAGEFX_GPEN,
  14995. + MMAL_PARAM_IMAGEFX_PASTEL,
  14996. + MMAL_PARAM_IMAGEFX_WATERCOLOUR,
  14997. + MMAL_PARAM_IMAGEFX_FILM,
  14998. + MMAL_PARAM_IMAGEFX_BLUR,
  14999. + MMAL_PARAM_IMAGEFX_SATURATION,
  15000. + MMAL_PARAM_IMAGEFX_COLOURSWAP,
  15001. + MMAL_PARAM_IMAGEFX_WASHEDOUT,
  15002. + MMAL_PARAM_IMAGEFX_POSTERISE,
  15003. + MMAL_PARAM_IMAGEFX_COLOURPOINT,
  15004. + MMAL_PARAM_IMAGEFX_COLOURBALANCE,
  15005. + MMAL_PARAM_IMAGEFX_CARTOON,
  15006. +};
  15007. +
  15008. +enum MMAL_PARAM_FLICKERAVOID_T {
  15009. + MMAL_PARAM_FLICKERAVOID_OFF,
  15010. + MMAL_PARAM_FLICKERAVOID_AUTO,
  15011. + MMAL_PARAM_FLICKERAVOID_50HZ,
  15012. + MMAL_PARAM_FLICKERAVOID_60HZ,
  15013. + MMAL_PARAM_FLICKERAVOID_MAX = 0x7FFFFFFF
  15014. +};
  15015. +
  15016. +struct mmal_parameter_awbgains {
  15017. + struct mmal_parameter_rational r_gain; /**< Red gain */
  15018. + struct mmal_parameter_rational b_gain; /**< Blue gain */
  15019. +};
  15020. +
  15021. +/** Manner of video rate control */
  15022. +enum mmal_parameter_rate_control_mode {
  15023. + MMAL_VIDEO_RATECONTROL_DEFAULT,
  15024. + MMAL_VIDEO_RATECONTROL_VARIABLE,
  15025. + MMAL_VIDEO_RATECONTROL_CONSTANT,
  15026. + MMAL_VIDEO_RATECONTROL_VARIABLE_SKIP_FRAMES,
  15027. + MMAL_VIDEO_RATECONTROL_CONSTANT_SKIP_FRAMES
  15028. +};
  15029. +
  15030. +enum mmal_video_profile {
  15031. + MMAL_VIDEO_PROFILE_H263_BASELINE,
  15032. + MMAL_VIDEO_PROFILE_H263_H320CODING,
  15033. + MMAL_VIDEO_PROFILE_H263_BACKWARDCOMPATIBLE,
  15034. + MMAL_VIDEO_PROFILE_H263_ISWV2,
  15035. + MMAL_VIDEO_PROFILE_H263_ISWV3,
  15036. + MMAL_VIDEO_PROFILE_H263_HIGHCOMPRESSION,
  15037. + MMAL_VIDEO_PROFILE_H263_INTERNET,
  15038. + MMAL_VIDEO_PROFILE_H263_INTERLACE,
  15039. + MMAL_VIDEO_PROFILE_H263_HIGHLATENCY,
  15040. + MMAL_VIDEO_PROFILE_MP4V_SIMPLE,
  15041. + MMAL_VIDEO_PROFILE_MP4V_SIMPLESCALABLE,
  15042. + MMAL_VIDEO_PROFILE_MP4V_CORE,
  15043. + MMAL_VIDEO_PROFILE_MP4V_MAIN,
  15044. + MMAL_VIDEO_PROFILE_MP4V_NBIT,
  15045. + MMAL_VIDEO_PROFILE_MP4V_SCALABLETEXTURE,
  15046. + MMAL_VIDEO_PROFILE_MP4V_SIMPLEFACE,
  15047. + MMAL_VIDEO_PROFILE_MP4V_SIMPLEFBA,
  15048. + MMAL_VIDEO_PROFILE_MP4V_BASICANIMATED,
  15049. + MMAL_VIDEO_PROFILE_MP4V_HYBRID,
  15050. + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDREALTIME,
  15051. + MMAL_VIDEO_PROFILE_MP4V_CORESCALABLE,
  15052. + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDCODING,
  15053. + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDCORE,
  15054. + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDSCALABLE,
  15055. + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDSIMPLE,
  15056. + MMAL_VIDEO_PROFILE_H264_BASELINE,
  15057. + MMAL_VIDEO_PROFILE_H264_MAIN,
  15058. + MMAL_VIDEO_PROFILE_H264_EXTENDED,
  15059. + MMAL_VIDEO_PROFILE_H264_HIGH,
  15060. + MMAL_VIDEO_PROFILE_H264_HIGH10,
  15061. + MMAL_VIDEO_PROFILE_H264_HIGH422,
  15062. + MMAL_VIDEO_PROFILE_H264_HIGH444,
  15063. + MMAL_VIDEO_PROFILE_H264_CONSTRAINED_BASELINE,
  15064. + MMAL_VIDEO_PROFILE_DUMMY = 0x7FFFFFFF
  15065. +};
  15066. +
  15067. +enum mmal_video_level {
  15068. + MMAL_VIDEO_LEVEL_H263_10,
  15069. + MMAL_VIDEO_LEVEL_H263_20,
  15070. + MMAL_VIDEO_LEVEL_H263_30,
  15071. + MMAL_VIDEO_LEVEL_H263_40,
  15072. + MMAL_VIDEO_LEVEL_H263_45,
  15073. + MMAL_VIDEO_LEVEL_H263_50,
  15074. + MMAL_VIDEO_LEVEL_H263_60,
  15075. + MMAL_VIDEO_LEVEL_H263_70,
  15076. + MMAL_VIDEO_LEVEL_MP4V_0,
  15077. + MMAL_VIDEO_LEVEL_MP4V_0b,
  15078. + MMAL_VIDEO_LEVEL_MP4V_1,
  15079. + MMAL_VIDEO_LEVEL_MP4V_2,
  15080. + MMAL_VIDEO_LEVEL_MP4V_3,
  15081. + MMAL_VIDEO_LEVEL_MP4V_4,
  15082. + MMAL_VIDEO_LEVEL_MP4V_4a,
  15083. + MMAL_VIDEO_LEVEL_MP4V_5,
  15084. + MMAL_VIDEO_LEVEL_MP4V_6,
  15085. + MMAL_VIDEO_LEVEL_H264_1,
  15086. + MMAL_VIDEO_LEVEL_H264_1b,
  15087. + MMAL_VIDEO_LEVEL_H264_11,
  15088. + MMAL_VIDEO_LEVEL_H264_12,
  15089. + MMAL_VIDEO_LEVEL_H264_13,
  15090. + MMAL_VIDEO_LEVEL_H264_2,
  15091. + MMAL_VIDEO_LEVEL_H264_21,
  15092. + MMAL_VIDEO_LEVEL_H264_22,
  15093. + MMAL_VIDEO_LEVEL_H264_3,
  15094. + MMAL_VIDEO_LEVEL_H264_31,
  15095. + MMAL_VIDEO_LEVEL_H264_32,
  15096. + MMAL_VIDEO_LEVEL_H264_4,
  15097. + MMAL_VIDEO_LEVEL_H264_41,
  15098. + MMAL_VIDEO_LEVEL_H264_42,
  15099. + MMAL_VIDEO_LEVEL_H264_5,
  15100. + MMAL_VIDEO_LEVEL_H264_51,
  15101. + MMAL_VIDEO_LEVEL_DUMMY = 0x7FFFFFFF
  15102. +};
  15103. +
  15104. +struct mmal_parameter_video_profile {
  15105. + enum mmal_video_profile profile;
  15106. + enum mmal_video_level level;
  15107. +};
  15108. +
  15109. +/* video parameters */
  15110. +
  15111. +enum mmal_parameter_video_type {
  15112. + /** @ref MMAL_DISPLAYREGION_T */
  15113. + MMAL_PARAMETER_DISPLAYREGION = MMAL_PARAMETER_GROUP_VIDEO,
  15114. +
  15115. + /** @ref MMAL_PARAMETER_VIDEO_PROFILE_T */
  15116. + MMAL_PARAMETER_SUPPORTED_PROFILES,
  15117. +
  15118. + /** @ref MMAL_PARAMETER_VIDEO_PROFILE_T */
  15119. + MMAL_PARAMETER_PROFILE,
  15120. +
  15121. + /** @ref MMAL_PARAMETER_UINT32_T */
  15122. + MMAL_PARAMETER_INTRAPERIOD,
  15123. +
  15124. + /** @ref MMAL_PARAMETER_VIDEO_RATECONTROL_T */
  15125. + MMAL_PARAMETER_RATECONTROL,
  15126. +
  15127. + /** @ref MMAL_PARAMETER_VIDEO_NALUNITFORMAT_T */
  15128. + MMAL_PARAMETER_NALUNITFORMAT,
  15129. +
  15130. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  15131. + MMAL_PARAMETER_MINIMISE_FRAGMENTATION,
  15132. +
  15133. + /** @ref MMAL_PARAMETER_UINT32_T.
  15134. + * Setting the value to zero resets to the default (one slice per frame).
  15135. + */
  15136. + MMAL_PARAMETER_MB_ROWS_PER_SLICE,
  15137. +
  15138. + /** @ref MMAL_PARAMETER_VIDEO_LEVEL_EXTENSION_T */
  15139. + MMAL_PARAMETER_VIDEO_LEVEL_EXTENSION,
  15140. +
  15141. + /** @ref MMAL_PARAMETER_VIDEO_EEDE_ENABLE_T */
  15142. + MMAL_PARAMETER_VIDEO_EEDE_ENABLE,
  15143. +
  15144. + /** @ref MMAL_PARAMETER_VIDEO_EEDE_LOSSRATE_T */
  15145. + MMAL_PARAMETER_VIDEO_EEDE_LOSSRATE,
  15146. +
  15147. + /** @ref MMAL_PARAMETER_BOOLEAN_T. Request an I-frame. */
  15148. + MMAL_PARAMETER_VIDEO_REQUEST_I_FRAME,
  15149. + /** @ref MMAL_PARAMETER_VIDEO_INTRA_REFRESH_T */
  15150. + MMAL_PARAMETER_VIDEO_INTRA_REFRESH,
  15151. +
  15152. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  15153. + MMAL_PARAMETER_VIDEO_IMMUTABLE_INPUT,
  15154. +
  15155. + /** @ref MMAL_PARAMETER_UINT32_T. Run-time bit rate control */
  15156. + MMAL_PARAMETER_VIDEO_BIT_RATE,
  15157. +
  15158. + /** @ref MMAL_PARAMETER_FRAME_RATE_T */
  15159. + MMAL_PARAMETER_VIDEO_FRAME_RATE,
  15160. +
  15161. + /** @ref MMAL_PARAMETER_UINT32_T. */
  15162. + MMAL_PARAMETER_VIDEO_ENCODE_MIN_QUANT,
  15163. +
  15164. + /** @ref MMAL_PARAMETER_UINT32_T. */
  15165. + MMAL_PARAMETER_VIDEO_ENCODE_MAX_QUANT,
  15166. +
  15167. + /** @ref MMAL_PARAMETER_VIDEO_ENCODE_RC_MODEL_T. */
  15168. + MMAL_PARAMETER_VIDEO_ENCODE_RC_MODEL,
  15169. +
  15170. + MMAL_PARAMETER_EXTRA_BUFFERS, /**< @ref MMAL_PARAMETER_UINT32_T. */
  15171. + /** @ref MMAL_PARAMETER_UINT32_T.
  15172. + * Changing this parameter from the default can reduce frame rate
  15173. + * because image buffers need to be re-pitched.
  15174. + */
  15175. + MMAL_PARAMETER_VIDEO_ALIGN_HORIZ,
  15176. +
  15177. + /** @ref MMAL_PARAMETER_UINT32_T.
  15178. + * Changing this parameter from the default can reduce frame rate
  15179. + * because image buffers need to be re-pitched.
  15180. + */
  15181. + MMAL_PARAMETER_VIDEO_ALIGN_VERT,
  15182. +
  15183. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  15184. + MMAL_PARAMETER_VIDEO_DROPPABLE_PFRAMES,
  15185. +
  15186. + /** @ref MMAL_PARAMETER_UINT32_T. */
  15187. + MMAL_PARAMETER_VIDEO_ENCODE_INITIAL_QUANT,
  15188. +
  15189. + /**< @ref MMAL_PARAMETER_UINT32_T. */
  15190. + MMAL_PARAMETER_VIDEO_ENCODE_QP_P,
  15191. +
  15192. + /**< @ref MMAL_PARAMETER_UINT32_T. */
  15193. + MMAL_PARAMETER_VIDEO_ENCODE_RC_SLICE_DQUANT,
  15194. +
  15195. + /** @ref MMAL_PARAMETER_UINT32_T */
  15196. + MMAL_PARAMETER_VIDEO_ENCODE_FRAME_LIMIT_BITS,
  15197. +
  15198. + /** @ref MMAL_PARAMETER_UINT32_T. */
  15199. + MMAL_PARAMETER_VIDEO_ENCODE_PEAK_RATE,
  15200. +
  15201. + /* H264 specific parameters */
  15202. +
  15203. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  15204. + MMAL_PARAMETER_VIDEO_ENCODE_H264_DISABLE_CABAC,
  15205. +
  15206. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  15207. + MMAL_PARAMETER_VIDEO_ENCODE_H264_LOW_LATENCY,
  15208. +
  15209. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  15210. + MMAL_PARAMETER_VIDEO_ENCODE_H264_AU_DELIMITERS,
  15211. +
  15212. + /** @ref MMAL_PARAMETER_UINT32_T. */
  15213. + MMAL_PARAMETER_VIDEO_ENCODE_H264_DEBLOCK_IDC,
  15214. +
  15215. + /** @ref MMAL_PARAMETER_VIDEO_ENCODER_H264_MB_INTRA_MODES_T. */
  15216. + MMAL_PARAMETER_VIDEO_ENCODE_H264_MB_INTRA_MODE,
  15217. +
  15218. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  15219. + MMAL_PARAMETER_VIDEO_ENCODE_HEADER_ON_OPEN,
  15220. +
  15221. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  15222. + MMAL_PARAMETER_VIDEO_ENCODE_PRECODE_FOR_QP,
  15223. +
  15224. + /** @ref MMAL_PARAMETER_VIDEO_DRM_INIT_INFO_T. */
  15225. + MMAL_PARAMETER_VIDEO_DRM_INIT_INFO,
  15226. +
  15227. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  15228. + MMAL_PARAMETER_VIDEO_TIMESTAMP_FIFO,
  15229. +
  15230. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  15231. + MMAL_PARAMETER_VIDEO_DECODE_ERROR_CONCEALMENT,
  15232. +
  15233. + /** @ref MMAL_PARAMETER_VIDEO_DRM_PROTECT_BUFFER_T. */
  15234. + MMAL_PARAMETER_VIDEO_DRM_PROTECT_BUFFER,
  15235. +
  15236. + /** @ref MMAL_PARAMETER_BYTES_T */
  15237. + MMAL_PARAMETER_VIDEO_DECODE_CONFIG_VD3,
  15238. +
  15239. + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15240. + MMAL_PARAMETER_VIDEO_ENCODE_H264_VCL_HRD_PARAMETERS,
  15241. +
  15242. + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15243. + MMAL_PARAMETER_VIDEO_ENCODE_H264_LOW_DELAY_HRD_FLAG,
  15244. +
  15245. + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15246. + MMAL_PARAMETER_VIDEO_ENCODE_INLINE_HEADER
  15247. +};
  15248. +
  15249. +/** Valid mirror modes */
  15250. +enum mmal_parameter_mirror {
  15251. + MMAL_PARAM_MIRROR_NONE,
  15252. + MMAL_PARAM_MIRROR_VERTICAL,
  15253. + MMAL_PARAM_MIRROR_HORIZONTAL,
  15254. + MMAL_PARAM_MIRROR_BOTH,
  15255. +};
  15256. +
  15257. +enum mmal_parameter_displaytransform {
  15258. + MMAL_DISPLAY_ROT0 = 0,
  15259. + MMAL_DISPLAY_MIRROR_ROT0 = 1,
  15260. + MMAL_DISPLAY_MIRROR_ROT180 = 2,
  15261. + MMAL_DISPLAY_ROT180 = 3,
  15262. + MMAL_DISPLAY_MIRROR_ROT90 = 4,
  15263. + MMAL_DISPLAY_ROT270 = 5,
  15264. + MMAL_DISPLAY_ROT90 = 6,
  15265. + MMAL_DISPLAY_MIRROR_ROT270 = 7,
  15266. +};
  15267. +
  15268. +enum mmal_parameter_displaymode {
  15269. + MMAL_DISPLAY_MODE_FILL = 0,
  15270. + MMAL_DISPLAY_MODE_LETTERBOX = 1,
  15271. +};
  15272. +
  15273. +enum mmal_parameter_displayset {
  15274. + MMAL_DISPLAY_SET_NONE = 0,
  15275. + MMAL_DISPLAY_SET_NUM = 1,
  15276. + MMAL_DISPLAY_SET_FULLSCREEN = 2,
  15277. + MMAL_DISPLAY_SET_TRANSFORM = 4,
  15278. + MMAL_DISPLAY_SET_DEST_RECT = 8,
  15279. + MMAL_DISPLAY_SET_SRC_RECT = 0x10,
  15280. + MMAL_DISPLAY_SET_MODE = 0x20,
  15281. + MMAL_DISPLAY_SET_PIXEL = 0x40,
  15282. + MMAL_DISPLAY_SET_NOASPECT = 0x80,
  15283. + MMAL_DISPLAY_SET_LAYER = 0x100,
  15284. + MMAL_DISPLAY_SET_COPYPROTECT = 0x200,
  15285. + MMAL_DISPLAY_SET_ALPHA = 0x400,
  15286. +};
  15287. +
  15288. +struct mmal_parameter_displayregion {
  15289. + /** Bitfield that indicates which fields are set and should be
  15290. + * used. All other fields will maintain their current value.
  15291. + * \ref MMAL_DISPLAYSET_T defines the bits that can be
  15292. + * combined.
  15293. + */
  15294. + u32 set;
  15295. +
  15296. + /** Describes the display output device, with 0 typically
  15297. + * being a directly connected LCD display. The actual values
  15298. + * will depend on the hardware. Code using hard-wired numbers
  15299. + * (e.g. 2) is certain to fail.
  15300. + */
  15301. +
  15302. + u32 display_num;
  15303. + /** Indicates that we are using the full device screen area,
  15304. + * rather than a window of the display. If zero, then
  15305. + * dest_rect is used to specify a region of the display to
  15306. + * use.
  15307. + */
  15308. +
  15309. + s32 fullscreen;
  15310. + /** Indicates any rotation or flipping used to map frames onto
  15311. + * the natural display orientation.
  15312. + */
  15313. + u32 transform; /* enum mmal_parameter_displaytransform */
  15314. +
  15315. + /** Where to display the frame within the screen, if
  15316. + * fullscreen is zero.
  15317. + */
  15318. + struct vchiq_mmal_rect dest_rect;
  15319. +
  15320. + /** Indicates which area of the frame to display. If all
  15321. + * values are zero, the whole frame will be used.
  15322. + */
  15323. + struct vchiq_mmal_rect src_rect;
  15324. +
  15325. + /** If set to non-zero, indicates that any display scaling
  15326. + * should disregard the aspect ratio of the frame region being
  15327. + * displayed.
  15328. + */
  15329. + s32 noaspect;
  15330. +
  15331. + /** Indicates how the image should be scaled to fit the
  15332. + * display. \code MMAL_DISPLAY_MODE_FILL \endcode indicates
  15333. + * that the image should fill the screen by potentially
  15334. + * cropping the frames. Setting \code mode \endcode to \code
  15335. + * MMAL_DISPLAY_MODE_LETTERBOX \endcode indicates that all the
  15336. + * source region should be displayed and black bars added if
  15337. + * necessary.
  15338. + */
  15339. + u32 mode; /* enum mmal_parameter_displaymode */
  15340. +
  15341. + /** If non-zero, defines the width of a source pixel relative
  15342. + * to \code pixel_y \endcode. If zero, then pixels default to
  15343. + * being square.
  15344. + */
  15345. + u32 pixel_x;
  15346. +
  15347. + /** If non-zero, defines the height of a source pixel relative
  15348. + * to \code pixel_x \endcode. If zero, then pixels default to
  15349. + * being square.
  15350. + */
  15351. + u32 pixel_y;
  15352. +
  15353. + /** Sets the relative depth of the images, with greater values
  15354. + * being in front of smaller values.
  15355. + */
  15356. + u32 layer;
  15357. +
  15358. + /** Set to non-zero to ensure copy protection is used on
  15359. + * output.
  15360. + */
  15361. + s32 copyprotect_required;
  15362. +
  15363. + /** Level of opacity of the layer, where zero is fully
  15364. + * transparent and 255 is fully opaque.
  15365. + */
  15366. + u32 alpha;
  15367. +};
  15368. +
  15369. +#define MMAL_MAX_IMAGEFX_PARAMETERS 5
  15370. +
  15371. +struct mmal_parameter_imagefx_parameters {
  15372. + enum mmal_parameter_imagefx effect;
  15373. + u32 num_effect_params;
  15374. + u32 effect_parameter[MMAL_MAX_IMAGEFX_PARAMETERS];
  15375. +};
  15376. diff -Nur linux-3.13.11/drivers/media/platform/bcm2835/mmal-vchiq.c linux-rpi/drivers/media/platform/bcm2835/mmal-vchiq.c
  15377. --- linux-3.13.11/drivers/media/platform/bcm2835/mmal-vchiq.c 1970-01-01 01:00:00.000000000 +0100
  15378. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-vchiq.c 2014-04-24 15:36:50.070736112 +0200
  15379. @@ -0,0 +1,1916 @@
  15380. +/*
  15381. + * Broadcom BM2835 V4L2 driver
  15382. + *
  15383. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  15384. + *
  15385. + * This file is subject to the terms and conditions of the GNU General Public
  15386. + * License. See the file COPYING in the main directory of this archive
  15387. + * for more details.
  15388. + *
  15389. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  15390. + * Dave Stevenson <dsteve@broadcom.com>
  15391. + * Simon Mellor <simellor@broadcom.com>
  15392. + * Luke Diamand <luked@broadcom.com>
  15393. + *
  15394. + * V4L2 driver MMAL vchiq interface code
  15395. + */
  15396. +
  15397. +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  15398. +
  15399. +#include <linux/errno.h>
  15400. +#include <linux/kernel.h>
  15401. +#include <linux/mutex.h>
  15402. +#include <linux/mm.h>
  15403. +#include <linux/slab.h>
  15404. +#include <linux/completion.h>
  15405. +#include <linux/vmalloc.h>
  15406. +#include <asm/cacheflush.h>
  15407. +#include <media/videobuf2-vmalloc.h>
  15408. +
  15409. +#include "mmal-common.h"
  15410. +#include "mmal-vchiq.h"
  15411. +#include "mmal-msg.h"
  15412. +
  15413. +#define USE_VCHIQ_ARM
  15414. +#include "interface/vchi/vchi.h"
  15415. +
  15416. +/* maximum number of components supported */
  15417. +#define VCHIQ_MMAL_MAX_COMPONENTS 4
  15418. +
  15419. +/*#define FULL_MSG_DUMP 1*/
  15420. +
  15421. +#ifdef DEBUG
  15422. +static const char *const msg_type_names[] = {
  15423. + "UNKNOWN",
  15424. + "QUIT",
  15425. + "SERVICE_CLOSED",
  15426. + "GET_VERSION",
  15427. + "COMPONENT_CREATE",
  15428. + "COMPONENT_DESTROY",
  15429. + "COMPONENT_ENABLE",
  15430. + "COMPONENT_DISABLE",
  15431. + "PORT_INFO_GET",
  15432. + "PORT_INFO_SET",
  15433. + "PORT_ACTION",
  15434. + "BUFFER_FROM_HOST",
  15435. + "BUFFER_TO_HOST",
  15436. + "GET_STATS",
  15437. + "PORT_PARAMETER_SET",
  15438. + "PORT_PARAMETER_GET",
  15439. + "EVENT_TO_HOST",
  15440. + "GET_CORE_STATS_FOR_PORT",
  15441. + "OPAQUE_ALLOCATOR",
  15442. + "CONSUME_MEM",
  15443. + "LMK",
  15444. + "OPAQUE_ALLOCATOR_DESC",
  15445. + "DRM_GET_LHS32",
  15446. + "DRM_GET_TIME",
  15447. + "BUFFER_FROM_HOST_ZEROLEN",
  15448. + "PORT_FLUSH",
  15449. + "HOST_LOG",
  15450. +};
  15451. +#endif
  15452. +
  15453. +static const char *const port_action_type_names[] = {
  15454. + "UNKNOWN",
  15455. + "ENABLE",
  15456. + "DISABLE",
  15457. + "FLUSH",
  15458. + "CONNECT",
  15459. + "DISCONNECT",
  15460. + "SET_REQUIREMENTS",
  15461. +};
  15462. +
  15463. +#if defined(DEBUG)
  15464. +#if defined(FULL_MSG_DUMP)
  15465. +#define DBG_DUMP_MSG(MSG, MSG_LEN, TITLE) \
  15466. + do { \
  15467. + pr_debug(TITLE" type:%s(%d) length:%d\n", \
  15468. + msg_type_names[(MSG)->h.type], \
  15469. + (MSG)->h.type, (MSG_LEN)); \
  15470. + print_hex_dump(KERN_DEBUG, "<<h: ", DUMP_PREFIX_OFFSET, \
  15471. + 16, 4, (MSG), \
  15472. + sizeof(struct mmal_msg_header), 1); \
  15473. + print_hex_dump(KERN_DEBUG, "<<p: ", DUMP_PREFIX_OFFSET, \
  15474. + 16, 4, \
  15475. + ((u8 *)(MSG)) + sizeof(struct mmal_msg_header),\
  15476. + (MSG_LEN) - sizeof(struct mmal_msg_header), 1); \
  15477. + } while (0)
  15478. +#else
  15479. +#define DBG_DUMP_MSG(MSG, MSG_LEN, TITLE) \
  15480. + { \
  15481. + pr_debug(TITLE" type:%s(%d) length:%d\n", \
  15482. + msg_type_names[(MSG)->h.type], \
  15483. + (MSG)->h.type, (MSG_LEN)); \
  15484. + }
  15485. +#endif
  15486. +#else
  15487. +#define DBG_DUMP_MSG(MSG, MSG_LEN, TITLE)
  15488. +#endif
  15489. +
  15490. +/* normal message context */
  15491. +struct mmal_msg_context {
  15492. + union {
  15493. + struct {
  15494. + /* work struct for defered callback - must come first */
  15495. + struct work_struct work;
  15496. + /* mmal instance */
  15497. + struct vchiq_mmal_instance *instance;
  15498. + /* mmal port */
  15499. + struct vchiq_mmal_port *port;
  15500. + /* actual buffer used to store bulk reply */
  15501. + struct mmal_buffer *buffer;
  15502. + /* amount of buffer used */
  15503. + unsigned long buffer_used;
  15504. + /* MMAL buffer flags */
  15505. + u32 mmal_flags;
  15506. + /* Presentation and Decode timestamps */
  15507. + s64 pts;
  15508. + s64 dts;
  15509. +
  15510. + int status; /* context status */
  15511. +
  15512. + } bulk; /* bulk data */
  15513. +
  15514. + struct {
  15515. + /* message handle to release */
  15516. + VCHI_HELD_MSG_T msg_handle;
  15517. + /* pointer to received message */
  15518. + struct mmal_msg *msg;
  15519. + /* received message length */
  15520. + u32 msg_len;
  15521. + /* completion upon reply */
  15522. + struct completion cmplt;
  15523. + } sync; /* synchronous response */
  15524. + } u;
  15525. +
  15526. +};
  15527. +
  15528. +struct vchiq_mmal_instance {
  15529. + VCHI_SERVICE_HANDLE_T handle;
  15530. +
  15531. + /* ensure serialised access to service */
  15532. + struct mutex vchiq_mutex;
  15533. +
  15534. + /* ensure serialised access to bulk operations */
  15535. + struct mutex bulk_mutex;
  15536. +
  15537. + /* vmalloc page to receive scratch bulk xfers into */
  15538. + void *bulk_scratch;
  15539. +
  15540. + /* component to use next */
  15541. + int component_idx;
  15542. + struct vchiq_mmal_component component[VCHIQ_MMAL_MAX_COMPONENTS];
  15543. +};
  15544. +
  15545. +static struct mmal_msg_context *get_msg_context(struct vchiq_mmal_instance
  15546. + *instance)
  15547. +{
  15548. + struct mmal_msg_context *msg_context;
  15549. +
  15550. + /* todo: should this be allocated from a pool to avoid kmalloc */
  15551. + msg_context = kmalloc(sizeof(*msg_context), GFP_KERNEL);
  15552. + memset(msg_context, 0, sizeof(*msg_context));
  15553. +
  15554. + return msg_context;
  15555. +}
  15556. +
  15557. +static void release_msg_context(struct mmal_msg_context *msg_context)
  15558. +{
  15559. + kfree(msg_context);
  15560. +}
  15561. +
  15562. +/* deals with receipt of event to host message */
  15563. +static void event_to_host_cb(struct vchiq_mmal_instance *instance,
  15564. + struct mmal_msg *msg, u32 msg_len)
  15565. +{
  15566. + pr_debug("unhandled event\n");
  15567. + pr_debug("component:%p port type:%d num:%d cmd:0x%x length:%d\n",
  15568. + msg->u.event_to_host.client_component,
  15569. + msg->u.event_to_host.port_type,
  15570. + msg->u.event_to_host.port_num,
  15571. + msg->u.event_to_host.cmd, msg->u.event_to_host.length);
  15572. +}
  15573. +
  15574. +/* workqueue scheduled callback
  15575. + *
  15576. + * we do this because it is important we do not call any other vchiq
  15577. + * sync calls from witin the message delivery thread
  15578. + */
  15579. +static void buffer_work_cb(struct work_struct *work)
  15580. +{
  15581. + struct mmal_msg_context *msg_context = (struct mmal_msg_context *)work;
  15582. +
  15583. + msg_context->u.bulk.port->buffer_cb(msg_context->u.bulk.instance,
  15584. + msg_context->u.bulk.port,
  15585. + msg_context->u.bulk.status,
  15586. + msg_context->u.bulk.buffer,
  15587. + msg_context->u.bulk.buffer_used,
  15588. + msg_context->u.bulk.mmal_flags,
  15589. + msg_context->u.bulk.dts,
  15590. + msg_context->u.bulk.pts);
  15591. +
  15592. + /* release message context */
  15593. + release_msg_context(msg_context);
  15594. +}
  15595. +
  15596. +/* enqueue a bulk receive for a given message context */
  15597. +static int bulk_receive(struct vchiq_mmal_instance *instance,
  15598. + struct mmal_msg *msg,
  15599. + struct mmal_msg_context *msg_context)
  15600. +{
  15601. + unsigned long rd_len;
  15602. + unsigned long flags = 0;
  15603. + int ret;
  15604. +
  15605. + /* bulk mutex stops other bulk operations while we have a
  15606. + * receive in progress - released in callback
  15607. + */
  15608. + ret = mutex_lock_interruptible(&instance->bulk_mutex);
  15609. + if (ret != 0)
  15610. + return ret;
  15611. +
  15612. + rd_len = msg->u.buffer_from_host.buffer_header.length;
  15613. +
  15614. + /* take buffer from queue */
  15615. + spin_lock_irqsave(&msg_context->u.bulk.port->slock, flags);
  15616. + if (list_empty(&msg_context->u.bulk.port->buffers)) {
  15617. + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
  15618. + pr_err("buffer list empty trying to submit bulk receive\n");
  15619. +
  15620. + /* todo: this is a serious error, we should never have
  15621. + * commited a buffer_to_host operation to the mmal
  15622. + * port without the buffer to back it up (underflow
  15623. + * handling) and there is no obvious way to deal with
  15624. + * this - how is the mmal servie going to react when
  15625. + * we fail to do the xfer and reschedule a buffer when
  15626. + * it arrives? perhaps a starved flag to indicate a
  15627. + * waiting bulk receive?
  15628. + */
  15629. +
  15630. + mutex_unlock(&instance->bulk_mutex);
  15631. +
  15632. + return -EINVAL;
  15633. + }
  15634. +
  15635. + msg_context->u.bulk.buffer =
  15636. + list_entry(msg_context->u.bulk.port->buffers.next,
  15637. + struct mmal_buffer, list);
  15638. + list_del(&msg_context->u.bulk.buffer->list);
  15639. +
  15640. + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
  15641. +
  15642. + /* ensure we do not overrun the available buffer */
  15643. + if (rd_len > msg_context->u.bulk.buffer->buffer_size) {
  15644. + rd_len = msg_context->u.bulk.buffer->buffer_size;
  15645. + pr_warn("short read as not enough receive buffer space\n");
  15646. + /* todo: is this the correct response, what happens to
  15647. + * the rest of the message data?
  15648. + */
  15649. + }
  15650. +
  15651. + /* store length */
  15652. + msg_context->u.bulk.buffer_used = rd_len;
  15653. + msg_context->u.bulk.mmal_flags =
  15654. + msg->u.buffer_from_host.buffer_header.flags;
  15655. + msg_context->u.bulk.dts = msg->u.buffer_from_host.buffer_header.dts;
  15656. + msg_context->u.bulk.pts = msg->u.buffer_from_host.buffer_header.pts;
  15657. +
  15658. + // only need to flush L1 cache here, as VCHIQ takes care of the L2
  15659. + // cache.
  15660. + __cpuc_flush_dcache_area(msg_context->u.bulk.buffer->buffer, rd_len);
  15661. +
  15662. + /* queue the bulk submission */
  15663. + vchi_service_use(instance->handle);
  15664. + ret = vchi_bulk_queue_receive(instance->handle,
  15665. + msg_context->u.bulk.buffer->buffer,
  15666. + /* Actual receive needs to be a multiple
  15667. + * of 4 bytes
  15668. + */
  15669. + (rd_len + 3) & ~3,
  15670. + VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE |
  15671. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED,
  15672. + msg_context);
  15673. +
  15674. + vchi_service_release(instance->handle);
  15675. +
  15676. + if (ret != 0) {
  15677. + /* callback will not be clearing the mutex */
  15678. + mutex_unlock(&instance->bulk_mutex);
  15679. + }
  15680. +
  15681. + return ret;
  15682. +}
  15683. +
  15684. +/* enque a dummy bulk receive for a given message context */
  15685. +static int dummy_bulk_receive(struct vchiq_mmal_instance *instance,
  15686. + struct mmal_msg_context *msg_context)
  15687. +{
  15688. + int ret;
  15689. +
  15690. + /* bulk mutex stops other bulk operations while we have a
  15691. + * receive in progress - released in callback
  15692. + */
  15693. + ret = mutex_lock_interruptible(&instance->bulk_mutex);
  15694. + if (ret != 0)
  15695. + return ret;
  15696. +
  15697. + /* zero length indicates this was a dummy transfer */
  15698. + msg_context->u.bulk.buffer_used = 0;
  15699. +
  15700. + /* queue the bulk submission */
  15701. + vchi_service_use(instance->handle);
  15702. +
  15703. + ret = vchi_bulk_queue_receive(instance->handle,
  15704. + instance->bulk_scratch,
  15705. + 8,
  15706. + VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE |
  15707. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED,
  15708. + msg_context);
  15709. +
  15710. + vchi_service_release(instance->handle);
  15711. +
  15712. + if (ret != 0) {
  15713. + /* callback will not be clearing the mutex */
  15714. + mutex_unlock(&instance->bulk_mutex);
  15715. + }
  15716. +
  15717. + return ret;
  15718. +}
  15719. +
  15720. +/* data in message, memcpy from packet into output buffer */
  15721. +static int inline_receive(struct vchiq_mmal_instance *instance,
  15722. + struct mmal_msg *msg,
  15723. + struct mmal_msg_context *msg_context)
  15724. +{
  15725. + unsigned long flags = 0;
  15726. +
  15727. + /* take buffer from queue */
  15728. + spin_lock_irqsave(&msg_context->u.bulk.port->slock, flags);
  15729. + if (list_empty(&msg_context->u.bulk.port->buffers)) {
  15730. + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
  15731. + pr_err("buffer list empty trying to receive inline\n");
  15732. +
  15733. + /* todo: this is a serious error, we should never have
  15734. + * commited a buffer_to_host operation to the mmal
  15735. + * port without the buffer to back it up (with
  15736. + * underflow handling) and there is no obvious way to
  15737. + * deal with this. Less bad than the bulk case as we
  15738. + * can just drop this on the floor but...unhelpful
  15739. + */
  15740. + return -EINVAL;
  15741. + }
  15742. +
  15743. + msg_context->u.bulk.buffer =
  15744. + list_entry(msg_context->u.bulk.port->buffers.next,
  15745. + struct mmal_buffer, list);
  15746. + list_del(&msg_context->u.bulk.buffer->list);
  15747. +
  15748. + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
  15749. +
  15750. + memcpy(msg_context->u.bulk.buffer->buffer,
  15751. + msg->u.buffer_from_host.short_data,
  15752. + msg->u.buffer_from_host.payload_in_message);
  15753. +
  15754. + msg_context->u.bulk.buffer_used =
  15755. + msg->u.buffer_from_host.payload_in_message;
  15756. +
  15757. + return 0;
  15758. +}
  15759. +
  15760. +/* queue the buffer availability with MMAL_MSG_TYPE_BUFFER_FROM_HOST */
  15761. +static int
  15762. +buffer_from_host(struct vchiq_mmal_instance *instance,
  15763. + struct vchiq_mmal_port *port, struct mmal_buffer *buf)
  15764. +{
  15765. + struct mmal_msg_context *msg_context;
  15766. + struct mmal_msg m;
  15767. + int ret;
  15768. +
  15769. + pr_debug("instance:%p buffer:%p\n", instance->handle, buf);
  15770. +
  15771. + /* bulk mutex stops other bulk operations while we
  15772. + * have a receive in progress
  15773. + */
  15774. + if (mutex_lock_interruptible(&instance->bulk_mutex))
  15775. + return -EINTR;
  15776. +
  15777. + /* get context */
  15778. + msg_context = get_msg_context(instance);
  15779. + if (msg_context == NULL)
  15780. + return -ENOMEM;
  15781. +
  15782. + /* store bulk message context for when data arrives */
  15783. + msg_context->u.bulk.instance = instance;
  15784. + msg_context->u.bulk.port = port;
  15785. + msg_context->u.bulk.buffer = NULL; /* not valid until bulk xfer */
  15786. + msg_context->u.bulk.buffer_used = 0;
  15787. +
  15788. + /* initialise work structure ready to schedule callback */
  15789. + INIT_WORK(&msg_context->u.bulk.work, buffer_work_cb);
  15790. +
  15791. + /* prep the buffer from host message */
  15792. + memset(&m, 0xbc, sizeof(m)); /* just to make debug clearer */
  15793. +
  15794. + m.h.type = MMAL_MSG_TYPE_BUFFER_FROM_HOST;
  15795. + m.h.magic = MMAL_MAGIC;
  15796. + m.h.context = msg_context;
  15797. + m.h.status = 0;
  15798. +
  15799. + /* drvbuf is our private data passed back */
  15800. + m.u.buffer_from_host.drvbuf.magic = MMAL_MAGIC;
  15801. + m.u.buffer_from_host.drvbuf.component_handle = port->component->handle;
  15802. + m.u.buffer_from_host.drvbuf.port_handle = port->handle;
  15803. + m.u.buffer_from_host.drvbuf.client_context = msg_context;
  15804. +
  15805. + /* buffer header */
  15806. + m.u.buffer_from_host.buffer_header.cmd = 0;
  15807. + m.u.buffer_from_host.buffer_header.data = buf->buffer;
  15808. + m.u.buffer_from_host.buffer_header.alloc_size = buf->buffer_size;
  15809. + m.u.buffer_from_host.buffer_header.length = 0; /* nothing used yet */
  15810. + m.u.buffer_from_host.buffer_header.offset = 0; /* no offset */
  15811. + m.u.buffer_from_host.buffer_header.flags = 0; /* no flags */
  15812. + m.u.buffer_from_host.buffer_header.pts = MMAL_TIME_UNKNOWN;
  15813. + m.u.buffer_from_host.buffer_header.dts = MMAL_TIME_UNKNOWN;
  15814. +
  15815. + /* clear buffer type sepecific data */
  15816. + memset(&m.u.buffer_from_host.buffer_header_type_specific, 0,
  15817. + sizeof(m.u.buffer_from_host.buffer_header_type_specific));
  15818. +
  15819. + /* no payload in message */
  15820. + m.u.buffer_from_host.payload_in_message = 0;
  15821. +
  15822. + vchi_service_use(instance->handle);
  15823. +
  15824. + ret = vchi_msg_queue(instance->handle, &m,
  15825. + sizeof(struct mmal_msg_header) +
  15826. + sizeof(m.u.buffer_from_host),
  15827. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  15828. +
  15829. + if (ret != 0) {
  15830. + release_msg_context(msg_context);
  15831. + /* todo: is this correct error value? */
  15832. + }
  15833. +
  15834. + vchi_service_release(instance->handle);
  15835. +
  15836. + mutex_unlock(&instance->bulk_mutex);
  15837. +
  15838. + return ret;
  15839. +}
  15840. +
  15841. +/* submit a buffer to the mmal sevice
  15842. + *
  15843. + * the buffer_from_host uses size data from the ports next available
  15844. + * mmal_buffer and deals with there being no buffer available by
  15845. + * incrementing the underflow for later
  15846. + */
  15847. +static int port_buffer_from_host(struct vchiq_mmal_instance *instance,
  15848. + struct vchiq_mmal_port *port)
  15849. +{
  15850. + int ret;
  15851. + struct mmal_buffer *buf;
  15852. + unsigned long flags = 0;
  15853. +
  15854. + if (!port->enabled)
  15855. + return -EINVAL;
  15856. +
  15857. + /* peek buffer from queue */
  15858. + spin_lock_irqsave(&port->slock, flags);
  15859. + if (list_empty(&port->buffers)) {
  15860. + port->buffer_underflow++;
  15861. + spin_unlock_irqrestore(&port->slock, flags);
  15862. + return -ENOSPC;
  15863. + }
  15864. +
  15865. + buf = list_entry(port->buffers.next, struct mmal_buffer, list);
  15866. +
  15867. + spin_unlock_irqrestore(&port->slock, flags);
  15868. +
  15869. + /* issue buffer to mmal service */
  15870. + ret = buffer_from_host(instance, port, buf);
  15871. + if (ret) {
  15872. + pr_err("adding buffer header failed\n");
  15873. + /* todo: how should this be dealt with */
  15874. + }
  15875. +
  15876. + return ret;
  15877. +}
  15878. +
  15879. +/* deals with receipt of buffer to host message */
  15880. +static void buffer_to_host_cb(struct vchiq_mmal_instance *instance,
  15881. + struct mmal_msg *msg, u32 msg_len)
  15882. +{
  15883. + struct mmal_msg_context *msg_context;
  15884. +
  15885. + pr_debug("buffer_to_host_cb: instance:%p msg:%p msg_len:%d\n",
  15886. + instance, msg, msg_len);
  15887. +
  15888. + if (msg->u.buffer_from_host.drvbuf.magic == MMAL_MAGIC) {
  15889. + msg_context = msg->u.buffer_from_host.drvbuf.client_context;
  15890. + } else {
  15891. + pr_err("MMAL_MSG_TYPE_BUFFER_TO_HOST with bad magic\n");
  15892. + return;
  15893. + }
  15894. +
  15895. + if (msg->h.status != MMAL_MSG_STATUS_SUCCESS) {
  15896. + /* message reception had an error */
  15897. + pr_warn("error %d in reply\n", msg->h.status);
  15898. +
  15899. + msg_context->u.bulk.status = msg->h.status;
  15900. +
  15901. + } else if (msg->u.buffer_from_host.buffer_header.length == 0) {
  15902. + /* empty buffer */
  15903. + if (msg->u.buffer_from_host.buffer_header.flags &
  15904. + MMAL_BUFFER_HEADER_FLAG_EOS) {
  15905. + msg_context->u.bulk.status =
  15906. + dummy_bulk_receive(instance, msg_context);
  15907. + if (msg_context->u.bulk.status == 0)
  15908. + return; /* successful bulk submission, bulk
  15909. + * completion will trigger callback
  15910. + */
  15911. + } else {
  15912. + /* do callback with empty buffer - not EOS though */
  15913. + msg_context->u.bulk.status = 0;
  15914. + msg_context->u.bulk.buffer_used = 0;
  15915. + }
  15916. + } else if (msg->u.buffer_from_host.payload_in_message == 0) {
  15917. + /* data is not in message, queue a bulk receive */
  15918. + msg_context->u.bulk.status =
  15919. + bulk_receive(instance, msg, msg_context);
  15920. + if (msg_context->u.bulk.status == 0)
  15921. + return; /* successful bulk submission, bulk
  15922. + * completion will trigger callback
  15923. + */
  15924. +
  15925. + /* failed to submit buffer, this will end badly */
  15926. + pr_err("error %d on bulk submission\n",
  15927. + msg_context->u.bulk.status);
  15928. +
  15929. + } else if (msg->u.buffer_from_host.payload_in_message <=
  15930. + MMAL_VC_SHORT_DATA) {
  15931. + /* data payload within message */
  15932. + msg_context->u.bulk.status = inline_receive(instance, msg,
  15933. + msg_context);
  15934. + } else {
  15935. + pr_err("message with invalid short payload\n");
  15936. +
  15937. + /* signal error */
  15938. + msg_context->u.bulk.status = -EINVAL;
  15939. + msg_context->u.bulk.buffer_used =
  15940. + msg->u.buffer_from_host.payload_in_message;
  15941. + }
  15942. +
  15943. + /* replace the buffer header */
  15944. + port_buffer_from_host(instance, msg_context->u.bulk.port);
  15945. +
  15946. + /* schedule the port callback */
  15947. + schedule_work(&msg_context->u.bulk.work);
  15948. +}
  15949. +
  15950. +static void bulk_receive_cb(struct vchiq_mmal_instance *instance,
  15951. + struct mmal_msg_context *msg_context)
  15952. +{
  15953. + /* bulk receive operation complete */
  15954. + mutex_unlock(&msg_context->u.bulk.instance->bulk_mutex);
  15955. +
  15956. + /* replace the buffer header */
  15957. + port_buffer_from_host(msg_context->u.bulk.instance,
  15958. + msg_context->u.bulk.port);
  15959. +
  15960. + msg_context->u.bulk.status = 0;
  15961. +
  15962. + /* schedule the port callback */
  15963. + schedule_work(&msg_context->u.bulk.work);
  15964. +}
  15965. +
  15966. +static void bulk_abort_cb(struct vchiq_mmal_instance *instance,
  15967. + struct mmal_msg_context *msg_context)
  15968. +{
  15969. + pr_err("%s: bulk ABORTED msg_context:%p\n", __func__, msg_context);
  15970. +
  15971. + /* bulk receive operation complete */
  15972. + mutex_unlock(&msg_context->u.bulk.instance->bulk_mutex);
  15973. +
  15974. + /* replace the buffer header */
  15975. + port_buffer_from_host(msg_context->u.bulk.instance,
  15976. + msg_context->u.bulk.port);
  15977. +
  15978. + msg_context->u.bulk.status = -EINTR;
  15979. +
  15980. + schedule_work(&msg_context->u.bulk.work);
  15981. +}
  15982. +
  15983. +/* incoming event service callback */
  15984. +static void service_callback(void *param,
  15985. + const VCHI_CALLBACK_REASON_T reason,
  15986. + void *bulk_ctx)
  15987. +{
  15988. + struct vchiq_mmal_instance *instance = param;
  15989. + int status;
  15990. + u32 msg_len;
  15991. + struct mmal_msg *msg;
  15992. + VCHI_HELD_MSG_T msg_handle;
  15993. +
  15994. + if (!instance) {
  15995. + pr_err("Message callback passed NULL instance\n");
  15996. + return;
  15997. + }
  15998. +
  15999. + switch (reason) {
  16000. + case VCHI_CALLBACK_MSG_AVAILABLE:
  16001. + status = vchi_msg_hold(instance->handle, (void **)&msg,
  16002. + &msg_len, VCHI_FLAGS_NONE, &msg_handle);
  16003. + if (status) {
  16004. + pr_err("Unable to dequeue a message (%d)\n", status);
  16005. + break;
  16006. + }
  16007. +
  16008. + DBG_DUMP_MSG(msg, msg_len, "<<< reply message");
  16009. +
  16010. + /* handling is different for buffer messages */
  16011. + switch (msg->h.type) {
  16012. +
  16013. + case MMAL_MSG_TYPE_BUFFER_FROM_HOST:
  16014. + vchi_held_msg_release(&msg_handle);
  16015. + break;
  16016. +
  16017. + case MMAL_MSG_TYPE_EVENT_TO_HOST:
  16018. + event_to_host_cb(instance, msg, msg_len);
  16019. + vchi_held_msg_release(&msg_handle);
  16020. +
  16021. + break;
  16022. +
  16023. + case MMAL_MSG_TYPE_BUFFER_TO_HOST:
  16024. + buffer_to_host_cb(instance, msg, msg_len);
  16025. + vchi_held_msg_release(&msg_handle);
  16026. + break;
  16027. +
  16028. + default:
  16029. + /* messages dependant on header context to complete */
  16030. +
  16031. + /* todo: the msg.context really ought to be sanity
  16032. + * checked before we just use it, afaict it comes back
  16033. + * and is used raw from the videocore. Perhaps it
  16034. + * should be verified the address lies in the kernel
  16035. + * address space.
  16036. + */
  16037. + if (msg->h.context == NULL) {
  16038. + pr_err("received message context was null!\n");
  16039. + vchi_held_msg_release(&msg_handle);
  16040. + break;
  16041. + }
  16042. +
  16043. + /* fill in context values */
  16044. + msg->h.context->u.sync.msg_handle = msg_handle;
  16045. + msg->h.context->u.sync.msg = msg;
  16046. + msg->h.context->u.sync.msg_len = msg_len;
  16047. +
  16048. + /* todo: should this check (completion_done()
  16049. + * == 1) for no one waiting? or do we need a
  16050. + * flag to tell us the completion has been
  16051. + * interrupted so we can free the message and
  16052. + * its context. This probably also solves the
  16053. + * message arriving after interruption todo
  16054. + * below
  16055. + */
  16056. +
  16057. + /* complete message so caller knows it happened */
  16058. + complete(&msg->h.context->u.sync.cmplt);
  16059. + break;
  16060. + }
  16061. +
  16062. + break;
  16063. +
  16064. + case VCHI_CALLBACK_BULK_RECEIVED:
  16065. + bulk_receive_cb(instance, bulk_ctx);
  16066. + break;
  16067. +
  16068. + case VCHI_CALLBACK_BULK_RECEIVE_ABORTED:
  16069. + bulk_abort_cb(instance, bulk_ctx);
  16070. + break;
  16071. +
  16072. + case VCHI_CALLBACK_SERVICE_CLOSED:
  16073. + /* TODO: consider if this requires action if received when
  16074. + * driver is not explicitly closing the service
  16075. + */
  16076. + break;
  16077. +
  16078. + default:
  16079. + pr_err("Received unhandled message reason %d\n", reason);
  16080. + break;
  16081. + }
  16082. +}
  16083. +
  16084. +static int send_synchronous_mmal_msg(struct vchiq_mmal_instance *instance,
  16085. + struct mmal_msg *msg,
  16086. + unsigned int payload_len,
  16087. + struct mmal_msg **msg_out,
  16088. + VCHI_HELD_MSG_T *msg_handle_out)
  16089. +{
  16090. + struct mmal_msg_context msg_context;
  16091. + int ret;
  16092. +
  16093. + /* payload size must not cause message to exceed max size */
  16094. + if (payload_len >
  16095. + (MMAL_MSG_MAX_SIZE - sizeof(struct mmal_msg_header))) {
  16096. + pr_err("payload length %d exceeds max:%d\n", payload_len,
  16097. + (MMAL_MSG_MAX_SIZE - sizeof(struct mmal_msg_header)));
  16098. + return -EINVAL;
  16099. + }
  16100. +
  16101. + init_completion(&msg_context.u.sync.cmplt);
  16102. +
  16103. + msg->h.magic = MMAL_MAGIC;
  16104. + msg->h.context = &msg_context;
  16105. + msg->h.status = 0;
  16106. +
  16107. + DBG_DUMP_MSG(msg, (sizeof(struct mmal_msg_header) + payload_len),
  16108. + ">>> sync message");
  16109. +
  16110. + vchi_service_use(instance->handle);
  16111. +
  16112. + ret = vchi_msg_queue(instance->handle,
  16113. + msg,
  16114. + sizeof(struct mmal_msg_header) + payload_len,
  16115. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  16116. +
  16117. + vchi_service_release(instance->handle);
  16118. +
  16119. + if (ret) {
  16120. + pr_err("error %d queuing message\n", ret);
  16121. + return ret;
  16122. + }
  16123. +
  16124. + ret = wait_for_completion_timeout(&msg_context.u.sync.cmplt, HZ);
  16125. + if (ret <= 0) {
  16126. + pr_err("error %d waiting for sync completion\n", ret);
  16127. + if (ret == 0)
  16128. + ret = -ETIME;
  16129. + /* todo: what happens if the message arrives after aborting */
  16130. + return ret;
  16131. + }
  16132. +
  16133. + *msg_out = msg_context.u.sync.msg;
  16134. + *msg_handle_out = msg_context.u.sync.msg_handle;
  16135. +
  16136. + return 0;
  16137. +}
  16138. +
  16139. +static void dump_port_info(struct vchiq_mmal_port *port)
  16140. +{
  16141. + pr_debug("port handle:0x%x enabled:%d\n", port->handle, port->enabled);
  16142. +
  16143. + pr_debug("buffer minimum num:%d size:%d align:%d\n",
  16144. + port->minimum_buffer.num,
  16145. + port->minimum_buffer.size, port->minimum_buffer.alignment);
  16146. +
  16147. + pr_debug("buffer recommended num:%d size:%d align:%d\n",
  16148. + port->recommended_buffer.num,
  16149. + port->recommended_buffer.size,
  16150. + port->recommended_buffer.alignment);
  16151. +
  16152. + pr_debug("buffer current values num:%d size:%d align:%d\n",
  16153. + port->current_buffer.num,
  16154. + port->current_buffer.size, port->current_buffer.alignment);
  16155. +
  16156. + pr_debug("elementry stream: type:%d encoding:0x%x varient:0x%x\n",
  16157. + port->format.type,
  16158. + port->format.encoding, port->format.encoding_variant);
  16159. +
  16160. + pr_debug(" bitrate:%d flags:0x%x\n",
  16161. + port->format.bitrate, port->format.flags);
  16162. +
  16163. + if (port->format.type == MMAL_ES_TYPE_VIDEO) {
  16164. + pr_debug
  16165. + ("es video format: width:%d height:%d colourspace:0x%x\n",
  16166. + port->es.video.width, port->es.video.height,
  16167. + port->es.video.color_space);
  16168. +
  16169. + pr_debug(" : crop xywh %d,%d,%d,%d\n",
  16170. + port->es.video.crop.x,
  16171. + port->es.video.crop.y,
  16172. + port->es.video.crop.width, port->es.video.crop.height);
  16173. + pr_debug(" : framerate %d/%d aspect %d/%d\n",
  16174. + port->es.video.frame_rate.num,
  16175. + port->es.video.frame_rate.den,
  16176. + port->es.video.par.num, port->es.video.par.den);
  16177. + }
  16178. +}
  16179. +
  16180. +static void port_to_mmal_msg(struct vchiq_mmal_port *port, struct mmal_port *p)
  16181. +{
  16182. +
  16183. + /* todo do readonly fields need setting at all? */
  16184. + p->type = port->type;
  16185. + p->index = port->index;
  16186. + p->index_all = 0;
  16187. + p->is_enabled = port->enabled;
  16188. + p->buffer_num_min = port->minimum_buffer.num;
  16189. + p->buffer_size_min = port->minimum_buffer.size;
  16190. + p->buffer_alignment_min = port->minimum_buffer.alignment;
  16191. + p->buffer_num_recommended = port->recommended_buffer.num;
  16192. + p->buffer_size_recommended = port->recommended_buffer.size;
  16193. +
  16194. + /* only three writable fields in a port */
  16195. + p->buffer_num = port->current_buffer.num;
  16196. + p->buffer_size = port->current_buffer.size;
  16197. + p->userdata = port;
  16198. +}
  16199. +
  16200. +static int port_info_set(struct vchiq_mmal_instance *instance,
  16201. + struct vchiq_mmal_port *port)
  16202. +{
  16203. + int ret;
  16204. + struct mmal_msg m;
  16205. + struct mmal_msg *rmsg;
  16206. + VCHI_HELD_MSG_T rmsg_handle;
  16207. +
  16208. + pr_debug("setting port info port %p\n", port);
  16209. + if (!port)
  16210. + return -1;
  16211. + dump_port_info(port);
  16212. +
  16213. + m.h.type = MMAL_MSG_TYPE_PORT_INFO_SET;
  16214. +
  16215. + m.u.port_info_set.component_handle = port->component->handle;
  16216. + m.u.port_info_set.port_type = port->type;
  16217. + m.u.port_info_set.port_index = port->index;
  16218. +
  16219. + port_to_mmal_msg(port, &m.u.port_info_set.port);
  16220. +
  16221. + /* elementry stream format setup */
  16222. + m.u.port_info_set.format.type = port->format.type;
  16223. + m.u.port_info_set.format.encoding = port->format.encoding;
  16224. + m.u.port_info_set.format.encoding_variant =
  16225. + port->format.encoding_variant;
  16226. + m.u.port_info_set.format.bitrate = port->format.bitrate;
  16227. + m.u.port_info_set.format.flags = port->format.flags;
  16228. +
  16229. + memcpy(&m.u.port_info_set.es, &port->es,
  16230. + sizeof(union mmal_es_specific_format));
  16231. +
  16232. + m.u.port_info_set.format.extradata_size = port->format.extradata_size;
  16233. + memcpy(rmsg->u.port_info_set.extradata, port->format.extradata,
  16234. + port->format.extradata_size);
  16235. +
  16236. + ret = send_synchronous_mmal_msg(instance, &m,
  16237. + sizeof(m.u.port_info_set),
  16238. + &rmsg, &rmsg_handle);
  16239. + if (ret)
  16240. + return ret;
  16241. +
  16242. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_INFO_SET) {
  16243. + /* got an unexpected message type in reply */
  16244. + ret = -EINVAL;
  16245. + goto release_msg;
  16246. + }
  16247. +
  16248. + /* return operation status */
  16249. + ret = -rmsg->u.port_info_get_reply.status;
  16250. +
  16251. + pr_debug("%s:result:%d component:0x%x port:%d\n", __func__, ret,
  16252. + port->component->handle, port->handle);
  16253. +
  16254. +release_msg:
  16255. + vchi_held_msg_release(&rmsg_handle);
  16256. +
  16257. + return ret;
  16258. +
  16259. +}
  16260. +
  16261. +/* use port info get message to retrive port information */
  16262. +static int port_info_get(struct vchiq_mmal_instance *instance,
  16263. + struct vchiq_mmal_port *port)
  16264. +{
  16265. + int ret;
  16266. + struct mmal_msg m;
  16267. + struct mmal_msg *rmsg;
  16268. + VCHI_HELD_MSG_T rmsg_handle;
  16269. +
  16270. + /* port info time */
  16271. + m.h.type = MMAL_MSG_TYPE_PORT_INFO_GET;
  16272. + m.u.port_info_get.component_handle = port->component->handle;
  16273. + m.u.port_info_get.port_type = port->type;
  16274. + m.u.port_info_get.index = port->index;
  16275. +
  16276. + ret = send_synchronous_mmal_msg(instance, &m,
  16277. + sizeof(m.u.port_info_get),
  16278. + &rmsg, &rmsg_handle);
  16279. + if (ret)
  16280. + return ret;
  16281. +
  16282. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_INFO_GET) {
  16283. + /* got an unexpected message type in reply */
  16284. + ret = -EINVAL;
  16285. + goto release_msg;
  16286. + }
  16287. +
  16288. + /* return operation status */
  16289. + ret = -rmsg->u.port_info_get_reply.status;
  16290. + if (ret != MMAL_MSG_STATUS_SUCCESS)
  16291. + goto release_msg;
  16292. +
  16293. + if (rmsg->u.port_info_get_reply.port.is_enabled == 0)
  16294. + port->enabled = false;
  16295. + else
  16296. + port->enabled = true;
  16297. +
  16298. + /* copy the values out of the message */
  16299. + port->handle = rmsg->u.port_info_get_reply.port_handle;
  16300. +
  16301. + /* port type and index cached to use on port info set becuase
  16302. + * it does not use a port handle
  16303. + */
  16304. + port->type = rmsg->u.port_info_get_reply.port_type;
  16305. + port->index = rmsg->u.port_info_get_reply.port_index;
  16306. +
  16307. + port->minimum_buffer.num =
  16308. + rmsg->u.port_info_get_reply.port.buffer_num_min;
  16309. + port->minimum_buffer.size =
  16310. + rmsg->u.port_info_get_reply.port.buffer_size_min;
  16311. + port->minimum_buffer.alignment =
  16312. + rmsg->u.port_info_get_reply.port.buffer_alignment_min;
  16313. +
  16314. + port->recommended_buffer.alignment =
  16315. + rmsg->u.port_info_get_reply.port.buffer_alignment_min;
  16316. + port->recommended_buffer.num =
  16317. + rmsg->u.port_info_get_reply.port.buffer_num_recommended;
  16318. +
  16319. + port->current_buffer.num = rmsg->u.port_info_get_reply.port.buffer_num;
  16320. + port->current_buffer.size =
  16321. + rmsg->u.port_info_get_reply.port.buffer_size;
  16322. +
  16323. + /* stream format */
  16324. + port->format.type = rmsg->u.port_info_get_reply.format.type;
  16325. + port->format.encoding = rmsg->u.port_info_get_reply.format.encoding;
  16326. + port->format.encoding_variant =
  16327. + rmsg->u.port_info_get_reply.format.encoding_variant;
  16328. + port->format.bitrate = rmsg->u.port_info_get_reply.format.bitrate;
  16329. + port->format.flags = rmsg->u.port_info_get_reply.format.flags;
  16330. +
  16331. + /* elementry stream format */
  16332. + memcpy(&port->es,
  16333. + &rmsg->u.port_info_get_reply.es,
  16334. + sizeof(union mmal_es_specific_format));
  16335. + port->format.es = &port->es;
  16336. +
  16337. + port->format.extradata_size =
  16338. + rmsg->u.port_info_get_reply.format.extradata_size;
  16339. + memcpy(port->format.extradata,
  16340. + rmsg->u.port_info_get_reply.extradata,
  16341. + port->format.extradata_size);
  16342. +
  16343. + pr_debug("received port info\n");
  16344. + dump_port_info(port);
  16345. +
  16346. +release_msg:
  16347. +
  16348. + pr_debug("%s:result:%d component:0x%x port:%d\n",
  16349. + __func__, ret, port->component->handle, port->handle);
  16350. +
  16351. + vchi_held_msg_release(&rmsg_handle);
  16352. +
  16353. + return ret;
  16354. +}
  16355. +
  16356. +/* create comonent on vc */
  16357. +static int create_component(struct vchiq_mmal_instance *instance,
  16358. + struct vchiq_mmal_component *component,
  16359. + const char *name)
  16360. +{
  16361. + int ret;
  16362. + struct mmal_msg m;
  16363. + struct mmal_msg *rmsg;
  16364. + VCHI_HELD_MSG_T rmsg_handle;
  16365. +
  16366. + /* build component create message */
  16367. + m.h.type = MMAL_MSG_TYPE_COMPONENT_CREATE;
  16368. + m.u.component_create.client_component = component;
  16369. + strncpy(m.u.component_create.name, name,
  16370. + sizeof(m.u.component_create.name));
  16371. +
  16372. + ret = send_synchronous_mmal_msg(instance, &m,
  16373. + sizeof(m.u.component_create),
  16374. + &rmsg, &rmsg_handle);
  16375. + if (ret)
  16376. + return ret;
  16377. +
  16378. + if (rmsg->h.type != m.h.type) {
  16379. + /* got an unexpected message type in reply */
  16380. + ret = -EINVAL;
  16381. + goto release_msg;
  16382. + }
  16383. +
  16384. + ret = -rmsg->u.component_create_reply.status;
  16385. + if (ret != MMAL_MSG_STATUS_SUCCESS)
  16386. + goto release_msg;
  16387. +
  16388. + /* a valid component response received */
  16389. + component->handle = rmsg->u.component_create_reply.component_handle;
  16390. + component->inputs = rmsg->u.component_create_reply.input_num;
  16391. + component->outputs = rmsg->u.component_create_reply.output_num;
  16392. + component->clocks = rmsg->u.component_create_reply.clock_num;
  16393. +
  16394. + pr_debug("Component handle:0x%x in:%d out:%d clock:%d\n",
  16395. + component->handle,
  16396. + component->inputs, component->outputs, component->clocks);
  16397. +
  16398. +release_msg:
  16399. + vchi_held_msg_release(&rmsg_handle);
  16400. +
  16401. + return ret;
  16402. +}
  16403. +
  16404. +/* destroys a component on vc */
  16405. +static int destroy_component(struct vchiq_mmal_instance *instance,
  16406. + struct vchiq_mmal_component *component)
  16407. +{
  16408. + int ret;
  16409. + struct mmal_msg m;
  16410. + struct mmal_msg *rmsg;
  16411. + VCHI_HELD_MSG_T rmsg_handle;
  16412. +
  16413. + m.h.type = MMAL_MSG_TYPE_COMPONENT_DESTROY;
  16414. + m.u.component_destroy.component_handle = component->handle;
  16415. +
  16416. + ret = send_synchronous_mmal_msg(instance, &m,
  16417. + sizeof(m.u.component_destroy),
  16418. + &rmsg, &rmsg_handle);
  16419. + if (ret)
  16420. + return ret;
  16421. +
  16422. + if (rmsg->h.type != m.h.type) {
  16423. + /* got an unexpected message type in reply */
  16424. + ret = -EINVAL;
  16425. + goto release_msg;
  16426. + }
  16427. +
  16428. + ret = -rmsg->u.component_destroy_reply.status;
  16429. +
  16430. +release_msg:
  16431. +
  16432. + vchi_held_msg_release(&rmsg_handle);
  16433. +
  16434. + return ret;
  16435. +}
  16436. +
  16437. +/* enable a component on vc */
  16438. +static int enable_component(struct vchiq_mmal_instance *instance,
  16439. + struct vchiq_mmal_component *component)
  16440. +{
  16441. + int ret;
  16442. + struct mmal_msg m;
  16443. + struct mmal_msg *rmsg;
  16444. + VCHI_HELD_MSG_T rmsg_handle;
  16445. +
  16446. + m.h.type = MMAL_MSG_TYPE_COMPONENT_ENABLE;
  16447. + m.u.component_enable.component_handle = component->handle;
  16448. +
  16449. + ret = send_synchronous_mmal_msg(instance, &m,
  16450. + sizeof(m.u.component_enable),
  16451. + &rmsg, &rmsg_handle);
  16452. + if (ret)
  16453. + return ret;
  16454. +
  16455. + if (rmsg->h.type != m.h.type) {
  16456. + /* got an unexpected message type in reply */
  16457. + ret = -EINVAL;
  16458. + goto release_msg;
  16459. + }
  16460. +
  16461. + ret = -rmsg->u.component_enable_reply.status;
  16462. +
  16463. +release_msg:
  16464. + vchi_held_msg_release(&rmsg_handle);
  16465. +
  16466. + return ret;
  16467. +}
  16468. +
  16469. +/* disable a component on vc */
  16470. +static int disable_component(struct vchiq_mmal_instance *instance,
  16471. + struct vchiq_mmal_component *component)
  16472. +{
  16473. + int ret;
  16474. + struct mmal_msg m;
  16475. + struct mmal_msg *rmsg;
  16476. + VCHI_HELD_MSG_T rmsg_handle;
  16477. +
  16478. + m.h.type = MMAL_MSG_TYPE_COMPONENT_DISABLE;
  16479. + m.u.component_disable.component_handle = component->handle;
  16480. +
  16481. + ret = send_synchronous_mmal_msg(instance, &m,
  16482. + sizeof(m.u.component_disable),
  16483. + &rmsg, &rmsg_handle);
  16484. + if (ret)
  16485. + return ret;
  16486. +
  16487. + if (rmsg->h.type != m.h.type) {
  16488. + /* got an unexpected message type in reply */
  16489. + ret = -EINVAL;
  16490. + goto release_msg;
  16491. + }
  16492. +
  16493. + ret = -rmsg->u.component_disable_reply.status;
  16494. +
  16495. +release_msg:
  16496. +
  16497. + vchi_held_msg_release(&rmsg_handle);
  16498. +
  16499. + return ret;
  16500. +}
  16501. +
  16502. +/* get version of mmal implementation */
  16503. +static int get_version(struct vchiq_mmal_instance *instance,
  16504. + u32 *major_out, u32 *minor_out)
  16505. +{
  16506. + int ret;
  16507. + struct mmal_msg m;
  16508. + struct mmal_msg *rmsg;
  16509. + VCHI_HELD_MSG_T rmsg_handle;
  16510. +
  16511. + m.h.type = MMAL_MSG_TYPE_GET_VERSION;
  16512. +
  16513. + ret = send_synchronous_mmal_msg(instance, &m,
  16514. + sizeof(m.u.version),
  16515. + &rmsg, &rmsg_handle);
  16516. + if (ret)
  16517. + return ret;
  16518. +
  16519. + if (rmsg->h.type != m.h.type) {
  16520. + /* got an unexpected message type in reply */
  16521. + ret = -EINVAL;
  16522. + goto release_msg;
  16523. + }
  16524. +
  16525. + *major_out = rmsg->u.version.major;
  16526. + *minor_out = rmsg->u.version.minor;
  16527. +
  16528. +release_msg:
  16529. + vchi_held_msg_release(&rmsg_handle);
  16530. +
  16531. + return ret;
  16532. +}
  16533. +
  16534. +/* do a port action with a port as a parameter */
  16535. +static int port_action_port(struct vchiq_mmal_instance *instance,
  16536. + struct vchiq_mmal_port *port,
  16537. + enum mmal_msg_port_action_type action_type)
  16538. +{
  16539. + int ret;
  16540. + struct mmal_msg m;
  16541. + struct mmal_msg *rmsg;
  16542. + VCHI_HELD_MSG_T rmsg_handle;
  16543. +
  16544. + m.h.type = MMAL_MSG_TYPE_PORT_ACTION;
  16545. + m.u.port_action_port.component_handle = port->component->handle;
  16546. + m.u.port_action_port.port_handle = port->handle;
  16547. + m.u.port_action_port.action = action_type;
  16548. +
  16549. + port_to_mmal_msg(port, &m.u.port_action_port.port);
  16550. +
  16551. + ret = send_synchronous_mmal_msg(instance, &m,
  16552. + sizeof(m.u.port_action_port),
  16553. + &rmsg, &rmsg_handle);
  16554. + if (ret)
  16555. + return ret;
  16556. +
  16557. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_ACTION) {
  16558. + /* got an unexpected message type in reply */
  16559. + ret = -EINVAL;
  16560. + goto release_msg;
  16561. + }
  16562. +
  16563. + ret = -rmsg->u.port_action_reply.status;
  16564. +
  16565. + pr_debug("%s:result:%d component:0x%x port:%d action:%s(%d)\n",
  16566. + __func__,
  16567. + ret, port->component->handle, port->handle,
  16568. + port_action_type_names[action_type], action_type);
  16569. +
  16570. +release_msg:
  16571. + vchi_held_msg_release(&rmsg_handle);
  16572. +
  16573. + return ret;
  16574. +}
  16575. +
  16576. +/* do a port action with handles as parameters */
  16577. +static int port_action_handle(struct vchiq_mmal_instance *instance,
  16578. + struct vchiq_mmal_port *port,
  16579. + enum mmal_msg_port_action_type action_type,
  16580. + u32 connect_component_handle,
  16581. + u32 connect_port_handle)
  16582. +{
  16583. + int ret;
  16584. + struct mmal_msg m;
  16585. + struct mmal_msg *rmsg;
  16586. + VCHI_HELD_MSG_T rmsg_handle;
  16587. +
  16588. + m.h.type = MMAL_MSG_TYPE_PORT_ACTION;
  16589. +
  16590. + m.u.port_action_handle.component_handle = port->component->handle;
  16591. + m.u.port_action_handle.port_handle = port->handle;
  16592. + m.u.port_action_handle.action = action_type;
  16593. +
  16594. + m.u.port_action_handle.connect_component_handle =
  16595. + connect_component_handle;
  16596. + m.u.port_action_handle.connect_port_handle = connect_port_handle;
  16597. +
  16598. + ret = send_synchronous_mmal_msg(instance, &m,
  16599. + sizeof(m.u.port_action_handle),
  16600. + &rmsg, &rmsg_handle);
  16601. + if (ret)
  16602. + return ret;
  16603. +
  16604. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_ACTION) {
  16605. + /* got an unexpected message type in reply */
  16606. + ret = -EINVAL;
  16607. + goto release_msg;
  16608. + }
  16609. +
  16610. + ret = -rmsg->u.port_action_reply.status;
  16611. +
  16612. + pr_debug("%s:result:%d component:0x%x port:%d action:%s(%d)" \
  16613. + " connect component:0x%x connect port:%d\n",
  16614. + __func__,
  16615. + ret, port->component->handle, port->handle,
  16616. + port_action_type_names[action_type],
  16617. + action_type, connect_component_handle, connect_port_handle);
  16618. +
  16619. +release_msg:
  16620. + vchi_held_msg_release(&rmsg_handle);
  16621. +
  16622. + return ret;
  16623. +}
  16624. +
  16625. +static int port_parameter_set(struct vchiq_mmal_instance *instance,
  16626. + struct vchiq_mmal_port *port,
  16627. + u32 parameter_id, void *value, u32 value_size)
  16628. +{
  16629. + int ret;
  16630. + struct mmal_msg m;
  16631. + struct mmal_msg *rmsg;
  16632. + VCHI_HELD_MSG_T rmsg_handle;
  16633. +
  16634. + m.h.type = MMAL_MSG_TYPE_PORT_PARAMETER_SET;
  16635. +
  16636. + m.u.port_parameter_set.component_handle = port->component->handle;
  16637. + m.u.port_parameter_set.port_handle = port->handle;
  16638. + m.u.port_parameter_set.id = parameter_id;
  16639. + m.u.port_parameter_set.size = (2 * sizeof(u32)) + value_size;
  16640. + memcpy(&m.u.port_parameter_set.value, value, value_size);
  16641. +
  16642. + ret = send_synchronous_mmal_msg(instance, &m,
  16643. + (4 * sizeof(u32)) + value_size,
  16644. + &rmsg, &rmsg_handle);
  16645. + if (ret)
  16646. + return ret;
  16647. +
  16648. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_PARAMETER_SET) {
  16649. + /* got an unexpected message type in reply */
  16650. + ret = -EINVAL;
  16651. + goto release_msg;
  16652. + }
  16653. +
  16654. + ret = -rmsg->u.port_parameter_set_reply.status;
  16655. +
  16656. + pr_debug("%s:result:%d component:0x%x port:%d parameter:%d\n",
  16657. + __func__,
  16658. + ret, port->component->handle, port->handle, parameter_id);
  16659. +
  16660. +release_msg:
  16661. + vchi_held_msg_release(&rmsg_handle);
  16662. +
  16663. + return ret;
  16664. +}
  16665. +
  16666. +static int port_parameter_get(struct vchiq_mmal_instance *instance,
  16667. + struct vchiq_mmal_port *port,
  16668. + u32 parameter_id, void *value, u32 *value_size)
  16669. +{
  16670. + int ret;
  16671. + struct mmal_msg m;
  16672. + struct mmal_msg *rmsg;
  16673. + VCHI_HELD_MSG_T rmsg_handle;
  16674. +
  16675. + m.h.type = MMAL_MSG_TYPE_PORT_PARAMETER_GET;
  16676. +
  16677. + m.u.port_parameter_get.component_handle = port->component->handle;
  16678. + m.u.port_parameter_get.port_handle = port->handle;
  16679. + m.u.port_parameter_get.id = parameter_id;
  16680. + m.u.port_parameter_get.size = (2 * sizeof(u32)) + *value_size;
  16681. +
  16682. + ret = send_synchronous_mmal_msg(instance, &m,
  16683. + sizeof(struct
  16684. + mmal_msg_port_parameter_get),
  16685. + &rmsg, &rmsg_handle);
  16686. + if (ret)
  16687. + return ret;
  16688. +
  16689. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_PARAMETER_GET) {
  16690. + /* got an unexpected message type in reply */
  16691. + pr_err("Incorrect reply type %d\n", rmsg->h.type);
  16692. + ret = -EINVAL;
  16693. + goto release_msg;
  16694. + }
  16695. +
  16696. + ret = -rmsg->u.port_parameter_get_reply.status;
  16697. + if (ret) {
  16698. + /* Copy only as much as we have space for
  16699. + * but report true size of parameter
  16700. + */
  16701. + memcpy(value, &rmsg->u.port_parameter_get_reply.value,
  16702. + *value_size);
  16703. + *value_size = rmsg->u.port_parameter_get_reply.size;
  16704. + } else
  16705. + memcpy(value, &rmsg->u.port_parameter_get_reply.value,
  16706. + rmsg->u.port_parameter_get_reply.size);
  16707. +
  16708. + pr_debug("%s:result:%d component:0x%x port:%d parameter:%d\n", __func__,
  16709. + ret, port->component->handle, port->handle, parameter_id);
  16710. +
  16711. +release_msg:
  16712. + vchi_held_msg_release(&rmsg_handle);
  16713. +
  16714. + return ret;
  16715. +}
  16716. +
  16717. +/* disables a port and drains buffers from it */
  16718. +static int port_disable(struct vchiq_mmal_instance *instance,
  16719. + struct vchiq_mmal_port *port)
  16720. +{
  16721. + int ret;
  16722. + struct list_head *q, *buf_head;
  16723. + unsigned long flags = 0;
  16724. +
  16725. + if (!port->enabled)
  16726. + return 0;
  16727. +
  16728. + port->enabled = false;
  16729. +
  16730. + ret = port_action_port(instance, port,
  16731. + MMAL_MSG_PORT_ACTION_TYPE_DISABLE);
  16732. + if (ret == 0) {
  16733. +
  16734. + /* drain all queued buffers on port */
  16735. + spin_lock_irqsave(&port->slock, flags);
  16736. +
  16737. + list_for_each_safe(buf_head, q, &port->buffers) {
  16738. + struct mmal_buffer *mmalbuf;
  16739. + mmalbuf = list_entry(buf_head, struct mmal_buffer,
  16740. + list);
  16741. + list_del(buf_head);
  16742. + if (port->buffer_cb)
  16743. + port->buffer_cb(instance,
  16744. + port, 0, mmalbuf, 0, 0,
  16745. + MMAL_TIME_UNKNOWN,
  16746. + MMAL_TIME_UNKNOWN);
  16747. + }
  16748. +
  16749. + spin_unlock_irqrestore(&port->slock, flags);
  16750. +
  16751. + ret = port_info_get(instance, port);
  16752. + }
  16753. +
  16754. + return ret;
  16755. +}
  16756. +
  16757. +/* enable a port */
  16758. +static int port_enable(struct vchiq_mmal_instance *instance,
  16759. + struct vchiq_mmal_port *port)
  16760. +{
  16761. + unsigned int hdr_count;
  16762. + struct list_head *buf_head;
  16763. + int ret;
  16764. +
  16765. + if (port->enabled)
  16766. + return 0;
  16767. +
  16768. + /* ensure there are enough buffers queued to cover the buffer headers */
  16769. + if (port->buffer_cb != NULL) {
  16770. + hdr_count = 0;
  16771. + list_for_each(buf_head, &port->buffers) {
  16772. + hdr_count++;
  16773. + }
  16774. + if (hdr_count < port->current_buffer.num)
  16775. + return -ENOSPC;
  16776. + }
  16777. +
  16778. + ret = port_action_port(instance, port,
  16779. + MMAL_MSG_PORT_ACTION_TYPE_ENABLE);
  16780. + if (ret)
  16781. + goto done;
  16782. +
  16783. + port->enabled = true;
  16784. +
  16785. + if (port->buffer_cb) {
  16786. + /* send buffer headers to videocore */
  16787. + hdr_count = 1;
  16788. + list_for_each(buf_head, &port->buffers) {
  16789. + struct mmal_buffer *mmalbuf;
  16790. + mmalbuf = list_entry(buf_head, struct mmal_buffer,
  16791. + list);
  16792. + ret = buffer_from_host(instance, port, mmalbuf);
  16793. + if (ret)
  16794. + goto done;
  16795. +
  16796. + hdr_count++;
  16797. + if (hdr_count > port->current_buffer.num)
  16798. + break;
  16799. + }
  16800. + }
  16801. +
  16802. + ret = port_info_get(instance, port);
  16803. +
  16804. +done:
  16805. + return ret;
  16806. +}
  16807. +
  16808. +/* ------------------------------------------------------------------
  16809. + * Exported API
  16810. + *------------------------------------------------------------------*/
  16811. +
  16812. +int vchiq_mmal_port_set_format(struct vchiq_mmal_instance *instance,
  16813. + struct vchiq_mmal_port *port)
  16814. +{
  16815. + int ret;
  16816. +
  16817. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  16818. + return -EINTR;
  16819. +
  16820. + ret = port_info_set(instance, port);
  16821. + if (ret)
  16822. + goto release_unlock;
  16823. +
  16824. + /* read what has actually been set */
  16825. + ret = port_info_get(instance, port);
  16826. +
  16827. +release_unlock:
  16828. + mutex_unlock(&instance->vchiq_mutex);
  16829. +
  16830. + return ret;
  16831. +
  16832. +}
  16833. +
  16834. +int vchiq_mmal_port_parameter_set(struct vchiq_mmal_instance *instance,
  16835. + struct vchiq_mmal_port *port,
  16836. + u32 parameter, void *value, u32 value_size)
  16837. +{
  16838. + int ret;
  16839. +
  16840. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  16841. + return -EINTR;
  16842. +
  16843. + ret = port_parameter_set(instance, port, parameter, value, value_size);
  16844. +
  16845. + mutex_unlock(&instance->vchiq_mutex);
  16846. +
  16847. + return ret;
  16848. +}
  16849. +
  16850. +int vchiq_mmal_port_parameter_get(struct vchiq_mmal_instance *instance,
  16851. + struct vchiq_mmal_port *port,
  16852. + u32 parameter, void *value, u32 *value_size)
  16853. +{
  16854. + int ret;
  16855. +
  16856. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  16857. + return -EINTR;
  16858. +
  16859. + ret = port_parameter_get(instance, port, parameter, value, value_size);
  16860. +
  16861. + mutex_unlock(&instance->vchiq_mutex);
  16862. +
  16863. + return ret;
  16864. +}
  16865. +
  16866. +/* enable a port
  16867. + *
  16868. + * enables a port and queues buffers for satisfying callbacks if we
  16869. + * provide a callback handler
  16870. + */
  16871. +int vchiq_mmal_port_enable(struct vchiq_mmal_instance *instance,
  16872. + struct vchiq_mmal_port *port,
  16873. + vchiq_mmal_buffer_cb buffer_cb)
  16874. +{
  16875. + int ret;
  16876. +
  16877. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  16878. + return -EINTR;
  16879. +
  16880. + /* already enabled - noop */
  16881. + if (port->enabled) {
  16882. + ret = 0;
  16883. + goto unlock;
  16884. + }
  16885. +
  16886. + port->buffer_cb = buffer_cb;
  16887. +
  16888. + ret = port_enable(instance, port);
  16889. +
  16890. +unlock:
  16891. + mutex_unlock(&instance->vchiq_mutex);
  16892. +
  16893. + return ret;
  16894. +}
  16895. +
  16896. +int vchiq_mmal_port_disable(struct vchiq_mmal_instance *instance,
  16897. + struct vchiq_mmal_port *port)
  16898. +{
  16899. + int ret;
  16900. +
  16901. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  16902. + return -EINTR;
  16903. +
  16904. + if (!port->enabled) {
  16905. + mutex_unlock(&instance->vchiq_mutex);
  16906. + return 0;
  16907. + }
  16908. +
  16909. + ret = port_disable(instance, port);
  16910. +
  16911. + mutex_unlock(&instance->vchiq_mutex);
  16912. +
  16913. + return ret;
  16914. +}
  16915. +
  16916. +/* ports will be connected in a tunneled manner so data buffers
  16917. + * are not handled by client.
  16918. + */
  16919. +int vchiq_mmal_port_connect_tunnel(struct vchiq_mmal_instance *instance,
  16920. + struct vchiq_mmal_port *src,
  16921. + struct vchiq_mmal_port *dst)
  16922. +{
  16923. + int ret;
  16924. +
  16925. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  16926. + return -EINTR;
  16927. +
  16928. + /* disconnect ports if connected */
  16929. + if (src->connected != NULL) {
  16930. + ret = port_disable(instance, src);
  16931. + if (ret) {
  16932. + pr_err("failed disabling src port(%d)\n", ret);
  16933. + goto release_unlock;
  16934. + }
  16935. +
  16936. + /* do not need to disable the destination port as they
  16937. + * are connected and it is done automatically
  16938. + */
  16939. +
  16940. + ret = port_action_handle(instance, src,
  16941. + MMAL_MSG_PORT_ACTION_TYPE_DISCONNECT,
  16942. + src->connected->component->handle,
  16943. + src->connected->handle);
  16944. + if (ret < 0) {
  16945. + pr_err("failed disconnecting src port\n");
  16946. + goto release_unlock;
  16947. + }
  16948. + src->connected->enabled = false;
  16949. + src->connected = NULL;
  16950. + }
  16951. +
  16952. + if (dst == NULL) {
  16953. + /* do not make new connection */
  16954. + ret = 0;
  16955. + pr_debug("not making new connection\n");
  16956. + goto release_unlock;
  16957. + }
  16958. +
  16959. + /* copy src port format to dst */
  16960. + dst->format.encoding = src->format.encoding;
  16961. + dst->es.video.width = src->es.video.width;
  16962. + dst->es.video.height = src->es.video.height;
  16963. + dst->es.video.crop.x = src->es.video.crop.x;
  16964. + dst->es.video.crop.y = src->es.video.crop.y;
  16965. + dst->es.video.crop.width = src->es.video.crop.width;
  16966. + dst->es.video.crop.height = src->es.video.crop.height;
  16967. + dst->es.video.frame_rate.num = src->es.video.frame_rate.num;
  16968. + dst->es.video.frame_rate.den = src->es.video.frame_rate.den;
  16969. +
  16970. + /* set new format */
  16971. + ret = port_info_set(instance, dst);
  16972. + if (ret) {
  16973. + pr_debug("setting port info failed\n");
  16974. + goto release_unlock;
  16975. + }
  16976. +
  16977. + /* read what has actually been set */
  16978. + ret = port_info_get(instance, dst);
  16979. + if (ret) {
  16980. + pr_debug("read back port info failed\n");
  16981. + goto release_unlock;
  16982. + }
  16983. +
  16984. + /* connect two ports together */
  16985. + ret = port_action_handle(instance, src,
  16986. + MMAL_MSG_PORT_ACTION_TYPE_CONNECT,
  16987. + dst->component->handle, dst->handle);
  16988. + if (ret < 0) {
  16989. + pr_debug("connecting port %d:%d to %d:%d failed\n",
  16990. + src->component->handle, src->handle,
  16991. + dst->component->handle, dst->handle);
  16992. + goto release_unlock;
  16993. + }
  16994. + src->connected = dst;
  16995. +
  16996. +release_unlock:
  16997. +
  16998. + mutex_unlock(&instance->vchiq_mutex);
  16999. +
  17000. + return ret;
  17001. +}
  17002. +
  17003. +int vchiq_mmal_submit_buffer(struct vchiq_mmal_instance *instance,
  17004. + struct vchiq_mmal_port *port,
  17005. + struct mmal_buffer *buffer)
  17006. +{
  17007. + unsigned long flags = 0;
  17008. +
  17009. + spin_lock_irqsave(&port->slock, flags);
  17010. + list_add_tail(&buffer->list, &port->buffers);
  17011. + spin_unlock_irqrestore(&port->slock, flags);
  17012. +
  17013. + /* the port previously underflowed because it was missing a
  17014. + * mmal_buffer which has just been added, submit that buffer
  17015. + * to the mmal service.
  17016. + */
  17017. + if (port->buffer_underflow) {
  17018. + port_buffer_from_host(instance, port);
  17019. + port->buffer_underflow--;
  17020. + }
  17021. +
  17022. + return 0;
  17023. +}
  17024. +
  17025. +/* Initialise a mmal component and its ports
  17026. + *
  17027. + */
  17028. +int vchiq_mmal_component_init(struct vchiq_mmal_instance *instance,
  17029. + const char *name,
  17030. + struct vchiq_mmal_component **component_out)
  17031. +{
  17032. + int ret;
  17033. + int idx; /* port index */
  17034. + struct vchiq_mmal_component *component;
  17035. +
  17036. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  17037. + return -EINTR;
  17038. +
  17039. + if (instance->component_idx == VCHIQ_MMAL_MAX_COMPONENTS) {
  17040. + ret = -EINVAL; /* todo is this correct error? */
  17041. + goto unlock;
  17042. + }
  17043. +
  17044. + component = &instance->component[instance->component_idx];
  17045. +
  17046. + ret = create_component(instance, component, name);
  17047. + if (ret < 0)
  17048. + goto unlock;
  17049. +
  17050. + /* ports info needs gathering */
  17051. + component->control.type = MMAL_PORT_TYPE_CONTROL;
  17052. + component->control.index = 0;
  17053. + component->control.component = component;
  17054. + spin_lock_init(&component->control.slock);
  17055. + INIT_LIST_HEAD(&component->control.buffers);
  17056. + ret = port_info_get(instance, &component->control);
  17057. + if (ret < 0)
  17058. + goto release_component;
  17059. +
  17060. + for (idx = 0; idx < component->inputs; idx++) {
  17061. + component->input[idx].type = MMAL_PORT_TYPE_INPUT;
  17062. + component->input[idx].index = idx;
  17063. + component->input[idx].component = component;
  17064. + spin_lock_init(&component->input[idx].slock);
  17065. + INIT_LIST_HEAD(&component->input[idx].buffers);
  17066. + ret = port_info_get(instance, &component->input[idx]);
  17067. + if (ret < 0)
  17068. + goto release_component;
  17069. + }
  17070. +
  17071. + for (idx = 0; idx < component->outputs; idx++) {
  17072. + component->output[idx].type = MMAL_PORT_TYPE_OUTPUT;
  17073. + component->output[idx].index = idx;
  17074. + component->output[idx].component = component;
  17075. + spin_lock_init(&component->output[idx].slock);
  17076. + INIT_LIST_HEAD(&component->output[idx].buffers);
  17077. + ret = port_info_get(instance, &component->output[idx]);
  17078. + if (ret < 0)
  17079. + goto release_component;
  17080. + }
  17081. +
  17082. + for (idx = 0; idx < component->clocks; idx++) {
  17083. + component->clock[idx].type = MMAL_PORT_TYPE_CLOCK;
  17084. + component->clock[idx].index = idx;
  17085. + component->clock[idx].component = component;
  17086. + spin_lock_init(&component->clock[idx].slock);
  17087. + INIT_LIST_HEAD(&component->clock[idx].buffers);
  17088. + ret = port_info_get(instance, &component->clock[idx]);
  17089. + if (ret < 0)
  17090. + goto release_component;
  17091. + }
  17092. +
  17093. + instance->component_idx++;
  17094. +
  17095. + *component_out = component;
  17096. +
  17097. + mutex_unlock(&instance->vchiq_mutex);
  17098. +
  17099. + return 0;
  17100. +
  17101. +release_component:
  17102. + destroy_component(instance, component);
  17103. +unlock:
  17104. + mutex_unlock(&instance->vchiq_mutex);
  17105. +
  17106. + return ret;
  17107. +}
  17108. +
  17109. +/*
  17110. + * cause a mmal component to be destroyed
  17111. + */
  17112. +int vchiq_mmal_component_finalise(struct vchiq_mmal_instance *instance,
  17113. + struct vchiq_mmal_component *component)
  17114. +{
  17115. + int ret;
  17116. +
  17117. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  17118. + return -EINTR;
  17119. +
  17120. + if (component->enabled)
  17121. + ret = disable_component(instance, component);
  17122. +
  17123. + ret = destroy_component(instance, component);
  17124. +
  17125. + mutex_unlock(&instance->vchiq_mutex);
  17126. +
  17127. + return ret;
  17128. +}
  17129. +
  17130. +/*
  17131. + * cause a mmal component to be enabled
  17132. + */
  17133. +int vchiq_mmal_component_enable(struct vchiq_mmal_instance *instance,
  17134. + struct vchiq_mmal_component *component)
  17135. +{
  17136. + int ret;
  17137. +
  17138. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  17139. + return -EINTR;
  17140. +
  17141. + if (component->enabled) {
  17142. + mutex_unlock(&instance->vchiq_mutex);
  17143. + return 0;
  17144. + }
  17145. +
  17146. + ret = enable_component(instance, component);
  17147. + if (ret == 0)
  17148. + component->enabled = true;
  17149. +
  17150. + mutex_unlock(&instance->vchiq_mutex);
  17151. +
  17152. + return ret;
  17153. +}
  17154. +
  17155. +/*
  17156. + * cause a mmal component to be enabled
  17157. + */
  17158. +int vchiq_mmal_component_disable(struct vchiq_mmal_instance *instance,
  17159. + struct vchiq_mmal_component *component)
  17160. +{
  17161. + int ret;
  17162. +
  17163. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  17164. + return -EINTR;
  17165. +
  17166. + if (!component->enabled) {
  17167. + mutex_unlock(&instance->vchiq_mutex);
  17168. + return 0;
  17169. + }
  17170. +
  17171. + ret = disable_component(instance, component);
  17172. + if (ret == 0)
  17173. + component->enabled = false;
  17174. +
  17175. + mutex_unlock(&instance->vchiq_mutex);
  17176. +
  17177. + return ret;
  17178. +}
  17179. +
  17180. +int vchiq_mmal_version(struct vchiq_mmal_instance *instance,
  17181. + u32 *major_out, u32 *minor_out)
  17182. +{
  17183. + int ret;
  17184. +
  17185. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  17186. + return -EINTR;
  17187. +
  17188. + ret = get_version(instance, major_out, minor_out);
  17189. +
  17190. + mutex_unlock(&instance->vchiq_mutex);
  17191. +
  17192. + return ret;
  17193. +}
  17194. +
  17195. +int vchiq_mmal_finalise(struct vchiq_mmal_instance *instance)
  17196. +{
  17197. + int status = 0;
  17198. +
  17199. + if (instance == NULL)
  17200. + return -EINVAL;
  17201. +
  17202. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  17203. + return -EINTR;
  17204. +
  17205. + vchi_service_use(instance->handle);
  17206. +
  17207. + status = vchi_service_close(instance->handle);
  17208. + if (status != 0)
  17209. + pr_err("mmal-vchiq: VCHIQ close failed");
  17210. +
  17211. + mutex_unlock(&instance->vchiq_mutex);
  17212. +
  17213. + vfree(instance->bulk_scratch);
  17214. +
  17215. + kfree(instance);
  17216. +
  17217. + return status;
  17218. +}
  17219. +
  17220. +int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance)
  17221. +{
  17222. + int status;
  17223. + struct vchiq_mmal_instance *instance;
  17224. + static VCHI_CONNECTION_T *vchi_connection;
  17225. + static VCHI_INSTANCE_T vchi_instance;
  17226. + SERVICE_CREATION_T params = {
  17227. + VCHI_VERSION_EX(VC_MMAL_VER, VC_MMAL_MIN_VER),
  17228. + VC_MMAL_SERVER_NAME,
  17229. + vchi_connection,
  17230. + 0, /* rx fifo size (unused) */
  17231. + 0, /* tx fifo size (unused) */
  17232. + service_callback,
  17233. + NULL, /* service callback parameter */
  17234. + 1, /* unaligned bulk receives */
  17235. + 1, /* unaligned bulk transmits */
  17236. + 0 /* want crc check on bulk transfers */
  17237. + };
  17238. +
  17239. + /* compile time checks to ensure structure size as they are
  17240. + * directly (de)serialised from memory.
  17241. + */
  17242. +
  17243. + /* ensure the header structure has packed to the correct size */
  17244. + BUILD_BUG_ON(sizeof(struct mmal_msg_header) != 24);
  17245. +
  17246. + /* ensure message structure does not exceed maximum length */
  17247. + BUILD_BUG_ON(sizeof(struct mmal_msg) > MMAL_MSG_MAX_SIZE);
  17248. +
  17249. + /* mmal port struct is correct size */
  17250. + BUILD_BUG_ON(sizeof(struct mmal_port) != 64);
  17251. +
  17252. + /* create a vchi instance */
  17253. + status = vchi_initialise(&vchi_instance);
  17254. + if (status) {
  17255. + pr_err("Failed to initialise VCHI instance (status=%d)\n",
  17256. + status);
  17257. + return -EIO;
  17258. + }
  17259. +
  17260. + status = vchi_connect(NULL, 0, vchi_instance);
  17261. + if (status) {
  17262. + pr_err("Failed to connect VCHI instance (status=%d)\n", status);
  17263. + return -EIO;
  17264. + }
  17265. +
  17266. + instance = kmalloc(sizeof(*instance), GFP_KERNEL);
  17267. + memset(instance, 0, sizeof(*instance));
  17268. +
  17269. + mutex_init(&instance->vchiq_mutex);
  17270. + mutex_init(&instance->bulk_mutex);
  17271. +
  17272. + instance->bulk_scratch = vmalloc(PAGE_SIZE);
  17273. +
  17274. + params.callback_param = instance;
  17275. +
  17276. + status = vchi_service_open(vchi_instance, &params, &instance->handle);
  17277. + if (status) {
  17278. + pr_err("Failed to open VCHI service connection (status=%d)\n",
  17279. + status);
  17280. + goto err_close_services;
  17281. + }
  17282. +
  17283. + vchi_service_release(instance->handle);
  17284. +
  17285. + *out_instance = instance;
  17286. +
  17287. + return 0;
  17288. +
  17289. +err_close_services:
  17290. +
  17291. + vchi_service_close(instance->handle);
  17292. + vfree(instance->bulk_scratch);
  17293. + kfree(instance);
  17294. + return -ENODEV;
  17295. +}
  17296. diff -Nur linux-3.13.11/drivers/media/platform/bcm2835/mmal-vchiq.h linux-rpi/drivers/media/platform/bcm2835/mmal-vchiq.h
  17297. --- linux-3.13.11/drivers/media/platform/bcm2835/mmal-vchiq.h 1970-01-01 01:00:00.000000000 +0100
  17298. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-vchiq.h 2014-04-24 15:35:02.713549510 +0200
  17299. @@ -0,0 +1,178 @@
  17300. +/*
  17301. + * Broadcom BM2835 V4L2 driver
  17302. + *
  17303. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  17304. + *
  17305. + * This file is subject to the terms and conditions of the GNU General Public
  17306. + * License. See the file COPYING in the main directory of this archive
  17307. + * for more details.
  17308. + *
  17309. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  17310. + * Dave Stevenson <dsteve@broadcom.com>
  17311. + * Simon Mellor <simellor@broadcom.com>
  17312. + * Luke Diamand <luked@broadcom.com>
  17313. + *
  17314. + * MMAL interface to VCHIQ message passing
  17315. + */
  17316. +
  17317. +#ifndef MMAL_VCHIQ_H
  17318. +#define MMAL_VCHIQ_H
  17319. +
  17320. +#include "mmal-msg-format.h"
  17321. +
  17322. +#define MAX_PORT_COUNT 4
  17323. +
  17324. +/* Maximum size of the format extradata. */
  17325. +#define MMAL_FORMAT_EXTRADATA_MAX_SIZE 128
  17326. +
  17327. +struct vchiq_mmal_instance;
  17328. +
  17329. +enum vchiq_mmal_es_type {
  17330. + MMAL_ES_TYPE_UNKNOWN, /**< Unknown elementary stream type */
  17331. + MMAL_ES_TYPE_CONTROL, /**< Elementary stream of control commands */
  17332. + MMAL_ES_TYPE_AUDIO, /**< Audio elementary stream */
  17333. + MMAL_ES_TYPE_VIDEO, /**< Video elementary stream */
  17334. + MMAL_ES_TYPE_SUBPICTURE /**< Sub-picture elementary stream */
  17335. +};
  17336. +
  17337. +/* rectangle, used lots so it gets its own struct */
  17338. +struct vchiq_mmal_rect {
  17339. + s32 x;
  17340. + s32 y;
  17341. + s32 width;
  17342. + s32 height;
  17343. +};
  17344. +
  17345. +struct vchiq_mmal_port_buffer {
  17346. + unsigned int num; /* number of buffers */
  17347. + u32 size; /* size of buffers */
  17348. + u32 alignment; /* alignment of buffers */
  17349. +};
  17350. +
  17351. +struct vchiq_mmal_port;
  17352. +
  17353. +typedef void (*vchiq_mmal_buffer_cb)(
  17354. + struct vchiq_mmal_instance *instance,
  17355. + struct vchiq_mmal_port *port,
  17356. + int status, struct mmal_buffer *buffer,
  17357. + unsigned long length, u32 mmal_flags, s64 dts, s64 pts);
  17358. +
  17359. +struct vchiq_mmal_port {
  17360. + bool enabled;
  17361. + u32 handle;
  17362. + u32 type; /* port type, cached to use on port info set */
  17363. + u32 index; /* port index, cached to use on port info set */
  17364. +
  17365. + /* component port belongs to, allows simple deref */
  17366. + struct vchiq_mmal_component *component;
  17367. +
  17368. + struct vchiq_mmal_port *connected; /* port conencted to */
  17369. +
  17370. + /* buffer info */
  17371. + struct vchiq_mmal_port_buffer minimum_buffer;
  17372. + struct vchiq_mmal_port_buffer recommended_buffer;
  17373. + struct vchiq_mmal_port_buffer current_buffer;
  17374. +
  17375. + /* stream format */
  17376. + struct mmal_es_format format;
  17377. + /* elementry stream format */
  17378. + union mmal_es_specific_format es;
  17379. +
  17380. + /* data buffers to fill */
  17381. + struct list_head buffers;
  17382. + /* lock to serialise adding and removing buffers from list */
  17383. + spinlock_t slock;
  17384. + /* count of how many buffer header refils have failed because
  17385. + * there was no buffer to satisfy them
  17386. + */
  17387. + int buffer_underflow;
  17388. + /* callback on buffer completion */
  17389. + vchiq_mmal_buffer_cb buffer_cb;
  17390. + /* callback context */
  17391. + void *cb_ctx;
  17392. +};
  17393. +
  17394. +struct vchiq_mmal_component {
  17395. + bool enabled;
  17396. + u32 handle; /* VideoCore handle for component */
  17397. + u32 inputs; /* Number of input ports */
  17398. + u32 outputs; /* Number of output ports */
  17399. + u32 clocks; /* Number of clock ports */
  17400. + struct vchiq_mmal_port control; /* control port */
  17401. + struct vchiq_mmal_port input[MAX_PORT_COUNT]; /* input ports */
  17402. + struct vchiq_mmal_port output[MAX_PORT_COUNT]; /* output ports */
  17403. + struct vchiq_mmal_port clock[MAX_PORT_COUNT]; /* clock ports */
  17404. +};
  17405. +
  17406. +
  17407. +int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance);
  17408. +int vchiq_mmal_finalise(struct vchiq_mmal_instance *instance);
  17409. +
  17410. +/* Initialise a mmal component and its ports
  17411. +*
  17412. +*/
  17413. +int vchiq_mmal_component_init(
  17414. + struct vchiq_mmal_instance *instance,
  17415. + const char *name,
  17416. + struct vchiq_mmal_component **component_out);
  17417. +
  17418. +int vchiq_mmal_component_finalise(
  17419. + struct vchiq_mmal_instance *instance,
  17420. + struct vchiq_mmal_component *component);
  17421. +
  17422. +int vchiq_mmal_component_enable(
  17423. + struct vchiq_mmal_instance *instance,
  17424. + struct vchiq_mmal_component *component);
  17425. +
  17426. +int vchiq_mmal_component_disable(
  17427. + struct vchiq_mmal_instance *instance,
  17428. + struct vchiq_mmal_component *component);
  17429. +
  17430. +
  17431. +
  17432. +/* enable a mmal port
  17433. + *
  17434. + * enables a port and if a buffer callback provided enque buffer
  17435. + * headers as apropriate for the port.
  17436. + */
  17437. +int vchiq_mmal_port_enable(
  17438. + struct vchiq_mmal_instance *instance,
  17439. + struct vchiq_mmal_port *port,
  17440. + vchiq_mmal_buffer_cb buffer_cb);
  17441. +
  17442. +/* disable a port
  17443. + *
  17444. + * disable a port will dequeue any pending buffers
  17445. + */
  17446. +int vchiq_mmal_port_disable(struct vchiq_mmal_instance *instance,
  17447. + struct vchiq_mmal_port *port);
  17448. +
  17449. +
  17450. +int vchiq_mmal_port_parameter_set(struct vchiq_mmal_instance *instance,
  17451. + struct vchiq_mmal_port *port,
  17452. + u32 parameter,
  17453. + void *value,
  17454. + u32 value_size);
  17455. +
  17456. +int vchiq_mmal_port_parameter_get(struct vchiq_mmal_instance *instance,
  17457. + struct vchiq_mmal_port *port,
  17458. + u32 parameter,
  17459. + void *value,
  17460. + u32 *value_size);
  17461. +
  17462. +int vchiq_mmal_port_set_format(struct vchiq_mmal_instance *instance,
  17463. + struct vchiq_mmal_port *port);
  17464. +
  17465. +int vchiq_mmal_port_connect_tunnel(struct vchiq_mmal_instance *instance,
  17466. + struct vchiq_mmal_port *src,
  17467. + struct vchiq_mmal_port *dst);
  17468. +
  17469. +int vchiq_mmal_version(struct vchiq_mmal_instance *instance,
  17470. + u32 *major_out,
  17471. + u32 *minor_out);
  17472. +
  17473. +int vchiq_mmal_submit_buffer(struct vchiq_mmal_instance *instance,
  17474. + struct vchiq_mmal_port *port,
  17475. + struct mmal_buffer *buf);
  17476. +
  17477. +#endif /* MMAL_VCHIQ_H */
  17478. diff -Nur linux-3.13.11/drivers/media/platform/Kconfig linux-rpi/drivers/media/platform/Kconfig
  17479. --- linux-3.13.11/drivers/media/platform/Kconfig 2014-04-23 01:49:33.000000000 +0200
  17480. +++ linux-rpi/drivers/media/platform/Kconfig 2014-04-24 15:36:50.070736112 +0200
  17481. @@ -124,6 +124,7 @@
  17482. source "drivers/media/platform/soc_camera/Kconfig"
  17483. source "drivers/media/platform/exynos4-is/Kconfig"
  17484. source "drivers/media/platform/s5p-tv/Kconfig"
  17485. +source "drivers/media/platform/bcm2835/Kconfig"
  17486. endif # V4L_PLATFORM_DRIVERS
  17487. diff -Nur linux-3.13.11/drivers/media/platform/Makefile linux-rpi/drivers/media/platform/Makefile
  17488. --- linux-3.13.11/drivers/media/platform/Makefile 2014-04-23 01:49:33.000000000 +0200
  17489. +++ linux-rpi/drivers/media/platform/Makefile 2014-04-24 15:36:50.070736112 +0200
  17490. @@ -54,4 +54,6 @@
  17491. obj-$(CONFIG_ARCH_OMAP) += omap/
  17492. +obj-$(CONFIG_VIDEO_BCM2835) += bcm2835/
  17493. +
  17494. ccflags-y += -I$(srctree)/drivers/media/i2c
  17495. diff -Nur linux-3.13.11/drivers/media/usb/dvb-usb-v2/rtl28xxu.c linux-rpi/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
  17496. --- linux-3.13.11/drivers/media/usb/dvb-usb-v2/rtl28xxu.c 2014-04-23 01:49:33.000000000 +0200
  17497. +++ linux-rpi/drivers/media/usb/dvb-usb-v2/rtl28xxu.c 2014-04-24 15:36:50.758743654 +0200
  17498. @@ -1423,6 +1423,10 @@
  17499. &rtl2832u_props, "Compro VideoMate U620F", NULL) },
  17500. { DVB_USB_DEVICE(USB_VID_KWORLD_2, 0xd394,
  17501. &rtl2832u_props, "MaxMedia HU394-T", NULL) },
  17502. + { DVB_USB_DEVICE(USB_VID_GTEK, 0xb803 /*USB_PID_AUGUST_DVBT205*/,
  17503. + &rtl2832u_props, "August DVB-T 205", NULL) },
  17504. + { DVB_USB_DEVICE(USB_VID_GTEK, 0xa803 /*USB_PID_AUGUST_DVBT205*/,
  17505. + &rtl2832u_props, "August DVB-T 205", NULL) },
  17506. { DVB_USB_DEVICE(USB_VID_LEADTEK, 0x6a03,
  17507. &rtl2832u_props, "Leadtek WinFast DTV Dongle mini", NULL) },
  17508. { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_CPYTO_REDI_PC50A,
  17509. diff -Nur linux-3.13.11/drivers/misc/Kconfig linux-rpi/drivers/misc/Kconfig
  17510. --- linux-3.13.11/drivers/misc/Kconfig 2014-04-23 01:49:33.000000000 +0200
  17511. +++ linux-rpi/drivers/misc/Kconfig 2014-04-24 15:36:51.162748084 +0200
  17512. @@ -524,5 +524,6 @@
  17513. source "drivers/misc/altera-stapl/Kconfig"
  17514. source "drivers/misc/mei/Kconfig"
  17515. source "drivers/misc/vmw_vmci/Kconfig"
  17516. +source "drivers/misc/vc04_services/Kconfig"
  17517. source "drivers/misc/mic/Kconfig"
  17518. endmenu
  17519. diff -Nur linux-3.13.11/drivers/misc/Makefile linux-rpi/drivers/misc/Makefile
  17520. --- linux-3.13.11/drivers/misc/Makefile 2014-04-23 01:49:33.000000000 +0200
  17521. +++ linux-rpi/drivers/misc/Makefile 2014-04-24 15:36:51.162748084 +0200
  17522. @@ -52,4 +52,5 @@
  17523. obj-$(CONFIG_VMWARE_VMCI) += vmw_vmci/
  17524. obj-$(CONFIG_LATTICE_ECP3_CONFIG) += lattice-ecp3-config.o
  17525. obj-$(CONFIG_SRAM) += sram.o
  17526. +obj-$(CONFIG_BCM2708_VCHIQ) += vc04_services/
  17527. obj-y += mic/
  17528. diff -Nur linux-3.13.11/drivers/misc/vc04_services/interface/vchi/connections/connection.h linux-rpi/drivers/misc/vc04_services/interface/vchi/connections/connection.h
  17529. --- linux-3.13.11/drivers/misc/vc04_services/interface/vchi/connections/connection.h 1970-01-01 01:00:00.000000000 +0100
  17530. +++ linux-rpi/drivers/misc/vc04_services/interface/vchi/connections/connection.h 2014-04-24 15:35:02.889551471 +0200
  17531. @@ -0,0 +1,328 @@
  17532. +/**
  17533. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  17534. + *
  17535. + * Redistribution and use in source and binary forms, with or without
  17536. + * modification, are permitted provided that the following conditions
  17537. + * are met:
  17538. + * 1. Redistributions of source code must retain the above copyright
  17539. + * notice, this list of conditions, and the following disclaimer,
  17540. + * without modification.
  17541. + * 2. Redistributions in binary form must reproduce the above copyright
  17542. + * notice, this list of conditions and the following disclaimer in the
  17543. + * documentation and/or other materials provided with the distribution.
  17544. + * 3. The names of the above-listed copyright holders may not be used
  17545. + * to endorse or promote products derived from this software without
  17546. + * specific prior written permission.
  17547. + *
  17548. + * ALTERNATIVELY, this software may be distributed under the terms of the
  17549. + * GNU General Public License ("GPL") version 2, as published by the Free
  17550. + * Software Foundation.
  17551. + *
  17552. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  17553. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  17554. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  17555. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  17556. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  17557. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  17558. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  17559. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  17560. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  17561. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  17562. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  17563. + */
  17564. +
  17565. +#ifndef CONNECTION_H_
  17566. +#define CONNECTION_H_
  17567. +
  17568. +#include <linux/kernel.h>
  17569. +#include <linux/types.h>
  17570. +#include <linux/semaphore.h>
  17571. +
  17572. +#include "interface/vchi/vchi_cfg_internal.h"
  17573. +#include "interface/vchi/vchi_common.h"
  17574. +#include "interface/vchi/message_drivers/message.h"
  17575. +
  17576. +/******************************************************************************
  17577. + Global defs
  17578. + *****************************************************************************/
  17579. +
  17580. +// Opaque handle for a connection / service pair
  17581. +typedef struct opaque_vchi_connection_connected_service_handle_t *VCHI_CONNECTION_SERVICE_HANDLE_T;
  17582. +
  17583. +// opaque handle to the connection state information
  17584. +typedef struct opaque_vchi_connection_info_t VCHI_CONNECTION_STATE_T;
  17585. +
  17586. +typedef struct vchi_connection_t VCHI_CONNECTION_T;
  17587. +
  17588. +
  17589. +/******************************************************************************
  17590. + API
  17591. + *****************************************************************************/
  17592. +
  17593. +// Routine to init a connection with a particular low level driver
  17594. +typedef VCHI_CONNECTION_STATE_T * (*VCHI_CONNECTION_INIT_T)( struct vchi_connection_t * connection,
  17595. + const VCHI_MESSAGE_DRIVER_T * driver );
  17596. +
  17597. +// Routine to control CRC enabling at a connection level
  17598. +typedef int32_t (*VCHI_CONNECTION_CRC_CONTROL_T)( VCHI_CONNECTION_STATE_T *state_handle,
  17599. + VCHI_CRC_CONTROL_T control );
  17600. +
  17601. +// Routine to create a service
  17602. +typedef int32_t (*VCHI_CONNECTION_SERVICE_CONNECT_T)( VCHI_CONNECTION_STATE_T *state_handle,
  17603. + int32_t service_id,
  17604. + uint32_t rx_fifo_size,
  17605. + uint32_t tx_fifo_size,
  17606. + int server,
  17607. + VCHI_CALLBACK_T callback,
  17608. + void *callback_param,
  17609. + int32_t want_crc,
  17610. + int32_t want_unaligned_bulk_rx,
  17611. + int32_t want_unaligned_bulk_tx,
  17612. + VCHI_CONNECTION_SERVICE_HANDLE_T *service_handle );
  17613. +
  17614. +// Routine to close a service
  17615. +typedef int32_t (*VCHI_CONNECTION_SERVICE_DISCONNECT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle );
  17616. +
  17617. +// Routine to queue a message
  17618. +typedef int32_t (*VCHI_CONNECTION_SERVICE_QUEUE_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  17619. + const void *data,
  17620. + uint32_t data_size,
  17621. + VCHI_FLAGS_T flags,
  17622. + void *msg_handle );
  17623. +
  17624. +// scatter-gather (vector) message queueing
  17625. +typedef int32_t (*VCHI_CONNECTION_SERVICE_QUEUE_MESSAGEV_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  17626. + VCHI_MSG_VECTOR_T *vector,
  17627. + uint32_t count,
  17628. + VCHI_FLAGS_T flags,
  17629. + void *msg_handle );
  17630. +
  17631. +// Routine to dequeue a message
  17632. +typedef int32_t (*VCHI_CONNECTION_SERVICE_DEQUEUE_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  17633. + void *data,
  17634. + uint32_t max_data_size_to_read,
  17635. + uint32_t *actual_msg_size,
  17636. + VCHI_FLAGS_T flags );
  17637. +
  17638. +// Routine to peek at a message
  17639. +typedef int32_t (*VCHI_CONNECTION_SERVICE_PEEK_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  17640. + void **data,
  17641. + uint32_t *msg_size,
  17642. + VCHI_FLAGS_T flags );
  17643. +
  17644. +// Routine to hold a message
  17645. +typedef int32_t (*VCHI_CONNECTION_SERVICE_HOLD_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  17646. + void **data,
  17647. + uint32_t *msg_size,
  17648. + VCHI_FLAGS_T flags,
  17649. + void **message_handle );
  17650. +
  17651. +// Routine to initialise a received message iterator
  17652. +typedef int32_t (*VCHI_CONNECTION_SERVICE_LOOKAHEAD_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  17653. + VCHI_MSG_ITER_T *iter,
  17654. + VCHI_FLAGS_T flags );
  17655. +
  17656. +// Routine to release a held message
  17657. +typedef int32_t (*VCHI_CONNECTION_HELD_MSG_RELEASE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  17658. + void *message_handle );
  17659. +
  17660. +// Routine to get info on a held message
  17661. +typedef int32_t (*VCHI_CONNECTION_HELD_MSG_INFO_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  17662. + void *message_handle,
  17663. + void **data,
  17664. + int32_t *msg_size,
  17665. + uint32_t *tx_timestamp,
  17666. + uint32_t *rx_timestamp );
  17667. +
  17668. +// Routine to check whether the iterator has a next message
  17669. +typedef int32_t (*VCHI_CONNECTION_MSG_ITER_HAS_NEXT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
  17670. + const VCHI_MSG_ITER_T *iter );
  17671. +
  17672. +// Routine to advance the iterator
  17673. +typedef int32_t (*VCHI_CONNECTION_MSG_ITER_NEXT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
  17674. + VCHI_MSG_ITER_T *iter,
  17675. + void **data,
  17676. + uint32_t *msg_size );
  17677. +
  17678. +// Routine to remove the last message returned by the iterator
  17679. +typedef int32_t (*VCHI_CONNECTION_MSG_ITER_REMOVE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
  17680. + VCHI_MSG_ITER_T *iter );
  17681. +
  17682. +// Routine to hold the last message returned by the iterator
  17683. +typedef int32_t (*VCHI_CONNECTION_MSG_ITER_HOLD_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
  17684. + VCHI_MSG_ITER_T *iter,
  17685. + void **msg_handle );
  17686. +
  17687. +// Routine to transmit bulk data
  17688. +typedef int32_t (*VCHI_CONNECTION_BULK_QUEUE_TRANSMIT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  17689. + const void *data_src,
  17690. + uint32_t data_size,
  17691. + VCHI_FLAGS_T flags,
  17692. + void *bulk_handle );
  17693. +
  17694. +// Routine to receive data
  17695. +typedef int32_t (*VCHI_CONNECTION_BULK_QUEUE_RECEIVE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  17696. + void *data_dst,
  17697. + uint32_t data_size,
  17698. + VCHI_FLAGS_T flags,
  17699. + void *bulk_handle );
  17700. +
  17701. +// Routine to report if a server is available
  17702. +typedef int32_t (*VCHI_CONNECTION_SERVER_PRESENT)( VCHI_CONNECTION_STATE_T *state, int32_t service_id, int32_t peer_flags );
  17703. +
  17704. +// Routine to report the number of RX slots available
  17705. +typedef int (*VCHI_CONNECTION_RX_SLOTS_AVAILABLE)( const VCHI_CONNECTION_STATE_T *state );
  17706. +
  17707. +// Routine to report the RX slot size
  17708. +typedef uint32_t (*VCHI_CONNECTION_RX_SLOT_SIZE)( const VCHI_CONNECTION_STATE_T *state );
  17709. +
  17710. +// Callback to indicate that the other side has added a buffer to the rx bulk DMA FIFO
  17711. +typedef void (*VCHI_CONNECTION_RX_BULK_BUFFER_ADDED)(VCHI_CONNECTION_STATE_T *state,
  17712. + int32_t service,
  17713. + uint32_t length,
  17714. + MESSAGE_TX_CHANNEL_T channel,
  17715. + uint32_t channel_params,
  17716. + uint32_t data_length,
  17717. + uint32_t data_offset);
  17718. +
  17719. +// Callback to inform a service that a Xon or Xoff message has been received
  17720. +typedef void (*VCHI_CONNECTION_FLOW_CONTROL)(VCHI_CONNECTION_STATE_T *state, int32_t service_id, int32_t xoff);
  17721. +
  17722. +// Callback to inform a service that a server available reply message has been received
  17723. +typedef void (*VCHI_CONNECTION_SERVER_AVAILABLE_REPLY)(VCHI_CONNECTION_STATE_T *state, int32_t service_id, uint32_t flags);
  17724. +
  17725. +// Callback to indicate that bulk auxiliary messages have arrived
  17726. +typedef void (*VCHI_CONNECTION_BULK_AUX_RECEIVED)(VCHI_CONNECTION_STATE_T *state);
  17727. +
  17728. +// Callback to indicate that bulk auxiliary messages have arrived
  17729. +typedef void (*VCHI_CONNECTION_BULK_AUX_TRANSMITTED)(VCHI_CONNECTION_STATE_T *state, void *handle);
  17730. +
  17731. +// Callback with all the connection info you require
  17732. +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);
  17733. +
  17734. +// Callback to inform of a disconnect
  17735. +typedef void (*VCHI_CONNECTION_DISCONNECT)(VCHI_CONNECTION_STATE_T *state, uint32_t flags);
  17736. +
  17737. +// Callback to inform of a power control request
  17738. +typedef void (*VCHI_CONNECTION_POWER_CONTROL)(VCHI_CONNECTION_STATE_T *state, MESSAGE_TX_CHANNEL_T channel, int32_t enable);
  17739. +
  17740. +// allocate memory suitably aligned for this connection
  17741. +typedef void * (*VCHI_BUFFER_ALLOCATE)(VCHI_CONNECTION_SERVICE_HANDLE_T service_handle, uint32_t * length);
  17742. +
  17743. +// free memory allocated by buffer_allocate
  17744. +typedef void (*VCHI_BUFFER_FREE)(VCHI_CONNECTION_SERVICE_HANDLE_T service_handle, void * address);
  17745. +
  17746. +
  17747. +/******************************************************************************
  17748. + System driver struct
  17749. + *****************************************************************************/
  17750. +
  17751. +struct opaque_vchi_connection_api_t
  17752. +{
  17753. + // Routine to init the connection
  17754. + VCHI_CONNECTION_INIT_T init;
  17755. +
  17756. + // Connection-level CRC control
  17757. + VCHI_CONNECTION_CRC_CONTROL_T crc_control;
  17758. +
  17759. + // Routine to connect to or create service
  17760. + VCHI_CONNECTION_SERVICE_CONNECT_T service_connect;
  17761. +
  17762. + // Routine to disconnect from a service
  17763. + VCHI_CONNECTION_SERVICE_DISCONNECT_T service_disconnect;
  17764. +
  17765. + // Routine to queue a message
  17766. + VCHI_CONNECTION_SERVICE_QUEUE_MESSAGE_T service_queue_msg;
  17767. +
  17768. + // scatter-gather (vector) message queue
  17769. + VCHI_CONNECTION_SERVICE_QUEUE_MESSAGEV_T service_queue_msgv;
  17770. +
  17771. + // Routine to dequeue a message
  17772. + VCHI_CONNECTION_SERVICE_DEQUEUE_MESSAGE_T service_dequeue_msg;
  17773. +
  17774. + // Routine to peek at a message
  17775. + VCHI_CONNECTION_SERVICE_PEEK_MESSAGE_T service_peek_msg;
  17776. +
  17777. + // Routine to hold a message
  17778. + VCHI_CONNECTION_SERVICE_HOLD_MESSAGE_T service_hold_msg;
  17779. +
  17780. + // Routine to initialise a received message iterator
  17781. + VCHI_CONNECTION_SERVICE_LOOKAHEAD_MESSAGE_T service_look_ahead_msg;
  17782. +
  17783. + // Routine to release a message
  17784. + VCHI_CONNECTION_HELD_MSG_RELEASE_T held_msg_release;
  17785. +
  17786. + // Routine to get information on a held message
  17787. + VCHI_CONNECTION_HELD_MSG_INFO_T held_msg_info;
  17788. +
  17789. + // Routine to check for next message on iterator
  17790. + VCHI_CONNECTION_MSG_ITER_HAS_NEXT_T msg_iter_has_next;
  17791. +
  17792. + // Routine to get next message on iterator
  17793. + VCHI_CONNECTION_MSG_ITER_NEXT_T msg_iter_next;
  17794. +
  17795. + // Routine to remove the last message returned by iterator
  17796. + VCHI_CONNECTION_MSG_ITER_REMOVE_T msg_iter_remove;
  17797. +
  17798. + // Routine to hold the last message returned by iterator
  17799. + VCHI_CONNECTION_MSG_ITER_HOLD_T msg_iter_hold;
  17800. +
  17801. + // Routine to transmit bulk data
  17802. + VCHI_CONNECTION_BULK_QUEUE_TRANSMIT_T bulk_queue_transmit;
  17803. +
  17804. + // Routine to receive data
  17805. + VCHI_CONNECTION_BULK_QUEUE_RECEIVE_T bulk_queue_receive;
  17806. +
  17807. + // Routine to report the available servers
  17808. + VCHI_CONNECTION_SERVER_PRESENT server_present;
  17809. +
  17810. + // Routine to report the number of RX slots available
  17811. + VCHI_CONNECTION_RX_SLOTS_AVAILABLE connection_rx_slots_available;
  17812. +
  17813. + // Routine to report the RX slot size
  17814. + VCHI_CONNECTION_RX_SLOT_SIZE connection_rx_slot_size;
  17815. +
  17816. + // Callback to indicate that the other side has added a buffer to the rx bulk DMA FIFO
  17817. + VCHI_CONNECTION_RX_BULK_BUFFER_ADDED rx_bulk_buffer_added;
  17818. +
  17819. + // Callback to inform a service that a Xon or Xoff message has been received
  17820. + VCHI_CONNECTION_FLOW_CONTROL flow_control;
  17821. +
  17822. + // Callback to inform a service that a server available reply message has been received
  17823. + VCHI_CONNECTION_SERVER_AVAILABLE_REPLY server_available_reply;
  17824. +
  17825. + // Callback to indicate that bulk auxiliary messages have arrived
  17826. + VCHI_CONNECTION_BULK_AUX_RECEIVED bulk_aux_received;
  17827. +
  17828. + // Callback to indicate that a bulk auxiliary message has been transmitted
  17829. + VCHI_CONNECTION_BULK_AUX_TRANSMITTED bulk_aux_transmitted;
  17830. +
  17831. + // Callback to provide information about the connection
  17832. + VCHI_CONNECTION_INFO connection_info;
  17833. +
  17834. + // Callback to notify that peer has requested disconnect
  17835. + VCHI_CONNECTION_DISCONNECT disconnect;
  17836. +
  17837. + // Callback to notify that peer has requested power change
  17838. + VCHI_CONNECTION_POWER_CONTROL power_control;
  17839. +
  17840. + // allocate memory suitably aligned for this connection
  17841. + VCHI_BUFFER_ALLOCATE buffer_allocate;
  17842. +
  17843. + // free memory allocated by buffer_allocate
  17844. + VCHI_BUFFER_FREE buffer_free;
  17845. +
  17846. +};
  17847. +
  17848. +struct vchi_connection_t {
  17849. + const VCHI_CONNECTION_API_T *api;
  17850. + VCHI_CONNECTION_STATE_T *state;
  17851. +#ifdef VCHI_COARSE_LOCKING
  17852. + struct semaphore sem;
  17853. +#endif
  17854. +};
  17855. +
  17856. +
  17857. +#endif /* CONNECTION_H_ */
  17858. +
  17859. +/****************************** End of file **********************************/
  17860. diff -Nur linux-3.13.11/drivers/misc/vc04_services/interface/vchi/message_drivers/message.h linux-rpi/drivers/misc/vc04_services/interface/vchi/message_drivers/message.h
  17861. --- linux-3.13.11/drivers/misc/vc04_services/interface/vchi/message_drivers/message.h 1970-01-01 01:00:00.000000000 +0100
  17862. +++ linux-rpi/drivers/misc/vc04_services/interface/vchi/message_drivers/message.h 2014-04-24 15:35:02.889551471 +0200
  17863. @@ -0,0 +1,204 @@
  17864. +/**
  17865. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  17866. + *
  17867. + * Redistribution and use in source and binary forms, with or without
  17868. + * modification, are permitted provided that the following conditions
  17869. + * are met:
  17870. + * 1. Redistributions of source code must retain the above copyright
  17871. + * notice, this list of conditions, and the following disclaimer,
  17872. + * without modification.
  17873. + * 2. Redistributions in binary form must reproduce the above copyright
  17874. + * notice, this list of conditions and the following disclaimer in the
  17875. + * documentation and/or other materials provided with the distribution.
  17876. + * 3. The names of the above-listed copyright holders may not be used
  17877. + * to endorse or promote products derived from this software without
  17878. + * specific prior written permission.
  17879. + *
  17880. + * ALTERNATIVELY, this software may be distributed under the terms of the
  17881. + * GNU General Public License ("GPL") version 2, as published by the Free
  17882. + * Software Foundation.
  17883. + *
  17884. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  17885. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  17886. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  17887. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  17888. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  17889. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  17890. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  17891. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  17892. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  17893. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  17894. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  17895. + */
  17896. +
  17897. +#ifndef _VCHI_MESSAGE_H_
  17898. +#define _VCHI_MESSAGE_H_
  17899. +
  17900. +#include <linux/kernel.h>
  17901. +#include <linux/types.h>
  17902. +#include <linux/semaphore.h>
  17903. +
  17904. +#include "interface/vchi/vchi_cfg_internal.h"
  17905. +#include "interface/vchi/vchi_common.h"
  17906. +
  17907. +
  17908. +typedef enum message_event_type {
  17909. + MESSAGE_EVENT_NONE,
  17910. + MESSAGE_EVENT_NOP,
  17911. + MESSAGE_EVENT_MESSAGE,
  17912. + MESSAGE_EVENT_SLOT_COMPLETE,
  17913. + MESSAGE_EVENT_RX_BULK_PAUSED,
  17914. + MESSAGE_EVENT_RX_BULK_COMPLETE,
  17915. + MESSAGE_EVENT_TX_COMPLETE,
  17916. + MESSAGE_EVENT_MSG_DISCARDED
  17917. +} MESSAGE_EVENT_TYPE_T;
  17918. +
  17919. +typedef enum vchi_msg_flags
  17920. +{
  17921. + VCHI_MSG_FLAGS_NONE = 0x0,
  17922. + VCHI_MSG_FLAGS_TERMINATE_DMA = 0x1
  17923. +} VCHI_MSG_FLAGS_T;
  17924. +
  17925. +typedef enum message_tx_channel
  17926. +{
  17927. + MESSAGE_TX_CHANNEL_MESSAGE = 0,
  17928. + MESSAGE_TX_CHANNEL_BULK = 1 // drivers may provide multiple bulk channels, from 1 upwards
  17929. +} MESSAGE_TX_CHANNEL_T;
  17930. +
  17931. +// Macros used for cycling through bulk channels
  17932. +#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)
  17933. +#define MESSAGE_TX_CHANNEL_BULK_NEXT(c) (MESSAGE_TX_CHANNEL_BULK+((c)-MESSAGE_TX_CHANNEL_BULK+1)%VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION)
  17934. +
  17935. +typedef enum message_rx_channel
  17936. +{
  17937. + MESSAGE_RX_CHANNEL_MESSAGE = 0,
  17938. + MESSAGE_RX_CHANNEL_BULK = 1 // drivers may provide multiple bulk channels, from 1 upwards
  17939. +} MESSAGE_RX_CHANNEL_T;
  17940. +
  17941. +// Message receive slot information
  17942. +typedef struct rx_msg_slot_info {
  17943. +
  17944. + struct rx_msg_slot_info *next;
  17945. + //struct slot_info *prev;
  17946. +#if !defined VCHI_COARSE_LOCKING
  17947. + struct semaphore sem;
  17948. +#endif
  17949. +
  17950. + uint8_t *addr; // base address of slot
  17951. + uint32_t len; // length of slot in bytes
  17952. +
  17953. + uint32_t write_ptr; // hardware causes this to advance
  17954. + uint32_t read_ptr; // this module does the reading
  17955. + int active; // is this slot in the hardware dma fifo?
  17956. + uint32_t msgs_parsed; // count how many messages are in this slot
  17957. + uint32_t msgs_released; // how many messages have been released
  17958. + void *state; // connection state information
  17959. + uint8_t ref_count[VCHI_MAX_SERVICES_PER_CONNECTION]; // reference count for slots held by services
  17960. +} RX_MSG_SLOTINFO_T;
  17961. +
  17962. +// The message driver no longer needs to know about the fields of RX_BULK_SLOTINFO_T - sort this out.
  17963. +// In particular, it mustn't use addr and len - they're the client buffer, but the message
  17964. +// driver will be tasked with sending the aligned core section.
  17965. +typedef struct rx_bulk_slotinfo_t {
  17966. + struct rx_bulk_slotinfo_t *next;
  17967. +
  17968. + struct semaphore *blocking;
  17969. +
  17970. + // needed by DMA
  17971. + void *addr;
  17972. + uint32_t len;
  17973. +
  17974. + // needed for the callback
  17975. + void *service;
  17976. + void *handle;
  17977. + VCHI_FLAGS_T flags;
  17978. +} RX_BULK_SLOTINFO_T;
  17979. +
  17980. +
  17981. +/* ----------------------------------------------------------------------
  17982. + * each connection driver will have a pool of the following struct.
  17983. + *
  17984. + * the pool will be managed by vchi_qman_*
  17985. + * this means there will be multiple queues (single linked lists)
  17986. + * a given struct message_info will be on exactly one of these queues
  17987. + * at any one time
  17988. + * -------------------------------------------------------------------- */
  17989. +typedef struct rx_message_info {
  17990. +
  17991. + struct message_info *next;
  17992. + //struct message_info *prev;
  17993. +
  17994. + uint8_t *addr;
  17995. + uint32_t len;
  17996. + RX_MSG_SLOTINFO_T *slot; // points to whichever slot contains this message
  17997. + uint32_t tx_timestamp;
  17998. + uint32_t rx_timestamp;
  17999. +
  18000. +} RX_MESSAGE_INFO_T;
  18001. +
  18002. +typedef struct {
  18003. + MESSAGE_EVENT_TYPE_T type;
  18004. +
  18005. + struct {
  18006. + // for messages
  18007. + void *addr; // address of message
  18008. + uint16_t slot_delta; // whether this message indicated slot delta
  18009. + uint32_t len; // length of message
  18010. + RX_MSG_SLOTINFO_T *slot; // slot this message is in
  18011. + int32_t service; // service id this message is destined for
  18012. + uint32_t tx_timestamp; // timestamp from the header
  18013. + uint32_t rx_timestamp; // timestamp when we parsed it
  18014. + } message;
  18015. +
  18016. + // FIXME: cleanup slot reporting...
  18017. + RX_MSG_SLOTINFO_T *rx_msg;
  18018. + RX_BULK_SLOTINFO_T *rx_bulk;
  18019. + void *tx_handle;
  18020. + MESSAGE_TX_CHANNEL_T tx_channel;
  18021. +
  18022. +} MESSAGE_EVENT_T;
  18023. +
  18024. +
  18025. +// callbacks
  18026. +typedef void VCHI_MESSAGE_DRIVER_EVENT_CALLBACK_T( void *state );
  18027. +
  18028. +typedef struct {
  18029. + VCHI_MESSAGE_DRIVER_EVENT_CALLBACK_T *event_callback;
  18030. +} VCHI_MESSAGE_DRIVER_OPEN_T;
  18031. +
  18032. +
  18033. +// handle to this instance of message driver (as returned by ->open)
  18034. +typedef struct opaque_mhandle_t *VCHI_MDRIVER_HANDLE_T;
  18035. +
  18036. +struct opaque_vchi_message_driver_t {
  18037. + VCHI_MDRIVER_HANDLE_T *(*open)( VCHI_MESSAGE_DRIVER_OPEN_T *params, void *state );
  18038. + int32_t (*suspending)( VCHI_MDRIVER_HANDLE_T *handle );
  18039. + int32_t (*resumed)( VCHI_MDRIVER_HANDLE_T *handle );
  18040. + int32_t (*power_control)( VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T, int32_t enable );
  18041. + int32_t (*add_msg_rx_slot)( VCHI_MDRIVER_HANDLE_T *handle, RX_MSG_SLOTINFO_T *slot ); // rx message
  18042. + int32_t (*add_bulk_rx)( VCHI_MDRIVER_HANDLE_T *handle, void *data, uint32_t len, RX_BULK_SLOTINFO_T *slot ); // rx data (bulk)
  18043. + 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)
  18044. + void (*next_event)( VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_EVENT_T *event ); // get the next event from message_driver
  18045. + int32_t (*enable)( VCHI_MDRIVER_HANDLE_T *handle );
  18046. + int32_t (*form_message)( VCHI_MDRIVER_HANDLE_T *handle, int32_t service_id, VCHI_MSG_VECTOR_T *vector, uint32_t count, void
  18047. + *address, uint32_t length_avail, uint32_t max_total_length, int32_t pad_to_fill, int32_t allow_partial );
  18048. +
  18049. + int32_t (*update_message)( VCHI_MDRIVER_HANDLE_T *handle, void *dest, int16_t *slot_count );
  18050. + int32_t (*buffer_aligned)( VCHI_MDRIVER_HANDLE_T *handle, int tx, int uncached, const void *address, const uint32_t length );
  18051. + void * (*allocate_buffer)( VCHI_MDRIVER_HANDLE_T *handle, uint32_t *length );
  18052. + void (*free_buffer)( VCHI_MDRIVER_HANDLE_T *handle, void *address );
  18053. + int (*rx_slot_size)( VCHI_MDRIVER_HANDLE_T *handle, int msg_size );
  18054. + int (*tx_slot_size)( VCHI_MDRIVER_HANDLE_T *handle, int msg_size );
  18055. +
  18056. + int32_t (*tx_supports_terminate)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel );
  18057. + uint32_t (*tx_bulk_chunk_size)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel );
  18058. + int (*tx_alignment)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel );
  18059. + int (*rx_alignment)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_RX_CHANNEL_T channel );
  18060. + 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 );
  18061. + void (*debug)( VCHI_MDRIVER_HANDLE_T *handle );
  18062. +};
  18063. +
  18064. +
  18065. +#endif // _VCHI_MESSAGE_H_
  18066. +
  18067. +/****************************** End of file ***********************************/
  18068. diff -Nur linux-3.13.11/drivers/misc/vc04_services/interface/vchi/vchi_cfg.h linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_cfg.h
  18069. --- linux-3.13.11/drivers/misc/vc04_services/interface/vchi/vchi_cfg.h 1970-01-01 01:00:00.000000000 +0100
  18070. +++ linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_cfg.h 2014-04-24 15:35:02.889551471 +0200
  18071. @@ -0,0 +1,224 @@
  18072. +/**
  18073. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  18074. + *
  18075. + * Redistribution and use in source and binary forms, with or without
  18076. + * modification, are permitted provided that the following conditions
  18077. + * are met:
  18078. + * 1. Redistributions of source code must retain the above copyright
  18079. + * notice, this list of conditions, and the following disclaimer,
  18080. + * without modification.
  18081. + * 2. Redistributions in binary form must reproduce the above copyright
  18082. + * notice, this list of conditions and the following disclaimer in the
  18083. + * documentation and/or other materials provided with the distribution.
  18084. + * 3. The names of the above-listed copyright holders may not be used
  18085. + * to endorse or promote products derived from this software without
  18086. + * specific prior written permission.
  18087. + *
  18088. + * ALTERNATIVELY, this software may be distributed under the terms of the
  18089. + * GNU General Public License ("GPL") version 2, as published by the Free
  18090. + * Software Foundation.
  18091. + *
  18092. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  18093. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  18094. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  18095. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  18096. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18097. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  18098. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  18099. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  18100. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  18101. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  18102. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  18103. + */
  18104. +
  18105. +#ifndef VCHI_CFG_H_
  18106. +#define VCHI_CFG_H_
  18107. +
  18108. +/****************************************************************************************
  18109. + * Defines in this first section are part of the VCHI API and may be examined by VCHI
  18110. + * services.
  18111. + ***************************************************************************************/
  18112. +
  18113. +/* Required alignment of base addresses for bulk transfer, if unaligned transfers are not enabled */
  18114. +/* Really determined by the message driver, and should be available from a run-time call. */
  18115. +#ifndef VCHI_BULK_ALIGN
  18116. +# if __VCCOREVER__ >= 0x04000000
  18117. +# define VCHI_BULK_ALIGN 32 // Allows for the need to do cache cleans
  18118. +# else
  18119. +# define VCHI_BULK_ALIGN 16
  18120. +# endif
  18121. +#endif
  18122. +
  18123. +/* Required length multiple for bulk transfers, if unaligned transfers are not enabled */
  18124. +/* May be less than or greater than VCHI_BULK_ALIGN */
  18125. +/* Really determined by the message driver, and should be available from a run-time call. */
  18126. +#ifndef VCHI_BULK_GRANULARITY
  18127. +# if __VCCOREVER__ >= 0x04000000
  18128. +# define VCHI_BULK_GRANULARITY 32 // Allows for the need to do cache cleans
  18129. +# else
  18130. +# define VCHI_BULK_GRANULARITY 16
  18131. +# endif
  18132. +#endif
  18133. +
  18134. +/* The largest possible message to be queued with vchi_msg_queue. */
  18135. +#ifndef VCHI_MAX_MSG_SIZE
  18136. +# if defined VCHI_LOCAL_HOST_PORT
  18137. +# define VCHI_MAX_MSG_SIZE 16384 // makes file transfers fast, but should they be using bulk?
  18138. +# else
  18139. +# define VCHI_MAX_MSG_SIZE 4096 // NOTE: THIS MUST BE LARGER THAN OR EQUAL TO THE SIZE OF THE KHRONOS MERGE BUFFER!!
  18140. +# endif
  18141. +#endif
  18142. +
  18143. +/******************************************************************************************
  18144. + * Defines below are system configuration options, and should not be used by VCHI services.
  18145. + *****************************************************************************************/
  18146. +
  18147. +/* How many connections can we support? A localhost implementation uses 2 connections,
  18148. + * 1 for host-app, 1 for VMCS, and these are hooked together by a loopback MPHI VCFW
  18149. + * driver. */
  18150. +#ifndef VCHI_MAX_NUM_CONNECTIONS
  18151. +# define VCHI_MAX_NUM_CONNECTIONS 3
  18152. +#endif
  18153. +
  18154. +/* How many services can we open per connection? Extending this doesn't cost processing time, just a small
  18155. + * amount of static memory. */
  18156. +#ifndef VCHI_MAX_SERVICES_PER_CONNECTION
  18157. +# define VCHI_MAX_SERVICES_PER_CONNECTION 36
  18158. +#endif
  18159. +
  18160. +/* Adjust if using a message driver that supports more logical TX channels */
  18161. +#ifndef VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION
  18162. +# define VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION 9 // 1 MPHI + 8 CCP2 logical channels
  18163. +#endif
  18164. +
  18165. +/* Adjust if using a message driver that supports more logical RX channels */
  18166. +#ifndef VCHI_MAX_BULK_RX_CHANNELS_PER_CONNECTION
  18167. +# define VCHI_MAX_BULK_RX_CHANNELS_PER_CONNECTION 1 // 1 MPHI
  18168. +#endif
  18169. +
  18170. +/* How many receive slots do we use. This times VCHI_MAX_MSG_SIZE gives the effective
  18171. + * receive queue space, less message headers. */
  18172. +#ifndef VCHI_NUM_READ_SLOTS
  18173. +# if defined(VCHI_LOCAL_HOST_PORT)
  18174. +# define VCHI_NUM_READ_SLOTS 4
  18175. +# else
  18176. +# define VCHI_NUM_READ_SLOTS 48
  18177. +# endif
  18178. +#endif
  18179. +
  18180. +/* Do we utilise overrun facility for receive message slots? Can aid peer transmit
  18181. + * performance. Only define on VideoCore end, talking to host.
  18182. + */
  18183. +//#define VCHI_MSG_RX_OVERRUN
  18184. +
  18185. +/* How many transmit slots do we use. Generally don't need many, as the hardware driver
  18186. + * underneath VCHI will usually have its own buffering. */
  18187. +#ifndef VCHI_NUM_WRITE_SLOTS
  18188. +# define VCHI_NUM_WRITE_SLOTS 4
  18189. +#endif
  18190. +
  18191. +/* If a service has held or queued received messages in VCHI_XOFF_THRESHOLD or more slots,
  18192. + * then it's taking up too much buffer space, and the peer service will be told to stop
  18193. + * transmitting with an XOFF message. For this to be effective, the VCHI_NUM_READ_SLOTS
  18194. + * needs to be considerably bigger than VCHI_NUM_WRITE_SLOTS, or the transmit latency
  18195. + * is too high. */
  18196. +#ifndef VCHI_XOFF_THRESHOLD
  18197. +# define VCHI_XOFF_THRESHOLD (VCHI_NUM_READ_SLOTS / 2)
  18198. +#endif
  18199. +
  18200. +/* After we've sent an XOFF, the peer will be told to resume transmission once the local
  18201. + * service has dequeued/released enough messages that it's now occupying
  18202. + * VCHI_XON_THRESHOLD slots or fewer. */
  18203. +#ifndef VCHI_XON_THRESHOLD
  18204. +# define VCHI_XON_THRESHOLD (VCHI_NUM_READ_SLOTS / 4)
  18205. +#endif
  18206. +
  18207. +/* A size below which a bulk transfer omits the handshake completely and always goes
  18208. + * via the message channel, if bulk auxiliary is being sent on that service. (The user
  18209. + * can guarantee this by enabling unaligned transmits).
  18210. + * Not API. */
  18211. +#ifndef VCHI_MIN_BULK_SIZE
  18212. +# define VCHI_MIN_BULK_SIZE ( VCHI_MAX_MSG_SIZE / 2 < 4096 ? VCHI_MAX_MSG_SIZE / 2 : 4096 )
  18213. +#endif
  18214. +
  18215. +/* Maximum size of bulk transmission chunks, for each interface type. A trade-off between
  18216. + * speed and latency; the smaller the chunk size the better change of messages and other
  18217. + * bulk transmissions getting in when big bulk transfers are happening. Set to 0 to not
  18218. + * break transmissions into chunks.
  18219. + */
  18220. +#ifndef VCHI_MAX_BULK_CHUNK_SIZE_MPHI
  18221. +# define VCHI_MAX_BULK_CHUNK_SIZE_MPHI (16 * 1024)
  18222. +#endif
  18223. +
  18224. +/* NB Chunked CCP2 transmissions violate the letter of the CCP2 spec by using "JPEG8" mode
  18225. + * with multiple-line frames. Only use if the receiver can cope. */
  18226. +#ifndef VCHI_MAX_BULK_CHUNK_SIZE_CCP2
  18227. +# define VCHI_MAX_BULK_CHUNK_SIZE_CCP2 0
  18228. +#endif
  18229. +
  18230. +/* How many TX messages can we have pending in our transmit slots. Once exhausted,
  18231. + * vchi_msg_queue will be blocked. */
  18232. +#ifndef VCHI_TX_MSG_QUEUE_SIZE
  18233. +# define VCHI_TX_MSG_QUEUE_SIZE 256
  18234. +#endif
  18235. +
  18236. +/* How many RX messages can we have parsed in the receive slots. Once exhausted, parsing
  18237. + * will be suspended until older messages are dequeued/released. */
  18238. +#ifndef VCHI_RX_MSG_QUEUE_SIZE
  18239. +# define VCHI_RX_MSG_QUEUE_SIZE 256
  18240. +#endif
  18241. +
  18242. +/* Really should be able to cope if we run out of received message descriptors, by
  18243. + * suspending parsing as the comment above says, but we don't. This sweeps the issue
  18244. + * under the carpet. */
  18245. +#if VCHI_RX_MSG_QUEUE_SIZE < (VCHI_MAX_MSG_SIZE/16 + 1) * VCHI_NUM_READ_SLOTS
  18246. +# undef VCHI_RX_MSG_QUEUE_SIZE
  18247. +# define VCHI_RX_MSG_QUEUE_SIZE (VCHI_MAX_MSG_SIZE/16 + 1) * VCHI_NUM_READ_SLOTS
  18248. +#endif
  18249. +
  18250. +/* How many bulk transmits can we have pending. Once exhausted, vchi_bulk_queue_transmit
  18251. + * will be blocked. */
  18252. +#ifndef VCHI_TX_BULK_QUEUE_SIZE
  18253. +# define VCHI_TX_BULK_QUEUE_SIZE 64
  18254. +#endif
  18255. +
  18256. +/* How many bulk receives can we have pending. Once exhausted, vchi_bulk_queue_receive
  18257. + * will be blocked. */
  18258. +#ifndef VCHI_RX_BULK_QUEUE_SIZE
  18259. +# define VCHI_RX_BULK_QUEUE_SIZE 64
  18260. +#endif
  18261. +
  18262. +/* A limit on how many outstanding bulk requests we expect the peer to give us. If
  18263. + * the peer asks for more than this, VCHI will fail and assert. The number is determined
  18264. + * by the peer's hardware - it's the number of outstanding requests that can be queued
  18265. + * on all bulk channels. VC3's MPHI peripheral allows 16. */
  18266. +#ifndef VCHI_MAX_PEER_BULK_REQUESTS
  18267. +# define VCHI_MAX_PEER_BULK_REQUESTS 32
  18268. +#endif
  18269. +
  18270. +/* Define VCHI_CCP2TX_MANUAL_POWER if the host tells us when to turn the CCP2
  18271. + * transmitter on and off.
  18272. + */
  18273. +/*#define VCHI_CCP2TX_MANUAL_POWER*/
  18274. +
  18275. +#ifndef VCHI_CCP2TX_MANUAL_POWER
  18276. +
  18277. +/* Timeout (in milliseconds) for putting the CCP2TX interface into IDLE state. Set
  18278. + * negative for no IDLE.
  18279. + */
  18280. +# ifndef VCHI_CCP2TX_IDLE_TIMEOUT
  18281. +# define VCHI_CCP2TX_IDLE_TIMEOUT 5
  18282. +# endif
  18283. +
  18284. +/* Timeout (in milliseconds) for putting the CCP2TX interface into OFF state. Set
  18285. + * negative for no OFF.
  18286. + */
  18287. +# ifndef VCHI_CCP2TX_OFF_TIMEOUT
  18288. +# define VCHI_CCP2TX_OFF_TIMEOUT 1000
  18289. +# endif
  18290. +
  18291. +#endif /* VCHI_CCP2TX_MANUAL_POWER */
  18292. +
  18293. +#endif /* VCHI_CFG_H_ */
  18294. +
  18295. +/****************************** End of file **********************************/
  18296. diff -Nur linux-3.13.11/drivers/misc/vc04_services/interface/vchi/vchi_cfg_internal.h linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_cfg_internal.h
  18297. --- linux-3.13.11/drivers/misc/vc04_services/interface/vchi/vchi_cfg_internal.h 1970-01-01 01:00:00.000000000 +0100
  18298. +++ linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_cfg_internal.h 2014-04-24 15:35:02.889551471 +0200
  18299. @@ -0,0 +1,71 @@
  18300. +/**
  18301. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  18302. + *
  18303. + * Redistribution and use in source and binary forms, with or without
  18304. + * modification, are permitted provided that the following conditions
  18305. + * are met:
  18306. + * 1. Redistributions of source code must retain the above copyright
  18307. + * notice, this list of conditions, and the following disclaimer,
  18308. + * without modification.
  18309. + * 2. Redistributions in binary form must reproduce the above copyright
  18310. + * notice, this list of conditions and the following disclaimer in the
  18311. + * documentation and/or other materials provided with the distribution.
  18312. + * 3. The names of the above-listed copyright holders may not be used
  18313. + * to endorse or promote products derived from this software without
  18314. + * specific prior written permission.
  18315. + *
  18316. + * ALTERNATIVELY, this software may be distributed under the terms of the
  18317. + * GNU General Public License ("GPL") version 2, as published by the Free
  18318. + * Software Foundation.
  18319. + *
  18320. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  18321. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  18322. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  18323. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  18324. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18325. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  18326. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  18327. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  18328. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  18329. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  18330. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  18331. + */
  18332. +
  18333. +#ifndef VCHI_CFG_INTERNAL_H_
  18334. +#define VCHI_CFG_INTERNAL_H_
  18335. +
  18336. +/****************************************************************************************
  18337. + * Control optimisation attempts.
  18338. + ***************************************************************************************/
  18339. +
  18340. +// Don't use lots of short-term locks - use great long ones, reducing the overall locks-per-second
  18341. +#define VCHI_COARSE_LOCKING
  18342. +
  18343. +// Avoid lock then unlock on exit from blocking queue operations (msg tx, bulk rx/tx)
  18344. +// (only relevant if VCHI_COARSE_LOCKING)
  18345. +#define VCHI_ELIDE_BLOCK_EXIT_LOCK
  18346. +
  18347. +// Avoid lock on non-blocking peek
  18348. +// (only relevant if VCHI_COARSE_LOCKING)
  18349. +#define VCHI_AVOID_PEEK_LOCK
  18350. +
  18351. +// Use one slot-handler thread per connection, rather than 1 thread dealing with all connections in rotation.
  18352. +#define VCHI_MULTIPLE_HANDLER_THREADS
  18353. +
  18354. +// Put free descriptors onto the head of the free queue, rather than the tail, so that we don't thrash
  18355. +// our way through the pool of descriptors.
  18356. +#define VCHI_PUSH_FREE_DESCRIPTORS_ONTO_HEAD
  18357. +
  18358. +// Don't issue a MSG_AVAILABLE callback for every single message. Possibly only safe if VCHI_COARSE_LOCKING.
  18359. +#define VCHI_FEWER_MSG_AVAILABLE_CALLBACKS
  18360. +
  18361. +// Don't use message descriptors for TX messages that don't need them
  18362. +#define VCHI_MINIMISE_TX_MSG_DESCRIPTORS
  18363. +
  18364. +// Nano-locks for multiqueue
  18365. +//#define VCHI_MQUEUE_NANOLOCKS
  18366. +
  18367. +// Lock-free(er) dequeuing
  18368. +//#define VCHI_RX_NANOLOCKS
  18369. +
  18370. +#endif /*VCHI_CFG_INTERNAL_H_*/
  18371. diff -Nur linux-3.13.11/drivers/misc/vc04_services/interface/vchi/vchi_common.h linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_common.h
  18372. --- linux-3.13.11/drivers/misc/vc04_services/interface/vchi/vchi_common.h 1970-01-01 01:00:00.000000000 +0100
  18373. +++ linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_common.h 2014-04-24 15:35:02.889551471 +0200
  18374. @@ -0,0 +1,163 @@
  18375. +/**
  18376. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  18377. + *
  18378. + * Redistribution and use in source and binary forms, with or without
  18379. + * modification, are permitted provided that the following conditions
  18380. + * are met:
  18381. + * 1. Redistributions of source code must retain the above copyright
  18382. + * notice, this list of conditions, and the following disclaimer,
  18383. + * without modification.
  18384. + * 2. Redistributions in binary form must reproduce the above copyright
  18385. + * notice, this list of conditions and the following disclaimer in the
  18386. + * documentation and/or other materials provided with the distribution.
  18387. + * 3. The names of the above-listed copyright holders may not be used
  18388. + * to endorse or promote products derived from this software without
  18389. + * specific prior written permission.
  18390. + *
  18391. + * ALTERNATIVELY, this software may be distributed under the terms of the
  18392. + * GNU General Public License ("GPL") version 2, as published by the Free
  18393. + * Software Foundation.
  18394. + *
  18395. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  18396. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  18397. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  18398. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  18399. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18400. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  18401. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  18402. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  18403. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  18404. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  18405. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  18406. + */
  18407. +
  18408. +#ifndef VCHI_COMMON_H_
  18409. +#define VCHI_COMMON_H_
  18410. +
  18411. +
  18412. +//flags used when sending messages (must be bitmapped)
  18413. +typedef enum
  18414. +{
  18415. + VCHI_FLAGS_NONE = 0x0,
  18416. + 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)
  18417. + VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE = 0x2, // run a callback when message sent
  18418. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED = 0x4, // return once the transfer is in a queue ready to go
  18419. + VCHI_FLAGS_ALLOW_PARTIAL = 0x8,
  18420. + VCHI_FLAGS_BLOCK_UNTIL_DATA_READ = 0x10,
  18421. + VCHI_FLAGS_CALLBACK_WHEN_DATA_READ = 0x20,
  18422. +
  18423. + VCHI_FLAGS_ALIGN_SLOT = 0x000080, // internal use only
  18424. + VCHI_FLAGS_BULK_AUX_QUEUED = 0x010000, // internal use only
  18425. + VCHI_FLAGS_BULK_AUX_COMPLETE = 0x020000, // internal use only
  18426. + VCHI_FLAGS_BULK_DATA_QUEUED = 0x040000, // internal use only
  18427. + VCHI_FLAGS_BULK_DATA_COMPLETE = 0x080000, // internal use only
  18428. + VCHI_FLAGS_INTERNAL = 0xFF0000
  18429. +} VCHI_FLAGS_T;
  18430. +
  18431. +// constants for vchi_crc_control()
  18432. +typedef enum {
  18433. + VCHI_CRC_NOTHING = -1,
  18434. + VCHI_CRC_PER_SERVICE = 0,
  18435. + VCHI_CRC_EVERYTHING = 1,
  18436. +} VCHI_CRC_CONTROL_T;
  18437. +
  18438. +//callback reasons when an event occurs on a service
  18439. +typedef enum
  18440. +{
  18441. + VCHI_CALLBACK_REASON_MIN,
  18442. +
  18443. + //This indicates that there is data available
  18444. + //handle is the msg id that was transmitted with the data
  18445. + // When a message is received and there was no FULL message available previously, send callback
  18446. + // Tasks get kicked by the callback, reset their event and try and read from the fifo until it fails
  18447. + VCHI_CALLBACK_MSG_AVAILABLE,
  18448. + VCHI_CALLBACK_MSG_SENT,
  18449. + VCHI_CALLBACK_MSG_SPACE_AVAILABLE, // XXX not yet implemented
  18450. +
  18451. + // This indicates that a transfer from the other side has completed
  18452. + VCHI_CALLBACK_BULK_RECEIVED,
  18453. + //This indicates that data queued up to be sent has now gone
  18454. + //handle is the msg id that was used when sending the data
  18455. + VCHI_CALLBACK_BULK_SENT,
  18456. + VCHI_CALLBACK_BULK_RX_SPACE_AVAILABLE, // XXX not yet implemented
  18457. + VCHI_CALLBACK_BULK_TX_SPACE_AVAILABLE, // XXX not yet implemented
  18458. +
  18459. + VCHI_CALLBACK_SERVICE_CLOSED,
  18460. +
  18461. + // this side has sent XOFF to peer due to lack of data consumption by service
  18462. + // (suggests the service may need to take some recovery action if it has
  18463. + // been deliberately holding off consuming data)
  18464. + VCHI_CALLBACK_SENT_XOFF,
  18465. + VCHI_CALLBACK_SENT_XON,
  18466. +
  18467. + // indicates that a bulk transfer has finished reading the source buffer
  18468. + VCHI_CALLBACK_BULK_DATA_READ,
  18469. +
  18470. + // power notification events (currently host side only)
  18471. + VCHI_CALLBACK_PEER_OFF,
  18472. + VCHI_CALLBACK_PEER_SUSPENDED,
  18473. + VCHI_CALLBACK_PEER_ON,
  18474. + VCHI_CALLBACK_PEER_RESUMED,
  18475. + VCHI_CALLBACK_FORCED_POWER_OFF,
  18476. +
  18477. +#ifdef USE_VCHIQ_ARM
  18478. + // some extra notifications provided by vchiq_arm
  18479. + VCHI_CALLBACK_SERVICE_OPENED,
  18480. + VCHI_CALLBACK_BULK_RECEIVE_ABORTED,
  18481. + VCHI_CALLBACK_BULK_TRANSMIT_ABORTED,
  18482. +#endif
  18483. +
  18484. + VCHI_CALLBACK_REASON_MAX
  18485. +} VCHI_CALLBACK_REASON_T;
  18486. +
  18487. +//Calback used by all services / bulk transfers
  18488. +typedef void (*VCHI_CALLBACK_T)( void *callback_param, //my service local param
  18489. + VCHI_CALLBACK_REASON_T reason,
  18490. + void *handle ); //for transmitting msg's only
  18491. +
  18492. +
  18493. +
  18494. +/*
  18495. + * Define vector struct for scatter-gather (vector) operations
  18496. + * Vectors can be nested - if a vector element has negative length, then
  18497. + * the data pointer is treated as pointing to another vector array, with
  18498. + * '-vec_len' elements. Thus to append a header onto an existing vector,
  18499. + * you can do this:
  18500. + *
  18501. + * void foo(const VCHI_MSG_VECTOR_T *v, int n)
  18502. + * {
  18503. + * VCHI_MSG_VECTOR_T nv[2];
  18504. + * nv[0].vec_base = my_header;
  18505. + * nv[0].vec_len = sizeof my_header;
  18506. + * nv[1].vec_base = v;
  18507. + * nv[1].vec_len = -n;
  18508. + * ...
  18509. + *
  18510. + */
  18511. +typedef struct vchi_msg_vector {
  18512. + const void *vec_base;
  18513. + int32_t vec_len;
  18514. +} VCHI_MSG_VECTOR_T;
  18515. +
  18516. +// Opaque type for a connection API
  18517. +typedef struct opaque_vchi_connection_api_t VCHI_CONNECTION_API_T;
  18518. +
  18519. +// Opaque type for a message driver
  18520. +typedef struct opaque_vchi_message_driver_t VCHI_MESSAGE_DRIVER_T;
  18521. +
  18522. +
  18523. +// Iterator structure for reading ahead through received message queue. Allocated by client,
  18524. +// initialised by vchi_msg_look_ahead. Fields are for internal VCHI use only.
  18525. +// Iterates over messages in queue at the instant of the call to vchi_msg_lookahead -
  18526. +// will not proceed to messages received since. Behaviour is undefined if an iterator
  18527. +// is used again after messages for that service are removed/dequeued by any
  18528. +// means other than vchi_msg_iter_... calls on the iterator itself.
  18529. +typedef struct {
  18530. + struct opaque_vchi_service_t *service;
  18531. + void *last;
  18532. + void *next;
  18533. + void *remove;
  18534. +} VCHI_MSG_ITER_T;
  18535. +
  18536. +
  18537. +#endif // VCHI_COMMON_H_
  18538. diff -Nur linux-3.13.11/drivers/misc/vc04_services/interface/vchi/vchi.h linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi.h
  18539. --- linux-3.13.11/drivers/misc/vc04_services/interface/vchi/vchi.h 1970-01-01 01:00:00.000000000 +0100
  18540. +++ linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi.h 2014-04-24 15:35:02.889551471 +0200
  18541. @@ -0,0 +1,373 @@
  18542. +/**
  18543. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  18544. + *
  18545. + * Redistribution and use in source and binary forms, with or without
  18546. + * modification, are permitted provided that the following conditions
  18547. + * are met:
  18548. + * 1. Redistributions of source code must retain the above copyright
  18549. + * notice, this list of conditions, and the following disclaimer,
  18550. + * without modification.
  18551. + * 2. Redistributions in binary form must reproduce the above copyright
  18552. + * notice, this list of conditions and the following disclaimer in the
  18553. + * documentation and/or other materials provided with the distribution.
  18554. + * 3. The names of the above-listed copyright holders may not be used
  18555. + * to endorse or promote products derived from this software without
  18556. + * specific prior written permission.
  18557. + *
  18558. + * ALTERNATIVELY, this software may be distributed under the terms of the
  18559. + * GNU General Public License ("GPL") version 2, as published by the Free
  18560. + * Software Foundation.
  18561. + *
  18562. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  18563. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  18564. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  18565. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  18566. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18567. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  18568. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  18569. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  18570. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  18571. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  18572. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  18573. + */
  18574. +
  18575. +#ifndef VCHI_H_
  18576. +#define VCHI_H_
  18577. +
  18578. +#include "interface/vchi/vchi_cfg.h"
  18579. +#include "interface/vchi/vchi_common.h"
  18580. +#include "interface/vchi/connections/connection.h"
  18581. +#include "vchi_mh.h"
  18582. +
  18583. +
  18584. +/******************************************************************************
  18585. + Global defs
  18586. + *****************************************************************************/
  18587. +
  18588. +#define VCHI_BULK_ROUND_UP(x) ((((unsigned long)(x))+VCHI_BULK_ALIGN-1) & ~(VCHI_BULK_ALIGN-1))
  18589. +#define VCHI_BULK_ROUND_DOWN(x) (((unsigned long)(x)) & ~(VCHI_BULK_ALIGN-1))
  18590. +#define VCHI_BULK_ALIGN_NBYTES(x) (VCHI_BULK_ALIGNED(x) ? 0 : (VCHI_BULK_ALIGN - ((unsigned long)(x) & (VCHI_BULK_ALIGN-1))))
  18591. +
  18592. +#ifdef USE_VCHIQ_ARM
  18593. +#define VCHI_BULK_ALIGNED(x) 1
  18594. +#else
  18595. +#define VCHI_BULK_ALIGNED(x) (((unsigned long)(x) & (VCHI_BULK_ALIGN-1)) == 0)
  18596. +#endif
  18597. +
  18598. +struct vchi_version {
  18599. + uint32_t version;
  18600. + uint32_t version_min;
  18601. +};
  18602. +#define VCHI_VERSION(v_) { v_, v_ }
  18603. +#define VCHI_VERSION_EX(v_, m_) { v_, m_ }
  18604. +
  18605. +typedef enum
  18606. +{
  18607. + VCHI_VEC_POINTER,
  18608. + VCHI_VEC_HANDLE,
  18609. + VCHI_VEC_LIST
  18610. +} VCHI_MSG_VECTOR_TYPE_T;
  18611. +
  18612. +typedef struct vchi_msg_vector_ex {
  18613. +
  18614. + VCHI_MSG_VECTOR_TYPE_T type;
  18615. + union
  18616. + {
  18617. + // a memory handle
  18618. + struct
  18619. + {
  18620. + VCHI_MEM_HANDLE_T handle;
  18621. + uint32_t offset;
  18622. + int32_t vec_len;
  18623. + } handle;
  18624. +
  18625. + // an ordinary data pointer
  18626. + struct
  18627. + {
  18628. + const void *vec_base;
  18629. + int32_t vec_len;
  18630. + } ptr;
  18631. +
  18632. + // a nested vector list
  18633. + struct
  18634. + {
  18635. + struct vchi_msg_vector_ex *vec;
  18636. + uint32_t vec_len;
  18637. + } list;
  18638. + } u;
  18639. +} VCHI_MSG_VECTOR_EX_T;
  18640. +
  18641. +
  18642. +// Construct an entry in a msg vector for a pointer (p) of length (l)
  18643. +#define VCHI_VEC_POINTER(p,l) VCHI_VEC_POINTER, { { (VCHI_MEM_HANDLE_T)(p), (l) } }
  18644. +
  18645. +// Construct an entry in a msg vector for a message handle (h), starting at offset (o) of length (l)
  18646. +#define VCHI_VEC_HANDLE(h,o,l) VCHI_VEC_HANDLE, { { (h), (o), (l) } }
  18647. +
  18648. +// Macros to manipulate 'FOURCC' values
  18649. +#define MAKE_FOURCC(x) ((int32_t)( (x[0] << 24) | (x[1] << 16) | (x[2] << 8) | x[3] ))
  18650. +#define FOURCC_TO_CHAR(x) (x >> 24) & 0xFF,(x >> 16) & 0xFF,(x >> 8) & 0xFF, x & 0xFF
  18651. +
  18652. +
  18653. +// Opaque service information
  18654. +struct opaque_vchi_service_t;
  18655. +
  18656. +// Descriptor for a held message. Allocated by client, initialised by vchi_msg_hold,
  18657. +// vchi_msg_iter_hold or vchi_msg_iter_hold_next. Fields are for internal VCHI use only.
  18658. +typedef struct
  18659. +{
  18660. + struct opaque_vchi_service_t *service;
  18661. + void *message;
  18662. +} VCHI_HELD_MSG_T;
  18663. +
  18664. +
  18665. +
  18666. +// structure used to provide the information needed to open a server or a client
  18667. +typedef struct {
  18668. + struct vchi_version version;
  18669. + int32_t service_id;
  18670. + VCHI_CONNECTION_T *connection;
  18671. + uint32_t rx_fifo_size;
  18672. + uint32_t tx_fifo_size;
  18673. + VCHI_CALLBACK_T callback;
  18674. + void *callback_param;
  18675. + /* client intends to receive bulk transfers of
  18676. + odd lengths or into unaligned buffers */
  18677. + int32_t want_unaligned_bulk_rx;
  18678. + /* client intends to transmit bulk transfers of
  18679. + odd lengths or out of unaligned buffers */
  18680. + int32_t want_unaligned_bulk_tx;
  18681. + /* client wants to check CRCs on (bulk) xfers.
  18682. + Only needs to be set at 1 end - will do both directions. */
  18683. + int32_t want_crc;
  18684. +} SERVICE_CREATION_T;
  18685. +
  18686. +// Opaque handle for a VCHI instance
  18687. +typedef struct opaque_vchi_instance_handle_t *VCHI_INSTANCE_T;
  18688. +
  18689. +// Opaque handle for a server or client
  18690. +typedef struct opaque_vchi_service_handle_t *VCHI_SERVICE_HANDLE_T;
  18691. +
  18692. +// Service registration & startup
  18693. +typedef void (*VCHI_SERVICE_INIT)(VCHI_INSTANCE_T initialise_instance, VCHI_CONNECTION_T **connections, uint32_t num_connections);
  18694. +
  18695. +typedef struct service_info_tag {
  18696. + const char * const vll_filename; /* VLL to load to start this service. This is an empty string if VLL is "static" */
  18697. + VCHI_SERVICE_INIT init; /* Service initialisation function */
  18698. + void *vll_handle; /* VLL handle; NULL when unloaded or a "static VLL" in build */
  18699. +} SERVICE_INFO_T;
  18700. +
  18701. +/******************************************************************************
  18702. + Global funcs - implementation is specific to which side you are on (local / remote)
  18703. + *****************************************************************************/
  18704. +
  18705. +#ifdef __cplusplus
  18706. +extern "C" {
  18707. +#endif
  18708. +
  18709. +extern /*@observer@*/ VCHI_CONNECTION_T * vchi_create_connection( const VCHI_CONNECTION_API_T * function_table,
  18710. + const VCHI_MESSAGE_DRIVER_T * low_level);
  18711. +
  18712. +
  18713. +// Routine used to initialise the vchi on both local + remote connections
  18714. +extern int32_t vchi_initialise( VCHI_INSTANCE_T *instance_handle );
  18715. +
  18716. +extern int32_t vchi_exit( void );
  18717. +
  18718. +extern int32_t vchi_connect( VCHI_CONNECTION_T **connections,
  18719. + const uint32_t num_connections,
  18720. + VCHI_INSTANCE_T instance_handle );
  18721. +
  18722. +//When this is called, ensure that all services have no data pending.
  18723. +//Bulk transfers can remain 'queued'
  18724. +extern int32_t vchi_disconnect( VCHI_INSTANCE_T instance_handle );
  18725. +
  18726. +// Global control over bulk CRC checking
  18727. +extern int32_t vchi_crc_control( VCHI_CONNECTION_T *connection,
  18728. + VCHI_CRC_CONTROL_T control );
  18729. +
  18730. +// helper functions
  18731. +extern void * vchi_allocate_buffer(VCHI_SERVICE_HANDLE_T handle, uint32_t *length);
  18732. +extern void vchi_free_buffer(VCHI_SERVICE_HANDLE_T handle, void *address);
  18733. +extern uint32_t vchi_current_time(VCHI_INSTANCE_T instance_handle);
  18734. +
  18735. +
  18736. +/******************************************************************************
  18737. + Global service API
  18738. + *****************************************************************************/
  18739. +// Routine to create a named service
  18740. +extern int32_t vchi_service_create( VCHI_INSTANCE_T instance_handle,
  18741. + SERVICE_CREATION_T *setup,
  18742. + VCHI_SERVICE_HANDLE_T *handle );
  18743. +
  18744. +// Routine to destory a service
  18745. +extern int32_t vchi_service_destroy( const VCHI_SERVICE_HANDLE_T handle );
  18746. +
  18747. +// Routine to open a named service
  18748. +extern int32_t vchi_service_open( VCHI_INSTANCE_T instance_handle,
  18749. + SERVICE_CREATION_T *setup,
  18750. + VCHI_SERVICE_HANDLE_T *handle);
  18751. +
  18752. +extern int32_t vchi_get_peer_version( const VCHI_SERVICE_HANDLE_T handle,
  18753. + short *peer_version );
  18754. +
  18755. +// Routine to close a named service
  18756. +extern int32_t vchi_service_close( const VCHI_SERVICE_HANDLE_T handle );
  18757. +
  18758. +// Routine to increment ref count on a named service
  18759. +extern int32_t vchi_service_use( const VCHI_SERVICE_HANDLE_T handle );
  18760. +
  18761. +// Routine to decrement ref count on a named service
  18762. +extern int32_t vchi_service_release( const VCHI_SERVICE_HANDLE_T handle );
  18763. +
  18764. +// Routine to send a message accross a service
  18765. +extern int32_t vchi_msg_queue( VCHI_SERVICE_HANDLE_T handle,
  18766. + const void *data,
  18767. + uint32_t data_size,
  18768. + VCHI_FLAGS_T flags,
  18769. + void *msg_handle );
  18770. +
  18771. +// scatter-gather (vector) and send message
  18772. +int32_t vchi_msg_queuev_ex( VCHI_SERVICE_HANDLE_T handle,
  18773. + VCHI_MSG_VECTOR_EX_T *vector,
  18774. + uint32_t count,
  18775. + VCHI_FLAGS_T flags,
  18776. + void *msg_handle );
  18777. +
  18778. +// legacy scatter-gather (vector) and send message, only handles pointers
  18779. +int32_t vchi_msg_queuev( VCHI_SERVICE_HANDLE_T handle,
  18780. + VCHI_MSG_VECTOR_T *vector,
  18781. + uint32_t count,
  18782. + VCHI_FLAGS_T flags,
  18783. + void *msg_handle );
  18784. +
  18785. +// Routine to receive a msg from a service
  18786. +// Dequeue is equivalent to hold, copy into client buffer, release
  18787. +extern int32_t vchi_msg_dequeue( VCHI_SERVICE_HANDLE_T handle,
  18788. + void *data,
  18789. + uint32_t max_data_size_to_read,
  18790. + uint32_t *actual_msg_size,
  18791. + VCHI_FLAGS_T flags );
  18792. +
  18793. +// Routine to look at a message in place.
  18794. +// The message is not dequeued, so a subsequent call to peek or dequeue
  18795. +// will return the same message.
  18796. +extern int32_t vchi_msg_peek( VCHI_SERVICE_HANDLE_T handle,
  18797. + void **data,
  18798. + uint32_t *msg_size,
  18799. + VCHI_FLAGS_T flags );
  18800. +
  18801. +// Routine to remove a message after it has been read in place with peek
  18802. +// The first message on the queue is dequeued.
  18803. +extern int32_t vchi_msg_remove( VCHI_SERVICE_HANDLE_T handle );
  18804. +
  18805. +// Routine to look at a message in place.
  18806. +// The message is dequeued, so the caller is left holding it; the descriptor is
  18807. +// filled in and must be released when the user has finished with the message.
  18808. +extern int32_t vchi_msg_hold( VCHI_SERVICE_HANDLE_T handle,
  18809. + void **data, // } may be NULL, as info can be
  18810. + uint32_t *msg_size, // } obtained from HELD_MSG_T
  18811. + VCHI_FLAGS_T flags,
  18812. + VCHI_HELD_MSG_T *message_descriptor );
  18813. +
  18814. +// Initialise an iterator to look through messages in place
  18815. +extern int32_t vchi_msg_look_ahead( VCHI_SERVICE_HANDLE_T handle,
  18816. + VCHI_MSG_ITER_T *iter,
  18817. + VCHI_FLAGS_T flags );
  18818. +
  18819. +/******************************************************************************
  18820. + Global service support API - operations on held messages and message iterators
  18821. + *****************************************************************************/
  18822. +
  18823. +// Routine to get the address of a held message
  18824. +extern void *vchi_held_msg_ptr( const VCHI_HELD_MSG_T *message );
  18825. +
  18826. +// Routine to get the size of a held message
  18827. +extern int32_t vchi_held_msg_size( const VCHI_HELD_MSG_T *message );
  18828. +
  18829. +// Routine to get the transmit timestamp as written into the header by the peer
  18830. +extern uint32_t vchi_held_msg_tx_timestamp( const VCHI_HELD_MSG_T *message );
  18831. +
  18832. +// Routine to get the reception timestamp, written as we parsed the header
  18833. +extern uint32_t vchi_held_msg_rx_timestamp( const VCHI_HELD_MSG_T *message );
  18834. +
  18835. +// Routine to release a held message after it has been processed
  18836. +extern int32_t vchi_held_msg_release( VCHI_HELD_MSG_T *message );
  18837. +
  18838. +// Indicates whether the iterator has a next message.
  18839. +extern int32_t vchi_msg_iter_has_next( const VCHI_MSG_ITER_T *iter );
  18840. +
  18841. +// Return the pointer and length for the next message and advance the iterator.
  18842. +extern int32_t vchi_msg_iter_next( VCHI_MSG_ITER_T *iter,
  18843. + void **data,
  18844. + uint32_t *msg_size );
  18845. +
  18846. +// Remove the last message returned by vchi_msg_iter_next.
  18847. +// Can only be called once after each call to vchi_msg_iter_next.
  18848. +extern int32_t vchi_msg_iter_remove( VCHI_MSG_ITER_T *iter );
  18849. +
  18850. +// Hold the last message returned by vchi_msg_iter_next.
  18851. +// Can only be called once after each call to vchi_msg_iter_next.
  18852. +extern int32_t vchi_msg_iter_hold( VCHI_MSG_ITER_T *iter,
  18853. + VCHI_HELD_MSG_T *message );
  18854. +
  18855. +// Return information for the next message, and hold it, advancing the iterator.
  18856. +extern int32_t vchi_msg_iter_hold_next( VCHI_MSG_ITER_T *iter,
  18857. + void **data, // } may be NULL
  18858. + uint32_t *msg_size, // }
  18859. + VCHI_HELD_MSG_T *message );
  18860. +
  18861. +
  18862. +/******************************************************************************
  18863. + Global bulk API
  18864. + *****************************************************************************/
  18865. +
  18866. +// Routine to prepare interface for a transfer from the other side
  18867. +extern int32_t vchi_bulk_queue_receive( VCHI_SERVICE_HANDLE_T handle,
  18868. + void *data_dst,
  18869. + uint32_t data_size,
  18870. + VCHI_FLAGS_T flags,
  18871. + void *transfer_handle );
  18872. +
  18873. +
  18874. +// Prepare interface for a transfer from the other side into relocatable memory.
  18875. +int32_t vchi_bulk_queue_receive_reloc( const VCHI_SERVICE_HANDLE_T handle,
  18876. + VCHI_MEM_HANDLE_T h_dst,
  18877. + uint32_t offset,
  18878. + uint32_t data_size,
  18879. + const VCHI_FLAGS_T flags,
  18880. + void * const bulk_handle );
  18881. +
  18882. +// Routine to queue up data ready for transfer to the other (once they have signalled they are ready)
  18883. +extern int32_t vchi_bulk_queue_transmit( VCHI_SERVICE_HANDLE_T handle,
  18884. + const void *data_src,
  18885. + uint32_t data_size,
  18886. + VCHI_FLAGS_T flags,
  18887. + void *transfer_handle );
  18888. +
  18889. +
  18890. +/******************************************************************************
  18891. + Configuration plumbing
  18892. + *****************************************************************************/
  18893. +
  18894. +// function prototypes for the different mid layers (the state info gives the different physical connections)
  18895. +extern const VCHI_CONNECTION_API_T *single_get_func_table( void );
  18896. +//extern const VCHI_CONNECTION_API_T *local_server_get_func_table( void );
  18897. +//extern const VCHI_CONNECTION_API_T *local_client_get_func_table( void );
  18898. +
  18899. +// declare all message drivers here
  18900. +const VCHI_MESSAGE_DRIVER_T *vchi_mphi_message_driver_func_table( void );
  18901. +
  18902. +#ifdef __cplusplus
  18903. +}
  18904. +#endif
  18905. +
  18906. +extern int32_t vchi_bulk_queue_transmit_reloc( VCHI_SERVICE_HANDLE_T handle,
  18907. + VCHI_MEM_HANDLE_T h_src,
  18908. + uint32_t offset,
  18909. + uint32_t data_size,
  18910. + VCHI_FLAGS_T flags,
  18911. + void *transfer_handle );
  18912. +#endif /* VCHI_H_ */
  18913. +
  18914. +/****************************** End of file **********************************/
  18915. diff -Nur linux-3.13.11/drivers/misc/vc04_services/interface/vchi/vchi_mh.h linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_mh.h
  18916. --- linux-3.13.11/drivers/misc/vc04_services/interface/vchi/vchi_mh.h 1970-01-01 01:00:00.000000000 +0100
  18917. +++ linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_mh.h 2014-04-24 15:35:02.893551516 +0200
  18918. @@ -0,0 +1,42 @@
  18919. +/**
  18920. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  18921. + *
  18922. + * Redistribution and use in source and binary forms, with or without
  18923. + * modification, are permitted provided that the following conditions
  18924. + * are met:
  18925. + * 1. Redistributions of source code must retain the above copyright
  18926. + * notice, this list of conditions, and the following disclaimer,
  18927. + * without modification.
  18928. + * 2. Redistributions in binary form must reproduce the above copyright
  18929. + * notice, this list of conditions and the following disclaimer in the
  18930. + * documentation and/or other materials provided with the distribution.
  18931. + * 3. The names of the above-listed copyright holders may not be used
  18932. + * to endorse or promote products derived from this software without
  18933. + * specific prior written permission.
  18934. + *
  18935. + * ALTERNATIVELY, this software may be distributed under the terms of the
  18936. + * GNU General Public License ("GPL") version 2, as published by the Free
  18937. + * Software Foundation.
  18938. + *
  18939. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  18940. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  18941. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  18942. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  18943. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18944. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  18945. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  18946. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  18947. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  18948. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  18949. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  18950. + */
  18951. +
  18952. +#ifndef VCHI_MH_H_
  18953. +#define VCHI_MH_H_
  18954. +
  18955. +#include <linux/types.h>
  18956. +
  18957. +typedef int32_t VCHI_MEM_HANDLE_T;
  18958. +#define VCHI_MEM_HANDLE_INVALID 0
  18959. +
  18960. +#endif
  18961. diff -Nur linux-3.13.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
  18962. --- linux-3.13.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c 1970-01-01 01:00:00.000000000 +0100
  18963. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c 2014-04-24 15:35:02.893551516 +0200
  18964. @@ -0,0 +1,561 @@
  18965. +/**
  18966. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  18967. + *
  18968. + * Redistribution and use in source and binary forms, with or without
  18969. + * modification, are permitted provided that the following conditions
  18970. + * are met:
  18971. + * 1. Redistributions of source code must retain the above copyright
  18972. + * notice, this list of conditions, and the following disclaimer,
  18973. + * without modification.
  18974. + * 2. Redistributions in binary form must reproduce the above copyright
  18975. + * notice, this list of conditions and the following disclaimer in the
  18976. + * documentation and/or other materials provided with the distribution.
  18977. + * 3. The names of the above-listed copyright holders may not be used
  18978. + * to endorse or promote products derived from this software without
  18979. + * specific prior written permission.
  18980. + *
  18981. + * ALTERNATIVELY, this software may be distributed under the terms of the
  18982. + * GNU General Public License ("GPL") version 2, as published by the Free
  18983. + * Software Foundation.
  18984. + *
  18985. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  18986. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  18987. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  18988. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  18989. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18990. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  18991. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  18992. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  18993. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  18994. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  18995. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  18996. + */
  18997. +
  18998. +#include <linux/kernel.h>
  18999. +#include <linux/types.h>
  19000. +#include <linux/errno.h>
  19001. +#include <linux/interrupt.h>
  19002. +#include <linux/irq.h>
  19003. +#include <linux/pagemap.h>
  19004. +#include <linux/dma-mapping.h>
  19005. +#include <linux/version.h>
  19006. +#include <linux/io.h>
  19007. +#include <linux/uaccess.h>
  19008. +#include <asm/pgtable.h>
  19009. +
  19010. +#include <mach/irqs.h>
  19011. +
  19012. +#include <mach/platform.h>
  19013. +#include <mach/vcio.h>
  19014. +
  19015. +#define TOTAL_SLOTS (VCHIQ_SLOT_ZERO_SLOTS + 2 * 32)
  19016. +
  19017. +#define VCHIQ_DOORBELL_IRQ IRQ_ARM_DOORBELL_0
  19018. +#define VCHIQ_ARM_ADDRESS(x) ((void *)__virt_to_bus((unsigned)x))
  19019. +
  19020. +#include "vchiq_arm.h"
  19021. +#include "vchiq_2835.h"
  19022. +#include "vchiq_connected.h"
  19023. +
  19024. +#define MAX_FRAGMENTS (VCHIQ_NUM_CURRENT_BULKS * 2)
  19025. +
  19026. +typedef struct vchiq_2835_state_struct {
  19027. + int inited;
  19028. + VCHIQ_ARM_STATE_T arm_state;
  19029. +} VCHIQ_2835_ARM_STATE_T;
  19030. +
  19031. +static char *g_slot_mem;
  19032. +static int g_slot_mem_size;
  19033. +dma_addr_t g_slot_phys;
  19034. +static FRAGMENTS_T *g_fragments_base;
  19035. +static FRAGMENTS_T *g_free_fragments;
  19036. +struct semaphore g_free_fragments_sema;
  19037. +
  19038. +extern int vchiq_arm_log_level;
  19039. +
  19040. +static DEFINE_SEMAPHORE(g_free_fragments_mutex);
  19041. +
  19042. +static irqreturn_t
  19043. +vchiq_doorbell_irq(int irq, void *dev_id);
  19044. +
  19045. +static int
  19046. +create_pagelist(char __user *buf, size_t count, unsigned short type,
  19047. + struct task_struct *task, PAGELIST_T ** ppagelist);
  19048. +
  19049. +static void
  19050. +free_pagelist(PAGELIST_T *pagelist, int actual);
  19051. +
  19052. +int __init
  19053. +vchiq_platform_init(VCHIQ_STATE_T *state)
  19054. +{
  19055. + VCHIQ_SLOT_ZERO_T *vchiq_slot_zero;
  19056. + int frag_mem_size;
  19057. + int err;
  19058. + int i;
  19059. +
  19060. + /* Allocate space for the channels in coherent memory */
  19061. + g_slot_mem_size = PAGE_ALIGN(TOTAL_SLOTS * VCHIQ_SLOT_SIZE);
  19062. + frag_mem_size = PAGE_ALIGN(sizeof(FRAGMENTS_T) * MAX_FRAGMENTS);
  19063. +
  19064. + g_slot_mem = dma_alloc_coherent(NULL, g_slot_mem_size + frag_mem_size,
  19065. + &g_slot_phys, GFP_ATOMIC);
  19066. +
  19067. + if (!g_slot_mem) {
  19068. + vchiq_log_error(vchiq_arm_log_level,
  19069. + "Unable to allocate channel memory");
  19070. + err = -ENOMEM;
  19071. + goto failed_alloc;
  19072. + }
  19073. +
  19074. + WARN_ON(((int)g_slot_mem & (PAGE_SIZE - 1)) != 0);
  19075. +
  19076. + vchiq_slot_zero = vchiq_init_slots(g_slot_mem, g_slot_mem_size);
  19077. + if (!vchiq_slot_zero) {
  19078. + err = -EINVAL;
  19079. + goto failed_init_slots;
  19080. + }
  19081. +
  19082. + vchiq_slot_zero->platform_data[VCHIQ_PLATFORM_FRAGMENTS_OFFSET_IDX] =
  19083. + (int)g_slot_phys + g_slot_mem_size;
  19084. + vchiq_slot_zero->platform_data[VCHIQ_PLATFORM_FRAGMENTS_COUNT_IDX] =
  19085. + MAX_FRAGMENTS;
  19086. +
  19087. + g_fragments_base = (FRAGMENTS_T *)(g_slot_mem + g_slot_mem_size);
  19088. + g_slot_mem_size += frag_mem_size;
  19089. +
  19090. + g_free_fragments = g_fragments_base;
  19091. + for (i = 0; i < (MAX_FRAGMENTS - 1); i++) {
  19092. + *(FRAGMENTS_T **)&g_fragments_base[i] =
  19093. + &g_fragments_base[i + 1];
  19094. + }
  19095. + *(FRAGMENTS_T **)&g_fragments_base[i] = NULL;
  19096. + sema_init(&g_free_fragments_sema, MAX_FRAGMENTS);
  19097. +
  19098. + if (vchiq_init_state(state, vchiq_slot_zero, 0/*slave*/) !=
  19099. + VCHIQ_SUCCESS) {
  19100. + err = -EINVAL;
  19101. + goto failed_vchiq_init;
  19102. + }
  19103. +
  19104. + err = request_irq(VCHIQ_DOORBELL_IRQ, vchiq_doorbell_irq,
  19105. + IRQF_IRQPOLL, "VCHIQ doorbell",
  19106. + state);
  19107. + if (err < 0) {
  19108. + vchiq_log_error(vchiq_arm_log_level, "%s: failed to register "
  19109. + "irq=%d err=%d", __func__,
  19110. + VCHIQ_DOORBELL_IRQ, err);
  19111. + goto failed_request_irq;
  19112. + }
  19113. +
  19114. + /* Send the base address of the slots to VideoCore */
  19115. +
  19116. + dsb(); /* Ensure all writes have completed */
  19117. +
  19118. + bcm_mailbox_write(MBOX_CHAN_VCHIQ, (unsigned int)g_slot_phys);
  19119. +
  19120. + vchiq_log_info(vchiq_arm_log_level,
  19121. + "vchiq_init - done (slots %x, phys %x)",
  19122. + (unsigned int)vchiq_slot_zero, g_slot_phys);
  19123. +
  19124. + vchiq_call_connected_callbacks();
  19125. +
  19126. + return 0;
  19127. +
  19128. +failed_request_irq:
  19129. +failed_vchiq_init:
  19130. +failed_init_slots:
  19131. + dma_free_coherent(NULL, g_slot_mem_size, g_slot_mem, g_slot_phys);
  19132. +
  19133. +failed_alloc:
  19134. + return err;
  19135. +}
  19136. +
  19137. +void __exit
  19138. +vchiq_platform_exit(VCHIQ_STATE_T *state)
  19139. +{
  19140. + free_irq(VCHIQ_DOORBELL_IRQ, state);
  19141. + dma_free_coherent(NULL, g_slot_mem_size,
  19142. + g_slot_mem, g_slot_phys);
  19143. +}
  19144. +
  19145. +
  19146. +VCHIQ_STATUS_T
  19147. +vchiq_platform_init_state(VCHIQ_STATE_T *state)
  19148. +{
  19149. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  19150. + state->platform_state = kzalloc(sizeof(VCHIQ_2835_ARM_STATE_T), GFP_KERNEL);
  19151. + ((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->inited = 1;
  19152. + status = vchiq_arm_init_state(state, &((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->arm_state);
  19153. + if(status != VCHIQ_SUCCESS)
  19154. + {
  19155. + ((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->inited = 0;
  19156. + }
  19157. + return status;
  19158. +}
  19159. +
  19160. +VCHIQ_ARM_STATE_T*
  19161. +vchiq_platform_get_arm_state(VCHIQ_STATE_T *state)
  19162. +{
  19163. + if(!((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->inited)
  19164. + {
  19165. + BUG();
  19166. + }
  19167. + return &((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->arm_state;
  19168. +}
  19169. +
  19170. +void
  19171. +remote_event_signal(REMOTE_EVENT_T *event)
  19172. +{
  19173. + wmb();
  19174. +
  19175. + event->fired = 1;
  19176. +
  19177. + dsb(); /* data barrier operation */
  19178. +
  19179. + if (event->armed) {
  19180. + /* trigger vc interrupt */
  19181. +
  19182. + writel(0, __io_address(ARM_0_BELL2));
  19183. + }
  19184. +}
  19185. +
  19186. +int
  19187. +vchiq_copy_from_user(void *dst, const void *src, int size)
  19188. +{
  19189. + if ((uint32_t)src < TASK_SIZE) {
  19190. + return copy_from_user(dst, src, size);
  19191. + } else {
  19192. + memcpy(dst, src, size);
  19193. + return 0;
  19194. + }
  19195. +}
  19196. +
  19197. +VCHIQ_STATUS_T
  19198. +vchiq_prepare_bulk_data(VCHIQ_BULK_T *bulk, VCHI_MEM_HANDLE_T memhandle,
  19199. + void *offset, int size, int dir)
  19200. +{
  19201. + PAGELIST_T *pagelist;
  19202. + int ret;
  19203. +
  19204. + WARN_ON(memhandle != VCHI_MEM_HANDLE_INVALID);
  19205. +
  19206. + ret = create_pagelist((char __user *)offset, size,
  19207. + (dir == VCHIQ_BULK_RECEIVE)
  19208. + ? PAGELIST_READ
  19209. + : PAGELIST_WRITE,
  19210. + current,
  19211. + &pagelist);
  19212. + if (ret != 0)
  19213. + return VCHIQ_ERROR;
  19214. +
  19215. + bulk->handle = memhandle;
  19216. + bulk->data = VCHIQ_ARM_ADDRESS(pagelist);
  19217. +
  19218. + /* Store the pagelist address in remote_data, which isn't used by the
  19219. + slave. */
  19220. + bulk->remote_data = pagelist;
  19221. +
  19222. + return VCHIQ_SUCCESS;
  19223. +}
  19224. +
  19225. +void
  19226. +vchiq_complete_bulk(VCHIQ_BULK_T *bulk)
  19227. +{
  19228. + if (bulk && bulk->remote_data && bulk->actual)
  19229. + free_pagelist((PAGELIST_T *)bulk->remote_data, bulk->actual);
  19230. +}
  19231. +
  19232. +void
  19233. +vchiq_transfer_bulk(VCHIQ_BULK_T *bulk)
  19234. +{
  19235. + /*
  19236. + * This should only be called on the master (VideoCore) side, but
  19237. + * provide an implementation to avoid the need for ifdefery.
  19238. + */
  19239. + BUG();
  19240. +}
  19241. +
  19242. +void
  19243. +vchiq_dump_platform_state(void *dump_context)
  19244. +{
  19245. + char buf[80];
  19246. + int len;
  19247. + len = snprintf(buf, sizeof(buf),
  19248. + " Platform: 2835 (VC master)");
  19249. + vchiq_dump(dump_context, buf, len + 1);
  19250. +}
  19251. +
  19252. +VCHIQ_STATUS_T
  19253. +vchiq_platform_suspend(VCHIQ_STATE_T *state)
  19254. +{
  19255. + return VCHIQ_ERROR;
  19256. +}
  19257. +
  19258. +VCHIQ_STATUS_T
  19259. +vchiq_platform_resume(VCHIQ_STATE_T *state)
  19260. +{
  19261. + return VCHIQ_SUCCESS;
  19262. +}
  19263. +
  19264. +void
  19265. +vchiq_platform_paused(VCHIQ_STATE_T *state)
  19266. +{
  19267. +}
  19268. +
  19269. +void
  19270. +vchiq_platform_resumed(VCHIQ_STATE_T *state)
  19271. +{
  19272. +}
  19273. +
  19274. +int
  19275. +vchiq_platform_videocore_wanted(VCHIQ_STATE_T* state)
  19276. +{
  19277. + return 1; // autosuspend not supported - videocore always wanted
  19278. +}
  19279. +
  19280. +int
  19281. +vchiq_platform_use_suspend_timer(void)
  19282. +{
  19283. + return 0;
  19284. +}
  19285. +void
  19286. +vchiq_dump_platform_use_state(VCHIQ_STATE_T *state)
  19287. +{
  19288. + vchiq_log_info((vchiq_arm_log_level>=VCHIQ_LOG_INFO),"Suspend timer not in use");
  19289. +}
  19290. +void
  19291. +vchiq_platform_handle_timeout(VCHIQ_STATE_T *state)
  19292. +{
  19293. + (void)state;
  19294. +}
  19295. +/*
  19296. + * Local functions
  19297. + */
  19298. +
  19299. +static irqreturn_t
  19300. +vchiq_doorbell_irq(int irq, void *dev_id)
  19301. +{
  19302. + VCHIQ_STATE_T *state = dev_id;
  19303. + irqreturn_t ret = IRQ_NONE;
  19304. + unsigned int status;
  19305. +
  19306. + /* Read (and clear) the doorbell */
  19307. + status = readl(__io_address(ARM_0_BELL0));
  19308. +
  19309. + if (status & 0x4) { /* Was the doorbell rung? */
  19310. + remote_event_pollall(state);
  19311. + ret = IRQ_HANDLED;
  19312. + }
  19313. +
  19314. + return ret;
  19315. +}
  19316. +
  19317. +/* There is a potential problem with partial cache lines (pages?)
  19318. +** at the ends of the block when reading. If the CPU accessed anything in
  19319. +** the same line (page?) then it may have pulled old data into the cache,
  19320. +** obscuring the new data underneath. We can solve this by transferring the
  19321. +** partial cache lines separately, and allowing the ARM to copy into the
  19322. +** cached area.
  19323. +
  19324. +** N.B. This implementation plays slightly fast and loose with the Linux
  19325. +** driver programming rules, e.g. its use of __virt_to_bus instead of
  19326. +** dma_map_single, but it isn't a multi-platform driver and it benefits
  19327. +** from increased speed as a result.
  19328. +*/
  19329. +
  19330. +static int
  19331. +create_pagelist(char __user *buf, size_t count, unsigned short type,
  19332. + struct task_struct *task, PAGELIST_T ** ppagelist)
  19333. +{
  19334. + PAGELIST_T *pagelist;
  19335. + struct page **pages;
  19336. + struct page *page;
  19337. + unsigned long *addrs;
  19338. + unsigned int num_pages, offset, i;
  19339. + char *addr, *base_addr, *next_addr;
  19340. + int run, addridx, actual_pages;
  19341. + unsigned long *need_release;
  19342. +
  19343. + offset = (unsigned int)buf & (PAGE_SIZE - 1);
  19344. + num_pages = (count + offset + PAGE_SIZE - 1) / PAGE_SIZE;
  19345. +
  19346. + *ppagelist = NULL;
  19347. +
  19348. + /* Allocate enough storage to hold the page pointers and the page
  19349. + ** list
  19350. + */
  19351. + pagelist = kmalloc(sizeof(PAGELIST_T) +
  19352. + (num_pages * sizeof(unsigned long)) +
  19353. + sizeof(unsigned long) +
  19354. + (num_pages * sizeof(pages[0])),
  19355. + GFP_KERNEL);
  19356. +
  19357. + vchiq_log_trace(vchiq_arm_log_level,
  19358. + "create_pagelist - %x", (unsigned int)pagelist);
  19359. + if (!pagelist)
  19360. + return -ENOMEM;
  19361. +
  19362. + addrs = pagelist->addrs;
  19363. + need_release = (unsigned long *)(addrs + num_pages);
  19364. + pages = (struct page **)(addrs + num_pages + 1);
  19365. +
  19366. + if (is_vmalloc_addr(buf)) {
  19367. + for (actual_pages = 0; actual_pages < num_pages; actual_pages++) {
  19368. + pages[actual_pages] = vmalloc_to_page(buf + (actual_pages * PAGE_SIZE));
  19369. + }
  19370. + *need_release = 0; /* do not try and release vmalloc pages */
  19371. + } else {
  19372. + down_read(&task->mm->mmap_sem);
  19373. + actual_pages = get_user_pages(task, task->mm,
  19374. + (unsigned long)buf & ~(PAGE_SIZE - 1),
  19375. + num_pages,
  19376. + (type == PAGELIST_READ) /*Write */ ,
  19377. + 0 /*Force */ ,
  19378. + pages,
  19379. + NULL /*vmas */);
  19380. + up_read(&task->mm->mmap_sem);
  19381. +
  19382. + if (actual_pages != num_pages) {
  19383. + vchiq_log_info(vchiq_arm_log_level,
  19384. + "create_pagelist - only %d/%d pages locked",
  19385. + actual_pages,
  19386. + num_pages);
  19387. +
  19388. + /* This is probably due to the process being killed */
  19389. + while (actual_pages > 0)
  19390. + {
  19391. + actual_pages--;
  19392. + page_cache_release(pages[actual_pages]);
  19393. + }
  19394. + kfree(pagelist);
  19395. + if (actual_pages == 0)
  19396. + actual_pages = -ENOMEM;
  19397. + return actual_pages;
  19398. + }
  19399. + *need_release = 1; /* release user pages */
  19400. + }
  19401. +
  19402. + pagelist->length = count;
  19403. + pagelist->type = type;
  19404. + pagelist->offset = offset;
  19405. +
  19406. + /* Group the pages into runs of contiguous pages */
  19407. +
  19408. + base_addr = VCHIQ_ARM_ADDRESS(page_address(pages[0]));
  19409. + next_addr = base_addr + PAGE_SIZE;
  19410. + addridx = 0;
  19411. + run = 0;
  19412. +
  19413. + for (i = 1; i < num_pages; i++) {
  19414. + addr = VCHIQ_ARM_ADDRESS(page_address(pages[i]));
  19415. + if ((addr == next_addr) && (run < (PAGE_SIZE - 1))) {
  19416. + next_addr += PAGE_SIZE;
  19417. + run++;
  19418. + } else {
  19419. + addrs[addridx] = (unsigned long)base_addr + run;
  19420. + addridx++;
  19421. + base_addr = addr;
  19422. + next_addr = addr + PAGE_SIZE;
  19423. + run = 0;
  19424. + }
  19425. + }
  19426. +
  19427. + addrs[addridx] = (unsigned long)base_addr + run;
  19428. + addridx++;
  19429. +
  19430. + /* Partial cache lines (fragments) require special measures */
  19431. + if ((type == PAGELIST_READ) &&
  19432. + ((pagelist->offset & (CACHE_LINE_SIZE - 1)) ||
  19433. + ((pagelist->offset + pagelist->length) &
  19434. + (CACHE_LINE_SIZE - 1)))) {
  19435. + FRAGMENTS_T *fragments;
  19436. +
  19437. + if (down_interruptible(&g_free_fragments_sema) != 0) {
  19438. + kfree(pagelist);
  19439. + return -EINTR;
  19440. + }
  19441. +
  19442. + WARN_ON(g_free_fragments == NULL);
  19443. +
  19444. + down(&g_free_fragments_mutex);
  19445. + fragments = (FRAGMENTS_T *) g_free_fragments;
  19446. + WARN_ON(fragments == NULL);
  19447. + g_free_fragments = *(FRAGMENTS_T **) g_free_fragments;
  19448. + up(&g_free_fragments_mutex);
  19449. + pagelist->type =
  19450. + PAGELIST_READ_WITH_FRAGMENTS + (fragments -
  19451. + g_fragments_base);
  19452. + }
  19453. +
  19454. + for (page = virt_to_page(pagelist);
  19455. + page <= virt_to_page(addrs + num_pages - 1); page++) {
  19456. + flush_dcache_page(page);
  19457. + }
  19458. +
  19459. + *ppagelist = pagelist;
  19460. +
  19461. + return 0;
  19462. +}
  19463. +
  19464. +static void
  19465. +free_pagelist(PAGELIST_T *pagelist, int actual)
  19466. +{
  19467. + unsigned long *need_release;
  19468. + struct page **pages;
  19469. + unsigned int num_pages, i;
  19470. +
  19471. + vchiq_log_trace(vchiq_arm_log_level,
  19472. + "free_pagelist - %x, %d", (unsigned int)pagelist, actual);
  19473. +
  19474. + num_pages =
  19475. + (pagelist->length + pagelist->offset + PAGE_SIZE - 1) /
  19476. + PAGE_SIZE;
  19477. +
  19478. + need_release = (unsigned long *)(pagelist->addrs + num_pages);
  19479. + pages = (struct page **)(pagelist->addrs + num_pages + 1);
  19480. +
  19481. + /* Deal with any partial cache lines (fragments) */
  19482. + if (pagelist->type >= PAGELIST_READ_WITH_FRAGMENTS) {
  19483. + FRAGMENTS_T *fragments = g_fragments_base +
  19484. + (pagelist->type - PAGELIST_READ_WITH_FRAGMENTS);
  19485. + int head_bytes, tail_bytes;
  19486. + head_bytes = (CACHE_LINE_SIZE - pagelist->offset) &
  19487. + (CACHE_LINE_SIZE - 1);
  19488. + tail_bytes = (pagelist->offset + actual) &
  19489. + (CACHE_LINE_SIZE - 1);
  19490. +
  19491. + if ((actual >= 0) && (head_bytes != 0)) {
  19492. + if (head_bytes > actual)
  19493. + head_bytes = actual;
  19494. +
  19495. + memcpy((char *)page_address(pages[0]) +
  19496. + pagelist->offset,
  19497. + fragments->headbuf,
  19498. + head_bytes);
  19499. + }
  19500. + if ((actual >= 0) && (head_bytes < actual) &&
  19501. + (tail_bytes != 0)) {
  19502. + memcpy((char *)page_address(pages[num_pages - 1]) +
  19503. + ((pagelist->offset + actual) &
  19504. + (PAGE_SIZE - 1) & ~(CACHE_LINE_SIZE - 1)),
  19505. + fragments->tailbuf, tail_bytes);
  19506. + }
  19507. +
  19508. + down(&g_free_fragments_mutex);
  19509. + *(FRAGMENTS_T **) fragments = g_free_fragments;
  19510. + g_free_fragments = fragments;
  19511. + up(&g_free_fragments_mutex);
  19512. + up(&g_free_fragments_sema);
  19513. + }
  19514. +
  19515. + if (*need_release) {
  19516. + for (i = 0; i < num_pages; i++) {
  19517. + if (pagelist->type != PAGELIST_WRITE)
  19518. + set_page_dirty(pages[i]);
  19519. +
  19520. + page_cache_release(pages[i]);
  19521. + }
  19522. + }
  19523. +
  19524. + kfree(pagelist);
  19525. +}
  19526. diff -Nur linux-3.13.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835.h
  19527. --- linux-3.13.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835.h 1970-01-01 01:00:00.000000000 +0100
  19528. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835.h 2014-04-24 15:35:02.893551516 +0200
  19529. @@ -0,0 +1,42 @@
  19530. +/**
  19531. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  19532. + *
  19533. + * Redistribution and use in source and binary forms, with or without
  19534. + * modification, are permitted provided that the following conditions
  19535. + * are met:
  19536. + * 1. Redistributions of source code must retain the above copyright
  19537. + * notice, this list of conditions, and the following disclaimer,
  19538. + * without modification.
  19539. + * 2. Redistributions in binary form must reproduce the above copyright
  19540. + * notice, this list of conditions and the following disclaimer in the
  19541. + * documentation and/or other materials provided with the distribution.
  19542. + * 3. The names of the above-listed copyright holders may not be used
  19543. + * to endorse or promote products derived from this software without
  19544. + * specific prior written permission.
  19545. + *
  19546. + * ALTERNATIVELY, this software may be distributed under the terms of the
  19547. + * GNU General Public License ("GPL") version 2, as published by the Free
  19548. + * Software Foundation.
  19549. + *
  19550. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  19551. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  19552. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19553. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  19554. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  19555. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19556. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  19557. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  19558. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  19559. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  19560. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  19561. + */
  19562. +
  19563. +#ifndef VCHIQ_2835_H
  19564. +#define VCHIQ_2835_H
  19565. +
  19566. +#include "vchiq_pagelist.h"
  19567. +
  19568. +#define VCHIQ_PLATFORM_FRAGMENTS_OFFSET_IDX 0
  19569. +#define VCHIQ_PLATFORM_FRAGMENTS_COUNT_IDX 1
  19570. +
  19571. +#endif /* VCHIQ_2835_H */
  19572. diff -Nur linux-3.13.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c
  19573. --- linux-3.13.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c 1970-01-01 01:00:00.000000000 +0100
  19574. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c 2014-04-24 15:36:51.710754091 +0200
  19575. @@ -0,0 +1,2813 @@
  19576. +/**
  19577. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  19578. + *
  19579. + * Redistribution and use in source and binary forms, with or without
  19580. + * modification, are permitted provided that the following conditions
  19581. + * are met:
  19582. + * 1. Redistributions of source code must retain the above copyright
  19583. + * notice, this list of conditions, and the following disclaimer,
  19584. + * without modification.
  19585. + * 2. Redistributions in binary form must reproduce the above copyright
  19586. + * notice, this list of conditions and the following disclaimer in the
  19587. + * documentation and/or other materials provided with the distribution.
  19588. + * 3. The names of the above-listed copyright holders may not be used
  19589. + * to endorse or promote products derived from this software without
  19590. + * specific prior written permission.
  19591. + *
  19592. + * ALTERNATIVELY, this software may be distributed under the terms of the
  19593. + * GNU General Public License ("GPL") version 2, as published by the Free
  19594. + * Software Foundation.
  19595. + *
  19596. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  19597. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  19598. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19599. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  19600. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  19601. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19602. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  19603. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  19604. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  19605. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  19606. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  19607. + */
  19608. +
  19609. +#include <linux/kernel.h>
  19610. +#include <linux/module.h>
  19611. +#include <linux/types.h>
  19612. +#include <linux/errno.h>
  19613. +#include <linux/cdev.h>
  19614. +#include <linux/fs.h>
  19615. +#include <linux/device.h>
  19616. +#include <linux/mm.h>
  19617. +#include <linux/highmem.h>
  19618. +#include <linux/pagemap.h>
  19619. +#include <linux/bug.h>
  19620. +#include <linux/semaphore.h>
  19621. +#include <linux/list.h>
  19622. +#include <linux/proc_fs.h>
  19623. +
  19624. +#include "vchiq_core.h"
  19625. +#include "vchiq_ioctl.h"
  19626. +#include "vchiq_arm.h"
  19627. +
  19628. +#define DEVICE_NAME "vchiq"
  19629. +
  19630. +/* Override the default prefix, which would be vchiq_arm (from the filename) */
  19631. +#undef MODULE_PARAM_PREFIX
  19632. +#define MODULE_PARAM_PREFIX DEVICE_NAME "."
  19633. +
  19634. +#define VCHIQ_MINOR 0
  19635. +
  19636. +/* Some per-instance constants */
  19637. +#define MAX_COMPLETIONS 16
  19638. +#define MAX_SERVICES 64
  19639. +#define MAX_ELEMENTS 8
  19640. +#define MSG_QUEUE_SIZE 64
  19641. +
  19642. +#define KEEPALIVE_VER 1
  19643. +#define KEEPALIVE_VER_MIN KEEPALIVE_VER
  19644. +
  19645. +/* Run time control of log level, based on KERN_XXX level. */
  19646. +int vchiq_arm_log_level = VCHIQ_LOG_DEFAULT;
  19647. +int vchiq_susp_log_level = VCHIQ_LOG_ERROR;
  19648. +
  19649. +#define SUSPEND_TIMER_TIMEOUT_MS 100
  19650. +#define SUSPEND_RETRY_TIMER_TIMEOUT_MS 1000
  19651. +
  19652. +#define VC_SUSPEND_NUM_OFFSET 3 /* number of values before idle which are -ve */
  19653. +static const char *const suspend_state_names[] = {
  19654. + "VC_SUSPEND_FORCE_CANCELED",
  19655. + "VC_SUSPEND_REJECTED",
  19656. + "VC_SUSPEND_FAILED",
  19657. + "VC_SUSPEND_IDLE",
  19658. + "VC_SUSPEND_REQUESTED",
  19659. + "VC_SUSPEND_IN_PROGRESS",
  19660. + "VC_SUSPEND_SUSPENDED"
  19661. +};
  19662. +#define VC_RESUME_NUM_OFFSET 1 /* number of values before idle which are -ve */
  19663. +static const char *const resume_state_names[] = {
  19664. + "VC_RESUME_FAILED",
  19665. + "VC_RESUME_IDLE",
  19666. + "VC_RESUME_REQUESTED",
  19667. + "VC_RESUME_IN_PROGRESS",
  19668. + "VC_RESUME_RESUMED"
  19669. +};
  19670. +/* The number of times we allow force suspend to timeout before actually
  19671. +** _forcing_ suspend. This is to cater for SW which fails to release vchiq
  19672. +** correctly - we don't want to prevent ARM suspend indefinitely in this case.
  19673. +*/
  19674. +#define FORCE_SUSPEND_FAIL_MAX 8
  19675. +
  19676. +/* The time in ms allowed for videocore to go idle when force suspend has been
  19677. + * requested */
  19678. +#define FORCE_SUSPEND_TIMEOUT_MS 200
  19679. +
  19680. +
  19681. +static void suspend_timer_callback(unsigned long context);
  19682. +static int vchiq_proc_add_instance(VCHIQ_INSTANCE_T instance);
  19683. +static void vchiq_proc_remove_instance(VCHIQ_INSTANCE_T instance);
  19684. +
  19685. +
  19686. +typedef struct user_service_struct {
  19687. + VCHIQ_SERVICE_T *service;
  19688. + void *userdata;
  19689. + VCHIQ_INSTANCE_T instance;
  19690. + int is_vchi;
  19691. + int dequeue_pending;
  19692. + int message_available_pos;
  19693. + int msg_insert;
  19694. + int msg_remove;
  19695. + struct semaphore insert_event;
  19696. + struct semaphore remove_event;
  19697. + VCHIQ_HEADER_T * msg_queue[MSG_QUEUE_SIZE];
  19698. +} USER_SERVICE_T;
  19699. +
  19700. +struct bulk_waiter_node {
  19701. + struct bulk_waiter bulk_waiter;
  19702. + int pid;
  19703. + struct list_head list;
  19704. +};
  19705. +
  19706. +struct vchiq_instance_struct {
  19707. + VCHIQ_STATE_T *state;
  19708. + VCHIQ_COMPLETION_DATA_T completions[MAX_COMPLETIONS];
  19709. + int completion_insert;
  19710. + int completion_remove;
  19711. + struct semaphore insert_event;
  19712. + struct semaphore remove_event;
  19713. + struct mutex completion_mutex;
  19714. +
  19715. + int connected;
  19716. + int closing;
  19717. + int pid;
  19718. + int mark;
  19719. +
  19720. + struct list_head bulk_waiter_list;
  19721. + struct mutex bulk_waiter_list_mutex;
  19722. +
  19723. + struct proc_dir_entry *proc_entry;
  19724. +};
  19725. +
  19726. +typedef struct dump_context_struct {
  19727. + char __user *buf;
  19728. + size_t actual;
  19729. + size_t space;
  19730. + loff_t offset;
  19731. +} DUMP_CONTEXT_T;
  19732. +
  19733. +static struct cdev vchiq_cdev;
  19734. +static dev_t vchiq_devid;
  19735. +static VCHIQ_STATE_T g_state;
  19736. +static struct class *vchiq_class;
  19737. +static struct device *vchiq_dev;
  19738. +static DEFINE_SPINLOCK(msg_queue_spinlock);
  19739. +
  19740. +static const char *const ioctl_names[] = {
  19741. + "CONNECT",
  19742. + "SHUTDOWN",
  19743. + "CREATE_SERVICE",
  19744. + "REMOVE_SERVICE",
  19745. + "QUEUE_MESSAGE",
  19746. + "QUEUE_BULK_TRANSMIT",
  19747. + "QUEUE_BULK_RECEIVE",
  19748. + "AWAIT_COMPLETION",
  19749. + "DEQUEUE_MESSAGE",
  19750. + "GET_CLIENT_ID",
  19751. + "GET_CONFIG",
  19752. + "CLOSE_SERVICE",
  19753. + "USE_SERVICE",
  19754. + "RELEASE_SERVICE",
  19755. + "SET_SERVICE_OPTION",
  19756. + "DUMP_PHYS_MEM"
  19757. +};
  19758. +
  19759. +vchiq_static_assert((sizeof(ioctl_names)/sizeof(ioctl_names[0])) ==
  19760. + (VCHIQ_IOC_MAX + 1));
  19761. +
  19762. +static void
  19763. +dump_phys_mem(void *virt_addr, uint32_t num_bytes);
  19764. +
  19765. +/****************************************************************************
  19766. +*
  19767. +* add_completion
  19768. +*
  19769. +***************************************************************************/
  19770. +
  19771. +static VCHIQ_STATUS_T
  19772. +add_completion(VCHIQ_INSTANCE_T instance, VCHIQ_REASON_T reason,
  19773. + VCHIQ_HEADER_T *header, USER_SERVICE_T *user_service,
  19774. + void *bulk_userdata)
  19775. +{
  19776. + VCHIQ_COMPLETION_DATA_T *completion;
  19777. + DEBUG_INITIALISE(g_state.local)
  19778. +
  19779. + while (instance->completion_insert ==
  19780. + (instance->completion_remove + MAX_COMPLETIONS)) {
  19781. + /* Out of space - wait for the client */
  19782. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  19783. + vchiq_log_trace(vchiq_arm_log_level,
  19784. + "add_completion - completion queue full");
  19785. + DEBUG_COUNT(COMPLETION_QUEUE_FULL_COUNT);
  19786. + if (down_interruptible(&instance->remove_event) != 0) {
  19787. + vchiq_log_info(vchiq_arm_log_level,
  19788. + "service_callback interrupted");
  19789. + return VCHIQ_RETRY;
  19790. + } else if (instance->closing) {
  19791. + vchiq_log_info(vchiq_arm_log_level,
  19792. + "service_callback closing");
  19793. + return VCHIQ_ERROR;
  19794. + }
  19795. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  19796. + }
  19797. +
  19798. + completion =
  19799. + &instance->completions[instance->completion_insert &
  19800. + (MAX_COMPLETIONS - 1)];
  19801. +
  19802. + completion->header = header;
  19803. + completion->reason = reason;
  19804. + /* N.B. service_userdata is updated while processing AWAIT_COMPLETION */
  19805. + completion->service_userdata = user_service->service;
  19806. + completion->bulk_userdata = bulk_userdata;
  19807. +
  19808. + if (reason == VCHIQ_SERVICE_CLOSED)
  19809. + /* Take an extra reference, to be held until
  19810. + this CLOSED notification is delivered. */
  19811. + lock_service(user_service->service);
  19812. +
  19813. + /* A write barrier is needed here to ensure that the entire completion
  19814. + record is written out before the insert point. */
  19815. + wmb();
  19816. +
  19817. + if (reason == VCHIQ_MESSAGE_AVAILABLE)
  19818. + user_service->message_available_pos =
  19819. + instance->completion_insert;
  19820. + instance->completion_insert++;
  19821. +
  19822. + up(&instance->insert_event);
  19823. +
  19824. + return VCHIQ_SUCCESS;
  19825. +}
  19826. +
  19827. +/****************************************************************************
  19828. +*
  19829. +* service_callback
  19830. +*
  19831. +***************************************************************************/
  19832. +
  19833. +static VCHIQ_STATUS_T
  19834. +service_callback(VCHIQ_REASON_T reason, VCHIQ_HEADER_T *header,
  19835. + VCHIQ_SERVICE_HANDLE_T handle, void *bulk_userdata)
  19836. +{
  19837. + /* How do we ensure the callback goes to the right client?
  19838. + ** The service_user data points to a USER_SERVICE_T record containing
  19839. + ** the original callback and the user state structure, which contains a
  19840. + ** circular buffer for completion records.
  19841. + */
  19842. + USER_SERVICE_T *user_service;
  19843. + VCHIQ_SERVICE_T *service;
  19844. + VCHIQ_INSTANCE_T instance;
  19845. + DEBUG_INITIALISE(g_state.local)
  19846. +
  19847. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  19848. +
  19849. + service = handle_to_service(handle);
  19850. + BUG_ON(!service);
  19851. + user_service = (USER_SERVICE_T *)service->base.userdata;
  19852. + instance = user_service->instance;
  19853. +
  19854. + if (!instance || instance->closing)
  19855. + return VCHIQ_SUCCESS;
  19856. +
  19857. + vchiq_log_trace(vchiq_arm_log_level,
  19858. + "service_callback - service %lx(%d), reason %d, header %lx, "
  19859. + "instance %lx, bulk_userdata %lx",
  19860. + (unsigned long)user_service,
  19861. + service->localport,
  19862. + reason, (unsigned long)header,
  19863. + (unsigned long)instance, (unsigned long)bulk_userdata);
  19864. +
  19865. + if (header && user_service->is_vchi) {
  19866. + spin_lock(&msg_queue_spinlock);
  19867. + while (user_service->msg_insert ==
  19868. + (user_service->msg_remove + MSG_QUEUE_SIZE)) {
  19869. + spin_unlock(&msg_queue_spinlock);
  19870. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  19871. + DEBUG_COUNT(MSG_QUEUE_FULL_COUNT);
  19872. + vchiq_log_trace(vchiq_arm_log_level,
  19873. + "service_callback - msg queue full");
  19874. + /* If there is no MESSAGE_AVAILABLE in the completion
  19875. + ** queue, add one
  19876. + */
  19877. + if ((user_service->message_available_pos -
  19878. + instance->completion_remove) < 0) {
  19879. + VCHIQ_STATUS_T status;
  19880. + vchiq_log_info(vchiq_arm_log_level,
  19881. + "Inserting extra MESSAGE_AVAILABLE");
  19882. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  19883. + status = add_completion(instance, reason,
  19884. + NULL, user_service, bulk_userdata);
  19885. + if (status != VCHIQ_SUCCESS) {
  19886. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  19887. + return status;
  19888. + }
  19889. + }
  19890. +
  19891. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  19892. + if (down_interruptible(&user_service->remove_event)
  19893. + != 0) {
  19894. + vchiq_log_info(vchiq_arm_log_level,
  19895. + "service_callback interrupted");
  19896. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  19897. + return VCHIQ_RETRY;
  19898. + } else if (instance->closing) {
  19899. + vchiq_log_info(vchiq_arm_log_level,
  19900. + "service_callback closing");
  19901. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  19902. + return VCHIQ_ERROR;
  19903. + }
  19904. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  19905. + spin_lock(&msg_queue_spinlock);
  19906. + }
  19907. +
  19908. + user_service->msg_queue[user_service->msg_insert &
  19909. + (MSG_QUEUE_SIZE - 1)] = header;
  19910. + user_service->msg_insert++;
  19911. + spin_unlock(&msg_queue_spinlock);
  19912. +
  19913. + up(&user_service->insert_event);
  19914. +
  19915. + /* If there is a thread waiting in DEQUEUE_MESSAGE, or if
  19916. + ** there is a MESSAGE_AVAILABLE in the completion queue then
  19917. + ** bypass the completion queue.
  19918. + */
  19919. + if (((user_service->message_available_pos -
  19920. + instance->completion_remove) >= 0) ||
  19921. + user_service->dequeue_pending) {
  19922. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  19923. + user_service->dequeue_pending = 0;
  19924. + return VCHIQ_SUCCESS;
  19925. + }
  19926. +
  19927. + header = NULL;
  19928. + }
  19929. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  19930. +
  19931. + return add_completion(instance, reason, header, user_service,
  19932. + bulk_userdata);
  19933. +}
  19934. +
  19935. +/****************************************************************************
  19936. +*
  19937. +* user_service_free
  19938. +*
  19939. +***************************************************************************/
  19940. +static void
  19941. +user_service_free(void *userdata)
  19942. +{
  19943. + kfree(userdata);
  19944. +}
  19945. +
  19946. +/****************************************************************************
  19947. +*
  19948. +* vchiq_ioctl
  19949. +*
  19950. +***************************************************************************/
  19951. +
  19952. +static long
  19953. +vchiq_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  19954. +{
  19955. + VCHIQ_INSTANCE_T instance = file->private_data;
  19956. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  19957. + VCHIQ_SERVICE_T *service = NULL;
  19958. + long ret = 0;
  19959. + int i, rc;
  19960. + DEBUG_INITIALISE(g_state.local)
  19961. +
  19962. + vchiq_log_trace(vchiq_arm_log_level,
  19963. + "vchiq_ioctl - instance %x, cmd %s, arg %lx",
  19964. + (unsigned int)instance,
  19965. + ((_IOC_TYPE(cmd) == VCHIQ_IOC_MAGIC) &&
  19966. + (_IOC_NR(cmd) <= VCHIQ_IOC_MAX)) ?
  19967. + ioctl_names[_IOC_NR(cmd)] : "<invalid>", arg);
  19968. +
  19969. + switch (cmd) {
  19970. + case VCHIQ_IOC_SHUTDOWN:
  19971. + if (!instance->connected)
  19972. + break;
  19973. +
  19974. + /* Remove all services */
  19975. + i = 0;
  19976. + while ((service = next_service_by_instance(instance->state,
  19977. + instance, &i)) != NULL) {
  19978. + status = vchiq_remove_service(service->handle);
  19979. + unlock_service(service);
  19980. + if (status != VCHIQ_SUCCESS)
  19981. + break;
  19982. + }
  19983. + service = NULL;
  19984. +
  19985. + if (status == VCHIQ_SUCCESS) {
  19986. + /* Wake the completion thread and ask it to exit */
  19987. + instance->closing = 1;
  19988. + up(&instance->insert_event);
  19989. + }
  19990. +
  19991. + break;
  19992. +
  19993. + case VCHIQ_IOC_CONNECT:
  19994. + if (instance->connected) {
  19995. + ret = -EINVAL;
  19996. + break;
  19997. + }
  19998. + rc = mutex_lock_interruptible(&instance->state->mutex);
  19999. + if (rc != 0) {
  20000. + vchiq_log_error(vchiq_arm_log_level,
  20001. + "vchiq: connect: could not lock mutex for "
  20002. + "state %d: %d",
  20003. + instance->state->id, rc);
  20004. + ret = -EINTR;
  20005. + break;
  20006. + }
  20007. + status = vchiq_connect_internal(instance->state, instance);
  20008. + mutex_unlock(&instance->state->mutex);
  20009. +
  20010. + if (status == VCHIQ_SUCCESS)
  20011. + instance->connected = 1;
  20012. + else
  20013. + vchiq_log_error(vchiq_arm_log_level,
  20014. + "vchiq: could not connect: %d", status);
  20015. + break;
  20016. +
  20017. + case VCHIQ_IOC_CREATE_SERVICE: {
  20018. + VCHIQ_CREATE_SERVICE_T args;
  20019. + USER_SERVICE_T *user_service = NULL;
  20020. + void *userdata;
  20021. + int srvstate;
  20022. +
  20023. + if (copy_from_user
  20024. + (&args, (const void __user *)arg,
  20025. + sizeof(args)) != 0) {
  20026. + ret = -EFAULT;
  20027. + break;
  20028. + }
  20029. +
  20030. + user_service = kmalloc(sizeof(USER_SERVICE_T), GFP_KERNEL);
  20031. + if (!user_service) {
  20032. + ret = -ENOMEM;
  20033. + break;
  20034. + }
  20035. +
  20036. + if (args.is_open) {
  20037. + if (!instance->connected) {
  20038. + ret = -ENOTCONN;
  20039. + kfree(user_service);
  20040. + break;
  20041. + }
  20042. + srvstate = VCHIQ_SRVSTATE_OPENING;
  20043. + } else {
  20044. + srvstate =
  20045. + instance->connected ?
  20046. + VCHIQ_SRVSTATE_LISTENING :
  20047. + VCHIQ_SRVSTATE_HIDDEN;
  20048. + }
  20049. +
  20050. + userdata = args.params.userdata;
  20051. + args.params.callback = service_callback;
  20052. + args.params.userdata = user_service;
  20053. + service = vchiq_add_service_internal(
  20054. + instance->state,
  20055. + &args.params, srvstate,
  20056. + instance, user_service_free);
  20057. +
  20058. + if (service != NULL) {
  20059. + user_service->service = service;
  20060. + user_service->userdata = userdata;
  20061. + user_service->instance = instance;
  20062. + user_service->is_vchi = args.is_vchi;
  20063. + user_service->dequeue_pending = 0;
  20064. + user_service->message_available_pos =
  20065. + instance->completion_remove - 1;
  20066. + user_service->msg_insert = 0;
  20067. + user_service->msg_remove = 0;
  20068. + sema_init(&user_service->insert_event, 0);
  20069. + sema_init(&user_service->remove_event, 0);
  20070. +
  20071. + if (args.is_open) {
  20072. + status = vchiq_open_service_internal
  20073. + (service, instance->pid);
  20074. + if (status != VCHIQ_SUCCESS) {
  20075. + vchiq_remove_service(service->handle);
  20076. + service = NULL;
  20077. + ret = (status == VCHIQ_RETRY) ?
  20078. + -EINTR : -EIO;
  20079. + break;
  20080. + }
  20081. + }
  20082. +
  20083. + if (copy_to_user((void __user *)
  20084. + &(((VCHIQ_CREATE_SERVICE_T __user *)
  20085. + arg)->handle),
  20086. + (const void *)&service->handle,
  20087. + sizeof(service->handle)) != 0) {
  20088. + ret = -EFAULT;
  20089. + vchiq_remove_service(service->handle);
  20090. + }
  20091. +
  20092. + service = NULL;
  20093. + } else {
  20094. + ret = -EEXIST;
  20095. + kfree(user_service);
  20096. + }
  20097. + } break;
  20098. +
  20099. + case VCHIQ_IOC_CLOSE_SERVICE: {
  20100. + VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
  20101. +
  20102. + service = find_service_for_instance(instance, handle);
  20103. + if (service != NULL)
  20104. + status = vchiq_close_service(service->handle);
  20105. + else
  20106. + ret = -EINVAL;
  20107. + } break;
  20108. +
  20109. + case VCHIQ_IOC_REMOVE_SERVICE: {
  20110. + VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
  20111. +
  20112. + service = find_service_for_instance(instance, handle);
  20113. + if (service != NULL)
  20114. + status = vchiq_remove_service(service->handle);
  20115. + else
  20116. + ret = -EINVAL;
  20117. + } break;
  20118. +
  20119. + case VCHIQ_IOC_USE_SERVICE:
  20120. + case VCHIQ_IOC_RELEASE_SERVICE: {
  20121. + VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
  20122. +
  20123. + service = find_service_for_instance(instance, handle);
  20124. + if (service != NULL) {
  20125. + status = (cmd == VCHIQ_IOC_USE_SERVICE) ?
  20126. + vchiq_use_service_internal(service) :
  20127. + vchiq_release_service_internal(service);
  20128. + if (status != VCHIQ_SUCCESS) {
  20129. + vchiq_log_error(vchiq_susp_log_level,
  20130. + "%s: cmd %s returned error %d for "
  20131. + "service %c%c%c%c:%03d",
  20132. + __func__,
  20133. + (cmd == VCHIQ_IOC_USE_SERVICE) ?
  20134. + "VCHIQ_IOC_USE_SERVICE" :
  20135. + "VCHIQ_IOC_RELEASE_SERVICE",
  20136. + status,
  20137. + VCHIQ_FOURCC_AS_4CHARS(
  20138. + service->base.fourcc),
  20139. + service->client_id);
  20140. + ret = -EINVAL;
  20141. + }
  20142. + } else
  20143. + ret = -EINVAL;
  20144. + } break;
  20145. +
  20146. + case VCHIQ_IOC_QUEUE_MESSAGE: {
  20147. + VCHIQ_QUEUE_MESSAGE_T args;
  20148. + if (copy_from_user
  20149. + (&args, (const void __user *)arg,
  20150. + sizeof(args)) != 0) {
  20151. + ret = -EFAULT;
  20152. + break;
  20153. + }
  20154. +
  20155. + service = find_service_for_instance(instance, args.handle);
  20156. +
  20157. + if ((service != NULL) && (args.count <= MAX_ELEMENTS)) {
  20158. + /* Copy elements into kernel space */
  20159. + VCHIQ_ELEMENT_T elements[MAX_ELEMENTS];
  20160. + if (copy_from_user(elements, args.elements,
  20161. + args.count * sizeof(VCHIQ_ELEMENT_T)) == 0)
  20162. + status = vchiq_queue_message
  20163. + (args.handle,
  20164. + elements, args.count);
  20165. + else
  20166. + ret = -EFAULT;
  20167. + } else {
  20168. + ret = -EINVAL;
  20169. + }
  20170. + } break;
  20171. +
  20172. + case VCHIQ_IOC_QUEUE_BULK_TRANSMIT:
  20173. + case VCHIQ_IOC_QUEUE_BULK_RECEIVE: {
  20174. + VCHIQ_QUEUE_BULK_TRANSFER_T args;
  20175. + struct bulk_waiter_node *waiter = NULL;
  20176. + VCHIQ_BULK_DIR_T dir =
  20177. + (cmd == VCHIQ_IOC_QUEUE_BULK_TRANSMIT) ?
  20178. + VCHIQ_BULK_TRANSMIT : VCHIQ_BULK_RECEIVE;
  20179. +
  20180. + if (copy_from_user
  20181. + (&args, (const void __user *)arg,
  20182. + sizeof(args)) != 0) {
  20183. + ret = -EFAULT;
  20184. + break;
  20185. + }
  20186. +
  20187. + service = find_service_for_instance(instance, args.handle);
  20188. + if (!service) {
  20189. + ret = -EINVAL;
  20190. + break;
  20191. + }
  20192. +
  20193. + if (args.mode == VCHIQ_BULK_MODE_BLOCKING) {
  20194. + waiter = kzalloc(sizeof(struct bulk_waiter_node),
  20195. + GFP_KERNEL);
  20196. + if (!waiter) {
  20197. + ret = -ENOMEM;
  20198. + break;
  20199. + }
  20200. + args.userdata = &waiter->bulk_waiter;
  20201. + } else if (args.mode == VCHIQ_BULK_MODE_WAITING) {
  20202. + struct list_head *pos;
  20203. + mutex_lock(&instance->bulk_waiter_list_mutex);
  20204. + list_for_each(pos, &instance->bulk_waiter_list) {
  20205. + if (list_entry(pos, struct bulk_waiter_node,
  20206. + list)->pid == current->pid) {
  20207. + waiter = list_entry(pos,
  20208. + struct bulk_waiter_node,
  20209. + list);
  20210. + list_del(pos);
  20211. + break;
  20212. + }
  20213. +
  20214. + }
  20215. + mutex_unlock(&instance->bulk_waiter_list_mutex);
  20216. + if (!waiter) {
  20217. + vchiq_log_error(vchiq_arm_log_level,
  20218. + "no bulk_waiter found for pid %d",
  20219. + current->pid);
  20220. + ret = -ESRCH;
  20221. + break;
  20222. + }
  20223. + vchiq_log_info(vchiq_arm_log_level,
  20224. + "found bulk_waiter %x for pid %d",
  20225. + (unsigned int)waiter, current->pid);
  20226. + args.userdata = &waiter->bulk_waiter;
  20227. + }
  20228. + status = vchiq_bulk_transfer
  20229. + (args.handle,
  20230. + VCHI_MEM_HANDLE_INVALID,
  20231. + args.data, args.size,
  20232. + args.userdata, args.mode,
  20233. + dir);
  20234. + if (!waiter)
  20235. + break;
  20236. + if ((status != VCHIQ_RETRY) || fatal_signal_pending(current) ||
  20237. + !waiter->bulk_waiter.bulk) {
  20238. + if (waiter->bulk_waiter.bulk) {
  20239. + /* Cancel the signal when the transfer
  20240. + ** completes. */
  20241. + spin_lock(&bulk_waiter_spinlock);
  20242. + waiter->bulk_waiter.bulk->userdata = NULL;
  20243. + spin_unlock(&bulk_waiter_spinlock);
  20244. + }
  20245. + kfree(waiter);
  20246. + } else {
  20247. + const VCHIQ_BULK_MODE_T mode_waiting =
  20248. + VCHIQ_BULK_MODE_WAITING;
  20249. + waiter->pid = current->pid;
  20250. + mutex_lock(&instance->bulk_waiter_list_mutex);
  20251. + list_add(&waiter->list, &instance->bulk_waiter_list);
  20252. + mutex_unlock(&instance->bulk_waiter_list_mutex);
  20253. + vchiq_log_info(vchiq_arm_log_level,
  20254. + "saved bulk_waiter %x for pid %d",
  20255. + (unsigned int)waiter, current->pid);
  20256. +
  20257. + if (copy_to_user((void __user *)
  20258. + &(((VCHIQ_QUEUE_BULK_TRANSFER_T __user *)
  20259. + arg)->mode),
  20260. + (const void *)&mode_waiting,
  20261. + sizeof(mode_waiting)) != 0)
  20262. + ret = -EFAULT;
  20263. + }
  20264. + } break;
  20265. +
  20266. + case VCHIQ_IOC_AWAIT_COMPLETION: {
  20267. + VCHIQ_AWAIT_COMPLETION_T args;
  20268. +
  20269. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  20270. + if (!instance->connected) {
  20271. + ret = -ENOTCONN;
  20272. + break;
  20273. + }
  20274. +
  20275. + if (copy_from_user(&args, (const void __user *)arg,
  20276. + sizeof(args)) != 0) {
  20277. + ret = -EFAULT;
  20278. + break;
  20279. + }
  20280. +
  20281. + mutex_lock(&instance->completion_mutex);
  20282. +
  20283. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  20284. + while ((instance->completion_remove ==
  20285. + instance->completion_insert)
  20286. + && !instance->closing) {
  20287. + int rc;
  20288. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  20289. + mutex_unlock(&instance->completion_mutex);
  20290. + rc = down_interruptible(&instance->insert_event);
  20291. + mutex_lock(&instance->completion_mutex);
  20292. + if (rc != 0) {
  20293. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  20294. + vchiq_log_info(vchiq_arm_log_level,
  20295. + "AWAIT_COMPLETION interrupted");
  20296. + ret = -EINTR;
  20297. + break;
  20298. + }
  20299. + }
  20300. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  20301. +
  20302. + /* A read memory barrier is needed to stop prefetch of a stale
  20303. + ** completion record
  20304. + */
  20305. + rmb();
  20306. +
  20307. + if (ret == 0) {
  20308. + int msgbufcount = args.msgbufcount;
  20309. + for (ret = 0; ret < args.count; ret++) {
  20310. + VCHIQ_COMPLETION_DATA_T *completion;
  20311. + VCHIQ_SERVICE_T *service;
  20312. + USER_SERVICE_T *user_service;
  20313. + VCHIQ_HEADER_T *header;
  20314. + if (instance->completion_remove ==
  20315. + instance->completion_insert)
  20316. + break;
  20317. + completion = &instance->completions[
  20318. + instance->completion_remove &
  20319. + (MAX_COMPLETIONS - 1)];
  20320. +
  20321. + service = completion->service_userdata;
  20322. + user_service = service->base.userdata;
  20323. + completion->service_userdata =
  20324. + user_service->userdata;
  20325. +
  20326. + header = completion->header;
  20327. + if (header) {
  20328. + void __user *msgbuf;
  20329. + int msglen;
  20330. +
  20331. + msglen = header->size +
  20332. + sizeof(VCHIQ_HEADER_T);
  20333. + /* This must be a VCHIQ-style service */
  20334. + if (args.msgbufsize < msglen) {
  20335. + vchiq_log_error(
  20336. + vchiq_arm_log_level,
  20337. + "header %x: msgbufsize"
  20338. + " %x < msglen %x",
  20339. + (unsigned int)header,
  20340. + args.msgbufsize,
  20341. + msglen);
  20342. + WARN(1, "invalid message "
  20343. + "size\n");
  20344. + if (ret == 0)
  20345. + ret = -EMSGSIZE;
  20346. + break;
  20347. + }
  20348. + if (msgbufcount <= 0)
  20349. + /* Stall here for lack of a
  20350. + ** buffer for the message. */
  20351. + break;
  20352. + /* Get the pointer from user space */
  20353. + msgbufcount--;
  20354. + if (copy_from_user(&msgbuf,
  20355. + (const void __user *)
  20356. + &args.msgbufs[msgbufcount],
  20357. + sizeof(msgbuf)) != 0) {
  20358. + if (ret == 0)
  20359. + ret = -EFAULT;
  20360. + break;
  20361. + }
  20362. +
  20363. + /* Copy the message to user space */
  20364. + if (copy_to_user(msgbuf, header,
  20365. + msglen) != 0) {
  20366. + if (ret == 0)
  20367. + ret = -EFAULT;
  20368. + break;
  20369. + }
  20370. +
  20371. + /* Now it has been copied, the message
  20372. + ** can be released. */
  20373. + vchiq_release_message(service->handle,
  20374. + header);
  20375. +
  20376. + /* The completion must point to the
  20377. + ** msgbuf. */
  20378. + completion->header = msgbuf;
  20379. + }
  20380. +
  20381. + if (completion->reason ==
  20382. + VCHIQ_SERVICE_CLOSED)
  20383. + unlock_service(service);
  20384. +
  20385. + if (copy_to_user((void __user *)(
  20386. + (size_t)args.buf +
  20387. + ret * sizeof(VCHIQ_COMPLETION_DATA_T)),
  20388. + completion,
  20389. + sizeof(VCHIQ_COMPLETION_DATA_T)) != 0) {
  20390. + if (ret == 0)
  20391. + ret = -EFAULT;
  20392. + break;
  20393. + }
  20394. +
  20395. + instance->completion_remove++;
  20396. + }
  20397. +
  20398. + if (msgbufcount != args.msgbufcount) {
  20399. + if (copy_to_user((void __user *)
  20400. + &((VCHIQ_AWAIT_COMPLETION_T *)arg)->
  20401. + msgbufcount,
  20402. + &msgbufcount,
  20403. + sizeof(msgbufcount)) != 0) {
  20404. + ret = -EFAULT;
  20405. + }
  20406. + }
  20407. + }
  20408. +
  20409. + if (ret != 0)
  20410. + up(&instance->remove_event);
  20411. + mutex_unlock(&instance->completion_mutex);
  20412. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  20413. + } break;
  20414. +
  20415. + case VCHIQ_IOC_DEQUEUE_MESSAGE: {
  20416. + VCHIQ_DEQUEUE_MESSAGE_T args;
  20417. + USER_SERVICE_T *user_service;
  20418. + VCHIQ_HEADER_T *header;
  20419. +
  20420. + DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
  20421. + if (copy_from_user
  20422. + (&args, (const void __user *)arg,
  20423. + sizeof(args)) != 0) {
  20424. + ret = -EFAULT;
  20425. + break;
  20426. + }
  20427. + service = find_service_for_instance(instance, args.handle);
  20428. + if (!service) {
  20429. + ret = -EINVAL;
  20430. + break;
  20431. + }
  20432. + user_service = (USER_SERVICE_T *)service->base.userdata;
  20433. + if (user_service->is_vchi == 0) {
  20434. + ret = -EINVAL;
  20435. + break;
  20436. + }
  20437. +
  20438. + spin_lock(&msg_queue_spinlock);
  20439. + if (user_service->msg_remove == user_service->msg_insert) {
  20440. + if (!args.blocking) {
  20441. + spin_unlock(&msg_queue_spinlock);
  20442. + DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
  20443. + ret = -EWOULDBLOCK;
  20444. + break;
  20445. + }
  20446. + user_service->dequeue_pending = 1;
  20447. + do {
  20448. + spin_unlock(&msg_queue_spinlock);
  20449. + DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
  20450. + if (down_interruptible(
  20451. + &user_service->insert_event) != 0) {
  20452. + vchiq_log_info(vchiq_arm_log_level,
  20453. + "DEQUEUE_MESSAGE interrupted");
  20454. + ret = -EINTR;
  20455. + break;
  20456. + }
  20457. + spin_lock(&msg_queue_spinlock);
  20458. + } while (user_service->msg_remove ==
  20459. + user_service->msg_insert);
  20460. +
  20461. + if (ret)
  20462. + break;
  20463. + }
  20464. +
  20465. + BUG_ON((int)(user_service->msg_insert -
  20466. + user_service->msg_remove) < 0);
  20467. +
  20468. + header = user_service->msg_queue[user_service->msg_remove &
  20469. + (MSG_QUEUE_SIZE - 1)];
  20470. + user_service->msg_remove++;
  20471. + spin_unlock(&msg_queue_spinlock);
  20472. +
  20473. + up(&user_service->remove_event);
  20474. + if (header == NULL)
  20475. + ret = -ENOTCONN;
  20476. + else if (header->size <= args.bufsize) {
  20477. + /* Copy to user space if msgbuf is not NULL */
  20478. + if ((args.buf == NULL) ||
  20479. + (copy_to_user((void __user *)args.buf,
  20480. + header->data,
  20481. + header->size) == 0)) {
  20482. + ret = header->size;
  20483. + vchiq_release_message(
  20484. + service->handle,
  20485. + header);
  20486. + } else
  20487. + ret = -EFAULT;
  20488. + } else {
  20489. + vchiq_log_error(vchiq_arm_log_level,
  20490. + "header %x: bufsize %x < size %x",
  20491. + (unsigned int)header, args.bufsize,
  20492. + header->size);
  20493. + WARN(1, "invalid size\n");
  20494. + ret = -EMSGSIZE;
  20495. + }
  20496. + DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
  20497. + } break;
  20498. +
  20499. + case VCHIQ_IOC_GET_CLIENT_ID: {
  20500. + VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
  20501. +
  20502. + ret = vchiq_get_client_id(handle);
  20503. + } break;
  20504. +
  20505. + case VCHIQ_IOC_GET_CONFIG: {
  20506. + VCHIQ_GET_CONFIG_T args;
  20507. + VCHIQ_CONFIG_T config;
  20508. +
  20509. + if (copy_from_user(&args, (const void __user *)arg,
  20510. + sizeof(args)) != 0) {
  20511. + ret = -EFAULT;
  20512. + break;
  20513. + }
  20514. + if (args.config_size > sizeof(config)) {
  20515. + ret = -EINVAL;
  20516. + break;
  20517. + }
  20518. + status = vchiq_get_config(instance, args.config_size, &config);
  20519. + if (status == VCHIQ_SUCCESS) {
  20520. + if (copy_to_user((void __user *)args.pconfig,
  20521. + &config, args.config_size) != 0) {
  20522. + ret = -EFAULT;
  20523. + break;
  20524. + }
  20525. + }
  20526. + } break;
  20527. +
  20528. + case VCHIQ_IOC_SET_SERVICE_OPTION: {
  20529. + VCHIQ_SET_SERVICE_OPTION_T args;
  20530. +
  20531. + if (copy_from_user(
  20532. + &args, (const void __user *)arg,
  20533. + sizeof(args)) != 0) {
  20534. + ret = -EFAULT;
  20535. + break;
  20536. + }
  20537. +
  20538. + service = find_service_for_instance(instance, args.handle);
  20539. + if (!service) {
  20540. + ret = -EINVAL;
  20541. + break;
  20542. + }
  20543. +
  20544. + status = vchiq_set_service_option(
  20545. + args.handle, args.option, args.value);
  20546. + } break;
  20547. +
  20548. + case VCHIQ_IOC_DUMP_PHYS_MEM: {
  20549. + VCHIQ_DUMP_MEM_T args;
  20550. +
  20551. + if (copy_from_user
  20552. + (&args, (const void __user *)arg,
  20553. + sizeof(args)) != 0) {
  20554. + ret = -EFAULT;
  20555. + break;
  20556. + }
  20557. + dump_phys_mem(args.virt_addr, args.num_bytes);
  20558. + } break;
  20559. +
  20560. + default:
  20561. + ret = -ENOTTY;
  20562. + break;
  20563. + }
  20564. +
  20565. + if (service)
  20566. + unlock_service(service);
  20567. +
  20568. + if (ret == 0) {
  20569. + if (status == VCHIQ_ERROR)
  20570. + ret = -EIO;
  20571. + else if (status == VCHIQ_RETRY)
  20572. + ret = -EINTR;
  20573. + }
  20574. +
  20575. + if ((status == VCHIQ_SUCCESS) && (ret < 0) && (ret != -EINTR) &&
  20576. + (ret != -EWOULDBLOCK))
  20577. + vchiq_log_info(vchiq_arm_log_level,
  20578. + " ioctl instance %lx, cmd %s -> status %d, %ld",
  20579. + (unsigned long)instance,
  20580. + (_IOC_NR(cmd) <= VCHIQ_IOC_MAX) ?
  20581. + ioctl_names[_IOC_NR(cmd)] :
  20582. + "<invalid>",
  20583. + status, ret);
  20584. + else
  20585. + vchiq_log_trace(vchiq_arm_log_level,
  20586. + " ioctl instance %lx, cmd %s -> status %d, %ld",
  20587. + (unsigned long)instance,
  20588. + (_IOC_NR(cmd) <= VCHIQ_IOC_MAX) ?
  20589. + ioctl_names[_IOC_NR(cmd)] :
  20590. + "<invalid>",
  20591. + status, ret);
  20592. +
  20593. + return ret;
  20594. +}
  20595. +
  20596. +/****************************************************************************
  20597. +*
  20598. +* vchiq_open
  20599. +*
  20600. +***************************************************************************/
  20601. +
  20602. +static int
  20603. +vchiq_open(struct inode *inode, struct file *file)
  20604. +{
  20605. + int dev = iminor(inode) & 0x0f;
  20606. + vchiq_log_info(vchiq_arm_log_level, "vchiq_open");
  20607. + switch (dev) {
  20608. + case VCHIQ_MINOR: {
  20609. + int ret;
  20610. + VCHIQ_STATE_T *state = vchiq_get_state();
  20611. + VCHIQ_INSTANCE_T instance;
  20612. +
  20613. + if (!state) {
  20614. + vchiq_log_error(vchiq_arm_log_level,
  20615. + "vchiq has no connection to VideoCore");
  20616. + return -ENOTCONN;
  20617. + }
  20618. +
  20619. + instance = kzalloc(sizeof(*instance), GFP_KERNEL);
  20620. + if (!instance)
  20621. + return -ENOMEM;
  20622. +
  20623. + instance->state = state;
  20624. + instance->pid = current->tgid;
  20625. +
  20626. + ret = vchiq_proc_add_instance(instance);
  20627. + if (ret != 0) {
  20628. + kfree(instance);
  20629. + return ret;
  20630. + }
  20631. +
  20632. + sema_init(&instance->insert_event, 0);
  20633. + sema_init(&instance->remove_event, 0);
  20634. + mutex_init(&instance->completion_mutex);
  20635. + mutex_init(&instance->bulk_waiter_list_mutex);
  20636. + INIT_LIST_HEAD(&instance->bulk_waiter_list);
  20637. +
  20638. + file->private_data = instance;
  20639. + } break;
  20640. +
  20641. + default:
  20642. + vchiq_log_error(vchiq_arm_log_level,
  20643. + "Unknown minor device: %d", dev);
  20644. + return -ENXIO;
  20645. + }
  20646. +
  20647. + return 0;
  20648. +}
  20649. +
  20650. +/****************************************************************************
  20651. +*
  20652. +* vchiq_release
  20653. +*
  20654. +***************************************************************************/
  20655. +
  20656. +static int
  20657. +vchiq_release(struct inode *inode, struct file *file)
  20658. +{
  20659. + int dev = iminor(inode) & 0x0f;
  20660. + int ret = 0;
  20661. + switch (dev) {
  20662. + case VCHIQ_MINOR: {
  20663. + VCHIQ_INSTANCE_T instance = file->private_data;
  20664. + VCHIQ_STATE_T *state = vchiq_get_state();
  20665. + VCHIQ_SERVICE_T *service;
  20666. + int i;
  20667. +
  20668. + vchiq_log_info(vchiq_arm_log_level,
  20669. + "vchiq_release: instance=%lx",
  20670. + (unsigned long)instance);
  20671. +
  20672. + if (!state) {
  20673. + ret = -EPERM;
  20674. + goto out;
  20675. + }
  20676. +
  20677. + /* Ensure videocore is awake to allow termination. */
  20678. + vchiq_use_internal(instance->state, NULL,
  20679. + USE_TYPE_VCHIQ);
  20680. +
  20681. + mutex_lock(&instance->completion_mutex);
  20682. +
  20683. + /* Wake the completion thread and ask it to exit */
  20684. + instance->closing = 1;
  20685. + up(&instance->insert_event);
  20686. +
  20687. + mutex_unlock(&instance->completion_mutex);
  20688. +
  20689. + /* Wake the slot handler if the completion queue is full. */
  20690. + up(&instance->remove_event);
  20691. +
  20692. + /* Mark all services for termination... */
  20693. + i = 0;
  20694. + while ((service = next_service_by_instance(state, instance,
  20695. + &i)) != NULL) {
  20696. + USER_SERVICE_T *user_service = service->base.userdata;
  20697. +
  20698. + /* Wake the slot handler if the msg queue is full. */
  20699. + up(&user_service->remove_event);
  20700. +
  20701. + vchiq_terminate_service_internal(service);
  20702. + unlock_service(service);
  20703. + }
  20704. +
  20705. + /* ...and wait for them to die */
  20706. + i = 0;
  20707. + while ((service = next_service_by_instance(state, instance, &i))
  20708. + != NULL) {
  20709. + USER_SERVICE_T *user_service = service->base.userdata;
  20710. +
  20711. + down(&service->remove_event);
  20712. +
  20713. + BUG_ON(service->srvstate != VCHIQ_SRVSTATE_FREE);
  20714. +
  20715. + spin_lock(&msg_queue_spinlock);
  20716. +
  20717. + while (user_service->msg_remove !=
  20718. + user_service->msg_insert) {
  20719. + VCHIQ_HEADER_T *header = user_service->
  20720. + msg_queue[user_service->msg_remove &
  20721. + (MSG_QUEUE_SIZE - 1)];
  20722. + user_service->msg_remove++;
  20723. + spin_unlock(&msg_queue_spinlock);
  20724. +
  20725. + if (header)
  20726. + vchiq_release_message(
  20727. + service->handle,
  20728. + header);
  20729. + spin_lock(&msg_queue_spinlock);
  20730. + }
  20731. +
  20732. + spin_unlock(&msg_queue_spinlock);
  20733. +
  20734. + unlock_service(service);
  20735. + }
  20736. +
  20737. + /* Release any closed services */
  20738. + while (instance->completion_remove !=
  20739. + instance->completion_insert) {
  20740. + VCHIQ_COMPLETION_DATA_T *completion;
  20741. + VCHIQ_SERVICE_T *service;
  20742. + completion = &instance->completions[
  20743. + instance->completion_remove &
  20744. + (MAX_COMPLETIONS - 1)];
  20745. + service = completion->service_userdata;
  20746. + if (completion->reason == VCHIQ_SERVICE_CLOSED)
  20747. + unlock_service(service);
  20748. + instance->completion_remove++;
  20749. + }
  20750. +
  20751. + /* Release the PEER service count. */
  20752. + vchiq_release_internal(instance->state, NULL);
  20753. +
  20754. + {
  20755. + struct list_head *pos, *next;
  20756. + list_for_each_safe(pos, next,
  20757. + &instance->bulk_waiter_list) {
  20758. + struct bulk_waiter_node *waiter;
  20759. + waiter = list_entry(pos,
  20760. + struct bulk_waiter_node,
  20761. + list);
  20762. + list_del(pos);
  20763. + vchiq_log_info(vchiq_arm_log_level,
  20764. + "bulk_waiter - cleaned up %x "
  20765. + "for pid %d",
  20766. + (unsigned int)waiter, waiter->pid);
  20767. + kfree(waiter);
  20768. + }
  20769. + }
  20770. +
  20771. + vchiq_proc_remove_instance(instance);
  20772. +
  20773. + kfree(instance);
  20774. + file->private_data = NULL;
  20775. + } break;
  20776. +
  20777. + default:
  20778. + vchiq_log_error(vchiq_arm_log_level,
  20779. + "Unknown minor device: %d", dev);
  20780. + ret = -ENXIO;
  20781. + }
  20782. +
  20783. +out:
  20784. + return ret;
  20785. +}
  20786. +
  20787. +/****************************************************************************
  20788. +*
  20789. +* vchiq_dump
  20790. +*
  20791. +***************************************************************************/
  20792. +
  20793. +void
  20794. +vchiq_dump(void *dump_context, const char *str, int len)
  20795. +{
  20796. + DUMP_CONTEXT_T *context = (DUMP_CONTEXT_T *)dump_context;
  20797. +
  20798. + if (context->actual < context->space) {
  20799. + int copy_bytes;
  20800. + if (context->offset > 0) {
  20801. + int skip_bytes = min(len, (int)context->offset);
  20802. + str += skip_bytes;
  20803. + len -= skip_bytes;
  20804. + context->offset -= skip_bytes;
  20805. + if (context->offset > 0)
  20806. + return;
  20807. + }
  20808. + copy_bytes = min(len, (int)(context->space - context->actual));
  20809. + if (copy_bytes == 0)
  20810. + return;
  20811. + if (copy_to_user(context->buf + context->actual, str,
  20812. + copy_bytes))
  20813. + context->actual = -EFAULT;
  20814. + context->actual += copy_bytes;
  20815. + len -= copy_bytes;
  20816. +
  20817. + /* If tne terminating NUL is included in the length, then it
  20818. + ** marks the end of a line and should be replaced with a
  20819. + ** carriage return. */
  20820. + if ((len == 0) && (str[copy_bytes - 1] == '\0')) {
  20821. + char cr = '\n';
  20822. + if (copy_to_user(context->buf + context->actual - 1,
  20823. + &cr, 1))
  20824. + context->actual = -EFAULT;
  20825. + }
  20826. + }
  20827. +}
  20828. +
  20829. +/****************************************************************************
  20830. +*
  20831. +* vchiq_dump_platform_instance_state
  20832. +*
  20833. +***************************************************************************/
  20834. +
  20835. +void
  20836. +vchiq_dump_platform_instances(void *dump_context)
  20837. +{
  20838. + VCHIQ_STATE_T *state = vchiq_get_state();
  20839. + char buf[80];
  20840. + int len;
  20841. + int i;
  20842. +
  20843. + /* There is no list of instances, so instead scan all services,
  20844. + marking those that have been dumped. */
  20845. +
  20846. + for (i = 0; i < state->unused_service; i++) {
  20847. + VCHIQ_SERVICE_T *service = state->services[i];
  20848. + VCHIQ_INSTANCE_T instance;
  20849. +
  20850. + if (service && (service->base.callback == service_callback)) {
  20851. + instance = service->instance;
  20852. + if (instance)
  20853. + instance->mark = 0;
  20854. + }
  20855. + }
  20856. +
  20857. + for (i = 0; i < state->unused_service; i++) {
  20858. + VCHIQ_SERVICE_T *service = state->services[i];
  20859. + VCHIQ_INSTANCE_T instance;
  20860. +
  20861. + if (service && (service->base.callback == service_callback)) {
  20862. + instance = service->instance;
  20863. + if (instance && !instance->mark) {
  20864. + len = snprintf(buf, sizeof(buf),
  20865. + "Instance %x: pid %d,%s completions "
  20866. + "%d/%d",
  20867. + (unsigned int)instance, instance->pid,
  20868. + instance->connected ? " connected, " :
  20869. + "",
  20870. + instance->completion_insert -
  20871. + instance->completion_remove,
  20872. + MAX_COMPLETIONS);
  20873. +
  20874. + vchiq_dump(dump_context, buf, len + 1);
  20875. +
  20876. + instance->mark = 1;
  20877. + }
  20878. + }
  20879. + }
  20880. +}
  20881. +
  20882. +/****************************************************************************
  20883. +*
  20884. +* vchiq_dump_platform_service_state
  20885. +*
  20886. +***************************************************************************/
  20887. +
  20888. +void
  20889. +vchiq_dump_platform_service_state(void *dump_context, VCHIQ_SERVICE_T *service)
  20890. +{
  20891. + USER_SERVICE_T *user_service = (USER_SERVICE_T *)service->base.userdata;
  20892. + char buf[80];
  20893. + int len;
  20894. +
  20895. + len = snprintf(buf, sizeof(buf), " instance %x",
  20896. + (unsigned int)service->instance);
  20897. +
  20898. + if ((service->base.callback == service_callback) &&
  20899. + user_service->is_vchi) {
  20900. + len += snprintf(buf + len, sizeof(buf) - len,
  20901. + ", %d/%d messages",
  20902. + user_service->msg_insert - user_service->msg_remove,
  20903. + MSG_QUEUE_SIZE);
  20904. +
  20905. + if (user_service->dequeue_pending)
  20906. + len += snprintf(buf + len, sizeof(buf) - len,
  20907. + " (dequeue pending)");
  20908. + }
  20909. +
  20910. + vchiq_dump(dump_context, buf, len + 1);
  20911. +}
  20912. +
  20913. +/****************************************************************************
  20914. +*
  20915. +* dump_user_mem
  20916. +*
  20917. +***************************************************************************/
  20918. +
  20919. +static void
  20920. +dump_phys_mem(void *virt_addr, uint32_t num_bytes)
  20921. +{
  20922. + int rc;
  20923. + uint8_t *end_virt_addr = virt_addr + num_bytes;
  20924. + int num_pages;
  20925. + int offset;
  20926. + int end_offset;
  20927. + int page_idx;
  20928. + int prev_idx;
  20929. + struct page *page;
  20930. + struct page **pages;
  20931. + uint8_t *kmapped_virt_ptr;
  20932. +
  20933. + /* Align virtAddr and endVirtAddr to 16 byte boundaries. */
  20934. +
  20935. + virt_addr = (void *)((unsigned long)virt_addr & ~0x0fuL);
  20936. + end_virt_addr = (void *)(((unsigned long)end_virt_addr + 15uL) &
  20937. + ~0x0fuL);
  20938. +
  20939. + offset = (int)(long)virt_addr & (PAGE_SIZE - 1);
  20940. + end_offset = (int)(long)end_virt_addr & (PAGE_SIZE - 1);
  20941. +
  20942. + num_pages = (offset + num_bytes + PAGE_SIZE - 1) / PAGE_SIZE;
  20943. +
  20944. + pages = kmalloc(sizeof(struct page *) * num_pages, GFP_KERNEL);
  20945. + if (pages == NULL) {
  20946. + vchiq_log_error(vchiq_arm_log_level,
  20947. + "Unable to allocation memory for %d pages\n",
  20948. + num_pages);
  20949. + return;
  20950. + }
  20951. +
  20952. + down_read(&current->mm->mmap_sem);
  20953. + rc = get_user_pages(current, /* task */
  20954. + current->mm, /* mm */
  20955. + (unsigned long)virt_addr, /* start */
  20956. + num_pages, /* len */
  20957. + 0, /* write */
  20958. + 0, /* force */
  20959. + pages, /* pages (array of page pointers) */
  20960. + NULL); /* vmas */
  20961. + up_read(&current->mm->mmap_sem);
  20962. +
  20963. + prev_idx = -1;
  20964. + page = NULL;
  20965. +
  20966. + while (offset < end_offset) {
  20967. +
  20968. + int page_offset = offset % PAGE_SIZE;
  20969. + page_idx = offset / PAGE_SIZE;
  20970. +
  20971. + if (page_idx != prev_idx) {
  20972. +
  20973. + if (page != NULL)
  20974. + kunmap(page);
  20975. + page = pages[page_idx];
  20976. + kmapped_virt_ptr = kmap(page);
  20977. +
  20978. + prev_idx = page_idx;
  20979. + }
  20980. +
  20981. + if (vchiq_arm_log_level >= VCHIQ_LOG_TRACE)
  20982. + vchiq_log_dump_mem("ph",
  20983. + (uint32_t)(unsigned long)&kmapped_virt_ptr[
  20984. + page_offset],
  20985. + &kmapped_virt_ptr[page_offset], 16);
  20986. +
  20987. + offset += 16;
  20988. + }
  20989. + if (page != NULL)
  20990. + kunmap(page);
  20991. +
  20992. + for (page_idx = 0; page_idx < num_pages; page_idx++)
  20993. + page_cache_release(pages[page_idx]);
  20994. +
  20995. + kfree(pages);
  20996. +}
  20997. +
  20998. +/****************************************************************************
  20999. +*
  21000. +* vchiq_read
  21001. +*
  21002. +***************************************************************************/
  21003. +
  21004. +static ssize_t
  21005. +vchiq_read(struct file *file, char __user *buf,
  21006. + size_t count, loff_t *ppos)
  21007. +{
  21008. + DUMP_CONTEXT_T context;
  21009. + context.buf = buf;
  21010. + context.actual = 0;
  21011. + context.space = count;
  21012. + context.offset = *ppos;
  21013. +
  21014. + vchiq_dump_state(&context, &g_state);
  21015. +
  21016. + *ppos += context.actual;
  21017. +
  21018. + return context.actual;
  21019. +}
  21020. +
  21021. +VCHIQ_STATE_T *
  21022. +vchiq_get_state(void)
  21023. +{
  21024. +
  21025. + if (g_state.remote == NULL)
  21026. + printk(KERN_ERR "%s: g_state.remote == NULL\n", __func__);
  21027. + else if (g_state.remote->initialised != 1)
  21028. + printk(KERN_NOTICE "%s: g_state.remote->initialised != 1 (%d)\n",
  21029. + __func__, g_state.remote->initialised);
  21030. +
  21031. + return ((g_state.remote != NULL) &&
  21032. + (g_state.remote->initialised == 1)) ? &g_state : NULL;
  21033. +}
  21034. +
  21035. +static const struct file_operations
  21036. +vchiq_fops = {
  21037. + .owner = THIS_MODULE,
  21038. + .unlocked_ioctl = vchiq_ioctl,
  21039. + .open = vchiq_open,
  21040. + .release = vchiq_release,
  21041. + .read = vchiq_read
  21042. +};
  21043. +
  21044. +/*
  21045. + * Autosuspend related functionality
  21046. + */
  21047. +
  21048. +int
  21049. +vchiq_videocore_wanted(VCHIQ_STATE_T *state)
  21050. +{
  21051. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  21052. + if (!arm_state)
  21053. + /* autosuspend not supported - always return wanted */
  21054. + return 1;
  21055. + else if (arm_state->blocked_count)
  21056. + return 1;
  21057. + else if (!arm_state->videocore_use_count)
  21058. + /* usage count zero - check for override unless we're forcing */
  21059. + if (arm_state->resume_blocked)
  21060. + return 0;
  21061. + else
  21062. + return vchiq_platform_videocore_wanted(state);
  21063. + else
  21064. + /* non-zero usage count - videocore still required */
  21065. + return 1;
  21066. +}
  21067. +
  21068. +static VCHIQ_STATUS_T
  21069. +vchiq_keepalive_vchiq_callback(VCHIQ_REASON_T reason,
  21070. + VCHIQ_HEADER_T *header,
  21071. + VCHIQ_SERVICE_HANDLE_T service_user,
  21072. + void *bulk_user)
  21073. +{
  21074. + vchiq_log_error(vchiq_susp_log_level,
  21075. + "%s callback reason %d", __func__, reason);
  21076. + return 0;
  21077. +}
  21078. +
  21079. +static int
  21080. +vchiq_keepalive_thread_func(void *v)
  21081. +{
  21082. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *) v;
  21083. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  21084. +
  21085. + VCHIQ_STATUS_T status;
  21086. + VCHIQ_INSTANCE_T instance;
  21087. + VCHIQ_SERVICE_HANDLE_T ka_handle;
  21088. +
  21089. + VCHIQ_SERVICE_PARAMS_T params = {
  21090. + .fourcc = VCHIQ_MAKE_FOURCC('K', 'E', 'E', 'P'),
  21091. + .callback = vchiq_keepalive_vchiq_callback,
  21092. + .version = KEEPALIVE_VER,
  21093. + .version_min = KEEPALIVE_VER_MIN
  21094. + };
  21095. +
  21096. + status = vchiq_initialise(&instance);
  21097. + if (status != VCHIQ_SUCCESS) {
  21098. + vchiq_log_error(vchiq_susp_log_level,
  21099. + "%s vchiq_initialise failed %d", __func__, status);
  21100. + goto exit;
  21101. + }
  21102. +
  21103. + status = vchiq_connect(instance);
  21104. + if (status != VCHIQ_SUCCESS) {
  21105. + vchiq_log_error(vchiq_susp_log_level,
  21106. + "%s vchiq_connect failed %d", __func__, status);
  21107. + goto shutdown;
  21108. + }
  21109. +
  21110. + status = vchiq_add_service(instance, &params, &ka_handle);
  21111. + if (status != VCHIQ_SUCCESS) {
  21112. + vchiq_log_error(vchiq_susp_log_level,
  21113. + "%s vchiq_open_service failed %d", __func__, status);
  21114. + goto shutdown;
  21115. + }
  21116. +
  21117. + while (1) {
  21118. + long rc = 0, uc = 0;
  21119. + if (wait_for_completion_interruptible(&arm_state->ka_evt)
  21120. + != 0) {
  21121. + vchiq_log_error(vchiq_susp_log_level,
  21122. + "%s interrupted", __func__);
  21123. + flush_signals(current);
  21124. + continue;
  21125. + }
  21126. +
  21127. + /* read and clear counters. Do release_count then use_count to
  21128. + * prevent getting more releases than uses */
  21129. + rc = atomic_xchg(&arm_state->ka_release_count, 0);
  21130. + uc = atomic_xchg(&arm_state->ka_use_count, 0);
  21131. +
  21132. + /* Call use/release service the requisite number of times.
  21133. + * Process use before release so use counts don't go negative */
  21134. + while (uc--) {
  21135. + atomic_inc(&arm_state->ka_use_ack_count);
  21136. + status = vchiq_use_service(ka_handle);
  21137. + if (status != VCHIQ_SUCCESS) {
  21138. + vchiq_log_error(vchiq_susp_log_level,
  21139. + "%s vchiq_use_service error %d",
  21140. + __func__, status);
  21141. + }
  21142. + }
  21143. + while (rc--) {
  21144. + status = vchiq_release_service(ka_handle);
  21145. + if (status != VCHIQ_SUCCESS) {
  21146. + vchiq_log_error(vchiq_susp_log_level,
  21147. + "%s vchiq_release_service error %d",
  21148. + __func__, status);
  21149. + }
  21150. + }
  21151. + }
  21152. +
  21153. +shutdown:
  21154. + vchiq_shutdown(instance);
  21155. +exit:
  21156. + return 0;
  21157. +}
  21158. +
  21159. +
  21160. +
  21161. +VCHIQ_STATUS_T
  21162. +vchiq_arm_init_state(VCHIQ_STATE_T *state, VCHIQ_ARM_STATE_T *arm_state)
  21163. +{
  21164. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  21165. +
  21166. + if (arm_state) {
  21167. + rwlock_init(&arm_state->susp_res_lock);
  21168. +
  21169. + init_completion(&arm_state->ka_evt);
  21170. + atomic_set(&arm_state->ka_use_count, 0);
  21171. + atomic_set(&arm_state->ka_use_ack_count, 0);
  21172. + atomic_set(&arm_state->ka_release_count, 0);
  21173. +
  21174. + init_completion(&arm_state->vc_suspend_complete);
  21175. +
  21176. + init_completion(&arm_state->vc_resume_complete);
  21177. + /* Initialise to 'done' state. We only want to block on resume
  21178. + * completion while videocore is suspended. */
  21179. + set_resume_state(arm_state, VC_RESUME_RESUMED);
  21180. +
  21181. + init_completion(&arm_state->resume_blocker);
  21182. + /* Initialise to 'done' state. We only want to block on this
  21183. + * completion while resume is blocked */
  21184. + complete_all(&arm_state->resume_blocker);
  21185. +
  21186. + init_completion(&arm_state->blocked_blocker);
  21187. + /* Initialise to 'done' state. We only want to block on this
  21188. + * completion while things are waiting on the resume blocker */
  21189. + complete_all(&arm_state->blocked_blocker);
  21190. +
  21191. + arm_state->suspend_timer_timeout = SUSPEND_TIMER_TIMEOUT_MS;
  21192. + arm_state->suspend_timer_running = 0;
  21193. + init_timer(&arm_state->suspend_timer);
  21194. + arm_state->suspend_timer.data = (unsigned long)(state);
  21195. + arm_state->suspend_timer.function = suspend_timer_callback;
  21196. +
  21197. + arm_state->first_connect = 0;
  21198. +
  21199. + }
  21200. + return status;
  21201. +}
  21202. +
  21203. +/*
  21204. +** Functions to modify the state variables;
  21205. +** set_suspend_state
  21206. +** set_resume_state
  21207. +**
  21208. +** There are more state variables than we might like, so ensure they remain in
  21209. +** step. Suspend and resume state are maintained separately, since most of
  21210. +** these state machines can operate independently. However, there are a few
  21211. +** states where state transitions in one state machine cause a reset to the
  21212. +** other state machine. In addition, there are some completion events which
  21213. +** need to occur on state machine reset and end-state(s), so these are also
  21214. +** dealt with in these functions.
  21215. +**
  21216. +** In all states we set the state variable according to the input, but in some
  21217. +** cases we perform additional steps outlined below;
  21218. +**
  21219. +** VC_SUSPEND_IDLE - Initialise the suspend completion at the same time.
  21220. +** The suspend completion is completed after any suspend
  21221. +** attempt. When we reset the state machine we also reset
  21222. +** the completion. This reset occurs when videocore is
  21223. +** resumed, and also if we initiate suspend after a suspend
  21224. +** failure.
  21225. +**
  21226. +** VC_SUSPEND_IN_PROGRESS - This state is considered the point of no return for
  21227. +** suspend - ie from this point on we must try to suspend
  21228. +** before resuming can occur. We therefore also reset the
  21229. +** resume state machine to VC_RESUME_IDLE in this state.
  21230. +**
  21231. +** VC_SUSPEND_SUSPENDED - Suspend has completed successfully. Also call
  21232. +** complete_all on the suspend completion to notify
  21233. +** anything waiting for suspend to happen.
  21234. +**
  21235. +** VC_SUSPEND_REJECTED - Videocore rejected suspend. Videocore will also
  21236. +** initiate resume, so no need to alter resume state.
  21237. +** We call complete_all on the suspend completion to notify
  21238. +** of suspend rejection.
  21239. +**
  21240. +** VC_SUSPEND_FAILED - We failed to initiate videocore suspend. We notify the
  21241. +** suspend completion and reset the resume state machine.
  21242. +**
  21243. +** VC_RESUME_IDLE - Initialise the resume completion at the same time. The
  21244. +** resume completion is in it's 'done' state whenever
  21245. +** videcore is running. Therfore, the VC_RESUME_IDLE state
  21246. +** implies that videocore is suspended.
  21247. +** Hence, any thread which needs to wait until videocore is
  21248. +** running can wait on this completion - it will only block
  21249. +** if videocore is suspended.
  21250. +**
  21251. +** VC_RESUME_RESUMED - Resume has completed successfully. Videocore is running.
  21252. +** Call complete_all on the resume completion to unblock
  21253. +** any threads waiting for resume. Also reset the suspend
  21254. +** state machine to it's idle state.
  21255. +**
  21256. +** VC_RESUME_FAILED - Currently unused - no mechanism to fail resume exists.
  21257. +*/
  21258. +
  21259. +inline void
  21260. +set_suspend_state(VCHIQ_ARM_STATE_T *arm_state,
  21261. + enum vc_suspend_status new_state)
  21262. +{
  21263. + /* set the state in all cases */
  21264. + arm_state->vc_suspend_state = new_state;
  21265. +
  21266. + /* state specific additional actions */
  21267. + switch (new_state) {
  21268. + case VC_SUSPEND_FORCE_CANCELED:
  21269. + complete_all(&arm_state->vc_suspend_complete);
  21270. + break;
  21271. + case VC_SUSPEND_REJECTED:
  21272. + complete_all(&arm_state->vc_suspend_complete);
  21273. + break;
  21274. + case VC_SUSPEND_FAILED:
  21275. + complete_all(&arm_state->vc_suspend_complete);
  21276. + arm_state->vc_resume_state = VC_RESUME_RESUMED;
  21277. + complete_all(&arm_state->vc_resume_complete);
  21278. + break;
  21279. + case VC_SUSPEND_IDLE:
  21280. + reinit_completion(&arm_state->vc_suspend_complete);
  21281. + break;
  21282. + case VC_SUSPEND_REQUESTED:
  21283. + break;
  21284. + case VC_SUSPEND_IN_PROGRESS:
  21285. + set_resume_state(arm_state, VC_RESUME_IDLE);
  21286. + break;
  21287. + case VC_SUSPEND_SUSPENDED:
  21288. + complete_all(&arm_state->vc_suspend_complete);
  21289. + break;
  21290. + default:
  21291. + BUG();
  21292. + break;
  21293. + }
  21294. +}
  21295. +
  21296. +inline void
  21297. +set_resume_state(VCHIQ_ARM_STATE_T *arm_state,
  21298. + enum vc_resume_status new_state)
  21299. +{
  21300. + /* set the state in all cases */
  21301. + arm_state->vc_resume_state = new_state;
  21302. +
  21303. + /* state specific additional actions */
  21304. + switch (new_state) {
  21305. + case VC_RESUME_FAILED:
  21306. + break;
  21307. + case VC_RESUME_IDLE:
  21308. + reinit_completion(&arm_state->vc_resume_complete);
  21309. + break;
  21310. + case VC_RESUME_REQUESTED:
  21311. + break;
  21312. + case VC_RESUME_IN_PROGRESS:
  21313. + break;
  21314. + case VC_RESUME_RESUMED:
  21315. + complete_all(&arm_state->vc_resume_complete);
  21316. + set_suspend_state(arm_state, VC_SUSPEND_IDLE);
  21317. + break;
  21318. + default:
  21319. + BUG();
  21320. + break;
  21321. + }
  21322. +}
  21323. +
  21324. +
  21325. +/* should be called with the write lock held */
  21326. +inline void
  21327. +start_suspend_timer(VCHIQ_ARM_STATE_T *arm_state)
  21328. +{
  21329. + del_timer(&arm_state->suspend_timer);
  21330. + arm_state->suspend_timer.expires = jiffies +
  21331. + msecs_to_jiffies(arm_state->
  21332. + suspend_timer_timeout);
  21333. + add_timer(&arm_state->suspend_timer);
  21334. + arm_state->suspend_timer_running = 1;
  21335. +}
  21336. +
  21337. +/* should be called with the write lock held */
  21338. +static inline void
  21339. +stop_suspend_timer(VCHIQ_ARM_STATE_T *arm_state)
  21340. +{
  21341. + if (arm_state->suspend_timer_running) {
  21342. + del_timer(&arm_state->suspend_timer);
  21343. + arm_state->suspend_timer_running = 0;
  21344. + }
  21345. +}
  21346. +
  21347. +static inline int
  21348. +need_resume(VCHIQ_STATE_T *state)
  21349. +{
  21350. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  21351. + return (arm_state->vc_suspend_state > VC_SUSPEND_IDLE) &&
  21352. + (arm_state->vc_resume_state < VC_RESUME_REQUESTED) &&
  21353. + vchiq_videocore_wanted(state);
  21354. +}
  21355. +
  21356. +static int
  21357. +block_resume(VCHIQ_ARM_STATE_T *arm_state)
  21358. +{
  21359. + int status = VCHIQ_SUCCESS;
  21360. + const unsigned long timeout_val =
  21361. + msecs_to_jiffies(FORCE_SUSPEND_TIMEOUT_MS);
  21362. + int resume_count = 0;
  21363. +
  21364. + /* Allow any threads which were blocked by the last force suspend to
  21365. + * complete if they haven't already. Only give this one shot; if
  21366. + * blocked_count is incremented after blocked_blocker is completed
  21367. + * (which only happens when blocked_count hits 0) then those threads
  21368. + * will have to wait until next time around */
  21369. + if (arm_state->blocked_count) {
  21370. + reinit_completion(&arm_state->blocked_blocker);
  21371. + write_unlock_bh(&arm_state->susp_res_lock);
  21372. + vchiq_log_info(vchiq_susp_log_level, "%s wait for previously "
  21373. + "blocked clients", __func__);
  21374. + if (wait_for_completion_interruptible_timeout(
  21375. + &arm_state->blocked_blocker, timeout_val)
  21376. + <= 0) {
  21377. + vchiq_log_error(vchiq_susp_log_level, "%s wait for "
  21378. + "previously blocked clients failed" , __func__);
  21379. + status = VCHIQ_ERROR;
  21380. + write_lock_bh(&arm_state->susp_res_lock);
  21381. + goto out;
  21382. + }
  21383. + vchiq_log_info(vchiq_susp_log_level, "%s previously blocked "
  21384. + "clients resumed", __func__);
  21385. + write_lock_bh(&arm_state->susp_res_lock);
  21386. + }
  21387. +
  21388. + /* We need to wait for resume to complete if it's in process */
  21389. + while (arm_state->vc_resume_state != VC_RESUME_RESUMED &&
  21390. + arm_state->vc_resume_state > VC_RESUME_IDLE) {
  21391. + if (resume_count > 1) {
  21392. + status = VCHIQ_ERROR;
  21393. + vchiq_log_error(vchiq_susp_log_level, "%s waited too "
  21394. + "many times for resume" , __func__);
  21395. + goto out;
  21396. + }
  21397. + write_unlock_bh(&arm_state->susp_res_lock);
  21398. + vchiq_log_info(vchiq_susp_log_level, "%s wait for resume",
  21399. + __func__);
  21400. + if (wait_for_completion_interruptible_timeout(
  21401. + &arm_state->vc_resume_complete, timeout_val)
  21402. + <= 0) {
  21403. + vchiq_log_error(vchiq_susp_log_level, "%s wait for "
  21404. + "resume failed (%s)", __func__,
  21405. + resume_state_names[arm_state->vc_resume_state +
  21406. + VC_RESUME_NUM_OFFSET]);
  21407. + status = VCHIQ_ERROR;
  21408. + write_lock_bh(&arm_state->susp_res_lock);
  21409. + goto out;
  21410. + }
  21411. + vchiq_log_info(vchiq_susp_log_level, "%s resumed", __func__);
  21412. + write_lock_bh(&arm_state->susp_res_lock);
  21413. + resume_count++;
  21414. + }
  21415. + reinit_completion(&arm_state->resume_blocker);
  21416. + arm_state->resume_blocked = 1;
  21417. +
  21418. +out:
  21419. + return status;
  21420. +}
  21421. +
  21422. +static inline void
  21423. +unblock_resume(VCHIQ_ARM_STATE_T *arm_state)
  21424. +{
  21425. + complete_all(&arm_state->resume_blocker);
  21426. + arm_state->resume_blocked = 0;
  21427. +}
  21428. +
  21429. +/* Initiate suspend via slot handler. Should be called with the write lock
  21430. + * held */
  21431. +VCHIQ_STATUS_T
  21432. +vchiq_arm_vcsuspend(VCHIQ_STATE_T *state)
  21433. +{
  21434. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  21435. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  21436. +
  21437. + if (!arm_state)
  21438. + goto out;
  21439. +
  21440. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  21441. + status = VCHIQ_SUCCESS;
  21442. +
  21443. +
  21444. + switch (arm_state->vc_suspend_state) {
  21445. + case VC_SUSPEND_REQUESTED:
  21446. + vchiq_log_info(vchiq_susp_log_level, "%s: suspend already "
  21447. + "requested", __func__);
  21448. + break;
  21449. + case VC_SUSPEND_IN_PROGRESS:
  21450. + vchiq_log_info(vchiq_susp_log_level, "%s: suspend already in "
  21451. + "progress", __func__);
  21452. + break;
  21453. +
  21454. + default:
  21455. + /* We don't expect to be in other states, so log but continue
  21456. + * anyway */
  21457. + vchiq_log_error(vchiq_susp_log_level,
  21458. + "%s unexpected suspend state %s", __func__,
  21459. + suspend_state_names[arm_state->vc_suspend_state +
  21460. + VC_SUSPEND_NUM_OFFSET]);
  21461. + /* fall through */
  21462. + case VC_SUSPEND_REJECTED:
  21463. + case VC_SUSPEND_FAILED:
  21464. + /* Ensure any idle state actions have been run */
  21465. + set_suspend_state(arm_state, VC_SUSPEND_IDLE);
  21466. + /* fall through */
  21467. + case VC_SUSPEND_IDLE:
  21468. + vchiq_log_info(vchiq_susp_log_level,
  21469. + "%s: suspending", __func__);
  21470. + set_suspend_state(arm_state, VC_SUSPEND_REQUESTED);
  21471. + /* kick the slot handler thread to initiate suspend */
  21472. + request_poll(state, NULL, 0);
  21473. + break;
  21474. + }
  21475. +
  21476. +out:
  21477. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, status);
  21478. + return status;
  21479. +}
  21480. +
  21481. +void
  21482. +vchiq_platform_check_suspend(VCHIQ_STATE_T *state)
  21483. +{
  21484. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  21485. + int susp = 0;
  21486. +
  21487. + if (!arm_state)
  21488. + goto out;
  21489. +
  21490. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  21491. +
  21492. + write_lock_bh(&arm_state->susp_res_lock);
  21493. + if (arm_state->vc_suspend_state == VC_SUSPEND_REQUESTED &&
  21494. + arm_state->vc_resume_state == VC_RESUME_RESUMED) {
  21495. + set_suspend_state(arm_state, VC_SUSPEND_IN_PROGRESS);
  21496. + susp = 1;
  21497. + }
  21498. + write_unlock_bh(&arm_state->susp_res_lock);
  21499. +
  21500. + if (susp)
  21501. + vchiq_platform_suspend(state);
  21502. +
  21503. +out:
  21504. + vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__);
  21505. + return;
  21506. +}
  21507. +
  21508. +
  21509. +static void
  21510. +output_timeout_error(VCHIQ_STATE_T *state)
  21511. +{
  21512. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  21513. + char service_err[50] = "";
  21514. + int vc_use_count = arm_state->videocore_use_count;
  21515. + int active_services = state->unused_service;
  21516. + int i;
  21517. +
  21518. + if (!arm_state->videocore_use_count) {
  21519. + snprintf(service_err, 50, " Videocore usecount is 0");
  21520. + goto output_msg;
  21521. + }
  21522. + for (i = 0; i < active_services; i++) {
  21523. + VCHIQ_SERVICE_T *service_ptr = state->services[i];
  21524. + if (service_ptr && service_ptr->service_use_count &&
  21525. + (service_ptr->srvstate != VCHIQ_SRVSTATE_FREE)) {
  21526. + snprintf(service_err, 50, " %c%c%c%c(%d) service has "
  21527. + "use count %d%s", VCHIQ_FOURCC_AS_4CHARS(
  21528. + service_ptr->base.fourcc),
  21529. + service_ptr->client_id,
  21530. + service_ptr->service_use_count,
  21531. + service_ptr->service_use_count ==
  21532. + vc_use_count ? "" : " (+ more)");
  21533. + break;
  21534. + }
  21535. + }
  21536. +
  21537. +output_msg:
  21538. + vchiq_log_error(vchiq_susp_log_level,
  21539. + "timed out waiting for vc suspend (%d).%s",
  21540. + arm_state->autosuspend_override, service_err);
  21541. +
  21542. +}
  21543. +
  21544. +/* Try to get videocore into suspended state, regardless of autosuspend state.
  21545. +** We don't actually force suspend, since videocore may get into a bad state
  21546. +** if we force suspend at a bad time. Instead, we wait for autosuspend to
  21547. +** determine a good point to suspend. If this doesn't happen within 100ms we
  21548. +** report failure.
  21549. +**
  21550. +** Returns VCHIQ_SUCCESS if videocore suspended successfully, VCHIQ_RETRY if
  21551. +** videocore failed to suspend in time or VCHIQ_ERROR if interrupted.
  21552. +*/
  21553. +VCHIQ_STATUS_T
  21554. +vchiq_arm_force_suspend(VCHIQ_STATE_T *state)
  21555. +{
  21556. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  21557. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  21558. + long rc = 0;
  21559. + int repeat = -1;
  21560. +
  21561. + if (!arm_state)
  21562. + goto out;
  21563. +
  21564. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  21565. +
  21566. + write_lock_bh(&arm_state->susp_res_lock);
  21567. +
  21568. + status = block_resume(arm_state);
  21569. + if (status != VCHIQ_SUCCESS)
  21570. + goto unlock;
  21571. + if (arm_state->vc_suspend_state == VC_SUSPEND_SUSPENDED) {
  21572. + /* Already suspended - just block resume and exit */
  21573. + vchiq_log_info(vchiq_susp_log_level, "%s already suspended",
  21574. + __func__);
  21575. + status = VCHIQ_SUCCESS;
  21576. + goto unlock;
  21577. + } else if (arm_state->vc_suspend_state <= VC_SUSPEND_IDLE) {
  21578. + /* initiate suspend immediately in the case that we're waiting
  21579. + * for the timeout */
  21580. + stop_suspend_timer(arm_state);
  21581. + if (!vchiq_videocore_wanted(state)) {
  21582. + vchiq_log_info(vchiq_susp_log_level, "%s videocore "
  21583. + "idle, initiating suspend", __func__);
  21584. + status = vchiq_arm_vcsuspend(state);
  21585. + } else if (arm_state->autosuspend_override <
  21586. + FORCE_SUSPEND_FAIL_MAX) {
  21587. + vchiq_log_info(vchiq_susp_log_level, "%s letting "
  21588. + "videocore go idle", __func__);
  21589. + status = VCHIQ_SUCCESS;
  21590. + } else {
  21591. + vchiq_log_warning(vchiq_susp_log_level, "%s failed too "
  21592. + "many times - attempting suspend", __func__);
  21593. + status = vchiq_arm_vcsuspend(state);
  21594. + }
  21595. + } else {
  21596. + vchiq_log_info(vchiq_susp_log_level, "%s videocore suspend "
  21597. + "in progress - wait for completion", __func__);
  21598. + status = VCHIQ_SUCCESS;
  21599. + }
  21600. +
  21601. + /* Wait for suspend to happen due to system idle (not forced..) */
  21602. + if (status != VCHIQ_SUCCESS)
  21603. + goto unblock_resume;
  21604. +
  21605. + do {
  21606. + write_unlock_bh(&arm_state->susp_res_lock);
  21607. +
  21608. + rc = wait_for_completion_interruptible_timeout(
  21609. + &arm_state->vc_suspend_complete,
  21610. + msecs_to_jiffies(FORCE_SUSPEND_TIMEOUT_MS));
  21611. +
  21612. + write_lock_bh(&arm_state->susp_res_lock);
  21613. + if (rc < 0) {
  21614. + vchiq_log_warning(vchiq_susp_log_level, "%s "
  21615. + "interrupted waiting for suspend", __func__);
  21616. + status = VCHIQ_ERROR;
  21617. + goto unblock_resume;
  21618. + } else if (rc == 0) {
  21619. + if (arm_state->vc_suspend_state > VC_SUSPEND_IDLE) {
  21620. + /* Repeat timeout once if in progress */
  21621. + if (repeat < 0) {
  21622. + repeat = 1;
  21623. + continue;
  21624. + }
  21625. + }
  21626. + arm_state->autosuspend_override++;
  21627. + output_timeout_error(state);
  21628. +
  21629. + status = VCHIQ_RETRY;
  21630. + goto unblock_resume;
  21631. + }
  21632. + } while (0 < (repeat--));
  21633. +
  21634. + /* Check and report state in case we need to abort ARM suspend */
  21635. + if (arm_state->vc_suspend_state != VC_SUSPEND_SUSPENDED) {
  21636. + status = VCHIQ_RETRY;
  21637. + vchiq_log_error(vchiq_susp_log_level,
  21638. + "%s videocore suspend failed (state %s)", __func__,
  21639. + suspend_state_names[arm_state->vc_suspend_state +
  21640. + VC_SUSPEND_NUM_OFFSET]);
  21641. + /* Reset the state only if it's still in an error state.
  21642. + * Something could have already initiated another suspend. */
  21643. + if (arm_state->vc_suspend_state < VC_SUSPEND_IDLE)
  21644. + set_suspend_state(arm_state, VC_SUSPEND_IDLE);
  21645. +
  21646. + goto unblock_resume;
  21647. + }
  21648. +
  21649. + /* successfully suspended - unlock and exit */
  21650. + goto unlock;
  21651. +
  21652. +unblock_resume:
  21653. + /* all error states need to unblock resume before exit */
  21654. + unblock_resume(arm_state);
  21655. +
  21656. +unlock:
  21657. + write_unlock_bh(&arm_state->susp_res_lock);
  21658. +
  21659. +out:
  21660. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, status);
  21661. + return status;
  21662. +}
  21663. +
  21664. +void
  21665. +vchiq_check_suspend(VCHIQ_STATE_T *state)
  21666. +{
  21667. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  21668. +
  21669. + if (!arm_state)
  21670. + goto out;
  21671. +
  21672. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  21673. +
  21674. + write_lock_bh(&arm_state->susp_res_lock);
  21675. + if (arm_state->vc_suspend_state != VC_SUSPEND_SUSPENDED &&
  21676. + arm_state->first_connect &&
  21677. + !vchiq_videocore_wanted(state)) {
  21678. + vchiq_arm_vcsuspend(state);
  21679. + }
  21680. + write_unlock_bh(&arm_state->susp_res_lock);
  21681. +
  21682. +out:
  21683. + vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__);
  21684. + return;
  21685. +}
  21686. +
  21687. +
  21688. +int
  21689. +vchiq_arm_allow_resume(VCHIQ_STATE_T *state)
  21690. +{
  21691. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  21692. + int resume = 0;
  21693. + int ret = -1;
  21694. +
  21695. + if (!arm_state)
  21696. + goto out;
  21697. +
  21698. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  21699. +
  21700. + write_lock_bh(&arm_state->susp_res_lock);
  21701. + unblock_resume(arm_state);
  21702. + resume = vchiq_check_resume(state);
  21703. + write_unlock_bh(&arm_state->susp_res_lock);
  21704. +
  21705. + if (resume) {
  21706. + if (wait_for_completion_interruptible(
  21707. + &arm_state->vc_resume_complete) < 0) {
  21708. + vchiq_log_error(vchiq_susp_log_level,
  21709. + "%s interrupted", __func__);
  21710. + /* failed, cannot accurately derive suspend
  21711. + * state, so exit early. */
  21712. + goto out;
  21713. + }
  21714. + }
  21715. +
  21716. + read_lock_bh(&arm_state->susp_res_lock);
  21717. + if (arm_state->vc_suspend_state == VC_SUSPEND_SUSPENDED) {
  21718. + vchiq_log_info(vchiq_susp_log_level,
  21719. + "%s: Videocore remains suspended", __func__);
  21720. + } else {
  21721. + vchiq_log_info(vchiq_susp_log_level,
  21722. + "%s: Videocore resumed", __func__);
  21723. + ret = 0;
  21724. + }
  21725. + read_unlock_bh(&arm_state->susp_res_lock);
  21726. +out:
  21727. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, ret);
  21728. + return ret;
  21729. +}
  21730. +
  21731. +/* This function should be called with the write lock held */
  21732. +int
  21733. +vchiq_check_resume(VCHIQ_STATE_T *state)
  21734. +{
  21735. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  21736. + int resume = 0;
  21737. +
  21738. + if (!arm_state)
  21739. + goto out;
  21740. +
  21741. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  21742. +
  21743. + if (need_resume(state)) {
  21744. + set_resume_state(arm_state, VC_RESUME_REQUESTED);
  21745. + request_poll(state, NULL, 0);
  21746. + resume = 1;
  21747. + }
  21748. +
  21749. +out:
  21750. + vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__);
  21751. + return resume;
  21752. +}
  21753. +
  21754. +void
  21755. +vchiq_platform_check_resume(VCHIQ_STATE_T *state)
  21756. +{
  21757. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  21758. + int res = 0;
  21759. +
  21760. + if (!arm_state)
  21761. + goto out;
  21762. +
  21763. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  21764. +
  21765. + write_lock_bh(&arm_state->susp_res_lock);
  21766. + if (arm_state->wake_address == 0) {
  21767. + vchiq_log_info(vchiq_susp_log_level,
  21768. + "%s: already awake", __func__);
  21769. + goto unlock;
  21770. + }
  21771. + if (arm_state->vc_resume_state == VC_RESUME_IN_PROGRESS) {
  21772. + vchiq_log_info(vchiq_susp_log_level,
  21773. + "%s: already resuming", __func__);
  21774. + goto unlock;
  21775. + }
  21776. +
  21777. + if (arm_state->vc_resume_state == VC_RESUME_REQUESTED) {
  21778. + set_resume_state(arm_state, VC_RESUME_IN_PROGRESS);
  21779. + res = 1;
  21780. + } else
  21781. + vchiq_log_trace(vchiq_susp_log_level,
  21782. + "%s: not resuming (resume state %s)", __func__,
  21783. + resume_state_names[arm_state->vc_resume_state +
  21784. + VC_RESUME_NUM_OFFSET]);
  21785. +
  21786. +unlock:
  21787. + write_unlock_bh(&arm_state->susp_res_lock);
  21788. +
  21789. + if (res)
  21790. + vchiq_platform_resume(state);
  21791. +
  21792. +out:
  21793. + vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__);
  21794. + return;
  21795. +
  21796. +}
  21797. +
  21798. +
  21799. +
  21800. +VCHIQ_STATUS_T
  21801. +vchiq_use_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
  21802. + enum USE_TYPE_E use_type)
  21803. +{
  21804. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  21805. + VCHIQ_STATUS_T ret = VCHIQ_SUCCESS;
  21806. + char entity[16];
  21807. + int *entity_uc;
  21808. + int local_uc, local_entity_uc;
  21809. +
  21810. + if (!arm_state)
  21811. + goto out;
  21812. +
  21813. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  21814. +
  21815. + if (use_type == USE_TYPE_VCHIQ) {
  21816. + sprintf(entity, "VCHIQ: ");
  21817. + entity_uc = &arm_state->peer_use_count;
  21818. + } else if (service) {
  21819. + sprintf(entity, "%c%c%c%c:%03d",
  21820. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  21821. + service->client_id);
  21822. + entity_uc = &service->service_use_count;
  21823. + } else {
  21824. + vchiq_log_error(vchiq_susp_log_level, "%s null service "
  21825. + "ptr", __func__);
  21826. + ret = VCHIQ_ERROR;
  21827. + goto out;
  21828. + }
  21829. +
  21830. + write_lock_bh(&arm_state->susp_res_lock);
  21831. + while (arm_state->resume_blocked) {
  21832. + /* If we call 'use' while force suspend is waiting for suspend,
  21833. + * then we're about to block the thread which the force is
  21834. + * waiting to complete, so we're bound to just time out. In this
  21835. + * case, set the suspend state such that the wait will be
  21836. + * canceled, so we can complete as quickly as possible. */
  21837. + if (arm_state->resume_blocked && arm_state->vc_suspend_state ==
  21838. + VC_SUSPEND_IDLE) {
  21839. + set_suspend_state(arm_state, VC_SUSPEND_FORCE_CANCELED);
  21840. + break;
  21841. + }
  21842. + /* If suspend is already in progress then we need to block */
  21843. + if (!try_wait_for_completion(&arm_state->resume_blocker)) {
  21844. + /* Indicate that there are threads waiting on the resume
  21845. + * blocker. These need to be allowed to complete before
  21846. + * a _second_ call to force suspend can complete,
  21847. + * otherwise low priority threads might never actually
  21848. + * continue */
  21849. + arm_state->blocked_count++;
  21850. + write_unlock_bh(&arm_state->susp_res_lock);
  21851. + vchiq_log_info(vchiq_susp_log_level, "%s %s resume "
  21852. + "blocked - waiting...", __func__, entity);
  21853. + if (wait_for_completion_killable(
  21854. + &arm_state->resume_blocker) != 0) {
  21855. + vchiq_log_error(vchiq_susp_log_level, "%s %s "
  21856. + "wait for resume blocker interrupted",
  21857. + __func__, entity);
  21858. + ret = VCHIQ_ERROR;
  21859. + write_lock_bh(&arm_state->susp_res_lock);
  21860. + arm_state->blocked_count--;
  21861. + write_unlock_bh(&arm_state->susp_res_lock);
  21862. + goto out;
  21863. + }
  21864. + vchiq_log_info(vchiq_susp_log_level, "%s %s resume "
  21865. + "unblocked", __func__, entity);
  21866. + write_lock_bh(&arm_state->susp_res_lock);
  21867. + if (--arm_state->blocked_count == 0)
  21868. + complete_all(&arm_state->blocked_blocker);
  21869. + }
  21870. + }
  21871. +
  21872. + stop_suspend_timer(arm_state);
  21873. +
  21874. + local_uc = ++arm_state->videocore_use_count;
  21875. + local_entity_uc = ++(*entity_uc);
  21876. +
  21877. + /* If there's a pending request which hasn't yet been serviced then
  21878. + * just clear it. If we're past VC_SUSPEND_REQUESTED state then
  21879. + * vc_resume_complete will block until we either resume or fail to
  21880. + * suspend */
  21881. + if (arm_state->vc_suspend_state <= VC_SUSPEND_REQUESTED)
  21882. + set_suspend_state(arm_state, VC_SUSPEND_IDLE);
  21883. +
  21884. + if ((use_type != USE_TYPE_SERVICE_NO_RESUME) && need_resume(state)) {
  21885. + set_resume_state(arm_state, VC_RESUME_REQUESTED);
  21886. + vchiq_log_info(vchiq_susp_log_level,
  21887. + "%s %s count %d, state count %d",
  21888. + __func__, entity, local_entity_uc, local_uc);
  21889. + request_poll(state, NULL, 0);
  21890. + } else
  21891. + vchiq_log_trace(vchiq_susp_log_level,
  21892. + "%s %s count %d, state count %d",
  21893. + __func__, entity, *entity_uc, local_uc);
  21894. +
  21895. +
  21896. + write_unlock_bh(&arm_state->susp_res_lock);
  21897. +
  21898. + /* Completion is in a done state when we're not suspended, so this won't
  21899. + * block for the non-suspended case. */
  21900. + if (!try_wait_for_completion(&arm_state->vc_resume_complete)) {
  21901. + vchiq_log_info(vchiq_susp_log_level, "%s %s wait for resume",
  21902. + __func__, entity);
  21903. + if (wait_for_completion_killable(
  21904. + &arm_state->vc_resume_complete) != 0) {
  21905. + vchiq_log_error(vchiq_susp_log_level, "%s %s wait for "
  21906. + "resume interrupted", __func__, entity);
  21907. + ret = VCHIQ_ERROR;
  21908. + goto out;
  21909. + }
  21910. + vchiq_log_info(vchiq_susp_log_level, "%s %s resumed", __func__,
  21911. + entity);
  21912. + }
  21913. +
  21914. + if (ret == VCHIQ_SUCCESS) {
  21915. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  21916. + long ack_cnt = atomic_xchg(&arm_state->ka_use_ack_count, 0);
  21917. + while (ack_cnt && (status == VCHIQ_SUCCESS)) {
  21918. + /* Send the use notify to videocore */
  21919. + status = vchiq_send_remote_use_active(state);
  21920. + if (status == VCHIQ_SUCCESS)
  21921. + ack_cnt--;
  21922. + else
  21923. + atomic_add(ack_cnt,
  21924. + &arm_state->ka_use_ack_count);
  21925. + }
  21926. + }
  21927. +
  21928. +out:
  21929. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, ret);
  21930. + return ret;
  21931. +}
  21932. +
  21933. +VCHIQ_STATUS_T
  21934. +vchiq_release_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service)
  21935. +{
  21936. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  21937. + VCHIQ_STATUS_T ret = VCHIQ_SUCCESS;
  21938. + char entity[16];
  21939. + int *entity_uc;
  21940. + int local_uc, local_entity_uc;
  21941. +
  21942. + if (!arm_state)
  21943. + goto out;
  21944. +
  21945. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  21946. +
  21947. + if (service) {
  21948. + sprintf(entity, "%c%c%c%c:%03d",
  21949. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  21950. + service->client_id);
  21951. + entity_uc = &service->service_use_count;
  21952. + } else {
  21953. + sprintf(entity, "PEER: ");
  21954. + entity_uc = &arm_state->peer_use_count;
  21955. + }
  21956. +
  21957. + write_lock_bh(&arm_state->susp_res_lock);
  21958. + if (!arm_state->videocore_use_count || !(*entity_uc)) {
  21959. + /* Don't use BUG_ON - don't allow user thread to crash kernel */
  21960. + WARN_ON(!arm_state->videocore_use_count);
  21961. + WARN_ON(!(*entity_uc));
  21962. + ret = VCHIQ_ERROR;
  21963. + goto unlock;
  21964. + }
  21965. + local_uc = --arm_state->videocore_use_count;
  21966. + local_entity_uc = --(*entity_uc);
  21967. +
  21968. + if (!vchiq_videocore_wanted(state)) {
  21969. + if (vchiq_platform_use_suspend_timer() &&
  21970. + !arm_state->resume_blocked) {
  21971. + /* Only use the timer if we're not trying to force
  21972. + * suspend (=> resume_blocked) */
  21973. + start_suspend_timer(arm_state);
  21974. + } else {
  21975. + vchiq_log_info(vchiq_susp_log_level,
  21976. + "%s %s count %d, state count %d - suspending",
  21977. + __func__, entity, *entity_uc,
  21978. + arm_state->videocore_use_count);
  21979. + vchiq_arm_vcsuspend(state);
  21980. + }
  21981. + } else
  21982. + vchiq_log_trace(vchiq_susp_log_level,
  21983. + "%s %s count %d, state count %d",
  21984. + __func__, entity, *entity_uc,
  21985. + arm_state->videocore_use_count);
  21986. +
  21987. +unlock:
  21988. + write_unlock_bh(&arm_state->susp_res_lock);
  21989. +
  21990. +out:
  21991. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, ret);
  21992. + return ret;
  21993. +}
  21994. +
  21995. +void
  21996. +vchiq_on_remote_use(VCHIQ_STATE_T *state)
  21997. +{
  21998. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  21999. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  22000. + atomic_inc(&arm_state->ka_use_count);
  22001. + complete(&arm_state->ka_evt);
  22002. +}
  22003. +
  22004. +void
  22005. +vchiq_on_remote_release(VCHIQ_STATE_T *state)
  22006. +{
  22007. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22008. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  22009. + atomic_inc(&arm_state->ka_release_count);
  22010. + complete(&arm_state->ka_evt);
  22011. +}
  22012. +
  22013. +VCHIQ_STATUS_T
  22014. +vchiq_use_service_internal(VCHIQ_SERVICE_T *service)
  22015. +{
  22016. + return vchiq_use_internal(service->state, service, USE_TYPE_SERVICE);
  22017. +}
  22018. +
  22019. +VCHIQ_STATUS_T
  22020. +vchiq_release_service_internal(VCHIQ_SERVICE_T *service)
  22021. +{
  22022. + return vchiq_release_internal(service->state, service);
  22023. +}
  22024. +
  22025. +static void suspend_timer_callback(unsigned long context)
  22026. +{
  22027. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *)context;
  22028. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22029. + if (!arm_state)
  22030. + goto out;
  22031. + vchiq_log_info(vchiq_susp_log_level,
  22032. + "%s - suspend timer expired - check suspend", __func__);
  22033. + vchiq_check_suspend(state);
  22034. +out:
  22035. + return;
  22036. +}
  22037. +
  22038. +VCHIQ_STATUS_T
  22039. +vchiq_use_service_no_resume(VCHIQ_SERVICE_HANDLE_T handle)
  22040. +{
  22041. + VCHIQ_STATUS_T ret = VCHIQ_ERROR;
  22042. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  22043. + if (service) {
  22044. + ret = vchiq_use_internal(service->state, service,
  22045. + USE_TYPE_SERVICE_NO_RESUME);
  22046. + unlock_service(service);
  22047. + }
  22048. + return ret;
  22049. +}
  22050. +
  22051. +VCHIQ_STATUS_T
  22052. +vchiq_use_service(VCHIQ_SERVICE_HANDLE_T handle)
  22053. +{
  22054. + VCHIQ_STATUS_T ret = VCHIQ_ERROR;
  22055. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  22056. + if (service) {
  22057. + ret = vchiq_use_internal(service->state, service,
  22058. + USE_TYPE_SERVICE);
  22059. + unlock_service(service);
  22060. + }
  22061. + return ret;
  22062. +}
  22063. +
  22064. +VCHIQ_STATUS_T
  22065. +vchiq_release_service(VCHIQ_SERVICE_HANDLE_T handle)
  22066. +{
  22067. + VCHIQ_STATUS_T ret = VCHIQ_ERROR;
  22068. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  22069. + if (service) {
  22070. + ret = vchiq_release_internal(service->state, service);
  22071. + unlock_service(service);
  22072. + }
  22073. + return ret;
  22074. +}
  22075. +
  22076. +void
  22077. +vchiq_dump_service_use_state(VCHIQ_STATE_T *state)
  22078. +{
  22079. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22080. + int i, j = 0;
  22081. + /* Only dump 64 services */
  22082. + static const int local_max_services = 64;
  22083. + /* If there's more than 64 services, only dump ones with
  22084. + * non-zero counts */
  22085. + int only_nonzero = 0;
  22086. + static const char *nz = "<-- preventing suspend";
  22087. +
  22088. + enum vc_suspend_status vc_suspend_state;
  22089. + enum vc_resume_status vc_resume_state;
  22090. + int peer_count;
  22091. + int vc_use_count;
  22092. + int active_services;
  22093. + struct service_data_struct {
  22094. + int fourcc;
  22095. + int clientid;
  22096. + int use_count;
  22097. + } service_data[local_max_services];
  22098. +
  22099. + if (!arm_state)
  22100. + return;
  22101. +
  22102. + read_lock_bh(&arm_state->susp_res_lock);
  22103. + vc_suspend_state = arm_state->vc_suspend_state;
  22104. + vc_resume_state = arm_state->vc_resume_state;
  22105. + peer_count = arm_state->peer_use_count;
  22106. + vc_use_count = arm_state->videocore_use_count;
  22107. + active_services = state->unused_service;
  22108. + if (active_services > local_max_services)
  22109. + only_nonzero = 1;
  22110. +
  22111. + for (i = 0; (i < active_services) && (j < local_max_services); i++) {
  22112. + VCHIQ_SERVICE_T *service_ptr = state->services[i];
  22113. + if (!service_ptr)
  22114. + continue;
  22115. +
  22116. + if (only_nonzero && !service_ptr->service_use_count)
  22117. + continue;
  22118. +
  22119. + if (service_ptr->srvstate != VCHIQ_SRVSTATE_FREE) {
  22120. + service_data[j].fourcc = service_ptr->base.fourcc;
  22121. + service_data[j].clientid = service_ptr->client_id;
  22122. + service_data[j++].use_count = service_ptr->
  22123. + service_use_count;
  22124. + }
  22125. + }
  22126. +
  22127. + read_unlock_bh(&arm_state->susp_res_lock);
  22128. +
  22129. + vchiq_log_warning(vchiq_susp_log_level,
  22130. + "-- Videcore suspend state: %s --",
  22131. + suspend_state_names[vc_suspend_state + VC_SUSPEND_NUM_OFFSET]);
  22132. + vchiq_log_warning(vchiq_susp_log_level,
  22133. + "-- Videcore resume state: %s --",
  22134. + resume_state_names[vc_resume_state + VC_RESUME_NUM_OFFSET]);
  22135. +
  22136. + if (only_nonzero)
  22137. + vchiq_log_warning(vchiq_susp_log_level, "Too many active "
  22138. + "services (%d). Only dumping up to first %d services "
  22139. + "with non-zero use-count", active_services,
  22140. + local_max_services);
  22141. +
  22142. + for (i = 0; i < j; i++) {
  22143. + vchiq_log_warning(vchiq_susp_log_level,
  22144. + "----- %c%c%c%c:%d service count %d %s",
  22145. + VCHIQ_FOURCC_AS_4CHARS(service_data[i].fourcc),
  22146. + service_data[i].clientid,
  22147. + service_data[i].use_count,
  22148. + service_data[i].use_count ? nz : "");
  22149. + }
  22150. + vchiq_log_warning(vchiq_susp_log_level,
  22151. + "----- VCHIQ use count count %d", peer_count);
  22152. + vchiq_log_warning(vchiq_susp_log_level,
  22153. + "--- Overall vchiq instance use count %d", vc_use_count);
  22154. +
  22155. + vchiq_dump_platform_use_state(state);
  22156. +}
  22157. +
  22158. +VCHIQ_STATUS_T
  22159. +vchiq_check_service(VCHIQ_SERVICE_T *service)
  22160. +{
  22161. + VCHIQ_ARM_STATE_T *arm_state;
  22162. + VCHIQ_STATUS_T ret = VCHIQ_ERROR;
  22163. +
  22164. + if (!service || !service->state)
  22165. + goto out;
  22166. +
  22167. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  22168. +
  22169. + arm_state = vchiq_platform_get_arm_state(service->state);
  22170. +
  22171. + read_lock_bh(&arm_state->susp_res_lock);
  22172. + if (service->service_use_count)
  22173. + ret = VCHIQ_SUCCESS;
  22174. + read_unlock_bh(&arm_state->susp_res_lock);
  22175. +
  22176. + if (ret == VCHIQ_ERROR) {
  22177. + vchiq_log_error(vchiq_susp_log_level,
  22178. + "%s ERROR - %c%c%c%c:%d service count %d, "
  22179. + "state count %d, videocore suspend state %s", __func__,
  22180. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  22181. + service->client_id, service->service_use_count,
  22182. + arm_state->videocore_use_count,
  22183. + suspend_state_names[arm_state->vc_suspend_state +
  22184. + VC_SUSPEND_NUM_OFFSET]);
  22185. + vchiq_dump_service_use_state(service->state);
  22186. + }
  22187. +out:
  22188. + return ret;
  22189. +}
  22190. +
  22191. +/* stub functions */
  22192. +void vchiq_on_remote_use_active(VCHIQ_STATE_T *state)
  22193. +{
  22194. + (void)state;
  22195. +}
  22196. +
  22197. +void vchiq_platform_conn_state_changed(VCHIQ_STATE_T *state,
  22198. + VCHIQ_CONNSTATE_T oldstate, VCHIQ_CONNSTATE_T newstate)
  22199. +{
  22200. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22201. + vchiq_log_info(vchiq_susp_log_level, "%d: %s->%s", state->id,
  22202. + get_conn_state_name(oldstate), get_conn_state_name(newstate));
  22203. + if (state->conn_state == VCHIQ_CONNSTATE_CONNECTED) {
  22204. + write_lock_bh(&arm_state->susp_res_lock);
  22205. + if (!arm_state->first_connect) {
  22206. + char threadname[10];
  22207. + arm_state->first_connect = 1;
  22208. + write_unlock_bh(&arm_state->susp_res_lock);
  22209. + snprintf(threadname, sizeof(threadname), "VCHIQka-%d",
  22210. + state->id);
  22211. + arm_state->ka_thread = kthread_create(
  22212. + &vchiq_keepalive_thread_func,
  22213. + (void *)state,
  22214. + threadname);
  22215. + if (arm_state->ka_thread == NULL) {
  22216. + vchiq_log_error(vchiq_susp_log_level,
  22217. + "vchiq: FATAL: couldn't create thread %s",
  22218. + threadname);
  22219. + } else {
  22220. + wake_up_process(arm_state->ka_thread);
  22221. + }
  22222. + } else
  22223. + write_unlock_bh(&arm_state->susp_res_lock);
  22224. + }
  22225. +}
  22226. +
  22227. +
  22228. +/****************************************************************************
  22229. +*
  22230. +* vchiq_init - called when the module is loaded.
  22231. +*
  22232. +***************************************************************************/
  22233. +
  22234. +static int __init
  22235. +vchiq_init(void)
  22236. +{
  22237. + int err;
  22238. + void *ptr_err;
  22239. +
  22240. + /* create proc entries */
  22241. + err = vchiq_proc_init();
  22242. + if (err != 0)
  22243. + goto failed_proc_init;
  22244. +
  22245. + err = alloc_chrdev_region(&vchiq_devid, VCHIQ_MINOR, 1, DEVICE_NAME);
  22246. + if (err != 0) {
  22247. + vchiq_log_error(vchiq_arm_log_level,
  22248. + "Unable to allocate device number");
  22249. + goto failed_alloc_chrdev;
  22250. + }
  22251. + cdev_init(&vchiq_cdev, &vchiq_fops);
  22252. + vchiq_cdev.owner = THIS_MODULE;
  22253. + err = cdev_add(&vchiq_cdev, vchiq_devid, 1);
  22254. + if (err != 0) {
  22255. + vchiq_log_error(vchiq_arm_log_level,
  22256. + "Unable to register device");
  22257. + goto failed_cdev_add;
  22258. + }
  22259. +
  22260. + /* create sysfs entries */
  22261. + vchiq_class = class_create(THIS_MODULE, DEVICE_NAME);
  22262. + ptr_err = vchiq_class;
  22263. + if (IS_ERR(ptr_err))
  22264. + goto failed_class_create;
  22265. +
  22266. + vchiq_dev = device_create(vchiq_class, NULL,
  22267. + vchiq_devid, NULL, "vchiq");
  22268. + ptr_err = vchiq_dev;
  22269. + if (IS_ERR(ptr_err))
  22270. + goto failed_device_create;
  22271. +
  22272. + err = vchiq_platform_init(&g_state);
  22273. + if (err != 0)
  22274. + goto failed_platform_init;
  22275. +
  22276. + vchiq_log_info(vchiq_arm_log_level,
  22277. + "vchiq: initialised - version %d (min %d), device %d.%d",
  22278. + VCHIQ_VERSION, VCHIQ_VERSION_MIN,
  22279. + MAJOR(vchiq_devid), MINOR(vchiq_devid));
  22280. +
  22281. + return 0;
  22282. +
  22283. +failed_platform_init:
  22284. + device_destroy(vchiq_class, vchiq_devid);
  22285. +failed_device_create:
  22286. + class_destroy(vchiq_class);
  22287. +failed_class_create:
  22288. + cdev_del(&vchiq_cdev);
  22289. + err = PTR_ERR(ptr_err);
  22290. +failed_cdev_add:
  22291. + unregister_chrdev_region(vchiq_devid, 1);
  22292. +failed_alloc_chrdev:
  22293. + vchiq_proc_deinit();
  22294. +failed_proc_init:
  22295. + vchiq_log_warning(vchiq_arm_log_level, "could not load vchiq");
  22296. + return err;
  22297. +}
  22298. +
  22299. +static int vchiq_instance_get_use_count(VCHIQ_INSTANCE_T instance)
  22300. +{
  22301. + VCHIQ_SERVICE_T *service;
  22302. + int use_count = 0, i;
  22303. + i = 0;
  22304. + while ((service = next_service_by_instance(instance->state,
  22305. + instance, &i)) != NULL) {
  22306. + use_count += service->service_use_count;
  22307. + unlock_service(service);
  22308. + }
  22309. + return use_count;
  22310. +}
  22311. +
  22312. +/* read the per-process use-count */
  22313. +static int proc_read_use_count(char *page, char **start,
  22314. + off_t off, int count,
  22315. + int *eof, void *data)
  22316. +{
  22317. + VCHIQ_INSTANCE_T instance = data;
  22318. + int len, use_count;
  22319. +
  22320. + use_count = vchiq_instance_get_use_count(instance);
  22321. + len = snprintf(page+off, count, "%d\n", use_count);
  22322. +
  22323. + return len;
  22324. +}
  22325. +
  22326. +/* add an instance (process) to the proc entries */
  22327. +static int vchiq_proc_add_instance(VCHIQ_INSTANCE_T instance)
  22328. +{
  22329. +#if 1
  22330. + return 0;
  22331. +#else
  22332. + char pidstr[32];
  22333. + struct proc_dir_entry *top, *use_count;
  22334. + struct proc_dir_entry *clients = vchiq_clients_top();
  22335. + int pid = instance->pid;
  22336. +
  22337. + snprintf(pidstr, sizeof(pidstr), "%d", pid);
  22338. + top = proc_mkdir(pidstr, clients);
  22339. + if (!top)
  22340. + goto fail_top;
  22341. +
  22342. + use_count = create_proc_read_entry("use_count",
  22343. + 0444, top,
  22344. + proc_read_use_count,
  22345. + instance);
  22346. + if (!use_count)
  22347. + goto fail_use_count;
  22348. +
  22349. + instance->proc_entry = top;
  22350. +
  22351. + return 0;
  22352. +
  22353. +fail_use_count:
  22354. + remove_proc_entry(top->name, clients);
  22355. +fail_top:
  22356. + return -ENOMEM;
  22357. +#endif
  22358. +}
  22359. +
  22360. +static void vchiq_proc_remove_instance(VCHIQ_INSTANCE_T instance)
  22361. +{
  22362. +#if 0
  22363. + struct proc_dir_entry *clients = vchiq_clients_top();
  22364. + remove_proc_entry("use_count", instance->proc_entry);
  22365. + remove_proc_entry(instance->proc_entry->name, clients);
  22366. +#endif
  22367. +}
  22368. +
  22369. +/****************************************************************************
  22370. +*
  22371. +* vchiq_exit - called when the module is unloaded.
  22372. +*
  22373. +***************************************************************************/
  22374. +
  22375. +static void __exit
  22376. +vchiq_exit(void)
  22377. +{
  22378. + vchiq_platform_exit(&g_state);
  22379. + device_destroy(vchiq_class, vchiq_devid);
  22380. + class_destroy(vchiq_class);
  22381. + cdev_del(&vchiq_cdev);
  22382. + unregister_chrdev_region(vchiq_devid, 1);
  22383. +}
  22384. +
  22385. +module_init(vchiq_init);
  22386. +module_exit(vchiq_exit);
  22387. +MODULE_LICENSE("GPL");
  22388. +MODULE_AUTHOR("Broadcom Corporation");
  22389. diff -Nur linux-3.13.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.h
  22390. --- linux-3.13.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.h 1970-01-01 01:00:00.000000000 +0100
  22391. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.h 2014-04-24 15:35:02.893551516 +0200
  22392. @@ -0,0 +1,212 @@
  22393. +/**
  22394. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  22395. + *
  22396. + * Redistribution and use in source and binary forms, with or without
  22397. + * modification, are permitted provided that the following conditions
  22398. + * are met:
  22399. + * 1. Redistributions of source code must retain the above copyright
  22400. + * notice, this list of conditions, and the following disclaimer,
  22401. + * without modification.
  22402. + * 2. Redistributions in binary form must reproduce the above copyright
  22403. + * notice, this list of conditions and the following disclaimer in the
  22404. + * documentation and/or other materials provided with the distribution.
  22405. + * 3. The names of the above-listed copyright holders may not be used
  22406. + * to endorse or promote products derived from this software without
  22407. + * specific prior written permission.
  22408. + *
  22409. + * ALTERNATIVELY, this software may be distributed under the terms of the
  22410. + * GNU General Public License ("GPL") version 2, as published by the Free
  22411. + * Software Foundation.
  22412. + *
  22413. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  22414. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  22415. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  22416. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  22417. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  22418. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  22419. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  22420. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  22421. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  22422. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  22423. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  22424. + */
  22425. +
  22426. +#ifndef VCHIQ_ARM_H
  22427. +#define VCHIQ_ARM_H
  22428. +
  22429. +#include <linux/mutex.h>
  22430. +#include <linux/semaphore.h>
  22431. +#include <linux/atomic.h>
  22432. +#include "vchiq_core.h"
  22433. +
  22434. +
  22435. +enum vc_suspend_status {
  22436. + VC_SUSPEND_FORCE_CANCELED = -3, /* Force suspend canceled, too busy */
  22437. + VC_SUSPEND_REJECTED = -2, /* Videocore rejected suspend request */
  22438. + VC_SUSPEND_FAILED = -1, /* Videocore suspend failed */
  22439. + VC_SUSPEND_IDLE = 0, /* VC active, no suspend actions */
  22440. + VC_SUSPEND_REQUESTED, /* User has requested suspend */
  22441. + VC_SUSPEND_IN_PROGRESS, /* Slot handler has recvd suspend request */
  22442. + VC_SUSPEND_SUSPENDED /* Videocore suspend succeeded */
  22443. +};
  22444. +
  22445. +enum vc_resume_status {
  22446. + VC_RESUME_FAILED = -1, /* Videocore resume failed */
  22447. + VC_RESUME_IDLE = 0, /* VC suspended, no resume actions */
  22448. + VC_RESUME_REQUESTED, /* User has requested resume */
  22449. + VC_RESUME_IN_PROGRESS, /* Slot handler has received resume request */
  22450. + VC_RESUME_RESUMED /* Videocore resumed successfully (active) */
  22451. +};
  22452. +
  22453. +
  22454. +enum USE_TYPE_E {
  22455. + USE_TYPE_SERVICE,
  22456. + USE_TYPE_SERVICE_NO_RESUME,
  22457. + USE_TYPE_VCHIQ
  22458. +};
  22459. +
  22460. +
  22461. +
  22462. +typedef struct vchiq_arm_state_struct {
  22463. + /* Keepalive-related data */
  22464. + struct task_struct *ka_thread;
  22465. + struct completion ka_evt;
  22466. + atomic_t ka_use_count;
  22467. + atomic_t ka_use_ack_count;
  22468. + atomic_t ka_release_count;
  22469. +
  22470. + struct completion vc_suspend_complete;
  22471. + struct completion vc_resume_complete;
  22472. +
  22473. + rwlock_t susp_res_lock;
  22474. + enum vc_suspend_status vc_suspend_state;
  22475. + enum vc_resume_status vc_resume_state;
  22476. +
  22477. + unsigned int wake_address;
  22478. +
  22479. + struct timer_list suspend_timer;
  22480. + int suspend_timer_timeout;
  22481. + int suspend_timer_running;
  22482. +
  22483. + /* Global use count for videocore.
  22484. + ** This is equal to the sum of the use counts for all services. When
  22485. + ** this hits zero the videocore suspend procedure will be initiated.
  22486. + */
  22487. + int videocore_use_count;
  22488. +
  22489. + /* Use count to track requests from videocore peer.
  22490. + ** This use count is not associated with a service, so needs to be
  22491. + ** tracked separately with the state.
  22492. + */
  22493. + int peer_use_count;
  22494. +
  22495. + /* Flag to indicate whether resume is blocked. This happens when the
  22496. + ** ARM is suspending
  22497. + */
  22498. + struct completion resume_blocker;
  22499. + int resume_blocked;
  22500. + struct completion blocked_blocker;
  22501. + int blocked_count;
  22502. +
  22503. + int autosuspend_override;
  22504. +
  22505. + /* Flag to indicate that the first vchiq connect has made it through.
  22506. + ** This means that both sides should be fully ready, and we should
  22507. + ** be able to suspend after this point.
  22508. + */
  22509. + int first_connect;
  22510. +
  22511. + unsigned long long suspend_start_time;
  22512. + unsigned long long sleep_start_time;
  22513. + unsigned long long resume_start_time;
  22514. + unsigned long long last_wake_time;
  22515. +
  22516. +} VCHIQ_ARM_STATE_T;
  22517. +
  22518. +extern int vchiq_arm_log_level;
  22519. +extern int vchiq_susp_log_level;
  22520. +
  22521. +extern int __init
  22522. +vchiq_platform_init(VCHIQ_STATE_T *state);
  22523. +
  22524. +extern void __exit
  22525. +vchiq_platform_exit(VCHIQ_STATE_T *state);
  22526. +
  22527. +extern VCHIQ_STATE_T *
  22528. +vchiq_get_state(void);
  22529. +
  22530. +extern VCHIQ_STATUS_T
  22531. +vchiq_arm_vcsuspend(VCHIQ_STATE_T *state);
  22532. +
  22533. +extern VCHIQ_STATUS_T
  22534. +vchiq_arm_force_suspend(VCHIQ_STATE_T *state);
  22535. +
  22536. +extern int
  22537. +vchiq_arm_allow_resume(VCHIQ_STATE_T *state);
  22538. +
  22539. +extern VCHIQ_STATUS_T
  22540. +vchiq_arm_vcresume(VCHIQ_STATE_T *state);
  22541. +
  22542. +extern VCHIQ_STATUS_T
  22543. +vchiq_arm_init_state(VCHIQ_STATE_T *state, VCHIQ_ARM_STATE_T *arm_state);
  22544. +
  22545. +extern int
  22546. +vchiq_check_resume(VCHIQ_STATE_T *state);
  22547. +
  22548. +extern void
  22549. +vchiq_check_suspend(VCHIQ_STATE_T *state);
  22550. +
  22551. +extern VCHIQ_STATUS_T
  22552. +vchiq_use_service(VCHIQ_SERVICE_HANDLE_T handle);
  22553. +
  22554. +extern VCHIQ_STATUS_T
  22555. +vchiq_release_service(VCHIQ_SERVICE_HANDLE_T handle);
  22556. +
  22557. +extern VCHIQ_STATUS_T
  22558. +vchiq_check_service(VCHIQ_SERVICE_T *service);
  22559. +
  22560. +extern VCHIQ_STATUS_T
  22561. +vchiq_platform_suspend(VCHIQ_STATE_T *state);
  22562. +
  22563. +extern int
  22564. +vchiq_platform_videocore_wanted(VCHIQ_STATE_T *state);
  22565. +
  22566. +extern int
  22567. +vchiq_platform_use_suspend_timer(void);
  22568. +
  22569. +extern void
  22570. +vchiq_dump_platform_use_state(VCHIQ_STATE_T *state);
  22571. +
  22572. +extern void
  22573. +vchiq_dump_service_use_state(VCHIQ_STATE_T *state);
  22574. +
  22575. +extern VCHIQ_ARM_STATE_T*
  22576. +vchiq_platform_get_arm_state(VCHIQ_STATE_T *state);
  22577. +
  22578. +extern int
  22579. +vchiq_videocore_wanted(VCHIQ_STATE_T *state);
  22580. +
  22581. +extern VCHIQ_STATUS_T
  22582. +vchiq_use_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
  22583. + enum USE_TYPE_E use_type);
  22584. +extern VCHIQ_STATUS_T
  22585. +vchiq_release_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service);
  22586. +
  22587. +void
  22588. +set_suspend_state(VCHIQ_ARM_STATE_T *arm_state,
  22589. + enum vc_suspend_status new_state);
  22590. +
  22591. +void
  22592. +set_resume_state(VCHIQ_ARM_STATE_T *arm_state,
  22593. + enum vc_resume_status new_state);
  22594. +
  22595. +void
  22596. +start_suspend_timer(VCHIQ_ARM_STATE_T *arm_state);
  22597. +
  22598. +extern int vchiq_proc_init(void);
  22599. +extern void vchiq_proc_deinit(void);
  22600. +extern struct proc_dir_entry *vchiq_proc_top(void);
  22601. +extern struct proc_dir_entry *vchiq_clients_top(void);
  22602. +
  22603. +
  22604. +#endif /* VCHIQ_ARM_H */
  22605. diff -Nur linux-3.13.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_build_info.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_build_info.h
  22606. --- linux-3.13.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_build_info.h 1970-01-01 01:00:00.000000000 +0100
  22607. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_build_info.h 2014-04-24 15:35:02.893551516 +0200
  22608. @@ -0,0 +1,37 @@
  22609. +/**
  22610. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  22611. + *
  22612. + * Redistribution and use in source and binary forms, with or without
  22613. + * modification, are permitted provided that the following conditions
  22614. + * are met:
  22615. + * 1. Redistributions of source code must retain the above copyright
  22616. + * notice, this list of conditions, and the following disclaimer,
  22617. + * without modification.
  22618. + * 2. Redistributions in binary form must reproduce the above copyright
  22619. + * notice, this list of conditions and the following disclaimer in the
  22620. + * documentation and/or other materials provided with the distribution.
  22621. + * 3. The names of the above-listed copyright holders may not be used
  22622. + * to endorse or promote products derived from this software without
  22623. + * specific prior written permission.
  22624. + *
  22625. + * ALTERNATIVELY, this software may be distributed under the terms of the
  22626. + * GNU General Public License ("GPL") version 2, as published by the Free
  22627. + * Software Foundation.
  22628. + *
  22629. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  22630. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  22631. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  22632. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  22633. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  22634. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  22635. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  22636. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  22637. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  22638. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  22639. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  22640. + */
  22641. +
  22642. +const char *vchiq_get_build_hostname(void);
  22643. +const char *vchiq_get_build_version(void);
  22644. +const char *vchiq_get_build_time(void);
  22645. +const char *vchiq_get_build_date(void);
  22646. diff -Nur linux-3.13.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_cfg.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_cfg.h
  22647. --- linux-3.13.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_cfg.h 1970-01-01 01:00:00.000000000 +0100
  22648. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_cfg.h 2014-04-24 15:35:02.893551516 +0200
  22649. @@ -0,0 +1,60 @@
  22650. +/**
  22651. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  22652. + *
  22653. + * Redistribution and use in source and binary forms, with or without
  22654. + * modification, are permitted provided that the following conditions
  22655. + * are met:
  22656. + * 1. Redistributions of source code must retain the above copyright
  22657. + * notice, this list of conditions, and the following disclaimer,
  22658. + * without modification.
  22659. + * 2. Redistributions in binary form must reproduce the above copyright
  22660. + * notice, this list of conditions and the following disclaimer in the
  22661. + * documentation and/or other materials provided with the distribution.
  22662. + * 3. The names of the above-listed copyright holders may not be used
  22663. + * to endorse or promote products derived from this software without
  22664. + * specific prior written permission.
  22665. + *
  22666. + * ALTERNATIVELY, this software may be distributed under the terms of the
  22667. + * GNU General Public License ("GPL") version 2, as published by the Free
  22668. + * Software Foundation.
  22669. + *
  22670. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  22671. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  22672. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  22673. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  22674. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  22675. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  22676. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  22677. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  22678. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  22679. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  22680. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  22681. + */
  22682. +
  22683. +#ifndef VCHIQ_CFG_H
  22684. +#define VCHIQ_CFG_H
  22685. +
  22686. +#define VCHIQ_MAGIC VCHIQ_MAKE_FOURCC('V', 'C', 'H', 'I')
  22687. +/* The version of VCHIQ - change with any non-trivial change */
  22688. +#define VCHIQ_VERSION 6
  22689. +/* The minimum compatible version - update to match VCHIQ_VERSION with any
  22690. +** incompatible change */
  22691. +#define VCHIQ_VERSION_MIN 3
  22692. +
  22693. +#define VCHIQ_MAX_STATES 1
  22694. +#define VCHIQ_MAX_SERVICES 4096
  22695. +#define VCHIQ_MAX_SLOTS 128
  22696. +#define VCHIQ_MAX_SLOTS_PER_SIDE 64
  22697. +
  22698. +#define VCHIQ_NUM_CURRENT_BULKS 32
  22699. +#define VCHIQ_NUM_SERVICE_BULKS 4
  22700. +
  22701. +#ifndef VCHIQ_ENABLE_DEBUG
  22702. +#define VCHIQ_ENABLE_DEBUG 1
  22703. +#endif
  22704. +
  22705. +#ifndef VCHIQ_ENABLE_STATS
  22706. +#define VCHIQ_ENABLE_STATS 1
  22707. +#endif
  22708. +
  22709. +#endif /* VCHIQ_CFG_H */
  22710. diff -Nur linux-3.13.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c
  22711. --- linux-3.13.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c 1970-01-01 01:00:00.000000000 +0100
  22712. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c 2014-04-24 15:35:02.893551516 +0200
  22713. @@ -0,0 +1,119 @@
  22714. +/**
  22715. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  22716. + *
  22717. + * Redistribution and use in source and binary forms, with or without
  22718. + * modification, are permitted provided that the following conditions
  22719. + * are met:
  22720. + * 1. Redistributions of source code must retain the above copyright
  22721. + * notice, this list of conditions, and the following disclaimer,
  22722. + * without modification.
  22723. + * 2. Redistributions in binary form must reproduce the above copyright
  22724. + * notice, this list of conditions and the following disclaimer in the
  22725. + * documentation and/or other materials provided with the distribution.
  22726. + * 3. The names of the above-listed copyright holders may not be used
  22727. + * to endorse or promote products derived from this software without
  22728. + * specific prior written permission.
  22729. + *
  22730. + * ALTERNATIVELY, this software may be distributed under the terms of the
  22731. + * GNU General Public License ("GPL") version 2, as published by the Free
  22732. + * Software Foundation.
  22733. + *
  22734. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  22735. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  22736. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  22737. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  22738. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  22739. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  22740. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  22741. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  22742. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  22743. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  22744. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  22745. + */
  22746. +
  22747. +#include "vchiq_connected.h"
  22748. +#include "vchiq_core.h"
  22749. +#include <linux/module.h>
  22750. +#include <linux/mutex.h>
  22751. +
  22752. +#define MAX_CALLBACKS 10
  22753. +
  22754. +static int g_connected;
  22755. +static int g_num_deferred_callbacks;
  22756. +static VCHIQ_CONNECTED_CALLBACK_T g_deferred_callback[MAX_CALLBACKS];
  22757. +static int g_once_init;
  22758. +static struct mutex g_connected_mutex;
  22759. +
  22760. +/****************************************************************************
  22761. +*
  22762. +* Function to initialize our lock.
  22763. +*
  22764. +***************************************************************************/
  22765. +
  22766. +static void connected_init(void)
  22767. +{
  22768. + if (!g_once_init) {
  22769. + mutex_init(&g_connected_mutex);
  22770. + g_once_init = 1;
  22771. + }
  22772. +}
  22773. +
  22774. +/****************************************************************************
  22775. +*
  22776. +* This function is used to defer initialization until the vchiq stack is
  22777. +* initialized. If the stack is already initialized, then the callback will
  22778. +* be made immediately, otherwise it will be deferred until
  22779. +* vchiq_call_connected_callbacks is called.
  22780. +*
  22781. +***************************************************************************/
  22782. +
  22783. +void vchiq_add_connected_callback(VCHIQ_CONNECTED_CALLBACK_T callback)
  22784. +{
  22785. + connected_init();
  22786. +
  22787. + if (mutex_lock_interruptible(&g_connected_mutex) != 0)
  22788. + return;
  22789. +
  22790. + if (g_connected)
  22791. + /* We're already connected. Call the callback immediately. */
  22792. +
  22793. + callback();
  22794. + else {
  22795. + if (g_num_deferred_callbacks >= MAX_CALLBACKS)
  22796. + vchiq_log_error(vchiq_core_log_level,
  22797. + "There already %d callback registered - "
  22798. + "please increase MAX_CALLBACKS",
  22799. + g_num_deferred_callbacks);
  22800. + else {
  22801. + g_deferred_callback[g_num_deferred_callbacks] =
  22802. + callback;
  22803. + g_num_deferred_callbacks++;
  22804. + }
  22805. + }
  22806. + mutex_unlock(&g_connected_mutex);
  22807. +}
  22808. +
  22809. +/****************************************************************************
  22810. +*
  22811. +* This function is called by the vchiq stack once it has been connected to
  22812. +* the videocore and clients can start to use the stack.
  22813. +*
  22814. +***************************************************************************/
  22815. +
  22816. +void vchiq_call_connected_callbacks(void)
  22817. +{
  22818. + int i;
  22819. +
  22820. + connected_init();
  22821. +
  22822. + if (mutex_lock_interruptible(&g_connected_mutex) != 0)
  22823. + return;
  22824. +
  22825. + for (i = 0; i < g_num_deferred_callbacks; i++)
  22826. + g_deferred_callback[i]();
  22827. +
  22828. + g_num_deferred_callbacks = 0;
  22829. + g_connected = 1;
  22830. + mutex_unlock(&g_connected_mutex);
  22831. +}
  22832. +EXPORT_SYMBOL(vchiq_add_connected_callback);
  22833. diff -Nur linux-3.13.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.h
  22834. --- linux-3.13.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.h 1970-01-01 01:00:00.000000000 +0100
  22835. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.h 2014-04-24 15:36:51.710754091 +0200
  22836. @@ -0,0 +1,50 @@
  22837. +/**
  22838. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  22839. + *
  22840. + * Redistribution and use in source and binary forms, with or without
  22841. + * modification, are permitted provided that the following conditions
  22842. + * are met:
  22843. + * 1. Redistributions of source code must retain the above copyright
  22844. + * notice, this list of conditions, and the following disclaimer,
  22845. + * without modification.
  22846. + * 2. Redistributions in binary form must reproduce the above copyright
  22847. + * notice, this list of conditions and the following disclaimer in the
  22848. + * documentation and/or other materials provided with the distribution.
  22849. + * 3. The names of the above-listed copyright holders may not be used
  22850. + * to endorse or promote products derived from this software without
  22851. + * specific prior written permission.
  22852. + *
  22853. + * ALTERNATIVELY, this software may be distributed under the terms of the
  22854. + * GNU General Public License ("GPL") version 2, as published by the Free
  22855. + * Software Foundation.
  22856. + *
  22857. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  22858. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  22859. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  22860. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  22861. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  22862. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  22863. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  22864. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  22865. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  22866. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  22867. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  22868. + */
  22869. +
  22870. +#ifndef VCHIQ_CONNECTED_H
  22871. +#define VCHIQ_CONNECTED_H
  22872. +
  22873. +/* ---- Include Files ----------------------------------------------------- */
  22874. +
  22875. +/* ---- Constants and Types ---------------------------------------------- */
  22876. +
  22877. +typedef void (*VCHIQ_CONNECTED_CALLBACK_T)(void);
  22878. +
  22879. +/* ---- Variable Externs ------------------------------------------------- */
  22880. +
  22881. +/* ---- Function Prototypes ---------------------------------------------- */
  22882. +
  22883. +void vchiq_add_connected_callback(VCHIQ_CONNECTED_CALLBACK_T callback);
  22884. +void vchiq_call_connected_callbacks(void);
  22885. +
  22886. +#endif /* VCHIQ_CONNECTED_H */
  22887. diff -Nur linux-3.13.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c
  22888. --- linux-3.13.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c 1970-01-01 01:00:00.000000000 +0100
  22889. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c 2014-04-24 15:35:02.893551516 +0200
  22890. @@ -0,0 +1,3824 @@
  22891. +/**
  22892. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  22893. + *
  22894. + * Redistribution and use in source and binary forms, with or without
  22895. + * modification, are permitted provided that the following conditions
  22896. + * are met:
  22897. + * 1. Redistributions of source code must retain the above copyright
  22898. + * notice, this list of conditions, and the following disclaimer,
  22899. + * without modification.
  22900. + * 2. Redistributions in binary form must reproduce the above copyright
  22901. + * notice, this list of conditions and the following disclaimer in the
  22902. + * documentation and/or other materials provided with the distribution.
  22903. + * 3. The names of the above-listed copyright holders may not be used
  22904. + * to endorse or promote products derived from this software without
  22905. + * specific prior written permission.
  22906. + *
  22907. + * ALTERNATIVELY, this software may be distributed under the terms of the
  22908. + * GNU General Public License ("GPL") version 2, as published by the Free
  22909. + * Software Foundation.
  22910. + *
  22911. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  22912. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  22913. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  22914. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  22915. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  22916. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  22917. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  22918. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  22919. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  22920. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  22921. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  22922. + */
  22923. +
  22924. +#include "vchiq_core.h"
  22925. +
  22926. +#define VCHIQ_SLOT_HANDLER_STACK 8192
  22927. +
  22928. +#define HANDLE_STATE_SHIFT 12
  22929. +
  22930. +#define SLOT_INFO_FROM_INDEX(state, index) (state->slot_info + (index))
  22931. +#define SLOT_DATA_FROM_INDEX(state, index) (state->slot_data + (index))
  22932. +#define SLOT_INDEX_FROM_DATA(state, data) \
  22933. + (((unsigned int)((char *)data - (char *)state->slot_data)) / \
  22934. + VCHIQ_SLOT_SIZE)
  22935. +#define SLOT_INDEX_FROM_INFO(state, info) \
  22936. + ((unsigned int)(info - state->slot_info))
  22937. +#define SLOT_QUEUE_INDEX_FROM_POS(pos) \
  22938. + ((int)((unsigned int)(pos) / VCHIQ_SLOT_SIZE))
  22939. +
  22940. +
  22941. +#define BULK_INDEX(x) (x & (VCHIQ_NUM_SERVICE_BULKS - 1))
  22942. +
  22943. +
  22944. +struct vchiq_open_payload {
  22945. + int fourcc;
  22946. + int client_id;
  22947. + short version;
  22948. + short version_min;
  22949. +};
  22950. +
  22951. +struct vchiq_openack_payload {
  22952. + short version;
  22953. +};
  22954. +
  22955. +/* we require this for consistency between endpoints */
  22956. +vchiq_static_assert(sizeof(VCHIQ_HEADER_T) == 8);
  22957. +vchiq_static_assert(IS_POW2(sizeof(VCHIQ_HEADER_T)));
  22958. +vchiq_static_assert(IS_POW2(VCHIQ_NUM_CURRENT_BULKS));
  22959. +vchiq_static_assert(IS_POW2(VCHIQ_NUM_SERVICE_BULKS));
  22960. +vchiq_static_assert(IS_POW2(VCHIQ_MAX_SERVICES));
  22961. +vchiq_static_assert(VCHIQ_VERSION >= VCHIQ_VERSION_MIN);
  22962. +
  22963. +/* Run time control of log level, based on KERN_XXX level. */
  22964. +int vchiq_core_log_level = VCHIQ_LOG_DEFAULT;
  22965. +int vchiq_core_msg_log_level = VCHIQ_LOG_DEFAULT;
  22966. +int vchiq_sync_log_level = VCHIQ_LOG_DEFAULT;
  22967. +
  22968. +static atomic_t pause_bulks_count = ATOMIC_INIT(0);
  22969. +
  22970. +static DEFINE_SPINLOCK(service_spinlock);
  22971. +DEFINE_SPINLOCK(bulk_waiter_spinlock);
  22972. +DEFINE_SPINLOCK(quota_spinlock);
  22973. +
  22974. +VCHIQ_STATE_T *vchiq_states[VCHIQ_MAX_STATES];
  22975. +static unsigned int handle_seq;
  22976. +
  22977. +static const char *const srvstate_names[] = {
  22978. + "FREE",
  22979. + "HIDDEN",
  22980. + "LISTENING",
  22981. + "OPENING",
  22982. + "OPEN",
  22983. + "OPENSYNC",
  22984. + "CLOSESENT",
  22985. + "CLOSERECVD",
  22986. + "CLOSEWAIT",
  22987. + "CLOSED"
  22988. +};
  22989. +
  22990. +static const char *const reason_names[] = {
  22991. + "SERVICE_OPENED",
  22992. + "SERVICE_CLOSED",
  22993. + "MESSAGE_AVAILABLE",
  22994. + "BULK_TRANSMIT_DONE",
  22995. + "BULK_RECEIVE_DONE",
  22996. + "BULK_TRANSMIT_ABORTED",
  22997. + "BULK_RECEIVE_ABORTED"
  22998. +};
  22999. +
  23000. +static const char *const conn_state_names[] = {
  23001. + "DISCONNECTED",
  23002. + "CONNECTING",
  23003. + "CONNECTED",
  23004. + "PAUSING",
  23005. + "PAUSE_SENT",
  23006. + "PAUSED",
  23007. + "RESUMING",
  23008. + "PAUSE_TIMEOUT",
  23009. + "RESUME_TIMEOUT"
  23010. +};
  23011. +
  23012. +
  23013. +static void
  23014. +release_message_sync(VCHIQ_STATE_T *state, VCHIQ_HEADER_T *header);
  23015. +
  23016. +static const char *msg_type_str(unsigned int msg_type)
  23017. +{
  23018. + switch (msg_type) {
  23019. + case VCHIQ_MSG_PADDING: return "PADDING";
  23020. + case VCHIQ_MSG_CONNECT: return "CONNECT";
  23021. + case VCHIQ_MSG_OPEN: return "OPEN";
  23022. + case VCHIQ_MSG_OPENACK: return "OPENACK";
  23023. + case VCHIQ_MSG_CLOSE: return "CLOSE";
  23024. + case VCHIQ_MSG_DATA: return "DATA";
  23025. + case VCHIQ_MSG_BULK_RX: return "BULK_RX";
  23026. + case VCHIQ_MSG_BULK_TX: return "BULK_TX";
  23027. + case VCHIQ_MSG_BULK_RX_DONE: return "BULK_RX_DONE";
  23028. + case VCHIQ_MSG_BULK_TX_DONE: return "BULK_TX_DONE";
  23029. + case VCHIQ_MSG_PAUSE: return "PAUSE";
  23030. + case VCHIQ_MSG_RESUME: return "RESUME";
  23031. + case VCHIQ_MSG_REMOTE_USE: return "REMOTE_USE";
  23032. + case VCHIQ_MSG_REMOTE_RELEASE: return "REMOTE_RELEASE";
  23033. + case VCHIQ_MSG_REMOTE_USE_ACTIVE: return "REMOTE_USE_ACTIVE";
  23034. + }
  23035. + return "???";
  23036. +}
  23037. +
  23038. +static inline void
  23039. +vchiq_set_service_state(VCHIQ_SERVICE_T *service, int newstate)
  23040. +{
  23041. + vchiq_log_info(vchiq_core_log_level, "%d: srv:%d %s->%s",
  23042. + service->state->id, service->localport,
  23043. + srvstate_names[service->srvstate],
  23044. + srvstate_names[newstate]);
  23045. + service->srvstate = newstate;
  23046. +}
  23047. +
  23048. +VCHIQ_SERVICE_T *
  23049. +find_service_by_handle(VCHIQ_SERVICE_HANDLE_T handle)
  23050. +{
  23051. + VCHIQ_SERVICE_T *service;
  23052. +
  23053. + spin_lock(&service_spinlock);
  23054. + service = handle_to_service(handle);
  23055. + if (service && (service->srvstate != VCHIQ_SRVSTATE_FREE) &&
  23056. + (service->handle == handle)) {
  23057. + BUG_ON(service->ref_count == 0);
  23058. + service->ref_count++;
  23059. + } else
  23060. + service = NULL;
  23061. + spin_unlock(&service_spinlock);
  23062. +
  23063. + if (!service)
  23064. + vchiq_log_info(vchiq_core_log_level,
  23065. + "Invalid service handle 0x%x", handle);
  23066. +
  23067. + return service;
  23068. +}
  23069. +
  23070. +VCHIQ_SERVICE_T *
  23071. +find_service_by_port(VCHIQ_STATE_T *state, int localport)
  23072. +{
  23073. + VCHIQ_SERVICE_T *service = NULL;
  23074. + if ((unsigned int)localport <= VCHIQ_PORT_MAX) {
  23075. + spin_lock(&service_spinlock);
  23076. + service = state->services[localport];
  23077. + if (service && (service->srvstate != VCHIQ_SRVSTATE_FREE)) {
  23078. + BUG_ON(service->ref_count == 0);
  23079. + service->ref_count++;
  23080. + } else
  23081. + service = NULL;
  23082. + spin_unlock(&service_spinlock);
  23083. + }
  23084. +
  23085. + if (!service)
  23086. + vchiq_log_info(vchiq_core_log_level,
  23087. + "Invalid port %d", localport);
  23088. +
  23089. + return service;
  23090. +}
  23091. +
  23092. +VCHIQ_SERVICE_T *
  23093. +find_service_for_instance(VCHIQ_INSTANCE_T instance,
  23094. + VCHIQ_SERVICE_HANDLE_T handle) {
  23095. + VCHIQ_SERVICE_T *service;
  23096. +
  23097. + spin_lock(&service_spinlock);
  23098. + service = handle_to_service(handle);
  23099. + if (service && (service->srvstate != VCHIQ_SRVSTATE_FREE) &&
  23100. + (service->handle == handle) &&
  23101. + (service->instance == instance)) {
  23102. + BUG_ON(service->ref_count == 0);
  23103. + service->ref_count++;
  23104. + } else
  23105. + service = NULL;
  23106. + spin_unlock(&service_spinlock);
  23107. +
  23108. + if (!service)
  23109. + vchiq_log_info(vchiq_core_log_level,
  23110. + "Invalid service handle 0x%x", handle);
  23111. +
  23112. + return service;
  23113. +}
  23114. +
  23115. +VCHIQ_SERVICE_T *
  23116. +next_service_by_instance(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance,
  23117. + int *pidx)
  23118. +{
  23119. + VCHIQ_SERVICE_T *service = NULL;
  23120. + int idx = *pidx;
  23121. +
  23122. + spin_lock(&service_spinlock);
  23123. + while (idx < state->unused_service) {
  23124. + VCHIQ_SERVICE_T *srv = state->services[idx++];
  23125. + if (srv && (srv->srvstate != VCHIQ_SRVSTATE_FREE) &&
  23126. + (srv->instance == instance)) {
  23127. + service = srv;
  23128. + BUG_ON(service->ref_count == 0);
  23129. + service->ref_count++;
  23130. + break;
  23131. + }
  23132. + }
  23133. + spin_unlock(&service_spinlock);
  23134. +
  23135. + *pidx = idx;
  23136. +
  23137. + return service;
  23138. +}
  23139. +
  23140. +void
  23141. +lock_service(VCHIQ_SERVICE_T *service)
  23142. +{
  23143. + spin_lock(&service_spinlock);
  23144. + BUG_ON(!service || (service->ref_count == 0));
  23145. + if (service)
  23146. + service->ref_count++;
  23147. + spin_unlock(&service_spinlock);
  23148. +}
  23149. +
  23150. +void
  23151. +unlock_service(VCHIQ_SERVICE_T *service)
  23152. +{
  23153. + VCHIQ_STATE_T *state = service->state;
  23154. + spin_lock(&service_spinlock);
  23155. + BUG_ON(!service || (service->ref_count == 0));
  23156. + if (service && service->ref_count) {
  23157. + service->ref_count--;
  23158. + if (!service->ref_count) {
  23159. + BUG_ON(service->srvstate != VCHIQ_SRVSTATE_FREE);
  23160. + state->services[service->localport] = NULL;
  23161. + } else
  23162. + service = NULL;
  23163. + }
  23164. + spin_unlock(&service_spinlock);
  23165. +
  23166. + if (service && service->userdata_term)
  23167. + service->userdata_term(service->base.userdata);
  23168. +
  23169. + kfree(service);
  23170. +}
  23171. +
  23172. +int
  23173. +vchiq_get_client_id(VCHIQ_SERVICE_HANDLE_T handle)
  23174. +{
  23175. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  23176. + int id;
  23177. +
  23178. + id = service ? service->client_id : 0;
  23179. + if (service)
  23180. + unlock_service(service);
  23181. +
  23182. + return id;
  23183. +}
  23184. +
  23185. +void *
  23186. +vchiq_get_service_userdata(VCHIQ_SERVICE_HANDLE_T handle)
  23187. +{
  23188. + VCHIQ_SERVICE_T *service = handle_to_service(handle);
  23189. +
  23190. + return service ? service->base.userdata : NULL;
  23191. +}
  23192. +
  23193. +int
  23194. +vchiq_get_service_fourcc(VCHIQ_SERVICE_HANDLE_T handle)
  23195. +{
  23196. + VCHIQ_SERVICE_T *service = handle_to_service(handle);
  23197. +
  23198. + return service ? service->base.fourcc : 0;
  23199. +}
  23200. +
  23201. +static void
  23202. +mark_service_closing_internal(VCHIQ_SERVICE_T *service, int sh_thread)
  23203. +{
  23204. + VCHIQ_STATE_T *state = service->state;
  23205. + VCHIQ_SERVICE_QUOTA_T *service_quota;
  23206. +
  23207. + service->closing = 1;
  23208. +
  23209. + /* Synchronise with other threads. */
  23210. + mutex_lock(&state->recycle_mutex);
  23211. + mutex_unlock(&state->recycle_mutex);
  23212. + if (!sh_thread || (state->conn_state != VCHIQ_CONNSTATE_PAUSE_SENT)) {
  23213. + /* If we're pausing then the slot_mutex is held until resume
  23214. + * by the slot handler. Therefore don't try to acquire this
  23215. + * mutex if we're the slot handler and in the pause sent state.
  23216. + * We don't need to in this case anyway. */
  23217. + mutex_lock(&state->slot_mutex);
  23218. + mutex_unlock(&state->slot_mutex);
  23219. + }
  23220. +
  23221. + /* Unblock any sending thread. */
  23222. + service_quota = &state->service_quotas[service->localport];
  23223. + up(&service_quota->quota_event);
  23224. +}
  23225. +
  23226. +static void
  23227. +mark_service_closing(VCHIQ_SERVICE_T *service)
  23228. +{
  23229. + mark_service_closing_internal(service, 0);
  23230. +}
  23231. +
  23232. +static inline VCHIQ_STATUS_T
  23233. +make_service_callback(VCHIQ_SERVICE_T *service, VCHIQ_REASON_T reason,
  23234. + VCHIQ_HEADER_T *header, void *bulk_userdata)
  23235. +{
  23236. + VCHIQ_STATUS_T status;
  23237. + vchiq_log_trace(vchiq_core_log_level, "%d: callback:%d (%s, %x, %x)",
  23238. + service->state->id, service->localport, reason_names[reason],
  23239. + (unsigned int)header, (unsigned int)bulk_userdata);
  23240. + status = service->base.callback(reason, header, service->handle,
  23241. + bulk_userdata);
  23242. + if (status == VCHIQ_ERROR) {
  23243. + vchiq_log_warning(vchiq_core_log_level,
  23244. + "%d: ignoring ERROR from callback to service %x",
  23245. + service->state->id, service->handle);
  23246. + status = VCHIQ_SUCCESS;
  23247. + }
  23248. + return status;
  23249. +}
  23250. +
  23251. +inline void
  23252. +vchiq_set_conn_state(VCHIQ_STATE_T *state, VCHIQ_CONNSTATE_T newstate)
  23253. +{
  23254. + VCHIQ_CONNSTATE_T oldstate = state->conn_state;
  23255. + vchiq_log_info(vchiq_core_log_level, "%d: %s->%s", state->id,
  23256. + conn_state_names[oldstate],
  23257. + conn_state_names[newstate]);
  23258. + state->conn_state = newstate;
  23259. + vchiq_platform_conn_state_changed(state, oldstate, newstate);
  23260. +}
  23261. +
  23262. +static inline void
  23263. +remote_event_create(REMOTE_EVENT_T *event)
  23264. +{
  23265. + event->armed = 0;
  23266. + /* Don't clear the 'fired' flag because it may already have been set
  23267. + ** by the other side. */
  23268. + sema_init(event->event, 0);
  23269. +}
  23270. +
  23271. +static inline void
  23272. +remote_event_destroy(REMOTE_EVENT_T *event)
  23273. +{
  23274. + (void)event;
  23275. +}
  23276. +
  23277. +static inline int
  23278. +remote_event_wait(REMOTE_EVENT_T *event)
  23279. +{
  23280. + if (!event->fired) {
  23281. + event->armed = 1;
  23282. + dsb();
  23283. + if (!event->fired) {
  23284. + if (down_interruptible(event->event) != 0) {
  23285. + event->armed = 0;
  23286. + return 0;
  23287. + }
  23288. + }
  23289. + event->armed = 0;
  23290. + wmb();
  23291. + }
  23292. +
  23293. + event->fired = 0;
  23294. + return 1;
  23295. +}
  23296. +
  23297. +static inline void
  23298. +remote_event_signal_local(REMOTE_EVENT_T *event)
  23299. +{
  23300. + event->armed = 0;
  23301. + up(event->event);
  23302. +}
  23303. +
  23304. +static inline void
  23305. +remote_event_poll(REMOTE_EVENT_T *event)
  23306. +{
  23307. + if (event->fired && event->armed)
  23308. + remote_event_signal_local(event);
  23309. +}
  23310. +
  23311. +void
  23312. +remote_event_pollall(VCHIQ_STATE_T *state)
  23313. +{
  23314. + remote_event_poll(&state->local->sync_trigger);
  23315. + remote_event_poll(&state->local->sync_release);
  23316. + remote_event_poll(&state->local->trigger);
  23317. + remote_event_poll(&state->local->recycle);
  23318. +}
  23319. +
  23320. +/* Round up message sizes so that any space at the end of a slot is always big
  23321. +** enough for a header. This relies on header size being a power of two, which
  23322. +** has been verified earlier by a static assertion. */
  23323. +
  23324. +static inline unsigned int
  23325. +calc_stride(unsigned int size)
  23326. +{
  23327. + /* Allow room for the header */
  23328. + size += sizeof(VCHIQ_HEADER_T);
  23329. +
  23330. + /* Round up */
  23331. + return (size + sizeof(VCHIQ_HEADER_T) - 1) & ~(sizeof(VCHIQ_HEADER_T)
  23332. + - 1);
  23333. +}
  23334. +
  23335. +/* Called by the slot handler thread */
  23336. +static VCHIQ_SERVICE_T *
  23337. +get_listening_service(VCHIQ_STATE_T *state, int fourcc)
  23338. +{
  23339. + int i;
  23340. +
  23341. + WARN_ON(fourcc == VCHIQ_FOURCC_INVALID);
  23342. +
  23343. + for (i = 0; i < state->unused_service; i++) {
  23344. + VCHIQ_SERVICE_T *service = state->services[i];
  23345. + if (service &&
  23346. + (service->public_fourcc == fourcc) &&
  23347. + ((service->srvstate == VCHIQ_SRVSTATE_LISTENING) ||
  23348. + ((service->srvstate == VCHIQ_SRVSTATE_OPEN) &&
  23349. + (service->remoteport == VCHIQ_PORT_FREE)))) {
  23350. + lock_service(service);
  23351. + return service;
  23352. + }
  23353. + }
  23354. +
  23355. + return NULL;
  23356. +}
  23357. +
  23358. +/* Called by the slot handler thread */
  23359. +static VCHIQ_SERVICE_T *
  23360. +get_connected_service(VCHIQ_STATE_T *state, unsigned int port)
  23361. +{
  23362. + int i;
  23363. + for (i = 0; i < state->unused_service; i++) {
  23364. + VCHIQ_SERVICE_T *service = state->services[i];
  23365. + if (service && (service->srvstate == VCHIQ_SRVSTATE_OPEN)
  23366. + && (service->remoteport == port)) {
  23367. + lock_service(service);
  23368. + return service;
  23369. + }
  23370. + }
  23371. + return NULL;
  23372. +}
  23373. +
  23374. +inline void
  23375. +request_poll(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service, int poll_type)
  23376. +{
  23377. + uint32_t value;
  23378. +
  23379. + if (service) {
  23380. + do {
  23381. + value = atomic_read(&service->poll_flags);
  23382. + } while (atomic_cmpxchg(&service->poll_flags, value,
  23383. + value | (1 << poll_type)) != value);
  23384. +
  23385. + do {
  23386. + value = atomic_read(&state->poll_services[
  23387. + service->localport>>5]);
  23388. + } while (atomic_cmpxchg(
  23389. + &state->poll_services[service->localport>>5],
  23390. + value, value | (1 << (service->localport & 0x1f)))
  23391. + != value);
  23392. + }
  23393. +
  23394. + state->poll_needed = 1;
  23395. + wmb();
  23396. +
  23397. + /* ... and ensure the slot handler runs. */
  23398. + remote_event_signal_local(&state->local->trigger);
  23399. +}
  23400. +
  23401. +/* Called from queue_message, by the slot handler and application threads,
  23402. +** with slot_mutex held */
  23403. +static VCHIQ_HEADER_T *
  23404. +reserve_space(VCHIQ_STATE_T *state, int space, int is_blocking)
  23405. +{
  23406. + VCHIQ_SHARED_STATE_T *local = state->local;
  23407. + int tx_pos = state->local_tx_pos;
  23408. + int slot_space = VCHIQ_SLOT_SIZE - (tx_pos & VCHIQ_SLOT_MASK);
  23409. +
  23410. + if (space > slot_space) {
  23411. + VCHIQ_HEADER_T *header;
  23412. + /* Fill the remaining space with padding */
  23413. + WARN_ON(state->tx_data == NULL);
  23414. + header = (VCHIQ_HEADER_T *)
  23415. + (state->tx_data + (tx_pos & VCHIQ_SLOT_MASK));
  23416. + header->msgid = VCHIQ_MSGID_PADDING;
  23417. + header->size = slot_space - sizeof(VCHIQ_HEADER_T);
  23418. +
  23419. + tx_pos += slot_space;
  23420. + }
  23421. +
  23422. + /* If necessary, get the next slot. */
  23423. + if ((tx_pos & VCHIQ_SLOT_MASK) == 0) {
  23424. + int slot_index;
  23425. +
  23426. + /* If there is no free slot... */
  23427. +
  23428. + if (down_trylock(&state->slot_available_event) != 0) {
  23429. + /* ...wait for one. */
  23430. +
  23431. + VCHIQ_STATS_INC(state, slot_stalls);
  23432. +
  23433. + /* But first, flush through the last slot. */
  23434. + state->local_tx_pos = tx_pos;
  23435. + local->tx_pos = tx_pos;
  23436. + remote_event_signal(&state->remote->trigger);
  23437. +
  23438. + if (!is_blocking ||
  23439. + (down_interruptible(
  23440. + &state->slot_available_event) != 0))
  23441. + return NULL; /* No space available */
  23442. + }
  23443. +
  23444. + BUG_ON(tx_pos ==
  23445. + (state->slot_queue_available * VCHIQ_SLOT_SIZE));
  23446. +
  23447. + slot_index = local->slot_queue[
  23448. + SLOT_QUEUE_INDEX_FROM_POS(tx_pos) &
  23449. + VCHIQ_SLOT_QUEUE_MASK];
  23450. + state->tx_data =
  23451. + (char *)SLOT_DATA_FROM_INDEX(state, slot_index);
  23452. + }
  23453. +
  23454. + state->local_tx_pos = tx_pos + space;
  23455. +
  23456. + return (VCHIQ_HEADER_T *)(state->tx_data + (tx_pos & VCHIQ_SLOT_MASK));
  23457. +}
  23458. +
  23459. +/* Called by the recycle thread. */
  23460. +static void
  23461. +process_free_queue(VCHIQ_STATE_T *state)
  23462. +{
  23463. + VCHIQ_SHARED_STATE_T *local = state->local;
  23464. + BITSET_T service_found[BITSET_SIZE(VCHIQ_MAX_SERVICES)];
  23465. + int slot_queue_available;
  23466. +
  23467. + /* Use a read memory barrier to ensure that any state that may have
  23468. + ** been modified by another thread is not masked by stale prefetched
  23469. + ** values. */
  23470. + rmb();
  23471. +
  23472. + /* Find slots which have been freed by the other side, and return them
  23473. + ** to the available queue. */
  23474. + slot_queue_available = state->slot_queue_available;
  23475. +
  23476. + while (slot_queue_available != local->slot_queue_recycle) {
  23477. + unsigned int pos;
  23478. + int slot_index = local->slot_queue[slot_queue_available++ &
  23479. + VCHIQ_SLOT_QUEUE_MASK];
  23480. + char *data = (char *)SLOT_DATA_FROM_INDEX(state, slot_index);
  23481. + int data_found = 0;
  23482. +
  23483. + vchiq_log_trace(vchiq_core_log_level, "%d: pfq %d=%x %x %x",
  23484. + state->id, slot_index, (unsigned int)data,
  23485. + local->slot_queue_recycle, slot_queue_available);
  23486. +
  23487. + /* Initialise the bitmask for services which have used this
  23488. + ** slot */
  23489. + BITSET_ZERO(service_found);
  23490. +
  23491. + pos = 0;
  23492. +
  23493. + while (pos < VCHIQ_SLOT_SIZE) {
  23494. + VCHIQ_HEADER_T *header =
  23495. + (VCHIQ_HEADER_T *)(data + pos);
  23496. + int msgid = header->msgid;
  23497. + if (VCHIQ_MSG_TYPE(msgid) == VCHIQ_MSG_DATA) {
  23498. + int port = VCHIQ_MSG_SRCPORT(msgid);
  23499. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  23500. + &state->service_quotas[port];
  23501. + int count;
  23502. + spin_lock(&quota_spinlock);
  23503. + count = service_quota->message_use_count;
  23504. + if (count > 0)
  23505. + service_quota->message_use_count =
  23506. + count - 1;
  23507. + spin_unlock(&quota_spinlock);
  23508. +
  23509. + if (count == service_quota->message_quota)
  23510. + /* Signal the service that it
  23511. + ** has dropped below its quota
  23512. + */
  23513. + up(&service_quota->quota_event);
  23514. + else if (count == 0) {
  23515. + vchiq_log_error(vchiq_core_log_level,
  23516. + "service %d "
  23517. + "message_use_count=%d "
  23518. + "(header %x, msgid %x, "
  23519. + "header->msgid %x, "
  23520. + "header->size %x)",
  23521. + port,
  23522. + service_quota->
  23523. + message_use_count,
  23524. + (unsigned int)header, msgid,
  23525. + header->msgid,
  23526. + header->size);
  23527. + WARN(1, "invalid message use count\n");
  23528. + }
  23529. + if (!BITSET_IS_SET(service_found, port)) {
  23530. + /* Set the found bit for this service */
  23531. + BITSET_SET(service_found, port);
  23532. +
  23533. + spin_lock(&quota_spinlock);
  23534. + count = service_quota->slot_use_count;
  23535. + if (count > 0)
  23536. + service_quota->slot_use_count =
  23537. + count - 1;
  23538. + spin_unlock(&quota_spinlock);
  23539. +
  23540. + if (count > 0) {
  23541. + /* Signal the service in case
  23542. + ** it has dropped below its
  23543. + ** quota */
  23544. + up(&service_quota->quota_event);
  23545. + vchiq_log_trace(
  23546. + vchiq_core_log_level,
  23547. + "%d: pfq:%d %x@%x - "
  23548. + "slot_use->%d",
  23549. + state->id, port,
  23550. + header->size,
  23551. + (unsigned int)header,
  23552. + count - 1);
  23553. + } else {
  23554. + vchiq_log_error(
  23555. + vchiq_core_log_level,
  23556. + "service %d "
  23557. + "slot_use_count"
  23558. + "=%d (header %x"
  23559. + ", msgid %x, "
  23560. + "header->msgid"
  23561. + " %x, header->"
  23562. + "size %x)",
  23563. + port, count,
  23564. + (unsigned int)header,
  23565. + msgid,
  23566. + header->msgid,
  23567. + header->size);
  23568. + WARN(1, "bad slot use count\n");
  23569. + }
  23570. + }
  23571. +
  23572. + data_found = 1;
  23573. + }
  23574. +
  23575. + pos += calc_stride(header->size);
  23576. + if (pos > VCHIQ_SLOT_SIZE) {
  23577. + vchiq_log_error(vchiq_core_log_level,
  23578. + "pfq - pos %x: header %x, msgid %x, "
  23579. + "header->msgid %x, header->size %x",
  23580. + pos, (unsigned int)header, msgid,
  23581. + header->msgid, header->size);
  23582. + WARN(1, "invalid slot position\n");
  23583. + }
  23584. + }
  23585. +
  23586. + if (data_found) {
  23587. + int count;
  23588. + spin_lock(&quota_spinlock);
  23589. + count = state->data_use_count;
  23590. + if (count > 0)
  23591. + state->data_use_count =
  23592. + count - 1;
  23593. + spin_unlock(&quota_spinlock);
  23594. + if (count == state->data_quota)
  23595. + up(&state->data_quota_event);
  23596. + }
  23597. +
  23598. + state->slot_queue_available = slot_queue_available;
  23599. + up(&state->slot_available_event);
  23600. + }
  23601. +}
  23602. +
  23603. +/* Called by the slot handler and application threads */
  23604. +static VCHIQ_STATUS_T
  23605. +queue_message(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
  23606. + int msgid, const VCHIQ_ELEMENT_T *elements,
  23607. + int count, int size, int is_blocking)
  23608. +{
  23609. + VCHIQ_SHARED_STATE_T *local;
  23610. + VCHIQ_SERVICE_QUOTA_T *service_quota = NULL;
  23611. + VCHIQ_HEADER_T *header;
  23612. + int type = VCHIQ_MSG_TYPE(msgid);
  23613. +
  23614. + unsigned int stride;
  23615. +
  23616. + local = state->local;
  23617. +
  23618. + stride = calc_stride(size);
  23619. +
  23620. + WARN_ON(!(stride <= VCHIQ_SLOT_SIZE));
  23621. +
  23622. + if ((type != VCHIQ_MSG_RESUME) &&
  23623. + (mutex_lock_interruptible(&state->slot_mutex) != 0))
  23624. + return VCHIQ_RETRY;
  23625. +
  23626. + if (type == VCHIQ_MSG_DATA) {
  23627. + int tx_end_index;
  23628. +
  23629. + BUG_ON(!service);
  23630. +
  23631. + if (service->closing) {
  23632. + /* The service has been closed */
  23633. + mutex_unlock(&state->slot_mutex);
  23634. + return VCHIQ_ERROR;
  23635. + }
  23636. +
  23637. + service_quota = &state->service_quotas[service->localport];
  23638. +
  23639. + spin_lock(&quota_spinlock);
  23640. +
  23641. + /* Ensure this service doesn't use more than its quota of
  23642. + ** messages or slots */
  23643. + tx_end_index = SLOT_QUEUE_INDEX_FROM_POS(
  23644. + state->local_tx_pos + stride - 1);
  23645. +
  23646. + /* Ensure data messages don't use more than their quota of
  23647. + ** slots */
  23648. + while ((tx_end_index != state->previous_data_index) &&
  23649. + (state->data_use_count == state->data_quota)) {
  23650. + VCHIQ_STATS_INC(state, data_stalls);
  23651. + spin_unlock(&quota_spinlock);
  23652. + mutex_unlock(&state->slot_mutex);
  23653. +
  23654. + if (down_interruptible(&state->data_quota_event)
  23655. + != 0)
  23656. + return VCHIQ_RETRY;
  23657. +
  23658. + mutex_lock(&state->slot_mutex);
  23659. + spin_lock(&quota_spinlock);
  23660. + tx_end_index = SLOT_QUEUE_INDEX_FROM_POS(
  23661. + state->local_tx_pos + stride - 1);
  23662. + if ((tx_end_index == state->previous_data_index) ||
  23663. + (state->data_use_count < state->data_quota)) {
  23664. + /* Pass the signal on to other waiters */
  23665. + up(&state->data_quota_event);
  23666. + break;
  23667. + }
  23668. + }
  23669. +
  23670. + while ((service_quota->message_use_count ==
  23671. + service_quota->message_quota) ||
  23672. + ((tx_end_index != service_quota->previous_tx_index) &&
  23673. + (service_quota->slot_use_count ==
  23674. + service_quota->slot_quota))) {
  23675. + spin_unlock(&quota_spinlock);
  23676. + vchiq_log_trace(vchiq_core_log_level,
  23677. + "%d: qm:%d %s,%x - quota stall "
  23678. + "(msg %d, slot %d)",
  23679. + state->id, service->localport,
  23680. + msg_type_str(type), size,
  23681. + service_quota->message_use_count,
  23682. + service_quota->slot_use_count);
  23683. + VCHIQ_SERVICE_STATS_INC(service, quota_stalls);
  23684. + mutex_unlock(&state->slot_mutex);
  23685. + if (down_interruptible(&service_quota->quota_event)
  23686. + != 0)
  23687. + return VCHIQ_RETRY;
  23688. + if (service->closing)
  23689. + return VCHIQ_ERROR;
  23690. + if (mutex_lock_interruptible(&state->slot_mutex) != 0)
  23691. + return VCHIQ_RETRY;
  23692. + if (service->srvstate != VCHIQ_SRVSTATE_OPEN) {
  23693. + /* The service has been closed */
  23694. + mutex_unlock(&state->slot_mutex);
  23695. + return VCHIQ_ERROR;
  23696. + }
  23697. + spin_lock(&quota_spinlock);
  23698. + tx_end_index = SLOT_QUEUE_INDEX_FROM_POS(
  23699. + state->local_tx_pos + stride - 1);
  23700. + }
  23701. +
  23702. + spin_unlock(&quota_spinlock);
  23703. + }
  23704. +
  23705. + header = reserve_space(state, stride, is_blocking);
  23706. +
  23707. + if (!header) {
  23708. + if (service)
  23709. + VCHIQ_SERVICE_STATS_INC(service, slot_stalls);
  23710. + mutex_unlock(&state->slot_mutex);
  23711. + return VCHIQ_RETRY;
  23712. + }
  23713. +
  23714. + if (type == VCHIQ_MSG_DATA) {
  23715. + int i, pos;
  23716. + int tx_end_index;
  23717. + int slot_use_count;
  23718. +
  23719. + vchiq_log_info(vchiq_core_log_level,
  23720. + "%d: qm %s@%x,%x (%d->%d)",
  23721. + state->id,
  23722. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  23723. + (unsigned int)header, size,
  23724. + VCHIQ_MSG_SRCPORT(msgid),
  23725. + VCHIQ_MSG_DSTPORT(msgid));
  23726. +
  23727. + BUG_ON(!service);
  23728. +
  23729. + for (i = 0, pos = 0; i < (unsigned int)count;
  23730. + pos += elements[i++].size)
  23731. + if (elements[i].size) {
  23732. + if (vchiq_copy_from_user
  23733. + (header->data + pos, elements[i].data,
  23734. + (size_t) elements[i].size) !=
  23735. + VCHIQ_SUCCESS) {
  23736. + mutex_unlock(&state->slot_mutex);
  23737. + VCHIQ_SERVICE_STATS_INC(service,
  23738. + error_count);
  23739. + return VCHIQ_ERROR;
  23740. + }
  23741. + if (i == 0) {
  23742. + if (vchiq_core_msg_log_level >=
  23743. + VCHIQ_LOG_INFO)
  23744. + vchiq_log_dump_mem("Sent", 0,
  23745. + header->data + pos,
  23746. + min(64u,
  23747. + elements[0].size));
  23748. + }
  23749. + }
  23750. +
  23751. + spin_lock(&quota_spinlock);
  23752. + service_quota->message_use_count++;
  23753. +
  23754. + tx_end_index =
  23755. + SLOT_QUEUE_INDEX_FROM_POS(state->local_tx_pos - 1);
  23756. +
  23757. + /* If this transmission can't fit in the last slot used by any
  23758. + ** service, the data_use_count must be increased. */
  23759. + if (tx_end_index != state->previous_data_index) {
  23760. + state->previous_data_index = tx_end_index;
  23761. + state->data_use_count++;
  23762. + }
  23763. +
  23764. + /* If this isn't the same slot last used by this service,
  23765. + ** the service's slot_use_count must be increased. */
  23766. + if (tx_end_index != service_quota->previous_tx_index) {
  23767. + service_quota->previous_tx_index = tx_end_index;
  23768. + slot_use_count = ++service_quota->slot_use_count;
  23769. + } else {
  23770. + slot_use_count = 0;
  23771. + }
  23772. +
  23773. + spin_unlock(&quota_spinlock);
  23774. +
  23775. + if (slot_use_count)
  23776. + vchiq_log_trace(vchiq_core_log_level,
  23777. + "%d: qm:%d %s,%x - slot_use->%d (hdr %p)",
  23778. + state->id, service->localport,
  23779. + msg_type_str(VCHIQ_MSG_TYPE(msgid)), size,
  23780. + slot_use_count, header);
  23781. +
  23782. + VCHIQ_SERVICE_STATS_INC(service, ctrl_tx_count);
  23783. + VCHIQ_SERVICE_STATS_ADD(service, ctrl_tx_bytes, size);
  23784. + } else {
  23785. + vchiq_log_info(vchiq_core_log_level,
  23786. + "%d: qm %s@%x,%x (%d->%d)", state->id,
  23787. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  23788. + (unsigned int)header, size,
  23789. + VCHIQ_MSG_SRCPORT(msgid),
  23790. + VCHIQ_MSG_DSTPORT(msgid));
  23791. + if (size != 0) {
  23792. + WARN_ON(!((count == 1) && (size == elements[0].size)));
  23793. + memcpy(header->data, elements[0].data,
  23794. + elements[0].size);
  23795. + }
  23796. + VCHIQ_STATS_INC(state, ctrl_tx_count);
  23797. + }
  23798. +
  23799. + header->msgid = msgid;
  23800. + header->size = size;
  23801. +
  23802. + {
  23803. + int svc_fourcc;
  23804. +
  23805. + svc_fourcc = service
  23806. + ? service->base.fourcc
  23807. + : VCHIQ_MAKE_FOURCC('?', '?', '?', '?');
  23808. +
  23809. + vchiq_log_info(vchiq_core_msg_log_level,
  23810. + "Sent Msg %s(%u) to %c%c%c%c s:%u d:%d len:%d",
  23811. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  23812. + VCHIQ_MSG_TYPE(msgid),
  23813. + VCHIQ_FOURCC_AS_4CHARS(svc_fourcc),
  23814. + VCHIQ_MSG_SRCPORT(msgid),
  23815. + VCHIQ_MSG_DSTPORT(msgid),
  23816. + size);
  23817. + }
  23818. +
  23819. + /* Make sure the new header is visible to the peer. */
  23820. + wmb();
  23821. +
  23822. + /* Make the new tx_pos visible to the peer. */
  23823. + local->tx_pos = state->local_tx_pos;
  23824. + wmb();
  23825. +
  23826. + if (service && (type == VCHIQ_MSG_CLOSE))
  23827. + vchiq_set_service_state(service, VCHIQ_SRVSTATE_CLOSESENT);
  23828. +
  23829. + if (VCHIQ_MSG_TYPE(msgid) != VCHIQ_MSG_PAUSE)
  23830. + mutex_unlock(&state->slot_mutex);
  23831. +
  23832. + remote_event_signal(&state->remote->trigger);
  23833. +
  23834. + return VCHIQ_SUCCESS;
  23835. +}
  23836. +
  23837. +/* Called by the slot handler and application threads */
  23838. +static VCHIQ_STATUS_T
  23839. +queue_message_sync(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
  23840. + int msgid, const VCHIQ_ELEMENT_T *elements,
  23841. + int count, int size, int is_blocking)
  23842. +{
  23843. + VCHIQ_SHARED_STATE_T *local;
  23844. + VCHIQ_HEADER_T *header;
  23845. +
  23846. + local = state->local;
  23847. +
  23848. + if ((VCHIQ_MSG_TYPE(msgid) != VCHIQ_MSG_RESUME) &&
  23849. + (mutex_lock_interruptible(&state->sync_mutex) != 0))
  23850. + return VCHIQ_RETRY;
  23851. +
  23852. + remote_event_wait(&local->sync_release);
  23853. +
  23854. + rmb();
  23855. +
  23856. + header = (VCHIQ_HEADER_T *)SLOT_DATA_FROM_INDEX(state,
  23857. + local->slot_sync);
  23858. +
  23859. + {
  23860. + int oldmsgid = header->msgid;
  23861. + if (oldmsgid != VCHIQ_MSGID_PADDING)
  23862. + vchiq_log_error(vchiq_core_log_level,
  23863. + "%d: qms - msgid %x, not PADDING",
  23864. + state->id, oldmsgid);
  23865. + }
  23866. +
  23867. + if (service) {
  23868. + int i, pos;
  23869. +
  23870. + vchiq_log_info(vchiq_sync_log_level,
  23871. + "%d: qms %s@%x,%x (%d->%d)", state->id,
  23872. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  23873. + (unsigned int)header, size,
  23874. + VCHIQ_MSG_SRCPORT(msgid),
  23875. + VCHIQ_MSG_DSTPORT(msgid));
  23876. +
  23877. + for (i = 0, pos = 0; i < (unsigned int)count;
  23878. + pos += elements[i++].size)
  23879. + if (elements[i].size) {
  23880. + if (vchiq_copy_from_user
  23881. + (header->data + pos, elements[i].data,
  23882. + (size_t) elements[i].size) !=
  23883. + VCHIQ_SUCCESS) {
  23884. + mutex_unlock(&state->sync_mutex);
  23885. + VCHIQ_SERVICE_STATS_INC(service,
  23886. + error_count);
  23887. + return VCHIQ_ERROR;
  23888. + }
  23889. + if (i == 0) {
  23890. + if (vchiq_sync_log_level >=
  23891. + VCHIQ_LOG_TRACE)
  23892. + vchiq_log_dump_mem("Sent Sync",
  23893. + 0, header->data + pos,
  23894. + min(64u,
  23895. + elements[0].size));
  23896. + }
  23897. + }
  23898. +
  23899. + VCHIQ_SERVICE_STATS_INC(service, ctrl_tx_count);
  23900. + VCHIQ_SERVICE_STATS_ADD(service, ctrl_tx_bytes, size);
  23901. + } else {
  23902. + vchiq_log_info(vchiq_sync_log_level,
  23903. + "%d: qms %s@%x,%x (%d->%d)", state->id,
  23904. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  23905. + (unsigned int)header, size,
  23906. + VCHIQ_MSG_SRCPORT(msgid),
  23907. + VCHIQ_MSG_DSTPORT(msgid));
  23908. + if (size != 0) {
  23909. + WARN_ON(!((count == 1) && (size == elements[0].size)));
  23910. + memcpy(header->data, elements[0].data,
  23911. + elements[0].size);
  23912. + }
  23913. + VCHIQ_STATS_INC(state, ctrl_tx_count);
  23914. + }
  23915. +
  23916. + header->size = size;
  23917. + header->msgid = msgid;
  23918. +
  23919. + if (vchiq_sync_log_level >= VCHIQ_LOG_TRACE) {
  23920. + int svc_fourcc;
  23921. +
  23922. + svc_fourcc = service
  23923. + ? service->base.fourcc
  23924. + : VCHIQ_MAKE_FOURCC('?', '?', '?', '?');
  23925. +
  23926. + vchiq_log_trace(vchiq_sync_log_level,
  23927. + "Sent Sync Msg %s(%u) to %c%c%c%c s:%u d:%d len:%d",
  23928. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  23929. + VCHIQ_MSG_TYPE(msgid),
  23930. + VCHIQ_FOURCC_AS_4CHARS(svc_fourcc),
  23931. + VCHIQ_MSG_SRCPORT(msgid),
  23932. + VCHIQ_MSG_DSTPORT(msgid),
  23933. + size);
  23934. + }
  23935. +
  23936. + /* Make sure the new header is visible to the peer. */
  23937. + wmb();
  23938. +
  23939. + remote_event_signal(&state->remote->sync_trigger);
  23940. +
  23941. + if (VCHIQ_MSG_TYPE(msgid) != VCHIQ_MSG_PAUSE)
  23942. + mutex_unlock(&state->sync_mutex);
  23943. +
  23944. + return VCHIQ_SUCCESS;
  23945. +}
  23946. +
  23947. +static inline void
  23948. +claim_slot(VCHIQ_SLOT_INFO_T *slot)
  23949. +{
  23950. + slot->use_count++;
  23951. +}
  23952. +
  23953. +static void
  23954. +release_slot(VCHIQ_STATE_T *state, VCHIQ_SLOT_INFO_T *slot_info,
  23955. + VCHIQ_HEADER_T *header, VCHIQ_SERVICE_T *service)
  23956. +{
  23957. + int release_count;
  23958. +
  23959. + mutex_lock(&state->recycle_mutex);
  23960. +
  23961. + if (header) {
  23962. + int msgid = header->msgid;
  23963. + if (((msgid & VCHIQ_MSGID_CLAIMED) == 0) ||
  23964. + (service && service->closing)) {
  23965. + mutex_unlock(&state->recycle_mutex);
  23966. + return;
  23967. + }
  23968. +
  23969. + /* Rewrite the message header to prevent a double
  23970. + ** release */
  23971. + header->msgid = msgid & ~VCHIQ_MSGID_CLAIMED;
  23972. + }
  23973. +
  23974. + release_count = slot_info->release_count;
  23975. + slot_info->release_count = ++release_count;
  23976. +
  23977. + if (release_count == slot_info->use_count) {
  23978. + int slot_queue_recycle;
  23979. + /* Add to the freed queue */
  23980. +
  23981. + /* A read barrier is necessary here to prevent speculative
  23982. + ** fetches of remote->slot_queue_recycle from overtaking the
  23983. + ** mutex. */
  23984. + rmb();
  23985. +
  23986. + slot_queue_recycle = state->remote->slot_queue_recycle;
  23987. + state->remote->slot_queue[slot_queue_recycle &
  23988. + VCHIQ_SLOT_QUEUE_MASK] =
  23989. + SLOT_INDEX_FROM_INFO(state, slot_info);
  23990. + state->remote->slot_queue_recycle = slot_queue_recycle + 1;
  23991. + vchiq_log_info(vchiq_core_log_level,
  23992. + "%d: release_slot %d - recycle->%x",
  23993. + state->id, SLOT_INDEX_FROM_INFO(state, slot_info),
  23994. + state->remote->slot_queue_recycle);
  23995. +
  23996. + /* A write barrier is necessary, but remote_event_signal
  23997. + ** contains one. */
  23998. + remote_event_signal(&state->remote->recycle);
  23999. + }
  24000. +
  24001. + mutex_unlock(&state->recycle_mutex);
  24002. +}
  24003. +
  24004. +/* Called by the slot handler - don't hold the bulk mutex */
  24005. +static VCHIQ_STATUS_T
  24006. +notify_bulks(VCHIQ_SERVICE_T *service, VCHIQ_BULK_QUEUE_T *queue,
  24007. + int retry_poll)
  24008. +{
  24009. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  24010. +
  24011. + vchiq_log_trace(vchiq_core_log_level,
  24012. + "%d: nb:%d %cx - p=%x rn=%x r=%x",
  24013. + service->state->id, service->localport,
  24014. + (queue == &service->bulk_tx) ? 't' : 'r',
  24015. + queue->process, queue->remote_notify, queue->remove);
  24016. +
  24017. + if (service->state->is_master) {
  24018. + while (queue->remote_notify != queue->process) {
  24019. + VCHIQ_BULK_T *bulk =
  24020. + &queue->bulks[BULK_INDEX(queue->remote_notify)];
  24021. + int msgtype = (bulk->dir == VCHIQ_BULK_TRANSMIT) ?
  24022. + VCHIQ_MSG_BULK_RX_DONE : VCHIQ_MSG_BULK_TX_DONE;
  24023. + int msgid = VCHIQ_MAKE_MSG(msgtype, service->localport,
  24024. + service->remoteport);
  24025. + VCHIQ_ELEMENT_T element = { &bulk->actual, 4 };
  24026. + /* Only reply to non-dummy bulk requests */
  24027. + if (bulk->remote_data) {
  24028. + status = queue_message(service->state, NULL,
  24029. + msgid, &element, 1, 4, 0);
  24030. + if (status != VCHIQ_SUCCESS)
  24031. + break;
  24032. + }
  24033. + queue->remote_notify++;
  24034. + }
  24035. + } else {
  24036. + queue->remote_notify = queue->process;
  24037. + }
  24038. +
  24039. + if (status == VCHIQ_SUCCESS) {
  24040. + while (queue->remove != queue->remote_notify) {
  24041. + VCHIQ_BULK_T *bulk =
  24042. + &queue->bulks[BULK_INDEX(queue->remove)];
  24043. +
  24044. + /* Only generate callbacks for non-dummy bulk
  24045. + ** requests, and non-terminated services */
  24046. + if (bulk->data && service->instance) {
  24047. + if (bulk->actual != VCHIQ_BULK_ACTUAL_ABORTED) {
  24048. + if (bulk->dir == VCHIQ_BULK_TRANSMIT) {
  24049. + VCHIQ_SERVICE_STATS_INC(service,
  24050. + bulk_tx_count);
  24051. + VCHIQ_SERVICE_STATS_ADD(service,
  24052. + bulk_tx_bytes,
  24053. + bulk->actual);
  24054. + } else {
  24055. + VCHIQ_SERVICE_STATS_INC(service,
  24056. + bulk_rx_count);
  24057. + VCHIQ_SERVICE_STATS_ADD(service,
  24058. + bulk_rx_bytes,
  24059. + bulk->actual);
  24060. + }
  24061. + } else {
  24062. + VCHIQ_SERVICE_STATS_INC(service,
  24063. + bulk_aborted_count);
  24064. + }
  24065. + if (bulk->mode == VCHIQ_BULK_MODE_BLOCKING) {
  24066. + struct bulk_waiter *waiter;
  24067. + spin_lock(&bulk_waiter_spinlock);
  24068. + waiter = bulk->userdata;
  24069. + if (waiter) {
  24070. + waiter->actual = bulk->actual;
  24071. + up(&waiter->event);
  24072. + }
  24073. + spin_unlock(&bulk_waiter_spinlock);
  24074. + } else if (bulk->mode ==
  24075. + VCHIQ_BULK_MODE_CALLBACK) {
  24076. + VCHIQ_REASON_T reason = (bulk->dir ==
  24077. + VCHIQ_BULK_TRANSMIT) ?
  24078. + ((bulk->actual ==
  24079. + VCHIQ_BULK_ACTUAL_ABORTED) ?
  24080. + VCHIQ_BULK_TRANSMIT_ABORTED :
  24081. + VCHIQ_BULK_TRANSMIT_DONE) :
  24082. + ((bulk->actual ==
  24083. + VCHIQ_BULK_ACTUAL_ABORTED) ?
  24084. + VCHIQ_BULK_RECEIVE_ABORTED :
  24085. + VCHIQ_BULK_RECEIVE_DONE);
  24086. + status = make_service_callback(service,
  24087. + reason, NULL, bulk->userdata);
  24088. + if (status == VCHIQ_RETRY)
  24089. + break;
  24090. + }
  24091. + }
  24092. +
  24093. + queue->remove++;
  24094. + up(&service->bulk_remove_event);
  24095. + }
  24096. + if (!retry_poll)
  24097. + status = VCHIQ_SUCCESS;
  24098. + }
  24099. +
  24100. + if (status == VCHIQ_RETRY)
  24101. + request_poll(service->state, service,
  24102. + (queue == &service->bulk_tx) ?
  24103. + VCHIQ_POLL_TXNOTIFY : VCHIQ_POLL_RXNOTIFY);
  24104. +
  24105. + return status;
  24106. +}
  24107. +
  24108. +/* Called by the slot handler thread */
  24109. +static void
  24110. +poll_services(VCHIQ_STATE_T *state)
  24111. +{
  24112. + int group, i;
  24113. +
  24114. + for (group = 0; group < BITSET_SIZE(state->unused_service); group++) {
  24115. + uint32_t flags;
  24116. + flags = atomic_xchg(&state->poll_services[group], 0);
  24117. + for (i = 0; flags; i++) {
  24118. + if (flags & (1 << i)) {
  24119. + VCHIQ_SERVICE_T *service =
  24120. + find_service_by_port(state,
  24121. + (group<<5) + i);
  24122. + uint32_t service_flags;
  24123. + flags &= ~(1 << i);
  24124. + if (!service)
  24125. + continue;
  24126. + service_flags =
  24127. + atomic_xchg(&service->poll_flags, 0);
  24128. + if (service_flags &
  24129. + (1 << VCHIQ_POLL_REMOVE)) {
  24130. + vchiq_log_info(vchiq_core_log_level,
  24131. + "%d: ps - remove %d<->%d",
  24132. + state->id, service->localport,
  24133. + service->remoteport);
  24134. +
  24135. + /* Make it look like a client, because
  24136. + it must be removed and not left in
  24137. + the LISTENING state. */
  24138. + service->public_fourcc =
  24139. + VCHIQ_FOURCC_INVALID;
  24140. +
  24141. + if (vchiq_close_service_internal(
  24142. + service, 0/*!close_recvd*/) !=
  24143. + VCHIQ_SUCCESS)
  24144. + request_poll(state, service,
  24145. + VCHIQ_POLL_REMOVE);
  24146. + } else if (service_flags &
  24147. + (1 << VCHIQ_POLL_TERMINATE)) {
  24148. + vchiq_log_info(vchiq_core_log_level,
  24149. + "%d: ps - terminate %d<->%d",
  24150. + state->id, service->localport,
  24151. + service->remoteport);
  24152. + if (vchiq_close_service_internal(
  24153. + service, 0/*!close_recvd*/) !=
  24154. + VCHIQ_SUCCESS)
  24155. + request_poll(state, service,
  24156. + VCHIQ_POLL_TERMINATE);
  24157. + }
  24158. + if (service_flags & (1 << VCHIQ_POLL_TXNOTIFY))
  24159. + notify_bulks(service,
  24160. + &service->bulk_tx,
  24161. + 1/*retry_poll*/);
  24162. + if (service_flags & (1 << VCHIQ_POLL_RXNOTIFY))
  24163. + notify_bulks(service,
  24164. + &service->bulk_rx,
  24165. + 1/*retry_poll*/);
  24166. + unlock_service(service);
  24167. + }
  24168. + }
  24169. + }
  24170. +}
  24171. +
  24172. +/* Called by the slot handler or application threads, holding the bulk mutex. */
  24173. +static int
  24174. +resolve_bulks(VCHIQ_SERVICE_T *service, VCHIQ_BULK_QUEUE_T *queue)
  24175. +{
  24176. + VCHIQ_STATE_T *state = service->state;
  24177. + int resolved = 0;
  24178. + int rc;
  24179. +
  24180. + while ((queue->process != queue->local_insert) &&
  24181. + (queue->process != queue->remote_insert)) {
  24182. + VCHIQ_BULK_T *bulk = &queue->bulks[BULK_INDEX(queue->process)];
  24183. +
  24184. + vchiq_log_trace(vchiq_core_log_level,
  24185. + "%d: rb:%d %cx - li=%x ri=%x p=%x",
  24186. + state->id, service->localport,
  24187. + (queue == &service->bulk_tx) ? 't' : 'r',
  24188. + queue->local_insert, queue->remote_insert,
  24189. + queue->process);
  24190. +
  24191. + WARN_ON(!((int)(queue->local_insert - queue->process) > 0));
  24192. + WARN_ON(!((int)(queue->remote_insert - queue->process) > 0));
  24193. +
  24194. + rc = mutex_lock_interruptible(&state->bulk_transfer_mutex);
  24195. + if (rc != 0)
  24196. + break;
  24197. +
  24198. + vchiq_transfer_bulk(bulk);
  24199. + mutex_unlock(&state->bulk_transfer_mutex);
  24200. +
  24201. + if (vchiq_core_msg_log_level >= VCHIQ_LOG_INFO) {
  24202. + const char *header = (queue == &service->bulk_tx) ?
  24203. + "Send Bulk to" : "Recv Bulk from";
  24204. + if (bulk->actual != VCHIQ_BULK_ACTUAL_ABORTED)
  24205. + vchiq_log_info(vchiq_core_msg_log_level,
  24206. + "%s %c%c%c%c d:%d len:%d %x<->%x",
  24207. + header,
  24208. + VCHIQ_FOURCC_AS_4CHARS(
  24209. + service->base.fourcc),
  24210. + service->remoteport,
  24211. + bulk->size,
  24212. + (unsigned int)bulk->data,
  24213. + (unsigned int)bulk->remote_data);
  24214. + else
  24215. + vchiq_log_info(vchiq_core_msg_log_level,
  24216. + "%s %c%c%c%c d:%d ABORTED - tx len:%d,"
  24217. + " rx len:%d %x<->%x",
  24218. + header,
  24219. + VCHIQ_FOURCC_AS_4CHARS(
  24220. + service->base.fourcc),
  24221. + service->remoteport,
  24222. + bulk->size,
  24223. + bulk->remote_size,
  24224. + (unsigned int)bulk->data,
  24225. + (unsigned int)bulk->remote_data);
  24226. + }
  24227. +
  24228. + vchiq_complete_bulk(bulk);
  24229. + queue->process++;
  24230. + resolved++;
  24231. + }
  24232. + return resolved;
  24233. +}
  24234. +
  24235. +/* Called with the bulk_mutex held */
  24236. +static void
  24237. +abort_outstanding_bulks(VCHIQ_SERVICE_T *service, VCHIQ_BULK_QUEUE_T *queue)
  24238. +{
  24239. + int is_tx = (queue == &service->bulk_tx);
  24240. + vchiq_log_trace(vchiq_core_log_level,
  24241. + "%d: aob:%d %cx - li=%x ri=%x p=%x",
  24242. + service->state->id, service->localport, is_tx ? 't' : 'r',
  24243. + queue->local_insert, queue->remote_insert, queue->process);
  24244. +
  24245. + WARN_ON(!((int)(queue->local_insert - queue->process) >= 0));
  24246. + WARN_ON(!((int)(queue->remote_insert - queue->process) >= 0));
  24247. +
  24248. + while ((queue->process != queue->local_insert) ||
  24249. + (queue->process != queue->remote_insert)) {
  24250. + VCHIQ_BULK_T *bulk = &queue->bulks[BULK_INDEX(queue->process)];
  24251. +
  24252. + if (queue->process == queue->remote_insert) {
  24253. + /* fabricate a matching dummy bulk */
  24254. + bulk->remote_data = NULL;
  24255. + bulk->remote_size = 0;
  24256. + queue->remote_insert++;
  24257. + }
  24258. +
  24259. + if (queue->process != queue->local_insert) {
  24260. + vchiq_complete_bulk(bulk);
  24261. +
  24262. + vchiq_log_info(vchiq_core_msg_log_level,
  24263. + "%s %c%c%c%c d:%d ABORTED - tx len:%d, "
  24264. + "rx len:%d",
  24265. + is_tx ? "Send Bulk to" : "Recv Bulk from",
  24266. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  24267. + service->remoteport,
  24268. + bulk->size,
  24269. + bulk->remote_size);
  24270. + } else {
  24271. + /* fabricate a matching dummy bulk */
  24272. + bulk->data = NULL;
  24273. + bulk->size = 0;
  24274. + bulk->actual = VCHIQ_BULK_ACTUAL_ABORTED;
  24275. + bulk->dir = is_tx ? VCHIQ_BULK_TRANSMIT :
  24276. + VCHIQ_BULK_RECEIVE;
  24277. + queue->local_insert++;
  24278. + }
  24279. +
  24280. + queue->process++;
  24281. + }
  24282. +}
  24283. +
  24284. +/* Called from the slot handler thread */
  24285. +static void
  24286. +pause_bulks(VCHIQ_STATE_T *state)
  24287. +{
  24288. + if (unlikely(atomic_inc_return(&pause_bulks_count) != 1)) {
  24289. + WARN_ON_ONCE(1);
  24290. + atomic_set(&pause_bulks_count, 1);
  24291. + return;
  24292. + }
  24293. +
  24294. + /* Block bulk transfers from all services */
  24295. + mutex_lock(&state->bulk_transfer_mutex);
  24296. +}
  24297. +
  24298. +/* Called from the slot handler thread */
  24299. +static void
  24300. +resume_bulks(VCHIQ_STATE_T *state)
  24301. +{
  24302. + int i;
  24303. + if (unlikely(atomic_dec_return(&pause_bulks_count) != 0)) {
  24304. + WARN_ON_ONCE(1);
  24305. + atomic_set(&pause_bulks_count, 0);
  24306. + return;
  24307. + }
  24308. +
  24309. + /* Allow bulk transfers from all services */
  24310. + mutex_unlock(&state->bulk_transfer_mutex);
  24311. +
  24312. + if (state->deferred_bulks == 0)
  24313. + return;
  24314. +
  24315. + /* Deal with any bulks which had to be deferred due to being in
  24316. + * paused state. Don't try to match up to number of deferred bulks
  24317. + * in case we've had something come and close the service in the
  24318. + * interim - just process all bulk queues for all services */
  24319. + vchiq_log_info(vchiq_core_log_level, "%s: processing %d deferred bulks",
  24320. + __func__, state->deferred_bulks);
  24321. +
  24322. + for (i = 0; i < state->unused_service; i++) {
  24323. + VCHIQ_SERVICE_T *service = state->services[i];
  24324. + int resolved_rx = 0;
  24325. + int resolved_tx = 0;
  24326. + if (!service || (service->srvstate != VCHIQ_SRVSTATE_OPEN))
  24327. + continue;
  24328. +
  24329. + mutex_lock(&service->bulk_mutex);
  24330. + resolved_rx = resolve_bulks(service, &service->bulk_rx);
  24331. + resolved_tx = resolve_bulks(service, &service->bulk_tx);
  24332. + mutex_unlock(&service->bulk_mutex);
  24333. + if (resolved_rx)
  24334. + notify_bulks(service, &service->bulk_rx, 1);
  24335. + if (resolved_tx)
  24336. + notify_bulks(service, &service->bulk_tx, 1);
  24337. + }
  24338. + state->deferred_bulks = 0;
  24339. +}
  24340. +
  24341. +static int
  24342. +parse_open(VCHIQ_STATE_T *state, VCHIQ_HEADER_T *header)
  24343. +{
  24344. + VCHIQ_SERVICE_T *service = NULL;
  24345. + int msgid, size;
  24346. + int type;
  24347. + unsigned int localport, remoteport;
  24348. +
  24349. + msgid = header->msgid;
  24350. + size = header->size;
  24351. + type = VCHIQ_MSG_TYPE(msgid);
  24352. + localport = VCHIQ_MSG_DSTPORT(msgid);
  24353. + remoteport = VCHIQ_MSG_SRCPORT(msgid);
  24354. + if (size >= sizeof(struct vchiq_open_payload)) {
  24355. + const struct vchiq_open_payload *payload =
  24356. + (struct vchiq_open_payload *)header->data;
  24357. + unsigned int fourcc;
  24358. +
  24359. + fourcc = payload->fourcc;
  24360. + vchiq_log_info(vchiq_core_log_level,
  24361. + "%d: prs OPEN@%x (%d->'%c%c%c%c')",
  24362. + state->id, (unsigned int)header,
  24363. + localport,
  24364. + VCHIQ_FOURCC_AS_4CHARS(fourcc));
  24365. +
  24366. + service = get_listening_service(state, fourcc);
  24367. +
  24368. + if (service) {
  24369. + /* A matching service exists */
  24370. + short version = payload->version;
  24371. + short version_min = payload->version_min;
  24372. + if ((service->version < version_min) ||
  24373. + (version < service->version_min)) {
  24374. + /* Version mismatch */
  24375. + vchiq_loud_error_header();
  24376. + vchiq_loud_error("%d: service %d (%c%c%c%c) "
  24377. + "version mismatch - local (%d, min %d)"
  24378. + " vs. remote (%d, min %d)",
  24379. + state->id, service->localport,
  24380. + VCHIQ_FOURCC_AS_4CHARS(fourcc),
  24381. + service->version, service->version_min,
  24382. + version, version_min);
  24383. + vchiq_loud_error_footer();
  24384. + unlock_service(service);
  24385. + service = NULL;
  24386. + goto fail_open;
  24387. + }
  24388. + service->peer_version = version;
  24389. +
  24390. + if (service->srvstate == VCHIQ_SRVSTATE_LISTENING) {
  24391. + struct vchiq_openack_payload ack_payload = {
  24392. + service->version
  24393. + };
  24394. + VCHIQ_ELEMENT_T body = {
  24395. + &ack_payload,
  24396. + sizeof(ack_payload)
  24397. + };
  24398. +
  24399. + /* Acknowledge the OPEN */
  24400. + if (service->sync) {
  24401. + if (queue_message_sync(state, NULL,
  24402. + VCHIQ_MAKE_MSG(
  24403. + VCHIQ_MSG_OPENACK,
  24404. + service->localport,
  24405. + remoteport),
  24406. + &body, 1, sizeof(ack_payload),
  24407. + 0) == VCHIQ_RETRY)
  24408. + goto bail_not_ready;
  24409. + } else {
  24410. + if (queue_message(state, NULL,
  24411. + VCHIQ_MAKE_MSG(
  24412. + VCHIQ_MSG_OPENACK,
  24413. + service->localport,
  24414. + remoteport),
  24415. + &body, 1, sizeof(ack_payload),
  24416. + 0) == VCHIQ_RETRY)
  24417. + goto bail_not_ready;
  24418. + }
  24419. +
  24420. + /* The service is now open */
  24421. + vchiq_set_service_state(service,
  24422. + service->sync ? VCHIQ_SRVSTATE_OPENSYNC
  24423. + : VCHIQ_SRVSTATE_OPEN);
  24424. + }
  24425. +
  24426. + service->remoteport = remoteport;
  24427. + service->client_id = ((int *)header->data)[1];
  24428. + if (make_service_callback(service, VCHIQ_SERVICE_OPENED,
  24429. + NULL, NULL) == VCHIQ_RETRY) {
  24430. + /* Bail out if not ready */
  24431. + service->remoteport = VCHIQ_PORT_FREE;
  24432. + goto bail_not_ready;
  24433. + }
  24434. +
  24435. + /* Success - the message has been dealt with */
  24436. + unlock_service(service);
  24437. + return 1;
  24438. + }
  24439. + }
  24440. +
  24441. +fail_open:
  24442. + /* No available service, or an invalid request - send a CLOSE */
  24443. + if (queue_message(state, NULL,
  24444. + VCHIQ_MAKE_MSG(VCHIQ_MSG_CLOSE, 0, VCHIQ_MSG_SRCPORT(msgid)),
  24445. + NULL, 0, 0, 0) == VCHIQ_RETRY)
  24446. + goto bail_not_ready;
  24447. +
  24448. + return 1;
  24449. +
  24450. +bail_not_ready:
  24451. + if (service)
  24452. + unlock_service(service);
  24453. +
  24454. + return 0;
  24455. +}
  24456. +
  24457. +/* Called by the slot handler thread */
  24458. +static void
  24459. +parse_rx_slots(VCHIQ_STATE_T *state)
  24460. +{
  24461. + VCHIQ_SHARED_STATE_T *remote = state->remote;
  24462. + VCHIQ_SERVICE_T *service = NULL;
  24463. + int tx_pos;
  24464. + DEBUG_INITIALISE(state->local)
  24465. +
  24466. + tx_pos = remote->tx_pos;
  24467. +
  24468. + while (state->rx_pos != tx_pos) {
  24469. + VCHIQ_HEADER_T *header;
  24470. + int msgid, size;
  24471. + int type;
  24472. + unsigned int localport, remoteport;
  24473. +
  24474. + DEBUG_TRACE(PARSE_LINE);
  24475. + if (!state->rx_data) {
  24476. + int rx_index;
  24477. + WARN_ON(!((state->rx_pos & VCHIQ_SLOT_MASK) == 0));
  24478. + rx_index = remote->slot_queue[
  24479. + SLOT_QUEUE_INDEX_FROM_POS(state->rx_pos) &
  24480. + VCHIQ_SLOT_QUEUE_MASK];
  24481. + state->rx_data = (char *)SLOT_DATA_FROM_INDEX(state,
  24482. + rx_index);
  24483. + state->rx_info = SLOT_INFO_FROM_INDEX(state, rx_index);
  24484. +
  24485. + /* Initialise use_count to one, and increment
  24486. + ** release_count at the end of the slot to avoid
  24487. + ** releasing the slot prematurely. */
  24488. + state->rx_info->use_count = 1;
  24489. + state->rx_info->release_count = 0;
  24490. + }
  24491. +
  24492. + header = (VCHIQ_HEADER_T *)(state->rx_data +
  24493. + (state->rx_pos & VCHIQ_SLOT_MASK));
  24494. + DEBUG_VALUE(PARSE_HEADER, (int)header);
  24495. + msgid = header->msgid;
  24496. + DEBUG_VALUE(PARSE_MSGID, msgid);
  24497. + size = header->size;
  24498. + type = VCHIQ_MSG_TYPE(msgid);
  24499. + localport = VCHIQ_MSG_DSTPORT(msgid);
  24500. + remoteport = VCHIQ_MSG_SRCPORT(msgid);
  24501. +
  24502. + if (type != VCHIQ_MSG_DATA)
  24503. + VCHIQ_STATS_INC(state, ctrl_rx_count);
  24504. +
  24505. + switch (type) {
  24506. + case VCHIQ_MSG_OPENACK:
  24507. + case VCHIQ_MSG_CLOSE:
  24508. + case VCHIQ_MSG_DATA:
  24509. + case VCHIQ_MSG_BULK_RX:
  24510. + case VCHIQ_MSG_BULK_TX:
  24511. + case VCHIQ_MSG_BULK_RX_DONE:
  24512. + case VCHIQ_MSG_BULK_TX_DONE:
  24513. + service = find_service_by_port(state, localport);
  24514. + if ((!service || service->remoteport != remoteport) &&
  24515. + (localport == 0) &&
  24516. + (type == VCHIQ_MSG_CLOSE)) {
  24517. + /* This could be a CLOSE from a client which
  24518. + hadn't yet received the OPENACK - look for
  24519. + the connected service */
  24520. + if (service)
  24521. + unlock_service(service);
  24522. + service = get_connected_service(state,
  24523. + remoteport);
  24524. + if (service)
  24525. + vchiq_log_warning(vchiq_core_log_level,
  24526. + "%d: prs %s@%x (%d->%d) - "
  24527. + "found connected service %d",
  24528. + state->id, msg_type_str(type),
  24529. + (unsigned int)header,
  24530. + remoteport, localport,
  24531. + service->localport);
  24532. + }
  24533. +
  24534. + if (!service) {
  24535. + vchiq_log_error(vchiq_core_log_level,
  24536. + "%d: prs %s@%x (%d->%d) - "
  24537. + "invalid/closed service %d",
  24538. + state->id, msg_type_str(type),
  24539. + (unsigned int)header,
  24540. + remoteport, localport, localport);
  24541. + goto skip_message;
  24542. + }
  24543. + break;
  24544. + default:
  24545. + break;
  24546. + }
  24547. +
  24548. + if (vchiq_core_msg_log_level >= VCHIQ_LOG_INFO) {
  24549. + int svc_fourcc;
  24550. +
  24551. + svc_fourcc = service
  24552. + ? service->base.fourcc
  24553. + : VCHIQ_MAKE_FOURCC('?', '?', '?', '?');
  24554. + vchiq_log_info(vchiq_core_msg_log_level,
  24555. + "Rcvd Msg %s(%u) from %c%c%c%c s:%d d:%d "
  24556. + "len:%d",
  24557. + msg_type_str(type), type,
  24558. + VCHIQ_FOURCC_AS_4CHARS(svc_fourcc),
  24559. + remoteport, localport, size);
  24560. + if (size > 0)
  24561. + vchiq_log_dump_mem("Rcvd", 0, header->data,
  24562. + min(64, size));
  24563. + }
  24564. +
  24565. + if (((unsigned int)header & VCHIQ_SLOT_MASK) + calc_stride(size)
  24566. + > VCHIQ_SLOT_SIZE) {
  24567. + vchiq_log_error(vchiq_core_log_level,
  24568. + "header %x (msgid %x) - size %x too big for "
  24569. + "slot",
  24570. + (unsigned int)header, (unsigned int)msgid,
  24571. + (unsigned int)size);
  24572. + WARN(1, "oversized for slot\n");
  24573. + }
  24574. +
  24575. + switch (type) {
  24576. + case VCHIQ_MSG_OPEN:
  24577. + WARN_ON(!(VCHIQ_MSG_DSTPORT(msgid) == 0));
  24578. + if (!parse_open(state, header))
  24579. + goto bail_not_ready;
  24580. + break;
  24581. + case VCHIQ_MSG_OPENACK:
  24582. + if (size >= sizeof(struct vchiq_openack_payload)) {
  24583. + const struct vchiq_openack_payload *payload =
  24584. + (struct vchiq_openack_payload *)
  24585. + header->data;
  24586. + service->peer_version = payload->version;
  24587. + }
  24588. + vchiq_log_info(vchiq_core_log_level,
  24589. + "%d: prs OPENACK@%x,%x (%d->%d) v:%d",
  24590. + state->id, (unsigned int)header, size,
  24591. + remoteport, localport, service->peer_version);
  24592. + if (service->srvstate ==
  24593. + VCHIQ_SRVSTATE_OPENING) {
  24594. + service->remoteport = remoteport;
  24595. + vchiq_set_service_state(service,
  24596. + VCHIQ_SRVSTATE_OPEN);
  24597. + up(&service->remove_event);
  24598. + } else
  24599. + vchiq_log_error(vchiq_core_log_level,
  24600. + "OPENACK received in state %s",
  24601. + srvstate_names[service->srvstate]);
  24602. + break;
  24603. + case VCHIQ_MSG_CLOSE:
  24604. + WARN_ON(size != 0); /* There should be no data */
  24605. +
  24606. + vchiq_log_info(vchiq_core_log_level,
  24607. + "%d: prs CLOSE@%x (%d->%d)",
  24608. + state->id, (unsigned int)header,
  24609. + remoteport, localport);
  24610. +
  24611. + mark_service_closing_internal(service, 1);
  24612. +
  24613. + if (vchiq_close_service_internal(service,
  24614. + 1/*close_recvd*/) == VCHIQ_RETRY)
  24615. + goto bail_not_ready;
  24616. +
  24617. + vchiq_log_info(vchiq_core_log_level,
  24618. + "Close Service %c%c%c%c s:%u d:%d",
  24619. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  24620. + service->localport,
  24621. + service->remoteport);
  24622. + break;
  24623. + case VCHIQ_MSG_DATA:
  24624. + vchiq_log_trace(vchiq_core_log_level,
  24625. + "%d: prs DATA@%x,%x (%d->%d)",
  24626. + state->id, (unsigned int)header, size,
  24627. + remoteport, localport);
  24628. +
  24629. + if ((service->remoteport == remoteport)
  24630. + && (service->srvstate ==
  24631. + VCHIQ_SRVSTATE_OPEN)) {
  24632. + header->msgid = msgid | VCHIQ_MSGID_CLAIMED;
  24633. + claim_slot(state->rx_info);
  24634. + DEBUG_TRACE(PARSE_LINE);
  24635. + if (make_service_callback(service,
  24636. + VCHIQ_MESSAGE_AVAILABLE, header,
  24637. + NULL) == VCHIQ_RETRY) {
  24638. + DEBUG_TRACE(PARSE_LINE);
  24639. + goto bail_not_ready;
  24640. + }
  24641. + VCHIQ_SERVICE_STATS_INC(service, ctrl_rx_count);
  24642. + VCHIQ_SERVICE_STATS_ADD(service, ctrl_rx_bytes,
  24643. + size);
  24644. + } else {
  24645. + VCHIQ_STATS_INC(state, error_count);
  24646. + }
  24647. + break;
  24648. + case VCHIQ_MSG_CONNECT:
  24649. + vchiq_log_info(vchiq_core_log_level,
  24650. + "%d: prs CONNECT@%x",
  24651. + state->id, (unsigned int)header);
  24652. + up(&state->connect);
  24653. + break;
  24654. + case VCHIQ_MSG_BULK_RX:
  24655. + case VCHIQ_MSG_BULK_TX: {
  24656. + VCHIQ_BULK_QUEUE_T *queue;
  24657. + WARN_ON(!state->is_master);
  24658. + queue = (type == VCHIQ_MSG_BULK_RX) ?
  24659. + &service->bulk_tx : &service->bulk_rx;
  24660. + if ((service->remoteport == remoteport)
  24661. + && (service->srvstate ==
  24662. + VCHIQ_SRVSTATE_OPEN)) {
  24663. + VCHIQ_BULK_T *bulk;
  24664. + int resolved = 0;
  24665. +
  24666. + DEBUG_TRACE(PARSE_LINE);
  24667. + if (mutex_lock_interruptible(
  24668. + &service->bulk_mutex) != 0) {
  24669. + DEBUG_TRACE(PARSE_LINE);
  24670. + goto bail_not_ready;
  24671. + }
  24672. +
  24673. + WARN_ON(!(queue->remote_insert < queue->remove +
  24674. + VCHIQ_NUM_SERVICE_BULKS));
  24675. + bulk = &queue->bulks[
  24676. + BULK_INDEX(queue->remote_insert)];
  24677. + bulk->remote_data =
  24678. + (void *)((int *)header->data)[0];
  24679. + bulk->remote_size = ((int *)header->data)[1];
  24680. + wmb();
  24681. +
  24682. + vchiq_log_info(vchiq_core_log_level,
  24683. + "%d: prs %s@%x (%d->%d) %x@%x",
  24684. + state->id, msg_type_str(type),
  24685. + (unsigned int)header,
  24686. + remoteport, localport,
  24687. + bulk->remote_size,
  24688. + (unsigned int)bulk->remote_data);
  24689. +
  24690. + queue->remote_insert++;
  24691. +
  24692. + if (atomic_read(&pause_bulks_count)) {
  24693. + state->deferred_bulks++;
  24694. + vchiq_log_info(vchiq_core_log_level,
  24695. + "%s: deferring bulk (%d)",
  24696. + __func__,
  24697. + state->deferred_bulks);
  24698. + if (state->conn_state !=
  24699. + VCHIQ_CONNSTATE_PAUSE_SENT)
  24700. + vchiq_log_error(
  24701. + vchiq_core_log_level,
  24702. + "%s: bulks paused in "
  24703. + "unexpected state %s",
  24704. + __func__,
  24705. + conn_state_names[
  24706. + state->conn_state]);
  24707. + } else if (state->conn_state ==
  24708. + VCHIQ_CONNSTATE_CONNECTED) {
  24709. + DEBUG_TRACE(PARSE_LINE);
  24710. + resolved = resolve_bulks(service,
  24711. + queue);
  24712. + }
  24713. +
  24714. + mutex_unlock(&service->bulk_mutex);
  24715. + if (resolved)
  24716. + notify_bulks(service, queue,
  24717. + 1/*retry_poll*/);
  24718. + }
  24719. + } break;
  24720. + case VCHIQ_MSG_BULK_RX_DONE:
  24721. + case VCHIQ_MSG_BULK_TX_DONE:
  24722. + WARN_ON(state->is_master);
  24723. + if ((service->remoteport == remoteport)
  24724. + && (service->srvstate !=
  24725. + VCHIQ_SRVSTATE_FREE)) {
  24726. + VCHIQ_BULK_QUEUE_T *queue;
  24727. + VCHIQ_BULK_T *bulk;
  24728. +
  24729. + queue = (type == VCHIQ_MSG_BULK_RX_DONE) ?
  24730. + &service->bulk_rx : &service->bulk_tx;
  24731. +
  24732. + DEBUG_TRACE(PARSE_LINE);
  24733. + if (mutex_lock_interruptible(
  24734. + &service->bulk_mutex) != 0) {
  24735. + DEBUG_TRACE(PARSE_LINE);
  24736. + goto bail_not_ready;
  24737. + }
  24738. + if ((int)(queue->remote_insert -
  24739. + queue->local_insert) >= 0) {
  24740. + vchiq_log_error(vchiq_core_log_level,
  24741. + "%d: prs %s@%x (%d->%d) "
  24742. + "unexpected (ri=%d,li=%d)",
  24743. + state->id, msg_type_str(type),
  24744. + (unsigned int)header,
  24745. + remoteport, localport,
  24746. + queue->remote_insert,
  24747. + queue->local_insert);
  24748. + mutex_unlock(&service->bulk_mutex);
  24749. + break;
  24750. + }
  24751. +
  24752. + BUG_ON(queue->process == queue->local_insert);
  24753. + BUG_ON(queue->process != queue->remote_insert);
  24754. +
  24755. + bulk = &queue->bulks[
  24756. + BULK_INDEX(queue->remote_insert)];
  24757. + bulk->actual = *(int *)header->data;
  24758. + queue->remote_insert++;
  24759. +
  24760. + vchiq_log_info(vchiq_core_log_level,
  24761. + "%d: prs %s@%x (%d->%d) %x@%x",
  24762. + state->id, msg_type_str(type),
  24763. + (unsigned int)header,
  24764. + remoteport, localport,
  24765. + bulk->actual, (unsigned int)bulk->data);
  24766. +
  24767. + vchiq_log_trace(vchiq_core_log_level,
  24768. + "%d: prs:%d %cx li=%x ri=%x p=%x",
  24769. + state->id, localport,
  24770. + (type == VCHIQ_MSG_BULK_RX_DONE) ?
  24771. + 'r' : 't',
  24772. + queue->local_insert,
  24773. + queue->remote_insert, queue->process);
  24774. +
  24775. + DEBUG_TRACE(PARSE_LINE);
  24776. + WARN_ON(queue->process == queue->local_insert);
  24777. + vchiq_complete_bulk(bulk);
  24778. + queue->process++;
  24779. + mutex_unlock(&service->bulk_mutex);
  24780. + DEBUG_TRACE(PARSE_LINE);
  24781. + notify_bulks(service, queue, 1/*retry_poll*/);
  24782. + DEBUG_TRACE(PARSE_LINE);
  24783. + }
  24784. + break;
  24785. + case VCHIQ_MSG_PADDING:
  24786. + vchiq_log_trace(vchiq_core_log_level,
  24787. + "%d: prs PADDING@%x,%x",
  24788. + state->id, (unsigned int)header, size);
  24789. + break;
  24790. + case VCHIQ_MSG_PAUSE:
  24791. + /* If initiated, signal the application thread */
  24792. + vchiq_log_trace(vchiq_core_log_level,
  24793. + "%d: prs PAUSE@%x,%x",
  24794. + state->id, (unsigned int)header, size);
  24795. + if (state->conn_state == VCHIQ_CONNSTATE_PAUSED) {
  24796. + vchiq_log_error(vchiq_core_log_level,
  24797. + "%d: PAUSE received in state PAUSED",
  24798. + state->id);
  24799. + break;
  24800. + }
  24801. + if (state->conn_state != VCHIQ_CONNSTATE_PAUSE_SENT) {
  24802. + /* Send a PAUSE in response */
  24803. + if (queue_message(state, NULL,
  24804. + VCHIQ_MAKE_MSG(VCHIQ_MSG_PAUSE, 0, 0),
  24805. + NULL, 0, 0, 0) == VCHIQ_RETRY)
  24806. + goto bail_not_ready;
  24807. + if (state->is_master)
  24808. + pause_bulks(state);
  24809. + }
  24810. + /* At this point slot_mutex is held */
  24811. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_PAUSED);
  24812. + vchiq_platform_paused(state);
  24813. + break;
  24814. + case VCHIQ_MSG_RESUME:
  24815. + vchiq_log_trace(vchiq_core_log_level,
  24816. + "%d: prs RESUME@%x,%x",
  24817. + state->id, (unsigned int)header, size);
  24818. + /* Release the slot mutex */
  24819. + mutex_unlock(&state->slot_mutex);
  24820. + if (state->is_master)
  24821. + resume_bulks(state);
  24822. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_CONNECTED);
  24823. + vchiq_platform_resumed(state);
  24824. + break;
  24825. +
  24826. + case VCHIQ_MSG_REMOTE_USE:
  24827. + vchiq_on_remote_use(state);
  24828. + break;
  24829. + case VCHIQ_MSG_REMOTE_RELEASE:
  24830. + vchiq_on_remote_release(state);
  24831. + break;
  24832. + case VCHIQ_MSG_REMOTE_USE_ACTIVE:
  24833. + vchiq_on_remote_use_active(state);
  24834. + break;
  24835. +
  24836. + default:
  24837. + vchiq_log_error(vchiq_core_log_level,
  24838. + "%d: prs invalid msgid %x@%x,%x",
  24839. + state->id, msgid, (unsigned int)header, size);
  24840. + WARN(1, "invalid message\n");
  24841. + break;
  24842. + }
  24843. +
  24844. +skip_message:
  24845. + if (service) {
  24846. + unlock_service(service);
  24847. + service = NULL;
  24848. + }
  24849. +
  24850. + state->rx_pos += calc_stride(size);
  24851. +
  24852. + DEBUG_TRACE(PARSE_LINE);
  24853. + /* Perform some housekeeping when the end of the slot is
  24854. + ** reached. */
  24855. + if ((state->rx_pos & VCHIQ_SLOT_MASK) == 0) {
  24856. + /* Remove the extra reference count. */
  24857. + release_slot(state, state->rx_info, NULL, NULL);
  24858. + state->rx_data = NULL;
  24859. + }
  24860. + }
  24861. +
  24862. +bail_not_ready:
  24863. + if (service)
  24864. + unlock_service(service);
  24865. +}
  24866. +
  24867. +/* Called by the slot handler thread */
  24868. +static int
  24869. +slot_handler_func(void *v)
  24870. +{
  24871. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *) v;
  24872. + VCHIQ_SHARED_STATE_T *local = state->local;
  24873. + DEBUG_INITIALISE(local)
  24874. +
  24875. + while (1) {
  24876. + DEBUG_COUNT(SLOT_HANDLER_COUNT);
  24877. + DEBUG_TRACE(SLOT_HANDLER_LINE);
  24878. + remote_event_wait(&local->trigger);
  24879. +
  24880. + rmb();
  24881. +
  24882. + DEBUG_TRACE(SLOT_HANDLER_LINE);
  24883. + if (state->poll_needed) {
  24884. + /* Check if we need to suspend - may change our
  24885. + * conn_state */
  24886. + vchiq_platform_check_suspend(state);
  24887. +
  24888. + state->poll_needed = 0;
  24889. +
  24890. + /* Handle service polling and other rare conditions here
  24891. + ** out of the mainline code */
  24892. + switch (state->conn_state) {
  24893. + case VCHIQ_CONNSTATE_CONNECTED:
  24894. + /* Poll the services as requested */
  24895. + poll_services(state);
  24896. + break;
  24897. +
  24898. + case VCHIQ_CONNSTATE_PAUSING:
  24899. + if (state->is_master)
  24900. + pause_bulks(state);
  24901. + if (queue_message(state, NULL,
  24902. + VCHIQ_MAKE_MSG(VCHIQ_MSG_PAUSE, 0, 0),
  24903. + NULL, 0, 0, 0) != VCHIQ_RETRY) {
  24904. + vchiq_set_conn_state(state,
  24905. + VCHIQ_CONNSTATE_PAUSE_SENT);
  24906. + } else {
  24907. + if (state->is_master)
  24908. + resume_bulks(state);
  24909. + /* Retry later */
  24910. + state->poll_needed = 1;
  24911. + }
  24912. + break;
  24913. +
  24914. + case VCHIQ_CONNSTATE_PAUSED:
  24915. + vchiq_platform_resume(state);
  24916. + break;
  24917. +
  24918. + case VCHIQ_CONNSTATE_RESUMING:
  24919. + if (queue_message(state, NULL,
  24920. + VCHIQ_MAKE_MSG(VCHIQ_MSG_RESUME, 0, 0),
  24921. + NULL, 0, 0, 0) != VCHIQ_RETRY) {
  24922. + if (state->is_master)
  24923. + resume_bulks(state);
  24924. + vchiq_set_conn_state(state,
  24925. + VCHIQ_CONNSTATE_CONNECTED);
  24926. + vchiq_platform_resumed(state);
  24927. + } else {
  24928. + /* This should really be impossible,
  24929. + ** since the PAUSE should have flushed
  24930. + ** through outstanding messages. */
  24931. + vchiq_log_error(vchiq_core_log_level,
  24932. + "Failed to send RESUME "
  24933. + "message");
  24934. + BUG();
  24935. + }
  24936. + break;
  24937. +
  24938. + case VCHIQ_CONNSTATE_PAUSE_TIMEOUT:
  24939. + case VCHIQ_CONNSTATE_RESUME_TIMEOUT:
  24940. + vchiq_platform_handle_timeout(state);
  24941. + break;
  24942. + default:
  24943. + break;
  24944. + }
  24945. +
  24946. +
  24947. + }
  24948. +
  24949. + DEBUG_TRACE(SLOT_HANDLER_LINE);
  24950. + parse_rx_slots(state);
  24951. + }
  24952. + return 0;
  24953. +}
  24954. +
  24955. +
  24956. +/* Called by the recycle thread */
  24957. +static int
  24958. +recycle_func(void *v)
  24959. +{
  24960. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *) v;
  24961. + VCHIQ_SHARED_STATE_T *local = state->local;
  24962. +
  24963. + while (1) {
  24964. + remote_event_wait(&local->recycle);
  24965. +
  24966. + process_free_queue(state);
  24967. + }
  24968. + return 0;
  24969. +}
  24970. +
  24971. +
  24972. +/* Called by the sync thread */
  24973. +static int
  24974. +sync_func(void *v)
  24975. +{
  24976. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *) v;
  24977. + VCHIQ_SHARED_STATE_T *local = state->local;
  24978. + VCHIQ_HEADER_T *header = (VCHIQ_HEADER_T *)SLOT_DATA_FROM_INDEX(state,
  24979. + state->remote->slot_sync);
  24980. +
  24981. + while (1) {
  24982. + VCHIQ_SERVICE_T *service;
  24983. + int msgid, size;
  24984. + int type;
  24985. + unsigned int localport, remoteport;
  24986. +
  24987. + remote_event_wait(&local->sync_trigger);
  24988. +
  24989. + rmb();
  24990. +
  24991. + msgid = header->msgid;
  24992. + size = header->size;
  24993. + type = VCHIQ_MSG_TYPE(msgid);
  24994. + localport = VCHIQ_MSG_DSTPORT(msgid);
  24995. + remoteport = VCHIQ_MSG_SRCPORT(msgid);
  24996. +
  24997. + service = find_service_by_port(state, localport);
  24998. +
  24999. + if (!service) {
  25000. + vchiq_log_error(vchiq_sync_log_level,
  25001. + "%d: sf %s@%x (%d->%d) - "
  25002. + "invalid/closed service %d",
  25003. + state->id, msg_type_str(type),
  25004. + (unsigned int)header,
  25005. + remoteport, localport, localport);
  25006. + release_message_sync(state, header);
  25007. + continue;
  25008. + }
  25009. +
  25010. + if (vchiq_sync_log_level >= VCHIQ_LOG_TRACE) {
  25011. + int svc_fourcc;
  25012. +
  25013. + svc_fourcc = service
  25014. + ? service->base.fourcc
  25015. + : VCHIQ_MAKE_FOURCC('?', '?', '?', '?');
  25016. + vchiq_log_trace(vchiq_sync_log_level,
  25017. + "Rcvd Msg %s from %c%c%c%c s:%d d:%d len:%d",
  25018. + msg_type_str(type),
  25019. + VCHIQ_FOURCC_AS_4CHARS(svc_fourcc),
  25020. + remoteport, localport, size);
  25021. + if (size > 0)
  25022. + vchiq_log_dump_mem("Rcvd", 0, header->data,
  25023. + min(64, size));
  25024. + }
  25025. +
  25026. + switch (type) {
  25027. + case VCHIQ_MSG_OPENACK:
  25028. + if (size >= sizeof(struct vchiq_openack_payload)) {
  25029. + const struct vchiq_openack_payload *payload =
  25030. + (struct vchiq_openack_payload *)
  25031. + header->data;
  25032. + service->peer_version = payload->version;
  25033. + }
  25034. + vchiq_log_info(vchiq_sync_log_level,
  25035. + "%d: sf OPENACK@%x,%x (%d->%d) v:%d",
  25036. + state->id, (unsigned int)header, size,
  25037. + remoteport, localport, service->peer_version);
  25038. + if (service->srvstate == VCHIQ_SRVSTATE_OPENING) {
  25039. + service->remoteport = remoteport;
  25040. + vchiq_set_service_state(service,
  25041. + VCHIQ_SRVSTATE_OPENSYNC);
  25042. + up(&service->remove_event);
  25043. + }
  25044. + release_message_sync(state, header);
  25045. + break;
  25046. +
  25047. + case VCHIQ_MSG_DATA:
  25048. + vchiq_log_trace(vchiq_sync_log_level,
  25049. + "%d: sf DATA@%x,%x (%d->%d)",
  25050. + state->id, (unsigned int)header, size,
  25051. + remoteport, localport);
  25052. +
  25053. + if ((service->remoteport == remoteport) &&
  25054. + (service->srvstate ==
  25055. + VCHIQ_SRVSTATE_OPENSYNC)) {
  25056. + if (make_service_callback(service,
  25057. + VCHIQ_MESSAGE_AVAILABLE, header,
  25058. + NULL) == VCHIQ_RETRY)
  25059. + vchiq_log_error(vchiq_sync_log_level,
  25060. + "synchronous callback to "
  25061. + "service %d returns "
  25062. + "VCHIQ_RETRY",
  25063. + localport);
  25064. + }
  25065. + break;
  25066. +
  25067. + default:
  25068. + vchiq_log_error(vchiq_sync_log_level,
  25069. + "%d: sf unexpected msgid %x@%x,%x",
  25070. + state->id, msgid, (unsigned int)header, size);
  25071. + release_message_sync(state, header);
  25072. + break;
  25073. + }
  25074. +
  25075. + unlock_service(service);
  25076. + }
  25077. +
  25078. + return 0;
  25079. +}
  25080. +
  25081. +
  25082. +static void
  25083. +init_bulk_queue(VCHIQ_BULK_QUEUE_T *queue)
  25084. +{
  25085. + queue->local_insert = 0;
  25086. + queue->remote_insert = 0;
  25087. + queue->process = 0;
  25088. + queue->remote_notify = 0;
  25089. + queue->remove = 0;
  25090. +}
  25091. +
  25092. +
  25093. +inline const char *
  25094. +get_conn_state_name(VCHIQ_CONNSTATE_T conn_state)
  25095. +{
  25096. + return conn_state_names[conn_state];
  25097. +}
  25098. +
  25099. +
  25100. +VCHIQ_SLOT_ZERO_T *
  25101. +vchiq_init_slots(void *mem_base, int mem_size)
  25102. +{
  25103. + int mem_align = (VCHIQ_SLOT_SIZE - (int)mem_base) & VCHIQ_SLOT_MASK;
  25104. + VCHIQ_SLOT_ZERO_T *slot_zero =
  25105. + (VCHIQ_SLOT_ZERO_T *)((char *)mem_base + mem_align);
  25106. + int num_slots = (mem_size - mem_align)/VCHIQ_SLOT_SIZE;
  25107. + int first_data_slot = VCHIQ_SLOT_ZERO_SLOTS;
  25108. +
  25109. + /* Ensure there is enough memory to run an absolutely minimum system */
  25110. + num_slots -= first_data_slot;
  25111. +
  25112. + if (num_slots < 4) {
  25113. + vchiq_log_error(vchiq_core_log_level,
  25114. + "vchiq_init_slots - insufficient memory %x bytes",
  25115. + mem_size);
  25116. + return NULL;
  25117. + }
  25118. +
  25119. + memset(slot_zero, 0, sizeof(VCHIQ_SLOT_ZERO_T));
  25120. +
  25121. + slot_zero->magic = VCHIQ_MAGIC;
  25122. + slot_zero->version = VCHIQ_VERSION;
  25123. + slot_zero->version_min = VCHIQ_VERSION_MIN;
  25124. + slot_zero->slot_zero_size = sizeof(VCHIQ_SLOT_ZERO_T);
  25125. + slot_zero->slot_size = VCHIQ_SLOT_SIZE;
  25126. + slot_zero->max_slots = VCHIQ_MAX_SLOTS;
  25127. + slot_zero->max_slots_per_side = VCHIQ_MAX_SLOTS_PER_SIDE;
  25128. +
  25129. + slot_zero->master.slot_sync = first_data_slot;
  25130. + slot_zero->master.slot_first = first_data_slot + 1;
  25131. + slot_zero->master.slot_last = first_data_slot + (num_slots/2) - 1;
  25132. + slot_zero->slave.slot_sync = first_data_slot + (num_slots/2);
  25133. + slot_zero->slave.slot_first = first_data_slot + (num_slots/2) + 1;
  25134. + slot_zero->slave.slot_last = first_data_slot + num_slots - 1;
  25135. +
  25136. + return slot_zero;
  25137. +}
  25138. +
  25139. +VCHIQ_STATUS_T
  25140. +vchiq_init_state(VCHIQ_STATE_T *state, VCHIQ_SLOT_ZERO_T *slot_zero,
  25141. + int is_master)
  25142. +{
  25143. + VCHIQ_SHARED_STATE_T *local;
  25144. + VCHIQ_SHARED_STATE_T *remote;
  25145. + VCHIQ_STATUS_T status;
  25146. + char threadname[10];
  25147. + static int id;
  25148. + int i;
  25149. +
  25150. + vchiq_log_warning(vchiq_core_log_level,
  25151. + "%s: slot_zero = 0x%08lx, is_master = %d",
  25152. + __func__, (unsigned long)slot_zero, is_master);
  25153. +
  25154. + /* Check the input configuration */
  25155. +
  25156. + if (slot_zero->magic != VCHIQ_MAGIC) {
  25157. + vchiq_loud_error_header();
  25158. + vchiq_loud_error("Invalid VCHIQ magic value found.");
  25159. + vchiq_loud_error("slot_zero=%x: magic=%x (expected %x)",
  25160. + (unsigned int)slot_zero, slot_zero->magic, VCHIQ_MAGIC);
  25161. + vchiq_loud_error_footer();
  25162. + return VCHIQ_ERROR;
  25163. + }
  25164. +
  25165. + if (slot_zero->version < VCHIQ_VERSION_MIN) {
  25166. + vchiq_loud_error_header();
  25167. + vchiq_loud_error("Incompatible VCHIQ versions found.");
  25168. + vchiq_loud_error("slot_zero=%x: VideoCore version=%d "
  25169. + "(minimum %d)",
  25170. + (unsigned int)slot_zero, slot_zero->version,
  25171. + VCHIQ_VERSION_MIN);
  25172. + vchiq_loud_error("Restart with a newer VideoCore image.");
  25173. + vchiq_loud_error_footer();
  25174. + return VCHIQ_ERROR;
  25175. + }
  25176. +
  25177. + if (VCHIQ_VERSION < slot_zero->version_min) {
  25178. + vchiq_loud_error_header();
  25179. + vchiq_loud_error("Incompatible VCHIQ versions found.");
  25180. + vchiq_loud_error("slot_zero=%x: version=%d (VideoCore "
  25181. + "minimum %d)",
  25182. + (unsigned int)slot_zero, VCHIQ_VERSION,
  25183. + slot_zero->version_min);
  25184. + vchiq_loud_error("Restart with a newer kernel.");
  25185. + vchiq_loud_error_footer();
  25186. + return VCHIQ_ERROR;
  25187. + }
  25188. +
  25189. + if ((slot_zero->slot_zero_size != sizeof(VCHIQ_SLOT_ZERO_T)) ||
  25190. + (slot_zero->slot_size != VCHIQ_SLOT_SIZE) ||
  25191. + (slot_zero->max_slots != VCHIQ_MAX_SLOTS) ||
  25192. + (slot_zero->max_slots_per_side != VCHIQ_MAX_SLOTS_PER_SIDE)) {
  25193. + vchiq_loud_error_header();
  25194. + if (slot_zero->slot_zero_size != sizeof(VCHIQ_SLOT_ZERO_T))
  25195. + vchiq_loud_error("slot_zero=%x: slot_zero_size=%x "
  25196. + "(expected %x)",
  25197. + (unsigned int)slot_zero,
  25198. + slot_zero->slot_zero_size,
  25199. + sizeof(VCHIQ_SLOT_ZERO_T));
  25200. + if (slot_zero->slot_size != VCHIQ_SLOT_SIZE)
  25201. + vchiq_loud_error("slot_zero=%x: slot_size=%d "
  25202. + "(expected %d",
  25203. + (unsigned int)slot_zero, slot_zero->slot_size,
  25204. + VCHIQ_SLOT_SIZE);
  25205. + if (slot_zero->max_slots != VCHIQ_MAX_SLOTS)
  25206. + vchiq_loud_error("slot_zero=%x: max_slots=%d "
  25207. + "(expected %d)",
  25208. + (unsigned int)slot_zero, slot_zero->max_slots,
  25209. + VCHIQ_MAX_SLOTS);
  25210. + if (slot_zero->max_slots_per_side != VCHIQ_MAX_SLOTS_PER_SIDE)
  25211. + vchiq_loud_error("slot_zero=%x: max_slots_per_side=%d "
  25212. + "(expected %d)",
  25213. + (unsigned int)slot_zero,
  25214. + slot_zero->max_slots_per_side,
  25215. + VCHIQ_MAX_SLOTS_PER_SIDE);
  25216. + vchiq_loud_error_footer();
  25217. + return VCHIQ_ERROR;
  25218. + }
  25219. +
  25220. + if (is_master) {
  25221. + local = &slot_zero->master;
  25222. + remote = &slot_zero->slave;
  25223. + } else {
  25224. + local = &slot_zero->slave;
  25225. + remote = &slot_zero->master;
  25226. + }
  25227. +
  25228. + if (local->initialised) {
  25229. + vchiq_loud_error_header();
  25230. + if (remote->initialised)
  25231. + vchiq_loud_error("local state has already been "
  25232. + "initialised");
  25233. + else
  25234. + vchiq_loud_error("master/slave mismatch - two %ss",
  25235. + is_master ? "master" : "slave");
  25236. + vchiq_loud_error_footer();
  25237. + return VCHIQ_ERROR;
  25238. + }
  25239. +
  25240. + memset(state, 0, sizeof(VCHIQ_STATE_T));
  25241. +
  25242. + state->id = id++;
  25243. + state->is_master = is_master;
  25244. +
  25245. + /*
  25246. + initialize shared state pointers
  25247. + */
  25248. +
  25249. + state->local = local;
  25250. + state->remote = remote;
  25251. + state->slot_data = (VCHIQ_SLOT_T *)slot_zero;
  25252. +
  25253. + /*
  25254. + initialize events and mutexes
  25255. + */
  25256. +
  25257. + sema_init(&state->connect, 0);
  25258. + mutex_init(&state->mutex);
  25259. + sema_init(&state->trigger_event, 0);
  25260. + sema_init(&state->recycle_event, 0);
  25261. + sema_init(&state->sync_trigger_event, 0);
  25262. + sema_init(&state->sync_release_event, 0);
  25263. +
  25264. + mutex_init(&state->slot_mutex);
  25265. + mutex_init(&state->recycle_mutex);
  25266. + mutex_init(&state->sync_mutex);
  25267. + mutex_init(&state->bulk_transfer_mutex);
  25268. +
  25269. + sema_init(&state->slot_available_event, 0);
  25270. + sema_init(&state->slot_remove_event, 0);
  25271. + sema_init(&state->data_quota_event, 0);
  25272. +
  25273. + state->slot_queue_available = 0;
  25274. +
  25275. + for (i = 0; i < VCHIQ_MAX_SERVICES; i++) {
  25276. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  25277. + &state->service_quotas[i];
  25278. + sema_init(&service_quota->quota_event, 0);
  25279. + }
  25280. +
  25281. + for (i = local->slot_first; i <= local->slot_last; i++) {
  25282. + local->slot_queue[state->slot_queue_available++] = i;
  25283. + up(&state->slot_available_event);
  25284. + }
  25285. +
  25286. + state->default_slot_quota = state->slot_queue_available/2;
  25287. + state->default_message_quota =
  25288. + min((unsigned short)(state->default_slot_quota * 256),
  25289. + (unsigned short)~0);
  25290. +
  25291. + state->previous_data_index = -1;
  25292. + state->data_use_count = 0;
  25293. + state->data_quota = state->slot_queue_available - 1;
  25294. +
  25295. + local->trigger.event = &state->trigger_event;
  25296. + remote_event_create(&local->trigger);
  25297. + local->tx_pos = 0;
  25298. +
  25299. + local->recycle.event = &state->recycle_event;
  25300. + remote_event_create(&local->recycle);
  25301. + local->slot_queue_recycle = state->slot_queue_available;
  25302. +
  25303. + local->sync_trigger.event = &state->sync_trigger_event;
  25304. + remote_event_create(&local->sync_trigger);
  25305. +
  25306. + local->sync_release.event = &state->sync_release_event;
  25307. + remote_event_create(&local->sync_release);
  25308. +
  25309. + /* At start-of-day, the slot is empty and available */
  25310. + ((VCHIQ_HEADER_T *)SLOT_DATA_FROM_INDEX(state, local->slot_sync))->msgid
  25311. + = VCHIQ_MSGID_PADDING;
  25312. + remote_event_signal_local(&local->sync_release);
  25313. +
  25314. + local->debug[DEBUG_ENTRIES] = DEBUG_MAX;
  25315. +
  25316. + status = vchiq_platform_init_state(state);
  25317. +
  25318. + /*
  25319. + bring up slot handler thread
  25320. + */
  25321. + snprintf(threadname, sizeof(threadname), "VCHIQ-%d", state->id);
  25322. + state->slot_handler_thread = kthread_create(&slot_handler_func,
  25323. + (void *)state,
  25324. + threadname);
  25325. +
  25326. + if (state->slot_handler_thread == NULL) {
  25327. + vchiq_loud_error_header();
  25328. + vchiq_loud_error("couldn't create thread %s", threadname);
  25329. + vchiq_loud_error_footer();
  25330. + return VCHIQ_ERROR;
  25331. + }
  25332. + set_user_nice(state->slot_handler_thread, -19);
  25333. + wake_up_process(state->slot_handler_thread);
  25334. +
  25335. + snprintf(threadname, sizeof(threadname), "VCHIQr-%d", state->id);
  25336. + state->recycle_thread = kthread_create(&recycle_func,
  25337. + (void *)state,
  25338. + threadname);
  25339. + if (state->recycle_thread == NULL) {
  25340. + vchiq_loud_error_header();
  25341. + vchiq_loud_error("couldn't create thread %s", threadname);
  25342. + vchiq_loud_error_footer();
  25343. + return VCHIQ_ERROR;
  25344. + }
  25345. + set_user_nice(state->recycle_thread, -19);
  25346. + wake_up_process(state->recycle_thread);
  25347. +
  25348. + snprintf(threadname, sizeof(threadname), "VCHIQs-%d", state->id);
  25349. + state->sync_thread = kthread_create(&sync_func,
  25350. + (void *)state,
  25351. + threadname);
  25352. + if (state->sync_thread == NULL) {
  25353. + vchiq_loud_error_header();
  25354. + vchiq_loud_error("couldn't create thread %s", threadname);
  25355. + vchiq_loud_error_footer();
  25356. + return VCHIQ_ERROR;
  25357. + }
  25358. + set_user_nice(state->sync_thread, -20);
  25359. + wake_up_process(state->sync_thread);
  25360. +
  25361. + BUG_ON(state->id >= VCHIQ_MAX_STATES);
  25362. + vchiq_states[state->id] = state;
  25363. +
  25364. + /* Indicate readiness to the other side */
  25365. + local->initialised = 1;
  25366. +
  25367. + return status;
  25368. +}
  25369. +
  25370. +/* Called from application thread when a client or server service is created. */
  25371. +VCHIQ_SERVICE_T *
  25372. +vchiq_add_service_internal(VCHIQ_STATE_T *state,
  25373. + const VCHIQ_SERVICE_PARAMS_T *params, int srvstate,
  25374. + VCHIQ_INSTANCE_T instance, VCHIQ_USERDATA_TERM_T userdata_term)
  25375. +{
  25376. + VCHIQ_SERVICE_T *service;
  25377. +
  25378. + service = kmalloc(sizeof(VCHIQ_SERVICE_T), GFP_KERNEL);
  25379. + if (service) {
  25380. + service->base.fourcc = params->fourcc;
  25381. + service->base.callback = params->callback;
  25382. + service->base.userdata = params->userdata;
  25383. + service->handle = VCHIQ_SERVICE_HANDLE_INVALID;
  25384. + service->ref_count = 1;
  25385. + service->srvstate = VCHIQ_SRVSTATE_FREE;
  25386. + service->userdata_term = userdata_term;
  25387. + service->localport = VCHIQ_PORT_FREE;
  25388. + service->remoteport = VCHIQ_PORT_FREE;
  25389. +
  25390. + service->public_fourcc = (srvstate == VCHIQ_SRVSTATE_OPENING) ?
  25391. + VCHIQ_FOURCC_INVALID : params->fourcc;
  25392. + service->client_id = 0;
  25393. + service->auto_close = 1;
  25394. + service->sync = 0;
  25395. + service->closing = 0;
  25396. + atomic_set(&service->poll_flags, 0);
  25397. + service->version = params->version;
  25398. + service->version_min = params->version_min;
  25399. + service->state = state;
  25400. + service->instance = instance;
  25401. + service->service_use_count = 0;
  25402. + init_bulk_queue(&service->bulk_tx);
  25403. + init_bulk_queue(&service->bulk_rx);
  25404. + sema_init(&service->remove_event, 0);
  25405. + sema_init(&service->bulk_remove_event, 0);
  25406. + mutex_init(&service->bulk_mutex);
  25407. + memset(&service->stats, 0, sizeof(service->stats));
  25408. + } else {
  25409. + vchiq_log_error(vchiq_core_log_level,
  25410. + "Out of memory");
  25411. + }
  25412. +
  25413. + if (service) {
  25414. + VCHIQ_SERVICE_T **pservice = NULL;
  25415. + int i;
  25416. +
  25417. + /* Although it is perfectly possible to use service_spinlock
  25418. + ** to protect the creation of services, it is overkill as it
  25419. + ** disables interrupts while the array is searched.
  25420. + ** The only danger is of another thread trying to create a
  25421. + ** service - service deletion is safe.
  25422. + ** Therefore it is preferable to use state->mutex which,
  25423. + ** although slower to claim, doesn't block interrupts while
  25424. + ** it is held.
  25425. + */
  25426. +
  25427. + mutex_lock(&state->mutex);
  25428. +
  25429. + /* Prepare to use a previously unused service */
  25430. + if (state->unused_service < VCHIQ_MAX_SERVICES)
  25431. + pservice = &state->services[state->unused_service];
  25432. +
  25433. + if (srvstate == VCHIQ_SRVSTATE_OPENING) {
  25434. + for (i = 0; i < state->unused_service; i++) {
  25435. + VCHIQ_SERVICE_T *srv = state->services[i];
  25436. + if (!srv) {
  25437. + pservice = &state->services[i];
  25438. + break;
  25439. + }
  25440. + }
  25441. + } else {
  25442. + for (i = (state->unused_service - 1); i >= 0; i--) {
  25443. + VCHIQ_SERVICE_T *srv = state->services[i];
  25444. + if (!srv)
  25445. + pservice = &state->services[i];
  25446. + else if ((srv->public_fourcc == params->fourcc)
  25447. + && ((srv->instance != instance) ||
  25448. + (srv->base.callback !=
  25449. + params->callback))) {
  25450. + /* There is another server using this
  25451. + ** fourcc which doesn't match. */
  25452. + pservice = NULL;
  25453. + break;
  25454. + }
  25455. + }
  25456. + }
  25457. +
  25458. + if (pservice) {
  25459. + service->localport = (pservice - state->services);
  25460. + if (!handle_seq)
  25461. + handle_seq = VCHIQ_MAX_STATES *
  25462. + VCHIQ_MAX_SERVICES;
  25463. + service->handle = handle_seq |
  25464. + (state->id * VCHIQ_MAX_SERVICES) |
  25465. + service->localport;
  25466. + handle_seq += VCHIQ_MAX_STATES * VCHIQ_MAX_SERVICES;
  25467. + *pservice = service;
  25468. + if (pservice == &state->services[state->unused_service])
  25469. + state->unused_service++;
  25470. + }
  25471. +
  25472. + mutex_unlock(&state->mutex);
  25473. +
  25474. + if (!pservice) {
  25475. + kfree(service);
  25476. + service = NULL;
  25477. + }
  25478. + }
  25479. +
  25480. + if (service) {
  25481. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  25482. + &state->service_quotas[service->localport];
  25483. + service_quota->slot_quota = state->default_slot_quota;
  25484. + service_quota->message_quota = state->default_message_quota;
  25485. + if (service_quota->slot_use_count == 0)
  25486. + service_quota->previous_tx_index =
  25487. + SLOT_QUEUE_INDEX_FROM_POS(state->local_tx_pos)
  25488. + - 1;
  25489. +
  25490. + /* Bring this service online */
  25491. + vchiq_set_service_state(service, srvstate);
  25492. +
  25493. + vchiq_log_info(vchiq_core_msg_log_level,
  25494. + "%s Service %c%c%c%c SrcPort:%d",
  25495. + (srvstate == VCHIQ_SRVSTATE_OPENING)
  25496. + ? "Open" : "Add",
  25497. + VCHIQ_FOURCC_AS_4CHARS(params->fourcc),
  25498. + service->localport);
  25499. + }
  25500. +
  25501. + /* Don't unlock the service - leave it with a ref_count of 1. */
  25502. +
  25503. + return service;
  25504. +}
  25505. +
  25506. +VCHIQ_STATUS_T
  25507. +vchiq_open_service_internal(VCHIQ_SERVICE_T *service, int client_id)
  25508. +{
  25509. + struct vchiq_open_payload payload = {
  25510. + service->base.fourcc,
  25511. + client_id,
  25512. + service->version,
  25513. + service->version_min
  25514. + };
  25515. + VCHIQ_ELEMENT_T body = { &payload, sizeof(payload) };
  25516. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  25517. +
  25518. + service->client_id = client_id;
  25519. + vchiq_use_service_internal(service);
  25520. + status = queue_message(service->state, NULL,
  25521. + VCHIQ_MAKE_MSG(VCHIQ_MSG_OPEN, service->localport, 0),
  25522. + &body, 1, sizeof(payload), 1);
  25523. + if (status == VCHIQ_SUCCESS) {
  25524. + if (down_interruptible(&service->remove_event) != 0) {
  25525. + status = VCHIQ_RETRY;
  25526. + vchiq_release_service_internal(service);
  25527. + } else if ((service->srvstate != VCHIQ_SRVSTATE_OPEN) &&
  25528. + (service->srvstate != VCHIQ_SRVSTATE_OPENSYNC)) {
  25529. + if (service->srvstate != VCHIQ_SRVSTATE_CLOSEWAIT)
  25530. + vchiq_log_error(vchiq_core_log_level,
  25531. + "%d: osi - srvstate = %s (ref %d)",
  25532. + service->state->id,
  25533. + srvstate_names[service->srvstate],
  25534. + service->ref_count);
  25535. + status = VCHIQ_ERROR;
  25536. + VCHIQ_SERVICE_STATS_INC(service, error_count);
  25537. + vchiq_release_service_internal(service);
  25538. + }
  25539. + }
  25540. + return status;
  25541. +}
  25542. +
  25543. +static void
  25544. +release_service_messages(VCHIQ_SERVICE_T *service)
  25545. +{
  25546. + VCHIQ_STATE_T *state = service->state;
  25547. + int slot_last = state->remote->slot_last;
  25548. + int i;
  25549. +
  25550. + /* Release any claimed messages */
  25551. + for (i = state->remote->slot_first; i <= slot_last; i++) {
  25552. + VCHIQ_SLOT_INFO_T *slot_info =
  25553. + SLOT_INFO_FROM_INDEX(state, i);
  25554. + if (slot_info->release_count != slot_info->use_count) {
  25555. + char *data =
  25556. + (char *)SLOT_DATA_FROM_INDEX(state, i);
  25557. + unsigned int pos, end;
  25558. +
  25559. + end = VCHIQ_SLOT_SIZE;
  25560. + if (data == state->rx_data)
  25561. + /* This buffer is still being read from - stop
  25562. + ** at the current read position */
  25563. + end = state->rx_pos & VCHIQ_SLOT_MASK;
  25564. +
  25565. + pos = 0;
  25566. +
  25567. + while (pos < end) {
  25568. + VCHIQ_HEADER_T *header =
  25569. + (VCHIQ_HEADER_T *)(data + pos);
  25570. + int msgid = header->msgid;
  25571. + int port = VCHIQ_MSG_DSTPORT(msgid);
  25572. + if ((port == service->localport) &&
  25573. + (msgid & VCHIQ_MSGID_CLAIMED)) {
  25574. + vchiq_log_info(vchiq_core_log_level,
  25575. + " fsi - hdr %x",
  25576. + (unsigned int)header);
  25577. + release_slot(state, slot_info, header,
  25578. + NULL);
  25579. + }
  25580. + pos += calc_stride(header->size);
  25581. + if (pos > VCHIQ_SLOT_SIZE) {
  25582. + vchiq_log_error(vchiq_core_log_level,
  25583. + "fsi - pos %x: header %x, "
  25584. + "msgid %x, header->msgid %x, "
  25585. + "header->size %x",
  25586. + pos, (unsigned int)header,
  25587. + msgid, header->msgid,
  25588. + header->size);
  25589. + WARN(1, "invalid slot position\n");
  25590. + }
  25591. + }
  25592. + }
  25593. + }
  25594. +}
  25595. +
  25596. +static int
  25597. +do_abort_bulks(VCHIQ_SERVICE_T *service)
  25598. +{
  25599. + VCHIQ_STATUS_T status;
  25600. +
  25601. + /* Abort any outstanding bulk transfers */
  25602. + if (mutex_lock_interruptible(&service->bulk_mutex) != 0)
  25603. + return 0;
  25604. + abort_outstanding_bulks(service, &service->bulk_tx);
  25605. + abort_outstanding_bulks(service, &service->bulk_rx);
  25606. + mutex_unlock(&service->bulk_mutex);
  25607. +
  25608. + status = notify_bulks(service, &service->bulk_tx, 0/*!retry_poll*/);
  25609. + if (status == VCHIQ_SUCCESS)
  25610. + status = notify_bulks(service, &service->bulk_rx,
  25611. + 0/*!retry_poll*/);
  25612. + return (status == VCHIQ_SUCCESS);
  25613. +}
  25614. +
  25615. +static VCHIQ_STATUS_T
  25616. +close_service_complete(VCHIQ_SERVICE_T *service, int failstate)
  25617. +{
  25618. + VCHIQ_STATUS_T status;
  25619. + int is_server = (service->public_fourcc != VCHIQ_FOURCC_INVALID);
  25620. + int newstate;
  25621. +
  25622. + switch (service->srvstate) {
  25623. + case VCHIQ_SRVSTATE_OPEN:
  25624. + case VCHIQ_SRVSTATE_CLOSESENT:
  25625. + case VCHIQ_SRVSTATE_CLOSERECVD:
  25626. + if (is_server) {
  25627. + if (service->auto_close) {
  25628. + service->client_id = 0;
  25629. + service->remoteport = VCHIQ_PORT_FREE;
  25630. + newstate = VCHIQ_SRVSTATE_LISTENING;
  25631. + } else
  25632. + newstate = VCHIQ_SRVSTATE_CLOSEWAIT;
  25633. + } else
  25634. + newstate = VCHIQ_SRVSTATE_CLOSED;
  25635. + vchiq_set_service_state(service, newstate);
  25636. + break;
  25637. + case VCHIQ_SRVSTATE_LISTENING:
  25638. + break;
  25639. + default:
  25640. + vchiq_log_error(vchiq_core_log_level,
  25641. + "close_service_complete(%x) called in state %s",
  25642. + service->handle, srvstate_names[service->srvstate]);
  25643. + WARN(1, "close_service_complete in unexpected state\n");
  25644. + return VCHIQ_ERROR;
  25645. + }
  25646. +
  25647. + status = make_service_callback(service,
  25648. + VCHIQ_SERVICE_CLOSED, NULL, NULL);
  25649. +
  25650. + if (status != VCHIQ_RETRY) {
  25651. + int uc = service->service_use_count;
  25652. + int i;
  25653. + /* Complete the close process */
  25654. + for (i = 0; i < uc; i++)
  25655. + /* cater for cases where close is forced and the
  25656. + ** client may not close all it's handles */
  25657. + vchiq_release_service_internal(service);
  25658. +
  25659. + service->client_id = 0;
  25660. + service->remoteport = VCHIQ_PORT_FREE;
  25661. +
  25662. + if (service->srvstate == VCHIQ_SRVSTATE_CLOSED)
  25663. + vchiq_free_service_internal(service);
  25664. + else if (service->srvstate != VCHIQ_SRVSTATE_CLOSEWAIT) {
  25665. + if (is_server)
  25666. + service->closing = 0;
  25667. +
  25668. + up(&service->remove_event);
  25669. + }
  25670. + } else
  25671. + vchiq_set_service_state(service, failstate);
  25672. +
  25673. + return status;
  25674. +}
  25675. +
  25676. +/* Called by the slot handler */
  25677. +VCHIQ_STATUS_T
  25678. +vchiq_close_service_internal(VCHIQ_SERVICE_T *service, int close_recvd)
  25679. +{
  25680. + VCHIQ_STATE_T *state = service->state;
  25681. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  25682. + int is_server = (service->public_fourcc != VCHIQ_FOURCC_INVALID);
  25683. +
  25684. + vchiq_log_info(vchiq_core_log_level, "%d: csi:%d,%d (%s)",
  25685. + service->state->id, service->localport, close_recvd,
  25686. + srvstate_names[service->srvstate]);
  25687. +
  25688. + switch (service->srvstate) {
  25689. + case VCHIQ_SRVSTATE_CLOSED:
  25690. + case VCHIQ_SRVSTATE_HIDDEN:
  25691. + case VCHIQ_SRVSTATE_LISTENING:
  25692. + case VCHIQ_SRVSTATE_CLOSEWAIT:
  25693. + if (close_recvd)
  25694. + vchiq_log_error(vchiq_core_log_level,
  25695. + "vchiq_close_service_internal(1) called "
  25696. + "in state %s",
  25697. + srvstate_names[service->srvstate]);
  25698. + else if (is_server) {
  25699. + if (service->srvstate == VCHIQ_SRVSTATE_LISTENING) {
  25700. + status = VCHIQ_ERROR;
  25701. + } else {
  25702. + service->client_id = 0;
  25703. + service->remoteport = VCHIQ_PORT_FREE;
  25704. + if (service->srvstate ==
  25705. + VCHIQ_SRVSTATE_CLOSEWAIT)
  25706. + vchiq_set_service_state(service,
  25707. + VCHIQ_SRVSTATE_LISTENING);
  25708. + }
  25709. + up(&service->remove_event);
  25710. + } else
  25711. + vchiq_free_service_internal(service);
  25712. + break;
  25713. + case VCHIQ_SRVSTATE_OPENING:
  25714. + if (close_recvd) {
  25715. + /* The open was rejected - tell the user */
  25716. + vchiq_set_service_state(service,
  25717. + VCHIQ_SRVSTATE_CLOSEWAIT);
  25718. + up(&service->remove_event);
  25719. + } else {
  25720. + /* Shutdown mid-open - let the other side know */
  25721. + status = queue_message(state, service,
  25722. + VCHIQ_MAKE_MSG
  25723. + (VCHIQ_MSG_CLOSE,
  25724. + service->localport,
  25725. + VCHIQ_MSG_DSTPORT(service->remoteport)),
  25726. + NULL, 0, 0, 0);
  25727. + }
  25728. + break;
  25729. +
  25730. + case VCHIQ_SRVSTATE_OPENSYNC:
  25731. + mutex_lock(&state->sync_mutex);
  25732. + /* Drop through */
  25733. +
  25734. + case VCHIQ_SRVSTATE_OPEN:
  25735. + if (state->is_master || close_recvd) {
  25736. + if (!do_abort_bulks(service))
  25737. + status = VCHIQ_RETRY;
  25738. + }
  25739. +
  25740. + release_service_messages(service);
  25741. +
  25742. + if (status == VCHIQ_SUCCESS)
  25743. + status = queue_message(state, service,
  25744. + VCHIQ_MAKE_MSG
  25745. + (VCHIQ_MSG_CLOSE,
  25746. + service->localport,
  25747. + VCHIQ_MSG_DSTPORT(service->remoteport)),
  25748. + NULL, 0, 0, 0);
  25749. +
  25750. + if (status == VCHIQ_SUCCESS) {
  25751. + if (!close_recvd)
  25752. + break;
  25753. + } else if (service->srvstate == VCHIQ_SRVSTATE_OPENSYNC) {
  25754. + mutex_unlock(&state->sync_mutex);
  25755. + break;
  25756. + } else
  25757. + break;
  25758. +
  25759. + status = close_service_complete(service,
  25760. + VCHIQ_SRVSTATE_CLOSERECVD);
  25761. + break;
  25762. +
  25763. + case VCHIQ_SRVSTATE_CLOSESENT:
  25764. + if (!close_recvd)
  25765. + /* This happens when a process is killed mid-close */
  25766. + break;
  25767. +
  25768. + if (!state->is_master) {
  25769. + if (!do_abort_bulks(service)) {
  25770. + status = VCHIQ_RETRY;
  25771. + break;
  25772. + }
  25773. + }
  25774. +
  25775. + if (status == VCHIQ_SUCCESS)
  25776. + status = close_service_complete(service,
  25777. + VCHIQ_SRVSTATE_CLOSERECVD);
  25778. + break;
  25779. +
  25780. + case VCHIQ_SRVSTATE_CLOSERECVD:
  25781. + if (!close_recvd && is_server)
  25782. + /* Force into LISTENING mode */
  25783. + vchiq_set_service_state(service,
  25784. + VCHIQ_SRVSTATE_LISTENING);
  25785. + status = close_service_complete(service,
  25786. + VCHIQ_SRVSTATE_CLOSERECVD);
  25787. + break;
  25788. +
  25789. + default:
  25790. + vchiq_log_error(vchiq_core_log_level,
  25791. + "vchiq_close_service_internal(%d) called in state %s",
  25792. + close_recvd, srvstate_names[service->srvstate]);
  25793. + break;
  25794. + }
  25795. +
  25796. + return status;
  25797. +}
  25798. +
  25799. +/* Called from the application process upon process death */
  25800. +void
  25801. +vchiq_terminate_service_internal(VCHIQ_SERVICE_T *service)
  25802. +{
  25803. + VCHIQ_STATE_T *state = service->state;
  25804. +
  25805. + vchiq_log_info(vchiq_core_log_level, "%d: tsi - (%d<->%d)",
  25806. + state->id, service->localport, service->remoteport);
  25807. +
  25808. + mark_service_closing(service);
  25809. +
  25810. + /* Mark the service for removal by the slot handler */
  25811. + request_poll(state, service, VCHIQ_POLL_REMOVE);
  25812. +}
  25813. +
  25814. +/* Called from the slot handler */
  25815. +void
  25816. +vchiq_free_service_internal(VCHIQ_SERVICE_T *service)
  25817. +{
  25818. + VCHIQ_STATE_T *state = service->state;
  25819. +
  25820. + vchiq_log_info(vchiq_core_log_level, "%d: fsi - (%d)",
  25821. + state->id, service->localport);
  25822. +
  25823. + switch (service->srvstate) {
  25824. + case VCHIQ_SRVSTATE_OPENING:
  25825. + case VCHIQ_SRVSTATE_CLOSED:
  25826. + case VCHIQ_SRVSTATE_HIDDEN:
  25827. + case VCHIQ_SRVSTATE_LISTENING:
  25828. + case VCHIQ_SRVSTATE_CLOSEWAIT:
  25829. + break;
  25830. + default:
  25831. + vchiq_log_error(vchiq_core_log_level,
  25832. + "%d: fsi - (%d) in state %s",
  25833. + state->id, service->localport,
  25834. + srvstate_names[service->srvstate]);
  25835. + return;
  25836. + }
  25837. +
  25838. + vchiq_set_service_state(service, VCHIQ_SRVSTATE_FREE);
  25839. +
  25840. + up(&service->remove_event);
  25841. +
  25842. + /* Release the initial lock */
  25843. + unlock_service(service);
  25844. +}
  25845. +
  25846. +VCHIQ_STATUS_T
  25847. +vchiq_connect_internal(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance)
  25848. +{
  25849. + VCHIQ_SERVICE_T *service;
  25850. + int i;
  25851. +
  25852. + /* Find all services registered to this client and enable them. */
  25853. + i = 0;
  25854. + while ((service = next_service_by_instance(state, instance,
  25855. + &i)) != NULL) {
  25856. + if (service->srvstate == VCHIQ_SRVSTATE_HIDDEN)
  25857. + vchiq_set_service_state(service,
  25858. + VCHIQ_SRVSTATE_LISTENING);
  25859. + unlock_service(service);
  25860. + }
  25861. +
  25862. + if (state->conn_state == VCHIQ_CONNSTATE_DISCONNECTED) {
  25863. + if (queue_message(state, NULL,
  25864. + VCHIQ_MAKE_MSG(VCHIQ_MSG_CONNECT, 0, 0), NULL, 0,
  25865. + 0, 1) == VCHIQ_RETRY)
  25866. + return VCHIQ_RETRY;
  25867. +
  25868. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_CONNECTING);
  25869. + }
  25870. +
  25871. + if (state->conn_state == VCHIQ_CONNSTATE_CONNECTING) {
  25872. + if (down_interruptible(&state->connect) != 0)
  25873. + return VCHIQ_RETRY;
  25874. +
  25875. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_CONNECTED);
  25876. + up(&state->connect);
  25877. + }
  25878. +
  25879. + return VCHIQ_SUCCESS;
  25880. +}
  25881. +
  25882. +VCHIQ_STATUS_T
  25883. +vchiq_shutdown_internal(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance)
  25884. +{
  25885. + VCHIQ_SERVICE_T *service;
  25886. + int i;
  25887. +
  25888. + /* Find all services registered to this client and enable them. */
  25889. + i = 0;
  25890. + while ((service = next_service_by_instance(state, instance,
  25891. + &i)) != NULL) {
  25892. + (void)vchiq_remove_service(service->handle);
  25893. + unlock_service(service);
  25894. + }
  25895. +
  25896. + return VCHIQ_SUCCESS;
  25897. +}
  25898. +
  25899. +VCHIQ_STATUS_T
  25900. +vchiq_pause_internal(VCHIQ_STATE_T *state)
  25901. +{
  25902. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  25903. +
  25904. + switch (state->conn_state) {
  25905. + case VCHIQ_CONNSTATE_CONNECTED:
  25906. + /* Request a pause */
  25907. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_PAUSING);
  25908. + request_poll(state, NULL, 0);
  25909. + break;
  25910. + default:
  25911. + vchiq_log_error(vchiq_core_log_level,
  25912. + "vchiq_pause_internal in state %s\n",
  25913. + conn_state_names[state->conn_state]);
  25914. + status = VCHIQ_ERROR;
  25915. + VCHIQ_STATS_INC(state, error_count);
  25916. + break;
  25917. + }
  25918. +
  25919. + return status;
  25920. +}
  25921. +
  25922. +VCHIQ_STATUS_T
  25923. +vchiq_resume_internal(VCHIQ_STATE_T *state)
  25924. +{
  25925. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  25926. +
  25927. + if (state->conn_state == VCHIQ_CONNSTATE_PAUSED) {
  25928. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_RESUMING);
  25929. + request_poll(state, NULL, 0);
  25930. + } else {
  25931. + status = VCHIQ_ERROR;
  25932. + VCHIQ_STATS_INC(state, error_count);
  25933. + }
  25934. +
  25935. + return status;
  25936. +}
  25937. +
  25938. +VCHIQ_STATUS_T
  25939. +vchiq_close_service(VCHIQ_SERVICE_HANDLE_T handle)
  25940. +{
  25941. + /* Unregister the service */
  25942. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  25943. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  25944. +
  25945. + if (!service)
  25946. + return VCHIQ_ERROR;
  25947. +
  25948. + vchiq_log_info(vchiq_core_log_level,
  25949. + "%d: close_service:%d",
  25950. + service->state->id, service->localport);
  25951. +
  25952. + if ((service->srvstate == VCHIQ_SRVSTATE_FREE) ||
  25953. + (service->srvstate == VCHIQ_SRVSTATE_LISTENING) ||
  25954. + (service->srvstate == VCHIQ_SRVSTATE_HIDDEN)) {
  25955. + unlock_service(service);
  25956. + return VCHIQ_ERROR;
  25957. + }
  25958. +
  25959. + mark_service_closing(service);
  25960. +
  25961. + if (current == service->state->slot_handler_thread) {
  25962. + status = vchiq_close_service_internal(service,
  25963. + 0/*!close_recvd*/);
  25964. + BUG_ON(status == VCHIQ_RETRY);
  25965. + } else {
  25966. + /* Mark the service for termination by the slot handler */
  25967. + request_poll(service->state, service, VCHIQ_POLL_TERMINATE);
  25968. + }
  25969. +
  25970. + while (1) {
  25971. + if (down_interruptible(&service->remove_event) != 0) {
  25972. + status = VCHIQ_RETRY;
  25973. + break;
  25974. + }
  25975. +
  25976. + if ((service->srvstate == VCHIQ_SRVSTATE_FREE) ||
  25977. + (service->srvstate == VCHIQ_SRVSTATE_LISTENING) ||
  25978. + (service->srvstate == VCHIQ_SRVSTATE_OPEN))
  25979. + break;
  25980. +
  25981. + vchiq_log_warning(vchiq_core_log_level,
  25982. + "%d: close_service:%d - waiting in state %s",
  25983. + service->state->id, service->localport,
  25984. + srvstate_names[service->srvstate]);
  25985. + }
  25986. +
  25987. + if ((status == VCHIQ_SUCCESS) &&
  25988. + (service->srvstate != VCHIQ_SRVSTATE_FREE) &&
  25989. + (service->srvstate != VCHIQ_SRVSTATE_LISTENING))
  25990. + status = VCHIQ_ERROR;
  25991. +
  25992. + unlock_service(service);
  25993. +
  25994. + return status;
  25995. +}
  25996. +
  25997. +VCHIQ_STATUS_T
  25998. +vchiq_remove_service(VCHIQ_SERVICE_HANDLE_T handle)
  25999. +{
  26000. + /* Unregister the service */
  26001. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  26002. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  26003. +
  26004. + if (!service)
  26005. + return VCHIQ_ERROR;
  26006. +
  26007. + vchiq_log_info(vchiq_core_log_level,
  26008. + "%d: remove_service:%d",
  26009. + service->state->id, service->localport);
  26010. +
  26011. + if (service->srvstate == VCHIQ_SRVSTATE_FREE) {
  26012. + unlock_service(service);
  26013. + return VCHIQ_ERROR;
  26014. + }
  26015. +
  26016. + mark_service_closing(service);
  26017. +
  26018. + if ((service->srvstate == VCHIQ_SRVSTATE_HIDDEN) ||
  26019. + (current == service->state->slot_handler_thread)) {
  26020. + /* Make it look like a client, because it must be removed and
  26021. + not left in the LISTENING state. */
  26022. + service->public_fourcc = VCHIQ_FOURCC_INVALID;
  26023. +
  26024. + status = vchiq_close_service_internal(service,
  26025. + 0/*!close_recvd*/);
  26026. + BUG_ON(status == VCHIQ_RETRY);
  26027. + } else {
  26028. + /* Mark the service for removal by the slot handler */
  26029. + request_poll(service->state, service, VCHIQ_POLL_REMOVE);
  26030. + }
  26031. + while (1) {
  26032. + if (down_interruptible(&service->remove_event) != 0) {
  26033. + status = VCHIQ_RETRY;
  26034. + break;
  26035. + }
  26036. +
  26037. + if ((service->srvstate == VCHIQ_SRVSTATE_FREE) ||
  26038. + (service->srvstate == VCHIQ_SRVSTATE_OPEN))
  26039. + break;
  26040. +
  26041. + vchiq_log_warning(vchiq_core_log_level,
  26042. + "%d: remove_service:%d - waiting in state %s",
  26043. + service->state->id, service->localport,
  26044. + srvstate_names[service->srvstate]);
  26045. + }
  26046. +
  26047. + if ((status == VCHIQ_SUCCESS) &&
  26048. + (service->srvstate != VCHIQ_SRVSTATE_FREE))
  26049. + status = VCHIQ_ERROR;
  26050. +
  26051. + unlock_service(service);
  26052. +
  26053. + return status;
  26054. +}
  26055. +
  26056. +
  26057. +/* This function may be called by kernel threads or user threads.
  26058. + * User threads may receive VCHIQ_RETRY to indicate that a signal has been
  26059. + * received and the call should be retried after being returned to user
  26060. + * context.
  26061. + * When called in blocking mode, the userdata field points to a bulk_waiter
  26062. + * structure.
  26063. + */
  26064. +VCHIQ_STATUS_T
  26065. +vchiq_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle,
  26066. + VCHI_MEM_HANDLE_T memhandle, void *offset, int size, void *userdata,
  26067. + VCHIQ_BULK_MODE_T mode, VCHIQ_BULK_DIR_T dir)
  26068. +{
  26069. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  26070. + VCHIQ_BULK_QUEUE_T *queue;
  26071. + VCHIQ_BULK_T *bulk;
  26072. + VCHIQ_STATE_T *state;
  26073. + struct bulk_waiter *bulk_waiter = NULL;
  26074. + const char dir_char = (dir == VCHIQ_BULK_TRANSMIT) ? 't' : 'r';
  26075. + const int dir_msgtype = (dir == VCHIQ_BULK_TRANSMIT) ?
  26076. + VCHIQ_MSG_BULK_TX : VCHIQ_MSG_BULK_RX;
  26077. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  26078. +
  26079. + if (!service ||
  26080. + (service->srvstate != VCHIQ_SRVSTATE_OPEN) ||
  26081. + ((memhandle == VCHI_MEM_HANDLE_INVALID) && (offset == NULL)) ||
  26082. + (vchiq_check_service(service) != VCHIQ_SUCCESS))
  26083. + goto error_exit;
  26084. +
  26085. + switch (mode) {
  26086. + case VCHIQ_BULK_MODE_NOCALLBACK:
  26087. + case VCHIQ_BULK_MODE_CALLBACK:
  26088. + break;
  26089. + case VCHIQ_BULK_MODE_BLOCKING:
  26090. + bulk_waiter = (struct bulk_waiter *)userdata;
  26091. + sema_init(&bulk_waiter->event, 0);
  26092. + bulk_waiter->actual = 0;
  26093. + bulk_waiter->bulk = NULL;
  26094. + break;
  26095. + case VCHIQ_BULK_MODE_WAITING:
  26096. + bulk_waiter = (struct bulk_waiter *)userdata;
  26097. + bulk = bulk_waiter->bulk;
  26098. + goto waiting;
  26099. + default:
  26100. + goto error_exit;
  26101. + }
  26102. +
  26103. + state = service->state;
  26104. +
  26105. + queue = (dir == VCHIQ_BULK_TRANSMIT) ?
  26106. + &service->bulk_tx : &service->bulk_rx;
  26107. +
  26108. + if (mutex_lock_interruptible(&service->bulk_mutex) != 0) {
  26109. + status = VCHIQ_RETRY;
  26110. + goto error_exit;
  26111. + }
  26112. +
  26113. + if (queue->local_insert == queue->remove + VCHIQ_NUM_SERVICE_BULKS) {
  26114. + VCHIQ_SERVICE_STATS_INC(service, bulk_stalls);
  26115. + do {
  26116. + mutex_unlock(&service->bulk_mutex);
  26117. + if (down_interruptible(&service->bulk_remove_event)
  26118. + != 0) {
  26119. + status = VCHIQ_RETRY;
  26120. + goto error_exit;
  26121. + }
  26122. + if (mutex_lock_interruptible(&service->bulk_mutex)
  26123. + != 0) {
  26124. + status = VCHIQ_RETRY;
  26125. + goto error_exit;
  26126. + }
  26127. + } while (queue->local_insert == queue->remove +
  26128. + VCHIQ_NUM_SERVICE_BULKS);
  26129. + }
  26130. +
  26131. + bulk = &queue->bulks[BULK_INDEX(queue->local_insert)];
  26132. +
  26133. + bulk->mode = mode;
  26134. + bulk->dir = dir;
  26135. + bulk->userdata = userdata;
  26136. + bulk->size = size;
  26137. + bulk->actual = VCHIQ_BULK_ACTUAL_ABORTED;
  26138. +
  26139. + if (vchiq_prepare_bulk_data(bulk, memhandle, offset, size, dir) !=
  26140. + VCHIQ_SUCCESS)
  26141. + goto unlock_error_exit;
  26142. +
  26143. + wmb();
  26144. +
  26145. + vchiq_log_info(vchiq_core_log_level,
  26146. + "%d: bt (%d->%d) %cx %x@%x %x",
  26147. + state->id,
  26148. + service->localport, service->remoteport, dir_char,
  26149. + size, (unsigned int)bulk->data, (unsigned int)userdata);
  26150. +
  26151. + if (state->is_master) {
  26152. + queue->local_insert++;
  26153. + if (resolve_bulks(service, queue))
  26154. + request_poll(state, service,
  26155. + (dir == VCHIQ_BULK_TRANSMIT) ?
  26156. + VCHIQ_POLL_TXNOTIFY : VCHIQ_POLL_RXNOTIFY);
  26157. + } else {
  26158. + int payload[2] = { (int)bulk->data, bulk->size };
  26159. + VCHIQ_ELEMENT_T element = { payload, sizeof(payload) };
  26160. +
  26161. + status = queue_message(state, NULL,
  26162. + VCHIQ_MAKE_MSG(dir_msgtype,
  26163. + service->localport, service->remoteport),
  26164. + &element, 1, sizeof(payload), 1);
  26165. + if (status != VCHIQ_SUCCESS) {
  26166. + vchiq_complete_bulk(bulk);
  26167. + goto unlock_error_exit;
  26168. + }
  26169. + queue->local_insert++;
  26170. + }
  26171. +
  26172. + mutex_unlock(&service->bulk_mutex);
  26173. +
  26174. + vchiq_log_trace(vchiq_core_log_level,
  26175. + "%d: bt:%d %cx li=%x ri=%x p=%x",
  26176. + state->id,
  26177. + service->localport, dir_char,
  26178. + queue->local_insert, queue->remote_insert, queue->process);
  26179. +
  26180. +waiting:
  26181. + unlock_service(service);
  26182. +
  26183. + status = VCHIQ_SUCCESS;
  26184. +
  26185. + if (bulk_waiter) {
  26186. + bulk_waiter->bulk = bulk;
  26187. + if (down_interruptible(&bulk_waiter->event) != 0)
  26188. + status = VCHIQ_RETRY;
  26189. + else if (bulk_waiter->actual == VCHIQ_BULK_ACTUAL_ABORTED)
  26190. + status = VCHIQ_ERROR;
  26191. + }
  26192. +
  26193. + return status;
  26194. +
  26195. +unlock_error_exit:
  26196. + mutex_unlock(&service->bulk_mutex);
  26197. +
  26198. +error_exit:
  26199. + if (service)
  26200. + unlock_service(service);
  26201. + return status;
  26202. +}
  26203. +
  26204. +VCHIQ_STATUS_T
  26205. +vchiq_queue_message(VCHIQ_SERVICE_HANDLE_T handle,
  26206. + const VCHIQ_ELEMENT_T *elements, unsigned int count)
  26207. +{
  26208. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  26209. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  26210. +
  26211. + unsigned int size = 0;
  26212. + unsigned int i;
  26213. +
  26214. + if (!service ||
  26215. + (vchiq_check_service(service) != VCHIQ_SUCCESS))
  26216. + goto error_exit;
  26217. +
  26218. + for (i = 0; i < (unsigned int)count; i++) {
  26219. + if (elements[i].size) {
  26220. + if (elements[i].data == NULL) {
  26221. + VCHIQ_SERVICE_STATS_INC(service, error_count);
  26222. + goto error_exit;
  26223. + }
  26224. + size += elements[i].size;
  26225. + }
  26226. + }
  26227. +
  26228. + if (size > VCHIQ_MAX_MSG_SIZE) {
  26229. + VCHIQ_SERVICE_STATS_INC(service, error_count);
  26230. + goto error_exit;
  26231. + }
  26232. +
  26233. + switch (service->srvstate) {
  26234. + case VCHIQ_SRVSTATE_OPEN:
  26235. + status = queue_message(service->state, service,
  26236. + VCHIQ_MAKE_MSG(VCHIQ_MSG_DATA,
  26237. + service->localport,
  26238. + service->remoteport),
  26239. + elements, count, size, 1);
  26240. + break;
  26241. + case VCHIQ_SRVSTATE_OPENSYNC:
  26242. + status = queue_message_sync(service->state, service,
  26243. + VCHIQ_MAKE_MSG(VCHIQ_MSG_DATA,
  26244. + service->localport,
  26245. + service->remoteport),
  26246. + elements, count, size, 1);
  26247. + break;
  26248. + default:
  26249. + status = VCHIQ_ERROR;
  26250. + break;
  26251. + }
  26252. +
  26253. +error_exit:
  26254. + if (service)
  26255. + unlock_service(service);
  26256. +
  26257. + return status;
  26258. +}
  26259. +
  26260. +void
  26261. +vchiq_release_message(VCHIQ_SERVICE_HANDLE_T handle, VCHIQ_HEADER_T *header)
  26262. +{
  26263. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  26264. + VCHIQ_SHARED_STATE_T *remote;
  26265. + VCHIQ_STATE_T *state;
  26266. + int slot_index;
  26267. +
  26268. + if (!service)
  26269. + return;
  26270. +
  26271. + state = service->state;
  26272. + remote = state->remote;
  26273. +
  26274. + slot_index = SLOT_INDEX_FROM_DATA(state, (void *)header);
  26275. +
  26276. + if ((slot_index >= remote->slot_first) &&
  26277. + (slot_index <= remote->slot_last)) {
  26278. + int msgid = header->msgid;
  26279. + if (msgid & VCHIQ_MSGID_CLAIMED) {
  26280. + VCHIQ_SLOT_INFO_T *slot_info =
  26281. + SLOT_INFO_FROM_INDEX(state, slot_index);
  26282. +
  26283. + release_slot(state, slot_info, header, service);
  26284. + }
  26285. + } else if (slot_index == remote->slot_sync)
  26286. + release_message_sync(state, header);
  26287. +
  26288. + unlock_service(service);
  26289. +}
  26290. +
  26291. +static void
  26292. +release_message_sync(VCHIQ_STATE_T *state, VCHIQ_HEADER_T *header)
  26293. +{
  26294. + header->msgid = VCHIQ_MSGID_PADDING;
  26295. + wmb();
  26296. + remote_event_signal(&state->remote->sync_release);
  26297. +}
  26298. +
  26299. +VCHIQ_STATUS_T
  26300. +vchiq_get_peer_version(VCHIQ_SERVICE_HANDLE_T handle, short *peer_version)
  26301. +{
  26302. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  26303. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  26304. +
  26305. + if (!service ||
  26306. + (vchiq_check_service(service) != VCHIQ_SUCCESS) ||
  26307. + !peer_version)
  26308. + goto exit;
  26309. + *peer_version = service->peer_version;
  26310. + status = VCHIQ_SUCCESS;
  26311. +
  26312. +exit:
  26313. + if (service)
  26314. + unlock_service(service);
  26315. + return status;
  26316. +}
  26317. +
  26318. +VCHIQ_STATUS_T
  26319. +vchiq_get_config(VCHIQ_INSTANCE_T instance,
  26320. + int config_size, VCHIQ_CONFIG_T *pconfig)
  26321. +{
  26322. + VCHIQ_CONFIG_T config;
  26323. +
  26324. + (void)instance;
  26325. +
  26326. + config.max_msg_size = VCHIQ_MAX_MSG_SIZE;
  26327. + config.bulk_threshold = VCHIQ_MAX_MSG_SIZE;
  26328. + config.max_outstanding_bulks = VCHIQ_NUM_SERVICE_BULKS;
  26329. + config.max_services = VCHIQ_MAX_SERVICES;
  26330. + config.version = VCHIQ_VERSION;
  26331. + config.version_min = VCHIQ_VERSION_MIN;
  26332. +
  26333. + if (config_size > sizeof(VCHIQ_CONFIG_T))
  26334. + return VCHIQ_ERROR;
  26335. +
  26336. + memcpy(pconfig, &config,
  26337. + min(config_size, (int)(sizeof(VCHIQ_CONFIG_T))));
  26338. +
  26339. + return VCHIQ_SUCCESS;
  26340. +}
  26341. +
  26342. +VCHIQ_STATUS_T
  26343. +vchiq_set_service_option(VCHIQ_SERVICE_HANDLE_T handle,
  26344. + VCHIQ_SERVICE_OPTION_T option, int value)
  26345. +{
  26346. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  26347. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  26348. +
  26349. + if (service) {
  26350. + switch (option) {
  26351. + case VCHIQ_SERVICE_OPTION_AUTOCLOSE:
  26352. + service->auto_close = value;
  26353. + status = VCHIQ_SUCCESS;
  26354. + break;
  26355. +
  26356. + case VCHIQ_SERVICE_OPTION_SLOT_QUOTA: {
  26357. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  26358. + &service->state->service_quotas[
  26359. + service->localport];
  26360. + if (value == 0)
  26361. + value = service->state->default_slot_quota;
  26362. + if ((value >= service_quota->slot_use_count) &&
  26363. + (value < (unsigned short)~0)) {
  26364. + service_quota->slot_quota = value;
  26365. + if ((value >= service_quota->slot_use_count) &&
  26366. + (service_quota->message_quota >=
  26367. + service_quota->message_use_count)) {
  26368. + /* Signal the service that it may have
  26369. + ** dropped below its quota */
  26370. + up(&service_quota->quota_event);
  26371. + }
  26372. + status = VCHIQ_SUCCESS;
  26373. + }
  26374. + } break;
  26375. +
  26376. + case VCHIQ_SERVICE_OPTION_MESSAGE_QUOTA: {
  26377. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  26378. + &service->state->service_quotas[
  26379. + service->localport];
  26380. + if (value == 0)
  26381. + value = service->state->default_message_quota;
  26382. + if ((value >= service_quota->message_use_count) &&
  26383. + (value < (unsigned short)~0)) {
  26384. + service_quota->message_quota = value;
  26385. + if ((value >=
  26386. + service_quota->message_use_count) &&
  26387. + (service_quota->slot_quota >=
  26388. + service_quota->slot_use_count))
  26389. + /* Signal the service that it may have
  26390. + ** dropped below its quota */
  26391. + up(&service_quota->quota_event);
  26392. + status = VCHIQ_SUCCESS;
  26393. + }
  26394. + } break;
  26395. +
  26396. + case VCHIQ_SERVICE_OPTION_SYNCHRONOUS:
  26397. + if ((service->srvstate == VCHIQ_SRVSTATE_HIDDEN) ||
  26398. + (service->srvstate ==
  26399. + VCHIQ_SRVSTATE_LISTENING)) {
  26400. + service->sync = value;
  26401. + status = VCHIQ_SUCCESS;
  26402. + }
  26403. + break;
  26404. +
  26405. + default:
  26406. + break;
  26407. + }
  26408. + unlock_service(service);
  26409. + }
  26410. +
  26411. + return status;
  26412. +}
  26413. +
  26414. +void
  26415. +vchiq_dump_shared_state(void *dump_context, VCHIQ_STATE_T *state,
  26416. + VCHIQ_SHARED_STATE_T *shared, const char *label)
  26417. +{
  26418. + static const char *const debug_names[] = {
  26419. + "<entries>",
  26420. + "SLOT_HANDLER_COUNT",
  26421. + "SLOT_HANDLER_LINE",
  26422. + "PARSE_LINE",
  26423. + "PARSE_HEADER",
  26424. + "PARSE_MSGID",
  26425. + "AWAIT_COMPLETION_LINE",
  26426. + "DEQUEUE_MESSAGE_LINE",
  26427. + "SERVICE_CALLBACK_LINE",
  26428. + "MSG_QUEUE_FULL_COUNT",
  26429. + "COMPLETION_QUEUE_FULL_COUNT"
  26430. + };
  26431. + int i;
  26432. +
  26433. + char buf[80];
  26434. + int len;
  26435. + len = snprintf(buf, sizeof(buf),
  26436. + " %s: slots %d-%d tx_pos=%x recycle=%x",
  26437. + label, shared->slot_first, shared->slot_last,
  26438. + shared->tx_pos, shared->slot_queue_recycle);
  26439. + vchiq_dump(dump_context, buf, len + 1);
  26440. +
  26441. + len = snprintf(buf, sizeof(buf),
  26442. + " Slots claimed:");
  26443. + vchiq_dump(dump_context, buf, len + 1);
  26444. +
  26445. + for (i = shared->slot_first; i <= shared->slot_last; i++) {
  26446. + VCHIQ_SLOT_INFO_T slot_info = *SLOT_INFO_FROM_INDEX(state, i);
  26447. + if (slot_info.use_count != slot_info.release_count) {
  26448. + len = snprintf(buf, sizeof(buf),
  26449. + " %d: %d/%d", i, slot_info.use_count,
  26450. + slot_info.release_count);
  26451. + vchiq_dump(dump_context, buf, len + 1);
  26452. + }
  26453. + }
  26454. +
  26455. + for (i = 1; i < shared->debug[DEBUG_ENTRIES]; i++) {
  26456. + len = snprintf(buf, sizeof(buf), " DEBUG: %s = %d(%x)",
  26457. + debug_names[i], shared->debug[i], shared->debug[i]);
  26458. + vchiq_dump(dump_context, buf, len + 1);
  26459. + }
  26460. +}
  26461. +
  26462. +void
  26463. +vchiq_dump_state(void *dump_context, VCHIQ_STATE_T *state)
  26464. +{
  26465. + char buf[80];
  26466. + int len;
  26467. + int i;
  26468. +
  26469. + len = snprintf(buf, sizeof(buf), "State %d: %s", state->id,
  26470. + conn_state_names[state->conn_state]);
  26471. + vchiq_dump(dump_context, buf, len + 1);
  26472. +
  26473. + len = snprintf(buf, sizeof(buf),
  26474. + " tx_pos=%x(@%x), rx_pos=%x(@%x)",
  26475. + state->local->tx_pos,
  26476. + (uint32_t)state->tx_data +
  26477. + (state->local_tx_pos & VCHIQ_SLOT_MASK),
  26478. + state->rx_pos,
  26479. + (uint32_t)state->rx_data +
  26480. + (state->rx_pos & VCHIQ_SLOT_MASK));
  26481. + vchiq_dump(dump_context, buf, len + 1);
  26482. +
  26483. + len = snprintf(buf, sizeof(buf),
  26484. + " Version: %d (min %d)",
  26485. + VCHIQ_VERSION, VCHIQ_VERSION_MIN);
  26486. + vchiq_dump(dump_context, buf, len + 1);
  26487. +
  26488. + if (VCHIQ_ENABLE_STATS) {
  26489. + len = snprintf(buf, sizeof(buf),
  26490. + " Stats: ctrl_tx_count=%d, ctrl_rx_count=%d, "
  26491. + "error_count=%d",
  26492. + state->stats.ctrl_tx_count, state->stats.ctrl_rx_count,
  26493. + state->stats.error_count);
  26494. + vchiq_dump(dump_context, buf, len + 1);
  26495. + }
  26496. +
  26497. + len = snprintf(buf, sizeof(buf),
  26498. + " Slots: %d available (%d data), %d recyclable, %d stalls "
  26499. + "(%d data)",
  26500. + ((state->slot_queue_available * VCHIQ_SLOT_SIZE) -
  26501. + state->local_tx_pos) / VCHIQ_SLOT_SIZE,
  26502. + state->data_quota - state->data_use_count,
  26503. + state->local->slot_queue_recycle - state->slot_queue_available,
  26504. + state->stats.slot_stalls, state->stats.data_stalls);
  26505. + vchiq_dump(dump_context, buf, len + 1);
  26506. +
  26507. + vchiq_dump_platform_state(dump_context);
  26508. +
  26509. + vchiq_dump_shared_state(dump_context, state, state->local, "Local");
  26510. + vchiq_dump_shared_state(dump_context, state, state->remote, "Remote");
  26511. +
  26512. + vchiq_dump_platform_instances(dump_context);
  26513. +
  26514. + for (i = 0; i < state->unused_service; i++) {
  26515. + VCHIQ_SERVICE_T *service = find_service_by_port(state, i);
  26516. +
  26517. + if (service) {
  26518. + vchiq_dump_service_state(dump_context, service);
  26519. + unlock_service(service);
  26520. + }
  26521. + }
  26522. +}
  26523. +
  26524. +void
  26525. +vchiq_dump_service_state(void *dump_context, VCHIQ_SERVICE_T *service)
  26526. +{
  26527. + char buf[80];
  26528. + int len;
  26529. +
  26530. + len = snprintf(buf, sizeof(buf), "Service %d: %s (ref %u)",
  26531. + service->localport, srvstate_names[service->srvstate],
  26532. + service->ref_count - 1); /*Don't include the lock just taken*/
  26533. +
  26534. + if (service->srvstate != VCHIQ_SRVSTATE_FREE) {
  26535. + char remoteport[30];
  26536. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  26537. + &service->state->service_quotas[service->localport];
  26538. + int fourcc = service->base.fourcc;
  26539. + int tx_pending, rx_pending;
  26540. + if (service->remoteport != VCHIQ_PORT_FREE) {
  26541. + int len2 = snprintf(remoteport, sizeof(remoteport),
  26542. + "%d", service->remoteport);
  26543. + if (service->public_fourcc != VCHIQ_FOURCC_INVALID)
  26544. + snprintf(remoteport + len2,
  26545. + sizeof(remoteport) - len2,
  26546. + " (client %x)", service->client_id);
  26547. + } else
  26548. + strcpy(remoteport, "n/a");
  26549. +
  26550. + len += snprintf(buf + len, sizeof(buf) - len,
  26551. + " '%c%c%c%c' remote %s (msg use %d/%d, slot use %d/%d)",
  26552. + VCHIQ_FOURCC_AS_4CHARS(fourcc),
  26553. + remoteport,
  26554. + service_quota->message_use_count,
  26555. + service_quota->message_quota,
  26556. + service_quota->slot_use_count,
  26557. + service_quota->slot_quota);
  26558. +
  26559. + vchiq_dump(dump_context, buf, len + 1);
  26560. +
  26561. + tx_pending = service->bulk_tx.local_insert -
  26562. + service->bulk_tx.remote_insert;
  26563. +
  26564. + rx_pending = service->bulk_rx.local_insert -
  26565. + service->bulk_rx.remote_insert;
  26566. +
  26567. + len = snprintf(buf, sizeof(buf),
  26568. + " Bulk: tx_pending=%d (size %d),"
  26569. + " rx_pending=%d (size %d)",
  26570. + tx_pending,
  26571. + tx_pending ? service->bulk_tx.bulks[
  26572. + BULK_INDEX(service->bulk_tx.remove)].size : 0,
  26573. + rx_pending,
  26574. + rx_pending ? service->bulk_rx.bulks[
  26575. + BULK_INDEX(service->bulk_rx.remove)].size : 0);
  26576. +
  26577. + if (VCHIQ_ENABLE_STATS) {
  26578. + vchiq_dump(dump_context, buf, len + 1);
  26579. +
  26580. + len = snprintf(buf, sizeof(buf),
  26581. + " Ctrl: tx_count=%d, tx_bytes=%llu, "
  26582. + "rx_count=%d, rx_bytes=%llu",
  26583. + service->stats.ctrl_tx_count,
  26584. + service->stats.ctrl_tx_bytes,
  26585. + service->stats.ctrl_rx_count,
  26586. + service->stats.ctrl_rx_bytes);
  26587. + vchiq_dump(dump_context, buf, len + 1);
  26588. +
  26589. + len = snprintf(buf, sizeof(buf),
  26590. + " Bulk: tx_count=%d, tx_bytes=%llu, "
  26591. + "rx_count=%d, rx_bytes=%llu",
  26592. + service->stats.bulk_tx_count,
  26593. + service->stats.bulk_tx_bytes,
  26594. + service->stats.bulk_rx_count,
  26595. + service->stats.bulk_rx_bytes);
  26596. + vchiq_dump(dump_context, buf, len + 1);
  26597. +
  26598. + len = snprintf(buf, sizeof(buf),
  26599. + " %d quota stalls, %d slot stalls, "
  26600. + "%d bulk stalls, %d aborted, %d errors",
  26601. + service->stats.quota_stalls,
  26602. + service->stats.slot_stalls,
  26603. + service->stats.bulk_stalls,
  26604. + service->stats.bulk_aborted_count,
  26605. + service->stats.error_count);
  26606. + }
  26607. + }
  26608. +
  26609. + vchiq_dump(dump_context, buf, len + 1);
  26610. +
  26611. + if (service->srvstate != VCHIQ_SRVSTATE_FREE)
  26612. + vchiq_dump_platform_service_state(dump_context, service);
  26613. +}
  26614. +
  26615. +
  26616. +void
  26617. +vchiq_loud_error_header(void)
  26618. +{
  26619. + vchiq_log_error(vchiq_core_log_level,
  26620. + "============================================================"
  26621. + "================");
  26622. + vchiq_log_error(vchiq_core_log_level,
  26623. + "============================================================"
  26624. + "================");
  26625. + vchiq_log_error(vchiq_core_log_level, "=====");
  26626. +}
  26627. +
  26628. +void
  26629. +vchiq_loud_error_footer(void)
  26630. +{
  26631. + vchiq_log_error(vchiq_core_log_level, "=====");
  26632. + vchiq_log_error(vchiq_core_log_level,
  26633. + "============================================================"
  26634. + "================");
  26635. + vchiq_log_error(vchiq_core_log_level,
  26636. + "============================================================"
  26637. + "================");
  26638. +}
  26639. +
  26640. +
  26641. +VCHIQ_STATUS_T vchiq_send_remote_use(VCHIQ_STATE_T *state)
  26642. +{
  26643. + VCHIQ_STATUS_T status = VCHIQ_RETRY;
  26644. + if (state->conn_state != VCHIQ_CONNSTATE_DISCONNECTED)
  26645. + status = queue_message(state, NULL,
  26646. + VCHIQ_MAKE_MSG(VCHIQ_MSG_REMOTE_USE, 0, 0),
  26647. + NULL, 0, 0, 0);
  26648. + return status;
  26649. +}
  26650. +
  26651. +VCHIQ_STATUS_T vchiq_send_remote_release(VCHIQ_STATE_T *state)
  26652. +{
  26653. + VCHIQ_STATUS_T status = VCHIQ_RETRY;
  26654. + if (state->conn_state != VCHIQ_CONNSTATE_DISCONNECTED)
  26655. + status = queue_message(state, NULL,
  26656. + VCHIQ_MAKE_MSG(VCHIQ_MSG_REMOTE_RELEASE, 0, 0),
  26657. + NULL, 0, 0, 0);
  26658. + return status;
  26659. +}
  26660. +
  26661. +VCHIQ_STATUS_T vchiq_send_remote_use_active(VCHIQ_STATE_T *state)
  26662. +{
  26663. + VCHIQ_STATUS_T status = VCHIQ_RETRY;
  26664. + if (state->conn_state != VCHIQ_CONNSTATE_DISCONNECTED)
  26665. + status = queue_message(state, NULL,
  26666. + VCHIQ_MAKE_MSG(VCHIQ_MSG_REMOTE_USE_ACTIVE, 0, 0),
  26667. + NULL, 0, 0, 0);
  26668. + return status;
  26669. +}
  26670. +
  26671. +void vchiq_log_dump_mem(const char *label, uint32_t addr, const void *voidMem,
  26672. + size_t numBytes)
  26673. +{
  26674. + const uint8_t *mem = (const uint8_t *)voidMem;
  26675. + size_t offset;
  26676. + char lineBuf[100];
  26677. + char *s;
  26678. +
  26679. + while (numBytes > 0) {
  26680. + s = lineBuf;
  26681. +
  26682. + for (offset = 0; offset < 16; offset++) {
  26683. + if (offset < numBytes)
  26684. + s += snprintf(s, 4, "%02x ", mem[offset]);
  26685. + else
  26686. + s += snprintf(s, 4, " ");
  26687. + }
  26688. +
  26689. + for (offset = 0; offset < 16; offset++) {
  26690. + if (offset < numBytes) {
  26691. + uint8_t ch = mem[offset];
  26692. +
  26693. + if ((ch < ' ') || (ch > '~'))
  26694. + ch = '.';
  26695. + *s++ = (char)ch;
  26696. + }
  26697. + }
  26698. + *s++ = '\0';
  26699. +
  26700. + if ((label != NULL) && (*label != '\0'))
  26701. + vchiq_log_trace(VCHIQ_LOG_TRACE,
  26702. + "%s: %08x: %s", label, addr, lineBuf);
  26703. + else
  26704. + vchiq_log_trace(VCHIQ_LOG_TRACE,
  26705. + "%08x: %s", addr, lineBuf);
  26706. +
  26707. + addr += 16;
  26708. + mem += 16;
  26709. + if (numBytes > 16)
  26710. + numBytes -= 16;
  26711. + else
  26712. + numBytes = 0;
  26713. + }
  26714. +}
  26715. diff -Nur linux-3.13.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.h
  26716. --- linux-3.13.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.h 1970-01-01 01:00:00.000000000 +0100
  26717. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.h 2014-04-24 15:35:02.893551516 +0200
  26718. @@ -0,0 +1,706 @@
  26719. +/**
  26720. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  26721. + *
  26722. + * Redistribution and use in source and binary forms, with or without
  26723. + * modification, are permitted provided that the following conditions
  26724. + * are met:
  26725. + * 1. Redistributions of source code must retain the above copyright
  26726. + * notice, this list of conditions, and the following disclaimer,
  26727. + * without modification.
  26728. + * 2. Redistributions in binary form must reproduce the above copyright
  26729. + * notice, this list of conditions and the following disclaimer in the
  26730. + * documentation and/or other materials provided with the distribution.
  26731. + * 3. The names of the above-listed copyright holders may not be used
  26732. + * to endorse or promote products derived from this software without
  26733. + * specific prior written permission.
  26734. + *
  26735. + * ALTERNATIVELY, this software may be distributed under the terms of the
  26736. + * GNU General Public License ("GPL") version 2, as published by the Free
  26737. + * Software Foundation.
  26738. + *
  26739. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  26740. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  26741. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  26742. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  26743. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  26744. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  26745. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  26746. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  26747. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  26748. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  26749. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26750. + */
  26751. +
  26752. +#ifndef VCHIQ_CORE_H
  26753. +#define VCHIQ_CORE_H
  26754. +
  26755. +#include <linux/mutex.h>
  26756. +#include <linux/semaphore.h>
  26757. +#include <linux/kthread.h>
  26758. +
  26759. +#include "vchiq_cfg.h"
  26760. +
  26761. +#include "vchiq.h"
  26762. +
  26763. +/* Run time control of log level, based on KERN_XXX level. */
  26764. +#define VCHIQ_LOG_DEFAULT 4
  26765. +#define VCHIQ_LOG_ERROR 3
  26766. +#define VCHIQ_LOG_WARNING 4
  26767. +#define VCHIQ_LOG_INFO 6
  26768. +#define VCHIQ_LOG_TRACE 7
  26769. +
  26770. +#define VCHIQ_LOG_PREFIX KERN_INFO "vchiq: "
  26771. +
  26772. +#ifndef vchiq_log_error
  26773. +#define vchiq_log_error(cat, fmt, ...) \
  26774. + do { if (cat >= VCHIQ_LOG_ERROR) \
  26775. + printk(VCHIQ_LOG_PREFIX fmt "\n", ##__VA_ARGS__); } while (0)
  26776. +#endif
  26777. +#ifndef vchiq_log_warning
  26778. +#define vchiq_log_warning(cat, fmt, ...) \
  26779. + do { if (cat >= VCHIQ_LOG_WARNING) \
  26780. + printk(VCHIQ_LOG_PREFIX fmt "\n", ##__VA_ARGS__); } while (0)
  26781. +#endif
  26782. +#ifndef vchiq_log_info
  26783. +#define vchiq_log_info(cat, fmt, ...) \
  26784. + do { if (cat >= VCHIQ_LOG_INFO) \
  26785. + printk(VCHIQ_LOG_PREFIX fmt "\n", ##__VA_ARGS__); } while (0)
  26786. +#endif
  26787. +#ifndef vchiq_log_trace
  26788. +#define vchiq_log_trace(cat, fmt, ...) \
  26789. + do { if (cat >= VCHIQ_LOG_TRACE) \
  26790. + printk(VCHIQ_LOG_PREFIX fmt "\n", ##__VA_ARGS__); } while (0)
  26791. +#endif
  26792. +
  26793. +#define vchiq_loud_error(...) \
  26794. + vchiq_log_error(vchiq_core_log_level, "===== " __VA_ARGS__)
  26795. +
  26796. +#ifndef vchiq_static_assert
  26797. +#define vchiq_static_assert(cond) __attribute__((unused)) \
  26798. + extern int vchiq_static_assert[(cond) ? 1 : -1]
  26799. +#endif
  26800. +
  26801. +#define IS_POW2(x) (x && ((x & (x - 1)) == 0))
  26802. +
  26803. +/* Ensure that the slot size and maximum number of slots are powers of 2 */
  26804. +vchiq_static_assert(IS_POW2(VCHIQ_SLOT_SIZE));
  26805. +vchiq_static_assert(IS_POW2(VCHIQ_MAX_SLOTS));
  26806. +vchiq_static_assert(IS_POW2(VCHIQ_MAX_SLOTS_PER_SIDE));
  26807. +
  26808. +#define VCHIQ_SLOT_MASK (VCHIQ_SLOT_SIZE - 1)
  26809. +#define VCHIQ_SLOT_QUEUE_MASK (VCHIQ_MAX_SLOTS_PER_SIDE - 1)
  26810. +#define VCHIQ_SLOT_ZERO_SLOTS ((sizeof(VCHIQ_SLOT_ZERO_T) + \
  26811. + VCHIQ_SLOT_SIZE - 1) / VCHIQ_SLOT_SIZE)
  26812. +
  26813. +#define VCHIQ_MSG_PADDING 0 /* - */
  26814. +#define VCHIQ_MSG_CONNECT 1 /* - */
  26815. +#define VCHIQ_MSG_OPEN 2 /* + (srcport, -), fourcc, client_id */
  26816. +#define VCHIQ_MSG_OPENACK 3 /* + (srcport, dstport) */
  26817. +#define VCHIQ_MSG_CLOSE 4 /* + (srcport, dstport) */
  26818. +#define VCHIQ_MSG_DATA 5 /* + (srcport, dstport) */
  26819. +#define VCHIQ_MSG_BULK_RX 6 /* + (srcport, dstport), data, size */
  26820. +#define VCHIQ_MSG_BULK_TX 7 /* + (srcport, dstport), data, size */
  26821. +#define VCHIQ_MSG_BULK_RX_DONE 8 /* + (srcport, dstport), actual */
  26822. +#define VCHIQ_MSG_BULK_TX_DONE 9 /* + (srcport, dstport), actual */
  26823. +#define VCHIQ_MSG_PAUSE 10 /* - */
  26824. +#define VCHIQ_MSG_RESUME 11 /* - */
  26825. +#define VCHIQ_MSG_REMOTE_USE 12 /* - */
  26826. +#define VCHIQ_MSG_REMOTE_RELEASE 13 /* - */
  26827. +#define VCHIQ_MSG_REMOTE_USE_ACTIVE 14 /* - */
  26828. +
  26829. +#define VCHIQ_PORT_MAX (VCHIQ_MAX_SERVICES - 1)
  26830. +#define VCHIQ_PORT_FREE 0x1000
  26831. +#define VCHIQ_PORT_IS_VALID(port) (port < VCHIQ_PORT_FREE)
  26832. +#define VCHIQ_MAKE_MSG(type, srcport, dstport) \
  26833. + ((type<<24) | (srcport<<12) | (dstport<<0))
  26834. +#define VCHIQ_MSG_TYPE(msgid) ((unsigned int)msgid >> 24)
  26835. +#define VCHIQ_MSG_SRCPORT(msgid) \
  26836. + (unsigned short)(((unsigned int)msgid >> 12) & 0xfff)
  26837. +#define VCHIQ_MSG_DSTPORT(msgid) \
  26838. + ((unsigned short)msgid & 0xfff)
  26839. +
  26840. +#define VCHIQ_FOURCC_AS_4CHARS(fourcc) \
  26841. + ((fourcc) >> 24) & 0xff, \
  26842. + ((fourcc) >> 16) & 0xff, \
  26843. + ((fourcc) >> 8) & 0xff, \
  26844. + (fourcc) & 0xff
  26845. +
  26846. +/* Ensure the fields are wide enough */
  26847. +vchiq_static_assert(VCHIQ_MSG_SRCPORT(VCHIQ_MAKE_MSG(0, 0, VCHIQ_PORT_MAX))
  26848. + == 0);
  26849. +vchiq_static_assert(VCHIQ_MSG_TYPE(VCHIQ_MAKE_MSG(0, VCHIQ_PORT_MAX, 0)) == 0);
  26850. +vchiq_static_assert((unsigned int)VCHIQ_PORT_MAX <
  26851. + (unsigned int)VCHIQ_PORT_FREE);
  26852. +
  26853. +#define VCHIQ_MSGID_PADDING VCHIQ_MAKE_MSG(VCHIQ_MSG_PADDING, 0, 0)
  26854. +#define VCHIQ_MSGID_CLAIMED 0x40000000
  26855. +
  26856. +#define VCHIQ_FOURCC_INVALID 0x00000000
  26857. +#define VCHIQ_FOURCC_IS_LEGAL(fourcc) (fourcc != VCHIQ_FOURCC_INVALID)
  26858. +
  26859. +#define VCHIQ_BULK_ACTUAL_ABORTED -1
  26860. +
  26861. +typedef uint32_t BITSET_T;
  26862. +
  26863. +vchiq_static_assert((sizeof(BITSET_T) * 8) == 32);
  26864. +
  26865. +#define BITSET_SIZE(b) ((b + 31) >> 5)
  26866. +#define BITSET_WORD(b) (b >> 5)
  26867. +#define BITSET_BIT(b) (1 << (b & 31))
  26868. +#define BITSET_ZERO(bs) memset(bs, 0, sizeof(bs))
  26869. +#define BITSET_IS_SET(bs, b) (bs[BITSET_WORD(b)] & BITSET_BIT(b))
  26870. +#define BITSET_SET(bs, b) (bs[BITSET_WORD(b)] |= BITSET_BIT(b))
  26871. +#define BITSET_CLR(bs, b) (bs[BITSET_WORD(b)] &= ~BITSET_BIT(b))
  26872. +
  26873. +#if VCHIQ_ENABLE_STATS
  26874. +#define VCHIQ_STATS_INC(state, stat) (state->stats. stat++)
  26875. +#define VCHIQ_SERVICE_STATS_INC(service, stat) (service->stats. stat++)
  26876. +#define VCHIQ_SERVICE_STATS_ADD(service, stat, addend) \
  26877. + (service->stats. stat += addend)
  26878. +#else
  26879. +#define VCHIQ_STATS_INC(state, stat) ((void)0)
  26880. +#define VCHIQ_SERVICE_STATS_INC(service, stat) ((void)0)
  26881. +#define VCHIQ_SERVICE_STATS_ADD(service, stat, addend) ((void)0)
  26882. +#endif
  26883. +
  26884. +enum {
  26885. + DEBUG_ENTRIES,
  26886. +#if VCHIQ_ENABLE_DEBUG
  26887. + DEBUG_SLOT_HANDLER_COUNT,
  26888. + DEBUG_SLOT_HANDLER_LINE,
  26889. + DEBUG_PARSE_LINE,
  26890. + DEBUG_PARSE_HEADER,
  26891. + DEBUG_PARSE_MSGID,
  26892. + DEBUG_AWAIT_COMPLETION_LINE,
  26893. + DEBUG_DEQUEUE_MESSAGE_LINE,
  26894. + DEBUG_SERVICE_CALLBACK_LINE,
  26895. + DEBUG_MSG_QUEUE_FULL_COUNT,
  26896. + DEBUG_COMPLETION_QUEUE_FULL_COUNT,
  26897. +#endif
  26898. + DEBUG_MAX
  26899. +};
  26900. +
  26901. +#if VCHIQ_ENABLE_DEBUG
  26902. +
  26903. +#define DEBUG_INITIALISE(local) int *debug_ptr = (local)->debug;
  26904. +#define DEBUG_TRACE(d) \
  26905. + do { debug_ptr[DEBUG_ ## d] = __LINE__; dsb(); } while (0)
  26906. +#define DEBUG_VALUE(d, v) \
  26907. + do { debug_ptr[DEBUG_ ## d] = (v); dsb(); } while (0)
  26908. +#define DEBUG_COUNT(d) \
  26909. + do { debug_ptr[DEBUG_ ## d]++; dsb(); } while (0)
  26910. +
  26911. +#else /* VCHIQ_ENABLE_DEBUG */
  26912. +
  26913. +#define DEBUG_INITIALISE(local)
  26914. +#define DEBUG_TRACE(d)
  26915. +#define DEBUG_VALUE(d, v)
  26916. +#define DEBUG_COUNT(d)
  26917. +
  26918. +#endif /* VCHIQ_ENABLE_DEBUG */
  26919. +
  26920. +typedef enum {
  26921. + VCHIQ_CONNSTATE_DISCONNECTED,
  26922. + VCHIQ_CONNSTATE_CONNECTING,
  26923. + VCHIQ_CONNSTATE_CONNECTED,
  26924. + VCHIQ_CONNSTATE_PAUSING,
  26925. + VCHIQ_CONNSTATE_PAUSE_SENT,
  26926. + VCHIQ_CONNSTATE_PAUSED,
  26927. + VCHIQ_CONNSTATE_RESUMING,
  26928. + VCHIQ_CONNSTATE_PAUSE_TIMEOUT,
  26929. + VCHIQ_CONNSTATE_RESUME_TIMEOUT
  26930. +} VCHIQ_CONNSTATE_T;
  26931. +
  26932. +enum {
  26933. + VCHIQ_SRVSTATE_FREE,
  26934. + VCHIQ_SRVSTATE_HIDDEN,
  26935. + VCHIQ_SRVSTATE_LISTENING,
  26936. + VCHIQ_SRVSTATE_OPENING,
  26937. + VCHIQ_SRVSTATE_OPEN,
  26938. + VCHIQ_SRVSTATE_OPENSYNC,
  26939. + VCHIQ_SRVSTATE_CLOSESENT,
  26940. + VCHIQ_SRVSTATE_CLOSERECVD,
  26941. + VCHIQ_SRVSTATE_CLOSEWAIT,
  26942. + VCHIQ_SRVSTATE_CLOSED
  26943. +};
  26944. +
  26945. +enum {
  26946. + VCHIQ_POLL_TERMINATE,
  26947. + VCHIQ_POLL_REMOVE,
  26948. + VCHIQ_POLL_TXNOTIFY,
  26949. + VCHIQ_POLL_RXNOTIFY,
  26950. + VCHIQ_POLL_COUNT
  26951. +};
  26952. +
  26953. +typedef enum {
  26954. + VCHIQ_BULK_TRANSMIT,
  26955. + VCHIQ_BULK_RECEIVE
  26956. +} VCHIQ_BULK_DIR_T;
  26957. +
  26958. +typedef void (*VCHIQ_USERDATA_TERM_T)(void *userdata);
  26959. +
  26960. +typedef struct vchiq_bulk_struct {
  26961. + short mode;
  26962. + short dir;
  26963. + void *userdata;
  26964. + VCHI_MEM_HANDLE_T handle;
  26965. + void *data;
  26966. + int size;
  26967. + void *remote_data;
  26968. + int remote_size;
  26969. + int actual;
  26970. +} VCHIQ_BULK_T;
  26971. +
  26972. +typedef struct vchiq_bulk_queue_struct {
  26973. + int local_insert; /* Where to insert the next local bulk */
  26974. + int remote_insert; /* Where to insert the next remote bulk (master) */
  26975. + int process; /* Bulk to transfer next */
  26976. + int remote_notify; /* Bulk to notify the remote client of next (mstr) */
  26977. + int remove; /* Bulk to notify the local client of, and remove,
  26978. + ** next */
  26979. + VCHIQ_BULK_T bulks[VCHIQ_NUM_SERVICE_BULKS];
  26980. +} VCHIQ_BULK_QUEUE_T;
  26981. +
  26982. +typedef struct remote_event_struct {
  26983. + int armed;
  26984. + int fired;
  26985. + struct semaphore *event;
  26986. +} REMOTE_EVENT_T;
  26987. +
  26988. +typedef struct opaque_platform_state_t *VCHIQ_PLATFORM_STATE_T;
  26989. +
  26990. +typedef struct vchiq_state_struct VCHIQ_STATE_T;
  26991. +
  26992. +typedef struct vchiq_slot_struct {
  26993. + char data[VCHIQ_SLOT_SIZE];
  26994. +} VCHIQ_SLOT_T;
  26995. +
  26996. +typedef struct vchiq_slot_info_struct {
  26997. + /* Use two counters rather than one to avoid the need for a mutex. */
  26998. + short use_count;
  26999. + short release_count;
  27000. +} VCHIQ_SLOT_INFO_T;
  27001. +
  27002. +typedef struct vchiq_service_struct {
  27003. + VCHIQ_SERVICE_BASE_T base;
  27004. + VCHIQ_SERVICE_HANDLE_T handle;
  27005. + unsigned int ref_count;
  27006. + int srvstate;
  27007. + VCHIQ_USERDATA_TERM_T userdata_term;
  27008. + unsigned int localport;
  27009. + unsigned int remoteport;
  27010. + int public_fourcc;
  27011. + int client_id;
  27012. + char auto_close;
  27013. + char sync;
  27014. + char closing;
  27015. + atomic_t poll_flags;
  27016. + short version;
  27017. + short version_min;
  27018. + short peer_version;
  27019. +
  27020. + VCHIQ_STATE_T *state;
  27021. + VCHIQ_INSTANCE_T instance;
  27022. +
  27023. + int service_use_count;
  27024. +
  27025. + VCHIQ_BULK_QUEUE_T bulk_tx;
  27026. + VCHIQ_BULK_QUEUE_T bulk_rx;
  27027. +
  27028. + struct semaphore remove_event;
  27029. + struct semaphore bulk_remove_event;
  27030. + struct mutex bulk_mutex;
  27031. +
  27032. + struct service_stats_struct {
  27033. + int quota_stalls;
  27034. + int slot_stalls;
  27035. + int bulk_stalls;
  27036. + int error_count;
  27037. + int ctrl_tx_count;
  27038. + int ctrl_rx_count;
  27039. + int bulk_tx_count;
  27040. + int bulk_rx_count;
  27041. + int bulk_aborted_count;
  27042. + uint64_t ctrl_tx_bytes;
  27043. + uint64_t ctrl_rx_bytes;
  27044. + uint64_t bulk_tx_bytes;
  27045. + uint64_t bulk_rx_bytes;
  27046. + } stats;
  27047. +} VCHIQ_SERVICE_T;
  27048. +
  27049. +/* The quota information is outside VCHIQ_SERVICE_T so that it can be
  27050. + statically allocated, since for accounting reasons a service's slot
  27051. + usage is carried over between users of the same port number.
  27052. + */
  27053. +typedef struct vchiq_service_quota_struct {
  27054. + unsigned short slot_quota;
  27055. + unsigned short slot_use_count;
  27056. + unsigned short message_quota;
  27057. + unsigned short message_use_count;
  27058. + struct semaphore quota_event;
  27059. + int previous_tx_index;
  27060. +} VCHIQ_SERVICE_QUOTA_T;
  27061. +
  27062. +typedef struct vchiq_shared_state_struct {
  27063. +
  27064. + /* A non-zero value here indicates that the content is valid. */
  27065. + int initialised;
  27066. +
  27067. + /* The first and last (inclusive) slots allocated to the owner. */
  27068. + int slot_first;
  27069. + int slot_last;
  27070. +
  27071. + /* The slot allocated to synchronous messages from the owner. */
  27072. + int slot_sync;
  27073. +
  27074. + /* Signalling this event indicates that owner's slot handler thread
  27075. + ** should run. */
  27076. + REMOTE_EVENT_T trigger;
  27077. +
  27078. + /* Indicates the byte position within the stream where the next message
  27079. + ** will be written. The least significant bits are an index into the
  27080. + ** slot. The next bits are the index of the slot in slot_queue. */
  27081. + int tx_pos;
  27082. +
  27083. + /* This event should be signalled when a slot is recycled. */
  27084. + REMOTE_EVENT_T recycle;
  27085. +
  27086. + /* The slot_queue index where the next recycled slot will be written. */
  27087. + int slot_queue_recycle;
  27088. +
  27089. + /* This event should be signalled when a synchronous message is sent. */
  27090. + REMOTE_EVENT_T sync_trigger;
  27091. +
  27092. + /* This event should be signalled when a synchronous message has been
  27093. + ** released. */
  27094. + REMOTE_EVENT_T sync_release;
  27095. +
  27096. + /* A circular buffer of slot indexes. */
  27097. + int slot_queue[VCHIQ_MAX_SLOTS_PER_SIDE];
  27098. +
  27099. + /* Debugging state */
  27100. + int debug[DEBUG_MAX];
  27101. +} VCHIQ_SHARED_STATE_T;
  27102. +
  27103. +typedef struct vchiq_slot_zero_struct {
  27104. + int magic;
  27105. + short version;
  27106. + short version_min;
  27107. + int slot_zero_size;
  27108. + int slot_size;
  27109. + int max_slots;
  27110. + int max_slots_per_side;
  27111. + int platform_data[2];
  27112. + VCHIQ_SHARED_STATE_T master;
  27113. + VCHIQ_SHARED_STATE_T slave;
  27114. + VCHIQ_SLOT_INFO_T slots[VCHIQ_MAX_SLOTS];
  27115. +} VCHIQ_SLOT_ZERO_T;
  27116. +
  27117. +struct vchiq_state_struct {
  27118. + int id;
  27119. + int initialised;
  27120. + VCHIQ_CONNSTATE_T conn_state;
  27121. + int is_master;
  27122. +
  27123. + VCHIQ_SHARED_STATE_T *local;
  27124. + VCHIQ_SHARED_STATE_T *remote;
  27125. + VCHIQ_SLOT_T *slot_data;
  27126. +
  27127. + unsigned short default_slot_quota;
  27128. + unsigned short default_message_quota;
  27129. +
  27130. + /* Event indicating connect message received */
  27131. + struct semaphore connect;
  27132. +
  27133. + /* Mutex protecting services */
  27134. + struct mutex mutex;
  27135. + VCHIQ_INSTANCE_T *instance;
  27136. +
  27137. + /* Processes incoming messages */
  27138. + struct task_struct *slot_handler_thread;
  27139. +
  27140. + /* Processes recycled slots */
  27141. + struct task_struct *recycle_thread;
  27142. +
  27143. + /* Processes synchronous messages */
  27144. + struct task_struct *sync_thread;
  27145. +
  27146. + /* Local implementation of the trigger remote event */
  27147. + struct semaphore trigger_event;
  27148. +
  27149. + /* Local implementation of the recycle remote event */
  27150. + struct semaphore recycle_event;
  27151. +
  27152. + /* Local implementation of the sync trigger remote event */
  27153. + struct semaphore sync_trigger_event;
  27154. +
  27155. + /* Local implementation of the sync release remote event */
  27156. + struct semaphore sync_release_event;
  27157. +
  27158. + char *tx_data;
  27159. + char *rx_data;
  27160. + VCHIQ_SLOT_INFO_T *rx_info;
  27161. +
  27162. + struct mutex slot_mutex;
  27163. +
  27164. + struct mutex recycle_mutex;
  27165. +
  27166. + struct mutex sync_mutex;
  27167. +
  27168. + struct mutex bulk_transfer_mutex;
  27169. +
  27170. + /* Indicates the byte position within the stream from where the next
  27171. + ** message will be read. The least significant bits are an index into
  27172. + ** the slot.The next bits are the index of the slot in
  27173. + ** remote->slot_queue. */
  27174. + int rx_pos;
  27175. +
  27176. + /* A cached copy of local->tx_pos. Only write to local->tx_pos, and read
  27177. + from remote->tx_pos. */
  27178. + int local_tx_pos;
  27179. +
  27180. + /* The slot_queue index of the slot to become available next. */
  27181. + int slot_queue_available;
  27182. +
  27183. + /* A flag to indicate if any poll has been requested */
  27184. + int poll_needed;
  27185. +
  27186. + /* Ths index of the previous slot used for data messages. */
  27187. + int previous_data_index;
  27188. +
  27189. + /* The number of slots occupied by data messages. */
  27190. + unsigned short data_use_count;
  27191. +
  27192. + /* The maximum number of slots to be occupied by data messages. */
  27193. + unsigned short data_quota;
  27194. +
  27195. + /* An array of bit sets indicating which services must be polled. */
  27196. + atomic_t poll_services[BITSET_SIZE(VCHIQ_MAX_SERVICES)];
  27197. +
  27198. + /* The number of the first unused service */
  27199. + int unused_service;
  27200. +
  27201. + /* Signalled when a free slot becomes available. */
  27202. + struct semaphore slot_available_event;
  27203. +
  27204. + struct semaphore slot_remove_event;
  27205. +
  27206. + /* Signalled when a free data slot becomes available. */
  27207. + struct semaphore data_quota_event;
  27208. +
  27209. + /* Incremented when there are bulk transfers which cannot be processed
  27210. + * whilst paused and must be processed on resume */
  27211. + int deferred_bulks;
  27212. +
  27213. + struct state_stats_struct {
  27214. + int slot_stalls;
  27215. + int data_stalls;
  27216. + int ctrl_tx_count;
  27217. + int ctrl_rx_count;
  27218. + int error_count;
  27219. + } stats;
  27220. +
  27221. + VCHIQ_SERVICE_T * services[VCHIQ_MAX_SERVICES];
  27222. + VCHIQ_SERVICE_QUOTA_T service_quotas[VCHIQ_MAX_SERVICES];
  27223. + VCHIQ_SLOT_INFO_T slot_info[VCHIQ_MAX_SLOTS];
  27224. +
  27225. + VCHIQ_PLATFORM_STATE_T platform_state;
  27226. +};
  27227. +
  27228. +struct bulk_waiter {
  27229. + VCHIQ_BULK_T *bulk;
  27230. + struct semaphore event;
  27231. + int actual;
  27232. +};
  27233. +
  27234. +extern spinlock_t bulk_waiter_spinlock;
  27235. +
  27236. +extern int vchiq_core_log_level;
  27237. +extern int vchiq_core_msg_log_level;
  27238. +extern int vchiq_sync_log_level;
  27239. +
  27240. +extern VCHIQ_STATE_T *vchiq_states[VCHIQ_MAX_STATES];
  27241. +
  27242. +extern const char *
  27243. +get_conn_state_name(VCHIQ_CONNSTATE_T conn_state);
  27244. +
  27245. +extern VCHIQ_SLOT_ZERO_T *
  27246. +vchiq_init_slots(void *mem_base, int mem_size);
  27247. +
  27248. +extern VCHIQ_STATUS_T
  27249. +vchiq_init_state(VCHIQ_STATE_T *state, VCHIQ_SLOT_ZERO_T *slot_zero,
  27250. + int is_master);
  27251. +
  27252. +extern VCHIQ_STATUS_T
  27253. +vchiq_connect_internal(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance);
  27254. +
  27255. +extern VCHIQ_SERVICE_T *
  27256. +vchiq_add_service_internal(VCHIQ_STATE_T *state,
  27257. + const VCHIQ_SERVICE_PARAMS_T *params, int srvstate,
  27258. + VCHIQ_INSTANCE_T instance, VCHIQ_USERDATA_TERM_T userdata_term);
  27259. +
  27260. +extern VCHIQ_STATUS_T
  27261. +vchiq_open_service_internal(VCHIQ_SERVICE_T *service, int client_id);
  27262. +
  27263. +extern VCHIQ_STATUS_T
  27264. +vchiq_close_service_internal(VCHIQ_SERVICE_T *service, int close_recvd);
  27265. +
  27266. +extern void
  27267. +vchiq_terminate_service_internal(VCHIQ_SERVICE_T *service);
  27268. +
  27269. +extern void
  27270. +vchiq_free_service_internal(VCHIQ_SERVICE_T *service);
  27271. +
  27272. +extern VCHIQ_STATUS_T
  27273. +vchiq_shutdown_internal(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance);
  27274. +
  27275. +extern VCHIQ_STATUS_T
  27276. +vchiq_pause_internal(VCHIQ_STATE_T *state);
  27277. +
  27278. +extern VCHIQ_STATUS_T
  27279. +vchiq_resume_internal(VCHIQ_STATE_T *state);
  27280. +
  27281. +extern void
  27282. +remote_event_pollall(VCHIQ_STATE_T *state);
  27283. +
  27284. +extern VCHIQ_STATUS_T
  27285. +vchiq_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle,
  27286. + VCHI_MEM_HANDLE_T memhandle, void *offset, int size, void *userdata,
  27287. + VCHIQ_BULK_MODE_T mode, VCHIQ_BULK_DIR_T dir);
  27288. +
  27289. +extern void
  27290. +vchiq_dump_state(void *dump_context, VCHIQ_STATE_T *state);
  27291. +
  27292. +extern void
  27293. +vchiq_dump_service_state(void *dump_context, VCHIQ_SERVICE_T *service);
  27294. +
  27295. +extern void
  27296. +vchiq_loud_error_header(void);
  27297. +
  27298. +extern void
  27299. +vchiq_loud_error_footer(void);
  27300. +
  27301. +extern void
  27302. +request_poll(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service, int poll_type);
  27303. +
  27304. +static inline VCHIQ_SERVICE_T *
  27305. +handle_to_service(VCHIQ_SERVICE_HANDLE_T handle)
  27306. +{
  27307. + VCHIQ_STATE_T *state = vchiq_states[(handle / VCHIQ_MAX_SERVICES) &
  27308. + (VCHIQ_MAX_STATES - 1)];
  27309. + if (!state)
  27310. + return NULL;
  27311. +
  27312. + return state->services[handle & (VCHIQ_MAX_SERVICES - 1)];
  27313. +}
  27314. +
  27315. +extern VCHIQ_SERVICE_T *
  27316. +find_service_by_handle(VCHIQ_SERVICE_HANDLE_T handle);
  27317. +
  27318. +extern VCHIQ_SERVICE_T *
  27319. +find_service_by_port(VCHIQ_STATE_T *state, int localport);
  27320. +
  27321. +extern VCHIQ_SERVICE_T *
  27322. +find_service_for_instance(VCHIQ_INSTANCE_T instance,
  27323. + VCHIQ_SERVICE_HANDLE_T handle);
  27324. +
  27325. +extern VCHIQ_SERVICE_T *
  27326. +next_service_by_instance(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance,
  27327. + int *pidx);
  27328. +
  27329. +extern void
  27330. +lock_service(VCHIQ_SERVICE_T *service);
  27331. +
  27332. +extern void
  27333. +unlock_service(VCHIQ_SERVICE_T *service);
  27334. +
  27335. +/* The following functions are called from vchiq_core, and external
  27336. +** implementations must be provided. */
  27337. +
  27338. +extern VCHIQ_STATUS_T
  27339. +vchiq_prepare_bulk_data(VCHIQ_BULK_T *bulk,
  27340. + VCHI_MEM_HANDLE_T memhandle, void *offset, int size, int dir);
  27341. +
  27342. +extern void
  27343. +vchiq_transfer_bulk(VCHIQ_BULK_T *bulk);
  27344. +
  27345. +extern void
  27346. +vchiq_complete_bulk(VCHIQ_BULK_T *bulk);
  27347. +
  27348. +extern VCHIQ_STATUS_T
  27349. +vchiq_copy_from_user(void *dst, const void *src, int size);
  27350. +
  27351. +extern void
  27352. +remote_event_signal(REMOTE_EVENT_T *event);
  27353. +
  27354. +void
  27355. +vchiq_platform_check_suspend(VCHIQ_STATE_T *state);
  27356. +
  27357. +extern void
  27358. +vchiq_platform_paused(VCHIQ_STATE_T *state);
  27359. +
  27360. +extern VCHIQ_STATUS_T
  27361. +vchiq_platform_resume(VCHIQ_STATE_T *state);
  27362. +
  27363. +extern void
  27364. +vchiq_platform_resumed(VCHIQ_STATE_T *state);
  27365. +
  27366. +extern void
  27367. +vchiq_dump(void *dump_context, const char *str, int len);
  27368. +
  27369. +extern void
  27370. +vchiq_dump_platform_state(void *dump_context);
  27371. +
  27372. +extern void
  27373. +vchiq_dump_platform_instances(void *dump_context);
  27374. +
  27375. +extern void
  27376. +vchiq_dump_platform_service_state(void *dump_context,
  27377. + VCHIQ_SERVICE_T *service);
  27378. +
  27379. +extern VCHIQ_STATUS_T
  27380. +vchiq_use_service_internal(VCHIQ_SERVICE_T *service);
  27381. +
  27382. +extern VCHIQ_STATUS_T
  27383. +vchiq_release_service_internal(VCHIQ_SERVICE_T *service);
  27384. +
  27385. +extern void
  27386. +vchiq_on_remote_use(VCHIQ_STATE_T *state);
  27387. +
  27388. +extern void
  27389. +vchiq_on_remote_release(VCHIQ_STATE_T *state);
  27390. +
  27391. +extern VCHIQ_STATUS_T
  27392. +vchiq_platform_init_state(VCHIQ_STATE_T *state);
  27393. +
  27394. +extern VCHIQ_STATUS_T
  27395. +vchiq_check_service(VCHIQ_SERVICE_T *service);
  27396. +
  27397. +extern void
  27398. +vchiq_on_remote_use_active(VCHIQ_STATE_T *state);
  27399. +
  27400. +extern VCHIQ_STATUS_T
  27401. +vchiq_send_remote_use(VCHIQ_STATE_T *state);
  27402. +
  27403. +extern VCHIQ_STATUS_T
  27404. +vchiq_send_remote_release(VCHIQ_STATE_T *state);
  27405. +
  27406. +extern VCHIQ_STATUS_T
  27407. +vchiq_send_remote_use_active(VCHIQ_STATE_T *state);
  27408. +
  27409. +extern void
  27410. +vchiq_platform_conn_state_changed(VCHIQ_STATE_T *state,
  27411. + VCHIQ_CONNSTATE_T oldstate, VCHIQ_CONNSTATE_T newstate);
  27412. +
  27413. +extern void
  27414. +vchiq_platform_handle_timeout(VCHIQ_STATE_T *state);
  27415. +
  27416. +extern void
  27417. +vchiq_set_conn_state(VCHIQ_STATE_T *state, VCHIQ_CONNSTATE_T newstate);
  27418. +
  27419. +
  27420. +extern void
  27421. +vchiq_log_dump_mem(const char *label, uint32_t addr, const void *voidMem,
  27422. + size_t numBytes);
  27423. +
  27424. +#endif
  27425. diff -Nur linux-3.13.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_genversion linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_genversion
  27426. --- linux-3.13.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_genversion 1970-01-01 01:00:00.000000000 +0100
  27427. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_genversion 2014-04-24 15:36:51.710754091 +0200
  27428. @@ -0,0 +1,87 @@
  27429. +#!/usr/bin/perl -w
  27430. +
  27431. +use strict;
  27432. +
  27433. +#
  27434. +# Generate a version from available information
  27435. +#
  27436. +
  27437. +my $prefix = shift @ARGV;
  27438. +my $root = shift @ARGV;
  27439. +
  27440. +
  27441. +if ( not defined $root ) {
  27442. + die "usage: $0 prefix root-dir\n";
  27443. +}
  27444. +
  27445. +if ( ! -d $root ) {
  27446. + die "root directory $root not found\n";
  27447. +}
  27448. +
  27449. +my $version = "unknown";
  27450. +my $tainted = "";
  27451. +
  27452. +if ( -d "$root/.git" ) {
  27453. + # attempt to work out git version. only do so
  27454. + # on a linux build host, as cygwin builds are
  27455. + # already slow enough
  27456. +
  27457. + if ( -f "/usr/bin/git" || -f "/usr/local/bin/git" ) {
  27458. + if (not open(F, "git --git-dir $root/.git rev-parse --verify HEAD|")) {
  27459. + $version = "no git version";
  27460. + }
  27461. + else {
  27462. + $version = <F>;
  27463. + $version =~ s/[ \r\n]*$//; # chomp may not be enough (cygwin).
  27464. + $version =~ s/^[ \r\n]*//; # chomp may not be enough (cygwin).
  27465. + }
  27466. +
  27467. + if (open(G, "git --git-dir $root/.git status --porcelain|")) {
  27468. + $tainted = <G>;
  27469. + $tainted =~ s/[ \r\n]*$//; # chomp may not be enough (cygwin).
  27470. + $tainted =~ s/^[ \r\n]*//; # chomp may not be enough (cygwin).
  27471. + if (length $tainted) {
  27472. + $version = join ' ', $version, "(tainted)";
  27473. + }
  27474. + else {
  27475. + $version = join ' ', $version, "(clean)";
  27476. + }
  27477. + }
  27478. + }
  27479. +}
  27480. +
  27481. +my $hostname = `hostname`;
  27482. +$hostname =~ s/[ \r\n]*$//; # chomp may not be enough (cygwin).
  27483. +$hostname =~ s/^[ \r\n]*//; # chomp may not be enough (cygwin).
  27484. +
  27485. +
  27486. +print STDERR "Version $version\n";
  27487. +print <<EOF;
  27488. +#include "${prefix}_build_info.h"
  27489. +#include <linux/broadcom/vc_debug_sym.h>
  27490. +
  27491. +VC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_hostname, "$hostname" );
  27492. +VC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_version, "$version" );
  27493. +VC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_time, __TIME__ );
  27494. +VC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_date, __DATE__ );
  27495. +
  27496. +const char *vchiq_get_build_hostname( void )
  27497. +{
  27498. + return vchiq_build_hostname;
  27499. +}
  27500. +
  27501. +const char *vchiq_get_build_version( void )
  27502. +{
  27503. + return vchiq_build_version;
  27504. +}
  27505. +
  27506. +const char *vchiq_get_build_date( void )
  27507. +{
  27508. + return vchiq_build_date;
  27509. +}
  27510. +
  27511. +const char *vchiq_get_build_time( void )
  27512. +{
  27513. + return vchiq_build_time;
  27514. +}
  27515. +EOF
  27516. diff -Nur linux-3.13.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq.h
  27517. --- linux-3.13.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq.h 1970-01-01 01:00:00.000000000 +0100
  27518. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq.h 2014-04-24 15:36:51.710754091 +0200
  27519. @@ -0,0 +1,40 @@
  27520. +/**
  27521. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  27522. + *
  27523. + * Redistribution and use in source and binary forms, with or without
  27524. + * modification, are permitted provided that the following conditions
  27525. + * are met:
  27526. + * 1. Redistributions of source code must retain the above copyright
  27527. + * notice, this list of conditions, and the following disclaimer,
  27528. + * without modification.
  27529. + * 2. Redistributions in binary form must reproduce the above copyright
  27530. + * notice, this list of conditions and the following disclaimer in the
  27531. + * documentation and/or other materials provided with the distribution.
  27532. + * 3. The names of the above-listed copyright holders may not be used
  27533. + * to endorse or promote products derived from this software without
  27534. + * specific prior written permission.
  27535. + *
  27536. + * ALTERNATIVELY, this software may be distributed under the terms of the
  27537. + * GNU General Public License ("GPL") version 2, as published by the Free
  27538. + * Software Foundation.
  27539. + *
  27540. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  27541. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  27542. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  27543. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  27544. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  27545. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  27546. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  27547. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  27548. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  27549. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27550. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27551. + */
  27552. +
  27553. +#ifndef VCHIQ_VCHIQ_H
  27554. +#define VCHIQ_VCHIQ_H
  27555. +
  27556. +#include "vchiq_if.h"
  27557. +#include "vchiq_util.h"
  27558. +
  27559. +#endif
  27560. diff -Nur linux-3.13.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_if.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_if.h
  27561. --- linux-3.13.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_if.h 1970-01-01 01:00:00.000000000 +0100
  27562. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_if.h 2014-04-24 15:35:02.893551516 +0200
  27563. @@ -0,0 +1,188 @@
  27564. +/**
  27565. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  27566. + *
  27567. + * Redistribution and use in source and binary forms, with or without
  27568. + * modification, are permitted provided that the following conditions
  27569. + * are met:
  27570. + * 1. Redistributions of source code must retain the above copyright
  27571. + * notice, this list of conditions, and the following disclaimer,
  27572. + * without modification.
  27573. + * 2. Redistributions in binary form must reproduce the above copyright
  27574. + * notice, this list of conditions and the following disclaimer in the
  27575. + * documentation and/or other materials provided with the distribution.
  27576. + * 3. The names of the above-listed copyright holders may not be used
  27577. + * to endorse or promote products derived from this software without
  27578. + * specific prior written permission.
  27579. + *
  27580. + * ALTERNATIVELY, this software may be distributed under the terms of the
  27581. + * GNU General Public License ("GPL") version 2, as published by the Free
  27582. + * Software Foundation.
  27583. + *
  27584. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  27585. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  27586. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  27587. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  27588. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  27589. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  27590. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  27591. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  27592. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  27593. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27594. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27595. + */
  27596. +
  27597. +#ifndef VCHIQ_IF_H
  27598. +#define VCHIQ_IF_H
  27599. +
  27600. +#include "interface/vchi/vchi_mh.h"
  27601. +
  27602. +#define VCHIQ_SERVICE_HANDLE_INVALID 0
  27603. +
  27604. +#define VCHIQ_SLOT_SIZE 4096
  27605. +#define VCHIQ_MAX_MSG_SIZE (VCHIQ_SLOT_SIZE - sizeof(VCHIQ_HEADER_T))
  27606. +#define VCHIQ_CHANNEL_SIZE VCHIQ_MAX_MSG_SIZE /* For backwards compatibility */
  27607. +
  27608. +#define VCHIQ_MAKE_FOURCC(x0, x1, x2, x3) \
  27609. + (((x0) << 24) | ((x1) << 16) | ((x2) << 8) | (x3))
  27610. +#define VCHIQ_GET_SERVICE_USERDATA(service) vchiq_get_service_userdata(service)
  27611. +#define VCHIQ_GET_SERVICE_FOURCC(service) vchiq_get_service_fourcc(service)
  27612. +
  27613. +typedef enum {
  27614. + VCHIQ_SERVICE_OPENED, /* service, -, - */
  27615. + VCHIQ_SERVICE_CLOSED, /* service, -, - */
  27616. + VCHIQ_MESSAGE_AVAILABLE, /* service, header, - */
  27617. + VCHIQ_BULK_TRANSMIT_DONE, /* service, -, bulk_userdata */
  27618. + VCHIQ_BULK_RECEIVE_DONE, /* service, -, bulk_userdata */
  27619. + VCHIQ_BULK_TRANSMIT_ABORTED, /* service, -, bulk_userdata */
  27620. + VCHIQ_BULK_RECEIVE_ABORTED /* service, -, bulk_userdata */
  27621. +} VCHIQ_REASON_T;
  27622. +
  27623. +typedef enum {
  27624. + VCHIQ_ERROR = -1,
  27625. + VCHIQ_SUCCESS = 0,
  27626. + VCHIQ_RETRY = 1
  27627. +} VCHIQ_STATUS_T;
  27628. +
  27629. +typedef enum {
  27630. + VCHIQ_BULK_MODE_CALLBACK,
  27631. + VCHIQ_BULK_MODE_BLOCKING,
  27632. + VCHIQ_BULK_MODE_NOCALLBACK,
  27633. + VCHIQ_BULK_MODE_WAITING /* Reserved for internal use */
  27634. +} VCHIQ_BULK_MODE_T;
  27635. +
  27636. +typedef enum {
  27637. + VCHIQ_SERVICE_OPTION_AUTOCLOSE,
  27638. + VCHIQ_SERVICE_OPTION_SLOT_QUOTA,
  27639. + VCHIQ_SERVICE_OPTION_MESSAGE_QUOTA,
  27640. + VCHIQ_SERVICE_OPTION_SYNCHRONOUS
  27641. +} VCHIQ_SERVICE_OPTION_T;
  27642. +
  27643. +typedef struct vchiq_header_struct {
  27644. + /* The message identifier - opaque to applications. */
  27645. + int msgid;
  27646. +
  27647. + /* Size of message data. */
  27648. + unsigned int size;
  27649. +
  27650. + char data[0]; /* message */
  27651. +} VCHIQ_HEADER_T;
  27652. +
  27653. +typedef struct {
  27654. + const void *data;
  27655. + unsigned int size;
  27656. +} VCHIQ_ELEMENT_T;
  27657. +
  27658. +typedef unsigned int VCHIQ_SERVICE_HANDLE_T;
  27659. +
  27660. +typedef VCHIQ_STATUS_T (*VCHIQ_CALLBACK_T)(VCHIQ_REASON_T, VCHIQ_HEADER_T *,
  27661. + VCHIQ_SERVICE_HANDLE_T, void *);
  27662. +
  27663. +typedef struct vchiq_service_base_struct {
  27664. + int fourcc;
  27665. + VCHIQ_CALLBACK_T callback;
  27666. + void *userdata;
  27667. +} VCHIQ_SERVICE_BASE_T;
  27668. +
  27669. +typedef struct vchiq_service_params_struct {
  27670. + int fourcc;
  27671. + VCHIQ_CALLBACK_T callback;
  27672. + void *userdata;
  27673. + short version; /* Increment for non-trivial changes */
  27674. + short version_min; /* Update for incompatible changes */
  27675. +} VCHIQ_SERVICE_PARAMS_T;
  27676. +
  27677. +typedef struct vchiq_config_struct {
  27678. + unsigned int max_msg_size;
  27679. + unsigned int bulk_threshold; /* The message size above which it
  27680. + is better to use a bulk transfer
  27681. + (<= max_msg_size) */
  27682. + unsigned int max_outstanding_bulks;
  27683. + unsigned int max_services;
  27684. + short version; /* The version of VCHIQ */
  27685. + short version_min; /* The minimum compatible version of VCHIQ */
  27686. +} VCHIQ_CONFIG_T;
  27687. +
  27688. +typedef struct vchiq_instance_struct *VCHIQ_INSTANCE_T;
  27689. +typedef void (*VCHIQ_REMOTE_USE_CALLBACK_T)(void *cb_arg);
  27690. +
  27691. +extern VCHIQ_STATUS_T vchiq_initialise(VCHIQ_INSTANCE_T *pinstance);
  27692. +extern VCHIQ_STATUS_T vchiq_shutdown(VCHIQ_INSTANCE_T instance);
  27693. +extern VCHIQ_STATUS_T vchiq_connect(VCHIQ_INSTANCE_T instance);
  27694. +extern VCHIQ_STATUS_T vchiq_add_service(VCHIQ_INSTANCE_T instance,
  27695. + const VCHIQ_SERVICE_PARAMS_T *params,
  27696. + VCHIQ_SERVICE_HANDLE_T *pservice);
  27697. +extern VCHIQ_STATUS_T vchiq_open_service(VCHIQ_INSTANCE_T instance,
  27698. + const VCHIQ_SERVICE_PARAMS_T *params,
  27699. + VCHIQ_SERVICE_HANDLE_T *pservice);
  27700. +extern VCHIQ_STATUS_T vchiq_close_service(VCHIQ_SERVICE_HANDLE_T service);
  27701. +extern VCHIQ_STATUS_T vchiq_remove_service(VCHIQ_SERVICE_HANDLE_T service);
  27702. +extern VCHIQ_STATUS_T vchiq_use_service(VCHIQ_SERVICE_HANDLE_T service);
  27703. +extern VCHIQ_STATUS_T vchiq_use_service_no_resume(
  27704. + VCHIQ_SERVICE_HANDLE_T service);
  27705. +extern VCHIQ_STATUS_T vchiq_release_service(VCHIQ_SERVICE_HANDLE_T service);
  27706. +
  27707. +extern VCHIQ_STATUS_T vchiq_queue_message(VCHIQ_SERVICE_HANDLE_T service,
  27708. + const VCHIQ_ELEMENT_T *elements, unsigned int count);
  27709. +extern void vchiq_release_message(VCHIQ_SERVICE_HANDLE_T service,
  27710. + VCHIQ_HEADER_T *header);
  27711. +extern VCHIQ_STATUS_T vchiq_queue_bulk_transmit(VCHIQ_SERVICE_HANDLE_T service,
  27712. + const void *data, unsigned int size, void *userdata);
  27713. +extern VCHIQ_STATUS_T vchiq_queue_bulk_receive(VCHIQ_SERVICE_HANDLE_T service,
  27714. + void *data, unsigned int size, void *userdata);
  27715. +extern VCHIQ_STATUS_T vchiq_queue_bulk_transmit_handle(
  27716. + VCHIQ_SERVICE_HANDLE_T service, VCHI_MEM_HANDLE_T handle,
  27717. + const void *offset, unsigned int size, void *userdata);
  27718. +extern VCHIQ_STATUS_T vchiq_queue_bulk_receive_handle(
  27719. + VCHIQ_SERVICE_HANDLE_T service, VCHI_MEM_HANDLE_T handle,
  27720. + void *offset, unsigned int size, void *userdata);
  27721. +extern VCHIQ_STATUS_T vchiq_bulk_transmit(VCHIQ_SERVICE_HANDLE_T service,
  27722. + const void *data, unsigned int size, void *userdata,
  27723. + VCHIQ_BULK_MODE_T mode);
  27724. +extern VCHIQ_STATUS_T vchiq_bulk_receive(VCHIQ_SERVICE_HANDLE_T service,
  27725. + void *data, unsigned int size, void *userdata,
  27726. + VCHIQ_BULK_MODE_T mode);
  27727. +extern VCHIQ_STATUS_T vchiq_bulk_transmit_handle(VCHIQ_SERVICE_HANDLE_T service,
  27728. + VCHI_MEM_HANDLE_T handle, const void *offset, unsigned int size,
  27729. + void *userdata, VCHIQ_BULK_MODE_T mode);
  27730. +extern VCHIQ_STATUS_T vchiq_bulk_receive_handle(VCHIQ_SERVICE_HANDLE_T service,
  27731. + VCHI_MEM_HANDLE_T handle, void *offset, unsigned int size,
  27732. + void *userdata, VCHIQ_BULK_MODE_T mode);
  27733. +extern int vchiq_get_client_id(VCHIQ_SERVICE_HANDLE_T service);
  27734. +extern void *vchiq_get_service_userdata(VCHIQ_SERVICE_HANDLE_T service);
  27735. +extern int vchiq_get_service_fourcc(VCHIQ_SERVICE_HANDLE_T service);
  27736. +extern VCHIQ_STATUS_T vchiq_get_config(VCHIQ_INSTANCE_T instance,
  27737. + int config_size, VCHIQ_CONFIG_T *pconfig);
  27738. +extern VCHIQ_STATUS_T vchiq_set_service_option(VCHIQ_SERVICE_HANDLE_T service,
  27739. + VCHIQ_SERVICE_OPTION_T option, int value);
  27740. +
  27741. +extern VCHIQ_STATUS_T vchiq_remote_use(VCHIQ_INSTANCE_T instance,
  27742. + VCHIQ_REMOTE_USE_CALLBACK_T callback, void *cb_arg);
  27743. +extern VCHIQ_STATUS_T vchiq_remote_release(VCHIQ_INSTANCE_T instance);
  27744. +
  27745. +extern VCHIQ_STATUS_T vchiq_dump_phys_mem(VCHIQ_SERVICE_HANDLE_T service,
  27746. + void *ptr, size_t num_bytes);
  27747. +
  27748. +extern VCHIQ_STATUS_T vchiq_get_peer_version(VCHIQ_SERVICE_HANDLE_T handle,
  27749. + short *peer_version);
  27750. +
  27751. +#endif /* VCHIQ_IF_H */
  27752. diff -Nur linux-3.13.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_ioctl.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_ioctl.h
  27753. --- linux-3.13.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_ioctl.h 1970-01-01 01:00:00.000000000 +0100
  27754. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_ioctl.h 2014-04-24 15:35:02.893551516 +0200
  27755. @@ -0,0 +1,129 @@
  27756. +/**
  27757. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  27758. + *
  27759. + * Redistribution and use in source and binary forms, with or without
  27760. + * modification, are permitted provided that the following conditions
  27761. + * are met:
  27762. + * 1. Redistributions of source code must retain the above copyright
  27763. + * notice, this list of conditions, and the following disclaimer,
  27764. + * without modification.
  27765. + * 2. Redistributions in binary form must reproduce the above copyright
  27766. + * notice, this list of conditions and the following disclaimer in the
  27767. + * documentation and/or other materials provided with the distribution.
  27768. + * 3. The names of the above-listed copyright holders may not be used
  27769. + * to endorse or promote products derived from this software without
  27770. + * specific prior written permission.
  27771. + *
  27772. + * ALTERNATIVELY, this software may be distributed under the terms of the
  27773. + * GNU General Public License ("GPL") version 2, as published by the Free
  27774. + * Software Foundation.
  27775. + *
  27776. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  27777. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  27778. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  27779. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  27780. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  27781. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  27782. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  27783. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  27784. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  27785. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27786. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27787. + */
  27788. +
  27789. +#ifndef VCHIQ_IOCTLS_H
  27790. +#define VCHIQ_IOCTLS_H
  27791. +
  27792. +#include <linux/ioctl.h>
  27793. +#include "vchiq_if.h"
  27794. +
  27795. +#define VCHIQ_IOC_MAGIC 0xc4
  27796. +#define VCHIQ_INVALID_HANDLE (~0)
  27797. +
  27798. +typedef struct {
  27799. + VCHIQ_SERVICE_PARAMS_T params;
  27800. + int is_open;
  27801. + int is_vchi;
  27802. + unsigned int handle; /* OUT */
  27803. +} VCHIQ_CREATE_SERVICE_T;
  27804. +
  27805. +typedef struct {
  27806. + unsigned int handle;
  27807. + unsigned int count;
  27808. + const VCHIQ_ELEMENT_T *elements;
  27809. +} VCHIQ_QUEUE_MESSAGE_T;
  27810. +
  27811. +typedef struct {
  27812. + unsigned int handle;
  27813. + void *data;
  27814. + unsigned int size;
  27815. + void *userdata;
  27816. + VCHIQ_BULK_MODE_T mode;
  27817. +} VCHIQ_QUEUE_BULK_TRANSFER_T;
  27818. +
  27819. +typedef struct {
  27820. + VCHIQ_REASON_T reason;
  27821. + VCHIQ_HEADER_T *header;
  27822. + void *service_userdata;
  27823. + void *bulk_userdata;
  27824. +} VCHIQ_COMPLETION_DATA_T;
  27825. +
  27826. +typedef struct {
  27827. + unsigned int count;
  27828. + VCHIQ_COMPLETION_DATA_T *buf;
  27829. + unsigned int msgbufsize;
  27830. + unsigned int msgbufcount; /* IN/OUT */
  27831. + void **msgbufs;
  27832. +} VCHIQ_AWAIT_COMPLETION_T;
  27833. +
  27834. +typedef struct {
  27835. + unsigned int handle;
  27836. + int blocking;
  27837. + unsigned int bufsize;
  27838. + void *buf;
  27839. +} VCHIQ_DEQUEUE_MESSAGE_T;
  27840. +
  27841. +typedef struct {
  27842. + unsigned int config_size;
  27843. + VCHIQ_CONFIG_T *pconfig;
  27844. +} VCHIQ_GET_CONFIG_T;
  27845. +
  27846. +typedef struct {
  27847. + unsigned int handle;
  27848. + VCHIQ_SERVICE_OPTION_T option;
  27849. + int value;
  27850. +} VCHIQ_SET_SERVICE_OPTION_T;
  27851. +
  27852. +typedef struct {
  27853. + void *virt_addr;
  27854. + size_t num_bytes;
  27855. +} VCHIQ_DUMP_MEM_T;
  27856. +
  27857. +#define VCHIQ_IOC_CONNECT _IO(VCHIQ_IOC_MAGIC, 0)
  27858. +#define VCHIQ_IOC_SHUTDOWN _IO(VCHIQ_IOC_MAGIC, 1)
  27859. +#define VCHIQ_IOC_CREATE_SERVICE \
  27860. + _IOWR(VCHIQ_IOC_MAGIC, 2, VCHIQ_CREATE_SERVICE_T)
  27861. +#define VCHIQ_IOC_REMOVE_SERVICE _IO(VCHIQ_IOC_MAGIC, 3)
  27862. +#define VCHIQ_IOC_QUEUE_MESSAGE \
  27863. + _IOW(VCHIQ_IOC_MAGIC, 4, VCHIQ_QUEUE_MESSAGE_T)
  27864. +#define VCHIQ_IOC_QUEUE_BULK_TRANSMIT \
  27865. + _IOWR(VCHIQ_IOC_MAGIC, 5, VCHIQ_QUEUE_BULK_TRANSFER_T)
  27866. +#define VCHIQ_IOC_QUEUE_BULK_RECEIVE \
  27867. + _IOWR(VCHIQ_IOC_MAGIC, 6, VCHIQ_QUEUE_BULK_TRANSFER_T)
  27868. +#define VCHIQ_IOC_AWAIT_COMPLETION \
  27869. + _IOWR(VCHIQ_IOC_MAGIC, 7, VCHIQ_AWAIT_COMPLETION_T)
  27870. +#define VCHIQ_IOC_DEQUEUE_MESSAGE \
  27871. + _IOWR(VCHIQ_IOC_MAGIC, 8, VCHIQ_DEQUEUE_MESSAGE_T)
  27872. +#define VCHIQ_IOC_GET_CLIENT_ID _IO(VCHIQ_IOC_MAGIC, 9)
  27873. +#define VCHIQ_IOC_GET_CONFIG \
  27874. + _IOWR(VCHIQ_IOC_MAGIC, 10, VCHIQ_GET_CONFIG_T)
  27875. +#define VCHIQ_IOC_CLOSE_SERVICE _IO(VCHIQ_IOC_MAGIC, 11)
  27876. +#define VCHIQ_IOC_USE_SERVICE _IO(VCHIQ_IOC_MAGIC, 12)
  27877. +#define VCHIQ_IOC_RELEASE_SERVICE _IO(VCHIQ_IOC_MAGIC, 13)
  27878. +#define VCHIQ_IOC_SET_SERVICE_OPTION \
  27879. + _IOW(VCHIQ_IOC_MAGIC, 14, VCHIQ_SET_SERVICE_OPTION_T)
  27880. +#define VCHIQ_IOC_DUMP_PHYS_MEM \
  27881. + _IOW(VCHIQ_IOC_MAGIC, 15, VCHIQ_DUMP_MEM_T)
  27882. +#define VCHIQ_IOC_MAX 15
  27883. +
  27884. +#endif
  27885. diff -Nur linux-3.13.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c
  27886. --- linux-3.13.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c 1970-01-01 01:00:00.000000000 +0100
  27887. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c 2014-04-24 15:35:02.893551516 +0200
  27888. @@ -0,0 +1,456 @@
  27889. +/**
  27890. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  27891. + *
  27892. + * Redistribution and use in source and binary forms, with or without
  27893. + * modification, are permitted provided that the following conditions
  27894. + * are met:
  27895. + * 1. Redistributions of source code must retain the above copyright
  27896. + * notice, this list of conditions, and the following disclaimer,
  27897. + * without modification.
  27898. + * 2. Redistributions in binary form must reproduce the above copyright
  27899. + * notice, this list of conditions and the following disclaimer in the
  27900. + * documentation and/or other materials provided with the distribution.
  27901. + * 3. The names of the above-listed copyright holders may not be used
  27902. + * to endorse or promote products derived from this software without
  27903. + * specific prior written permission.
  27904. + *
  27905. + * ALTERNATIVELY, this software may be distributed under the terms of the
  27906. + * GNU General Public License ("GPL") version 2, as published by the Free
  27907. + * Software Foundation.
  27908. + *
  27909. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  27910. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  27911. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  27912. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  27913. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  27914. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  27915. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  27916. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  27917. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  27918. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27919. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27920. + */
  27921. +
  27922. +/* ---- Include Files ---------------------------------------------------- */
  27923. +
  27924. +#include <linux/kernel.h>
  27925. +#include <linux/module.h>
  27926. +#include <linux/mutex.h>
  27927. +
  27928. +#include "vchiq_core.h"
  27929. +#include "vchiq_arm.h"
  27930. +
  27931. +/* ---- Public Variables ------------------------------------------------- */
  27932. +
  27933. +/* ---- Private Constants and Types -------------------------------------- */
  27934. +
  27935. +struct bulk_waiter_node {
  27936. + struct bulk_waiter bulk_waiter;
  27937. + int pid;
  27938. + struct list_head list;
  27939. +};
  27940. +
  27941. +struct vchiq_instance_struct {
  27942. + VCHIQ_STATE_T *state;
  27943. +
  27944. + int connected;
  27945. +
  27946. + struct list_head bulk_waiter_list;
  27947. + struct mutex bulk_waiter_list_mutex;
  27948. +};
  27949. +
  27950. +static VCHIQ_STATUS_T
  27951. +vchiq_blocking_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle, void *data,
  27952. + unsigned int size, VCHIQ_BULK_DIR_T dir);
  27953. +
  27954. +/****************************************************************************
  27955. +*
  27956. +* vchiq_initialise
  27957. +*
  27958. +***************************************************************************/
  27959. +#define VCHIQ_INIT_RETRIES 10
  27960. +VCHIQ_STATUS_T vchiq_initialise(VCHIQ_INSTANCE_T *instanceOut)
  27961. +{
  27962. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  27963. + VCHIQ_STATE_T *state;
  27964. + VCHIQ_INSTANCE_T instance = NULL;
  27965. + int i;
  27966. +
  27967. + vchiq_log_trace(vchiq_core_log_level, "%s called", __func__);
  27968. +
  27969. + /* VideoCore may not be ready due to boot up timing.
  27970. + It may never be ready if kernel and firmware are mismatched, so don't block forever. */
  27971. + for (i=0; i<VCHIQ_INIT_RETRIES; i++) {
  27972. + state = vchiq_get_state();
  27973. + if (state)
  27974. + break;
  27975. + udelay(500);
  27976. + }
  27977. + if (i==VCHIQ_INIT_RETRIES) {
  27978. + vchiq_log_error(vchiq_core_log_level,
  27979. + "%s: videocore not initialized\n", __func__);
  27980. + goto failed;
  27981. + } else if (i>0) {
  27982. + vchiq_log_warning(vchiq_core_log_level,
  27983. + "%s: videocore initialized after %d retries\n", __func__, i);
  27984. + }
  27985. +
  27986. + instance = kzalloc(sizeof(*instance), GFP_KERNEL);
  27987. + if (!instance) {
  27988. + vchiq_log_error(vchiq_core_log_level,
  27989. + "%s: error allocating vchiq instance\n", __func__);
  27990. + goto failed;
  27991. + }
  27992. +
  27993. + instance->connected = 0;
  27994. + instance->state = state;
  27995. + mutex_init(&instance->bulk_waiter_list_mutex);
  27996. + INIT_LIST_HEAD(&instance->bulk_waiter_list);
  27997. +
  27998. + *instanceOut = instance;
  27999. +
  28000. + status = VCHIQ_SUCCESS;
  28001. +
  28002. +failed:
  28003. + vchiq_log_trace(vchiq_core_log_level,
  28004. + "%s(%p): returning %d", __func__, instance, status);
  28005. +
  28006. + return status;
  28007. +}
  28008. +EXPORT_SYMBOL(vchiq_initialise);
  28009. +
  28010. +/****************************************************************************
  28011. +*
  28012. +* vchiq_shutdown
  28013. +*
  28014. +***************************************************************************/
  28015. +
  28016. +VCHIQ_STATUS_T vchiq_shutdown(VCHIQ_INSTANCE_T instance)
  28017. +{
  28018. + VCHIQ_STATUS_T status;
  28019. + VCHIQ_STATE_T *state = instance->state;
  28020. +
  28021. + vchiq_log_trace(vchiq_core_log_level,
  28022. + "%s(%p) called", __func__, instance);
  28023. +
  28024. + if (mutex_lock_interruptible(&state->mutex) != 0)
  28025. + return VCHIQ_RETRY;
  28026. +
  28027. + /* Remove all services */
  28028. + status = vchiq_shutdown_internal(state, instance);
  28029. +
  28030. + mutex_unlock(&state->mutex);
  28031. +
  28032. + vchiq_log_trace(vchiq_core_log_level,
  28033. + "%s(%p): returning %d", __func__, instance, status);
  28034. +
  28035. + if (status == VCHIQ_SUCCESS) {
  28036. + struct list_head *pos, *next;
  28037. + list_for_each_safe(pos, next,
  28038. + &instance->bulk_waiter_list) {
  28039. + struct bulk_waiter_node *waiter;
  28040. + waiter = list_entry(pos,
  28041. + struct bulk_waiter_node,
  28042. + list);
  28043. + list_del(pos);
  28044. + vchiq_log_info(vchiq_arm_log_level,
  28045. + "bulk_waiter - cleaned up %x "
  28046. + "for pid %d",
  28047. + (unsigned int)waiter, waiter->pid);
  28048. + kfree(waiter);
  28049. + }
  28050. + kfree(instance);
  28051. + }
  28052. +
  28053. + return status;
  28054. +}
  28055. +EXPORT_SYMBOL(vchiq_shutdown);
  28056. +
  28057. +/****************************************************************************
  28058. +*
  28059. +* vchiq_is_connected
  28060. +*
  28061. +***************************************************************************/
  28062. +
  28063. +int vchiq_is_connected(VCHIQ_INSTANCE_T instance)
  28064. +{
  28065. + return instance->connected;
  28066. +}
  28067. +
  28068. +/****************************************************************************
  28069. +*
  28070. +* vchiq_connect
  28071. +*
  28072. +***************************************************************************/
  28073. +
  28074. +VCHIQ_STATUS_T vchiq_connect(VCHIQ_INSTANCE_T instance)
  28075. +{
  28076. + VCHIQ_STATUS_T status;
  28077. + VCHIQ_STATE_T *state = instance->state;
  28078. +
  28079. + vchiq_log_trace(vchiq_core_log_level,
  28080. + "%s(%p) called", __func__, instance);
  28081. +
  28082. + if (mutex_lock_interruptible(&state->mutex) != 0) {
  28083. + vchiq_log_trace(vchiq_core_log_level,
  28084. + "%s: call to mutex_lock failed", __func__);
  28085. + status = VCHIQ_RETRY;
  28086. + goto failed;
  28087. + }
  28088. + status = vchiq_connect_internal(state, instance);
  28089. +
  28090. + if (status == VCHIQ_SUCCESS)
  28091. + instance->connected = 1;
  28092. +
  28093. + mutex_unlock(&state->mutex);
  28094. +
  28095. +failed:
  28096. + vchiq_log_trace(vchiq_core_log_level,
  28097. + "%s(%p): returning %d", __func__, instance, status);
  28098. +
  28099. + return status;
  28100. +}
  28101. +EXPORT_SYMBOL(vchiq_connect);
  28102. +
  28103. +/****************************************************************************
  28104. +*
  28105. +* vchiq_add_service
  28106. +*
  28107. +***************************************************************************/
  28108. +
  28109. +VCHIQ_STATUS_T vchiq_add_service(
  28110. + VCHIQ_INSTANCE_T instance,
  28111. + const VCHIQ_SERVICE_PARAMS_T *params,
  28112. + VCHIQ_SERVICE_HANDLE_T *phandle)
  28113. +{
  28114. + VCHIQ_STATUS_T status;
  28115. + VCHIQ_STATE_T *state = instance->state;
  28116. + VCHIQ_SERVICE_T *service = NULL;
  28117. + int srvstate;
  28118. +
  28119. + vchiq_log_trace(vchiq_core_log_level,
  28120. + "%s(%p) called", __func__, instance);
  28121. +
  28122. + *phandle = VCHIQ_SERVICE_HANDLE_INVALID;
  28123. +
  28124. + srvstate = vchiq_is_connected(instance)
  28125. + ? VCHIQ_SRVSTATE_LISTENING
  28126. + : VCHIQ_SRVSTATE_HIDDEN;
  28127. +
  28128. + service = vchiq_add_service_internal(
  28129. + state,
  28130. + params,
  28131. + srvstate,
  28132. + instance,
  28133. + NULL);
  28134. +
  28135. + if (service) {
  28136. + *phandle = service->handle;
  28137. + status = VCHIQ_SUCCESS;
  28138. + } else
  28139. + status = VCHIQ_ERROR;
  28140. +
  28141. + vchiq_log_trace(vchiq_core_log_level,
  28142. + "%s(%p): returning %d", __func__, instance, status);
  28143. +
  28144. + return status;
  28145. +}
  28146. +EXPORT_SYMBOL(vchiq_add_service);
  28147. +
  28148. +/****************************************************************************
  28149. +*
  28150. +* vchiq_open_service
  28151. +*
  28152. +***************************************************************************/
  28153. +
  28154. +VCHIQ_STATUS_T vchiq_open_service(
  28155. + VCHIQ_INSTANCE_T instance,
  28156. + const VCHIQ_SERVICE_PARAMS_T *params,
  28157. + VCHIQ_SERVICE_HANDLE_T *phandle)
  28158. +{
  28159. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  28160. + VCHIQ_STATE_T *state = instance->state;
  28161. + VCHIQ_SERVICE_T *service = NULL;
  28162. +
  28163. + vchiq_log_trace(vchiq_core_log_level,
  28164. + "%s(%p) called", __func__, instance);
  28165. +
  28166. + *phandle = VCHIQ_SERVICE_HANDLE_INVALID;
  28167. +
  28168. + if (!vchiq_is_connected(instance))
  28169. + goto failed;
  28170. +
  28171. + service = vchiq_add_service_internal(state,
  28172. + params,
  28173. + VCHIQ_SRVSTATE_OPENING,
  28174. + instance,
  28175. + NULL);
  28176. +
  28177. + if (service) {
  28178. + status = vchiq_open_service_internal(service, current->pid);
  28179. + if (status == VCHIQ_SUCCESS)
  28180. + *phandle = service->handle;
  28181. + else
  28182. + vchiq_remove_service(service->handle);
  28183. + }
  28184. +
  28185. +failed:
  28186. + vchiq_log_trace(vchiq_core_log_level,
  28187. + "%s(%p): returning %d", __func__, instance, status);
  28188. +
  28189. + return status;
  28190. +}
  28191. +EXPORT_SYMBOL(vchiq_open_service);
  28192. +
  28193. +VCHIQ_STATUS_T
  28194. +vchiq_queue_bulk_transmit(VCHIQ_SERVICE_HANDLE_T handle,
  28195. + const void *data, unsigned int size, void *userdata)
  28196. +{
  28197. + return vchiq_bulk_transfer(handle,
  28198. + VCHI_MEM_HANDLE_INVALID, (void *)data, size, userdata,
  28199. + VCHIQ_BULK_MODE_CALLBACK, VCHIQ_BULK_TRANSMIT);
  28200. +}
  28201. +EXPORT_SYMBOL(vchiq_queue_bulk_transmit);
  28202. +
  28203. +VCHIQ_STATUS_T
  28204. +vchiq_queue_bulk_receive(VCHIQ_SERVICE_HANDLE_T handle, void *data,
  28205. + unsigned int size, void *userdata)
  28206. +{
  28207. + return vchiq_bulk_transfer(handle,
  28208. + VCHI_MEM_HANDLE_INVALID, data, size, userdata,
  28209. + VCHIQ_BULK_MODE_CALLBACK, VCHIQ_BULK_RECEIVE);
  28210. +}
  28211. +EXPORT_SYMBOL(vchiq_queue_bulk_receive);
  28212. +
  28213. +VCHIQ_STATUS_T
  28214. +vchiq_bulk_transmit(VCHIQ_SERVICE_HANDLE_T handle, const void *data,
  28215. + unsigned int size, void *userdata, VCHIQ_BULK_MODE_T mode)
  28216. +{
  28217. + VCHIQ_STATUS_T status;
  28218. +
  28219. + switch (mode) {
  28220. + case VCHIQ_BULK_MODE_NOCALLBACK:
  28221. + case VCHIQ_BULK_MODE_CALLBACK:
  28222. + status = vchiq_bulk_transfer(handle,
  28223. + VCHI_MEM_HANDLE_INVALID, (void *)data, size, userdata,
  28224. + mode, VCHIQ_BULK_TRANSMIT);
  28225. + break;
  28226. + case VCHIQ_BULK_MODE_BLOCKING:
  28227. + status = vchiq_blocking_bulk_transfer(handle,
  28228. + (void *)data, size, VCHIQ_BULK_TRANSMIT);
  28229. + break;
  28230. + default:
  28231. + return VCHIQ_ERROR;
  28232. + }
  28233. +
  28234. + return status;
  28235. +}
  28236. +EXPORT_SYMBOL(vchiq_bulk_transmit);
  28237. +
  28238. +VCHIQ_STATUS_T
  28239. +vchiq_bulk_receive(VCHIQ_SERVICE_HANDLE_T handle, void *data,
  28240. + unsigned int size, void *userdata, VCHIQ_BULK_MODE_T mode)
  28241. +{
  28242. + VCHIQ_STATUS_T status;
  28243. +
  28244. + switch (mode) {
  28245. + case VCHIQ_BULK_MODE_NOCALLBACK:
  28246. + case VCHIQ_BULK_MODE_CALLBACK:
  28247. + status = vchiq_bulk_transfer(handle,
  28248. + VCHI_MEM_HANDLE_INVALID, data, size, userdata,
  28249. + mode, VCHIQ_BULK_RECEIVE);
  28250. + break;
  28251. + case VCHIQ_BULK_MODE_BLOCKING:
  28252. + status = vchiq_blocking_bulk_transfer(handle,
  28253. + (void *)data, size, VCHIQ_BULK_RECEIVE);
  28254. + break;
  28255. + default:
  28256. + return VCHIQ_ERROR;
  28257. + }
  28258. +
  28259. + return status;
  28260. +}
  28261. +EXPORT_SYMBOL(vchiq_bulk_receive);
  28262. +
  28263. +static VCHIQ_STATUS_T
  28264. +vchiq_blocking_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle, void *data,
  28265. + unsigned int size, VCHIQ_BULK_DIR_T dir)
  28266. +{
  28267. + VCHIQ_INSTANCE_T instance;
  28268. + VCHIQ_SERVICE_T *service;
  28269. + VCHIQ_STATUS_T status;
  28270. + struct bulk_waiter_node *waiter = NULL;
  28271. + struct list_head *pos;
  28272. +
  28273. + service = find_service_by_handle(handle);
  28274. + if (!service)
  28275. + return VCHIQ_ERROR;
  28276. +
  28277. + instance = service->instance;
  28278. +
  28279. + unlock_service(service);
  28280. +
  28281. + mutex_lock(&instance->bulk_waiter_list_mutex);
  28282. + list_for_each(pos, &instance->bulk_waiter_list) {
  28283. + if (list_entry(pos, struct bulk_waiter_node,
  28284. + list)->pid == current->pid) {
  28285. + waiter = list_entry(pos,
  28286. + struct bulk_waiter_node,
  28287. + list);
  28288. + list_del(pos);
  28289. + break;
  28290. + }
  28291. + }
  28292. + mutex_unlock(&instance->bulk_waiter_list_mutex);
  28293. +
  28294. + if (waiter) {
  28295. + VCHIQ_BULK_T *bulk = waiter->bulk_waiter.bulk;
  28296. + if (bulk) {
  28297. + /* This thread has an outstanding bulk transfer. */
  28298. + if ((bulk->data != data) ||
  28299. + (bulk->size != size)) {
  28300. + /* This is not a retry of the previous one.
  28301. + ** Cancel the signal when the transfer
  28302. + ** completes. */
  28303. + spin_lock(&bulk_waiter_spinlock);
  28304. + bulk->userdata = NULL;
  28305. + spin_unlock(&bulk_waiter_spinlock);
  28306. + }
  28307. + }
  28308. + }
  28309. +
  28310. + if (!waiter) {
  28311. + waiter = kzalloc(sizeof(struct bulk_waiter_node), GFP_KERNEL);
  28312. + if (!waiter) {
  28313. + vchiq_log_error(vchiq_core_log_level,
  28314. + "%s - out of memory", __func__);
  28315. + return VCHIQ_ERROR;
  28316. + }
  28317. + }
  28318. +
  28319. + status = vchiq_bulk_transfer(handle, VCHI_MEM_HANDLE_INVALID,
  28320. + data, size, &waiter->bulk_waiter, VCHIQ_BULK_MODE_BLOCKING,
  28321. + dir);
  28322. + if ((status != VCHIQ_RETRY) || fatal_signal_pending(current) ||
  28323. + !waiter->bulk_waiter.bulk) {
  28324. + VCHIQ_BULK_T *bulk = waiter->bulk_waiter.bulk;
  28325. + if (bulk) {
  28326. + /* Cancel the signal when the transfer
  28327. + ** completes. */
  28328. + spin_lock(&bulk_waiter_spinlock);
  28329. + bulk->userdata = NULL;
  28330. + spin_unlock(&bulk_waiter_spinlock);
  28331. + }
  28332. + kfree(waiter);
  28333. + } else {
  28334. + waiter->pid = current->pid;
  28335. + mutex_lock(&instance->bulk_waiter_list_mutex);
  28336. + list_add(&waiter->list, &instance->bulk_waiter_list);
  28337. + mutex_unlock(&instance->bulk_waiter_list_mutex);
  28338. + vchiq_log_info(vchiq_arm_log_level,
  28339. + "saved bulk_waiter %x for pid %d",
  28340. + (unsigned int)waiter, current->pid);
  28341. + }
  28342. +
  28343. + return status;
  28344. +}
  28345. diff -Nur linux-3.13.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_memdrv.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_memdrv.h
  28346. --- linux-3.13.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_memdrv.h 1970-01-01 01:00:00.000000000 +0100
  28347. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_memdrv.h 2014-04-24 15:35:02.893551516 +0200
  28348. @@ -0,0 +1,71 @@
  28349. +/**
  28350. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  28351. + *
  28352. + * Redistribution and use in source and binary forms, with or without
  28353. + * modification, are permitted provided that the following conditions
  28354. + * are met:
  28355. + * 1. Redistributions of source code must retain the above copyright
  28356. + * notice, this list of conditions, and the following disclaimer,
  28357. + * without modification.
  28358. + * 2. Redistributions in binary form must reproduce the above copyright
  28359. + * notice, this list of conditions and the following disclaimer in the
  28360. + * documentation and/or other materials provided with the distribution.
  28361. + * 3. The names of the above-listed copyright holders may not be used
  28362. + * to endorse or promote products derived from this software without
  28363. + * specific prior written permission.
  28364. + *
  28365. + * ALTERNATIVELY, this software may be distributed under the terms of the
  28366. + * GNU General Public License ("GPL") version 2, as published by the Free
  28367. + * Software Foundation.
  28368. + *
  28369. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  28370. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  28371. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  28372. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  28373. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  28374. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  28375. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28376. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  28377. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  28378. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28379. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28380. + */
  28381. +
  28382. +#ifndef VCHIQ_MEMDRV_H
  28383. +#define VCHIQ_MEMDRV_H
  28384. +
  28385. +/* ---- Include Files ----------------------------------------------------- */
  28386. +
  28387. +#include <linux/kernel.h>
  28388. +#include "vchiq_if.h"
  28389. +
  28390. +/* ---- Constants and Types ---------------------------------------------- */
  28391. +
  28392. +typedef struct {
  28393. + void *armSharedMemVirt;
  28394. + dma_addr_t armSharedMemPhys;
  28395. + size_t armSharedMemSize;
  28396. +
  28397. + void *vcSharedMemVirt;
  28398. + dma_addr_t vcSharedMemPhys;
  28399. + size_t vcSharedMemSize;
  28400. +} VCHIQ_SHARED_MEM_INFO_T;
  28401. +
  28402. +/* ---- Variable Externs ------------------------------------------------- */
  28403. +
  28404. +/* ---- Function Prototypes ---------------------------------------------- */
  28405. +
  28406. +void vchiq_get_shared_mem_info(VCHIQ_SHARED_MEM_INFO_T *info);
  28407. +
  28408. +VCHIQ_STATUS_T vchiq_memdrv_initialise(void);
  28409. +
  28410. +VCHIQ_STATUS_T vchiq_userdrv_create_instance(
  28411. + const VCHIQ_PLATFORM_DATA_T * platform_data);
  28412. +
  28413. +VCHIQ_STATUS_T vchiq_userdrv_suspend(
  28414. + const VCHIQ_PLATFORM_DATA_T * platform_data);
  28415. +
  28416. +VCHIQ_STATUS_T vchiq_userdrv_resume(
  28417. + const VCHIQ_PLATFORM_DATA_T * platform_data);
  28418. +
  28419. +#endif
  28420. diff -Nur linux-3.13.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_pagelist.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_pagelist.h
  28421. --- linux-3.13.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_pagelist.h 1970-01-01 01:00:00.000000000 +0100
  28422. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_pagelist.h 2014-04-24 15:35:02.893551516 +0200
  28423. @@ -0,0 +1,58 @@
  28424. +/**
  28425. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  28426. + *
  28427. + * Redistribution and use in source and binary forms, with or without
  28428. + * modification, are permitted provided that the following conditions
  28429. + * are met:
  28430. + * 1. Redistributions of source code must retain the above copyright
  28431. + * notice, this list of conditions, and the following disclaimer,
  28432. + * without modification.
  28433. + * 2. Redistributions in binary form must reproduce the above copyright
  28434. + * notice, this list of conditions and the following disclaimer in the
  28435. + * documentation and/or other materials provided with the distribution.
  28436. + * 3. The names of the above-listed copyright holders may not be used
  28437. + * to endorse or promote products derived from this software without
  28438. + * specific prior written permission.
  28439. + *
  28440. + * ALTERNATIVELY, this software may be distributed under the terms of the
  28441. + * GNU General Public License ("GPL") version 2, as published by the Free
  28442. + * Software Foundation.
  28443. + *
  28444. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  28445. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  28446. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  28447. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  28448. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  28449. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  28450. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28451. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  28452. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  28453. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28454. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28455. + */
  28456. +
  28457. +#ifndef VCHIQ_PAGELIST_H
  28458. +#define VCHIQ_PAGELIST_H
  28459. +
  28460. +#ifndef PAGE_SIZE
  28461. +#define PAGE_SIZE 4096
  28462. +#endif
  28463. +#define CACHE_LINE_SIZE 32
  28464. +#define PAGELIST_WRITE 0
  28465. +#define PAGELIST_READ 1
  28466. +#define PAGELIST_READ_WITH_FRAGMENTS 2
  28467. +
  28468. +typedef struct pagelist_struct {
  28469. + unsigned long length;
  28470. + unsigned short type;
  28471. + unsigned short offset;
  28472. + unsigned long addrs[1]; /* N.B. 12 LSBs hold the number of following
  28473. + pages at consecutive addresses. */
  28474. +} PAGELIST_T;
  28475. +
  28476. +typedef struct fragments_struct {
  28477. + char headbuf[CACHE_LINE_SIZE];
  28478. + char tailbuf[CACHE_LINE_SIZE];
  28479. +} FRAGMENTS_T;
  28480. +
  28481. +#endif /* VCHIQ_PAGELIST_H */
  28482. diff -Nur linux-3.13.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_proc.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_proc.c
  28483. --- linux-3.13.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_proc.c 1970-01-01 01:00:00.000000000 +0100
  28484. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_proc.c 2014-04-24 15:36:51.710754091 +0200
  28485. @@ -0,0 +1,253 @@
  28486. +/**
  28487. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  28488. + *
  28489. + * Redistribution and use in source and binary forms, with or without
  28490. + * modification, are permitted provided that the following conditions
  28491. + * are met:
  28492. + * 1. Redistributions of source code must retain the above copyright
  28493. + * notice, this list of conditions, and the following disclaimer,
  28494. + * without modification.
  28495. + * 2. Redistributions in binary form must reproduce the above copyright
  28496. + * notice, this list of conditions and the following disclaimer in the
  28497. + * documentation and/or other materials provided with the distribution.
  28498. + * 3. The names of the above-listed copyright holders may not be used
  28499. + * to endorse or promote products derived from this software without
  28500. + * specific prior written permission.
  28501. + *
  28502. + * ALTERNATIVELY, this software may be distributed under the terms of the
  28503. + * GNU General Public License ("GPL") version 2, as published by the Free
  28504. + * Software Foundation.
  28505. + *
  28506. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  28507. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  28508. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  28509. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  28510. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  28511. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  28512. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28513. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  28514. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  28515. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28516. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28517. + */
  28518. +
  28519. +
  28520. +#include <linux/proc_fs.h>
  28521. +#include "vchiq_core.h"
  28522. +#include "vchiq_arm.h"
  28523. +
  28524. +#if 1
  28525. +
  28526. +int vchiq_proc_init(void)
  28527. +{
  28528. + return 0;
  28529. +}
  28530. +
  28531. +void vchiq_proc_deinit(void)
  28532. +{
  28533. +}
  28534. +
  28535. +#else
  28536. +
  28537. +struct vchiq_proc_info {
  28538. + /* Global 'vc' proc entry used by all instances */
  28539. + struct proc_dir_entry *vc_cfg_dir;
  28540. +
  28541. + /* one entry per client process */
  28542. + struct proc_dir_entry *clients;
  28543. +
  28544. + /* log categories */
  28545. + struct proc_dir_entry *log_categories;
  28546. +};
  28547. +
  28548. +static struct vchiq_proc_info proc_info;
  28549. +
  28550. +struct proc_dir_entry *vchiq_proc_top(void)
  28551. +{
  28552. + BUG_ON(proc_info.vc_cfg_dir == NULL);
  28553. + return proc_info.vc_cfg_dir;
  28554. +}
  28555. +
  28556. +/****************************************************************************
  28557. +*
  28558. +* log category entries
  28559. +*
  28560. +***************************************************************************/
  28561. +#define PROC_WRITE_BUF_SIZE 256
  28562. +
  28563. +#define VCHIQ_LOG_ERROR_STR "error"
  28564. +#define VCHIQ_LOG_WARNING_STR "warning"
  28565. +#define VCHIQ_LOG_INFO_STR "info"
  28566. +#define VCHIQ_LOG_TRACE_STR "trace"
  28567. +
  28568. +static int log_cfg_read(char *buffer,
  28569. + char **start,
  28570. + off_t off,
  28571. + int count,
  28572. + int *eof,
  28573. + void *data)
  28574. +{
  28575. + int len = 0;
  28576. + char *log_value = NULL;
  28577. +
  28578. + switch (*((int *)data)) {
  28579. + case VCHIQ_LOG_ERROR:
  28580. + log_value = VCHIQ_LOG_ERROR_STR;
  28581. + break;
  28582. + case VCHIQ_LOG_WARNING:
  28583. + log_value = VCHIQ_LOG_WARNING_STR;
  28584. + break;
  28585. + case VCHIQ_LOG_INFO:
  28586. + log_value = VCHIQ_LOG_INFO_STR;
  28587. + break;
  28588. + case VCHIQ_LOG_TRACE:
  28589. + log_value = VCHIQ_LOG_TRACE_STR;
  28590. + break;
  28591. + default:
  28592. + break;
  28593. + }
  28594. +
  28595. + len += sprintf(buffer + len,
  28596. + "%s\n",
  28597. + log_value ? log_value : "(null)");
  28598. +
  28599. + return len;
  28600. +}
  28601. +
  28602. +
  28603. +static int log_cfg_write(struct file *file,
  28604. + const char __user *buffer,
  28605. + unsigned long count,
  28606. + void *data)
  28607. +{
  28608. + int *log_module = data;
  28609. + char kbuf[PROC_WRITE_BUF_SIZE + 1];
  28610. +
  28611. + (void)file;
  28612. +
  28613. + memset(kbuf, 0, PROC_WRITE_BUF_SIZE + 1);
  28614. + if (count >= PROC_WRITE_BUF_SIZE)
  28615. + count = PROC_WRITE_BUF_SIZE;
  28616. +
  28617. + if (copy_from_user(kbuf,
  28618. + buffer,
  28619. + count) != 0)
  28620. + return -EFAULT;
  28621. + kbuf[count - 1] = 0;
  28622. +
  28623. + if (strncmp("error", kbuf, strlen("error")) == 0)
  28624. + *log_module = VCHIQ_LOG_ERROR;
  28625. + else if (strncmp("warning", kbuf, strlen("warning")) == 0)
  28626. + *log_module = VCHIQ_LOG_WARNING;
  28627. + else if (strncmp("info", kbuf, strlen("info")) == 0)
  28628. + *log_module = VCHIQ_LOG_INFO;
  28629. + else if (strncmp("trace", kbuf, strlen("trace")) == 0)
  28630. + *log_module = VCHIQ_LOG_TRACE;
  28631. + else
  28632. + *log_module = VCHIQ_LOG_DEFAULT;
  28633. +
  28634. + return count;
  28635. +}
  28636. +
  28637. +/* Log category proc entries */
  28638. +struct vchiq_proc_log_entry {
  28639. + const char *name;
  28640. + int *plevel;
  28641. + struct proc_dir_entry *dir;
  28642. +};
  28643. +
  28644. +static struct vchiq_proc_log_entry vchiq_proc_log_entries[] = {
  28645. + { "core", &vchiq_core_log_level },
  28646. + { "msg", &vchiq_core_msg_log_level },
  28647. + { "sync", &vchiq_sync_log_level },
  28648. + { "susp", &vchiq_susp_log_level },
  28649. + { "arm", &vchiq_arm_log_level },
  28650. +};
  28651. +static int n_log_entries =
  28652. + sizeof(vchiq_proc_log_entries)/sizeof(vchiq_proc_log_entries[0]);
  28653. +
  28654. +/* create an entry under /proc/vc/log for each log category */
  28655. +static int vchiq_proc_create_log_entries(struct proc_dir_entry *top)
  28656. +{
  28657. + struct proc_dir_entry *dir;
  28658. + size_t i;
  28659. + int ret = 0;
  28660. + dir = proc_mkdir("log", proc_info.vc_cfg_dir);
  28661. + if (!dir)
  28662. + return -ENOMEM;
  28663. + proc_info.log_categories = dir;
  28664. +
  28665. + for (i = 0; i < n_log_entries; i++) {
  28666. + dir = create_proc_entry(vchiq_proc_log_entries[i].name,
  28667. + 0644,
  28668. + proc_info.log_categories);
  28669. + if (!dir) {
  28670. + ret = -ENOMEM;
  28671. + break;
  28672. + }
  28673. +
  28674. + dir->read_proc = &log_cfg_read;
  28675. + dir->write_proc = &log_cfg_write;
  28676. + dir->data = (void *)vchiq_proc_log_entries[i].plevel;
  28677. +
  28678. + vchiq_proc_log_entries[i].dir = dir;
  28679. + }
  28680. + return ret;
  28681. +}
  28682. +
  28683. +
  28684. +int vchiq_proc_init(void)
  28685. +{
  28686. + BUG_ON(proc_info.vc_cfg_dir != NULL);
  28687. +
  28688. + proc_info.vc_cfg_dir = proc_mkdir("vc", NULL);
  28689. + if (proc_info.vc_cfg_dir == NULL)
  28690. + goto fail;
  28691. +
  28692. + proc_info.clients = proc_mkdir("clients",
  28693. + proc_info.vc_cfg_dir);
  28694. + if (!proc_info.clients)
  28695. + goto fail;
  28696. +
  28697. + if (vchiq_proc_create_log_entries(proc_info.vc_cfg_dir) != 0)
  28698. + goto fail;
  28699. +
  28700. + return 0;
  28701. +
  28702. +fail:
  28703. + vchiq_proc_deinit();
  28704. + vchiq_log_error(vchiq_arm_log_level,
  28705. + "%s: failed to create proc directory",
  28706. + __func__);
  28707. +
  28708. + return -ENOMEM;
  28709. +}
  28710. +
  28711. +/* remove all the proc entries */
  28712. +void vchiq_proc_deinit(void)
  28713. +{
  28714. + /* log category entries */
  28715. + if (proc_info.log_categories) {
  28716. + size_t i;
  28717. + for (i = 0; i < n_log_entries; i++)
  28718. + if (vchiq_proc_log_entries[i].dir)
  28719. + remove_proc_entry(
  28720. + vchiq_proc_log_entries[i].name,
  28721. + proc_info.log_categories);
  28722. +
  28723. + remove_proc_entry(proc_info.log_categories->name,
  28724. + proc_info.vc_cfg_dir);
  28725. + }
  28726. + if (proc_info.clients)
  28727. + remove_proc_entry(proc_info.clients->name,
  28728. + proc_info.vc_cfg_dir);
  28729. + if (proc_info.vc_cfg_dir)
  28730. + remove_proc_entry(proc_info.vc_cfg_dir->name, NULL);
  28731. +}
  28732. +
  28733. +struct proc_dir_entry *vchiq_clients_top(void)
  28734. +{
  28735. + return proc_info.clients;
  28736. +}
  28737. +
  28738. +#endif
  28739. diff -Nur linux-3.13.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_shim.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_shim.c
  28740. --- linux-3.13.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_shim.c 1970-01-01 01:00:00.000000000 +0100
  28741. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_shim.c 2014-04-24 15:35:02.893551516 +0200
  28742. @@ -0,0 +1,828 @@
  28743. +/**
  28744. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  28745. + *
  28746. + * Redistribution and use in source and binary forms, with or without
  28747. + * modification, are permitted provided that the following conditions
  28748. + * are met:
  28749. + * 1. Redistributions of source code must retain the above copyright
  28750. + * notice, this list of conditions, and the following disclaimer,
  28751. + * without modification.
  28752. + * 2. Redistributions in binary form must reproduce the above copyright
  28753. + * notice, this list of conditions and the following disclaimer in the
  28754. + * documentation and/or other materials provided with the distribution.
  28755. + * 3. The names of the above-listed copyright holders may not be used
  28756. + * to endorse or promote products derived from this software without
  28757. + * specific prior written permission.
  28758. + *
  28759. + * ALTERNATIVELY, this software may be distributed under the terms of the
  28760. + * GNU General Public License ("GPL") version 2, as published by the Free
  28761. + * Software Foundation.
  28762. + *
  28763. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  28764. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  28765. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  28766. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  28767. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  28768. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  28769. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28770. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  28771. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  28772. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28773. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28774. + */
  28775. +#include <linux/module.h>
  28776. +#include <linux/types.h>
  28777. +
  28778. +#include "interface/vchi/vchi.h"
  28779. +#include "vchiq.h"
  28780. +#include "vchiq_core.h"
  28781. +
  28782. +#include "vchiq_util.h"
  28783. +
  28784. +#include <stddef.h>
  28785. +
  28786. +#define vchiq_status_to_vchi(status) ((int32_t)status)
  28787. +
  28788. +typedef struct {
  28789. + VCHIQ_SERVICE_HANDLE_T handle;
  28790. +
  28791. + VCHIU_QUEUE_T queue;
  28792. +
  28793. + VCHI_CALLBACK_T callback;
  28794. + void *callback_param;
  28795. +} SHIM_SERVICE_T;
  28796. +
  28797. +/* ----------------------------------------------------------------------
  28798. + * return pointer to the mphi message driver function table
  28799. + * -------------------------------------------------------------------- */
  28800. +const VCHI_MESSAGE_DRIVER_T *
  28801. +vchi_mphi_message_driver_func_table(void)
  28802. +{
  28803. + return NULL;
  28804. +}
  28805. +
  28806. +/* ----------------------------------------------------------------------
  28807. + * return a pointer to the 'single' connection driver fops
  28808. + * -------------------------------------------------------------------- */
  28809. +const VCHI_CONNECTION_API_T *
  28810. +single_get_func_table(void)
  28811. +{
  28812. + return NULL;
  28813. +}
  28814. +
  28815. +VCHI_CONNECTION_T *vchi_create_connection(
  28816. + const VCHI_CONNECTION_API_T *function_table,
  28817. + const VCHI_MESSAGE_DRIVER_T *low_level)
  28818. +{
  28819. + (void)function_table;
  28820. + (void)low_level;
  28821. + return NULL;
  28822. +}
  28823. +
  28824. +/***********************************************************
  28825. + * Name: vchi_msg_peek
  28826. + *
  28827. + * Arguments: const VCHI_SERVICE_HANDLE_T handle,
  28828. + * void **data,
  28829. + * uint32_t *msg_size,
  28830. +
  28831. +
  28832. + * VCHI_FLAGS_T flags
  28833. + *
  28834. + * Description: Routine to return a pointer to the current message (to allow in
  28835. + * place processing). The message can be removed using
  28836. + * vchi_msg_remove when you're finished
  28837. + *
  28838. + * Returns: int32_t - success == 0
  28839. + *
  28840. + ***********************************************************/
  28841. +int32_t vchi_msg_peek(VCHI_SERVICE_HANDLE_T handle,
  28842. + void **data,
  28843. + uint32_t *msg_size,
  28844. + VCHI_FLAGS_T flags)
  28845. +{
  28846. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  28847. + VCHIQ_HEADER_T *header;
  28848. +
  28849. + WARN_ON((flags != VCHI_FLAGS_NONE) &&
  28850. + (flags != VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE));
  28851. +
  28852. + if (flags == VCHI_FLAGS_NONE)
  28853. + if (vchiu_queue_is_empty(&service->queue))
  28854. + return -1;
  28855. +
  28856. + header = vchiu_queue_peek(&service->queue);
  28857. +
  28858. + *data = header->data;
  28859. + *msg_size = header->size;
  28860. +
  28861. + return 0;
  28862. +}
  28863. +EXPORT_SYMBOL(vchi_msg_peek);
  28864. +
  28865. +/***********************************************************
  28866. + * Name: vchi_msg_remove
  28867. + *
  28868. + * Arguments: const VCHI_SERVICE_HANDLE_T handle,
  28869. + *
  28870. + * Description: Routine to remove a message (after it has been read with
  28871. + * vchi_msg_peek)
  28872. + *
  28873. + * Returns: int32_t - success == 0
  28874. + *
  28875. + ***********************************************************/
  28876. +int32_t vchi_msg_remove(VCHI_SERVICE_HANDLE_T handle)
  28877. +{
  28878. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  28879. + VCHIQ_HEADER_T *header;
  28880. +
  28881. + header = vchiu_queue_pop(&service->queue);
  28882. +
  28883. + vchiq_release_message(service->handle, header);
  28884. +
  28885. + return 0;
  28886. +}
  28887. +EXPORT_SYMBOL(vchi_msg_remove);
  28888. +
  28889. +/***********************************************************
  28890. + * Name: vchi_msg_queue
  28891. + *
  28892. + * Arguments: VCHI_SERVICE_HANDLE_T handle,
  28893. + * const void *data,
  28894. + * uint32_t data_size,
  28895. + * VCHI_FLAGS_T flags,
  28896. + * void *msg_handle,
  28897. + *
  28898. + * Description: Thin wrapper to queue a message onto a connection
  28899. + *
  28900. + * Returns: int32_t - success == 0
  28901. + *
  28902. + ***********************************************************/
  28903. +int32_t vchi_msg_queue(VCHI_SERVICE_HANDLE_T handle,
  28904. + const void *data,
  28905. + uint32_t data_size,
  28906. + VCHI_FLAGS_T flags,
  28907. + void *msg_handle)
  28908. +{
  28909. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  28910. + VCHIQ_ELEMENT_T element = {data, data_size};
  28911. + VCHIQ_STATUS_T status;
  28912. +
  28913. + (void)msg_handle;
  28914. +
  28915. + WARN_ON(flags != VCHI_FLAGS_BLOCK_UNTIL_QUEUED);
  28916. +
  28917. + status = vchiq_queue_message(service->handle, &element, 1);
  28918. +
  28919. + /* vchiq_queue_message() may return VCHIQ_RETRY, so we need to
  28920. + ** implement a retry mechanism since this function is supposed
  28921. + ** to block until queued
  28922. + */
  28923. + while (status == VCHIQ_RETRY) {
  28924. + msleep(1);
  28925. + status = vchiq_queue_message(service->handle, &element, 1);
  28926. + }
  28927. +
  28928. + return vchiq_status_to_vchi(status);
  28929. +}
  28930. +EXPORT_SYMBOL(vchi_msg_queue);
  28931. +
  28932. +/***********************************************************
  28933. + * Name: vchi_bulk_queue_receive
  28934. + *
  28935. + * Arguments: VCHI_BULK_HANDLE_T handle,
  28936. + * void *data_dst,
  28937. + * const uint32_t data_size,
  28938. + * VCHI_FLAGS_T flags
  28939. + * void *bulk_handle
  28940. + *
  28941. + * Description: Routine to setup a rcv buffer
  28942. + *
  28943. + * Returns: int32_t - success == 0
  28944. + *
  28945. + ***********************************************************/
  28946. +int32_t vchi_bulk_queue_receive(VCHI_SERVICE_HANDLE_T handle,
  28947. + void *data_dst,
  28948. + uint32_t data_size,
  28949. + VCHI_FLAGS_T flags,
  28950. + void *bulk_handle)
  28951. +{
  28952. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  28953. + VCHIQ_BULK_MODE_T mode;
  28954. + VCHIQ_STATUS_T status;
  28955. +
  28956. + switch ((int)flags) {
  28957. + case VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE
  28958. + | VCHI_FLAGS_BLOCK_UNTIL_QUEUED:
  28959. + WARN_ON(!service->callback);
  28960. + mode = VCHIQ_BULK_MODE_CALLBACK;
  28961. + break;
  28962. + case VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE:
  28963. + mode = VCHIQ_BULK_MODE_BLOCKING;
  28964. + break;
  28965. + case VCHI_FLAGS_BLOCK_UNTIL_QUEUED:
  28966. + case VCHI_FLAGS_NONE:
  28967. + mode = VCHIQ_BULK_MODE_NOCALLBACK;
  28968. + break;
  28969. + default:
  28970. + WARN(1, "unsupported message\n");
  28971. + return vchiq_status_to_vchi(VCHIQ_ERROR);
  28972. + }
  28973. +
  28974. + status = vchiq_bulk_receive(service->handle, data_dst, data_size,
  28975. + bulk_handle, mode);
  28976. +
  28977. + /* vchiq_bulk_receive() may return VCHIQ_RETRY, so we need to
  28978. + ** implement a retry mechanism since this function is supposed
  28979. + ** to block until queued
  28980. + */
  28981. + while (status == VCHIQ_RETRY) {
  28982. + msleep(1);
  28983. + status = vchiq_bulk_receive(service->handle, data_dst,
  28984. + data_size, bulk_handle, mode);
  28985. + }
  28986. +
  28987. + return vchiq_status_to_vchi(status);
  28988. +}
  28989. +EXPORT_SYMBOL(vchi_bulk_queue_receive);
  28990. +
  28991. +/***********************************************************
  28992. + * Name: vchi_bulk_queue_transmit
  28993. + *
  28994. + * Arguments: VCHI_BULK_HANDLE_T handle,
  28995. + * const void *data_src,
  28996. + * uint32_t data_size,
  28997. + * VCHI_FLAGS_T flags,
  28998. + * void *bulk_handle
  28999. + *
  29000. + * Description: Routine to transmit some data
  29001. + *
  29002. + * Returns: int32_t - success == 0
  29003. + *
  29004. + ***********************************************************/
  29005. +int32_t vchi_bulk_queue_transmit(VCHI_SERVICE_HANDLE_T handle,
  29006. + const void *data_src,
  29007. + uint32_t data_size,
  29008. + VCHI_FLAGS_T flags,
  29009. + void *bulk_handle)
  29010. +{
  29011. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  29012. + VCHIQ_BULK_MODE_T mode;
  29013. + VCHIQ_STATUS_T status;
  29014. +
  29015. + switch ((int)flags) {
  29016. + case VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE
  29017. + | VCHI_FLAGS_BLOCK_UNTIL_QUEUED:
  29018. + WARN_ON(!service->callback);
  29019. + mode = VCHIQ_BULK_MODE_CALLBACK;
  29020. + break;
  29021. + case VCHI_FLAGS_BLOCK_UNTIL_DATA_READ:
  29022. + case VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE:
  29023. + mode = VCHIQ_BULK_MODE_BLOCKING;
  29024. + break;
  29025. + case VCHI_FLAGS_BLOCK_UNTIL_QUEUED:
  29026. + case VCHI_FLAGS_NONE:
  29027. + mode = VCHIQ_BULK_MODE_NOCALLBACK;
  29028. + break;
  29029. + default:
  29030. + WARN(1, "unsupported message\n");
  29031. + return vchiq_status_to_vchi(VCHIQ_ERROR);
  29032. + }
  29033. +
  29034. + status = vchiq_bulk_transmit(service->handle, data_src, data_size,
  29035. + bulk_handle, mode);
  29036. +
  29037. + /* vchiq_bulk_transmit() may return VCHIQ_RETRY, so we need to
  29038. + ** implement a retry mechanism since this function is supposed
  29039. + ** to block until queued
  29040. + */
  29041. + while (status == VCHIQ_RETRY) {
  29042. + msleep(1);
  29043. + status = vchiq_bulk_transmit(service->handle, data_src,
  29044. + data_size, bulk_handle, mode);
  29045. + }
  29046. +
  29047. + return vchiq_status_to_vchi(status);
  29048. +}
  29049. +EXPORT_SYMBOL(vchi_bulk_queue_transmit);
  29050. +
  29051. +/***********************************************************
  29052. + * Name: vchi_msg_dequeue
  29053. + *
  29054. + * Arguments: VCHI_SERVICE_HANDLE_T handle,
  29055. + * void *data,
  29056. + * uint32_t max_data_size_to_read,
  29057. + * uint32_t *actual_msg_size
  29058. + * VCHI_FLAGS_T flags
  29059. + *
  29060. + * Description: Routine to dequeue a message into the supplied buffer
  29061. + *
  29062. + * Returns: int32_t - success == 0
  29063. + *
  29064. + ***********************************************************/
  29065. +int32_t vchi_msg_dequeue(VCHI_SERVICE_HANDLE_T handle,
  29066. + void *data,
  29067. + uint32_t max_data_size_to_read,
  29068. + uint32_t *actual_msg_size,
  29069. + VCHI_FLAGS_T flags)
  29070. +{
  29071. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  29072. + VCHIQ_HEADER_T *header;
  29073. +
  29074. + WARN_ON((flags != VCHI_FLAGS_NONE) &&
  29075. + (flags != VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE));
  29076. +
  29077. + if (flags == VCHI_FLAGS_NONE)
  29078. + if (vchiu_queue_is_empty(&service->queue))
  29079. + return -1;
  29080. +
  29081. + header = vchiu_queue_pop(&service->queue);
  29082. +
  29083. + memcpy(data, header->data, header->size < max_data_size_to_read ?
  29084. + header->size : max_data_size_to_read);
  29085. +
  29086. + *actual_msg_size = header->size;
  29087. +
  29088. + vchiq_release_message(service->handle, header);
  29089. +
  29090. + return 0;
  29091. +}
  29092. +EXPORT_SYMBOL(vchi_msg_dequeue);
  29093. +
  29094. +/***********************************************************
  29095. + * Name: vchi_msg_queuev
  29096. + *
  29097. + * Arguments: VCHI_SERVICE_HANDLE_T handle,
  29098. + * VCHI_MSG_VECTOR_T *vector,
  29099. + * uint32_t count,
  29100. + * VCHI_FLAGS_T flags,
  29101. + * void *msg_handle
  29102. + *
  29103. + * Description: Thin wrapper to queue a message onto a connection
  29104. + *
  29105. + * Returns: int32_t - success == 0
  29106. + *
  29107. + ***********************************************************/
  29108. +
  29109. +vchiq_static_assert(sizeof(VCHI_MSG_VECTOR_T) == sizeof(VCHIQ_ELEMENT_T));
  29110. +vchiq_static_assert(offsetof(VCHI_MSG_VECTOR_T, vec_base) ==
  29111. + offsetof(VCHIQ_ELEMENT_T, data));
  29112. +vchiq_static_assert(offsetof(VCHI_MSG_VECTOR_T, vec_len) ==
  29113. + offsetof(VCHIQ_ELEMENT_T, size));
  29114. +
  29115. +int32_t vchi_msg_queuev(VCHI_SERVICE_HANDLE_T handle,
  29116. + VCHI_MSG_VECTOR_T *vector,
  29117. + uint32_t count,
  29118. + VCHI_FLAGS_T flags,
  29119. + void *msg_handle)
  29120. +{
  29121. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  29122. +
  29123. + (void)msg_handle;
  29124. +
  29125. + WARN_ON(flags != VCHI_FLAGS_BLOCK_UNTIL_QUEUED);
  29126. +
  29127. + return vchiq_status_to_vchi(vchiq_queue_message(service->handle,
  29128. + (const VCHIQ_ELEMENT_T *)vector, count));
  29129. +}
  29130. +EXPORT_SYMBOL(vchi_msg_queuev);
  29131. +
  29132. +/***********************************************************
  29133. + * Name: vchi_held_msg_release
  29134. + *
  29135. + * Arguments: VCHI_HELD_MSG_T *message
  29136. + *
  29137. + * Description: Routine to release a held message (after it has been read with
  29138. + * vchi_msg_hold)
  29139. + *
  29140. + * Returns: int32_t - success == 0
  29141. + *
  29142. + ***********************************************************/
  29143. +int32_t vchi_held_msg_release(VCHI_HELD_MSG_T *message)
  29144. +{
  29145. + vchiq_release_message((VCHIQ_SERVICE_HANDLE_T)message->service,
  29146. + (VCHIQ_HEADER_T *)message->message);
  29147. +
  29148. + return 0;
  29149. +}
  29150. +EXPORT_SYMBOL(vchi_held_msg_release);
  29151. +
  29152. +/***********************************************************
  29153. + * Name: vchi_msg_hold
  29154. + *
  29155. + * Arguments: VCHI_SERVICE_HANDLE_T handle,
  29156. + * void **data,
  29157. + * uint32_t *msg_size,
  29158. + * VCHI_FLAGS_T flags,
  29159. + * VCHI_HELD_MSG_T *message_handle
  29160. + *
  29161. + * Description: Routine to return a pointer to the current message (to allow
  29162. + * in place processing). The message is dequeued - don't forget
  29163. + * to release the message using vchi_held_msg_release when you're
  29164. + * finished.
  29165. + *
  29166. + * Returns: int32_t - success == 0
  29167. + *
  29168. + ***********************************************************/
  29169. +int32_t vchi_msg_hold(VCHI_SERVICE_HANDLE_T handle,
  29170. + void **data,
  29171. + uint32_t *msg_size,
  29172. + VCHI_FLAGS_T flags,
  29173. + VCHI_HELD_MSG_T *message_handle)
  29174. +{
  29175. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  29176. + VCHIQ_HEADER_T *header;
  29177. +
  29178. + WARN_ON((flags != VCHI_FLAGS_NONE) &&
  29179. + (flags != VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE));
  29180. +
  29181. + if (flags == VCHI_FLAGS_NONE)
  29182. + if (vchiu_queue_is_empty(&service->queue))
  29183. + return -1;
  29184. +
  29185. + header = vchiu_queue_pop(&service->queue);
  29186. +
  29187. + *data = header->data;
  29188. + *msg_size = header->size;
  29189. +
  29190. + message_handle->service =
  29191. + (struct opaque_vchi_service_t *)service->handle;
  29192. + message_handle->message = header;
  29193. +
  29194. + return 0;
  29195. +}
  29196. +EXPORT_SYMBOL(vchi_msg_hold);
  29197. +
  29198. +/***********************************************************
  29199. + * Name: vchi_initialise
  29200. + *
  29201. + * Arguments: VCHI_INSTANCE_T *instance_handle
  29202. + * VCHI_CONNECTION_T **connections
  29203. + * const uint32_t num_connections
  29204. + *
  29205. + * Description: Initialises the hardware but does not transmit anything
  29206. + * When run as a Host App this will be called twice hence the need
  29207. + * to malloc the state information
  29208. + *
  29209. + * Returns: 0 if successful, failure otherwise
  29210. + *
  29211. + ***********************************************************/
  29212. +
  29213. +int32_t vchi_initialise(VCHI_INSTANCE_T *instance_handle)
  29214. +{
  29215. + VCHIQ_INSTANCE_T instance;
  29216. + VCHIQ_STATUS_T status;
  29217. +
  29218. + status = vchiq_initialise(&instance);
  29219. +
  29220. + *instance_handle = (VCHI_INSTANCE_T)instance;
  29221. +
  29222. + return vchiq_status_to_vchi(status);
  29223. +}
  29224. +EXPORT_SYMBOL(vchi_initialise);
  29225. +
  29226. +/***********************************************************
  29227. + * Name: vchi_connect
  29228. + *
  29229. + * Arguments: VCHI_CONNECTION_T **connections
  29230. + * const uint32_t num_connections
  29231. + * VCHI_INSTANCE_T instance_handle)
  29232. + *
  29233. + * Description: Starts the command service on each connection,
  29234. + * causing INIT messages to be pinged back and forth
  29235. + *
  29236. + * Returns: 0 if successful, failure otherwise
  29237. + *
  29238. + ***********************************************************/
  29239. +int32_t vchi_connect(VCHI_CONNECTION_T **connections,
  29240. + const uint32_t num_connections,
  29241. + VCHI_INSTANCE_T instance_handle)
  29242. +{
  29243. + VCHIQ_INSTANCE_T instance = (VCHIQ_INSTANCE_T)instance_handle;
  29244. +
  29245. + (void)connections;
  29246. + (void)num_connections;
  29247. +
  29248. + return vchiq_connect(instance);
  29249. +}
  29250. +EXPORT_SYMBOL(vchi_connect);
  29251. +
  29252. +
  29253. +/***********************************************************
  29254. + * Name: vchi_disconnect
  29255. + *
  29256. + * Arguments: VCHI_INSTANCE_T instance_handle
  29257. + *
  29258. + * Description: Stops the command service on each connection,
  29259. + * causing DE-INIT messages to be pinged back and forth
  29260. + *
  29261. + * Returns: 0 if successful, failure otherwise
  29262. + *
  29263. + ***********************************************************/
  29264. +int32_t vchi_disconnect(VCHI_INSTANCE_T instance_handle)
  29265. +{
  29266. + VCHIQ_INSTANCE_T instance = (VCHIQ_INSTANCE_T)instance_handle;
  29267. + return vchiq_status_to_vchi(vchiq_shutdown(instance));
  29268. +}
  29269. +EXPORT_SYMBOL(vchi_disconnect);
  29270. +
  29271. +
  29272. +/***********************************************************
  29273. + * Name: vchi_service_open
  29274. + * Name: vchi_service_create
  29275. + *
  29276. + * Arguments: VCHI_INSTANCE_T *instance_handle
  29277. + * SERVICE_CREATION_T *setup,
  29278. + * VCHI_SERVICE_HANDLE_T *handle
  29279. + *
  29280. + * Description: Routine to open a service
  29281. + *
  29282. + * Returns: int32_t - success == 0
  29283. + *
  29284. + ***********************************************************/
  29285. +
  29286. +static VCHIQ_STATUS_T shim_callback(VCHIQ_REASON_T reason,
  29287. + VCHIQ_HEADER_T *header, VCHIQ_SERVICE_HANDLE_T handle, void *bulk_user)
  29288. +{
  29289. + SHIM_SERVICE_T *service =
  29290. + (SHIM_SERVICE_T *)VCHIQ_GET_SERVICE_USERDATA(handle);
  29291. +
  29292. + if (!service->callback)
  29293. + goto release;
  29294. +
  29295. + switch (reason) {
  29296. + case VCHIQ_MESSAGE_AVAILABLE:
  29297. + vchiu_queue_push(&service->queue, header);
  29298. +
  29299. + service->callback(service->callback_param,
  29300. + VCHI_CALLBACK_MSG_AVAILABLE, NULL);
  29301. +
  29302. + goto done;
  29303. + break;
  29304. +
  29305. + case VCHIQ_BULK_TRANSMIT_DONE:
  29306. + service->callback(service->callback_param,
  29307. + VCHI_CALLBACK_BULK_SENT, bulk_user);
  29308. + break;
  29309. +
  29310. + case VCHIQ_BULK_RECEIVE_DONE:
  29311. + service->callback(service->callback_param,
  29312. + VCHI_CALLBACK_BULK_RECEIVED, bulk_user);
  29313. + break;
  29314. +
  29315. + case VCHIQ_SERVICE_CLOSED:
  29316. + service->callback(service->callback_param,
  29317. + VCHI_CALLBACK_SERVICE_CLOSED, NULL);
  29318. + break;
  29319. +
  29320. + case VCHIQ_SERVICE_OPENED:
  29321. + /* No equivalent VCHI reason */
  29322. + break;
  29323. +
  29324. + case VCHIQ_BULK_TRANSMIT_ABORTED:
  29325. + service->callback(service->callback_param,
  29326. + VCHI_CALLBACK_BULK_TRANSMIT_ABORTED,
  29327. + bulk_user);
  29328. + break;
  29329. +
  29330. + case VCHIQ_BULK_RECEIVE_ABORTED:
  29331. + service->callback(service->callback_param,
  29332. + VCHI_CALLBACK_BULK_RECEIVE_ABORTED,
  29333. + bulk_user);
  29334. + break;
  29335. +
  29336. + default:
  29337. + WARN(1, "not supported\n");
  29338. + break;
  29339. + }
  29340. +
  29341. +release:
  29342. + vchiq_release_message(service->handle, header);
  29343. +done:
  29344. + return VCHIQ_SUCCESS;
  29345. +}
  29346. +
  29347. +static SHIM_SERVICE_T *service_alloc(VCHIQ_INSTANCE_T instance,
  29348. + SERVICE_CREATION_T *setup)
  29349. +{
  29350. + SHIM_SERVICE_T *service = kzalloc(sizeof(SHIM_SERVICE_T), GFP_KERNEL);
  29351. +
  29352. + (void)instance;
  29353. +
  29354. + if (service) {
  29355. + if (vchiu_queue_init(&service->queue, 64)) {
  29356. + service->callback = setup->callback;
  29357. + service->callback_param = setup->callback_param;
  29358. + } else {
  29359. + kfree(service);
  29360. + service = NULL;
  29361. + }
  29362. + }
  29363. +
  29364. + return service;
  29365. +}
  29366. +
  29367. +static void service_free(SHIM_SERVICE_T *service)
  29368. +{
  29369. + if (service) {
  29370. + vchiu_queue_delete(&service->queue);
  29371. + kfree(service);
  29372. + }
  29373. +}
  29374. +
  29375. +int32_t vchi_service_open(VCHI_INSTANCE_T instance_handle,
  29376. + SERVICE_CREATION_T *setup,
  29377. + VCHI_SERVICE_HANDLE_T *handle)
  29378. +{
  29379. + VCHIQ_INSTANCE_T instance = (VCHIQ_INSTANCE_T)instance_handle;
  29380. + SHIM_SERVICE_T *service = service_alloc(instance, setup);
  29381. + if (service) {
  29382. + VCHIQ_SERVICE_PARAMS_T params;
  29383. + VCHIQ_STATUS_T status;
  29384. +
  29385. + memset(&params, 0, sizeof(params));
  29386. + params.fourcc = setup->service_id;
  29387. + params.callback = shim_callback;
  29388. + params.userdata = service;
  29389. + params.version = setup->version.version;
  29390. + params.version_min = setup->version.version_min;
  29391. +
  29392. + status = vchiq_open_service(instance, &params,
  29393. + &service->handle);
  29394. + if (status != VCHIQ_SUCCESS) {
  29395. + service_free(service);
  29396. + service = NULL;
  29397. + }
  29398. + }
  29399. +
  29400. + *handle = (VCHI_SERVICE_HANDLE_T)service;
  29401. +
  29402. + return (service != NULL) ? 0 : -1;
  29403. +}
  29404. +EXPORT_SYMBOL(vchi_service_open);
  29405. +
  29406. +int32_t vchi_service_create(VCHI_INSTANCE_T instance_handle,
  29407. + SERVICE_CREATION_T *setup,
  29408. + VCHI_SERVICE_HANDLE_T *handle)
  29409. +{
  29410. + VCHIQ_INSTANCE_T instance = (VCHIQ_INSTANCE_T)instance_handle;
  29411. + SHIM_SERVICE_T *service = service_alloc(instance, setup);
  29412. + if (service) {
  29413. + VCHIQ_SERVICE_PARAMS_T params;
  29414. + VCHIQ_STATUS_T status;
  29415. +
  29416. + memset(&params, 0, sizeof(params));
  29417. + params.fourcc = setup->service_id;
  29418. + params.callback = shim_callback;
  29419. + params.userdata = service;
  29420. + params.version = setup->version.version;
  29421. + params.version_min = setup->version.version_min;
  29422. + status = vchiq_add_service(instance, &params, &service->handle);
  29423. +
  29424. + if (status != VCHIQ_SUCCESS) {
  29425. + service_free(service);
  29426. + service = NULL;
  29427. + }
  29428. + }
  29429. +
  29430. + *handle = (VCHI_SERVICE_HANDLE_T)service;
  29431. +
  29432. + return (service != NULL) ? 0 : -1;
  29433. +}
  29434. +EXPORT_SYMBOL(vchi_service_create);
  29435. +
  29436. +int32_t vchi_service_close(const VCHI_SERVICE_HANDLE_T handle)
  29437. +{
  29438. + int32_t ret = -1;
  29439. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  29440. + if (service) {
  29441. + VCHIQ_STATUS_T status = vchiq_close_service(service->handle);
  29442. + if (status == VCHIQ_SUCCESS) {
  29443. + service_free(service);
  29444. + service = NULL;
  29445. + }
  29446. +
  29447. + ret = vchiq_status_to_vchi(status);
  29448. + }
  29449. + return ret;
  29450. +}
  29451. +EXPORT_SYMBOL(vchi_service_close);
  29452. +
  29453. +int32_t vchi_service_destroy(const VCHI_SERVICE_HANDLE_T handle)
  29454. +{
  29455. + int32_t ret = -1;
  29456. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  29457. + if (service) {
  29458. + VCHIQ_STATUS_T status = vchiq_remove_service(service->handle);
  29459. + if (status == VCHIQ_SUCCESS) {
  29460. + service_free(service);
  29461. + service = NULL;
  29462. + }
  29463. +
  29464. + ret = vchiq_status_to_vchi(status);
  29465. + }
  29466. + return ret;
  29467. +}
  29468. +EXPORT_SYMBOL(vchi_service_destroy);
  29469. +
  29470. +int32_t vchi_get_peer_version( const VCHI_SERVICE_HANDLE_T handle, short *peer_version )
  29471. +{
  29472. + int32_t ret = -1;
  29473. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  29474. + if(service)
  29475. + {
  29476. + VCHIQ_STATUS_T status = vchiq_get_peer_version(service->handle, peer_version);
  29477. + ret = vchiq_status_to_vchi( status );
  29478. + }
  29479. + return ret;
  29480. +}
  29481. +EXPORT_SYMBOL(vchi_get_peer_version);
  29482. +
  29483. +/* ----------------------------------------------------------------------
  29484. + * read a uint32_t from buffer.
  29485. + * network format is defined to be little endian
  29486. + * -------------------------------------------------------------------- */
  29487. +uint32_t
  29488. +vchi_readbuf_uint32(const void *_ptr)
  29489. +{
  29490. + const unsigned char *ptr = _ptr;
  29491. + return ptr[0] | (ptr[1] << 8) | (ptr[2] << 16) | (ptr[3] << 24);
  29492. +}
  29493. +
  29494. +/* ----------------------------------------------------------------------
  29495. + * write a uint32_t to buffer.
  29496. + * network format is defined to be little endian
  29497. + * -------------------------------------------------------------------- */
  29498. +void
  29499. +vchi_writebuf_uint32(void *_ptr, uint32_t value)
  29500. +{
  29501. + unsigned char *ptr = _ptr;
  29502. + ptr[0] = (unsigned char)((value >> 0) & 0xFF);
  29503. + ptr[1] = (unsigned char)((value >> 8) & 0xFF);
  29504. + ptr[2] = (unsigned char)((value >> 16) & 0xFF);
  29505. + ptr[3] = (unsigned char)((value >> 24) & 0xFF);
  29506. +}
  29507. +
  29508. +/* ----------------------------------------------------------------------
  29509. + * read a uint16_t from buffer.
  29510. + * network format is defined to be little endian
  29511. + * -------------------------------------------------------------------- */
  29512. +uint16_t
  29513. +vchi_readbuf_uint16(const void *_ptr)
  29514. +{
  29515. + const unsigned char *ptr = _ptr;
  29516. + return ptr[0] | (ptr[1] << 8);
  29517. +}
  29518. +
  29519. +/* ----------------------------------------------------------------------
  29520. + * write a uint16_t into the buffer.
  29521. + * network format is defined to be little endian
  29522. + * -------------------------------------------------------------------- */
  29523. +void
  29524. +vchi_writebuf_uint16(void *_ptr, uint16_t value)
  29525. +{
  29526. + unsigned char *ptr = _ptr;
  29527. + ptr[0] = (value >> 0) & 0xFF;
  29528. + ptr[1] = (value >> 8) & 0xFF;
  29529. +}
  29530. +
  29531. +/***********************************************************
  29532. + * Name: vchi_service_use
  29533. + *
  29534. + * Arguments: const VCHI_SERVICE_HANDLE_T handle
  29535. + *
  29536. + * Description: Routine to increment refcount on a service
  29537. + *
  29538. + * Returns: void
  29539. + *
  29540. + ***********************************************************/
  29541. +int32_t vchi_service_use(const VCHI_SERVICE_HANDLE_T handle)
  29542. +{
  29543. + int32_t ret = -1;
  29544. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  29545. + if (service)
  29546. + ret = vchiq_status_to_vchi(vchiq_use_service(service->handle));
  29547. + return ret;
  29548. +}
  29549. +EXPORT_SYMBOL(vchi_service_use);
  29550. +
  29551. +/***********************************************************
  29552. + * Name: vchi_service_release
  29553. + *
  29554. + * Arguments: const VCHI_SERVICE_HANDLE_T handle
  29555. + *
  29556. + * Description: Routine to decrement refcount on a service
  29557. + *
  29558. + * Returns: void
  29559. + *
  29560. + ***********************************************************/
  29561. +int32_t vchi_service_release(const VCHI_SERVICE_HANDLE_T handle)
  29562. +{
  29563. + int32_t ret = -1;
  29564. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  29565. + if (service)
  29566. + ret = vchiq_status_to_vchi(
  29567. + vchiq_release_service(service->handle));
  29568. + return ret;
  29569. +}
  29570. +EXPORT_SYMBOL(vchi_service_release);
  29571. diff -Nur linux-3.13.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c
  29572. --- linux-3.13.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c 1970-01-01 01:00:00.000000000 +0100
  29573. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c 2014-04-24 15:35:02.893551516 +0200
  29574. @@ -0,0 +1,151 @@
  29575. +/**
  29576. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  29577. + *
  29578. + * Redistribution and use in source and binary forms, with or without
  29579. + * modification, are permitted provided that the following conditions
  29580. + * are met:
  29581. + * 1. Redistributions of source code must retain the above copyright
  29582. + * notice, this list of conditions, and the following disclaimer,
  29583. + * without modification.
  29584. + * 2. Redistributions in binary form must reproduce the above copyright
  29585. + * notice, this list of conditions and the following disclaimer in the
  29586. + * documentation and/or other materials provided with the distribution.
  29587. + * 3. The names of the above-listed copyright holders may not be used
  29588. + * to endorse or promote products derived from this software without
  29589. + * specific prior written permission.
  29590. + *
  29591. + * ALTERNATIVELY, this software may be distributed under the terms of the
  29592. + * GNU General Public License ("GPL") version 2, as published by the Free
  29593. + * Software Foundation.
  29594. + *
  29595. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  29596. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  29597. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  29598. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  29599. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  29600. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  29601. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  29602. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  29603. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  29604. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29605. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29606. + */
  29607. +
  29608. +#include "vchiq_util.h"
  29609. +
  29610. +static inline int is_pow2(int i)
  29611. +{
  29612. + return i && !(i & (i - 1));
  29613. +}
  29614. +
  29615. +int vchiu_queue_init(VCHIU_QUEUE_T *queue, int size)
  29616. +{
  29617. + WARN_ON(!is_pow2(size));
  29618. +
  29619. + queue->size = size;
  29620. + queue->read = 0;
  29621. + queue->write = 0;
  29622. +
  29623. + sema_init(&queue->pop, 0);
  29624. + sema_init(&queue->push, 0);
  29625. +
  29626. + queue->storage = kzalloc(size * sizeof(VCHIQ_HEADER_T *), GFP_KERNEL);
  29627. + if (queue->storage == NULL) {
  29628. + vchiu_queue_delete(queue);
  29629. + return 0;
  29630. + }
  29631. + return 1;
  29632. +}
  29633. +
  29634. +void vchiu_queue_delete(VCHIU_QUEUE_T *queue)
  29635. +{
  29636. + if (queue->storage != NULL)
  29637. + kfree(queue->storage);
  29638. +}
  29639. +
  29640. +int vchiu_queue_is_empty(VCHIU_QUEUE_T *queue)
  29641. +{
  29642. + return queue->read == queue->write;
  29643. +}
  29644. +
  29645. +int vchiu_queue_is_full(VCHIU_QUEUE_T *queue)
  29646. +{
  29647. + return queue->write == queue->read + queue->size;
  29648. +}
  29649. +
  29650. +void vchiu_queue_push(VCHIU_QUEUE_T *queue, VCHIQ_HEADER_T *header)
  29651. +{
  29652. + while (queue->write == queue->read + queue->size) {
  29653. + if (down_interruptible(&queue->pop) != 0) {
  29654. + flush_signals(current);
  29655. + }
  29656. + }
  29657. +
  29658. + /*
  29659. + * Write to queue->storage must be visible after read from
  29660. + * queue->read
  29661. + */
  29662. + smp_mb();
  29663. +
  29664. + queue->storage[queue->write & (queue->size - 1)] = header;
  29665. +
  29666. + /*
  29667. + * Write to queue->storage must be visible before write to
  29668. + * queue->write
  29669. + */
  29670. + smp_wmb();
  29671. +
  29672. + queue->write++;
  29673. +
  29674. + up(&queue->push);
  29675. +}
  29676. +
  29677. +VCHIQ_HEADER_T *vchiu_queue_peek(VCHIU_QUEUE_T *queue)
  29678. +{
  29679. + while (queue->write == queue->read) {
  29680. + if (down_interruptible(&queue->push) != 0) {
  29681. + flush_signals(current);
  29682. + }
  29683. + }
  29684. +
  29685. + up(&queue->push); // We haven't removed anything from the queue.
  29686. +
  29687. + /*
  29688. + * Read from queue->storage must be visible after read from
  29689. + * queue->write
  29690. + */
  29691. + smp_rmb();
  29692. +
  29693. + return queue->storage[queue->read & (queue->size - 1)];
  29694. +}
  29695. +
  29696. +VCHIQ_HEADER_T *vchiu_queue_pop(VCHIU_QUEUE_T *queue)
  29697. +{
  29698. + VCHIQ_HEADER_T *header;
  29699. +
  29700. + while (queue->write == queue->read) {
  29701. + if (down_interruptible(&queue->push) != 0) {
  29702. + flush_signals(current);
  29703. + }
  29704. + }
  29705. +
  29706. + /*
  29707. + * Read from queue->storage must be visible after read from
  29708. + * queue->write
  29709. + */
  29710. + smp_rmb();
  29711. +
  29712. + header = queue->storage[queue->read & (queue->size - 1)];
  29713. +
  29714. + /*
  29715. + * Read from queue->storage must be visible before write to
  29716. + * queue->read
  29717. + */
  29718. + smp_mb();
  29719. +
  29720. + queue->read++;
  29721. +
  29722. + up(&queue->pop);
  29723. +
  29724. + return header;
  29725. +}
  29726. diff -Nur linux-3.13.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.h
  29727. --- linux-3.13.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.h 1970-01-01 01:00:00.000000000 +0100
  29728. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.h 2014-04-24 15:36:51.710754091 +0200
  29729. @@ -0,0 +1,81 @@
  29730. +/**
  29731. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  29732. + *
  29733. + * Redistribution and use in source and binary forms, with or without
  29734. + * modification, are permitted provided that the following conditions
  29735. + * are met:
  29736. + * 1. Redistributions of source code must retain the above copyright
  29737. + * notice, this list of conditions, and the following disclaimer,
  29738. + * without modification.
  29739. + * 2. Redistributions in binary form must reproduce the above copyright
  29740. + * notice, this list of conditions and the following disclaimer in the
  29741. + * documentation and/or other materials provided with the distribution.
  29742. + * 3. The names of the above-listed copyright holders may not be used
  29743. + * to endorse or promote products derived from this software without
  29744. + * specific prior written permission.
  29745. + *
  29746. + * ALTERNATIVELY, this software may be distributed under the terms of the
  29747. + * GNU General Public License ("GPL") version 2, as published by the Free
  29748. + * Software Foundation.
  29749. + *
  29750. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  29751. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  29752. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  29753. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  29754. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  29755. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  29756. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  29757. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  29758. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  29759. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29760. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29761. + */
  29762. +
  29763. +#ifndef VCHIQ_UTIL_H
  29764. +#define VCHIQ_UTIL_H
  29765. +
  29766. +#include <linux/types.h>
  29767. +#include <linux/semaphore.h>
  29768. +#include <linux/mutex.h>
  29769. +#include <linux/bitops.h>
  29770. +#include <linux/kthread.h>
  29771. +#include <linux/wait.h>
  29772. +#include <linux/vmalloc.h>
  29773. +#include <linux/jiffies.h>
  29774. +#include <linux/delay.h>
  29775. +#include <linux/string.h>
  29776. +#include <linux/types.h>
  29777. +#include <linux/interrupt.h>
  29778. +#include <linux/random.h>
  29779. +#include <linux/sched.h>
  29780. +#include <linux/ctype.h>
  29781. +#include <linux/uaccess.h>
  29782. +#include <linux/time.h> /* for time_t */
  29783. +#include <linux/slab.h>
  29784. +#include <linux/vmalloc.h>
  29785. +
  29786. +#include "vchiq_if.h"
  29787. +
  29788. +typedef struct {
  29789. + int size;
  29790. + int read;
  29791. + int write;
  29792. +
  29793. + struct semaphore pop;
  29794. + struct semaphore push;
  29795. +
  29796. + VCHIQ_HEADER_T **storage;
  29797. +} VCHIU_QUEUE_T;
  29798. +
  29799. +extern int vchiu_queue_init(VCHIU_QUEUE_T *queue, int size);
  29800. +extern void vchiu_queue_delete(VCHIU_QUEUE_T *queue);
  29801. +
  29802. +extern int vchiu_queue_is_empty(VCHIU_QUEUE_T *queue);
  29803. +extern int vchiu_queue_is_full(VCHIU_QUEUE_T *queue);
  29804. +
  29805. +extern void vchiu_queue_push(VCHIU_QUEUE_T *queue, VCHIQ_HEADER_T *header);
  29806. +
  29807. +extern VCHIQ_HEADER_T *vchiu_queue_peek(VCHIU_QUEUE_T *queue);
  29808. +extern VCHIQ_HEADER_T *vchiu_queue_pop(VCHIU_QUEUE_T *queue);
  29809. +
  29810. +#endif
  29811. diff -Nur linux-3.13.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_version.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_version.c
  29812. --- linux-3.13.11/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_version.c 1970-01-01 01:00:00.000000000 +0100
  29813. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_version.c 2014-04-24 15:35:02.893551516 +0200
  29814. @@ -0,0 +1,59 @@
  29815. +/**
  29816. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  29817. + *
  29818. + * Redistribution and use in source and binary forms, with or without
  29819. + * modification, are permitted provided that the following conditions
  29820. + * are met:
  29821. + * 1. Redistributions of source code must retain the above copyright
  29822. + * notice, this list of conditions, and the following disclaimer,
  29823. + * without modification.
  29824. + * 2. Redistributions in binary form must reproduce the above copyright
  29825. + * notice, this list of conditions and the following disclaimer in the
  29826. + * documentation and/or other materials provided with the distribution.
  29827. + * 3. The names of the above-listed copyright holders may not be used
  29828. + * to endorse or promote products derived from this software without
  29829. + * specific prior written permission.
  29830. + *
  29831. + * ALTERNATIVELY, this software may be distributed under the terms of the
  29832. + * GNU General Public License ("GPL") version 2, as published by the Free
  29833. + * Software Foundation.
  29834. + *
  29835. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  29836. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  29837. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  29838. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  29839. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  29840. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  29841. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  29842. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  29843. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  29844. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29845. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29846. + */
  29847. +#include "vchiq_build_info.h"
  29848. +#include <linux/broadcom/vc_debug_sym.h>
  29849. +
  29850. +VC_DEBUG_DECLARE_STRING_VAR( vchiq_build_hostname, "dc4-arm-01" );
  29851. +VC_DEBUG_DECLARE_STRING_VAR( vchiq_build_version, "9245b4c35b99b3870e1f7dc598c5692b3c66a6f0 (tainted)" );
  29852. +VC_DEBUG_DECLARE_STRING_VAR( vchiq_build_time, __TIME__ );
  29853. +VC_DEBUG_DECLARE_STRING_VAR( vchiq_build_date, __DATE__ );
  29854. +
  29855. +const char *vchiq_get_build_hostname( void )
  29856. +{
  29857. + return vchiq_build_hostname;
  29858. +}
  29859. +
  29860. +const char *vchiq_get_build_version( void )
  29861. +{
  29862. + return vchiq_build_version;
  29863. +}
  29864. +
  29865. +const char *vchiq_get_build_date( void )
  29866. +{
  29867. + return vchiq_build_date;
  29868. +}
  29869. +
  29870. +const char *vchiq_get_build_time( void )
  29871. +{
  29872. + return vchiq_build_time;
  29873. +}
  29874. diff -Nur linux-3.13.11/drivers/misc/vc04_services/Kconfig linux-rpi/drivers/misc/vc04_services/Kconfig
  29875. --- linux-3.13.11/drivers/misc/vc04_services/Kconfig 1970-01-01 01:00:00.000000000 +0100
  29876. +++ linux-rpi/drivers/misc/vc04_services/Kconfig 2014-04-24 15:36:51.710754091 +0200
  29877. @@ -0,0 +1,9 @@
  29878. +config BCM2708_VCHIQ
  29879. + tristate "Videocore VCHIQ"
  29880. + depends on MACH_BCM2708
  29881. + default y
  29882. + help
  29883. + Kernel to VideoCore communication interface for the
  29884. + BCM2708 family of products.
  29885. + Defaults to Y when the Broadcom Videocore services
  29886. + are included in the build, N otherwise.
  29887. diff -Nur linux-3.13.11/drivers/misc/vc04_services/Makefile linux-rpi/drivers/misc/vc04_services/Makefile
  29888. --- linux-3.13.11/drivers/misc/vc04_services/Makefile 1970-01-01 01:00:00.000000000 +0100
  29889. +++ linux-rpi/drivers/misc/vc04_services/Makefile 2014-04-24 15:36:51.710754091 +0200
  29890. @@ -0,0 +1,17 @@
  29891. +ifeq ($(CONFIG_MACH_BCM2708),y)
  29892. +
  29893. +obj-$(CONFIG_BCM2708_VCHIQ) += vchiq.o
  29894. +
  29895. +vchiq-objs := \
  29896. + interface/vchiq_arm/vchiq_core.o \
  29897. + interface/vchiq_arm/vchiq_arm.o \
  29898. + interface/vchiq_arm/vchiq_kern_lib.o \
  29899. + interface/vchiq_arm/vchiq_2835_arm.o \
  29900. + interface/vchiq_arm/vchiq_proc.o \
  29901. + interface/vchiq_arm/vchiq_shim.o \
  29902. + interface/vchiq_arm/vchiq_util.o \
  29903. + interface/vchiq_arm/vchiq_connected.o \
  29904. +
  29905. +ccflags-y += -DVCOS_VERIFY_BKPTS=1 -Idrivers/misc/vc04_services -DUSE_VCHIQ_ARM -D__VCCOREVER__=0x04000000
  29906. +
  29907. +endif
  29908. diff -Nur linux-3.13.11/drivers/mmc/card/block.c linux-rpi/drivers/mmc/card/block.c
  29909. --- linux-3.13.11/drivers/mmc/card/block.c 2014-04-23 01:49:33.000000000 +0200
  29910. +++ linux-rpi/drivers/mmc/card/block.c 2014-04-24 15:36:51.714754135 +0200
  29911. @@ -1361,7 +1361,7 @@
  29912. brq->data.blocks = 1;
  29913. }
  29914. - if (brq->data.blocks > 1 || do_rel_wr) {
  29915. + if (brq->data.blocks > 1 || do_rel_wr || card->host->caps2 & MMC_CAP2_FORCE_MULTIBLOCK) {
  29916. /* SPI multiblock writes terminate using a special
  29917. * token, not a STOP_TRANSMISSION request.
  29918. */
  29919. diff -Nur linux-3.13.11/drivers/mmc/core/sd.c linux-rpi/drivers/mmc/core/sd.c
  29920. --- linux-3.13.11/drivers/mmc/core/sd.c 2014-04-23 01:49:33.000000000 +0200
  29921. +++ linux-rpi/drivers/mmc/core/sd.c 2014-04-24 15:36:51.718754179 +0200
  29922. @@ -15,6 +15,8 @@
  29923. #include <linux/slab.h>
  29924. #include <linux/stat.h>
  29925. #include <linux/pm_runtime.h>
  29926. +#include <linux/jiffies.h>
  29927. +#include <linux/nmi.h>
  29928. #include <linux/mmc/host.h>
  29929. #include <linux/mmc/card.h>
  29930. @@ -67,6 +69,15 @@
  29931. __res & __mask; \
  29932. })
  29933. +// timeout for tries
  29934. +static const unsigned long retry_timeout_ms= 10*1000;
  29935. +
  29936. +// try at least 10 times, even if timeout is reached
  29937. +static const int retry_min_tries= 10;
  29938. +
  29939. +// delay between tries
  29940. +static const unsigned long retry_delay_ms= 10;
  29941. +
  29942. /*
  29943. * Given the decoded CSD structure, decode the raw CID to our CID structure.
  29944. */
  29945. @@ -219,12 +230,63 @@
  29946. }
  29947. /*
  29948. - * Fetch and process SD Status register.
  29949. + * Fetch and process SD Configuration Register.
  29950. + */
  29951. +static int mmc_read_scr(struct mmc_card *card)
  29952. +{
  29953. + unsigned long timeout_at;
  29954. + int err, tries;
  29955. +
  29956. + timeout_at= jiffies + msecs_to_jiffies( retry_timeout_ms );
  29957. + tries= 0;
  29958. +
  29959. + while( tries < retry_min_tries || time_before( jiffies, timeout_at ) )
  29960. + {
  29961. + unsigned long delay_at;
  29962. + tries++;
  29963. +
  29964. + err = mmc_app_send_scr(card, card->raw_scr);
  29965. + if( !err )
  29966. + break; // success!!!
  29967. +
  29968. + touch_nmi_watchdog(); // we are still alive!
  29969. +
  29970. + // delay
  29971. + delay_at= jiffies + msecs_to_jiffies( retry_delay_ms );
  29972. + while( time_before( jiffies, delay_at ) )
  29973. + {
  29974. + mdelay( 1 );
  29975. + touch_nmi_watchdog(); // we are still alive!
  29976. + }
  29977. + }
  29978. +
  29979. + if( err)
  29980. + {
  29981. + 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 );
  29982. + return err;
  29983. + }
  29984. +
  29985. + if( tries > 1 )
  29986. + {
  29987. + pr_info("%s: could read SD Configuration register (SCR) at the %dth attempt\n", mmc_hostname(card->host), tries );
  29988. + }
  29989. +
  29990. + err = mmc_decode_scr(card);
  29991. + if (err)
  29992. + return err;
  29993. +
  29994. + return err;
  29995. +}
  29996. +
  29997. +/*
  29998. + * Fetch and process SD Status Register.
  29999. */
  30000. static int mmc_read_ssr(struct mmc_card *card)
  30001. {
  30002. + unsigned long timeout_at;
  30003. unsigned int au, es, et, eo;
  30004. int err, i;
  30005. + int tries;
  30006. u32 *ssr;
  30007. if (!(card->csd.cmdclass & CCC_APP_SPEC)) {
  30008. @@ -237,14 +299,40 @@
  30009. if (!ssr)
  30010. return -ENOMEM;
  30011. - err = mmc_app_sd_status(card, ssr);
  30012. - if (err) {
  30013. - pr_warning("%s: problem reading SD Status "
  30014. - "register.\n", mmc_hostname(card->host));
  30015. - err = 0;
  30016. + timeout_at= jiffies + msecs_to_jiffies( retry_timeout_ms );
  30017. + tries= 0;
  30018. +
  30019. + while( tries < retry_min_tries || time_before( jiffies, timeout_at ) )
  30020. + {
  30021. + unsigned long delay_at;
  30022. + tries++;
  30023. +
  30024. + err= mmc_app_sd_status(card, ssr);
  30025. + if( !err )
  30026. + break; // sucess!!!
  30027. +
  30028. + touch_nmi_watchdog(); // we are still alive!
  30029. +
  30030. + // delay
  30031. + delay_at= jiffies + msecs_to_jiffies( retry_delay_ms );
  30032. + while( time_before( jiffies, delay_at ) )
  30033. + {
  30034. + mdelay( 1 );
  30035. + touch_nmi_watchdog(); // we are still alive!
  30036. + }
  30037. + }
  30038. +
  30039. + if( err)
  30040. + {
  30041. + 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 );
  30042. goto out;
  30043. }
  30044. + if( tries > 1 )
  30045. + {
  30046. + pr_info("%s: read SD Status register (SSR) after %d attempts\n", mmc_hostname(card->host), tries );
  30047. + }
  30048. +
  30049. for (i = 0; i < 16; i++)
  30050. ssr[i] = be32_to_cpu(ssr[i]);
  30051. @@ -826,14 +914,10 @@
  30052. if (!reinit) {
  30053. /*
  30054. - * Fetch SCR from card.
  30055. + * Fetch and decode SD Configuration register.
  30056. */
  30057. - err = mmc_app_send_scr(card, card->raw_scr);
  30058. - if (err)
  30059. - return err;
  30060. -
  30061. - err = mmc_decode_scr(card);
  30062. - if (err)
  30063. + err = mmc_read_scr(card);
  30064. + if( err )
  30065. return err;
  30066. /*
  30067. diff -Nur linux-3.13.11/drivers/mmc/host/Kconfig linux-rpi/drivers/mmc/host/Kconfig
  30068. --- linux-3.13.11/drivers/mmc/host/Kconfig 2014-04-23 01:49:33.000000000 +0200
  30069. +++ linux-rpi/drivers/mmc/host/Kconfig 2014-04-24 15:36:51.718754179 +0200
  30070. @@ -260,6 +260,27 @@
  30071. If you have a controller with this interface, say Y or M here.
  30072. +config MMC_SDHCI_BCM2708
  30073. + tristate "SDHCI support on BCM2708"
  30074. + depends on MMC_SDHCI && MACH_BCM2708
  30075. + select MMC_SDHCI_IO_ACCESSORS
  30076. + help
  30077. + This selects the Secure Digital Host Controller Interface (SDHCI)
  30078. + often referrered to as the eMMC block.
  30079. +
  30080. + If you have a controller with this interface, say Y or M here.
  30081. +
  30082. + If unsure, say N.
  30083. +
  30084. +config MMC_SDHCI_BCM2708_DMA
  30085. + bool "DMA support on BCM2708 Arasan controller"
  30086. + depends on MMC_SDHCI_BCM2708
  30087. + help
  30088. + Enable DMA support on the Arasan SDHCI controller in Broadcom 2708
  30089. + based chips.
  30090. +
  30091. + If unsure, say N.
  30092. +
  30093. config MMC_SDHCI_BCM2835
  30094. tristate "SDHCI platform support for the BCM2835 SD/MMC Controller"
  30095. depends on ARCH_BCM2835
  30096. diff -Nur linux-3.13.11/drivers/mmc/host/Makefile linux-rpi/drivers/mmc/host/Makefile
  30097. --- linux-3.13.11/drivers/mmc/host/Makefile 2014-04-23 01:49:33.000000000 +0200
  30098. +++ linux-rpi/drivers/mmc/host/Makefile 2014-04-24 15:36:51.718754179 +0200
  30099. @@ -15,6 +15,7 @@
  30100. obj-$(CONFIG_MMC_SDHCI_S3C) += sdhci-s3c.o
  30101. obj-$(CONFIG_MMC_SDHCI_SIRF) += sdhci-sirf.o
  30102. obj-$(CONFIG_MMC_SDHCI_SPEAR) += sdhci-spear.o
  30103. +obj-$(CONFIG_MMC_SDHCI_BCM2708) += sdhci-bcm2708.o
  30104. obj-$(CONFIG_MMC_WBSD) += wbsd.o
  30105. obj-$(CONFIG_MMC_AU1X) += au1xmmc.o
  30106. obj-$(CONFIG_MMC_OMAP) += omap.o
  30107. diff -Nur linux-3.13.11/drivers/mmc/host/sdhci-bcm2708.c linux-rpi/drivers/mmc/host/sdhci-bcm2708.c
  30108. --- linux-3.13.11/drivers/mmc/host/sdhci-bcm2708.c 1970-01-01 01:00:00.000000000 +0100
  30109. +++ linux-rpi/drivers/mmc/host/sdhci-bcm2708.c 2014-04-24 15:36:51.726754267 +0200
  30110. @@ -0,0 +1,1410 @@
  30111. +/*
  30112. + * sdhci-bcm2708.c Support for SDHCI device on BCM2708
  30113. + * Copyright (c) 2010 Broadcom
  30114. + *
  30115. + * This program is free software; you can redistribute it and/or modify
  30116. + * it under the terms of the GNU General Public License version 2 as
  30117. + * published by the Free Software Foundation.
  30118. + *
  30119. + * This program is distributed in the hope that it will be useful,
  30120. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  30121. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  30122. + * GNU General Public License for more details.
  30123. + *
  30124. + * You should have received a copy of the GNU General Public License
  30125. + * along with this program; if not, write to the Free Software
  30126. + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  30127. + */
  30128. +
  30129. +/* Supports:
  30130. + * SDHCI platform device - Arasan SD controller in BCM2708
  30131. + *
  30132. + * Inspired by sdhci-pci.c, by Pierre Ossman
  30133. + */
  30134. +
  30135. +#include <linux/delay.h>
  30136. +#include <linux/highmem.h>
  30137. +#include <linux/platform_device.h>
  30138. +#include <linux/module.h>
  30139. +#include <linux/mmc/mmc.h>
  30140. +#include <linux/mmc/host.h>
  30141. +#include <linux/mmc/sd.h>
  30142. +
  30143. +#include <linux/io.h>
  30144. +#include <linux/dma-mapping.h>
  30145. +#include <mach/dma.h>
  30146. +
  30147. +#include "sdhci.h"
  30148. +
  30149. +/*****************************************************************************\
  30150. + * *
  30151. + * Configuration *
  30152. + * *
  30153. +\*****************************************************************************/
  30154. +
  30155. +#define DRIVER_NAME "bcm2708_sdhci"
  30156. +
  30157. +/* for the time being insist on DMA mode - PIO seems not to work */
  30158. +#ifndef CONFIG_MMC_SDHCI_BCM2708_DMA
  30159. +#warning Non-DMA (PIO) version of this driver currently unavailable
  30160. +#endif
  30161. +#undef CONFIG_MMC_SDHCI_BCM2708_DMA
  30162. +#define CONFIG_MMC_SDHCI_BCM2708_DMA y
  30163. +
  30164. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  30165. +/* #define CHECK_DMA_USE */
  30166. +#endif
  30167. +//#define LOG_REGISTERS
  30168. +
  30169. +#define USE_SCHED_TIME
  30170. +#define USE_SPACED_WRITES_2CLK 1 /* space consecutive register writes */
  30171. +#define USE_SOFTWARE_TIMEOUTS 1 /* not hardware timeouts */
  30172. +#define SOFTWARE_ERASE_TIMEOUT_SEC 30
  30173. +
  30174. +#define SDHCI_BCM_DMA_CHAN 4 /* this default is normally overriden */
  30175. +#define SDHCI_BCM_DMA_WAITS 0 /* delays slowing DMA transfers: 0-31 */
  30176. +/* We are worried that SD card DMA use may be blocking the AXI bus for others */
  30177. +
  30178. +/*! TODO: obtain these from the physical address */
  30179. +#define DMA_SDHCI_BASE 0x7e300000 /* EMMC register block on Videocore */
  30180. +#define DMA_SDHCI_BUFFER (DMA_SDHCI_BASE + SDHCI_BUFFER)
  30181. +
  30182. +#define BCM2708_SDHCI_SLEEP_TIMEOUT 1000 /* msecs */
  30183. +
  30184. +/* Mhz clock that the EMMC core is running at. Should match the platform clockman settings */
  30185. +#define BCM2708_EMMC_CLOCK_FREQ 50000000
  30186. +
  30187. +#define REG_EXRDFIFO_EN 0x80
  30188. +#define REG_EXRDFIFO_CFG 0x84
  30189. +
  30190. +int cycle_delay=2;
  30191. +
  30192. +/*****************************************************************************\
  30193. + * *
  30194. + * Debug *
  30195. + * *
  30196. +\*****************************************************************************/
  30197. +
  30198. +
  30199. +
  30200. +#define DBG(f, x...) \
  30201. + pr_debug(DRIVER_NAME " [%s()]: " f, __func__,## x)
  30202. +// printk(KERN_INFO DRIVER_NAME " [%s()]: " f, __func__,## x)//GRAYG
  30203. +
  30204. +
  30205. +/*****************************************************************************\
  30206. + * *
  30207. + * High Precision Time *
  30208. + * *
  30209. +\*****************************************************************************/
  30210. +
  30211. +#ifdef USE_SCHED_TIME
  30212. +
  30213. +#include <mach/frc.h>
  30214. +
  30215. +typedef unsigned long hptime_t;
  30216. +
  30217. +#define FMT_HPT "lu"
  30218. +
  30219. +static inline hptime_t hptime(void)
  30220. +{
  30221. + return frc_clock_ticks32();
  30222. +}
  30223. +
  30224. +#define HPTIME_CLK_NS 1000ul
  30225. +
  30226. +#else
  30227. +
  30228. +typedef unsigned long hptime_t;
  30229. +
  30230. +#define FMT_HPT "lu"
  30231. +
  30232. +static inline hptime_t hptime(void)
  30233. +{
  30234. + return jiffies;
  30235. +}
  30236. +
  30237. +#define HPTIME_CLK_NS (1000000000ul/HZ)
  30238. +
  30239. +#endif
  30240. +
  30241. +static inline unsigned long int since_ns(hptime_t t)
  30242. +{
  30243. + return (unsigned long)((hptime() - t) * HPTIME_CLK_NS);
  30244. +}
  30245. +
  30246. +static bool allow_highspeed = 1;
  30247. +static int emmc_clock_freq = BCM2708_EMMC_CLOCK_FREQ;
  30248. +static bool sync_after_dma = 1;
  30249. +static bool missing_status = 1;
  30250. +static bool spurious_crc_acmd51 = 0;
  30251. +bool enable_llm = 1;
  30252. +bool extra_messages = 0;
  30253. +
  30254. +#if 0
  30255. +static void hptime_test(void)
  30256. +{
  30257. + hptime_t now;
  30258. + hptime_t later;
  30259. +
  30260. + now = hptime();
  30261. + msleep(10);
  30262. + later = hptime();
  30263. +
  30264. + printk(KERN_INFO DRIVER_NAME": 10ms = %"FMT_HPT" clks "
  30265. + "(from %"FMT_HPT" to %"FMT_HPT") = %luns\n",
  30266. + later-now, now, later,
  30267. + (unsigned long)(HPTIME_CLK_NS * (later - now)));
  30268. +
  30269. + now = hptime();
  30270. + msleep(1000);
  30271. + later = hptime();
  30272. +
  30273. + printk(KERN_INFO DRIVER_NAME": 1s = %"FMT_HPT" clks "
  30274. + "(from %"FMT_HPT" to %"FMT_HPT") = %luns\n",
  30275. + later-now, now, later,
  30276. + (unsigned long)(HPTIME_CLK_NS * (later - now)));
  30277. +}
  30278. +#endif
  30279. +
  30280. +/*****************************************************************************\
  30281. + * *
  30282. + * SDHCI core callbacks *
  30283. + * *
  30284. +\*****************************************************************************/
  30285. +
  30286. +
  30287. +#ifdef CHECK_DMA_USE
  30288. +/*#define CHECK_DMA_REG_USE*/
  30289. +#endif
  30290. +
  30291. +#ifdef CHECK_DMA_REG_USE
  30292. +/* we don't expect anything to be using these registers during a
  30293. + DMA (except the IRQ status) - so check */
  30294. +static void check_dma_reg_use(struct sdhci_host *host, int reg);
  30295. +#else
  30296. +#define check_dma_reg_use(host, reg)
  30297. +#endif
  30298. +
  30299. +
  30300. +static inline u32 sdhci_bcm2708_raw_readl(struct sdhci_host *host, int reg)
  30301. +{
  30302. + return readl(host->ioaddr + reg);
  30303. +}
  30304. +
  30305. +u32 sdhci_bcm2708_readl(struct sdhci_host *host, int reg)
  30306. +{
  30307. + u32 l = sdhci_bcm2708_raw_readl(host, reg);
  30308. +
  30309. +#ifdef LOG_REGISTERS
  30310. + printk(KERN_ERR "%s: readl from 0x%02x, value 0x%08x\n",
  30311. + mmc_hostname(host->mmc), reg, l);
  30312. +#endif
  30313. + check_dma_reg_use(host, reg);
  30314. +
  30315. + return l;
  30316. +}
  30317. +
  30318. +u16 sdhci_bcm2708_readw(struct sdhci_host *host, int reg)
  30319. +{
  30320. + u32 l = sdhci_bcm2708_raw_readl(host, reg & ~3);
  30321. + u32 w = l >> (reg << 3 & 0x18) & 0xffff;
  30322. +
  30323. +#ifdef LOG_REGISTERS
  30324. + printk(KERN_ERR "%s: readw from 0x%02x, value 0x%04x\n",
  30325. + mmc_hostname(host->mmc), reg, w);
  30326. +#endif
  30327. + check_dma_reg_use(host, reg);
  30328. +
  30329. + return (u16)w;
  30330. +}
  30331. +
  30332. +u8 sdhci_bcm2708_readb(struct sdhci_host *host, int reg)
  30333. +{
  30334. + u32 l = sdhci_bcm2708_raw_readl(host, reg & ~3);
  30335. + u32 b = l >> (reg << 3 & 0x18) & 0xff;
  30336. +
  30337. +#ifdef LOG_REGISTERS
  30338. + printk(KERN_ERR "%s: readb from 0x%02x, value 0x%02x\n",
  30339. + mmc_hostname(host->mmc), reg, b);
  30340. +#endif
  30341. + check_dma_reg_use(host, reg);
  30342. +
  30343. + return (u8)b;
  30344. +}
  30345. +
  30346. +
  30347. +static void sdhci_bcm2708_raw_writel(struct sdhci_host *host, u32 val, int reg)
  30348. +{
  30349. + u32 ier;
  30350. +
  30351. +#if USE_SPACED_WRITES_2CLK
  30352. + static bool timeout_disabled = false;
  30353. + unsigned int ns_2clk = 0;
  30354. +
  30355. + /* The Arasan has a bugette whereby it may lose the content of
  30356. + * successive writes to registers that are within two SD-card clock
  30357. + * cycles of each other (a clock domain crossing problem).
  30358. + * It seems, however, that the data register does not have this problem.
  30359. + * (Which is just as well - otherwise we'd have to nobble the DMA engine
  30360. + * too)
  30361. + */
  30362. + if (reg != SDHCI_BUFFER && host->clock != 0) {
  30363. + /* host->clock is the clock freq in Hz */
  30364. + static hptime_t last_write_hpt;
  30365. + hptime_t now = hptime();
  30366. + ns_2clk = cycle_delay*1000000/(host->clock/1000);
  30367. +
  30368. + if (now == last_write_hpt || now == last_write_hpt+1) {
  30369. + /* we can't guarantee any significant time has
  30370. + * passed - we'll have to wait anyway ! */
  30371. + ndelay(ns_2clk);
  30372. + } else
  30373. + {
  30374. + /* we must have waited at least this many ns: */
  30375. + unsigned int ns_wait = HPTIME_CLK_NS *
  30376. + (now - last_write_hpt - 1);
  30377. + if (ns_wait < ns_2clk)
  30378. + ndelay(ns_2clk - ns_wait);
  30379. + }
  30380. + last_write_hpt = now;
  30381. + }
  30382. +#if USE_SOFTWARE_TIMEOUTS
  30383. + /* The Arasan is clocked for timeouts using the SD clock which is too
  30384. + * fast for ERASE commands and causes issues. So we disable timeouts
  30385. + * for ERASE */
  30386. + if (host->cmd != NULL && host->cmd->opcode == MMC_ERASE &&
  30387. + reg == (SDHCI_COMMAND & ~3)) {
  30388. + mod_timer(&host->timer,
  30389. + jiffies + SOFTWARE_ERASE_TIMEOUT_SEC * HZ);
  30390. + ier = readl(host->ioaddr + SDHCI_SIGNAL_ENABLE);
  30391. + ier &= ~SDHCI_INT_DATA_TIMEOUT;
  30392. + writel(ier, host->ioaddr + SDHCI_SIGNAL_ENABLE);
  30393. + timeout_disabled = true;
  30394. + ndelay(ns_2clk);
  30395. + } else if (timeout_disabled) {
  30396. + ier = readl(host->ioaddr + SDHCI_SIGNAL_ENABLE);
  30397. + ier |= SDHCI_INT_DATA_TIMEOUT;
  30398. + writel(ier, host->ioaddr + SDHCI_SIGNAL_ENABLE);
  30399. + timeout_disabled = false;
  30400. + ndelay(ns_2clk);
  30401. + }
  30402. +#endif
  30403. + writel(val, host->ioaddr + reg);
  30404. +#else
  30405. + void __iomem * regaddr = host->ioaddr + reg;
  30406. +
  30407. + writel(val, regaddr);
  30408. +
  30409. + if (reg != SDHCI_BUFFER && reg != SDHCI_INT_STATUS && host->clock != 0)
  30410. + {
  30411. + int timeout = 100000;
  30412. + while (val != readl(regaddr) && --timeout > 0)
  30413. + continue;
  30414. +
  30415. + if (timeout <= 0)
  30416. + printk(KERN_ERR "%s: writing 0x%X to reg 0x%X "
  30417. + "always gives 0x%X\n",
  30418. + mmc_hostname(host->mmc),
  30419. + val, reg, readl(regaddr));
  30420. + BUG_ON(timeout <= 0);
  30421. + }
  30422. +#endif
  30423. +}
  30424. +
  30425. +
  30426. +void sdhci_bcm2708_writel(struct sdhci_host *host, u32 val, int reg)
  30427. +{
  30428. +#ifdef LOG_REGISTERS
  30429. + printk(KERN_ERR "%s: writel to 0x%02x, value 0x%08x\n",
  30430. + mmc_hostname(host->mmc), reg, val);
  30431. +#endif
  30432. + check_dma_reg_use(host, reg);
  30433. +
  30434. + sdhci_bcm2708_raw_writel(host, val, reg);
  30435. +}
  30436. +
  30437. +void sdhci_bcm2708_writew(struct sdhci_host *host, u16 val, int reg)
  30438. +{
  30439. + static u32 shadow = 0;
  30440. +
  30441. + u32 p = reg == SDHCI_COMMAND ? shadow :
  30442. + sdhci_bcm2708_raw_readl(host, reg & ~3);
  30443. + u32 s = reg << 3 & 0x18;
  30444. + u32 l = val << s;
  30445. + u32 m = 0xffff << s;
  30446. +
  30447. +#ifdef LOG_REGISTERS
  30448. + printk(KERN_ERR "%s: writew to 0x%02x, value 0x%04x\n",
  30449. + mmc_hostname(host->mmc), reg, val);
  30450. +#endif
  30451. +
  30452. + if (reg == SDHCI_TRANSFER_MODE)
  30453. + shadow = (p & ~m) | l;
  30454. + else {
  30455. + check_dma_reg_use(host, reg);
  30456. + sdhci_bcm2708_raw_writel(host, (p & ~m) | l, reg & ~3);
  30457. + }
  30458. +}
  30459. +
  30460. +void sdhci_bcm2708_writeb(struct sdhci_host *host, u8 val, int reg)
  30461. +{
  30462. + u32 p = sdhci_bcm2708_raw_readl(host, reg & ~3);
  30463. + u32 s = reg << 3 & 0x18;
  30464. + u32 l = val << s;
  30465. + u32 m = 0xff << s;
  30466. +
  30467. +#ifdef LOG_REGISTERS
  30468. + printk(KERN_ERR "%s: writeb to 0x%02x, value 0x%02x\n",
  30469. + mmc_hostname(host->mmc), reg, val);
  30470. +#endif
  30471. +
  30472. + check_dma_reg_use(host, reg);
  30473. + sdhci_bcm2708_raw_writel(host, (p & ~m) | l, reg & ~3);
  30474. +}
  30475. +
  30476. +static unsigned int sdhci_bcm2708_get_max_clock(struct sdhci_host *host)
  30477. +{
  30478. + return emmc_clock_freq;
  30479. +}
  30480. +
  30481. +/*****************************************************************************\
  30482. + * *
  30483. + * DMA Operation *
  30484. + * *
  30485. +\*****************************************************************************/
  30486. +
  30487. +struct sdhci_bcm2708_priv {
  30488. + int dma_chan;
  30489. + int dma_irq;
  30490. + void __iomem *dma_chan_base;
  30491. + struct bcm2708_dma_cb *cb_base; /* DMA control blocks */
  30492. + dma_addr_t cb_handle;
  30493. + /* tracking scatter gather progress */
  30494. + unsigned sg_ix; /* scatter gather list index */
  30495. + unsigned sg_done; /* bytes in current sg_ix done */
  30496. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  30497. + unsigned char dma_wanted; /* DMA transfer requested */
  30498. + unsigned char dma_waits; /* wait states in DMAs */
  30499. +#ifdef CHECK_DMA_USE
  30500. + unsigned char dmas_pending; /* no of unfinished DMAs */
  30501. + hptime_t when_started;
  30502. + hptime_t when_reset;
  30503. + hptime_t when_stopped;
  30504. +#endif
  30505. +#endif
  30506. + /* signalling the end of a transfer */
  30507. + void (*complete)(struct sdhci_host *);
  30508. +};
  30509. +
  30510. +#define SDHCI_HOST_PRIV(host) \
  30511. + (struct sdhci_bcm2708_priv *)((struct sdhci_host *)(host)+1)
  30512. +
  30513. +
  30514. +
  30515. +#ifdef CHECK_DMA_REG_USE
  30516. +static void check_dma_reg_use(struct sdhci_host *host, int reg)
  30517. +{
  30518. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  30519. + if (host_priv->dma_wanted && reg != SDHCI_INT_STATUS) {
  30520. + printk(KERN_INFO"%s: accessing register 0x%x during DMA\n",
  30521. + mmc_hostname(host->mmc), reg);
  30522. + }
  30523. +}
  30524. +#endif
  30525. +
  30526. +
  30527. +
  30528. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  30529. +
  30530. +static void sdhci_clear_set_irqgen(struct sdhci_host *host, u32 clear, u32 set)
  30531. +{
  30532. + u32 ier;
  30533. +
  30534. + ier = sdhci_bcm2708_raw_readl(host, SDHCI_SIGNAL_ENABLE);
  30535. + ier &= ~clear;
  30536. + ier |= set;
  30537. + /* change which requests generate IRQs - makes no difference to
  30538. + the content of SDHCI_INT_STATUS, or the need to acknowledge IRQs */
  30539. + sdhci_bcm2708_raw_writel(host, ier, SDHCI_SIGNAL_ENABLE);
  30540. +}
  30541. +
  30542. +static void sdhci_signal_irqs(struct sdhci_host *host, u32 irqs)
  30543. +{
  30544. + sdhci_clear_set_irqgen(host, 0, irqs);
  30545. +}
  30546. +
  30547. +static void sdhci_unsignal_irqs(struct sdhci_host *host, u32 irqs)
  30548. +{
  30549. + sdhci_clear_set_irqgen(host, irqs, 0);
  30550. +}
  30551. +
  30552. +
  30553. +
  30554. +static void schci_bcm2708_cb_read(struct sdhci_bcm2708_priv *host,
  30555. + int ix,
  30556. + dma_addr_t dma_addr, unsigned len,
  30557. + int /*bool*/ is_last)
  30558. +{
  30559. + struct bcm2708_dma_cb *cb = &host->cb_base[ix];
  30560. + unsigned char dmawaits = host->dma_waits;
  30561. +
  30562. + cb->info = BCM2708_DMA_PER_MAP(BCM2708_DMA_DREQ_EMMC) |
  30563. + BCM2708_DMA_WAITS(dmawaits) |
  30564. + BCM2708_DMA_S_DREQ |
  30565. + BCM2708_DMA_D_WIDTH |
  30566. + BCM2708_DMA_D_INC;
  30567. + cb->src = DMA_SDHCI_BUFFER; /* DATA register DMA address */
  30568. + cb->dst = dma_addr;
  30569. + cb->length = len;
  30570. + cb->stride = 0;
  30571. +
  30572. + if (is_last) {
  30573. + cb->info |= BCM2708_DMA_INT_EN |
  30574. + BCM2708_DMA_WAIT_RESP;
  30575. + cb->next = 0;
  30576. + } else
  30577. + cb->next = host->cb_handle +
  30578. + (ix+1)*sizeof(struct bcm2708_dma_cb);
  30579. +
  30580. + cb->pad[0] = 0;
  30581. + cb->pad[1] = 0;
  30582. +}
  30583. +
  30584. +static void schci_bcm2708_cb_write(struct sdhci_bcm2708_priv *host,
  30585. + int ix,
  30586. + dma_addr_t dma_addr, unsigned len,
  30587. + int /*bool*/ is_last)
  30588. +{
  30589. + struct bcm2708_dma_cb *cb = &host->cb_base[ix];
  30590. + unsigned char dmawaits = host->dma_waits;
  30591. +
  30592. + /* We can make arbitrarily large writes as long as we specify DREQ to
  30593. + pace the delivery of bytes to the Arasan hardware */
  30594. + cb->info = BCM2708_DMA_PER_MAP(BCM2708_DMA_DREQ_EMMC) |
  30595. + BCM2708_DMA_WAITS(dmawaits) |
  30596. + BCM2708_DMA_D_DREQ |
  30597. + BCM2708_DMA_S_WIDTH |
  30598. + BCM2708_DMA_S_INC;
  30599. + cb->src = dma_addr;
  30600. + cb->dst = DMA_SDHCI_BUFFER; /* DATA register DMA address */
  30601. + cb->length = len;
  30602. + cb->stride = 0;
  30603. +
  30604. + if (is_last) {
  30605. + cb->info |= BCM2708_DMA_INT_EN |
  30606. + BCM2708_DMA_WAIT_RESP;
  30607. + cb->next = 0;
  30608. + } else
  30609. + cb->next = host->cb_handle +
  30610. + (ix+1)*sizeof(struct bcm2708_dma_cb);
  30611. +
  30612. + cb->pad[0] = 0;
  30613. + cb->pad[1] = 0;
  30614. +}
  30615. +
  30616. +
  30617. +static void schci_bcm2708_dma_go(struct sdhci_host *host)
  30618. +{
  30619. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  30620. + void __iomem *dma_chan_base = host_priv->dma_chan_base;
  30621. +
  30622. + BUG_ON(host_priv->dma_wanted);
  30623. +#ifdef CHECK_DMA_USE
  30624. + if (host_priv->dma_wanted)
  30625. + printk(KERN_ERR "%s: DMA already in progress - "
  30626. + "now %"FMT_HPT", last started %lu "
  30627. + "reset %lu stopped %lu\n",
  30628. + mmc_hostname(host->mmc),
  30629. + hptime(), since_ns(host_priv->when_started),
  30630. + since_ns(host_priv->when_reset),
  30631. + since_ns(host_priv->when_stopped));
  30632. + else if (host_priv->dmas_pending > 0)
  30633. + printk(KERN_INFO "%s: note - new DMA when %d reset DMAs "
  30634. + "already in progress - "
  30635. + "now %"FMT_HPT", started %lu reset %lu stopped %lu\n",
  30636. + mmc_hostname(host->mmc),
  30637. + host_priv->dmas_pending,
  30638. + hptime(), since_ns(host_priv->when_started),
  30639. + since_ns(host_priv->when_reset),
  30640. + since_ns(host_priv->when_stopped));
  30641. + host_priv->dmas_pending += 1;
  30642. + host_priv->when_started = hptime();
  30643. +#endif
  30644. + host_priv->dma_wanted = 1;
  30645. + DBG("PDMA go - base %p handle %08X\n", dma_chan_base,
  30646. + host_priv->cb_handle);
  30647. + bcm_dma_start(dma_chan_base, host_priv->cb_handle);
  30648. +}
  30649. +
  30650. +
  30651. +static void
  30652. +sdhci_platdma_read(struct sdhci_host *host, dma_addr_t dma_addr, size_t len)
  30653. +{
  30654. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  30655. +
  30656. + DBG("PDMA to read %d bytes\n", len);
  30657. + host_priv->sg_done += len;
  30658. + schci_bcm2708_cb_read(host_priv, 0, dma_addr, len, 1/*TRUE*/);
  30659. + schci_bcm2708_dma_go(host);
  30660. +}
  30661. +
  30662. +
  30663. +static void
  30664. +sdhci_platdma_write(struct sdhci_host *host, dma_addr_t dma_addr, size_t len)
  30665. +{
  30666. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  30667. +
  30668. + DBG("PDMA to write %d bytes\n", len);
  30669. + //BUG_ON(0 != (len & 0x1ff));
  30670. +
  30671. + host_priv->sg_done += len;
  30672. + schci_bcm2708_cb_write(host_priv, 0, dma_addr, len, 1/*TRUE*/);
  30673. + schci_bcm2708_dma_go(host);
  30674. +}
  30675. +
  30676. +/*! space is avaiable to receive into or data is available to write
  30677. + Platform DMA exported function
  30678. +*/
  30679. +void
  30680. +sdhci_bcm2708_platdma_avail(struct sdhci_host *host, unsigned int *ref_intmask,
  30681. + void(*completion_callback)(struct sdhci_host *host))
  30682. +{
  30683. + struct mmc_data *data = host->data;
  30684. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  30685. + int sg_ix;
  30686. + size_t bytes;
  30687. + dma_addr_t addr;
  30688. +
  30689. + BUG_ON(NULL == data);
  30690. + BUG_ON(0 == data->blksz);
  30691. +
  30692. + host_priv->complete = completion_callback;
  30693. +
  30694. + sg_ix = host_priv->sg_ix;
  30695. + BUG_ON(sg_ix >= data->sg_len);
  30696. +
  30697. + /* we can DMA blocks larger than blksz - it may hang the DMA
  30698. + channel but we are its only user */
  30699. + bytes = sg_dma_len(&data->sg[sg_ix]) - host_priv->sg_done;
  30700. + addr = sg_dma_address(&data->sg[sg_ix]) + host_priv->sg_done;
  30701. +
  30702. + if (bytes > 0) {
  30703. + /* We're going to poll for read/write available state until
  30704. + we finish this DMA
  30705. + */
  30706. +
  30707. + if (data->flags & MMC_DATA_READ) {
  30708. + if (*ref_intmask & SDHCI_INT_DATA_AVAIL) {
  30709. + sdhci_unsignal_irqs(host, SDHCI_INT_DATA_AVAIL |
  30710. + SDHCI_INT_SPACE_AVAIL);
  30711. + sdhci_platdma_read(host, addr, bytes);
  30712. + }
  30713. + } else {
  30714. + if (*ref_intmask & SDHCI_INT_SPACE_AVAIL) {
  30715. + sdhci_unsignal_irqs(host, SDHCI_INT_DATA_AVAIL |
  30716. + SDHCI_INT_SPACE_AVAIL);
  30717. + sdhci_platdma_write(host, addr, bytes);
  30718. + }
  30719. + }
  30720. + }
  30721. + /* else:
  30722. + we have run out of bytes that need transferring (e.g. we may be in
  30723. + the middle of the last DMA transfer), or
  30724. + it is also possible that we've been called when another IRQ is
  30725. + signalled, even though we've turned off signalling of our own IRQ */
  30726. +
  30727. + *ref_intmask &= ~SDHCI_INT_DATA_END;
  30728. + /* don't let the main sdhci driver act on this .. we'll deal with it
  30729. + when we respond to the DMA - if one is currently in progress */
  30730. +}
  30731. +
  30732. +/* is it possible to DMA the given mmc_data structure?
  30733. + Platform DMA exported function
  30734. +*/
  30735. +int /*bool*/
  30736. +sdhci_bcm2708_platdma_dmaable(struct sdhci_host *host, struct mmc_data *data)
  30737. +{
  30738. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  30739. + int ok = bcm_sg_suitable_for_dma(data->sg, data->sg_len);
  30740. +
  30741. + if (!ok)
  30742. + DBG("Reverting to PIO - bad cache alignment\n");
  30743. +
  30744. + else {
  30745. + host_priv->sg_ix = 0; /* first SG index */
  30746. + host_priv->sg_done = 0; /* no bytes done */
  30747. + }
  30748. +
  30749. + return ok;
  30750. +}
  30751. +
  30752. +#include <mach/arm_control.h> //GRAYG
  30753. +/*! the current SD transacton has been abandonned
  30754. + We need to tidy up if we were in the middle of a DMA
  30755. + Platform DMA exported function
  30756. +*/
  30757. +void
  30758. +sdhci_bcm2708_platdma_reset(struct sdhci_host *host, struct mmc_data *data)
  30759. +{
  30760. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  30761. +// unsigned long flags;
  30762. +
  30763. + BUG_ON(NULL == host);
  30764. +
  30765. +// spin_lock_irqsave(&host->lock, flags);
  30766. +
  30767. + if (host_priv->dma_wanted) {
  30768. + if (NULL == data) {
  30769. + printk(KERN_ERR "%s: ongoing DMA reset - no data!\n",
  30770. + mmc_hostname(host->mmc));
  30771. + BUG_ON(NULL == data);
  30772. + } else {
  30773. + struct scatterlist *sg;
  30774. + int sg_len;
  30775. + int sg_todo;
  30776. + int rc;
  30777. + unsigned long cs;
  30778. +
  30779. + sg = data->sg;
  30780. + sg_len = data->sg_len;
  30781. + sg_todo = sg_dma_len(&sg[host_priv->sg_ix]);
  30782. +
  30783. + cs = readl(host_priv->dma_chan_base + BCM2708_DMA_CS);
  30784. +
  30785. + if (!(BCM2708_DMA_ACTIVE & cs))
  30786. + {
  30787. + if (extra_messages)
  30788. + printk(KERN_INFO "%s: missed completion of "
  30789. + "cmd %d DMA (%d/%d [%d]/[%d]) - "
  30790. + "ignoring it\n",
  30791. + mmc_hostname(host->mmc),
  30792. + host->last_cmdop,
  30793. + host_priv->sg_done, sg_todo,
  30794. + host_priv->sg_ix+1, sg_len);
  30795. + }
  30796. + else
  30797. + printk(KERN_INFO "%s: resetting ongoing cmd %d"
  30798. + "DMA before %d/%d [%d]/[%d] complete\n",
  30799. + mmc_hostname(host->mmc),
  30800. + host->last_cmdop,
  30801. + host_priv->sg_done, sg_todo,
  30802. + host_priv->sg_ix+1, sg_len);
  30803. +#ifdef CHECK_DMA_USE
  30804. + printk(KERN_INFO "%s: now %"FMT_HPT" started %lu "
  30805. + "last reset %lu last stopped %lu\n",
  30806. + mmc_hostname(host->mmc),
  30807. + hptime(), since_ns(host_priv->when_started),
  30808. + since_ns(host_priv->when_reset),
  30809. + since_ns(host_priv->when_stopped));
  30810. + { unsigned long info, debug;
  30811. + void __iomem *base;
  30812. + unsigned long pend0, pend1, pend2;
  30813. +
  30814. + base = host_priv->dma_chan_base;
  30815. + cs = readl(base + BCM2708_DMA_CS);
  30816. + info = readl(base + BCM2708_DMA_INFO);
  30817. + debug = readl(base + BCM2708_DMA_DEBUG);
  30818. + printk(KERN_INFO "%s: DMA%d CS=%08lX TI=%08lX "
  30819. + "DEBUG=%08lX\n",
  30820. + mmc_hostname(host->mmc),
  30821. + host_priv->dma_chan,
  30822. + cs, info, debug);
  30823. + pend0 = readl(__io_address(ARM_IRQ_PEND0));
  30824. + pend1 = readl(__io_address(ARM_IRQ_PEND1));
  30825. + pend2 = readl(__io_address(ARM_IRQ_PEND2));
  30826. +
  30827. + printk(KERN_INFO "%s: PEND0=%08lX "
  30828. + "PEND1=%08lX PEND2=%08lX\n",
  30829. + mmc_hostname(host->mmc),
  30830. + pend0, pend1, pend2);
  30831. +
  30832. + //gintsts = readl(__io_address(GINTSTS));
  30833. + //gintmsk = readl(__io_address(GINTMSK));
  30834. + //printk(KERN_INFO "%s: USB GINTSTS=%08lX"
  30835. + // "GINTMSK=%08lX\n",
  30836. + // mmc_hostname(host->mmc), gintsts, gintmsk);
  30837. + }
  30838. +#endif
  30839. + rc = bcm_dma_abort(host_priv->dma_chan_base);
  30840. + BUG_ON(rc != 0);
  30841. + }
  30842. + host_priv->dma_wanted = 0;
  30843. +#ifdef CHECK_DMA_USE
  30844. + host_priv->when_reset = hptime();
  30845. +#endif
  30846. + }
  30847. +
  30848. +// spin_unlock_irqrestore(&host->lock, flags);
  30849. +}
  30850. +
  30851. +
  30852. +static void sdhci_bcm2708_dma_complete_irq(struct sdhci_host *host,
  30853. + u32 dma_cs)
  30854. +{
  30855. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  30856. + struct mmc_data *data;
  30857. + struct scatterlist *sg;
  30858. + int sg_len;
  30859. + int sg_ix;
  30860. + int sg_todo;
  30861. +// unsigned long flags;
  30862. +
  30863. + BUG_ON(NULL == host);
  30864. +
  30865. +// spin_lock_irqsave(&host->lock, flags);
  30866. + data = host->data;
  30867. +
  30868. +#ifdef CHECK_DMA_USE
  30869. + if (host_priv->dmas_pending <= 0)
  30870. + DBG("on completion no DMA in progress - "
  30871. + "now %"FMT_HPT" started %lu reset %lu stopped %lu\n",
  30872. + hptime(), since_ns(host_priv->when_started),
  30873. + since_ns(host_priv->when_reset),
  30874. + since_ns(host_priv->when_stopped));
  30875. + else if (host_priv->dmas_pending > 1)
  30876. + DBG("still %d DMA in progress after completion - "
  30877. + "now %"FMT_HPT" started %lu reset %lu stopped %lu\n",
  30878. + host_priv->dmas_pending - 1,
  30879. + hptime(), since_ns(host_priv->when_started),
  30880. + since_ns(host_priv->when_reset),
  30881. + since_ns(host_priv->when_stopped));
  30882. + BUG_ON(host_priv->dmas_pending <= 0);
  30883. + host_priv->dmas_pending -= 1;
  30884. + host_priv->when_stopped = hptime();
  30885. +#endif
  30886. + host_priv->dma_wanted = 0;
  30887. +
  30888. + if (NULL == data) {
  30889. + DBG("PDMA unused completion - status 0x%X\n", dma_cs);
  30890. +// spin_unlock_irqrestore(&host->lock, flags);
  30891. + return;
  30892. + }
  30893. + sg = data->sg;
  30894. + sg_len = data->sg_len;
  30895. + sg_todo = sg_dma_len(&sg[host_priv->sg_ix]);
  30896. +
  30897. + DBG("PDMA complete %d/%d [%d]/[%d]..\n",
  30898. + host_priv->sg_done, sg_todo,
  30899. + host_priv->sg_ix+1, sg_len);
  30900. +
  30901. + BUG_ON(host_priv->sg_done > sg_todo);
  30902. +
  30903. + if (host_priv->sg_done >= sg_todo) {
  30904. + host_priv->sg_ix++;
  30905. + host_priv->sg_done = 0;
  30906. + }
  30907. +
  30908. + sg_ix = host_priv->sg_ix;
  30909. + if (sg_ix < sg_len) {
  30910. + u32 irq_mask;
  30911. + /* Set off next DMA if we've got the capacity */
  30912. +
  30913. + if (data->flags & MMC_DATA_READ)
  30914. + irq_mask = SDHCI_INT_DATA_AVAIL;
  30915. + else
  30916. + irq_mask = SDHCI_INT_SPACE_AVAIL;
  30917. +
  30918. + /* We have to use the interrupt status register on the BCM2708
  30919. + rather than the SDHCI_PRESENT_STATE register because latency
  30920. + in the glue logic means that the information retrieved from
  30921. + the latter is not always up-to-date w.r.t the DMA engine -
  30922. + it may not indicate that a read or a write is ready yet */
  30923. + if (sdhci_bcm2708_raw_readl(host, SDHCI_INT_STATUS) &
  30924. + irq_mask) {
  30925. + size_t bytes = sg_dma_len(&sg[sg_ix]) -
  30926. + host_priv->sg_done;
  30927. + dma_addr_t addr = sg_dma_address(&data->sg[sg_ix]) +
  30928. + host_priv->sg_done;
  30929. +
  30930. + /* acknowledge interrupt */
  30931. + sdhci_bcm2708_raw_writel(host, irq_mask,
  30932. + SDHCI_INT_STATUS);
  30933. +
  30934. + BUG_ON(0 == bytes);
  30935. +
  30936. + if (data->flags & MMC_DATA_READ)
  30937. + sdhci_platdma_read(host, addr, bytes);
  30938. + else
  30939. + sdhci_platdma_write(host, addr, bytes);
  30940. + } else {
  30941. + DBG("PDMA - wait avail\n");
  30942. + /* may generate an IRQ if already present */
  30943. + sdhci_signal_irqs(host, SDHCI_INT_DATA_AVAIL |
  30944. + SDHCI_INT_SPACE_AVAIL);
  30945. + }
  30946. + } else {
  30947. + if (sync_after_dma) {
  30948. + /* On the Arasan controller the stop command (which will be
  30949. + scheduled after this completes) does not seem to work
  30950. + properly if we allow it to be issued when we are
  30951. + transferring data to/from the SD card.
  30952. + We get CRC and DEND errors unless we wait for
  30953. + the SD controller to finish reading/writing to the card. */
  30954. + u32 state_mask;
  30955. + int timeout=3*1000*1000;
  30956. +
  30957. + DBG("PDMA over - sync card\n");
  30958. + if (data->flags & MMC_DATA_READ)
  30959. + state_mask = SDHCI_DOING_READ;
  30960. + else
  30961. + state_mask = SDHCI_DOING_WRITE;
  30962. +
  30963. + while (0 != (sdhci_bcm2708_raw_readl(host, SDHCI_PRESENT_STATE)
  30964. + & state_mask) && --timeout > 0)
  30965. + {
  30966. + udelay(1);
  30967. + continue;
  30968. + }
  30969. + if (timeout <= 0)
  30970. + printk(KERN_ERR"%s: final %s to SD card still "
  30971. + "running\n",
  30972. + mmc_hostname(host->mmc),
  30973. + data->flags & MMC_DATA_READ? "read": "write");
  30974. + }
  30975. + if (host_priv->complete) {
  30976. + (*host_priv->complete)(host);
  30977. + DBG("PDMA %s complete\n",
  30978. + data->flags & MMC_DATA_READ?"read":"write");
  30979. + sdhci_signal_irqs(host, SDHCI_INT_DATA_AVAIL |
  30980. + SDHCI_INT_SPACE_AVAIL);
  30981. + }
  30982. + }
  30983. +// spin_unlock_irqrestore(&host->lock, flags);
  30984. +}
  30985. +
  30986. +static irqreturn_t sdhci_bcm2708_dma_irq(int irq, void *dev_id)
  30987. +{
  30988. + irqreturn_t result = IRQ_NONE;
  30989. + struct sdhci_host *host = dev_id;
  30990. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  30991. + u32 dma_cs; /* control and status register */
  30992. +
  30993. + BUG_ON(NULL == dev_id);
  30994. + BUG_ON(NULL == host_priv->dma_chan_base);
  30995. +
  30996. + sdhci_spin_lock(host);
  30997. +
  30998. + dma_cs = readl(host_priv->dma_chan_base + BCM2708_DMA_CS);
  30999. +
  31000. + if (dma_cs & BCM2708_DMA_ERR) {
  31001. + unsigned long debug;
  31002. + debug = readl(host_priv->dma_chan_base +
  31003. + BCM2708_DMA_DEBUG);
  31004. + printk(KERN_ERR "%s: DMA error - CS %lX DEBUG %lX\n",
  31005. + mmc_hostname(host->mmc), (unsigned long)dma_cs,
  31006. + (unsigned long)debug);
  31007. + /* reset error */
  31008. + writel(debug, host_priv->dma_chan_base +
  31009. + BCM2708_DMA_DEBUG);
  31010. + }
  31011. + if (dma_cs & BCM2708_DMA_INT) {
  31012. + /* acknowledge interrupt */
  31013. + writel(BCM2708_DMA_INT,
  31014. + host_priv->dma_chan_base + BCM2708_DMA_CS);
  31015. +
  31016. + dsb(); /* ARM data synchronization (push) operation */
  31017. +
  31018. + if (!host_priv->dma_wanted) {
  31019. + /* ignore this interrupt - it was reset */
  31020. + if (extra_messages)
  31021. + printk(KERN_INFO "%s: DMA IRQ %X ignored - "
  31022. + "results were reset\n",
  31023. + mmc_hostname(host->mmc), dma_cs);
  31024. +#ifdef CHECK_DMA_USE
  31025. + printk(KERN_INFO "%s: now %"FMT_HPT
  31026. + " started %lu reset %lu stopped %lu\n",
  31027. + mmc_hostname(host->mmc), hptime(),
  31028. + since_ns(host_priv->when_started),
  31029. + since_ns(host_priv->when_reset),
  31030. + since_ns(host_priv->when_stopped));
  31031. + host_priv->dmas_pending--;
  31032. +#endif
  31033. + } else
  31034. + sdhci_bcm2708_dma_complete_irq(host, dma_cs);
  31035. +
  31036. + result = IRQ_HANDLED;
  31037. + }
  31038. + sdhci_spin_unlock(host);
  31039. +
  31040. + return result;
  31041. +}
  31042. +#endif /* CONFIG_MMC_SDHCI_BCM2708_DMA */
  31043. +
  31044. +
  31045. +/***************************************************************************** \
  31046. + * *
  31047. + * Device Attributes *
  31048. + * *
  31049. +\*****************************************************************************/
  31050. +
  31051. +
  31052. +/**
  31053. + * Show the DMA-using status
  31054. + */
  31055. +static ssize_t attr_dma_show(struct device *_dev,
  31056. + struct device_attribute *attr, char *buf)
  31057. +{
  31058. + struct sdhci_host *host = (struct sdhci_host *)dev_get_drvdata(_dev);
  31059. +
  31060. + if (host) {
  31061. + int use_dma = (host->flags & SDHCI_USE_PLATDMA? 1:0);
  31062. + return sprintf(buf, "%d\n", use_dma);
  31063. + } else
  31064. + return -EINVAL;
  31065. +}
  31066. +
  31067. +/**
  31068. + * Set the DMA-using status
  31069. + */
  31070. +static ssize_t attr_dma_store(struct device *_dev,
  31071. + struct device_attribute *attr,
  31072. + const char *buf, size_t count)
  31073. +{
  31074. + struct sdhci_host *host = (struct sdhci_host *)dev_get_drvdata(_dev);
  31075. +
  31076. + if (host) {
  31077. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  31078. + int on = simple_strtol(buf, NULL, 0);
  31079. + if (on) {
  31080. + host->flags |= SDHCI_USE_PLATDMA;
  31081. + sdhci_bcm2708_writel(host, 1, REG_EXRDFIFO_EN);
  31082. + printk(KERN_INFO "%s: DMA enabled\n",
  31083. + mmc_hostname(host->mmc));
  31084. + } else {
  31085. + host->flags &= ~(SDHCI_USE_PLATDMA | SDHCI_REQ_USE_DMA);
  31086. + sdhci_bcm2708_writel(host, 0, REG_EXRDFIFO_EN);
  31087. + printk(KERN_INFO "%s: DMA disabled\n",
  31088. + mmc_hostname(host->mmc));
  31089. + }
  31090. +#endif
  31091. + return count;
  31092. + } else
  31093. + return -EINVAL;
  31094. +}
  31095. +
  31096. +static DEVICE_ATTR(use_dma, S_IRUGO | S_IWUGO, attr_dma_show, attr_dma_store);
  31097. +
  31098. +
  31099. +/**
  31100. + * Show the DMA wait states used
  31101. + */
  31102. +static ssize_t attr_dmawait_show(struct device *_dev,
  31103. + struct device_attribute *attr, char *buf)
  31104. +{
  31105. + struct sdhci_host *host = (struct sdhci_host *)dev_get_drvdata(_dev);
  31106. +
  31107. + if (host) {
  31108. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  31109. + int dmawait = host_priv->dma_waits;
  31110. + return sprintf(buf, "%d\n", dmawait);
  31111. + } else
  31112. + return -EINVAL;
  31113. +}
  31114. +
  31115. +/**
  31116. + * Set the DMA wait state used
  31117. + */
  31118. +static ssize_t attr_dmawait_store(struct device *_dev,
  31119. + struct device_attribute *attr,
  31120. + const char *buf, size_t count)
  31121. +{
  31122. + struct sdhci_host *host = (struct sdhci_host *)dev_get_drvdata(_dev);
  31123. +
  31124. + if (host) {
  31125. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  31126. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  31127. + int dma_waits = simple_strtol(buf, NULL, 0);
  31128. + if (dma_waits >= 0 && dma_waits < 32)
  31129. + host_priv->dma_waits = dma_waits;
  31130. + else
  31131. + printk(KERN_ERR "%s: illegal dma_waits value - %d",
  31132. + mmc_hostname(host->mmc), dma_waits);
  31133. +#endif
  31134. + return count;
  31135. + } else
  31136. + return -EINVAL;
  31137. +}
  31138. +
  31139. +static DEVICE_ATTR(dma_wait, S_IRUGO | S_IWUGO,
  31140. + attr_dmawait_show, attr_dmawait_store);
  31141. +
  31142. +
  31143. +/**
  31144. + * Show the DMA-using status
  31145. + */
  31146. +static ssize_t attr_status_show(struct device *_dev,
  31147. + struct device_attribute *attr, char *buf)
  31148. +{
  31149. + struct sdhci_host *host = (struct sdhci_host *)dev_get_drvdata(_dev);
  31150. +
  31151. + if (host) {
  31152. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  31153. + return sprintf(buf,
  31154. + "present: yes\n"
  31155. + "power: %s\n"
  31156. + "clock: %u Hz\n"
  31157. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  31158. + "dma: %s (%d waits)\n",
  31159. +#else
  31160. + "dma: unconfigured\n",
  31161. +#endif
  31162. + "always on",
  31163. + host->clock
  31164. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  31165. + , (host->flags & SDHCI_USE_PLATDMA)? "on": "off"
  31166. + , host_priv->dma_waits
  31167. +#endif
  31168. + );
  31169. + } else
  31170. + return -EINVAL;
  31171. +}
  31172. +
  31173. +static DEVICE_ATTR(status, S_IRUGO, attr_status_show, NULL);
  31174. +
  31175. +/***************************************************************************** \
  31176. + * *
  31177. + * Power Management *
  31178. + * *
  31179. +\*****************************************************************************/
  31180. +
  31181. +
  31182. +#ifdef CONFIG_PM
  31183. +static int sdhci_bcm2708_suspend(struct platform_device *dev, pm_message_t state)
  31184. +{
  31185. + struct sdhci_host *host = (struct sdhci_host *)
  31186. + platform_get_drvdata(dev);
  31187. + int ret = 0;
  31188. +
  31189. + if (host->mmc) {
  31190. + //ret = mmc_suspend_host(host->mmc);
  31191. + }
  31192. +
  31193. + return ret;
  31194. +}
  31195. +
  31196. +static int sdhci_bcm2708_resume(struct platform_device *dev)
  31197. +{
  31198. + struct sdhci_host *host = (struct sdhci_host *)
  31199. + platform_get_drvdata(dev);
  31200. + int ret = 0;
  31201. +
  31202. + if (host->mmc) {
  31203. + //ret = mmc_resume_host(host->mmc);
  31204. + }
  31205. +
  31206. + return ret;
  31207. +}
  31208. +#endif
  31209. +
  31210. +
  31211. +/*****************************************************************************\
  31212. + * *
  31213. + * Device quirk functions. Implemented as local ops because the flags *
  31214. + * field is out of space with newer kernels. This implementation can be *
  31215. + * back ported to older kernels as well. *
  31216. +\****************************************************************************/
  31217. +static unsigned int sdhci_bcm2708_quirk_extra_ints(struct sdhci_host *host)
  31218. +{
  31219. + return 1;
  31220. +}
  31221. +
  31222. +static unsigned int sdhci_bcm2708_quirk_spurious_crc_acmd51(struct sdhci_host *host)
  31223. +{
  31224. + return 1;
  31225. +}
  31226. +
  31227. +static unsigned int sdhci_bcm2708_missing_status(struct sdhci_host *host)
  31228. +{
  31229. + return 1;
  31230. +}
  31231. +
  31232. +/***************************************************************************** \
  31233. + * *
  31234. + * Device ops *
  31235. + * *
  31236. +\*****************************************************************************/
  31237. +
  31238. +static struct sdhci_ops sdhci_bcm2708_ops = {
  31239. +#ifdef CONFIG_MMC_SDHCI_IO_ACCESSORS
  31240. + .read_l = sdhci_bcm2708_readl,
  31241. + .read_w = sdhci_bcm2708_readw,
  31242. + .read_b = sdhci_bcm2708_readb,
  31243. + .write_l = sdhci_bcm2708_writel,
  31244. + .write_w = sdhci_bcm2708_writew,
  31245. + .write_b = sdhci_bcm2708_writeb,
  31246. +#else
  31247. +#error The BCM2708 SDHCI driver needs CONFIG_MMC_SDHCI_IO_ACCESSORS to be set
  31248. +#endif
  31249. + .get_max_clock = sdhci_bcm2708_get_max_clock,
  31250. +
  31251. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  31252. + // Platform DMA operations
  31253. + .pdma_able = sdhci_bcm2708_platdma_dmaable,
  31254. + .pdma_avail = sdhci_bcm2708_platdma_avail,
  31255. + .pdma_reset = sdhci_bcm2708_platdma_reset,
  31256. +#endif
  31257. + .extra_ints = sdhci_bcm2708_quirk_extra_ints,
  31258. +};
  31259. +
  31260. +/*****************************************************************************\
  31261. + * *
  31262. + * Device probing/removal *
  31263. + * *
  31264. +\*****************************************************************************/
  31265. +
  31266. +static int sdhci_bcm2708_probe(struct platform_device *pdev)
  31267. +{
  31268. + struct sdhci_host *host;
  31269. + struct resource *iomem;
  31270. + struct sdhci_bcm2708_priv *host_priv;
  31271. + int ret;
  31272. +
  31273. + BUG_ON(pdev == NULL);
  31274. +
  31275. + iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  31276. + if (!iomem) {
  31277. + ret = -ENOMEM;
  31278. + goto err;
  31279. + }
  31280. +
  31281. + if (resource_size(iomem) != 0x100)
  31282. + dev_err(&pdev->dev, "Invalid iomem size. You may "
  31283. + "experience problems.\n");
  31284. +
  31285. + if (pdev->dev.parent)
  31286. + host = sdhci_alloc_host(pdev->dev.parent,
  31287. + sizeof(struct sdhci_bcm2708_priv));
  31288. + else
  31289. + host = sdhci_alloc_host(&pdev->dev,
  31290. + sizeof(struct sdhci_bcm2708_priv));
  31291. +
  31292. + if (IS_ERR(host)) {
  31293. + ret = PTR_ERR(host);
  31294. + goto err;
  31295. + }
  31296. + if (missing_status) {
  31297. + sdhci_bcm2708_ops.missing_status = sdhci_bcm2708_missing_status;
  31298. + }
  31299. +
  31300. + if( spurious_crc_acmd51 ) {
  31301. + sdhci_bcm2708_ops.spurious_crc_acmd51 = sdhci_bcm2708_quirk_spurious_crc_acmd51;
  31302. + }
  31303. +
  31304. +
  31305. + printk("sdhci: %s low-latency mode\n",enable_llm?"Enable":"Disable");
  31306. +
  31307. + host->hw_name = "BCM2708_Arasan";
  31308. + host->ops = &sdhci_bcm2708_ops;
  31309. + host->irq = platform_get_irq(pdev, 0);
  31310. + host->second_irq = 0;
  31311. +
  31312. + host->quirks = SDHCI_QUIRK_BROKEN_CARD_DETECTION |
  31313. + SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK |
  31314. + SDHCI_QUIRK_BROKEN_TIMEOUT_VAL |
  31315. + SDHCI_QUIRK_MISSING_CAPS |
  31316. + SDHCI_QUIRK_NO_HISPD_BIT |
  31317. + (sync_after_dma ? 0:SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12);
  31318. +
  31319. +
  31320. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  31321. + host->flags = SDHCI_USE_PLATDMA;
  31322. +#endif
  31323. +
  31324. + if (!request_mem_region(iomem->start, resource_size(iomem),
  31325. + mmc_hostname(host->mmc))) {
  31326. + dev_err(&pdev->dev, "cannot request region\n");
  31327. + ret = -EBUSY;
  31328. + goto err_request;
  31329. + }
  31330. +
  31331. + host->ioaddr = ioremap(iomem->start, resource_size(iomem));
  31332. + if (!host->ioaddr) {
  31333. + dev_err(&pdev->dev, "failed to remap registers\n");
  31334. + ret = -ENOMEM;
  31335. + goto err_remap;
  31336. + }
  31337. +
  31338. + host_priv = SDHCI_HOST_PRIV(host);
  31339. +
  31340. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  31341. + host_priv->dma_wanted = 0;
  31342. +#ifdef CHECK_DMA_USE
  31343. + host_priv->dmas_pending = 0;
  31344. + host_priv->when_started = 0;
  31345. + host_priv->when_reset = 0;
  31346. + host_priv->when_stopped = 0;
  31347. +#endif
  31348. + host_priv->sg_ix = 0;
  31349. + host_priv->sg_done = 0;
  31350. + host_priv->complete = NULL;
  31351. + host_priv->dma_waits = SDHCI_BCM_DMA_WAITS;
  31352. +
  31353. + host_priv->cb_base = dma_alloc_writecombine(&pdev->dev, SZ_4K,
  31354. + &host_priv->cb_handle,
  31355. + GFP_KERNEL);
  31356. + if (!host_priv->cb_base) {
  31357. + dev_err(&pdev->dev, "cannot allocate DMA CBs\n");
  31358. + ret = -ENOMEM;
  31359. + goto err_alloc_cb;
  31360. + }
  31361. +
  31362. + ret = bcm_dma_chan_alloc(BCM_DMA_FEATURE_FAST,
  31363. + &host_priv->dma_chan_base,
  31364. + &host_priv->dma_irq);
  31365. + if (ret < 0) {
  31366. + dev_err(&pdev->dev, "couldn't allocate a DMA channel\n");
  31367. + goto err_add_dma;
  31368. + }
  31369. + host_priv->dma_chan = ret;
  31370. +
  31371. + ret = request_irq(host_priv->dma_irq, sdhci_bcm2708_dma_irq,
  31372. + 0 /*IRQF_SHARED*/, DRIVER_NAME " (dma)", host);
  31373. + if (ret) {
  31374. + dev_err(&pdev->dev, "cannot set DMA IRQ\n");
  31375. + goto err_add_dma_irq;
  31376. + }
  31377. + host->second_irq = host_priv->dma_irq;
  31378. + DBG("DMA CBs %p handle %08X DMA%d %p DMA IRQ %d\n",
  31379. + host_priv->cb_base, (unsigned)host_priv->cb_handle,
  31380. + host_priv->dma_chan, host_priv->dma_chan_base,
  31381. + host_priv->dma_irq);
  31382. +
  31383. + // we support 3.3V
  31384. + host->caps |= SDHCI_CAN_VDD_330;
  31385. + if (allow_highspeed)
  31386. + host->mmc->caps |= MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED;
  31387. +
  31388. + /* single block writes cause data loss with some SD cards! */
  31389. + host->mmc->caps2 |= MMC_CAP2_FORCE_MULTIBLOCK;
  31390. +#endif
  31391. +
  31392. + ret = sdhci_add_host(host);
  31393. + if (ret)
  31394. + goto err_add_host;
  31395. +
  31396. + platform_set_drvdata(pdev, host);
  31397. + ret = device_create_file(&pdev->dev, &dev_attr_use_dma);
  31398. + ret = device_create_file(&pdev->dev, &dev_attr_dma_wait);
  31399. + ret = device_create_file(&pdev->dev, &dev_attr_status);
  31400. +
  31401. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  31402. + /* enable extension fifo for paced DMA transfers */
  31403. + sdhci_bcm2708_writel(host, 1, REG_EXRDFIFO_EN);
  31404. + sdhci_bcm2708_writel(host, 4, REG_EXRDFIFO_CFG);
  31405. +#endif
  31406. +
  31407. + printk(KERN_INFO "%s: BCM2708 SDHC host at 0x%08llx DMA %d IRQ %d\n",
  31408. + mmc_hostname(host->mmc), (unsigned long long)iomem->start,
  31409. + host_priv->dma_chan, host_priv->dma_irq);
  31410. +
  31411. + return 0;
  31412. +
  31413. +err_add_host:
  31414. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  31415. + free_irq(host_priv->dma_irq, host);
  31416. +err_add_dma_irq:
  31417. + bcm_dma_chan_free(host_priv->dma_chan);
  31418. +err_add_dma:
  31419. + dma_free_writecombine(&pdev->dev, SZ_4K, host_priv->cb_base,
  31420. + host_priv->cb_handle);
  31421. +err_alloc_cb:
  31422. +#endif
  31423. + iounmap(host->ioaddr);
  31424. +err_remap:
  31425. + release_mem_region(iomem->start, resource_size(iomem));
  31426. +err_request:
  31427. + sdhci_free_host(host);
  31428. +err:
  31429. + dev_err(&pdev->dev, "probe failed, err %d\n", ret);
  31430. + return ret;
  31431. +}
  31432. +
  31433. +static int sdhci_bcm2708_remove(struct platform_device *pdev)
  31434. +{
  31435. + struct sdhci_host *host = platform_get_drvdata(pdev);
  31436. + struct resource *iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  31437. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  31438. + int dead;
  31439. + u32 scratch;
  31440. +
  31441. + dead = 0;
  31442. + scratch = sdhci_bcm2708_readl(host, SDHCI_INT_STATUS);
  31443. + if (scratch == (u32)-1)
  31444. + dead = 1;
  31445. +
  31446. + device_remove_file(&pdev->dev, &dev_attr_status);
  31447. + device_remove_file(&pdev->dev, &dev_attr_dma_wait);
  31448. + device_remove_file(&pdev->dev, &dev_attr_use_dma);
  31449. +
  31450. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  31451. + free_irq(host_priv->dma_irq, host);
  31452. + dma_free_writecombine(&pdev->dev, SZ_4K, host_priv->cb_base,
  31453. + host_priv->cb_handle);
  31454. +#endif
  31455. + sdhci_remove_host(host, dead);
  31456. + iounmap(host->ioaddr);
  31457. + release_mem_region(iomem->start, resource_size(iomem));
  31458. + sdhci_free_host(host);
  31459. + platform_set_drvdata(pdev, NULL);
  31460. +
  31461. + return 0;
  31462. +}
  31463. +
  31464. +static struct platform_driver sdhci_bcm2708_driver = {
  31465. + .driver = {
  31466. + .name = DRIVER_NAME,
  31467. + .owner = THIS_MODULE,
  31468. + },
  31469. + .probe = sdhci_bcm2708_probe,
  31470. + .remove = sdhci_bcm2708_remove,
  31471. +
  31472. +#ifdef CONFIG_PM
  31473. + .suspend = sdhci_bcm2708_suspend,
  31474. + .resume = sdhci_bcm2708_resume,
  31475. +#endif
  31476. +
  31477. +};
  31478. +
  31479. +/*****************************************************************************\
  31480. + * *
  31481. + * Driver init/exit *
  31482. + * *
  31483. +\*****************************************************************************/
  31484. +
  31485. +static int __init sdhci_drv_init(void)
  31486. +{
  31487. + return platform_driver_register(&sdhci_bcm2708_driver);
  31488. +}
  31489. +
  31490. +static void __exit sdhci_drv_exit(void)
  31491. +{
  31492. + platform_driver_unregister(&sdhci_bcm2708_driver);
  31493. +}
  31494. +
  31495. +module_init(sdhci_drv_init);
  31496. +module_exit(sdhci_drv_exit);
  31497. +
  31498. +module_param(allow_highspeed, bool, 0444);
  31499. +module_param(emmc_clock_freq, int, 0444);
  31500. +module_param(sync_after_dma, bool, 0444);
  31501. +module_param(missing_status, bool, 0444);
  31502. +module_param(spurious_crc_acmd51, bool, 0444);
  31503. +module_param(enable_llm, bool, 0444);
  31504. +module_param(cycle_delay, int, 0444);
  31505. +module_param(extra_messages, bool, 0444);
  31506. +
  31507. +MODULE_DESCRIPTION("Secure Digital Host Controller Interface platform driver");
  31508. +MODULE_AUTHOR("Broadcom <info@broadcom.com>");
  31509. +MODULE_LICENSE("GPL v2");
  31510. +MODULE_ALIAS("platform:"DRIVER_NAME);
  31511. +
  31512. +MODULE_PARM_DESC(allow_highspeed, "Allow high speed transfers modes");
  31513. +MODULE_PARM_DESC(emmc_clock_freq, "Specify the speed of emmc clock");
  31514. +MODULE_PARM_DESC(sync_after_dma, "Block in driver until dma complete");
  31515. +MODULE_PARM_DESC(missing_status, "Use the missing status quirk");
  31516. +MODULE_PARM_DESC(spurious_crc_acmd51, "Use the spurious crc quirk for reading SCR (ACMD51)");
  31517. +MODULE_PARM_DESC(enable_llm, "Enable low-latency mode");
  31518. +MODULE_PARM_DESC(extra_messages, "Enable more sdcard warning messages");
  31519. +
  31520. +
  31521. diff -Nur linux-3.13.11/drivers/mmc/host/sdhci.c linux-rpi/drivers/mmc/host/sdhci.c
  31522. --- linux-3.13.11/drivers/mmc/host/sdhci.c 2014-04-23 01:49:33.000000000 +0200
  31523. +++ linux-rpi/drivers/mmc/host/sdhci.c 2014-04-24 15:36:51.726754267 +0200
  31524. @@ -28,6 +28,7 @@
  31525. #include <linux/mmc/mmc.h>
  31526. #include <linux/mmc/host.h>
  31527. #include <linux/mmc/card.h>
  31528. +#include <linux/mmc/sd.h>
  31529. #include <linux/mmc/slot-gpio.h>
  31530. #include "sdhci.h"
  31531. @@ -130,6 +131,99 @@
  31532. * Low level functions *
  31533. * *
  31534. \*****************************************************************************/
  31535. +extern bool enable_llm;
  31536. +static int sdhci_locked=0;
  31537. +void sdhci_spin_lock(struct sdhci_host *host)
  31538. +{
  31539. + spin_lock(&host->lock);
  31540. +#ifdef CONFIG_PREEMPT
  31541. + if(enable_llm)
  31542. + {
  31543. + disable_irq_nosync(host->irq);
  31544. + if(host->second_irq)
  31545. + disable_irq_nosync(host->second_irq);
  31546. + local_irq_enable();
  31547. + }
  31548. +#endif
  31549. +}
  31550. +
  31551. +void sdhci_spin_unlock(struct sdhci_host *host)
  31552. +{
  31553. +#ifdef CONFIG_PREEMPT
  31554. + if(enable_llm)
  31555. + {
  31556. + local_irq_disable();
  31557. + if(host->second_irq)
  31558. + enable_irq(host->second_irq);
  31559. + enable_irq(host->irq);
  31560. + }
  31561. +#endif
  31562. + spin_unlock(&host->lock);
  31563. +}
  31564. +
  31565. +void sdhci_spin_lock_irqsave(struct sdhci_host *host,unsigned long *flags)
  31566. +{
  31567. +#ifdef CONFIG_PREEMPT
  31568. + if(enable_llm)
  31569. + {
  31570. + while(sdhci_locked)
  31571. + {
  31572. + preempt_schedule();
  31573. + }
  31574. + spin_lock_irqsave(&host->lock,*flags);
  31575. + disable_irq(host->irq);
  31576. + if(host->second_irq)
  31577. + disable_irq(host->second_irq);
  31578. + local_irq_enable();
  31579. + }
  31580. + else
  31581. +#endif
  31582. + spin_lock_irqsave(&host->lock,*flags);
  31583. +}
  31584. +
  31585. +void sdhci_spin_unlock_irqrestore(struct sdhci_host *host,unsigned long flags)
  31586. +{
  31587. +#ifdef CONFIG_PREEMPT
  31588. + if(enable_llm)
  31589. + {
  31590. + local_irq_disable();
  31591. + if(host->second_irq)
  31592. + enable_irq(host->second_irq);
  31593. + enable_irq(host->irq);
  31594. + }
  31595. +#endif
  31596. + spin_unlock_irqrestore(&host->lock,flags);
  31597. +}
  31598. +
  31599. +static void sdhci_spin_enable_schedule(struct sdhci_host *host)
  31600. +{
  31601. +#ifdef CONFIG_PREEMPT
  31602. + if(enable_llm)
  31603. + {
  31604. + sdhci_locked = 1;
  31605. + preempt_enable();
  31606. + }
  31607. +#endif
  31608. +}
  31609. +
  31610. +static void sdhci_spin_disable_schedule(struct sdhci_host *host)
  31611. +{
  31612. +#ifdef CONFIG_PREEMPT
  31613. + if(enable_llm)
  31614. + {
  31615. + preempt_disable();
  31616. + sdhci_locked = 0;
  31617. + }
  31618. +#endif
  31619. +}
  31620. +
  31621. +
  31622. +#undef spin_lock_irqsave
  31623. +#define spin_lock_irqsave(host_lock, flags) sdhci_spin_lock_irqsave(container_of(host_lock, struct sdhci_host, lock), &flags)
  31624. +#define spin_unlock_irqrestore(host_lock, flags) sdhci_spin_unlock_irqrestore(container_of(host_lock, struct sdhci_host, lock), flags)
  31625. +
  31626. +#define spin_lock(host_lock) sdhci_spin_lock(container_of(host_lock, struct sdhci_host, lock))
  31627. +#define spin_unlock(host_lock) sdhci_spin_unlock(container_of(host_lock, struct sdhci_host, lock))
  31628. static void sdhci_clear_set_irqs(struct sdhci_host *host, u32 clear, u32 set)
  31629. {
  31630. @@ -299,7 +393,7 @@
  31631. struct sdhci_host *host = container_of(led, struct sdhci_host, led);
  31632. unsigned long flags;
  31633. - spin_lock_irqsave(&host->lock, flags);
  31634. + sdhci_spin_lock_irqsave(host, &flags);
  31635. if (host->runtime_suspended)
  31636. goto out;
  31637. @@ -309,7 +403,7 @@
  31638. else
  31639. sdhci_activate_led(host);
  31640. out:
  31641. - spin_unlock_irqrestore(&host->lock, flags);
  31642. + sdhci_spin_unlock_irqrestore(host, flags);
  31643. }
  31644. #endif
  31645. @@ -326,7 +420,7 @@
  31646. u32 uninitialized_var(scratch);
  31647. u8 *buf;
  31648. - DBG("PIO reading\n");
  31649. + DBG("PIO reading %db\n", host->data->blksz);
  31650. blksize = host->data->blksz;
  31651. chunk = 0;
  31652. @@ -371,7 +465,7 @@
  31653. u32 scratch;
  31654. u8 *buf;
  31655. - DBG("PIO writing\n");
  31656. + DBG("PIO writing %db\n", host->data->blksz);
  31657. blksize = host->data->blksz;
  31658. chunk = 0;
  31659. @@ -410,19 +504,28 @@
  31660. local_irq_restore(flags);
  31661. }
  31662. -static void sdhci_transfer_pio(struct sdhci_host *host)
  31663. +static void sdhci_transfer_pio(struct sdhci_host *host, u32 intstate)
  31664. {
  31665. u32 mask;
  31666. + u32 state = 0;
  31667. + u32 intmask;
  31668. + int available;
  31669. BUG_ON(!host->data);
  31670. if (host->blocks == 0)
  31671. return;
  31672. - if (host->data->flags & MMC_DATA_READ)
  31673. + if (host->data->flags & MMC_DATA_READ) {
  31674. mask = SDHCI_DATA_AVAILABLE;
  31675. - else
  31676. + intmask = SDHCI_INT_DATA_AVAIL;
  31677. + } else {
  31678. mask = SDHCI_SPACE_AVAILABLE;
  31679. + intmask = SDHCI_INT_SPACE_AVAIL;
  31680. + }
  31681. +
  31682. + /* initially we can see whether we can procede using intstate */
  31683. + available = (intstate & intmask);
  31684. /*
  31685. * Some controllers (JMicron JMB38x) mess up the buffer bits
  31686. @@ -433,7 +536,7 @@
  31687. (host->data->blocks == 1))
  31688. mask = ~0;
  31689. - while (sdhci_readl(host, SDHCI_PRESENT_STATE) & mask) {
  31690. + while (available) {
  31691. if (host->quirks & SDHCI_QUIRK_PIO_NEEDS_DELAY)
  31692. udelay(100);
  31693. @@ -445,9 +548,12 @@
  31694. host->blocks--;
  31695. if (host->blocks == 0)
  31696. break;
  31697. + state = sdhci_readl(host, SDHCI_PRESENT_STATE);
  31698. + available = state & mask;
  31699. + break;
  31700. }
  31701. - DBG("PIO transfer complete.\n");
  31702. + DBG("PIO transfer complete - %d blocks left.\n", host->blocks);
  31703. }
  31704. static char *sdhci_kmap_atomic(struct scatterlist *sg, unsigned long *flags)
  31705. @@ -720,7 +826,9 @@
  31706. u32 pio_irqs = SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL;
  31707. u32 dma_irqs = SDHCI_INT_DMA_END | SDHCI_INT_ADMA_ERROR;
  31708. - if (host->flags & SDHCI_REQ_USE_DMA)
  31709. + /* platform DMA will begin on receipt of PIO irqs */
  31710. + if ((host->flags & SDHCI_REQ_USE_DMA) &&
  31711. + !(host->flags & SDHCI_USE_PLATDMA))
  31712. sdhci_clear_set_irqs(host, pio_irqs, dma_irqs);
  31713. else
  31714. sdhci_clear_set_irqs(host, dma_irqs, pio_irqs);
  31715. @@ -752,44 +860,25 @@
  31716. host->data_early = 0;
  31717. host->data->bytes_xfered = 0;
  31718. - if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA))
  31719. + if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA | SDHCI_USE_PLATDMA))
  31720. host->flags |= SDHCI_REQ_USE_DMA;
  31721. /*
  31722. * FIXME: This doesn't account for merging when mapping the
  31723. * scatterlist.
  31724. */
  31725. - if (host->flags & SDHCI_REQ_USE_DMA) {
  31726. - int broken, i;
  31727. - struct scatterlist *sg;
  31728. -
  31729. - broken = 0;
  31730. - if (host->flags & SDHCI_USE_ADMA) {
  31731. - if (host->quirks & SDHCI_QUIRK_32BIT_ADMA_SIZE)
  31732. - broken = 1;
  31733. - } else {
  31734. - if (host->quirks & SDHCI_QUIRK_32BIT_DMA_SIZE)
  31735. - broken = 1;
  31736. - }
  31737. -
  31738. - if (unlikely(broken)) {
  31739. - for_each_sg(data->sg, sg, data->sg_len, i) {
  31740. - if (sg->length & 0x3) {
  31741. - DBG("Reverting to PIO because of "
  31742. - "transfer size (%d)\n",
  31743. - sg->length);
  31744. - host->flags &= ~SDHCI_REQ_USE_DMA;
  31745. - break;
  31746. - }
  31747. - }
  31748. - }
  31749. - }
  31750. /*
  31751. * The assumption here being that alignment is the same after
  31752. * translation to device address space.
  31753. */
  31754. - if (host->flags & SDHCI_REQ_USE_DMA) {
  31755. + if ((host->flags & (SDHCI_REQ_USE_DMA | SDHCI_USE_PLATDMA)) ==
  31756. + (SDHCI_REQ_USE_DMA | SDHCI_USE_PLATDMA)) {
  31757. +
  31758. + if (! sdhci_platdma_dmaable(host, data))
  31759. + host->flags &= ~SDHCI_REQ_USE_DMA;
  31760. +
  31761. + } else if (host->flags & SDHCI_REQ_USE_DMA) {
  31762. int broken, i;
  31763. struct scatterlist *sg;
  31764. @@ -848,7 +937,8 @@
  31765. */
  31766. WARN_ON(1);
  31767. host->flags &= ~SDHCI_REQ_USE_DMA;
  31768. - } else {
  31769. + } else
  31770. + if (!(host->flags & SDHCI_USE_PLATDMA)) {
  31771. WARN_ON(sg_cnt != 1);
  31772. sdhci_writel(host, sg_dma_address(data->sg),
  31773. SDHCI_DMA_ADDRESS);
  31774. @@ -864,11 +954,13 @@
  31775. if (host->version >= SDHCI_SPEC_200) {
  31776. ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL);
  31777. ctrl &= ~SDHCI_CTRL_DMA_MASK;
  31778. + if (! (host->flags & SDHCI_USE_PLATDMA)) {
  31779. if ((host->flags & SDHCI_REQ_USE_DMA) &&
  31780. (host->flags & SDHCI_USE_ADMA))
  31781. ctrl |= SDHCI_CTRL_ADMA32;
  31782. else
  31783. ctrl |= SDHCI_CTRL_SDMA;
  31784. + }
  31785. sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
  31786. }
  31787. @@ -920,7 +1012,8 @@
  31788. if (data->flags & MMC_DATA_READ)
  31789. mode |= SDHCI_TRNS_READ;
  31790. - if (host->flags & SDHCI_REQ_USE_DMA)
  31791. + if ((host->flags & SDHCI_REQ_USE_DMA) &&
  31792. + !(host->flags & SDHCI_USE_PLATDMA))
  31793. mode |= SDHCI_TRNS_DMA;
  31794. sdhci_writew(host, mode, SDHCI_TRANSFER_MODE);
  31795. @@ -936,13 +1029,16 @@
  31796. host->data = NULL;
  31797. if (host->flags & SDHCI_REQ_USE_DMA) {
  31798. - if (host->flags & SDHCI_USE_ADMA)
  31799. - sdhci_adma_table_post(host, data);
  31800. - else {
  31801. + /* we may have to abandon an ongoing platform DMA */
  31802. + if (host->flags & SDHCI_USE_PLATDMA)
  31803. + sdhci_platdma_reset(host, data);
  31804. +
  31805. + if (host->flags & (SDHCI_USE_PLATDMA | SDHCI_USE_SDMA)) {
  31806. dma_unmap_sg(mmc_dev(host->mmc), data->sg,
  31807. data->sg_len, (data->flags & MMC_DATA_READ) ?
  31808. DMA_FROM_DEVICE : DMA_TO_DEVICE);
  31809. - }
  31810. + } else if (host->flags & SDHCI_USE_ADMA)
  31811. + sdhci_adma_table_post(host, data);
  31812. }
  31813. /*
  31814. @@ -995,6 +1091,12 @@
  31815. if ((cmd->data != NULL) || (cmd->flags & MMC_RSP_BUSY))
  31816. mask |= SDHCI_DATA_INHIBIT;
  31817. + if(host->ops->missing_status && (cmd->opcode == MMC_SEND_STATUS)) {
  31818. + timeout = 5000; // Really obscenely large delay to send the status, due to bug in controller
  31819. + // which might cause the STATUS command to get stuck when a data operation is in flow
  31820. + mask |= SDHCI_DATA_INHIBIT;
  31821. + }
  31822. +
  31823. /* We shouldn't wait for data inihibit for stop commands, even
  31824. though they might use busy signaling */
  31825. if (host->mrq->data && (cmd == host->mrq->data->stop))
  31826. @@ -1010,12 +1112,20 @@
  31827. return;
  31828. }
  31829. timeout--;
  31830. + sdhci_spin_enable_schedule(host);
  31831. mdelay(1);
  31832. + sdhci_spin_disable_schedule(host);
  31833. }
  31834. + DBG("send cmd %d - wait 0x%X irq 0x%x\n", cmd->opcode, mask,
  31835. + sdhci_readl(host, SDHCI_INT_STATUS));
  31836. mod_timer(&host->timer, jiffies + 10 * HZ);
  31837. host->cmd = cmd;
  31838. + if (host->last_cmdop == MMC_APP_CMD)
  31839. + host->last_cmdop = -cmd->opcode;
  31840. + else
  31841. + host->last_cmdop = cmd->opcode;
  31842. sdhci_prepare_data(host, cmd);
  31843. @@ -1232,7 +1342,9 @@
  31844. return;
  31845. }
  31846. timeout--;
  31847. + sdhci_spin_enable_schedule(host);
  31848. mdelay(1);
  31849. + sdhci_spin_disable_schedule(host);
  31850. }
  31851. clk |= SDHCI_CLOCK_CARD_EN;
  31852. @@ -1333,7 +1445,7 @@
  31853. sdhci_runtime_pm_get(host);
  31854. - spin_lock_irqsave(&host->lock, flags);
  31855. + sdhci_spin_lock_irqsave(host, &flags);
  31856. WARN_ON(host->mrq != NULL);
  31857. @@ -1391,9 +1503,9 @@
  31858. mmc->card->type == MMC_TYPE_MMC ?
  31859. MMC_SEND_TUNING_BLOCK_HS200 :
  31860. MMC_SEND_TUNING_BLOCK;
  31861. - spin_unlock_irqrestore(&host->lock, flags);
  31862. + sdhci_spin_unlock_irqrestore(host, flags);
  31863. sdhci_execute_tuning(mmc, tuning_opcode);
  31864. - spin_lock_irqsave(&host->lock, flags);
  31865. + sdhci_spin_lock_irqsave(host, &flags);
  31866. /* Restore original mmc_request structure */
  31867. host->mrq = mrq;
  31868. @@ -1407,7 +1519,7 @@
  31869. }
  31870. mmiowb();
  31871. - spin_unlock_irqrestore(&host->lock, flags);
  31872. + sdhci_spin_unlock_irqrestore(host, flags);
  31873. }
  31874. static void sdhci_do_set_ios(struct sdhci_host *host, struct mmc_ios *ios)
  31875. @@ -1416,10 +1528,10 @@
  31876. int vdd_bit = -1;
  31877. u8 ctrl;
  31878. - spin_lock_irqsave(&host->lock, flags);
  31879. + sdhci_spin_lock_irqsave(host, &flags);
  31880. if (host->flags & SDHCI_DEVICE_DEAD) {
  31881. - spin_unlock_irqrestore(&host->lock, flags);
  31882. + sdhci_spin_unlock_irqrestore(host, flags);
  31883. if (host->vmmc && ios->power_mode == MMC_POWER_OFF)
  31884. mmc_regulator_set_ocr(host->mmc, host->vmmc, 0);
  31885. return;
  31886. @@ -1447,9 +1559,9 @@
  31887. vdd_bit = sdhci_set_power(host, ios->vdd);
  31888. if (host->vmmc && vdd_bit != -1) {
  31889. - spin_unlock_irqrestore(&host->lock, flags);
  31890. + sdhci_spin_unlock_irqrestore(host, flags);
  31891. mmc_regulator_set_ocr(host->mmc, host->vmmc, vdd_bit);
  31892. - spin_lock_irqsave(&host->lock, flags);
  31893. + sdhci_spin_lock_irqsave(host, &flags);
  31894. }
  31895. if (host->ops->platform_send_init_74_clocks)
  31896. @@ -1586,7 +1698,7 @@
  31897. sdhci_reset(host, SDHCI_RESET_CMD | SDHCI_RESET_DATA);
  31898. mmiowb();
  31899. - spin_unlock_irqrestore(&host->lock, flags);
  31900. + sdhci_spin_unlock_irqrestore(host, flags);
  31901. }
  31902. static void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
  31903. @@ -1634,7 +1746,7 @@
  31904. unsigned long flags;
  31905. int is_readonly;
  31906. - spin_lock_irqsave(&host->lock, flags);
  31907. + sdhci_spin_lock_irqsave(host, &flags);
  31908. if (host->flags & SDHCI_DEVICE_DEAD)
  31909. is_readonly = 0;
  31910. @@ -1644,7 +1756,7 @@
  31911. is_readonly = !(sdhci_readl(host, SDHCI_PRESENT_STATE)
  31912. & SDHCI_WRITE_PROTECT);
  31913. - spin_unlock_irqrestore(&host->lock, flags);
  31914. + sdhci_spin_unlock_irqrestore(host, flags);
  31915. /* This quirk needs to be replaced by a callback-function later */
  31916. return host->quirks & SDHCI_QUIRK_INVERTED_WRITE_PROTECT ?
  31917. @@ -1717,9 +1829,9 @@
  31918. struct sdhci_host *host = mmc_priv(mmc);
  31919. unsigned long flags;
  31920. - spin_lock_irqsave(&host->lock, flags);
  31921. + sdhci_spin_lock_irqsave(host, &flags);
  31922. sdhci_enable_sdio_irq_nolock(host, enable);
  31923. - spin_unlock_irqrestore(&host->lock, flags);
  31924. + sdhci_spin_unlock_irqrestore(host, flags);
  31925. }
  31926. static int sdhci_do_start_signal_voltage_switch(struct sdhci_host *host,
  31927. @@ -2070,7 +2182,7 @@
  31928. if (host->ops->card_event)
  31929. host->ops->card_event(host);
  31930. - spin_lock_irqsave(&host->lock, flags);
  31931. + sdhci_spin_lock_irqsave(host, &flags);
  31932. /* Check host->mrq first in case we are runtime suspended */
  31933. if (host->mrq && !sdhci_do_get_cd(host)) {
  31934. @@ -2086,7 +2198,7 @@
  31935. tasklet_schedule(&host->finish_tasklet);
  31936. }
  31937. - spin_unlock_irqrestore(&host->lock, flags);
  31938. + sdhci_spin_unlock_irqrestore(host, flags);
  31939. }
  31940. static const struct mmc_host_ops sdhci_ops = {
  31941. @@ -2125,14 +2237,14 @@
  31942. host = (struct sdhci_host*)param;
  31943. - spin_lock_irqsave(&host->lock, flags);
  31944. + sdhci_spin_lock_irqsave(host, &flags);
  31945. /*
  31946. * If this tasklet gets rescheduled while running, it will
  31947. * be run again afterwards but without any active request.
  31948. */
  31949. if (!host->mrq) {
  31950. - spin_unlock_irqrestore(&host->lock, flags);
  31951. + sdhci_spin_unlock_irqrestore(host, flags);
  31952. return;
  31953. }
  31954. @@ -2170,7 +2282,7 @@
  31955. #endif
  31956. mmiowb();
  31957. - spin_unlock_irqrestore(&host->lock, flags);
  31958. + sdhci_spin_unlock_irqrestore(host, flags);
  31959. mmc_request_done(host->mmc, mrq);
  31960. sdhci_runtime_pm_put(host);
  31961. @@ -2183,11 +2295,11 @@
  31962. host = (struct sdhci_host*)data;
  31963. - spin_lock_irqsave(&host->lock, flags);
  31964. + sdhci_spin_lock_irqsave(host, &flags);
  31965. if (host->mrq) {
  31966. pr_err("%s: Timeout waiting for hardware "
  31967. - "interrupt.\n", mmc_hostname(host->mmc));
  31968. + "interrupt - cmd%d.\n", mmc_hostname(host->mmc), host->last_cmdop);
  31969. sdhci_dumpregs(host);
  31970. if (host->data) {
  31971. @@ -2204,7 +2316,7 @@
  31972. }
  31973. mmiowb();
  31974. - spin_unlock_irqrestore(&host->lock, flags);
  31975. + sdhci_spin_unlock_irqrestore(host, flags);
  31976. }
  31977. static void sdhci_tuning_timer(unsigned long data)
  31978. @@ -2214,11 +2326,11 @@
  31979. host = (struct sdhci_host *)data;
  31980. - spin_lock_irqsave(&host->lock, flags);
  31981. + sdhci_spin_lock_irqsave(host, &flags);
  31982. host->flags |= SDHCI_NEEDS_RETUNING;
  31983. - spin_unlock_irqrestore(&host->lock, flags);
  31984. + sdhci_spin_unlock_irqrestore(host, flags);
  31985. }
  31986. /*****************************************************************************\
  31987. @@ -2232,10 +2344,13 @@
  31988. BUG_ON(intmask == 0);
  31989. if (!host->cmd) {
  31990. + if (!(host->ops->extra_ints)) {
  31991. pr_err("%s: Got command interrupt 0x%08x even "
  31992. "though no command operation was in progress.\n",
  31993. mmc_hostname(host->mmc), (unsigned)intmask);
  31994. sdhci_dumpregs(host);
  31995. + } else
  31996. + DBG("cmd irq 0x%08x cmd complete\n", (unsigned)intmask);
  31997. return;
  31998. }
  31999. @@ -2305,6 +2420,19 @@
  32000. static void sdhci_show_adma_error(struct sdhci_host *host) { }
  32001. #endif
  32002. +static void sdhci_data_end(struct sdhci_host *host)
  32003. +{
  32004. + if (host->cmd) {
  32005. + /*
  32006. + * Data managed to finish before the
  32007. + * command completed. Make sure we do
  32008. + * things in the proper order.
  32009. + */
  32010. + host->data_early = 1;
  32011. + } else
  32012. + sdhci_finish_data(host);
  32013. +}
  32014. +
  32015. static void sdhci_data_irq(struct sdhci_host *host, u32 intmask)
  32016. {
  32017. u32 command;
  32018. @@ -2334,23 +2462,39 @@
  32019. }
  32020. }
  32021. + if (!(host->ops->extra_ints)) {
  32022. pr_err("%s: Got data interrupt 0x%08x even "
  32023. "though no data operation was in progress.\n",
  32024. mmc_hostname(host->mmc), (unsigned)intmask);
  32025. sdhci_dumpregs(host);
  32026. + } else
  32027. + DBG("data irq 0x%08x but no data\n", (unsigned)intmask);
  32028. return;
  32029. }
  32030. if (intmask & SDHCI_INT_DATA_TIMEOUT)
  32031. host->data->error = -ETIMEDOUT;
  32032. - else if (intmask & SDHCI_INT_DATA_END_BIT)
  32033. + else if (intmask & SDHCI_INT_DATA_END_BIT) {
  32034. + DBG("end error in cmd %d\n", host->last_cmdop);
  32035. + if (host->ops->spurious_crc_acmd51 &&
  32036. + host->last_cmdop == -SD_APP_SEND_SCR) {
  32037. + DBG("ignoring spurious data_end_bit error\n");
  32038. + intmask = SDHCI_INT_DATA_AVAIL|SDHCI_INT_DATA_END;
  32039. + } else
  32040. host->data->error = -EILSEQ;
  32041. - else if ((intmask & SDHCI_INT_DATA_CRC) &&
  32042. + } else if ((intmask & SDHCI_INT_DATA_CRC) &&
  32043. SDHCI_GET_CMD(sdhci_readw(host, SDHCI_COMMAND))
  32044. - != MMC_BUS_TEST_R)
  32045. + != MMC_BUS_TEST_R) {
  32046. + DBG("crc error in cmd %d\n", host->last_cmdop);
  32047. + if (host->ops->spurious_crc_acmd51 &&
  32048. + host->last_cmdop == -SD_APP_SEND_SCR) {
  32049. + DBG("ignoring spurious data_crc_bit error\n");
  32050. + intmask = SDHCI_INT_DATA_AVAIL|SDHCI_INT_DATA_END;
  32051. + } else {
  32052. host->data->error = -EILSEQ;
  32053. - else if (intmask & SDHCI_INT_ADMA_ERROR) {
  32054. + }
  32055. + } else if (intmask & SDHCI_INT_ADMA_ERROR) {
  32056. pr_err("%s: ADMA error\n", mmc_hostname(host->mmc));
  32057. sdhci_show_adma_error(host);
  32058. host->data->error = -EIO;
  32059. @@ -2358,11 +2502,18 @@
  32060. host->ops->adma_workaround(host, intmask);
  32061. }
  32062. - if (host->data->error)
  32063. + if (host->data->error) {
  32064. + DBG("finish request early on error %d\n", host->data->error);
  32065. sdhci_finish_data(host);
  32066. - else {
  32067. - if (intmask & (SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL))
  32068. - sdhci_transfer_pio(host);
  32069. + } else {
  32070. + if (intmask & (SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL)) {
  32071. + if (host->flags & SDHCI_REQ_USE_DMA) {
  32072. + /* possible only in PLATDMA mode */
  32073. + sdhci_platdma_avail(host, &intmask,
  32074. + &sdhci_data_end);
  32075. + } else
  32076. + sdhci_transfer_pio(host, intmask);
  32077. + }
  32078. /*
  32079. * We currently don't do anything fancy with DMA
  32080. @@ -2391,18 +2542,8 @@
  32081. sdhci_writel(host, dmanow, SDHCI_DMA_ADDRESS);
  32082. }
  32083. - if (intmask & SDHCI_INT_DATA_END) {
  32084. - if (host->cmd) {
  32085. - /*
  32086. - * Data managed to finish before the
  32087. - * command completed. Make sure we do
  32088. - * things in the proper order.
  32089. - */
  32090. - host->data_early = 1;
  32091. - } else {
  32092. - sdhci_finish_data(host);
  32093. - }
  32094. - }
  32095. + if (intmask & SDHCI_INT_DATA_END)
  32096. + sdhci_data_end(host);
  32097. }
  32098. }
  32099. @@ -2413,10 +2554,10 @@
  32100. u32 intmask, unexpected = 0;
  32101. int cardint = 0, max_loops = 16;
  32102. - spin_lock(&host->lock);
  32103. + sdhci_spin_lock(host);
  32104. if (host->runtime_suspended) {
  32105. - spin_unlock(&host->lock);
  32106. + sdhci_spin_unlock(host);
  32107. pr_warning("%s: got irq while runtime suspended\n",
  32108. mmc_hostname(host->mmc));
  32109. return IRQ_HANDLED;
  32110. @@ -2458,6 +2599,22 @@
  32111. tasklet_schedule(&host->card_tasklet);
  32112. }
  32113. + if (intmask & SDHCI_INT_ERROR_MASK & ~SDHCI_INT_ERROR)
  32114. + DBG("controller reports error 0x%x -"
  32115. + "%s%s%s%s%s%s%s%s%s%s",
  32116. + intmask,
  32117. + intmask & SDHCI_INT_TIMEOUT? " timeout": "",
  32118. + intmask & SDHCI_INT_CRC ? " crc": "",
  32119. + intmask & SDHCI_INT_END_BIT? " endbit": "",
  32120. + intmask & SDHCI_INT_INDEX? " index": "",
  32121. + intmask & SDHCI_INT_DATA_TIMEOUT? " data_timeout": "",
  32122. + intmask & SDHCI_INT_DATA_CRC? " data_crc": "",
  32123. + intmask & SDHCI_INT_DATA_END_BIT? " data_endbit": "",
  32124. + intmask & SDHCI_INT_BUS_POWER? " buspower": "",
  32125. + intmask & SDHCI_INT_ACMD12ERR? " acmd12": "",
  32126. + intmask & SDHCI_INT_ADMA_ERROR? " adma": ""
  32127. + );
  32128. +
  32129. if (intmask & SDHCI_INT_CMD_MASK) {
  32130. sdhci_writel(host, intmask & SDHCI_INT_CMD_MASK,
  32131. SDHCI_INT_STATUS);
  32132. @@ -2472,7 +2629,13 @@
  32133. intmask &= ~(SDHCI_INT_CMD_MASK | SDHCI_INT_DATA_MASK);
  32134. - intmask &= ~SDHCI_INT_ERROR;
  32135. + if (intmask & SDHCI_INT_ERROR_MASK) {
  32136. + /* collect any uncovered errors */
  32137. + sdhci_writel(host, intmask & SDHCI_INT_ERROR_MASK,
  32138. + SDHCI_INT_STATUS);
  32139. + }
  32140. +
  32141. + intmask &= ~SDHCI_INT_ERROR_MASK;
  32142. if (intmask & SDHCI_INT_BUS_POWER) {
  32143. pr_err("%s: Card is consuming too much power!\n",
  32144. @@ -2506,7 +2669,7 @@
  32145. if (intmask && --max_loops)
  32146. goto again;
  32147. out:
  32148. - spin_unlock(&host->lock);
  32149. + sdhci_spin_unlock(host);
  32150. if (unexpected) {
  32151. pr_err("%s: Unexpected interrupt 0x%08x.\n",
  32152. @@ -2585,13 +2748,14 @@
  32153. {
  32154. int ret = 0;
  32155. - if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) {
  32156. + if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA |
  32157. + SDHCI_USE_PLATDMA)) {
  32158. if (host->ops->enable_dma)
  32159. host->ops->enable_dma(host);
  32160. }
  32161. if (!device_may_wakeup(mmc_dev(host->mmc))) {
  32162. - ret = request_irq(host->irq, sdhci_irq, IRQF_SHARED,
  32163. + ret = request_irq(host->irq, sdhci_irq, 0 /*IRQF_SHARED*/,
  32164. mmc_hostname(host->mmc), host);
  32165. if (ret)
  32166. return ret;
  32167. @@ -2667,15 +2831,15 @@
  32168. host->flags &= ~SDHCI_NEEDS_RETUNING;
  32169. }
  32170. - spin_lock_irqsave(&host->lock, flags);
  32171. + sdhci_spin_lock_irqsave(host, &flags);
  32172. sdhci_mask_irqs(host, SDHCI_INT_ALL_MASK);
  32173. - spin_unlock_irqrestore(&host->lock, flags);
  32174. + sdhci_spin_unlock_irqrestore(host, flags);
  32175. synchronize_irq(host->irq);
  32176. - spin_lock_irqsave(&host->lock, flags);
  32177. + sdhci_spin_lock_irqsave(host, &flags);
  32178. host->runtime_suspended = true;
  32179. - spin_unlock_irqrestore(&host->lock, flags);
  32180. + sdhci_spin_unlock_irqrestore(host, flags);
  32181. return ret;
  32182. }
  32183. @@ -2701,16 +2865,16 @@
  32184. sdhci_do_start_signal_voltage_switch(host, &host->mmc->ios);
  32185. if ((host_flags & SDHCI_PV_ENABLED) &&
  32186. !(host->quirks2 & SDHCI_QUIRK2_PRESET_VALUE_BROKEN)) {
  32187. - spin_lock_irqsave(&host->lock, flags);
  32188. + sdhci_spin_lock_irqsave(host, &flags);
  32189. sdhci_enable_preset_value(host, true);
  32190. - spin_unlock_irqrestore(&host->lock, flags);
  32191. + sdhci_spin_unlock_irqrestore(host, flags);
  32192. }
  32193. /* Set the re-tuning expiration flag */
  32194. if (host->flags & SDHCI_USING_RETUNING_TIMER)
  32195. host->flags |= SDHCI_NEEDS_RETUNING;
  32196. - spin_lock_irqsave(&host->lock, flags);
  32197. + sdhci_spin_lock_irqsave(host, &flags);
  32198. host->runtime_suspended = false;
  32199. @@ -2721,7 +2885,7 @@
  32200. /* Enable Card Detection */
  32201. sdhci_enable_card_detection(host);
  32202. - spin_unlock_irqrestore(&host->lock, flags);
  32203. + sdhci_spin_unlock_irqrestore(host, flags);
  32204. return ret;
  32205. }
  32206. @@ -2816,14 +2980,16 @@
  32207. host->flags &= ~SDHCI_USE_ADMA;
  32208. }
  32209. - if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) {
  32210. + if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA |
  32211. + SDHCI_USE_PLATDMA)) {
  32212. if (host->ops->enable_dma) {
  32213. if (host->ops->enable_dma(host)) {
  32214. pr_warning("%s: No suitable DMA "
  32215. "available. Falling back to PIO.\n",
  32216. mmc_hostname(mmc));
  32217. host->flags &=
  32218. - ~(SDHCI_USE_SDMA | SDHCI_USE_ADMA);
  32219. + ~(SDHCI_USE_SDMA | SDHCI_USE_ADMA |
  32220. + SDHCI_USE_PLATDMA);
  32221. }
  32222. }
  32223. }
  32224. @@ -3215,8 +3381,8 @@
  32225. sdhci_init(host, 0);
  32226. - ret = request_irq(host->irq, sdhci_irq, IRQF_SHARED,
  32227. - mmc_hostname(mmc), host);
  32228. + ret = request_irq(host->irq, sdhci_irq, 0 /*IRQF_SHARED*/,
  32229. + mmc_hostname(mmc), host);
  32230. if (ret) {
  32231. pr_err("%s: Failed to request IRQ %d: %d\n",
  32232. mmc_hostname(mmc), host->irq, ret);
  32233. @@ -3249,6 +3415,7 @@
  32234. pr_info("%s: SDHCI controller on %s [%s] using %s\n",
  32235. mmc_hostname(mmc), host->hw_name, dev_name(mmc_dev(mmc)),
  32236. + (host->flags & SDHCI_USE_PLATDMA) ? "platform's DMA" :
  32237. (host->flags & SDHCI_USE_ADMA) ? "ADMA" :
  32238. (host->flags & SDHCI_USE_SDMA) ? "DMA" : "PIO");
  32239. @@ -3276,7 +3443,7 @@
  32240. unsigned long flags;
  32241. if (dead) {
  32242. - spin_lock_irqsave(&host->lock, flags);
  32243. + sdhci_spin_lock_irqsave(host, &flags);
  32244. host->flags |= SDHCI_DEVICE_DEAD;
  32245. @@ -3288,7 +3455,7 @@
  32246. tasklet_schedule(&host->finish_tasklet);
  32247. }
  32248. - spin_unlock_irqrestore(&host->lock, flags);
  32249. + sdhci_spin_unlock_irqrestore(host, flags);
  32250. }
  32251. sdhci_disable_card_detection(host);
  32252. diff -Nur linux-3.13.11/drivers/mmc/host/sdhci.h linux-rpi/drivers/mmc/host/sdhci.h
  32253. --- linux-3.13.11/drivers/mmc/host/sdhci.h 2014-04-23 01:49:33.000000000 +0200
  32254. +++ linux-rpi/drivers/mmc/host/sdhci.h 2014-04-24 15:36:51.726754267 +0200
  32255. @@ -290,6 +290,18 @@
  32256. void (*platform_reset_exit)(struct sdhci_host *host, u8 mask);
  32257. int (*platform_execute_tuning)(struct sdhci_host *host, u32 opcode);
  32258. int (*set_uhs_signaling)(struct sdhci_host *host, unsigned int uhs);
  32259. +
  32260. + int (*pdma_able)(struct sdhci_host *host,
  32261. + struct mmc_data *data);
  32262. + void (*pdma_avail)(struct sdhci_host *host,
  32263. + unsigned int *ref_intmask,
  32264. + void(*complete)(struct sdhci_host *));
  32265. + void (*pdma_reset)(struct sdhci_host *host,
  32266. + struct mmc_data *data);
  32267. + unsigned int (*extra_ints)(struct sdhci_host *host);
  32268. + unsigned int (*spurious_crc_acmd51)(struct sdhci_host *host);
  32269. + unsigned int (*missing_status)(struct sdhci_host *host);
  32270. +
  32271. void (*hw_reset)(struct sdhci_host *host);
  32272. void (*platform_suspend)(struct sdhci_host *host);
  32273. void (*platform_resume)(struct sdhci_host *host);
  32274. @@ -403,9 +415,38 @@
  32275. extern void sdhci_enable_irq_wakeups(struct sdhci_host *host);
  32276. #endif
  32277. +static inline int /*bool*/
  32278. +sdhci_platdma_dmaable(struct sdhci_host *host, struct mmc_data *data)
  32279. +{
  32280. + if (host->ops->pdma_able)
  32281. + return host->ops->pdma_able(host, data);
  32282. + else
  32283. + return 1;
  32284. +}
  32285. +static inline void
  32286. +sdhci_platdma_avail(struct sdhci_host *host, unsigned int *ref_intmask,
  32287. + void(*completion_callback)(struct sdhci_host *))
  32288. +{
  32289. + if (host->ops->pdma_avail)
  32290. + host->ops->pdma_avail(host, ref_intmask, completion_callback);
  32291. +}
  32292. +
  32293. +static inline void
  32294. +sdhci_platdma_reset(struct sdhci_host *host, struct mmc_data *data)
  32295. +{
  32296. + if (host->ops->pdma_reset)
  32297. + host->ops->pdma_reset(host, data);
  32298. +}
  32299. +
  32300. #ifdef CONFIG_PM_RUNTIME
  32301. extern int sdhci_runtime_suspend_host(struct sdhci_host *host);
  32302. extern int sdhci_runtime_resume_host(struct sdhci_host *host);
  32303. #endif
  32304. +extern void sdhci_spin_lock_irqsave(struct sdhci_host *host,unsigned long *flags);
  32305. +extern void sdhci_spin_unlock_irqrestore(struct sdhci_host *host,unsigned long flags);
  32306. +extern void sdhci_spin_lock(struct sdhci_host *host);
  32307. +extern void sdhci_spin_unlock(struct sdhci_host *host);
  32308. +
  32309. +
  32310. #endif /* __SDHCI_HW_H */
  32311. diff -Nur linux-3.13.11/drivers/net/usb/smsc95xx.c linux-rpi/drivers/net/usb/smsc95xx.c
  32312. --- linux-3.13.11/drivers/net/usb/smsc95xx.c 2014-04-23 01:49:33.000000000 +0200
  32313. +++ linux-rpi/drivers/net/usb/smsc95xx.c 2014-04-24 15:35:03.209555036 +0200
  32314. @@ -61,6 +61,7 @@
  32315. #define SUSPEND_SUSPEND3 (0x08)
  32316. #define SUSPEND_ALLMODES (SUSPEND_SUSPEND0 | SUSPEND_SUSPEND1 | \
  32317. SUSPEND_SUSPEND2 | SUSPEND_SUSPEND3)
  32318. +#define MAC_ADDR_LEN (6)
  32319. struct smsc95xx_priv {
  32320. u32 mac_cr;
  32321. @@ -76,6 +77,10 @@
  32322. module_param(turbo_mode, bool, 0644);
  32323. MODULE_PARM_DESC(turbo_mode, "Enable multiple frames per Rx transaction");
  32324. +static char *macaddr = ":";
  32325. +module_param(macaddr, charp, 0);
  32326. +MODULE_PARM_DESC(macaddr, "MAC address");
  32327. +
  32328. static int __must_check __smsc95xx_read_reg(struct usbnet *dev, u32 index,
  32329. u32 *data, int in_pm)
  32330. {
  32331. @@ -765,8 +770,59 @@
  32332. return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
  32333. }
  32334. +/* Check the macaddr module parameter for a MAC address */
  32335. +static int smsc95xx_is_macaddr_param(struct usbnet *dev, u8 *dev_mac)
  32336. +{
  32337. + int i, j, got_num, num;
  32338. + u8 mtbl[MAC_ADDR_LEN];
  32339. +
  32340. + if (macaddr[0] == ':')
  32341. + return 0;
  32342. +
  32343. + i = 0;
  32344. + j = 0;
  32345. + num = 0;
  32346. + got_num = 0;
  32347. + while (j < MAC_ADDR_LEN) {
  32348. + if (macaddr[i] && macaddr[i] != ':') {
  32349. + got_num++;
  32350. + if ('0' <= macaddr[i] && macaddr[i] <= '9')
  32351. + num = num * 16 + macaddr[i] - '0';
  32352. + else if ('A' <= macaddr[i] && macaddr[i] <= 'F')
  32353. + num = num * 16 + 10 + macaddr[i] - 'A';
  32354. + else if ('a' <= macaddr[i] && macaddr[i] <= 'f')
  32355. + num = num * 16 + 10 + macaddr[i] - 'a';
  32356. + else
  32357. + break;
  32358. + i++;
  32359. + } else if (got_num == 2) {
  32360. + mtbl[j++] = (u8) num;
  32361. + num = 0;
  32362. + got_num = 0;
  32363. + i++;
  32364. + } else {
  32365. + break;
  32366. + }
  32367. + }
  32368. +
  32369. + if (j == MAC_ADDR_LEN) {
  32370. + netif_dbg(dev, ifup, dev->net, "Overriding MAC address with: "
  32371. + "%02x:%02x:%02x:%02x:%02x:%02x\n", mtbl[0], mtbl[1], mtbl[2],
  32372. + mtbl[3], mtbl[4], mtbl[5]);
  32373. + for (i = 0; i < MAC_ADDR_LEN; i++)
  32374. + dev_mac[i] = mtbl[i];
  32375. + return 1;
  32376. + } else {
  32377. + return 0;
  32378. + }
  32379. +}
  32380. +
  32381. static void smsc95xx_init_mac_address(struct usbnet *dev)
  32382. {
  32383. + /* Check module parameters */
  32384. + if (smsc95xx_is_macaddr_param(dev, dev->net->dev_addr))
  32385. + return;
  32386. +
  32387. /* try reading mac address from EEPROM */
  32388. if (smsc95xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
  32389. dev->net->dev_addr) == 0) {
  32390. diff -Nur linux-3.13.11/drivers/pci/host/pcie-designware.c linux-rpi/drivers/pci/host/pcie-designware.c
  32391. --- linux-3.13.11/drivers/pci/host/pcie-designware.c 2014-04-23 01:49:33.000000000 +0200
  32392. +++ linux-rpi/drivers/pci/host/pcie-designware.c 2014-04-24 15:37:02.286869933 +0200
  32393. @@ -498,13 +498,13 @@
  32394. dw_pcie_writel_rc(pp, PCIE_ATU_REGION_OUTBOUND | PCIE_ATU_REGION_INDEX1,
  32395. PCIE_ATU_VIEWPORT);
  32396. dw_pcie_writel_rc(pp, PCIE_ATU_TYPE_CFG1, PCIE_ATU_CR1);
  32397. + dw_pcie_writel_rc(pp, PCIE_ATU_ENABLE, PCIE_ATU_CR2);
  32398. dw_pcie_writel_rc(pp, pp->cfg1_base, PCIE_ATU_LOWER_BASE);
  32399. dw_pcie_writel_rc(pp, (pp->cfg1_base >> 32), PCIE_ATU_UPPER_BASE);
  32400. dw_pcie_writel_rc(pp, pp->cfg1_base + pp->config.cfg1_size - 1,
  32401. PCIE_ATU_LIMIT);
  32402. dw_pcie_writel_rc(pp, busdev, PCIE_ATU_LOWER_TARGET);
  32403. dw_pcie_writel_rc(pp, 0, PCIE_ATU_UPPER_TARGET);
  32404. - dw_pcie_writel_rc(pp, PCIE_ATU_ENABLE, PCIE_ATU_CR2);
  32405. }
  32406. static void dw_pcie_prog_viewport_mem_outbound(struct pcie_port *pp)
  32407. @@ -513,6 +513,7 @@
  32408. dw_pcie_writel_rc(pp, PCIE_ATU_REGION_OUTBOUND | PCIE_ATU_REGION_INDEX0,
  32409. PCIE_ATU_VIEWPORT);
  32410. dw_pcie_writel_rc(pp, PCIE_ATU_TYPE_MEM, PCIE_ATU_CR1);
  32411. + dw_pcie_writel_rc(pp, PCIE_ATU_ENABLE, PCIE_ATU_CR2);
  32412. dw_pcie_writel_rc(pp, pp->mem_base, PCIE_ATU_LOWER_BASE);
  32413. dw_pcie_writel_rc(pp, (pp->mem_base >> 32), PCIE_ATU_UPPER_BASE);
  32414. dw_pcie_writel_rc(pp, pp->mem_base + pp->config.mem_size - 1,
  32415. @@ -520,7 +521,6 @@
  32416. dw_pcie_writel_rc(pp, pp->config.mem_bus_addr, PCIE_ATU_LOWER_TARGET);
  32417. dw_pcie_writel_rc(pp, upper_32_bits(pp->config.mem_bus_addr),
  32418. PCIE_ATU_UPPER_TARGET);
  32419. - dw_pcie_writel_rc(pp, PCIE_ATU_ENABLE, PCIE_ATU_CR2);
  32420. }
  32421. static void dw_pcie_prog_viewport_io_outbound(struct pcie_port *pp)
  32422. @@ -529,6 +529,7 @@
  32423. dw_pcie_writel_rc(pp, PCIE_ATU_REGION_OUTBOUND | PCIE_ATU_REGION_INDEX1,
  32424. PCIE_ATU_VIEWPORT);
  32425. dw_pcie_writel_rc(pp, PCIE_ATU_TYPE_IO, PCIE_ATU_CR1);
  32426. + dw_pcie_writel_rc(pp, PCIE_ATU_ENABLE, PCIE_ATU_CR2);
  32427. dw_pcie_writel_rc(pp, pp->io_base, PCIE_ATU_LOWER_BASE);
  32428. dw_pcie_writel_rc(pp, (pp->io_base >> 32), PCIE_ATU_UPPER_BASE);
  32429. dw_pcie_writel_rc(pp, pp->io_base + pp->config.io_size - 1,
  32430. @@ -536,7 +537,6 @@
  32431. dw_pcie_writel_rc(pp, pp->config.io_bus_addr, PCIE_ATU_LOWER_TARGET);
  32432. dw_pcie_writel_rc(pp, upper_32_bits(pp->config.io_bus_addr),
  32433. PCIE_ATU_UPPER_TARGET);
  32434. - dw_pcie_writel_rc(pp, PCIE_ATU_ENABLE, PCIE_ATU_CR2);
  32435. }
  32436. static int dw_pcie_rd_other_conf(struct pcie_port *pp, struct pci_bus *bus,
  32437. @@ -773,7 +773,7 @@
  32438. /* setup RC BARs */
  32439. dw_pcie_writel_rc(pp, 0x00000004, PCI_BASE_ADDRESS_0);
  32440. - dw_pcie_writel_rc(pp, 0x00000000, PCI_BASE_ADDRESS_1);
  32441. + dw_pcie_writel_rc(pp, 0x00000004, PCI_BASE_ADDRESS_1);
  32442. /* setup interrupt pins */
  32443. dw_pcie_readl_rc(pp, PCI_INTERRUPT_LINE, &val);
  32444. diff -Nur linux-3.13.11/drivers/pci/pci.c linux-rpi/drivers/pci/pci.c
  32445. --- linux-3.13.11/drivers/pci/pci.c 2014-04-23 01:49:33.000000000 +0200
  32446. +++ linux-rpi/drivers/pci/pci.c 2014-04-24 15:37:02.318870283 +0200
  32447. @@ -1134,9 +1134,6 @@
  32448. if (dev->msi_enabled || dev->msix_enabled)
  32449. return 0;
  32450. - if (dev->msi_enabled || dev->msix_enabled)
  32451. - return 0;
  32452. -
  32453. pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin);
  32454. if (pin) {
  32455. pci_read_config_word(dev, PCI_COMMAND, &cmd);
  32456. diff -Nur linux-3.13.11/drivers/scsi/sd.c linux-rpi/drivers/scsi/sd.c
  32457. --- linux-3.13.11/drivers/scsi/sd.c 2014-04-23 01:49:33.000000000 +0200
  32458. +++ linux-rpi/drivers/scsi/sd.c 2014-04-24 15:37:04.734896721 +0200
  32459. @@ -1463,8 +1463,8 @@
  32460. sd_print_sense_hdr(sdkp, &sshdr);
  32461. /* we need to evaluate the error return */
  32462. if (scsi_sense_valid(&sshdr) &&
  32463. - (sshdr.asc == 0x3a || /* medium not present */
  32464. - sshdr.asc == 0x20)) /* invalid command */
  32465. + /* 0x3a is medium not present */
  32466. + sshdr.asc == 0x3a)
  32467. /* this is no error here */
  32468. return 0;
  32469. diff -Nur linux-3.13.11/drivers/spi/Kconfig linux-rpi/drivers/spi/Kconfig
  32470. --- linux-3.13.11/drivers/spi/Kconfig 2014-04-23 01:49:33.000000000 +0200
  32471. +++ linux-rpi/drivers/spi/Kconfig 2014-04-24 15:37:04.738896765 +0200
  32472. @@ -85,6 +85,14 @@
  32473. is for the regular SPI controller. Slave mode operation is not also
  32474. not supported.
  32475. +config SPI_BCM2708
  32476. + tristate "BCM2708 SPI controller driver (SPI0)"
  32477. + depends on MACH_BCM2708
  32478. + help
  32479. + This selects a driver for the Broadcom BCM2708 SPI master (SPI0). This
  32480. + driver is not compatible with the "Universal SPI Master" or the SPI slave
  32481. + device.
  32482. +
  32483. config SPI_BFIN5XX
  32484. tristate "SPI controller driver for ADI Blackfin5xx"
  32485. depends on BLACKFIN && !BF60x
  32486. diff -Nur linux-3.13.11/drivers/spi/Makefile linux-rpi/drivers/spi/Makefile
  32487. --- linux-3.13.11/drivers/spi/Makefile 2014-04-23 01:49:33.000000000 +0200
  32488. +++ linux-rpi/drivers/spi/Makefile 2014-04-24 15:37:04.738896765 +0200
  32489. @@ -18,6 +18,7 @@
  32490. obj-$(CONFIG_SPI_BCM63XX) += spi-bcm63xx.o
  32491. obj-$(CONFIG_SPI_BFIN5XX) += spi-bfin5xx.o
  32492. obj-$(CONFIG_SPI_BFIN_V3) += spi-bfin-v3.o
  32493. +obj-$(CONFIG_SPI_BCM2708) += spi-bcm2708.o
  32494. obj-$(CONFIG_SPI_BFIN_SPORT) += spi-bfin-sport.o
  32495. obj-$(CONFIG_SPI_BITBANG) += spi-bitbang.o
  32496. obj-$(CONFIG_SPI_BUTTERFLY) += spi-butterfly.o
  32497. diff -Nur linux-3.13.11/drivers/spi/spi-bcm2708.c linux-rpi/drivers/spi/spi-bcm2708.c
  32498. --- linux-3.13.11/drivers/spi/spi-bcm2708.c 1970-01-01 01:00:00.000000000 +0100
  32499. +++ linux-rpi/drivers/spi/spi-bcm2708.c 2014-04-24 15:37:04.738896765 +0200
  32500. @@ -0,0 +1,626 @@
  32501. +/*
  32502. + * Driver for Broadcom BCM2708 SPI Controllers
  32503. + *
  32504. + * Copyright (C) 2012 Chris Boot
  32505. + *
  32506. + * This driver is inspired by:
  32507. + * spi-ath79.c, Copyright (C) 2009-2011 Gabor Juhos <juhosg@openwrt.org>
  32508. + * spi-atmel.c, Copyright (C) 2006 Atmel Corporation
  32509. + *
  32510. + * This program is free software; you can redistribute it and/or modify
  32511. + * it under the terms of the GNU General Public License as published by
  32512. + * the Free Software Foundation; either version 2 of the License, or
  32513. + * (at your option) any later version.
  32514. + *
  32515. + * This program is distributed in the hope that it will be useful,
  32516. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  32517. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  32518. + * GNU General Public License for more details.
  32519. + *
  32520. + * You should have received a copy of the GNU General Public License
  32521. + * along with this program; if not, write to the Free Software
  32522. + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  32523. + */
  32524. +
  32525. +#include <linux/kernel.h>
  32526. +#include <linux/module.h>
  32527. +#include <linux/spinlock.h>
  32528. +#include <linux/clk.h>
  32529. +#include <linux/err.h>
  32530. +#include <linux/platform_device.h>
  32531. +#include <linux/io.h>
  32532. +#include <linux/spi/spi.h>
  32533. +#include <linux/interrupt.h>
  32534. +#include <linux/delay.h>
  32535. +#include <linux/log2.h>
  32536. +#include <linux/sched.h>
  32537. +#include <linux/wait.h>
  32538. +
  32539. +/* SPI register offsets */
  32540. +#define SPI_CS 0x00
  32541. +#define SPI_FIFO 0x04
  32542. +#define SPI_CLK 0x08
  32543. +#define SPI_DLEN 0x0c
  32544. +#define SPI_LTOH 0x10
  32545. +#define SPI_DC 0x14
  32546. +
  32547. +/* Bitfields in CS */
  32548. +#define SPI_CS_LEN_LONG 0x02000000
  32549. +#define SPI_CS_DMA_LEN 0x01000000
  32550. +#define SPI_CS_CSPOL2 0x00800000
  32551. +#define SPI_CS_CSPOL1 0x00400000
  32552. +#define SPI_CS_CSPOL0 0x00200000
  32553. +#define SPI_CS_RXF 0x00100000
  32554. +#define SPI_CS_RXR 0x00080000
  32555. +#define SPI_CS_TXD 0x00040000
  32556. +#define SPI_CS_RXD 0x00020000
  32557. +#define SPI_CS_DONE 0x00010000
  32558. +#define SPI_CS_LEN 0x00002000
  32559. +#define SPI_CS_REN 0x00001000
  32560. +#define SPI_CS_ADCS 0x00000800
  32561. +#define SPI_CS_INTR 0x00000400
  32562. +#define SPI_CS_INTD 0x00000200
  32563. +#define SPI_CS_DMAEN 0x00000100
  32564. +#define SPI_CS_TA 0x00000080
  32565. +#define SPI_CS_CSPOL 0x00000040
  32566. +#define SPI_CS_CLEAR_RX 0x00000020
  32567. +#define SPI_CS_CLEAR_TX 0x00000010
  32568. +#define SPI_CS_CPOL 0x00000008
  32569. +#define SPI_CS_CPHA 0x00000004
  32570. +#define SPI_CS_CS_10 0x00000002
  32571. +#define SPI_CS_CS_01 0x00000001
  32572. +
  32573. +#define SPI_TIMEOUT_MS 150
  32574. +
  32575. +#define DRV_NAME "bcm2708_spi"
  32576. +
  32577. +struct bcm2708_spi {
  32578. + spinlock_t lock;
  32579. + void __iomem *base;
  32580. + int irq;
  32581. + struct clk *clk;
  32582. + bool stopping;
  32583. +
  32584. + struct list_head queue;
  32585. + struct workqueue_struct *workq;
  32586. + struct work_struct work;
  32587. + struct completion done;
  32588. +
  32589. + const u8 *tx_buf;
  32590. + u8 *rx_buf;
  32591. + int len;
  32592. +};
  32593. +
  32594. +struct bcm2708_spi_state {
  32595. + u32 cs;
  32596. + u16 cdiv;
  32597. +};
  32598. +
  32599. +/*
  32600. + * This function sets the ALT mode on the SPI pins so that we can use them with
  32601. + * the SPI hardware.
  32602. + *
  32603. + * FIXME: This is a hack. Use pinmux / pinctrl.
  32604. + */
  32605. +static void bcm2708_init_pinmode(void)
  32606. +{
  32607. +#define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3))
  32608. +#define SET_GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3))
  32609. +
  32610. + int pin;
  32611. + u32 *gpio = ioremap(0x20200000, SZ_16K);
  32612. +
  32613. + /* SPI is on GPIO 7..11 */
  32614. + for (pin = 7; pin <= 11; pin++) {
  32615. + INP_GPIO(pin); /* set mode to GPIO input first */
  32616. + SET_GPIO_ALT(pin, 0); /* set mode to ALT 0 */
  32617. + }
  32618. +
  32619. + iounmap(gpio);
  32620. +
  32621. +#undef INP_GPIO
  32622. +#undef SET_GPIO_ALT
  32623. +}
  32624. +
  32625. +static inline u32 bcm2708_rd(struct bcm2708_spi *bs, unsigned reg)
  32626. +{
  32627. + return readl(bs->base + reg);
  32628. +}
  32629. +
  32630. +static inline void bcm2708_wr(struct bcm2708_spi *bs, unsigned reg, u32 val)
  32631. +{
  32632. + writel(val, bs->base + reg);
  32633. +}
  32634. +
  32635. +static inline void bcm2708_rd_fifo(struct bcm2708_spi *bs, int len)
  32636. +{
  32637. + u8 byte;
  32638. +
  32639. + while (len--) {
  32640. + byte = bcm2708_rd(bs, SPI_FIFO);
  32641. + if (bs->rx_buf)
  32642. + *bs->rx_buf++ = byte;
  32643. + }
  32644. +}
  32645. +
  32646. +static inline void bcm2708_wr_fifo(struct bcm2708_spi *bs, int len)
  32647. +{
  32648. + u8 byte;
  32649. + u16 val;
  32650. +
  32651. + if (len > bs->len)
  32652. + len = bs->len;
  32653. +
  32654. + if (unlikely(bcm2708_rd(bs, SPI_CS) & SPI_CS_LEN)) {
  32655. + /* LoSSI mode */
  32656. + if (unlikely(len % 2)) {
  32657. + printk(KERN_ERR"bcm2708_wr_fifo: length must be even, skipping.\n");
  32658. + bs->len = 0;
  32659. + return;
  32660. + }
  32661. + while (len) {
  32662. + if (bs->tx_buf) {
  32663. + val = *(const u16 *)bs->tx_buf;
  32664. + bs->tx_buf += 2;
  32665. + } else
  32666. + val = 0;
  32667. + bcm2708_wr(bs, SPI_FIFO, val);
  32668. + bs->len -= 2;
  32669. + len -= 2;
  32670. + }
  32671. + return;
  32672. + }
  32673. +
  32674. + while (len--) {
  32675. + byte = bs->tx_buf ? *bs->tx_buf++ : 0;
  32676. + bcm2708_wr(bs, SPI_FIFO, byte);
  32677. + bs->len--;
  32678. + }
  32679. +}
  32680. +
  32681. +static irqreturn_t bcm2708_spi_interrupt(int irq, void *dev_id)
  32682. +{
  32683. + struct spi_master *master = dev_id;
  32684. + struct bcm2708_spi *bs = spi_master_get_devdata(master);
  32685. + u32 cs;
  32686. +
  32687. + spin_lock(&bs->lock);
  32688. +
  32689. + cs = bcm2708_rd(bs, SPI_CS);
  32690. +
  32691. + if (cs & SPI_CS_DONE) {
  32692. + if (bs->len) { /* first interrupt in a transfer */
  32693. + /* fill the TX fifo with up to 16 bytes */
  32694. + bcm2708_wr_fifo(bs, 16);
  32695. + } else { /* transfer complete */
  32696. + /* disable interrupts */
  32697. + cs &= ~(SPI_CS_INTR | SPI_CS_INTD);
  32698. + bcm2708_wr(bs, SPI_CS, cs);
  32699. +
  32700. + /* drain RX FIFO */
  32701. + while (cs & SPI_CS_RXD) {
  32702. + bcm2708_rd_fifo(bs, 1);
  32703. + cs = bcm2708_rd(bs, SPI_CS);
  32704. + }
  32705. +
  32706. + /* wake up our bh */
  32707. + complete(&bs->done);
  32708. + }
  32709. + } else if (cs & SPI_CS_RXR) {
  32710. + /* read 12 bytes of data */
  32711. + bcm2708_rd_fifo(bs, 12);
  32712. +
  32713. + /* write up to 12 bytes */
  32714. + bcm2708_wr_fifo(bs, 12);
  32715. + }
  32716. +
  32717. + spin_unlock(&bs->lock);
  32718. +
  32719. + return IRQ_HANDLED;
  32720. +}
  32721. +
  32722. +static int bcm2708_setup_state(struct spi_master *master,
  32723. + struct device *dev, struct bcm2708_spi_state *state,
  32724. + u32 hz, u8 csel, u8 mode, u8 bpw)
  32725. +{
  32726. + struct bcm2708_spi *bs = spi_master_get_devdata(master);
  32727. + int cdiv;
  32728. + unsigned long bus_hz;
  32729. + u32 cs = 0;
  32730. +
  32731. + bus_hz = clk_get_rate(bs->clk);
  32732. +
  32733. + if (hz >= bus_hz) {
  32734. + cdiv = 2; /* bus_hz / 2 is as fast as we can go */
  32735. + } else if (hz) {
  32736. + cdiv = DIV_ROUND_UP(bus_hz, hz);
  32737. +
  32738. + /* CDIV must be a power of 2, so round up */
  32739. + cdiv = roundup_pow_of_two(cdiv);
  32740. +
  32741. + if (cdiv > 65536) {
  32742. + dev_dbg(dev,
  32743. + "setup: %d Hz too slow, cdiv %u; min %ld Hz\n",
  32744. + hz, cdiv, bus_hz / 65536);
  32745. + return -EINVAL;
  32746. + } else if (cdiv == 65536) {
  32747. + cdiv = 0;
  32748. + } else if (cdiv == 1) {
  32749. + cdiv = 2; /* 1 gets rounded down to 0; == 65536 */
  32750. + }
  32751. + } else {
  32752. + cdiv = 0;
  32753. + }
  32754. +
  32755. + switch (bpw) {
  32756. + case 8:
  32757. + break;
  32758. + case 9:
  32759. + /* Reading in LoSSI mode is a special case. See 'BCM2835 ARM Peripherals' datasheet */
  32760. + cs |= SPI_CS_LEN;
  32761. + break;
  32762. + default:
  32763. + dev_dbg(dev, "setup: invalid bits_per_word %u (must be 8 or 9)\n",
  32764. + bpw);
  32765. + return -EINVAL;
  32766. + }
  32767. +
  32768. + if (mode & SPI_CPOL)
  32769. + cs |= SPI_CS_CPOL;
  32770. + if (mode & SPI_CPHA)
  32771. + cs |= SPI_CS_CPHA;
  32772. +
  32773. + if (!(mode & SPI_NO_CS)) {
  32774. + if (mode & SPI_CS_HIGH) {
  32775. + cs |= SPI_CS_CSPOL;
  32776. + cs |= SPI_CS_CSPOL0 << csel;
  32777. + }
  32778. +
  32779. + cs |= csel;
  32780. + } else {
  32781. + cs |= SPI_CS_CS_10 | SPI_CS_CS_01;
  32782. + }
  32783. +
  32784. + if (state) {
  32785. + state->cs = cs;
  32786. + state->cdiv = cdiv;
  32787. + dev_dbg(dev, "setup: want %d Hz; "
  32788. + "bus_hz=%lu / cdiv=%u == %lu Hz; "
  32789. + "mode %u: cs 0x%08X\n",
  32790. + hz, bus_hz, cdiv, bus_hz/cdiv, mode, cs);
  32791. + }
  32792. +
  32793. + return 0;
  32794. +}
  32795. +
  32796. +static int bcm2708_process_transfer(struct bcm2708_spi *bs,
  32797. + struct spi_message *msg, struct spi_transfer *xfer)
  32798. +{
  32799. + struct spi_device *spi = msg->spi;
  32800. + struct bcm2708_spi_state state, *stp;
  32801. + int ret;
  32802. + u32 cs;
  32803. +
  32804. + if (bs->stopping)
  32805. + return -ESHUTDOWN;
  32806. +
  32807. + if (xfer->bits_per_word || xfer->speed_hz) {
  32808. + ret = bcm2708_setup_state(spi->master, &spi->dev, &state,
  32809. + xfer->speed_hz ? xfer->speed_hz : spi->max_speed_hz,
  32810. + spi->chip_select, spi->mode,
  32811. + xfer->bits_per_word ? xfer->bits_per_word :
  32812. + spi->bits_per_word);
  32813. + if (ret)
  32814. + return ret;
  32815. +
  32816. + stp = &state;
  32817. + } else {
  32818. + stp = spi->controller_state;
  32819. + }
  32820. +
  32821. + reinit_completion(&bs->done);
  32822. + bs->tx_buf = xfer->tx_buf;
  32823. + bs->rx_buf = xfer->rx_buf;
  32824. + bs->len = xfer->len;
  32825. +
  32826. + cs = stp->cs | SPI_CS_INTR | SPI_CS_INTD | SPI_CS_TA;
  32827. +
  32828. + bcm2708_wr(bs, SPI_CLK, stp->cdiv);
  32829. + bcm2708_wr(bs, SPI_CS, cs);
  32830. +
  32831. + ret = wait_for_completion_timeout(&bs->done,
  32832. + msecs_to_jiffies(SPI_TIMEOUT_MS));
  32833. + if (ret == 0) {
  32834. + dev_err(&spi->dev, "transfer timed out\n");
  32835. + return -ETIMEDOUT;
  32836. + }
  32837. +
  32838. + if (xfer->delay_usecs)
  32839. + udelay(xfer->delay_usecs);
  32840. +
  32841. + if (list_is_last(&xfer->transfer_list, &msg->transfers) ||
  32842. + xfer->cs_change) {
  32843. + /* clear TA and interrupt flags */
  32844. + bcm2708_wr(bs, SPI_CS, stp->cs);
  32845. + }
  32846. +
  32847. + msg->actual_length += (xfer->len - bs->len);
  32848. +
  32849. + return 0;
  32850. +}
  32851. +
  32852. +static void bcm2708_work(struct work_struct *work)
  32853. +{
  32854. + struct bcm2708_spi *bs = container_of(work, struct bcm2708_spi, work);
  32855. + unsigned long flags;
  32856. + struct spi_message *msg;
  32857. + struct spi_transfer *xfer;
  32858. + int status = 0;
  32859. +
  32860. + spin_lock_irqsave(&bs->lock, flags);
  32861. + while (!list_empty(&bs->queue)) {
  32862. + msg = list_first_entry(&bs->queue, struct spi_message, queue);
  32863. + list_del_init(&msg->queue);
  32864. + spin_unlock_irqrestore(&bs->lock, flags);
  32865. +
  32866. + list_for_each_entry(xfer, &msg->transfers, transfer_list) {
  32867. + status = bcm2708_process_transfer(bs, msg, xfer);
  32868. + if (status)
  32869. + break;
  32870. + }
  32871. +
  32872. + msg->status = status;
  32873. + msg->complete(msg->context);
  32874. +
  32875. + spin_lock_irqsave(&bs->lock, flags);
  32876. + }
  32877. + spin_unlock_irqrestore(&bs->lock, flags);
  32878. +}
  32879. +
  32880. +static int bcm2708_spi_setup(struct spi_device *spi)
  32881. +{
  32882. + struct bcm2708_spi *bs = spi_master_get_devdata(spi->master);
  32883. + struct bcm2708_spi_state *state;
  32884. + int ret;
  32885. +
  32886. + if (bs->stopping)
  32887. + return -ESHUTDOWN;
  32888. +
  32889. + if (!(spi->mode & SPI_NO_CS) &&
  32890. + (spi->chip_select > spi->master->num_chipselect)) {
  32891. + dev_dbg(&spi->dev,
  32892. + "setup: invalid chipselect %u (%u defined)\n",
  32893. + spi->chip_select, spi->master->num_chipselect);
  32894. + return -EINVAL;
  32895. + }
  32896. +
  32897. + state = spi->controller_state;
  32898. + if (!state) {
  32899. + state = kzalloc(sizeof(*state), GFP_KERNEL);
  32900. + if (!state)
  32901. + return -ENOMEM;
  32902. +
  32903. + spi->controller_state = state;
  32904. + }
  32905. +
  32906. + ret = bcm2708_setup_state(spi->master, &spi->dev, state,
  32907. + spi->max_speed_hz, spi->chip_select, spi->mode,
  32908. + spi->bits_per_word);
  32909. + if (ret < 0) {
  32910. + kfree(state);
  32911. + spi->controller_state = NULL;
  32912. + return ret;
  32913. + }
  32914. +
  32915. + dev_dbg(&spi->dev,
  32916. + "setup: cd %d: %d Hz, bpw %u, mode 0x%x -> CS=%08x CDIV=%04x\n",
  32917. + spi->chip_select, spi->max_speed_hz, spi->bits_per_word,
  32918. + spi->mode, state->cs, state->cdiv);
  32919. +
  32920. + return 0;
  32921. +}
  32922. +
  32923. +static int bcm2708_spi_transfer(struct spi_device *spi, struct spi_message *msg)
  32924. +{
  32925. + struct bcm2708_spi *bs = spi_master_get_devdata(spi->master);
  32926. + struct spi_transfer *xfer;
  32927. + int ret;
  32928. + unsigned long flags;
  32929. +
  32930. + if (unlikely(list_empty(&msg->transfers)))
  32931. + return -EINVAL;
  32932. +
  32933. + if (bs->stopping)
  32934. + return -ESHUTDOWN;
  32935. +
  32936. + list_for_each_entry(xfer, &msg->transfers, transfer_list) {
  32937. + if (!(xfer->tx_buf || xfer->rx_buf) && xfer->len) {
  32938. + dev_dbg(&spi->dev, "missing rx or tx buf\n");
  32939. + return -EINVAL;
  32940. + }
  32941. +
  32942. + if (!xfer->bits_per_word || xfer->speed_hz)
  32943. + continue;
  32944. +
  32945. + ret = bcm2708_setup_state(spi->master, &spi->dev, NULL,
  32946. + xfer->speed_hz ? xfer->speed_hz : spi->max_speed_hz,
  32947. + spi->chip_select, spi->mode,
  32948. + xfer->bits_per_word ? xfer->bits_per_word :
  32949. + spi->bits_per_word);
  32950. + if (ret)
  32951. + return ret;
  32952. + }
  32953. +
  32954. + msg->status = -EINPROGRESS;
  32955. + msg->actual_length = 0;
  32956. +
  32957. + spin_lock_irqsave(&bs->lock, flags);
  32958. + list_add_tail(&msg->queue, &bs->queue);
  32959. + queue_work(bs->workq, &bs->work);
  32960. + spin_unlock_irqrestore(&bs->lock, flags);
  32961. +
  32962. + return 0;
  32963. +}
  32964. +
  32965. +static void bcm2708_spi_cleanup(struct spi_device *spi)
  32966. +{
  32967. + if (spi->controller_state) {
  32968. + kfree(spi->controller_state);
  32969. + spi->controller_state = NULL;
  32970. + }
  32971. +}
  32972. +
  32973. +static int bcm2708_spi_probe(struct platform_device *pdev)
  32974. +{
  32975. + struct resource *regs;
  32976. + int irq, err = -ENOMEM;
  32977. + struct clk *clk;
  32978. + struct spi_master *master;
  32979. + struct bcm2708_spi *bs;
  32980. +
  32981. + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  32982. + if (!regs) {
  32983. + dev_err(&pdev->dev, "could not get IO memory\n");
  32984. + return -ENXIO;
  32985. + }
  32986. +
  32987. + irq = platform_get_irq(pdev, 0);
  32988. + if (irq < 0) {
  32989. + dev_err(&pdev->dev, "could not get IRQ\n");
  32990. + return irq;
  32991. + }
  32992. +
  32993. + clk = clk_get(&pdev->dev, NULL);
  32994. + if (IS_ERR(clk)) {
  32995. + dev_err(&pdev->dev, "could not find clk: %ld\n", PTR_ERR(clk));
  32996. + return PTR_ERR(clk);
  32997. + }
  32998. +
  32999. + bcm2708_init_pinmode();
  33000. +
  33001. + master = spi_alloc_master(&pdev->dev, sizeof(*bs));
  33002. + if (!master) {
  33003. + dev_err(&pdev->dev, "spi_alloc_master() failed\n");
  33004. + goto out_clk_put;
  33005. + }
  33006. +
  33007. + /* the spi->mode bits understood by this driver: */
  33008. + master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_NO_CS;
  33009. +
  33010. + master->bus_num = pdev->id;
  33011. + master->num_chipselect = 3;
  33012. + master->setup = bcm2708_spi_setup;
  33013. + master->transfer = bcm2708_spi_transfer;
  33014. + master->cleanup = bcm2708_spi_cleanup;
  33015. + platform_set_drvdata(pdev, master);
  33016. +
  33017. + bs = spi_master_get_devdata(master);
  33018. +
  33019. + spin_lock_init(&bs->lock);
  33020. + INIT_LIST_HEAD(&bs->queue);
  33021. + init_completion(&bs->done);
  33022. + INIT_WORK(&bs->work, bcm2708_work);
  33023. +
  33024. + bs->base = ioremap(regs->start, resource_size(regs));
  33025. + if (!bs->base) {
  33026. + dev_err(&pdev->dev, "could not remap memory\n");
  33027. + goto out_master_put;
  33028. + }
  33029. +
  33030. + bs->workq = create_singlethread_workqueue(dev_name(&pdev->dev));
  33031. + if (!bs->workq) {
  33032. + dev_err(&pdev->dev, "could not create workqueue\n");
  33033. + goto out_iounmap;
  33034. + }
  33035. +
  33036. + bs->irq = irq;
  33037. + bs->clk = clk;
  33038. + bs->stopping = false;
  33039. +
  33040. + err = request_irq(irq, bcm2708_spi_interrupt, 0, dev_name(&pdev->dev),
  33041. + master);
  33042. + if (err) {
  33043. + dev_err(&pdev->dev, "could not request IRQ: %d\n", err);
  33044. + goto out_workqueue;
  33045. + }
  33046. +
  33047. + /* initialise the hardware */
  33048. + clk_enable(clk);
  33049. + bcm2708_wr(bs, SPI_CS, SPI_CS_REN | SPI_CS_CLEAR_RX | SPI_CS_CLEAR_TX);
  33050. +
  33051. + err = spi_register_master(master);
  33052. + if (err) {
  33053. + dev_err(&pdev->dev, "could not register SPI master: %d\n", err);
  33054. + goto out_free_irq;
  33055. + }
  33056. +
  33057. + dev_info(&pdev->dev, "SPI Controller at 0x%08lx (irq %d)\n",
  33058. + (unsigned long)regs->start, irq);
  33059. +
  33060. + return 0;
  33061. +
  33062. +out_free_irq:
  33063. + free_irq(bs->irq, master);
  33064. +out_workqueue:
  33065. + destroy_workqueue(bs->workq);
  33066. +out_iounmap:
  33067. + iounmap(bs->base);
  33068. +out_master_put:
  33069. + spi_master_put(master);
  33070. +out_clk_put:
  33071. + clk_put(clk);
  33072. + return err;
  33073. +}
  33074. +
  33075. +static int bcm2708_spi_remove(struct platform_device *pdev)
  33076. +{
  33077. + struct spi_master *master = platform_get_drvdata(pdev);
  33078. + struct bcm2708_spi *bs = spi_master_get_devdata(master);
  33079. +
  33080. + /* reset the hardware and block queue progress */
  33081. + spin_lock_irq(&bs->lock);
  33082. + bs->stopping = true;
  33083. + bcm2708_wr(bs, SPI_CS, SPI_CS_CLEAR_RX | SPI_CS_CLEAR_TX);
  33084. + spin_unlock_irq(&bs->lock);
  33085. +
  33086. + flush_work_sync(&bs->work);
  33087. +
  33088. + clk_disable(bs->clk);
  33089. + clk_put(bs->clk);
  33090. + free_irq(bs->irq, master);
  33091. + iounmap(bs->base);
  33092. +
  33093. + spi_unregister_master(master);
  33094. +
  33095. + return 0;
  33096. +}
  33097. +
  33098. +static struct platform_driver bcm2708_spi_driver = {
  33099. + .driver = {
  33100. + .name = DRV_NAME,
  33101. + .owner = THIS_MODULE,
  33102. + },
  33103. + .probe = bcm2708_spi_probe,
  33104. + .remove = bcm2708_spi_remove,
  33105. +};
  33106. +
  33107. +
  33108. +static int __init bcm2708_spi_init(void)
  33109. +{
  33110. + return platform_driver_probe(&bcm2708_spi_driver, bcm2708_spi_probe);
  33111. +}
  33112. +module_init(bcm2708_spi_init);
  33113. +
  33114. +static void __exit bcm2708_spi_exit(void)
  33115. +{
  33116. + platform_driver_unregister(&bcm2708_spi_driver);
  33117. +}
  33118. +module_exit(bcm2708_spi_exit);
  33119. +
  33120. +
  33121. +//module_platform_driver(bcm2708_spi_driver);
  33122. +
  33123. +MODULE_DESCRIPTION("SPI controller driver for Broadcom BCM2708");
  33124. +MODULE_AUTHOR("Chris Boot <bootc@bootc.net>");
  33125. +MODULE_LICENSE("GPL v2");
  33126. +MODULE_ALIAS("platform:" DRV_NAME);
  33127. diff -Nur linux-3.13.11/drivers/staging/comedi/drivers/8255_pci.c linux-rpi/drivers/staging/comedi/drivers/8255_pci.c
  33128. --- linux-3.13.11/drivers/staging/comedi/drivers/8255_pci.c 2014-04-23 01:49:33.000000000 +0200
  33129. +++ linux-rpi/drivers/staging/comedi/drivers/8255_pci.c 2014-04-24 15:37:04.770897115 +0200
  33130. @@ -56,7 +56,6 @@
  33131. #include "../comedidev.h"
  33132. #include "8255.h"
  33133. -#include "mite.h"
  33134. enum pci_8255_boardid {
  33135. BOARD_ADLINK_PCI7224,
  33136. @@ -80,7 +79,6 @@
  33137. const char *name;
  33138. int dio_badr;
  33139. int n_8255;
  33140. - unsigned int has_mite:1;
  33141. };
  33142. static const struct pci_8255_boardinfo pci_8255_boards[] = {
  33143. @@ -128,43 +126,36 @@
  33144. .name = "ni_pci-dio-96",
  33145. .dio_badr = 1,
  33146. .n_8255 = 4,
  33147. - .has_mite = 1,
  33148. },
  33149. [BOARD_NI_PCIDIO96B] = {
  33150. .name = "ni_pci-dio-96b",
  33151. .dio_badr = 1,
  33152. .n_8255 = 4,
  33153. - .has_mite = 1,
  33154. },
  33155. [BOARD_NI_PXI6508] = {
  33156. .name = "ni_pxi-6508",
  33157. .dio_badr = 1,
  33158. .n_8255 = 4,
  33159. - .has_mite = 1,
  33160. },
  33161. [BOARD_NI_PCI6503] = {
  33162. .name = "ni_pci-6503",
  33163. .dio_badr = 1,
  33164. .n_8255 = 1,
  33165. - .has_mite = 1,
  33166. },
  33167. [BOARD_NI_PCI6503B] = {
  33168. .name = "ni_pci-6503b",
  33169. .dio_badr = 1,
  33170. .n_8255 = 1,
  33171. - .has_mite = 1,
  33172. },
  33173. [BOARD_NI_PCI6503X] = {
  33174. .name = "ni_pci-6503x",
  33175. .dio_badr = 1,
  33176. .n_8255 = 1,
  33177. - .has_mite = 1,
  33178. },
  33179. [BOARD_NI_PXI_6503] = {
  33180. .name = "ni_pxi-6503",
  33181. .dio_badr = 1,
  33182. .n_8255 = 1,
  33183. - .has_mite = 1,
  33184. },
  33185. };
  33186. @@ -172,25 +163,6 @@
  33187. void __iomem *mmio_base;
  33188. };
  33189. -static int pci_8255_mite_init(struct pci_dev *pcidev)
  33190. -{
  33191. - void __iomem *mite_base;
  33192. - u32 main_phys_addr;
  33193. -
  33194. - /* ioremap the MITE registers (BAR 0) temporarily */
  33195. - mite_base = pci_ioremap_bar(pcidev, 0);
  33196. - if (!mite_base)
  33197. - return -ENOMEM;
  33198. -
  33199. - /* set data window to main registers (BAR 1) */
  33200. - main_phys_addr = pci_resource_start(pcidev, 1);
  33201. - writel(main_phys_addr | WENAB, mite_base + MITE_IODWBSR);
  33202. -
  33203. - /* finished with MITE registers */
  33204. - iounmap(mite_base);
  33205. - return 0;
  33206. -}
  33207. -
  33208. static int pci_8255_mmio(int dir, int port, int data, unsigned long iobase)
  33209. {
  33210. void __iomem *mmio_base = (void __iomem *)iobase;
  33211. @@ -229,12 +201,6 @@
  33212. if (ret)
  33213. return ret;
  33214. - if (board->has_mite) {
  33215. - ret = pci_8255_mite_init(pcidev);
  33216. - if (ret)
  33217. - return ret;
  33218. - }
  33219. -
  33220. is_mmio = (pci_resource_flags(pcidev, board->dio_badr) &
  33221. IORESOURCE_MEM) != 0;
  33222. if (is_mmio) {
  33223. diff -Nur linux-3.13.11/drivers/staging/media/lirc/Kconfig linux-rpi/drivers/staging/media/lirc/Kconfig
  33224. --- linux-3.13.11/drivers/staging/media/lirc/Kconfig 2014-04-23 01:49:33.000000000 +0200
  33225. +++ linux-rpi/drivers/staging/media/lirc/Kconfig 2014-04-24 15:35:03.925563013 +0200
  33226. @@ -38,6 +38,12 @@
  33227. help
  33228. Driver for Homebrew Parallel Port Receivers
  33229. +config LIRC_RPI
  33230. + tristate "Homebrew GPIO Port Receiver/Transmitter for the RaspberryPi"
  33231. + depends on LIRC
  33232. + help
  33233. + Driver for Homebrew GPIO Port Receiver/Transmitter for the RaspberryPi
  33234. +
  33235. config LIRC_SASEM
  33236. tristate "Sasem USB IR Remote"
  33237. depends on LIRC && USB
  33238. diff -Nur linux-3.13.11/drivers/staging/media/lirc/lirc_rpi.c linux-rpi/drivers/staging/media/lirc/lirc_rpi.c
  33239. --- linux-3.13.11/drivers/staging/media/lirc/lirc_rpi.c 1970-01-01 01:00:00.000000000 +0100
  33240. +++ linux-rpi/drivers/staging/media/lirc/lirc_rpi.c 2014-04-24 15:35:03.925563013 +0200
  33241. @@ -0,0 +1,693 @@
  33242. +/*
  33243. + * lirc_rpi.c
  33244. + *
  33245. + * lirc_rpi - Device driver that records pulse- and pause-lengths
  33246. + * (space-lengths) (just like the lirc_serial driver does)
  33247. + * between GPIO interrupt events on the Raspberry Pi.
  33248. + * Lots of code has been taken from the lirc_serial module,
  33249. + * so I would like say thanks to the authors.
  33250. + *
  33251. + * Copyright (C) 2012 Aron Robert Szabo <aron@reon.hu>,
  33252. + * Michael Bishop <cleverca22@gmail.com>
  33253. + * This program is free software; you can redistribute it and/or modify
  33254. + * it under the terms of the GNU General Public License as published by
  33255. + * the Free Software Foundation; either version 2 of the License, or
  33256. + * (at your option) any later version.
  33257. + *
  33258. + * This program is distributed in the hope that it will be useful,
  33259. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  33260. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  33261. + * GNU General Public License for more details.
  33262. + *
  33263. + * You should have received a copy of the GNU General Public License
  33264. + * along with this program; if not, write to the Free Software
  33265. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  33266. + */
  33267. +
  33268. +#include <linux/module.h>
  33269. +#include <linux/errno.h>
  33270. +#include <linux/interrupt.h>
  33271. +#include <linux/sched.h>
  33272. +#include <linux/kernel.h>
  33273. +#include <linux/time.h>
  33274. +#include <linux/string.h>
  33275. +#include <linux/delay.h>
  33276. +#include <linux/platform_device.h>
  33277. +#include <linux/irq.h>
  33278. +#include <linux/spinlock.h>
  33279. +#include <media/lirc.h>
  33280. +#include <media/lirc_dev.h>
  33281. +#include <linux/gpio.h>
  33282. +
  33283. +#define LIRC_DRIVER_NAME "lirc_rpi"
  33284. +#define RBUF_LEN 256
  33285. +#define LIRC_TRANSMITTER_LATENCY 256
  33286. +
  33287. +#ifndef MAX_UDELAY_MS
  33288. +#define MAX_UDELAY_US 5000
  33289. +#else
  33290. +#define MAX_UDELAY_US (MAX_UDELAY_MS*1000)
  33291. +#endif
  33292. +
  33293. +#define dprintk(fmt, args...) \
  33294. + do { \
  33295. + if (debug) \
  33296. + printk(KERN_DEBUG LIRC_DRIVER_NAME ": " \
  33297. + fmt, ## args); \
  33298. + } while (0)
  33299. +
  33300. +/* module parameters */
  33301. +
  33302. +/* set the default GPIO input pin */
  33303. +static int gpio_in_pin = 18;
  33304. +/* set the default GPIO output pin */
  33305. +static int gpio_out_pin = 17;
  33306. +/* enable debugging messages */
  33307. +static bool debug;
  33308. +/* -1 = auto, 0 = active high, 1 = active low */
  33309. +static int sense = -1;
  33310. +/* use softcarrier by default */
  33311. +static bool softcarrier = 1;
  33312. +/* 0 = do not invert output, 1 = invert output */
  33313. +static bool invert = 0;
  33314. +
  33315. +struct gpio_chip *gpiochip;
  33316. +struct irq_chip *irqchip;
  33317. +struct irq_data *irqdata;
  33318. +
  33319. +/* forward declarations */
  33320. +static long send_pulse(unsigned long length);
  33321. +static void send_space(long length);
  33322. +static void lirc_rpi_exit(void);
  33323. +
  33324. +int valid_gpio_pins[] = { 0, 1, 2, 3, 4, 7, 8, 9, 10, 11, 14, 15, 17, 18, 21,
  33325. + 22, 23, 24, 25 ,27, 28, 29, 30, 31 };
  33326. +
  33327. +static struct platform_device *lirc_rpi_dev;
  33328. +static struct timeval lasttv = { 0, 0 };
  33329. +static struct lirc_buffer rbuf;
  33330. +static spinlock_t lock;
  33331. +
  33332. +/* initialized/set in init_timing_params() */
  33333. +static unsigned int freq = 38000;
  33334. +static unsigned int duty_cycle = 50;
  33335. +static unsigned long period;
  33336. +static unsigned long pulse_width;
  33337. +static unsigned long space_width;
  33338. +
  33339. +static void safe_udelay(unsigned long usecs)
  33340. +{
  33341. + while (usecs > MAX_UDELAY_US) {
  33342. + udelay(MAX_UDELAY_US);
  33343. + usecs -= MAX_UDELAY_US;
  33344. + }
  33345. + udelay(usecs);
  33346. +}
  33347. +
  33348. +static int init_timing_params(unsigned int new_duty_cycle,
  33349. + unsigned int new_freq)
  33350. +{
  33351. + /*
  33352. + * period, pulse/space width are kept with 8 binary places -
  33353. + * IE multiplied by 256.
  33354. + */
  33355. + if (256 * 1000000L / new_freq * new_duty_cycle / 100 <=
  33356. + LIRC_TRANSMITTER_LATENCY)
  33357. + return -EINVAL;
  33358. + if (256 * 1000000L / new_freq * (100 - new_duty_cycle) / 100 <=
  33359. + LIRC_TRANSMITTER_LATENCY)
  33360. + return -EINVAL;
  33361. + duty_cycle = new_duty_cycle;
  33362. + freq = new_freq;
  33363. + period = 256 * 1000000L / freq;
  33364. + pulse_width = period * duty_cycle / 100;
  33365. + space_width = period - pulse_width;
  33366. + dprintk("in init_timing_params, freq=%d pulse=%ld, "
  33367. + "space=%ld\n", freq, pulse_width, space_width);
  33368. + return 0;
  33369. +}
  33370. +
  33371. +static long send_pulse_softcarrier(unsigned long length)
  33372. +{
  33373. + int flag;
  33374. + unsigned long actual, target, d;
  33375. +
  33376. + length <<= 8;
  33377. +
  33378. + actual = 0; target = 0; flag = 0;
  33379. + while (actual < length) {
  33380. + if (flag) {
  33381. + gpiochip->set(gpiochip, gpio_out_pin, invert);
  33382. + target += space_width;
  33383. + } else {
  33384. + gpiochip->set(gpiochip, gpio_out_pin, !invert);
  33385. + target += pulse_width;
  33386. + }
  33387. + d = (target - actual -
  33388. + LIRC_TRANSMITTER_LATENCY + 128) >> 8;
  33389. + /*
  33390. + * Note - we've checked in ioctl that the pulse/space
  33391. + * widths are big enough so that d is > 0
  33392. + */
  33393. + udelay(d);
  33394. + actual += (d << 8) + LIRC_TRANSMITTER_LATENCY;
  33395. + flag = !flag;
  33396. + }
  33397. + return (actual-length) >> 8;
  33398. +}
  33399. +
  33400. +static long send_pulse(unsigned long length)
  33401. +{
  33402. + if (length <= 0)
  33403. + return 0;
  33404. +
  33405. + if (softcarrier) {
  33406. + return send_pulse_softcarrier(length);
  33407. + } else {
  33408. + gpiochip->set(gpiochip, gpio_out_pin, !invert);
  33409. + safe_udelay(length);
  33410. + return 0;
  33411. + }
  33412. +}
  33413. +
  33414. +static void send_space(long length)
  33415. +{
  33416. + gpiochip->set(gpiochip, gpio_out_pin, invert);
  33417. + if (length <= 0)
  33418. + return;
  33419. + safe_udelay(length);
  33420. +}
  33421. +
  33422. +static void rbwrite(int l)
  33423. +{
  33424. + if (lirc_buffer_full(&rbuf)) {
  33425. + /* no new signals will be accepted */
  33426. + dprintk("Buffer overrun\n");
  33427. + return;
  33428. + }
  33429. + lirc_buffer_write(&rbuf, (void *)&l);
  33430. +}
  33431. +
  33432. +static void frbwrite(int l)
  33433. +{
  33434. + /* simple noise filter */
  33435. + static int pulse, space;
  33436. + static unsigned int ptr;
  33437. +
  33438. + if (ptr > 0 && (l & PULSE_BIT)) {
  33439. + pulse += l & PULSE_MASK;
  33440. + if (pulse > 250) {
  33441. + rbwrite(space);
  33442. + rbwrite(pulse | PULSE_BIT);
  33443. + ptr = 0;
  33444. + pulse = 0;
  33445. + }
  33446. + return;
  33447. + }
  33448. + if (!(l & PULSE_BIT)) {
  33449. + if (ptr == 0) {
  33450. + if (l > 20000) {
  33451. + space = l;
  33452. + ptr++;
  33453. + return;
  33454. + }
  33455. + } else {
  33456. + if (l > 20000) {
  33457. + space += pulse;
  33458. + if (space > PULSE_MASK)
  33459. + space = PULSE_MASK;
  33460. + space += l;
  33461. + if (space > PULSE_MASK)
  33462. + space = PULSE_MASK;
  33463. + pulse = 0;
  33464. + return;
  33465. + }
  33466. + rbwrite(space);
  33467. + rbwrite(pulse | PULSE_BIT);
  33468. + ptr = 0;
  33469. + pulse = 0;
  33470. + }
  33471. + }
  33472. + rbwrite(l);
  33473. +}
  33474. +
  33475. +static irqreturn_t irq_handler(int i, void *blah, struct pt_regs *regs)
  33476. +{
  33477. + struct timeval tv;
  33478. + long deltv;
  33479. + int data;
  33480. + int signal;
  33481. +
  33482. + /* use the GPIO signal level */
  33483. + signal = gpiochip->get(gpiochip, gpio_in_pin);
  33484. +
  33485. + /* unmask the irq */
  33486. + irqchip->irq_unmask(irqdata);
  33487. +
  33488. + if (sense != -1) {
  33489. + /* get current time */
  33490. + do_gettimeofday(&tv);
  33491. +
  33492. + /* calc time since last interrupt in microseconds */
  33493. + deltv = tv.tv_sec-lasttv.tv_sec;
  33494. + if (tv.tv_sec < lasttv.tv_sec ||
  33495. + (tv.tv_sec == lasttv.tv_sec &&
  33496. + tv.tv_usec < lasttv.tv_usec)) {
  33497. + printk(KERN_WARNING LIRC_DRIVER_NAME
  33498. + ": AIEEEE: your clock just jumped backwards\n");
  33499. + printk(KERN_WARNING LIRC_DRIVER_NAME
  33500. + ": %d %d %lx %lx %lx %lx\n", signal, sense,
  33501. + tv.tv_sec, lasttv.tv_sec,
  33502. + tv.tv_usec, lasttv.tv_usec);
  33503. + data = PULSE_MASK;
  33504. + } else if (deltv > 15) {
  33505. + data = PULSE_MASK; /* really long time */
  33506. + if (!(signal^sense)) {
  33507. + /* sanity check */
  33508. + printk(KERN_WARNING LIRC_DRIVER_NAME
  33509. + ": AIEEEE: %d %d %lx %lx %lx %lx\n",
  33510. + signal, sense, tv.tv_sec, lasttv.tv_sec,
  33511. + tv.tv_usec, lasttv.tv_usec);
  33512. + /*
  33513. + * detecting pulse while this
  33514. + * MUST be a space!
  33515. + */
  33516. + sense = sense ? 0 : 1;
  33517. + }
  33518. + } else {
  33519. + data = (int) (deltv*1000000 +
  33520. + (tv.tv_usec - lasttv.tv_usec));
  33521. + }
  33522. + frbwrite(signal^sense ? data : (data|PULSE_BIT));
  33523. + lasttv = tv;
  33524. + wake_up_interruptible(&rbuf.wait_poll);
  33525. + }
  33526. +
  33527. + return IRQ_HANDLED;
  33528. +}
  33529. +
  33530. +static int is_right_chip(struct gpio_chip *chip, void *data)
  33531. +{
  33532. + dprintk("is_right_chip %s %d\n", chip->label, strcmp(data, chip->label));
  33533. +
  33534. + if (strcmp(data, chip->label) == 0)
  33535. + return 1;
  33536. + return 0;
  33537. +}
  33538. +
  33539. +static int init_port(void)
  33540. +{
  33541. + int i, nlow, nhigh, ret, irq;
  33542. +
  33543. + gpiochip = gpiochip_find("bcm2708_gpio", is_right_chip);
  33544. +
  33545. + if (!gpiochip)
  33546. + return -ENODEV;
  33547. +
  33548. + if (gpio_request(gpio_out_pin, LIRC_DRIVER_NAME " ir/out")) {
  33549. + printk(KERN_ALERT LIRC_DRIVER_NAME
  33550. + ": cant claim gpio pin %d\n", gpio_out_pin);
  33551. + ret = -ENODEV;
  33552. + goto exit_init_port;
  33553. + }
  33554. +
  33555. + if (gpio_request(gpio_in_pin, LIRC_DRIVER_NAME " ir/in")) {
  33556. + printk(KERN_ALERT LIRC_DRIVER_NAME
  33557. + ": cant claim gpio pin %d\n", gpio_in_pin);
  33558. + ret = -ENODEV;
  33559. + goto exit_gpio_free_out_pin;
  33560. + }
  33561. +
  33562. + gpiochip->direction_input(gpiochip, gpio_in_pin);
  33563. + gpiochip->direction_output(gpiochip, gpio_out_pin, 1);
  33564. + gpiochip->set(gpiochip, gpio_out_pin, invert);
  33565. +
  33566. + irq = gpiochip->to_irq(gpiochip, gpio_in_pin);
  33567. + dprintk("to_irq %d\n", irq);
  33568. + irqdata = irq_get_irq_data(irq);
  33569. +
  33570. + if (irqdata && irqdata->chip) {
  33571. + irqchip = irqdata->chip;
  33572. + } else {
  33573. + ret = -ENODEV;
  33574. + goto exit_gpio_free_in_pin;
  33575. + }
  33576. +
  33577. + /* if pin is high, then this must be an active low receiver. */
  33578. + if (sense == -1) {
  33579. + /* wait 1/2 sec for the power supply */
  33580. + msleep(500);
  33581. +
  33582. + /*
  33583. + * probe 9 times every 0.04s, collect "votes" for
  33584. + * active high/low
  33585. + */
  33586. + nlow = 0;
  33587. + nhigh = 0;
  33588. + for (i = 0; i < 9; i++) {
  33589. + if (gpiochip->get(gpiochip, gpio_in_pin))
  33590. + nlow++;
  33591. + else
  33592. + nhigh++;
  33593. + msleep(40);
  33594. + }
  33595. + sense = (nlow >= nhigh ? 1 : 0);
  33596. + printk(KERN_INFO LIRC_DRIVER_NAME
  33597. + ": auto-detected active %s receiver on GPIO pin %d\n",
  33598. + sense ? "low" : "high", gpio_in_pin);
  33599. + } else {
  33600. + printk(KERN_INFO LIRC_DRIVER_NAME
  33601. + ": manually using active %s receiver on GPIO pin %d\n",
  33602. + sense ? "low" : "high", gpio_in_pin);
  33603. + }
  33604. +
  33605. + return 0;
  33606. +
  33607. + exit_gpio_free_in_pin:
  33608. + gpio_free(gpio_in_pin);
  33609. +
  33610. + exit_gpio_free_out_pin:
  33611. + gpio_free(gpio_out_pin);
  33612. +
  33613. + exit_init_port:
  33614. + return ret;
  33615. +}
  33616. +
  33617. +// called when the character device is opened
  33618. +static int set_use_inc(void *data)
  33619. +{
  33620. + int result;
  33621. + unsigned long flags;
  33622. +
  33623. + /* initialize timestamp */
  33624. + do_gettimeofday(&lasttv);
  33625. +
  33626. + result = request_irq(gpiochip->to_irq(gpiochip, gpio_in_pin),
  33627. + (irq_handler_t) irq_handler, 0,
  33628. + LIRC_DRIVER_NAME, (void*) 0);
  33629. +
  33630. + switch (result) {
  33631. + case -EBUSY:
  33632. + printk(KERN_ERR LIRC_DRIVER_NAME
  33633. + ": IRQ %d is busy\n",
  33634. + gpiochip->to_irq(gpiochip, gpio_in_pin));
  33635. + return -EBUSY;
  33636. + case -EINVAL:
  33637. + printk(KERN_ERR LIRC_DRIVER_NAME
  33638. + ": Bad irq number or handler\n");
  33639. + return -EINVAL;
  33640. + default:
  33641. + dprintk("Interrupt %d obtained\n",
  33642. + gpiochip->to_irq(gpiochip, gpio_in_pin));
  33643. + break;
  33644. + };
  33645. +
  33646. + /* initialize pulse/space widths */
  33647. + init_timing_params(duty_cycle, freq);
  33648. +
  33649. + spin_lock_irqsave(&lock, flags);
  33650. +
  33651. + /* GPIO Pin Falling/Rising Edge Detect Enable */
  33652. + irqchip->irq_set_type(irqdata,
  33653. + IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING);
  33654. +
  33655. + /* unmask the irq */
  33656. + irqchip->irq_unmask(irqdata);
  33657. +
  33658. + spin_unlock_irqrestore(&lock, flags);
  33659. +
  33660. + return 0;
  33661. +}
  33662. +
  33663. +static void set_use_dec(void *data)
  33664. +{
  33665. + unsigned long flags;
  33666. +
  33667. + spin_lock_irqsave(&lock, flags);
  33668. +
  33669. + /* GPIO Pin Falling/Rising Edge Detect Disable */
  33670. + irqchip->irq_set_type(irqdata, 0);
  33671. + irqchip->irq_mask(irqdata);
  33672. +
  33673. + spin_unlock_irqrestore(&lock, flags);
  33674. +
  33675. + free_irq(gpiochip->to_irq(gpiochip, gpio_in_pin), (void *) 0);
  33676. +
  33677. + dprintk(KERN_INFO LIRC_DRIVER_NAME
  33678. + ": freed IRQ %d\n", gpiochip->to_irq(gpiochip, gpio_in_pin));
  33679. +}
  33680. +
  33681. +static ssize_t lirc_write(struct file *file, const char *buf,
  33682. + size_t n, loff_t *ppos)
  33683. +{
  33684. + int i, count;
  33685. + unsigned long flags;
  33686. + long delta = 0;
  33687. + int *wbuf;
  33688. +
  33689. + count = n / sizeof(int);
  33690. + if (n % sizeof(int) || count % 2 == 0)
  33691. + return -EINVAL;
  33692. + wbuf = memdup_user(buf, n);
  33693. + if (IS_ERR(wbuf))
  33694. + return PTR_ERR(wbuf);
  33695. + spin_lock_irqsave(&lock, flags);
  33696. +
  33697. + for (i = 0; i < count; i++) {
  33698. + if (i%2)
  33699. + send_space(wbuf[i] - delta);
  33700. + else
  33701. + delta = send_pulse(wbuf[i]);
  33702. + }
  33703. + gpiochip->set(gpiochip, gpio_out_pin, invert);
  33704. +
  33705. + spin_unlock_irqrestore(&lock, flags);
  33706. + kfree(wbuf);
  33707. + return n;
  33708. +}
  33709. +
  33710. +static long lirc_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
  33711. +{
  33712. + int result;
  33713. + __u32 value;
  33714. +
  33715. + switch (cmd) {
  33716. + case LIRC_GET_SEND_MODE:
  33717. + return -ENOIOCTLCMD;
  33718. + break;
  33719. +
  33720. + case LIRC_SET_SEND_MODE:
  33721. + result = get_user(value, (__u32 *) arg);
  33722. + if (result)
  33723. + return result;
  33724. + /* only LIRC_MODE_PULSE supported */
  33725. + if (value != LIRC_MODE_PULSE)
  33726. + return -ENOSYS;
  33727. + break;
  33728. +
  33729. + case LIRC_GET_LENGTH:
  33730. + return -ENOSYS;
  33731. + break;
  33732. +
  33733. + case LIRC_SET_SEND_DUTY_CYCLE:
  33734. + dprintk("SET_SEND_DUTY_CYCLE\n");
  33735. + result = get_user(value, (__u32 *) arg);
  33736. + if (result)
  33737. + return result;
  33738. + if (value <= 0 || value > 100)
  33739. + return -EINVAL;
  33740. + return init_timing_params(value, freq);
  33741. + break;
  33742. +
  33743. + case LIRC_SET_SEND_CARRIER:
  33744. + dprintk("SET_SEND_CARRIER\n");
  33745. + result = get_user(value, (__u32 *) arg);
  33746. + if (result)
  33747. + return result;
  33748. + if (value > 500000 || value < 20000)
  33749. + return -EINVAL;
  33750. + return init_timing_params(duty_cycle, value);
  33751. + break;
  33752. +
  33753. + default:
  33754. + return lirc_dev_fop_ioctl(filep, cmd, arg);
  33755. + }
  33756. + return 0;
  33757. +}
  33758. +
  33759. +static const struct file_operations lirc_fops = {
  33760. + .owner = THIS_MODULE,
  33761. + .write = lirc_write,
  33762. + .unlocked_ioctl = lirc_ioctl,
  33763. + .read = lirc_dev_fop_read,
  33764. + .poll = lirc_dev_fop_poll,
  33765. + .open = lirc_dev_fop_open,
  33766. + .release = lirc_dev_fop_close,
  33767. + .llseek = no_llseek,
  33768. +};
  33769. +
  33770. +static struct lirc_driver driver = {
  33771. + .name = LIRC_DRIVER_NAME,
  33772. + .minor = -1,
  33773. + .code_length = 1,
  33774. + .sample_rate = 0,
  33775. + .data = NULL,
  33776. + .add_to_buf = NULL,
  33777. + .rbuf = &rbuf,
  33778. + .set_use_inc = set_use_inc,
  33779. + .set_use_dec = set_use_dec,
  33780. + .fops = &lirc_fops,
  33781. + .dev = NULL,
  33782. + .owner = THIS_MODULE,
  33783. +};
  33784. +
  33785. +static struct platform_driver lirc_rpi_driver = {
  33786. + .driver = {
  33787. + .name = LIRC_DRIVER_NAME,
  33788. + .owner = THIS_MODULE,
  33789. + },
  33790. +};
  33791. +
  33792. +static int __init lirc_rpi_init(void)
  33793. +{
  33794. + int result;
  33795. +
  33796. + /* Init read buffer. */
  33797. + result = lirc_buffer_init(&rbuf, sizeof(int), RBUF_LEN);
  33798. + if (result < 0)
  33799. + return -ENOMEM;
  33800. +
  33801. + result = platform_driver_register(&lirc_rpi_driver);
  33802. + if (result) {
  33803. + printk(KERN_ERR LIRC_DRIVER_NAME
  33804. + ": lirc register returned %d\n", result);
  33805. + goto exit_buffer_free;
  33806. + }
  33807. +
  33808. + lirc_rpi_dev = platform_device_alloc(LIRC_DRIVER_NAME, 0);
  33809. + if (!lirc_rpi_dev) {
  33810. + result = -ENOMEM;
  33811. + goto exit_driver_unregister;
  33812. + }
  33813. +
  33814. + result = platform_device_add(lirc_rpi_dev);
  33815. + if (result)
  33816. + goto exit_device_put;
  33817. +
  33818. + return 0;
  33819. +
  33820. + exit_device_put:
  33821. + platform_device_put(lirc_rpi_dev);
  33822. +
  33823. + exit_driver_unregister:
  33824. + platform_driver_unregister(&lirc_rpi_driver);
  33825. +
  33826. + exit_buffer_free:
  33827. + lirc_buffer_free(&rbuf);
  33828. +
  33829. + return result;
  33830. +}
  33831. +
  33832. +static void lirc_rpi_exit(void)
  33833. +{
  33834. + platform_device_unregister(lirc_rpi_dev);
  33835. + platform_driver_unregister(&lirc_rpi_driver);
  33836. + lirc_buffer_free(&rbuf);
  33837. +}
  33838. +
  33839. +static int __init lirc_rpi_init_module(void)
  33840. +{
  33841. + int result, i;
  33842. +
  33843. + result = lirc_rpi_init();
  33844. + if (result)
  33845. + return result;
  33846. +
  33847. + /* check if the module received valid gpio pin numbers */
  33848. + result = 0;
  33849. + if (gpio_in_pin != gpio_out_pin) {
  33850. + for(i = 0; (i < ARRAY_SIZE(valid_gpio_pins)) && (result != 2); i++) {
  33851. + if (gpio_in_pin == valid_gpio_pins[i] ||
  33852. + gpio_out_pin == valid_gpio_pins[i]) {
  33853. + result++;
  33854. + }
  33855. + }
  33856. + }
  33857. +
  33858. + if (result != 2) {
  33859. + result = -EINVAL;
  33860. + printk(KERN_ERR LIRC_DRIVER_NAME
  33861. + ": invalid GPIO pin(s) specified!\n");
  33862. + goto exit_rpi;
  33863. + }
  33864. +
  33865. + result = init_port();
  33866. + if (result < 0)
  33867. + goto exit_rpi;
  33868. +
  33869. + driver.features = LIRC_CAN_SET_SEND_DUTY_CYCLE |
  33870. + LIRC_CAN_SET_SEND_CARRIER |
  33871. + LIRC_CAN_SEND_PULSE |
  33872. + LIRC_CAN_REC_MODE2;
  33873. +
  33874. + driver.dev = &lirc_rpi_dev->dev;
  33875. + driver.minor = lirc_register_driver(&driver);
  33876. +
  33877. + if (driver.minor < 0) {
  33878. + printk(KERN_ERR LIRC_DRIVER_NAME
  33879. + ": device registration failed with %d\n", result);
  33880. + result = -EIO;
  33881. + goto exit_rpi;
  33882. + }
  33883. +
  33884. + printk(KERN_INFO LIRC_DRIVER_NAME ": driver registered!\n");
  33885. +
  33886. + return 0;
  33887. +
  33888. + exit_rpi:
  33889. + lirc_rpi_exit();
  33890. +
  33891. + return result;
  33892. +}
  33893. +
  33894. +static void __exit lirc_rpi_exit_module(void)
  33895. +{
  33896. + gpio_free(gpio_out_pin);
  33897. + gpio_free(gpio_in_pin);
  33898. +
  33899. + lirc_rpi_exit();
  33900. +
  33901. + lirc_unregister_driver(driver.minor);
  33902. + printk(KERN_INFO LIRC_DRIVER_NAME ": cleaned up module\n");
  33903. +}
  33904. +
  33905. +module_init(lirc_rpi_init_module);
  33906. +module_exit(lirc_rpi_exit_module);
  33907. +
  33908. +MODULE_DESCRIPTION("Infra-red receiver and blaster driver for Raspberry Pi GPIO.");
  33909. +MODULE_AUTHOR("Aron Robert Szabo <aron@reon.hu>");
  33910. +MODULE_AUTHOR("Michael Bishop <cleverca22@gmail.com>");
  33911. +MODULE_LICENSE("GPL");
  33912. +
  33913. +module_param(gpio_out_pin, int, S_IRUGO);
  33914. +MODULE_PARM_DESC(gpio_out_pin, "GPIO output/transmitter pin number of the BCM"
  33915. + " processor. Valid pin numbers are: 0, 1, 4, 8, 7, 9, 10, 11,"
  33916. + " 14, 15, 17, 18, 21, 22, 23, 24, 25, default 17");
  33917. +
  33918. +module_param(gpio_in_pin, int, S_IRUGO);
  33919. +MODULE_PARM_DESC(gpio_in_pin, "GPIO input pin number of the BCM processor."
  33920. + " Valid pin numbers are: 0, 1, 4, 8, 7, 9, 10, 11, 14, 15,"
  33921. + " 17, 18, 21, 22, 23, 24, 25, default 18");
  33922. +
  33923. +module_param(sense, int, S_IRUGO);
  33924. +MODULE_PARM_DESC(sense, "Override autodetection of IR receiver circuit"
  33925. + " (0 = active high, 1 = active low )");
  33926. +
  33927. +module_param(softcarrier, bool, S_IRUGO);
  33928. +MODULE_PARM_DESC(softcarrier, "Software carrier (0 = off, 1 = on, default on)");
  33929. +
  33930. +module_param(invert, bool, S_IRUGO);
  33931. +MODULE_PARM_DESC(invert, "Invert output (0 = off, 1 = on, default off");
  33932. +
  33933. +module_param(debug, bool, S_IRUGO | S_IWUSR);
  33934. +MODULE_PARM_DESC(debug, "Enable debugging messages");
  33935. diff -Nur linux-3.13.11/drivers/staging/media/lirc/Makefile linux-rpi/drivers/staging/media/lirc/Makefile
  33936. --- linux-3.13.11/drivers/staging/media/lirc/Makefile 2014-04-23 01:49:33.000000000 +0200
  33937. +++ linux-rpi/drivers/staging/media/lirc/Makefile 2014-04-24 15:35:03.925563013 +0200
  33938. @@ -7,6 +7,7 @@
  33939. obj-$(CONFIG_LIRC_IGORPLUGUSB) += lirc_igorplugusb.o
  33940. obj-$(CONFIG_LIRC_IMON) += lirc_imon.o
  33941. obj-$(CONFIG_LIRC_PARALLEL) += lirc_parallel.o
  33942. +obj-$(CONFIG_LIRC_RPI) += lirc_rpi.o
  33943. obj-$(CONFIG_LIRC_SASEM) += lirc_sasem.o
  33944. obj-$(CONFIG_LIRC_SERIAL) += lirc_serial.o
  33945. obj-$(CONFIG_LIRC_SIR) += lirc_sir.o
  33946. diff -Nur linux-3.13.11/drivers/thermal/bcm2835-thermal.c linux-rpi/drivers/thermal/bcm2835-thermal.c
  33947. --- linux-3.13.11/drivers/thermal/bcm2835-thermal.c 1970-01-01 01:00:00.000000000 +0100
  33948. +++ linux-rpi/drivers/thermal/bcm2835-thermal.c 2014-04-24 15:35:04.089564840 +0200
  33949. @@ -0,0 +1,184 @@
  33950. +/*****************************************************************************
  33951. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  33952. +*
  33953. +* Unless you and Broadcom execute a separate written software license
  33954. +* agreement governing use of this software, this software is licensed to you
  33955. +* under the terms of the GNU General Public License version 2, available at
  33956. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  33957. +*
  33958. +* Notwithstanding the above, under no circumstances may you combine this
  33959. +* software in any way with any other Broadcom software provided under a
  33960. +* license other than the GPL, without Broadcom's express prior written
  33961. +* consent.
  33962. +*****************************************************************************/
  33963. +
  33964. +#include <linux/kernel.h>
  33965. +#include <linux/module.h>
  33966. +#include <linux/init.h>
  33967. +#include <linux/platform_device.h>
  33968. +#include <linux/slab.h>
  33969. +#include <linux/sysfs.h>
  33970. +#include <mach/vcio.h>
  33971. +#include <linux/thermal.h>
  33972. +
  33973. +
  33974. +/* --- DEFINITIONS --- */
  33975. +#define MODULE_NAME "bcm2835_thermal"
  33976. +
  33977. +/*#define THERMAL_DEBUG_ENABLE*/
  33978. +
  33979. +#ifdef THERMAL_DEBUG_ENABLE
  33980. +#define print_debug(fmt,...) printk(KERN_INFO "%s:%s:%d: "fmt"\n", MODULE_NAME, __func__, __LINE__, ##__VA_ARGS__)
  33981. +#else
  33982. +#define print_debug(fmt,...)
  33983. +#endif
  33984. +#define print_err(fmt,...) printk(KERN_ERR "%s:%s:%d: "fmt"\n", MODULE_NAME, __func__,__LINE__, ##__VA_ARGS__)
  33985. +
  33986. +#define VC_TAG_GET_TEMP 0x00030006
  33987. +#define VC_TAG_GET_MAX_TEMP 0x0003000A
  33988. +
  33989. +typedef enum {
  33990. + TEMP,
  33991. + MAX_TEMP,
  33992. +} temp_type;
  33993. +
  33994. +/* --- STRUCTS --- */
  33995. +/* tag part of the message */
  33996. +struct vc_msg_tag {
  33997. + uint32_t tag_id; /* the tag ID for the temperature */
  33998. + uint32_t buffer_size; /* size of the buffer (should be 8) */
  33999. + uint32_t request_code; /* identifies message as a request (should be 0) */
  34000. + uint32_t id; /* extra ID field (should be 0) */
  34001. + uint32_t val; /* returned value of the temperature */
  34002. +};
  34003. +
  34004. +/* message structure to be sent to videocore */
  34005. +struct vc_msg {
  34006. + uint32_t msg_size; /* simply, sizeof(struct vc_msg) */
  34007. + uint32_t request_code; /* holds various information like the success and number of bytes returned (refer to mailboxes wiki) */
  34008. + struct vc_msg_tag tag; /* the tag structure above to make */
  34009. + uint32_t end_tag; /* an end identifier, should be set to NULL */
  34010. +};
  34011. +
  34012. +struct bcm2835_thermal_data {
  34013. + struct thermal_zone_device *thermal_dev;
  34014. + struct vc_msg msg;
  34015. +};
  34016. +
  34017. +/* --- GLOBALS --- */
  34018. +static struct bcm2835_thermal_data bcm2835_data;
  34019. +
  34020. +/* Thermal Device Operations */
  34021. +static struct thermal_zone_device_ops ops;
  34022. +
  34023. +/* --- FUNCTIONS --- */
  34024. +
  34025. +static int bcm2835_get_temp_or_max(struct thermal_zone_device *thermal_dev, unsigned long *temp, unsigned tag_id)
  34026. +{
  34027. + int result = -1, retry = 3;
  34028. + print_debug("IN");
  34029. +
  34030. + *temp = 0;
  34031. + while (result != 0 && retry-- > 0) {
  34032. + /* wipe all previous message data */
  34033. + memset(&bcm2835_data.msg, 0, sizeof bcm2835_data.msg);
  34034. +
  34035. + /* prepare message */
  34036. + bcm2835_data.msg.msg_size = sizeof bcm2835_data.msg;
  34037. + bcm2835_data.msg.tag.buffer_size = 8;
  34038. + bcm2835_data.msg.tag.tag_id = tag_id;
  34039. +
  34040. + /* send the message */
  34041. + result = bcm_mailbox_property(&bcm2835_data.msg, sizeof bcm2835_data.msg);
  34042. + 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);
  34043. + if (!(bcm2835_data.msg.request_code & 0x80000000))
  34044. + result = -1;
  34045. + }
  34046. +
  34047. + /* check if it was all ok and return the rate in milli degrees C */
  34048. + if (result == 0)
  34049. + *temp = (uint)bcm2835_data.msg.tag.val;
  34050. + else
  34051. + print_err("Failed to get temperature! (%x:%d)\n", tag_id, result);
  34052. + print_debug("OUT");
  34053. + return result;
  34054. +}
  34055. +
  34056. +static int bcm2835_get_temp(struct thermal_zone_device *thermal_dev, unsigned long *temp)
  34057. +{
  34058. + return bcm2835_get_temp_or_max(thermal_dev, temp, VC_TAG_GET_TEMP);
  34059. +}
  34060. +
  34061. +static int bcm2835_get_max_temp(struct thermal_zone_device *thermal_dev, int trip_num, unsigned long *temp)
  34062. +{
  34063. + return bcm2835_get_temp_or_max(thermal_dev, temp, VC_TAG_GET_MAX_TEMP);
  34064. +}
  34065. +
  34066. +static int bcm2835_get_trip_type(struct thermal_zone_device * thermal_dev, int trip_num, enum thermal_trip_type *trip_type)
  34067. +{
  34068. + *trip_type = THERMAL_TRIP_HOT;
  34069. + return 0;
  34070. +}
  34071. +
  34072. +
  34073. +static int bcm2835_get_mode(struct thermal_zone_device *thermal_dev, enum thermal_device_mode *dev_mode)
  34074. +{
  34075. + *dev_mode = THERMAL_DEVICE_ENABLED;
  34076. + return 0;
  34077. +}
  34078. +
  34079. +
  34080. +static int bcm2835_thermal_probe(struct platform_device *pdev)
  34081. +{
  34082. + print_debug("IN");
  34083. + print_debug("THERMAL Driver has been probed!");
  34084. +
  34085. + /* check that the device isn't null!*/
  34086. + if(pdev == NULL)
  34087. + {
  34088. + print_debug("Platform device is empty!");
  34089. + return -ENODEV;
  34090. + }
  34091. +
  34092. + if(!(bcm2835_data.thermal_dev = thermal_zone_device_register("bcm2835_thermal", 1, 0, NULL, &ops, NULL, 0, 0)))
  34093. + {
  34094. + print_debug("Unable to register the thermal device!");
  34095. + return -EFAULT;
  34096. + }
  34097. + return 0;
  34098. +}
  34099. +
  34100. +
  34101. +static int bcm2835_thermal_remove(struct platform_device *pdev)
  34102. +{
  34103. + print_debug("IN");
  34104. +
  34105. + thermal_zone_device_unregister(bcm2835_data.thermal_dev);
  34106. +
  34107. + print_debug("OUT");
  34108. +
  34109. + return 0;
  34110. +}
  34111. +
  34112. +static struct thermal_zone_device_ops ops = {
  34113. + .get_temp = bcm2835_get_temp,
  34114. + .get_trip_temp = bcm2835_get_max_temp,
  34115. + .get_trip_type = bcm2835_get_trip_type,
  34116. + .get_mode = bcm2835_get_mode,
  34117. +};
  34118. +
  34119. +/* Thermal Driver */
  34120. +static struct platform_driver bcm2835_thermal_driver = {
  34121. + .probe = bcm2835_thermal_probe,
  34122. + .remove = bcm2835_thermal_remove,
  34123. + .driver = {
  34124. + .name = "bcm2835_thermal",
  34125. + .owner = THIS_MODULE,
  34126. + },
  34127. +};
  34128. +
  34129. +MODULE_LICENSE("GPL");
  34130. +MODULE_AUTHOR("Dorian Peake");
  34131. +MODULE_DESCRIPTION("Thermal driver for bcm2835 chip");
  34132. +
  34133. +module_platform_driver(bcm2835_thermal_driver);
  34134. diff -Nur linux-3.13.11/drivers/thermal/Kconfig linux-rpi/drivers/thermal/Kconfig
  34135. --- linux-3.13.11/drivers/thermal/Kconfig 2014-04-23 01:49:33.000000000 +0200
  34136. +++ linux-rpi/drivers/thermal/Kconfig 2014-04-24 15:37:12.290979343 +0200
  34137. @@ -181,6 +181,12 @@
  34138. enforce idle time which results in more package C-state residency. The
  34139. user interface is exposed via generic thermal framework.
  34140. +config THERMAL_BCM2835
  34141. + tristate "BCM2835 Thermal Driver"
  34142. + help
  34143. + This will enable temperature monitoring for the Broadcom BCM2835
  34144. + chip. If built as a module, it will be called 'bcm2835-thermal'.
  34145. +
  34146. config X86_PKG_TEMP_THERMAL
  34147. tristate "X86 package temperature thermal driver"
  34148. depends on X86_THERMAL_VECTOR
  34149. diff -Nur linux-3.13.11/drivers/thermal/Makefile linux-rpi/drivers/thermal/Makefile
  34150. --- linux-3.13.11/drivers/thermal/Makefile 2014-04-23 01:49:33.000000000 +0200
  34151. +++ linux-rpi/drivers/thermal/Makefile 2014-04-24 15:37:12.290979343 +0200
  34152. @@ -27,5 +27,6 @@
  34153. obj-$(CONFIG_IMX_THERMAL) += imx_thermal.o
  34154. obj-$(CONFIG_DB8500_CPUFREQ_COOLING) += db8500_cpufreq_cooling.o
  34155. obj-$(CONFIG_INTEL_POWERCLAMP) += intel_powerclamp.o
  34156. +obj-$(CONFIG_THERMAL_BCM2835) += bcm2835-thermal.o
  34157. obj-$(CONFIG_X86_PKG_TEMP_THERMAL) += x86_pkg_temp_thermal.o
  34158. obj-$(CONFIG_TI_SOC_THERMAL) += ti-soc-thermal/
  34159. diff -Nur linux-3.13.11/drivers/tty/ipwireless/tty.c linux-rpi/drivers/tty/ipwireless/tty.c
  34160. --- linux-3.13.11/drivers/tty/ipwireless/tty.c 2014-04-23 01:49:33.000000000 +0200
  34161. +++ linux-rpi/drivers/tty/ipwireless/tty.c 2014-04-24 15:35:04.093564884 +0200
  34162. @@ -177,6 +177,9 @@
  34163. ": %d chars not inserted to flip buffer!\n",
  34164. length - work);
  34165. + /*
  34166. + * This may sleep if ->low_latency is set
  34167. + */
  34168. if (work)
  34169. tty_flip_buffer_push(&tty->port);
  34170. }
  34171. diff -Nur linux-3.13.11/drivers/tty/serial/amba-pl011.c linux-rpi/drivers/tty/serial/amba-pl011.c
  34172. --- linux-3.13.11/drivers/tty/serial/amba-pl011.c 2014-04-23 01:49:33.000000000 +0200
  34173. +++ linux-rpi/drivers/tty/serial/amba-pl011.c 2014-04-24 15:37:12.478981397 +0200
  34174. @@ -84,7 +84,7 @@
  34175. static unsigned int get_fifosize_arm(struct amba_device *dev)
  34176. {
  34177. - return amba_rev(dev) < 3 ? 16 : 32;
  34178. + return 16; //TODO: fix: amba_rev(dev) < 3 ? 16 : 32;
  34179. }
  34180. static struct vendor_data vendor_arm = {
  34181. diff -Nur linux-3.13.11/drivers/tty/tty_buffer.c linux-rpi/drivers/tty/tty_buffer.c
  34182. --- linux-3.13.11/drivers/tty/tty_buffer.c 2014-04-23 01:49:33.000000000 +0200
  34183. +++ linux-rpi/drivers/tty/tty_buffer.c 2014-04-24 15:37:12.726984108 +0200
  34184. @@ -332,11 +332,14 @@
  34185. * Takes any pending buffers and transfers their ownership to the
  34186. * ldisc side of the queue. It then schedules those characters for
  34187. * processing by the line discipline.
  34188. + * Note that this function can only be used when the low_latency flag
  34189. + * is unset. Otherwise the workqueue won't be flushed.
  34190. */
  34191. void tty_schedule_flip(struct tty_port *port)
  34192. {
  34193. struct tty_bufhead *buf = &port->buf;
  34194. + WARN_ON(port->low_latency);
  34195. buf->tail->commit = buf->tail->used;
  34196. schedule_work(&buf->work);
  34197. @@ -484,15 +487,17 @@
  34198. */
  34199. void tty_flush_to_ldisc(struct tty_struct *tty)
  34200. {
  34201. - flush_work(&tty->port->buf.work);
  34202. + if (!tty->port->low_latency)
  34203. + flush_work(&tty->port->buf.work);
  34204. }
  34205. /**
  34206. * tty_flip_buffer_push - terminal
  34207. * @port: tty port to push
  34208. *
  34209. - * Queue a push of the terminal flip buffers to the line discipline.
  34210. - * Can be called from IRQ/atomic context.
  34211. + * Queue a push of the terminal flip buffers to the line discipline. This
  34212. + * function must not be called from IRQ context if port->low_latency is
  34213. + * set.
  34214. *
  34215. * In the event of the queue being busy for flipping the work will be
  34216. * held off and retried later.
  34217. @@ -500,7 +505,14 @@
  34218. void tty_flip_buffer_push(struct tty_port *port)
  34219. {
  34220. - tty_schedule_flip(port);
  34221. + struct tty_bufhead *buf = &port->buf;
  34222. +
  34223. + buf->tail->commit = buf->tail->used;
  34224. +
  34225. + if (port->low_latency)
  34226. + flush_to_ldisc(&buf->work);
  34227. + else
  34228. + schedule_work(&buf->work);
  34229. }
  34230. EXPORT_SYMBOL(tty_flip_buffer_push);
  34231. diff -Nur linux-3.13.11/drivers/tty/tty_io.c linux-rpi/drivers/tty/tty_io.c
  34232. --- linux-3.13.11/drivers/tty/tty_io.c 2014-04-23 01:49:33.000000000 +0200
  34233. +++ linux-rpi/drivers/tty/tty_io.c 2014-04-24 15:37:12.726984108 +0200
  34234. @@ -1271,13 +1271,12 @@
  34235. *
  34236. * Locking: None
  34237. */
  34238. -static ssize_t tty_line_name(struct tty_driver *driver, int index, char *p)
  34239. +static void tty_line_name(struct tty_driver *driver, int index, char *p)
  34240. {
  34241. if (driver->flags & TTY_DRIVER_UNNUMBERED_NODE)
  34242. - return sprintf(p, "%s", driver->name);
  34243. + strcpy(p, driver->name);
  34244. else
  34245. - return sprintf(p, "%s%d", driver->name,
  34246. - index + driver->name_base);
  34247. + sprintf(p, "%s%d", driver->name, index + driver->name_base);
  34248. }
  34249. /**
  34250. @@ -3546,19 +3545,9 @@
  34251. if (i >= ARRAY_SIZE(cs))
  34252. break;
  34253. }
  34254. - while (i--) {
  34255. - int index = cs[i]->index;
  34256. - struct tty_driver *drv = cs[i]->device(cs[i], &index);
  34257. -
  34258. - /* don't resolve tty0 as some programs depend on it */
  34259. - if (drv && (cs[i]->index > 0 || drv->major != TTY_MAJOR))
  34260. - count += tty_line_name(drv, index, buf + count);
  34261. - else
  34262. - count += sprintf(buf + count, "%s%d",
  34263. - cs[i]->name, cs[i]->index);
  34264. -
  34265. - count += sprintf(buf + count, "%c", i ? ' ':'\n');
  34266. - }
  34267. + while (i--)
  34268. + count += sprintf(buf + count, "%s%d%c",
  34269. + cs[i]->name, cs[i]->index, i ? ' ':'\n');
  34270. console_unlock();
  34271. return count;
  34272. diff -Nur linux-3.13.11/drivers/usb/core/generic.c linux-rpi/drivers/usb/core/generic.c
  34273. --- linux-3.13.11/drivers/usb/core/generic.c 2014-04-23 01:49:33.000000000 +0200
  34274. +++ linux-rpi/drivers/usb/core/generic.c 2014-04-24 15:35:04.137565375 +0200
  34275. @@ -152,6 +152,7 @@
  34276. dev_warn(&udev->dev,
  34277. "no configuration chosen from %d choice%s\n",
  34278. num_configs, plural(num_configs));
  34279. + dev_warn(&udev->dev, "No support over %dmA\n", udev->bus_mA);
  34280. }
  34281. return i;
  34282. }
  34283. diff -Nur linux-3.13.11/drivers/usb/core/message.c linux-rpi/drivers/usb/core/message.c
  34284. --- linux-3.13.11/drivers/usb/core/message.c 2014-04-23 01:49:33.000000000 +0200
  34285. +++ linux-rpi/drivers/usb/core/message.c 2014-04-24 15:37:13.270990052 +0200
  34286. @@ -1889,6 +1889,85 @@
  34287. if (cp->string == NULL &&
  34288. !(dev->quirks & USB_QUIRK_CONFIG_INTF_STRINGS))
  34289. cp->string = usb_cache_string(dev, cp->desc.iConfiguration);
  34290. +/* Uncomment this define to enable the HS Electrical Test support */
  34291. +#define DWC_HS_ELECT_TST 1
  34292. +#ifdef DWC_HS_ELECT_TST
  34293. + /* Here we implement the HS Electrical Test support. The
  34294. + * tester uses a vendor ID of 0x1A0A to indicate we should
  34295. + * run a special test sequence. The product ID tells us
  34296. + * which sequence to run. We invoke the test sequence by
  34297. + * sending a non-standard SetFeature command to our root
  34298. + * hub port. Our dwc_otg_hcd_hub_control() routine will
  34299. + * recognize the command and perform the desired test
  34300. + * sequence.
  34301. + */
  34302. + if (dev->descriptor.idVendor == 0x1A0A) {
  34303. + /* HSOTG Electrical Test */
  34304. + dev_warn(&dev->dev, "VID from HSOTG Electrical Test Fixture\n");
  34305. +
  34306. + if (dev->bus && dev->bus->root_hub) {
  34307. + struct usb_device *hdev = dev->bus->root_hub;
  34308. + dev_warn(&dev->dev, "Got PID 0x%x\n", dev->descriptor.idProduct);
  34309. +
  34310. + switch (dev->descriptor.idProduct) {
  34311. + case 0x0101: /* TEST_SE0_NAK */
  34312. + dev_warn(&dev->dev, "TEST_SE0_NAK\n");
  34313. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  34314. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  34315. + USB_PORT_FEAT_TEST, 0x300, NULL, 0, HZ);
  34316. + break;
  34317. +
  34318. + case 0x0102: /* TEST_J */
  34319. + dev_warn(&dev->dev, "TEST_J\n");
  34320. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  34321. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  34322. + USB_PORT_FEAT_TEST, 0x100, NULL, 0, HZ);
  34323. + break;
  34324. +
  34325. + case 0x0103: /* TEST_K */
  34326. + dev_warn(&dev->dev, "TEST_K\n");
  34327. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  34328. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  34329. + USB_PORT_FEAT_TEST, 0x200, NULL, 0, HZ);
  34330. + break;
  34331. +
  34332. + case 0x0104: /* TEST_PACKET */
  34333. + dev_warn(&dev->dev, "TEST_PACKET\n");
  34334. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  34335. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  34336. + USB_PORT_FEAT_TEST, 0x400, NULL, 0, HZ);
  34337. + break;
  34338. +
  34339. + case 0x0105: /* TEST_FORCE_ENABLE */
  34340. + dev_warn(&dev->dev, "TEST_FORCE_ENABLE\n");
  34341. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  34342. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  34343. + USB_PORT_FEAT_TEST, 0x500, NULL, 0, HZ);
  34344. + break;
  34345. +
  34346. + case 0x0106: /* HS_HOST_PORT_SUSPEND_RESUME */
  34347. + dev_warn(&dev->dev, "HS_HOST_PORT_SUSPEND_RESUME\n");
  34348. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  34349. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  34350. + USB_PORT_FEAT_TEST, 0x600, NULL, 0, 40 * HZ);
  34351. + break;
  34352. +
  34353. + case 0x0107: /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR setup */
  34354. + dev_warn(&dev->dev, "SINGLE_STEP_GET_DEVICE_DESCRIPTOR setup\n");
  34355. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  34356. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  34357. + USB_PORT_FEAT_TEST, 0x700, NULL, 0, 40 * HZ);
  34358. + break;
  34359. +
  34360. + case 0x0108: /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR execute */
  34361. + dev_warn(&dev->dev, "SINGLE_STEP_GET_DEVICE_DESCRIPTOR execute\n");
  34362. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  34363. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  34364. + USB_PORT_FEAT_TEST, 0x800, NULL, 0, 40 * HZ);
  34365. + }
  34366. + }
  34367. + }
  34368. +#endif /* DWC_HS_ELECT_TST */
  34369. /* Now that the interfaces are installed, re-enable LPM. */
  34370. usb_unlocked_enable_lpm(dev);
  34371. diff -Nur linux-3.13.11/drivers/usb/core/otg_whitelist.h linux-rpi/drivers/usb/core/otg_whitelist.h
  34372. --- linux-3.13.11/drivers/usb/core/otg_whitelist.h 2014-04-23 01:49:33.000000000 +0200
  34373. +++ linux-rpi/drivers/usb/core/otg_whitelist.h 2014-04-24 15:37:13.270990052 +0200
  34374. @@ -19,33 +19,82 @@
  34375. static struct usb_device_id whitelist_table [] = {
  34376. /* hubs are optional in OTG, but very handy ... */
  34377. +#define CERT_WITHOUT_HUBS
  34378. +#if defined(CERT_WITHOUT_HUBS)
  34379. +{ USB_DEVICE( 0x0000, 0x0000 ), }, /* Root HUB Only*/
  34380. +#else
  34381. { USB_DEVICE_INFO(USB_CLASS_HUB, 0, 0), },
  34382. { USB_DEVICE_INFO(USB_CLASS_HUB, 0, 1), },
  34383. +{ USB_DEVICE_INFO(USB_CLASS_HUB, 0, 2), },
  34384. +#endif
  34385. #ifdef CONFIG_USB_PRINTER /* ignoring nonstatic linkage! */
  34386. /* FIXME actually, printers are NOT supposed to use device classes;
  34387. * they're supposed to use interface classes...
  34388. */
  34389. -{ USB_DEVICE_INFO(7, 1, 1) },
  34390. -{ USB_DEVICE_INFO(7, 1, 2) },
  34391. -{ USB_DEVICE_INFO(7, 1, 3) },
  34392. +//{ USB_DEVICE_INFO(7, 1, 1) },
  34393. +//{ USB_DEVICE_INFO(7, 1, 2) },
  34394. +//{ USB_DEVICE_INFO(7, 1, 3) },
  34395. #endif
  34396. #ifdef CONFIG_USB_NET_CDCETHER
  34397. /* Linux-USB CDC Ethernet gadget */
  34398. -{ USB_DEVICE(0x0525, 0xa4a1), },
  34399. +//{ USB_DEVICE(0x0525, 0xa4a1), },
  34400. /* Linux-USB CDC Ethernet + RNDIS gadget */
  34401. -{ USB_DEVICE(0x0525, 0xa4a2), },
  34402. +//{ USB_DEVICE(0x0525, 0xa4a2), },
  34403. #endif
  34404. #if defined(CONFIG_USB_TEST) || defined(CONFIG_USB_TEST_MODULE)
  34405. /* gadget zero, for testing */
  34406. -{ USB_DEVICE(0x0525, 0xa4a0), },
  34407. +//{ USB_DEVICE(0x0525, 0xa4a0), },
  34408. #endif
  34409. +/* OPT Tester */
  34410. +{ USB_DEVICE( 0x1a0a, 0x0101 ), }, /* TEST_SE0_NAK */
  34411. +{ USB_DEVICE( 0x1a0a, 0x0102 ), }, /* Test_J */
  34412. +{ USB_DEVICE( 0x1a0a, 0x0103 ), }, /* Test_K */
  34413. +{ USB_DEVICE( 0x1a0a, 0x0104 ), }, /* Test_PACKET */
  34414. +{ USB_DEVICE( 0x1a0a, 0x0105 ), }, /* Test_FORCE_ENABLE */
  34415. +{ USB_DEVICE( 0x1a0a, 0x0106 ), }, /* HS_PORT_SUSPEND_RESUME */
  34416. +{ USB_DEVICE( 0x1a0a, 0x0107 ), }, /* SINGLE_STEP_GET_DESCRIPTOR setup */
  34417. +{ USB_DEVICE( 0x1a0a, 0x0108 ), }, /* SINGLE_STEP_GET_DESCRIPTOR execute */
  34418. +
  34419. +/* Sony cameras */
  34420. +{ USB_DEVICE_VER(0x054c,0x0010,0x0410, 0x0500), },
  34421. +
  34422. +/* Memory Devices */
  34423. +//{ USB_DEVICE( 0x0781, 0x5150 ), }, /* SanDisk */
  34424. +//{ USB_DEVICE( 0x05DC, 0x0080 ), }, /* Lexar */
  34425. +//{ USB_DEVICE( 0x4146, 0x9281 ), }, /* IOMEGA */
  34426. +//{ USB_DEVICE( 0x067b, 0x2507 ), }, /* Hammer 20GB External HD */
  34427. +{ USB_DEVICE( 0x0EA0, 0x2168 ), }, /* Ours Technology Inc. (BUFFALO ClipDrive)*/
  34428. +//{ USB_DEVICE( 0x0457, 0x0150 ), }, /* Silicon Integrated Systems Corp. */
  34429. +
  34430. +/* HP Printers */
  34431. +//{ USB_DEVICE( 0x03F0, 0x1102 ), }, /* HP Photosmart 245 */
  34432. +//{ USB_DEVICE( 0x03F0, 0x1302 ), }, /* HP Photosmart 370 Series */
  34433. +
  34434. +/* Speakers */
  34435. +//{ USB_DEVICE( 0x0499, 0x3002 ), }, /* YAMAHA YST-MS35D USB Speakers */
  34436. +//{ USB_DEVICE( 0x0672, 0x1041 ), }, /* Labtec USB Headset */
  34437. +
  34438. { } /* Terminating entry */
  34439. };
  34440. +static inline void report_errors(struct usb_device *dev)
  34441. +{
  34442. + /* OTG MESSAGE: report errors here, customize to match your product */
  34443. + dev_info(&dev->dev, "device Vendor:%04x Product:%04x is not supported\n",
  34444. + le16_to_cpu(dev->descriptor.idVendor),
  34445. + le16_to_cpu(dev->descriptor.idProduct));
  34446. + if (USB_CLASS_HUB == dev->descriptor.bDeviceClass){
  34447. + dev_printk(KERN_CRIT, &dev->dev, "Unsupported Hub Topology\n");
  34448. + } else {
  34449. + dev_printk(KERN_CRIT, &dev->dev, "Attached Device is not Supported\n");
  34450. + }
  34451. +}
  34452. +
  34453. +
  34454. static int is_targeted(struct usb_device *dev)
  34455. {
  34456. struct usb_device_id *id = whitelist_table;
  34457. @@ -55,58 +104,83 @@
  34458. return 1;
  34459. /* HNP test device is _never_ targeted (see OTG spec 6.6.6) */
  34460. - if ((le16_to_cpu(dev->descriptor.idVendor) == 0x1a0a &&
  34461. - le16_to_cpu(dev->descriptor.idProduct) == 0xbadd))
  34462. - return 0;
  34463. + if (dev->descriptor.idVendor == 0x1a0a &&
  34464. + dev->descriptor.idProduct == 0xbadd) {
  34465. + return 0;
  34466. + } else if (!enable_whitelist) {
  34467. + return 1;
  34468. + } else {
  34469. - /* NOTE: can't use usb_match_id() since interface caches
  34470. - * aren't set up yet. this is cut/paste from that code.
  34471. - */
  34472. - for (id = whitelist_table; id->match_flags; id++) {
  34473. - if ((id->match_flags & USB_DEVICE_ID_MATCH_VENDOR) &&
  34474. - id->idVendor != le16_to_cpu(dev->descriptor.idVendor))
  34475. - continue;
  34476. -
  34477. - if ((id->match_flags & USB_DEVICE_ID_MATCH_PRODUCT) &&
  34478. - id->idProduct != le16_to_cpu(dev->descriptor.idProduct))
  34479. - continue;
  34480. -
  34481. - /* No need to test id->bcdDevice_lo != 0, since 0 is never
  34482. - greater than any unsigned number. */
  34483. - if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_LO) &&
  34484. - (id->bcdDevice_lo > le16_to_cpu(dev->descriptor.bcdDevice)))
  34485. - continue;
  34486. -
  34487. - if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_HI) &&
  34488. - (id->bcdDevice_hi < le16_to_cpu(dev->descriptor.bcdDevice)))
  34489. - continue;
  34490. -
  34491. - if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_CLASS) &&
  34492. - (id->bDeviceClass != dev->descriptor.bDeviceClass))
  34493. - continue;
  34494. -
  34495. - if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_SUBCLASS) &&
  34496. - (id->bDeviceSubClass != dev->descriptor.bDeviceSubClass))
  34497. - continue;
  34498. -
  34499. - if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_PROTOCOL) &&
  34500. - (id->bDeviceProtocol != dev->descriptor.bDeviceProtocol))
  34501. - continue;
  34502. +#ifdef DEBUG
  34503. + dev_dbg(&dev->dev, "device V:%04x P:%04x DC:%04x SC:%04x PR:%04x \n",
  34504. + dev->descriptor.idVendor,
  34505. + dev->descriptor.idProduct,
  34506. + dev->descriptor.bDeviceClass,
  34507. + dev->descriptor.bDeviceSubClass,
  34508. + dev->descriptor.bDeviceProtocol);
  34509. +#endif
  34510. return 1;
  34511. + /* NOTE: can't use usb_match_id() since interface caches
  34512. + * aren't set up yet. this is cut/paste from that code.
  34513. + */
  34514. + for (id = whitelist_table; id->match_flags; id++) {
  34515. +#ifdef DEBUG
  34516. + dev_dbg(&dev->dev,
  34517. + "ID: V:%04x P:%04x DC:%04x SC:%04x PR:%04x \n",
  34518. + id->idVendor,
  34519. + id->idProduct,
  34520. + id->bDeviceClass,
  34521. + id->bDeviceSubClass,
  34522. + id->bDeviceProtocol);
  34523. +#endif
  34524. +
  34525. + if ((id->match_flags & USB_DEVICE_ID_MATCH_VENDOR) &&
  34526. + id->idVendor != le16_to_cpu(dev->descriptor.idVendor))
  34527. + continue;
  34528. +
  34529. + if ((id->match_flags & USB_DEVICE_ID_MATCH_PRODUCT) &&
  34530. + id->idProduct != le16_to_cpu(dev->descriptor.idProduct))
  34531. + continue;
  34532. +
  34533. + /* No need to test id->bcdDevice_lo != 0, since 0 is never
  34534. + greater than any unsigned number. */
  34535. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_LO) &&
  34536. + (id->bcdDevice_lo > le16_to_cpu(dev->descriptor.bcdDevice)))
  34537. + continue;
  34538. +
  34539. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_HI) &&
  34540. + (id->bcdDevice_hi < le16_to_cpu(dev->descriptor.bcdDevice)))
  34541. + continue;
  34542. +
  34543. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_CLASS) &&
  34544. + (id->bDeviceClass != dev->descriptor.bDeviceClass))
  34545. + continue;
  34546. +
  34547. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_SUBCLASS) &&
  34548. + (id->bDeviceSubClass != dev->descriptor.bDeviceSubClass))
  34549. + continue;
  34550. +
  34551. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_PROTOCOL) &&
  34552. + (id->bDeviceProtocol != dev->descriptor.bDeviceProtocol))
  34553. + continue;
  34554. +
  34555. + return 1;
  34556. + }
  34557. }
  34558. /* add other match criteria here ... */
  34559. -
  34560. - /* OTG MESSAGE: report errors here, customize to match your product */
  34561. - dev_err(&dev->dev, "device v%04x p%04x is not supported\n",
  34562. - le16_to_cpu(dev->descriptor.idVendor),
  34563. - le16_to_cpu(dev->descriptor.idProduct));
  34564. #ifdef CONFIG_USB_OTG_WHITELIST
  34565. + report_errors(dev);
  34566. return 0;
  34567. #else
  34568. - return 1;
  34569. + if (enable_whitelist) {
  34570. + report_errors(dev);
  34571. + return 0;
  34572. + } else {
  34573. + return 1;
  34574. + }
  34575. #endif
  34576. }
  34577. diff -Nur linux-3.13.11/drivers/usb/gadget/file_storage.c linux-rpi/drivers/usb/gadget/file_storage.c
  34578. --- linux-3.13.11/drivers/usb/gadget/file_storage.c 1970-01-01 01:00:00.000000000 +0100
  34579. +++ linux-rpi/drivers/usb/gadget/file_storage.c 2014-04-24 15:35:04.153565553 +0200
  34580. @@ -0,0 +1,3676 @@
  34581. +/*
  34582. + * file_storage.c -- File-backed USB Storage Gadget, for USB development
  34583. + *
  34584. + * Copyright (C) 2003-2008 Alan Stern
  34585. + * All rights reserved.
  34586. + *
  34587. + * Redistribution and use in source and binary forms, with or without
  34588. + * modification, are permitted provided that the following conditions
  34589. + * are met:
  34590. + * 1. Redistributions of source code must retain the above copyright
  34591. + * notice, this list of conditions, and the following disclaimer,
  34592. + * without modification.
  34593. + * 2. Redistributions in binary form must reproduce the above copyright
  34594. + * notice, this list of conditions and the following disclaimer in the
  34595. + * documentation and/or other materials provided with the distribution.
  34596. + * 3. The names of the above-listed copyright holders may not be used
  34597. + * to endorse or promote products derived from this software without
  34598. + * specific prior written permission.
  34599. + *
  34600. + * ALTERNATIVELY, this software may be distributed under the terms of the
  34601. + * GNU General Public License ("GPL") as published by the Free Software
  34602. + * Foundation, either version 2 of that License or (at your option) any
  34603. + * later version.
  34604. + *
  34605. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  34606. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  34607. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  34608. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  34609. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  34610. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  34611. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  34612. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  34613. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  34614. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  34615. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34616. + */
  34617. +
  34618. +
  34619. +/*
  34620. + * The File-backed Storage Gadget acts as a USB Mass Storage device,
  34621. + * appearing to the host as a disk drive or as a CD-ROM drive. In addition
  34622. + * to providing an example of a genuinely useful gadget driver for a USB
  34623. + * device, it also illustrates a technique of double-buffering for increased
  34624. + * throughput. Last but not least, it gives an easy way to probe the
  34625. + * behavior of the Mass Storage drivers in a USB host.
  34626. + *
  34627. + * Backing storage is provided by a regular file or a block device, specified
  34628. + * by the "file" module parameter. Access can be limited to read-only by
  34629. + * setting the optional "ro" module parameter. (For CD-ROM emulation,
  34630. + * access is always read-only.) The gadget will indicate that it has
  34631. + * removable media if the optional "removable" module parameter is set.
  34632. + *
  34633. + * The gadget supports the Control-Bulk (CB), Control-Bulk-Interrupt (CBI),
  34634. + * and Bulk-Only (also known as Bulk-Bulk-Bulk or BBB) transports, selected
  34635. + * by the optional "transport" module parameter. It also supports the
  34636. + * following protocols: RBC (0x01), ATAPI or SFF-8020i (0x02), QIC-157 (0c03),
  34637. + * UFI (0x04), SFF-8070i (0x05), and transparent SCSI (0x06), selected by
  34638. + * the optional "protocol" module parameter. In addition, the default
  34639. + * Vendor ID, Product ID, release number and serial number can be overridden.
  34640. + *
  34641. + * There is support for multiple logical units (LUNs), each of which has
  34642. + * its own backing file. The number of LUNs can be set using the optional
  34643. + * "luns" module parameter (anywhere from 1 to 8), and the corresponding
  34644. + * files are specified using comma-separated lists for "file" and "ro".
  34645. + * The default number of LUNs is taken from the number of "file" elements;
  34646. + * it is 1 if "file" is not given. If "removable" is not set then a backing
  34647. + * file must be specified for each LUN. If it is set, then an unspecified
  34648. + * or empty backing filename means the LUN's medium is not loaded. Ideally
  34649. + * each LUN would be settable independently as a disk drive or a CD-ROM
  34650. + * drive, but currently all LUNs have to be the same type. The CD-ROM
  34651. + * emulation includes a single data track and no audio tracks; hence there
  34652. + * need be only one backing file per LUN.
  34653. + *
  34654. + * Requirements are modest; only a bulk-in and a bulk-out endpoint are
  34655. + * needed (an interrupt-out endpoint is also needed for CBI). The memory
  34656. + * requirement amounts to two 16K buffers, size configurable by a parameter.
  34657. + * Support is included for both full-speed and high-speed operation.
  34658. + *
  34659. + * Note that the driver is slightly non-portable in that it assumes a
  34660. + * single memory/DMA buffer will be useable for bulk-in, bulk-out, and
  34661. + * interrupt-in endpoints. With most device controllers this isn't an
  34662. + * issue, but there may be some with hardware restrictions that prevent
  34663. + * a buffer from being used by more than one endpoint.
  34664. + *
  34665. + * Module options:
  34666. + *
  34667. + * file=filename[,filename...]
  34668. + * Required if "removable" is not set, names of
  34669. + * the files or block devices used for
  34670. + * backing storage
  34671. + * serial=HHHH... Required serial number (string of hex chars)
  34672. + * ro=b[,b...] Default false, booleans for read-only access
  34673. + * removable Default false, boolean for removable media
  34674. + * luns=N Default N = number of filenames, number of
  34675. + * LUNs to support
  34676. + * nofua=b[,b...] Default false, booleans for ignore FUA flag
  34677. + * in SCSI WRITE(10,12) commands
  34678. + * stall Default determined according to the type of
  34679. + * USB device controller (usually true),
  34680. + * boolean to permit the driver to halt
  34681. + * bulk endpoints
  34682. + * cdrom Default false, boolean for whether to emulate
  34683. + * a CD-ROM drive
  34684. + * transport=XXX Default BBB, transport name (CB, CBI, or BBB)
  34685. + * protocol=YYY Default SCSI, protocol name (RBC, 8020 or
  34686. + * ATAPI, QIC, UFI, 8070, or SCSI;
  34687. + * also 1 - 6)
  34688. + * vendor=0xVVVV Default 0x0525 (NetChip), USB Vendor ID
  34689. + * product=0xPPPP Default 0xa4a5 (FSG), USB Product ID
  34690. + * release=0xRRRR Override the USB release number (bcdDevice)
  34691. + * buflen=N Default N=16384, buffer size used (will be
  34692. + * rounded down to a multiple of
  34693. + * PAGE_CACHE_SIZE)
  34694. + *
  34695. + * If CONFIG_USB_FILE_STORAGE_TEST is not set, only the "file", "serial", "ro",
  34696. + * "removable", "luns", "nofua", "stall", and "cdrom" options are available;
  34697. + * default values are used for everything else.
  34698. + *
  34699. + * The pathnames of the backing files and the ro settings are available in
  34700. + * the attribute files "file", "nofua", and "ro" in the lun<n> subdirectory of
  34701. + * the gadget's sysfs directory. If the "removable" option is set, writing to
  34702. + * these files will simulate ejecting/loading the medium (writing an empty
  34703. + * line means eject) and adjusting a write-enable tab. Changes to the ro
  34704. + * setting are not allowed when the medium is loaded or if CD-ROM emulation
  34705. + * is being used.
  34706. + *
  34707. + * This gadget driver is heavily based on "Gadget Zero" by David Brownell.
  34708. + * The driver's SCSI command interface was based on the "Information
  34709. + * technology - Small Computer System Interface - 2" document from
  34710. + * X3T9.2 Project 375D, Revision 10L, 7-SEP-93, available at
  34711. + * <http://www.t10.org/ftp/t10/drafts/s2/s2-r10l.pdf>. The single exception
  34712. + * is opcode 0x23 (READ FORMAT CAPACITIES), which was based on the
  34713. + * "Universal Serial Bus Mass Storage Class UFI Command Specification"
  34714. + * document, Revision 1.0, December 14, 1998, available at
  34715. + * <http://www.usb.org/developers/devclass_docs/usbmass-ufi10.pdf>.
  34716. + */
  34717. +
  34718. +
  34719. +/*
  34720. + * Driver Design
  34721. + *
  34722. + * The FSG driver is fairly straightforward. There is a main kernel
  34723. + * thread that handles most of the work. Interrupt routines field
  34724. + * callbacks from the controller driver: bulk- and interrupt-request
  34725. + * completion notifications, endpoint-0 events, and disconnect events.
  34726. + * Completion events are passed to the main thread by wakeup calls. Many
  34727. + * ep0 requests are handled at interrupt time, but SetInterface,
  34728. + * SetConfiguration, and device reset requests are forwarded to the
  34729. + * thread in the form of "exceptions" using SIGUSR1 signals (since they
  34730. + * should interrupt any ongoing file I/O operations).
  34731. + *
  34732. + * The thread's main routine implements the standard command/data/status
  34733. + * parts of a SCSI interaction. It and its subroutines are full of tests
  34734. + * for pending signals/exceptions -- all this polling is necessary since
  34735. + * the kernel has no setjmp/longjmp equivalents. (Maybe this is an
  34736. + * indication that the driver really wants to be running in userspace.)
  34737. + * An important point is that so long as the thread is alive it keeps an
  34738. + * open reference to the backing file. This will prevent unmounting
  34739. + * the backing file's underlying filesystem and could cause problems
  34740. + * during system shutdown, for example. To prevent such problems, the
  34741. + * thread catches INT, TERM, and KILL signals and converts them into
  34742. + * an EXIT exception.
  34743. + *
  34744. + * In normal operation the main thread is started during the gadget's
  34745. + * fsg_bind() callback and stopped during fsg_unbind(). But it can also
  34746. + * exit when it receives a signal, and there's no point leaving the
  34747. + * gadget running when the thread is dead. So just before the thread
  34748. + * exits, it deregisters the gadget driver. This makes things a little
  34749. + * tricky: The driver is deregistered at two places, and the exiting
  34750. + * thread can indirectly call fsg_unbind() which in turn can tell the
  34751. + * thread to exit. The first problem is resolved through the use of the
  34752. + * REGISTERED atomic bitflag; the driver will only be deregistered once.
  34753. + * The second problem is resolved by having fsg_unbind() check
  34754. + * fsg->state; it won't try to stop the thread if the state is already
  34755. + * FSG_STATE_TERMINATED.
  34756. + *
  34757. + * To provide maximum throughput, the driver uses a circular pipeline of
  34758. + * buffer heads (struct fsg_buffhd). In principle the pipeline can be
  34759. + * arbitrarily long; in practice the benefits don't justify having more
  34760. + * than 2 stages (i.e., double buffering). But it helps to think of the
  34761. + * pipeline as being a long one. Each buffer head contains a bulk-in and
  34762. + * a bulk-out request pointer (since the buffer can be used for both
  34763. + * output and input -- directions always are given from the host's
  34764. + * point of view) as well as a pointer to the buffer and various state
  34765. + * variables.
  34766. + *
  34767. + * Use of the pipeline follows a simple protocol. There is a variable
  34768. + * (fsg->next_buffhd_to_fill) that points to the next buffer head to use.
  34769. + * At any time that buffer head may still be in use from an earlier
  34770. + * request, so each buffer head has a state variable indicating whether
  34771. + * it is EMPTY, FULL, or BUSY. Typical use involves waiting for the
  34772. + * buffer head to be EMPTY, filling the buffer either by file I/O or by
  34773. + * USB I/O (during which the buffer head is BUSY), and marking the buffer
  34774. + * head FULL when the I/O is complete. Then the buffer will be emptied
  34775. + * (again possibly by USB I/O, during which it is marked BUSY) and
  34776. + * finally marked EMPTY again (possibly by a completion routine).
  34777. + *
  34778. + * A module parameter tells the driver to avoid stalling the bulk
  34779. + * endpoints wherever the transport specification allows. This is
  34780. + * necessary for some UDCs like the SuperH, which cannot reliably clear a
  34781. + * halt on a bulk endpoint. However, under certain circumstances the
  34782. + * Bulk-only specification requires a stall. In such cases the driver
  34783. + * will halt the endpoint and set a flag indicating that it should clear
  34784. + * the halt in software during the next device reset. Hopefully this
  34785. + * will permit everything to work correctly. Furthermore, although the
  34786. + * specification allows the bulk-out endpoint to halt when the host sends
  34787. + * too much data, implementing this would cause an unavoidable race.
  34788. + * The driver will always use the "no-stall" approach for OUT transfers.
  34789. + *
  34790. + * One subtle point concerns sending status-stage responses for ep0
  34791. + * requests. Some of these requests, such as device reset, can involve
  34792. + * interrupting an ongoing file I/O operation, which might take an
  34793. + * arbitrarily long time. During that delay the host might give up on
  34794. + * the original ep0 request and issue a new one. When that happens the
  34795. + * driver should not notify the host about completion of the original
  34796. + * request, as the host will no longer be waiting for it. So the driver
  34797. + * assigns to each ep0 request a unique tag, and it keeps track of the
  34798. + * tag value of the request associated with a long-running exception
  34799. + * (device-reset, interface-change, or configuration-change). When the
  34800. + * exception handler is finished, the status-stage response is submitted
  34801. + * only if the current ep0 request tag is equal to the exception request
  34802. + * tag. Thus only the most recently received ep0 request will get a
  34803. + * status-stage response.
  34804. + *
  34805. + * Warning: This driver source file is too long. It ought to be split up
  34806. + * into a header file plus about 3 separate .c files, to handle the details
  34807. + * of the Gadget, USB Mass Storage, and SCSI protocols.
  34808. + */
  34809. +
  34810. +
  34811. +/* #define VERBOSE_DEBUG */
  34812. +/* #define DUMP_MSGS */
  34813. +
  34814. +
  34815. +#include <linux/blkdev.h>
  34816. +#include <linux/completion.h>
  34817. +#include <linux/dcache.h>
  34818. +#include <linux/delay.h>
  34819. +#include <linux/device.h>
  34820. +#include <linux/fcntl.h>
  34821. +#include <linux/file.h>
  34822. +#include <linux/fs.h>
  34823. +#include <linux/kref.h>
  34824. +#include <linux/kthread.h>
  34825. +#include <linux/limits.h>
  34826. +#include <linux/module.h>
  34827. +#include <linux/rwsem.h>
  34828. +#include <linux/slab.h>
  34829. +#include <linux/spinlock.h>
  34830. +#include <linux/string.h>
  34831. +#include <linux/freezer.h>
  34832. +#include <linux/utsname.h>
  34833. +
  34834. +#include <linux/usb/ch9.h>
  34835. +#include <linux/usb/gadget.h>
  34836. +
  34837. +#include "gadget_chips.h"
  34838. +
  34839. +
  34840. +
  34841. +/*
  34842. + * Kbuild is not very cooperative with respect to linking separately
  34843. + * compiled library objects into one module. So for now we won't use
  34844. + * separate compilation ... ensuring init/exit sections work to shrink
  34845. + * the runtime footprint, and giving us at least some parts of what
  34846. + * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
  34847. + */
  34848. +#include "usbstring.c"
  34849. +#include "config.c"
  34850. +#include "epautoconf.c"
  34851. +
  34852. +/*-------------------------------------------------------------------------*/
  34853. +
  34854. +#define DRIVER_DESC "File-backed Storage Gadget"
  34855. +#define DRIVER_NAME "g_file_storage"
  34856. +#define DRIVER_VERSION "1 September 2010"
  34857. +
  34858. +static char fsg_string_manufacturer[64];
  34859. +static const char fsg_string_product[] = DRIVER_DESC;
  34860. +static const char fsg_string_config[] = "Self-powered";
  34861. +static const char fsg_string_interface[] = "Mass Storage";
  34862. +
  34863. +
  34864. +#include "storage_common.c"
  34865. +
  34866. +
  34867. +MODULE_DESCRIPTION(DRIVER_DESC);
  34868. +MODULE_AUTHOR("Alan Stern");
  34869. +MODULE_LICENSE("Dual BSD/GPL");
  34870. +
  34871. +/*
  34872. + * This driver assumes self-powered hardware and has no way for users to
  34873. + * trigger remote wakeup. It uses autoconfiguration to select endpoints
  34874. + * and endpoint addresses.
  34875. + */
  34876. +
  34877. +
  34878. +/*-------------------------------------------------------------------------*/
  34879. +
  34880. +
  34881. +/* Encapsulate the module parameter settings */
  34882. +
  34883. +static struct {
  34884. + char *file[FSG_MAX_LUNS];
  34885. + char *serial;
  34886. + bool ro[FSG_MAX_LUNS];
  34887. + bool nofua[FSG_MAX_LUNS];
  34888. + unsigned int num_filenames;
  34889. + unsigned int num_ros;
  34890. + unsigned int num_nofuas;
  34891. + unsigned int nluns;
  34892. +
  34893. + bool removable;
  34894. + bool can_stall;
  34895. + bool cdrom;
  34896. +
  34897. + char *transport_parm;
  34898. + char *protocol_parm;
  34899. + unsigned short vendor;
  34900. + unsigned short product;
  34901. + unsigned short release;
  34902. + unsigned int buflen;
  34903. +
  34904. + int transport_type;
  34905. + char *transport_name;
  34906. + int protocol_type;
  34907. + char *protocol_name;
  34908. +
  34909. +} mod_data = { // Default values
  34910. + .transport_parm = "BBB",
  34911. + .protocol_parm = "SCSI",
  34912. + .removable = 0,
  34913. + .can_stall = 1,
  34914. + .cdrom = 0,
  34915. + .vendor = FSG_VENDOR_ID,
  34916. + .product = FSG_PRODUCT_ID,
  34917. + .release = 0xffff, // Use controller chip type
  34918. + .buflen = 16384,
  34919. + };
  34920. +
  34921. +
  34922. +module_param_array_named(file, mod_data.file, charp, &mod_data.num_filenames,
  34923. + S_IRUGO);
  34924. +MODULE_PARM_DESC(file, "names of backing files or devices");
  34925. +
  34926. +module_param_named(serial, mod_data.serial, charp, S_IRUGO);
  34927. +MODULE_PARM_DESC(serial, "USB serial number");
  34928. +
  34929. +module_param_array_named(ro, mod_data.ro, bool, &mod_data.num_ros, S_IRUGO);
  34930. +MODULE_PARM_DESC(ro, "true to force read-only");
  34931. +
  34932. +module_param_array_named(nofua, mod_data.nofua, bool, &mod_data.num_nofuas,
  34933. + S_IRUGO);
  34934. +MODULE_PARM_DESC(nofua, "true to ignore SCSI WRITE(10,12) FUA bit");
  34935. +
  34936. +module_param_named(luns, mod_data.nluns, uint, S_IRUGO);
  34937. +MODULE_PARM_DESC(luns, "number of LUNs");
  34938. +
  34939. +module_param_named(removable, mod_data.removable, bool, S_IRUGO);
  34940. +MODULE_PARM_DESC(removable, "true to simulate removable media");
  34941. +
  34942. +module_param_named(stall, mod_data.can_stall, bool, S_IRUGO);
  34943. +MODULE_PARM_DESC(stall, "false to prevent bulk stalls");
  34944. +
  34945. +module_param_named(cdrom, mod_data.cdrom, bool, S_IRUGO);
  34946. +MODULE_PARM_DESC(cdrom, "true to emulate cdrom instead of disk");
  34947. +
  34948. +/* In the non-TEST version, only the module parameters listed above
  34949. + * are available. */
  34950. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  34951. +
  34952. +module_param_named(transport, mod_data.transport_parm, charp, S_IRUGO);
  34953. +MODULE_PARM_DESC(transport, "type of transport (BBB, CBI, or CB)");
  34954. +
  34955. +module_param_named(protocol, mod_data.protocol_parm, charp, S_IRUGO);
  34956. +MODULE_PARM_DESC(protocol, "type of protocol (RBC, 8020, QIC, UFI, "
  34957. + "8070, or SCSI)");
  34958. +
  34959. +module_param_named(vendor, mod_data.vendor, ushort, S_IRUGO);
  34960. +MODULE_PARM_DESC(vendor, "USB Vendor ID");
  34961. +
  34962. +module_param_named(product, mod_data.product, ushort, S_IRUGO);
  34963. +MODULE_PARM_DESC(product, "USB Product ID");
  34964. +
  34965. +module_param_named(release, mod_data.release, ushort, S_IRUGO);
  34966. +MODULE_PARM_DESC(release, "USB release number");
  34967. +
  34968. +module_param_named(buflen, mod_data.buflen, uint, S_IRUGO);
  34969. +MODULE_PARM_DESC(buflen, "I/O buffer size");
  34970. +
  34971. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  34972. +
  34973. +
  34974. +/*
  34975. + * These definitions will permit the compiler to avoid generating code for
  34976. + * parts of the driver that aren't used in the non-TEST version. Even gcc
  34977. + * can recognize when a test of a constant expression yields a dead code
  34978. + * path.
  34979. + */
  34980. +
  34981. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  34982. +
  34983. +#define transport_is_bbb() (mod_data.transport_type == USB_PR_BULK)
  34984. +#define transport_is_cbi() (mod_data.transport_type == USB_PR_CBI)
  34985. +#define protocol_is_scsi() (mod_data.protocol_type == USB_SC_SCSI)
  34986. +
  34987. +#else
  34988. +
  34989. +#define transport_is_bbb() 1
  34990. +#define transport_is_cbi() 0
  34991. +#define protocol_is_scsi() 1
  34992. +
  34993. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  34994. +
  34995. +
  34996. +/*-------------------------------------------------------------------------*/
  34997. +
  34998. +
  34999. +struct fsg_dev {
  35000. + /* lock protects: state, all the req_busy's, and cbbuf_cmnd */
  35001. + spinlock_t lock;
  35002. + struct usb_gadget *gadget;
  35003. +
  35004. + /* filesem protects: backing files in use */
  35005. + struct rw_semaphore filesem;
  35006. +
  35007. + /* reference counting: wait until all LUNs are released */
  35008. + struct kref ref;
  35009. +
  35010. + struct usb_ep *ep0; // Handy copy of gadget->ep0
  35011. + struct usb_request *ep0req; // For control responses
  35012. + unsigned int ep0_req_tag;
  35013. + const char *ep0req_name;
  35014. +
  35015. + struct usb_request *intreq; // For interrupt responses
  35016. + int intreq_busy;
  35017. + struct fsg_buffhd *intr_buffhd;
  35018. +
  35019. + unsigned int bulk_out_maxpacket;
  35020. + enum fsg_state state; // For exception handling
  35021. + unsigned int exception_req_tag;
  35022. +
  35023. + u8 config, new_config;
  35024. +
  35025. + unsigned int running : 1;
  35026. + unsigned int bulk_in_enabled : 1;
  35027. + unsigned int bulk_out_enabled : 1;
  35028. + unsigned int intr_in_enabled : 1;
  35029. + unsigned int phase_error : 1;
  35030. + unsigned int short_packet_received : 1;
  35031. + unsigned int bad_lun_okay : 1;
  35032. +
  35033. + unsigned long atomic_bitflags;
  35034. +#define REGISTERED 0
  35035. +#define IGNORE_BULK_OUT 1
  35036. +#define SUSPENDED 2
  35037. +
  35038. + struct usb_ep *bulk_in;
  35039. + struct usb_ep *bulk_out;
  35040. + struct usb_ep *intr_in;
  35041. +
  35042. + struct fsg_buffhd *next_buffhd_to_fill;
  35043. + struct fsg_buffhd *next_buffhd_to_drain;
  35044. +
  35045. + int thread_wakeup_needed;
  35046. + struct completion thread_notifier;
  35047. + struct task_struct *thread_task;
  35048. +
  35049. + int cmnd_size;
  35050. + u8 cmnd[MAX_COMMAND_SIZE];
  35051. + enum data_direction data_dir;
  35052. + u32 data_size;
  35053. + u32 data_size_from_cmnd;
  35054. + u32 tag;
  35055. + unsigned int lun;
  35056. + u32 residue;
  35057. + u32 usb_amount_left;
  35058. +
  35059. + /* The CB protocol offers no way for a host to know when a command
  35060. + * has completed. As a result the next command may arrive early,
  35061. + * and we will still have to handle it. For that reason we need
  35062. + * a buffer to store new commands when using CB (or CBI, which
  35063. + * does not oblige a host to wait for command completion either). */
  35064. + int cbbuf_cmnd_size;
  35065. + u8 cbbuf_cmnd[MAX_COMMAND_SIZE];
  35066. +
  35067. + unsigned int nluns;
  35068. + struct fsg_lun *luns;
  35069. + struct fsg_lun *curlun;
  35070. + /* Must be the last entry */
  35071. + struct fsg_buffhd buffhds[];
  35072. +};
  35073. +
  35074. +typedef void (*fsg_routine_t)(struct fsg_dev *);
  35075. +
  35076. +static int exception_in_progress(struct fsg_dev *fsg)
  35077. +{
  35078. + return (fsg->state > FSG_STATE_IDLE);
  35079. +}
  35080. +
  35081. +/* Make bulk-out requests be divisible by the maxpacket size */
  35082. +static void set_bulk_out_req_length(struct fsg_dev *fsg,
  35083. + struct fsg_buffhd *bh, unsigned int length)
  35084. +{
  35085. + unsigned int rem;
  35086. +
  35087. + bh->bulk_out_intended_length = length;
  35088. + rem = length % fsg->bulk_out_maxpacket;
  35089. + if (rem > 0)
  35090. + length += fsg->bulk_out_maxpacket - rem;
  35091. + bh->outreq->length = length;
  35092. +}
  35093. +
  35094. +static struct fsg_dev *the_fsg;
  35095. +static struct usb_gadget_driver fsg_driver;
  35096. +
  35097. +
  35098. +/*-------------------------------------------------------------------------*/
  35099. +
  35100. +static int fsg_set_halt(struct fsg_dev *fsg, struct usb_ep *ep)
  35101. +{
  35102. + const char *name;
  35103. +
  35104. + if (ep == fsg->bulk_in)
  35105. + name = "bulk-in";
  35106. + else if (ep == fsg->bulk_out)
  35107. + name = "bulk-out";
  35108. + else
  35109. + name = ep->name;
  35110. + DBG(fsg, "%s set halt\n", name);
  35111. + return usb_ep_set_halt(ep);
  35112. +}
  35113. +
  35114. +
  35115. +/*-------------------------------------------------------------------------*/
  35116. +
  35117. +/*
  35118. + * DESCRIPTORS ... most are static, but strings and (full) configuration
  35119. + * descriptors are built on demand. Also the (static) config and interface
  35120. + * descriptors are adjusted during fsg_bind().
  35121. + */
  35122. +
  35123. +/* There is only one configuration. */
  35124. +#define CONFIG_VALUE 1
  35125. +
  35126. +static struct usb_device_descriptor
  35127. +device_desc = {
  35128. + .bLength = sizeof device_desc,
  35129. + .bDescriptorType = USB_DT_DEVICE,
  35130. +
  35131. + .bcdUSB = cpu_to_le16(0x0200),
  35132. + .bDeviceClass = USB_CLASS_PER_INTERFACE,
  35133. +
  35134. + /* The next three values can be overridden by module parameters */
  35135. + .idVendor = cpu_to_le16(FSG_VENDOR_ID),
  35136. + .idProduct = cpu_to_le16(FSG_PRODUCT_ID),
  35137. + .bcdDevice = cpu_to_le16(0xffff),
  35138. +
  35139. + .iManufacturer = FSG_STRING_MANUFACTURER,
  35140. + .iProduct = FSG_STRING_PRODUCT,
  35141. + .iSerialNumber = FSG_STRING_SERIAL,
  35142. + .bNumConfigurations = 1,
  35143. +};
  35144. +
  35145. +static struct usb_config_descriptor
  35146. +config_desc = {
  35147. + .bLength = sizeof config_desc,
  35148. + .bDescriptorType = USB_DT_CONFIG,
  35149. +
  35150. + /* wTotalLength computed by usb_gadget_config_buf() */
  35151. + .bNumInterfaces = 1,
  35152. + .bConfigurationValue = CONFIG_VALUE,
  35153. + .iConfiguration = FSG_STRING_CONFIG,
  35154. + .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
  35155. + .bMaxPower = CONFIG_USB_GADGET_VBUS_DRAW / 2,
  35156. +};
  35157. +
  35158. +
  35159. +static struct usb_qualifier_descriptor
  35160. +dev_qualifier = {
  35161. + .bLength = sizeof dev_qualifier,
  35162. + .bDescriptorType = USB_DT_DEVICE_QUALIFIER,
  35163. +
  35164. + .bcdUSB = cpu_to_le16(0x0200),
  35165. + .bDeviceClass = USB_CLASS_PER_INTERFACE,
  35166. +
  35167. + .bNumConfigurations = 1,
  35168. +};
  35169. +
  35170. +static int populate_bos(struct fsg_dev *fsg, u8 *buf)
  35171. +{
  35172. + memcpy(buf, &fsg_bos_desc, USB_DT_BOS_SIZE);
  35173. + buf += USB_DT_BOS_SIZE;
  35174. +
  35175. + memcpy(buf, &fsg_ext_cap_desc, USB_DT_USB_EXT_CAP_SIZE);
  35176. + buf += USB_DT_USB_EXT_CAP_SIZE;
  35177. +
  35178. + memcpy(buf, &fsg_ss_cap_desc, USB_DT_USB_SS_CAP_SIZE);
  35179. +
  35180. + return USB_DT_BOS_SIZE + USB_DT_USB_SS_CAP_SIZE
  35181. + + USB_DT_USB_EXT_CAP_SIZE;
  35182. +}
  35183. +
  35184. +/*
  35185. + * Config descriptors must agree with the code that sets configurations
  35186. + * and with code managing interfaces and their altsettings. They must
  35187. + * also handle different speeds and other-speed requests.
  35188. + */
  35189. +static int populate_config_buf(struct usb_gadget *gadget,
  35190. + u8 *buf, u8 type, unsigned index)
  35191. +{
  35192. + enum usb_device_speed speed = gadget->speed;
  35193. + int len;
  35194. + const struct usb_descriptor_header **function;
  35195. +
  35196. + if (index > 0)
  35197. + return -EINVAL;
  35198. +
  35199. + if (gadget_is_dualspeed(gadget) && type == USB_DT_OTHER_SPEED_CONFIG)
  35200. + speed = (USB_SPEED_FULL + USB_SPEED_HIGH) - speed;
  35201. + function = gadget_is_dualspeed(gadget) && speed == USB_SPEED_HIGH
  35202. + ? (const struct usb_descriptor_header **)fsg_hs_function
  35203. + : (const struct usb_descriptor_header **)fsg_fs_function;
  35204. +
  35205. + /* for now, don't advertise srp-only devices */
  35206. + if (!gadget_is_otg(gadget))
  35207. + function++;
  35208. +
  35209. + len = usb_gadget_config_buf(&config_desc, buf, EP0_BUFSIZE, function);
  35210. + ((struct usb_config_descriptor *) buf)->bDescriptorType = type;
  35211. + return len;
  35212. +}
  35213. +
  35214. +
  35215. +/*-------------------------------------------------------------------------*/
  35216. +
  35217. +/* These routines may be called in process context or in_irq */
  35218. +
  35219. +/* Caller must hold fsg->lock */
  35220. +static void wakeup_thread(struct fsg_dev *fsg)
  35221. +{
  35222. + /* Tell the main thread that something has happened */
  35223. + fsg->thread_wakeup_needed = 1;
  35224. + if (fsg->thread_task)
  35225. + wake_up_process(fsg->thread_task);
  35226. +}
  35227. +
  35228. +
  35229. +static void raise_exception(struct fsg_dev *fsg, enum fsg_state new_state)
  35230. +{
  35231. + unsigned long flags;
  35232. +
  35233. + /* Do nothing if a higher-priority exception is already in progress.
  35234. + * If a lower-or-equal priority exception is in progress, preempt it
  35235. + * and notify the main thread by sending it a signal. */
  35236. + spin_lock_irqsave(&fsg->lock, flags);
  35237. + if (fsg->state <= new_state) {
  35238. + fsg->exception_req_tag = fsg->ep0_req_tag;
  35239. + fsg->state = new_state;
  35240. + if (fsg->thread_task)
  35241. + send_sig_info(SIGUSR1, SEND_SIG_FORCED,
  35242. + fsg->thread_task);
  35243. + }
  35244. + spin_unlock_irqrestore(&fsg->lock, flags);
  35245. +}
  35246. +
  35247. +
  35248. +/*-------------------------------------------------------------------------*/
  35249. +
  35250. +/* The disconnect callback and ep0 routines. These always run in_irq,
  35251. + * except that ep0_queue() is called in the main thread to acknowledge
  35252. + * completion of various requests: set config, set interface, and
  35253. + * Bulk-only device reset. */
  35254. +
  35255. +static void fsg_disconnect(struct usb_gadget *gadget)
  35256. +{
  35257. + struct fsg_dev *fsg = get_gadget_data(gadget);
  35258. +
  35259. + DBG(fsg, "disconnect or port reset\n");
  35260. + raise_exception(fsg, FSG_STATE_DISCONNECT);
  35261. +}
  35262. +
  35263. +
  35264. +static int ep0_queue(struct fsg_dev *fsg)
  35265. +{
  35266. + int rc;
  35267. +
  35268. + rc = usb_ep_queue(fsg->ep0, fsg->ep0req, GFP_ATOMIC);
  35269. + if (rc != 0 && rc != -ESHUTDOWN) {
  35270. +
  35271. + /* We can't do much more than wait for a reset */
  35272. + WARNING(fsg, "error in submission: %s --> %d\n",
  35273. + fsg->ep0->name, rc);
  35274. + }
  35275. + return rc;
  35276. +}
  35277. +
  35278. +static void ep0_complete(struct usb_ep *ep, struct usb_request *req)
  35279. +{
  35280. + struct fsg_dev *fsg = ep->driver_data;
  35281. +
  35282. + if (req->actual > 0)
  35283. + dump_msg(fsg, fsg->ep0req_name, req->buf, req->actual);
  35284. + if (req->status || req->actual != req->length)
  35285. + DBG(fsg, "%s --> %d, %u/%u\n", __func__,
  35286. + req->status, req->actual, req->length);
  35287. + if (req->status == -ECONNRESET) // Request was cancelled
  35288. + usb_ep_fifo_flush(ep);
  35289. +
  35290. + if (req->status == 0 && req->context)
  35291. + ((fsg_routine_t) (req->context))(fsg);
  35292. +}
  35293. +
  35294. +
  35295. +/*-------------------------------------------------------------------------*/
  35296. +
  35297. +/* Bulk and interrupt endpoint completion handlers.
  35298. + * These always run in_irq. */
  35299. +
  35300. +static void bulk_in_complete(struct usb_ep *ep, struct usb_request *req)
  35301. +{
  35302. + struct fsg_dev *fsg = ep->driver_data;
  35303. + struct fsg_buffhd *bh = req->context;
  35304. +
  35305. + if (req->status || req->actual != req->length)
  35306. + DBG(fsg, "%s --> %d, %u/%u\n", __func__,
  35307. + req->status, req->actual, req->length);
  35308. + if (req->status == -ECONNRESET) // Request was cancelled
  35309. + usb_ep_fifo_flush(ep);
  35310. +
  35311. + /* Hold the lock while we update the request and buffer states */
  35312. + smp_wmb();
  35313. + spin_lock(&fsg->lock);
  35314. + bh->inreq_busy = 0;
  35315. + bh->state = BUF_STATE_EMPTY;
  35316. + wakeup_thread(fsg);
  35317. + spin_unlock(&fsg->lock);
  35318. +}
  35319. +
  35320. +static void bulk_out_complete(struct usb_ep *ep, struct usb_request *req)
  35321. +{
  35322. + struct fsg_dev *fsg = ep->driver_data;
  35323. + struct fsg_buffhd *bh = req->context;
  35324. +
  35325. + dump_msg(fsg, "bulk-out", req->buf, req->actual);
  35326. + if (req->status || req->actual != bh->bulk_out_intended_length)
  35327. + DBG(fsg, "%s --> %d, %u/%u\n", __func__,
  35328. + req->status, req->actual,
  35329. + bh->bulk_out_intended_length);
  35330. + if (req->status == -ECONNRESET) // Request was cancelled
  35331. + usb_ep_fifo_flush(ep);
  35332. +
  35333. + /* Hold the lock while we update the request and buffer states */
  35334. + smp_wmb();
  35335. + spin_lock(&fsg->lock);
  35336. + bh->outreq_busy = 0;
  35337. + bh->state = BUF_STATE_FULL;
  35338. + wakeup_thread(fsg);
  35339. + spin_unlock(&fsg->lock);
  35340. +}
  35341. +
  35342. +
  35343. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  35344. +static void intr_in_complete(struct usb_ep *ep, struct usb_request *req)
  35345. +{
  35346. + struct fsg_dev *fsg = ep->driver_data;
  35347. + struct fsg_buffhd *bh = req->context;
  35348. +
  35349. + if (req->status || req->actual != req->length)
  35350. + DBG(fsg, "%s --> %d, %u/%u\n", __func__,
  35351. + req->status, req->actual, req->length);
  35352. + if (req->status == -ECONNRESET) // Request was cancelled
  35353. + usb_ep_fifo_flush(ep);
  35354. +
  35355. + /* Hold the lock while we update the request and buffer states */
  35356. + smp_wmb();
  35357. + spin_lock(&fsg->lock);
  35358. + fsg->intreq_busy = 0;
  35359. + bh->state = BUF_STATE_EMPTY;
  35360. + wakeup_thread(fsg);
  35361. + spin_unlock(&fsg->lock);
  35362. +}
  35363. +
  35364. +#else
  35365. +static void intr_in_complete(struct usb_ep *ep, struct usb_request *req)
  35366. +{}
  35367. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  35368. +
  35369. +
  35370. +/*-------------------------------------------------------------------------*/
  35371. +
  35372. +/* Ep0 class-specific handlers. These always run in_irq. */
  35373. +
  35374. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  35375. +static void received_cbi_adsc(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  35376. +{
  35377. + struct usb_request *req = fsg->ep0req;
  35378. + static u8 cbi_reset_cmnd[6] = {
  35379. + SEND_DIAGNOSTIC, 4, 0xff, 0xff, 0xff, 0xff};
  35380. +
  35381. + /* Error in command transfer? */
  35382. + if (req->status || req->length != req->actual ||
  35383. + req->actual < 6 || req->actual > MAX_COMMAND_SIZE) {
  35384. +
  35385. + /* Not all controllers allow a protocol stall after
  35386. + * receiving control-out data, but we'll try anyway. */
  35387. + fsg_set_halt(fsg, fsg->ep0);
  35388. + return; // Wait for reset
  35389. + }
  35390. +
  35391. + /* Is it the special reset command? */
  35392. + if (req->actual >= sizeof cbi_reset_cmnd &&
  35393. + memcmp(req->buf, cbi_reset_cmnd,
  35394. + sizeof cbi_reset_cmnd) == 0) {
  35395. +
  35396. + /* Raise an exception to stop the current operation
  35397. + * and reinitialize our state. */
  35398. + DBG(fsg, "cbi reset request\n");
  35399. + raise_exception(fsg, FSG_STATE_RESET);
  35400. + return;
  35401. + }
  35402. +
  35403. + VDBG(fsg, "CB[I] accept device-specific command\n");
  35404. + spin_lock(&fsg->lock);
  35405. +
  35406. + /* Save the command for later */
  35407. + if (fsg->cbbuf_cmnd_size)
  35408. + WARNING(fsg, "CB[I] overwriting previous command\n");
  35409. + fsg->cbbuf_cmnd_size = req->actual;
  35410. + memcpy(fsg->cbbuf_cmnd, req->buf, fsg->cbbuf_cmnd_size);
  35411. +
  35412. + wakeup_thread(fsg);
  35413. + spin_unlock(&fsg->lock);
  35414. +}
  35415. +
  35416. +#else
  35417. +static void received_cbi_adsc(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  35418. +{}
  35419. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  35420. +
  35421. +
  35422. +static int class_setup_req(struct fsg_dev *fsg,
  35423. + const struct usb_ctrlrequest *ctrl)
  35424. +{
  35425. + struct usb_request *req = fsg->ep0req;
  35426. + int value = -EOPNOTSUPP;
  35427. + u16 w_index = le16_to_cpu(ctrl->wIndex);
  35428. + u16 w_value = le16_to_cpu(ctrl->wValue);
  35429. + u16 w_length = le16_to_cpu(ctrl->wLength);
  35430. +
  35431. + if (!fsg->config)
  35432. + return value;
  35433. +
  35434. + /* Handle Bulk-only class-specific requests */
  35435. + if (transport_is_bbb()) {
  35436. + switch (ctrl->bRequest) {
  35437. +
  35438. + case US_BULK_RESET_REQUEST:
  35439. + if (ctrl->bRequestType != (USB_DIR_OUT |
  35440. + USB_TYPE_CLASS | USB_RECIP_INTERFACE))
  35441. + break;
  35442. + if (w_index != 0 || w_value != 0 || w_length != 0) {
  35443. + value = -EDOM;
  35444. + break;
  35445. + }
  35446. +
  35447. + /* Raise an exception to stop the current operation
  35448. + * and reinitialize our state. */
  35449. + DBG(fsg, "bulk reset request\n");
  35450. + raise_exception(fsg, FSG_STATE_RESET);
  35451. + value = DELAYED_STATUS;
  35452. + break;
  35453. +
  35454. + case US_BULK_GET_MAX_LUN:
  35455. + if (ctrl->bRequestType != (USB_DIR_IN |
  35456. + USB_TYPE_CLASS | USB_RECIP_INTERFACE))
  35457. + break;
  35458. + if (w_index != 0 || w_value != 0 || w_length != 1) {
  35459. + value = -EDOM;
  35460. + break;
  35461. + }
  35462. + VDBG(fsg, "get max LUN\n");
  35463. + *(u8 *) req->buf = fsg->nluns - 1;
  35464. + value = 1;
  35465. + break;
  35466. + }
  35467. + }
  35468. +
  35469. + /* Handle CBI class-specific requests */
  35470. + else {
  35471. + switch (ctrl->bRequest) {
  35472. +
  35473. + case USB_CBI_ADSC_REQUEST:
  35474. + if (ctrl->bRequestType != (USB_DIR_OUT |
  35475. + USB_TYPE_CLASS | USB_RECIP_INTERFACE))
  35476. + break;
  35477. + if (w_index != 0 || w_value != 0) {
  35478. + value = -EDOM;
  35479. + break;
  35480. + }
  35481. + if (w_length > MAX_COMMAND_SIZE) {
  35482. + value = -EOVERFLOW;
  35483. + break;
  35484. + }
  35485. + value = w_length;
  35486. + fsg->ep0req->context = received_cbi_adsc;
  35487. + break;
  35488. + }
  35489. + }
  35490. +
  35491. + if (value == -EOPNOTSUPP)
  35492. + VDBG(fsg,
  35493. + "unknown class-specific control req "
  35494. + "%02x.%02x v%04x i%04x l%u\n",
  35495. + ctrl->bRequestType, ctrl->bRequest,
  35496. + le16_to_cpu(ctrl->wValue), w_index, w_length);
  35497. + return value;
  35498. +}
  35499. +
  35500. +
  35501. +/*-------------------------------------------------------------------------*/
  35502. +
  35503. +/* Ep0 standard request handlers. These always run in_irq. */
  35504. +
  35505. +static int standard_setup_req(struct fsg_dev *fsg,
  35506. + const struct usb_ctrlrequest *ctrl)
  35507. +{
  35508. + struct usb_request *req = fsg->ep0req;
  35509. + int value = -EOPNOTSUPP;
  35510. + u16 w_index = le16_to_cpu(ctrl->wIndex);
  35511. + u16 w_value = le16_to_cpu(ctrl->wValue);
  35512. +
  35513. + /* Usually this just stores reply data in the pre-allocated ep0 buffer,
  35514. + * but config change events will also reconfigure hardware. */
  35515. + switch (ctrl->bRequest) {
  35516. +
  35517. + case USB_REQ_GET_DESCRIPTOR:
  35518. + if (ctrl->bRequestType != (USB_DIR_IN | USB_TYPE_STANDARD |
  35519. + USB_RECIP_DEVICE))
  35520. + break;
  35521. + switch (w_value >> 8) {
  35522. +
  35523. + case USB_DT_DEVICE:
  35524. + VDBG(fsg, "get device descriptor\n");
  35525. + device_desc.bMaxPacketSize0 = fsg->ep0->maxpacket;
  35526. + value = sizeof device_desc;
  35527. + memcpy(req->buf, &device_desc, value);
  35528. + break;
  35529. + case USB_DT_DEVICE_QUALIFIER:
  35530. + VDBG(fsg, "get device qualifier\n");
  35531. + if (!gadget_is_dualspeed(fsg->gadget) ||
  35532. + fsg->gadget->speed == USB_SPEED_SUPER)
  35533. + break;
  35534. + /*
  35535. + * Assume ep0 uses the same maxpacket value for both
  35536. + * speeds
  35537. + */
  35538. + dev_qualifier.bMaxPacketSize0 = fsg->ep0->maxpacket;
  35539. + value = sizeof dev_qualifier;
  35540. + memcpy(req->buf, &dev_qualifier, value);
  35541. + break;
  35542. +
  35543. + case USB_DT_OTHER_SPEED_CONFIG:
  35544. + VDBG(fsg, "get other-speed config descriptor\n");
  35545. + if (!gadget_is_dualspeed(fsg->gadget) ||
  35546. + fsg->gadget->speed == USB_SPEED_SUPER)
  35547. + break;
  35548. + goto get_config;
  35549. + case USB_DT_CONFIG:
  35550. + VDBG(fsg, "get configuration descriptor\n");
  35551. +get_config:
  35552. + value = populate_config_buf(fsg->gadget,
  35553. + req->buf,
  35554. + w_value >> 8,
  35555. + w_value & 0xff);
  35556. + break;
  35557. +
  35558. + case USB_DT_STRING:
  35559. + VDBG(fsg, "get string descriptor\n");
  35560. +
  35561. + /* wIndex == language code */
  35562. + value = usb_gadget_get_string(&fsg_stringtab,
  35563. + w_value & 0xff, req->buf);
  35564. + break;
  35565. +
  35566. + case USB_DT_BOS:
  35567. + VDBG(fsg, "get bos descriptor\n");
  35568. +
  35569. + if (gadget_is_superspeed(fsg->gadget))
  35570. + value = populate_bos(fsg, req->buf);
  35571. + break;
  35572. + }
  35573. +
  35574. + break;
  35575. +
  35576. + /* One config, two speeds */
  35577. + case USB_REQ_SET_CONFIGURATION:
  35578. + if (ctrl->bRequestType != (USB_DIR_OUT | USB_TYPE_STANDARD |
  35579. + USB_RECIP_DEVICE))
  35580. + break;
  35581. + VDBG(fsg, "set configuration\n");
  35582. + if (w_value == CONFIG_VALUE || w_value == 0) {
  35583. + fsg->new_config = w_value;
  35584. +
  35585. + /* Raise an exception to wipe out previous transaction
  35586. + * state (queued bufs, etc) and set the new config. */
  35587. + raise_exception(fsg, FSG_STATE_CONFIG_CHANGE);
  35588. + value = DELAYED_STATUS;
  35589. + }
  35590. + break;
  35591. + case USB_REQ_GET_CONFIGURATION:
  35592. + if (ctrl->bRequestType != (USB_DIR_IN | USB_TYPE_STANDARD |
  35593. + USB_RECIP_DEVICE))
  35594. + break;
  35595. + VDBG(fsg, "get configuration\n");
  35596. + *(u8 *) req->buf = fsg->config;
  35597. + value = 1;
  35598. + break;
  35599. +
  35600. + case USB_REQ_SET_INTERFACE:
  35601. + if (ctrl->bRequestType != (USB_DIR_OUT| USB_TYPE_STANDARD |
  35602. + USB_RECIP_INTERFACE))
  35603. + break;
  35604. + if (fsg->config && w_index == 0) {
  35605. +
  35606. + /* Raise an exception to wipe out previous transaction
  35607. + * state (queued bufs, etc) and install the new
  35608. + * interface altsetting. */
  35609. + raise_exception(fsg, FSG_STATE_INTERFACE_CHANGE);
  35610. + value = DELAYED_STATUS;
  35611. + }
  35612. + break;
  35613. + case USB_REQ_GET_INTERFACE:
  35614. + if (ctrl->bRequestType != (USB_DIR_IN | USB_TYPE_STANDARD |
  35615. + USB_RECIP_INTERFACE))
  35616. + break;
  35617. + if (!fsg->config)
  35618. + break;
  35619. + if (w_index != 0) {
  35620. + value = -EDOM;
  35621. + break;
  35622. + }
  35623. + VDBG(fsg, "get interface\n");
  35624. + *(u8 *) req->buf = 0;
  35625. + value = 1;
  35626. + break;
  35627. +
  35628. + default:
  35629. + VDBG(fsg,
  35630. + "unknown control req %02x.%02x v%04x i%04x l%u\n",
  35631. + ctrl->bRequestType, ctrl->bRequest,
  35632. + w_value, w_index, le16_to_cpu(ctrl->wLength));
  35633. + }
  35634. +
  35635. + return value;
  35636. +}
  35637. +
  35638. +
  35639. +static int fsg_setup(struct usb_gadget *gadget,
  35640. + const struct usb_ctrlrequest *ctrl)
  35641. +{
  35642. + struct fsg_dev *fsg = get_gadget_data(gadget);
  35643. + int rc;
  35644. + int w_length = le16_to_cpu(ctrl->wLength);
  35645. +
  35646. + ++fsg->ep0_req_tag; // Record arrival of a new request
  35647. + fsg->ep0req->context = NULL;
  35648. + fsg->ep0req->length = 0;
  35649. + dump_msg(fsg, "ep0-setup", (u8 *) ctrl, sizeof(*ctrl));
  35650. +
  35651. + if ((ctrl->bRequestType & USB_TYPE_MASK) == USB_TYPE_CLASS)
  35652. + rc = class_setup_req(fsg, ctrl);
  35653. + else
  35654. + rc = standard_setup_req(fsg, ctrl);
  35655. +
  35656. + /* Respond with data/status or defer until later? */
  35657. + if (rc >= 0 && rc != DELAYED_STATUS) {
  35658. + rc = min(rc, w_length);
  35659. + fsg->ep0req->length = rc;
  35660. + fsg->ep0req->zero = rc < w_length;
  35661. + fsg->ep0req_name = (ctrl->bRequestType & USB_DIR_IN ?
  35662. + "ep0-in" : "ep0-out");
  35663. + rc = ep0_queue(fsg);
  35664. + }
  35665. +
  35666. + /* Device either stalls (rc < 0) or reports success */
  35667. + return rc;
  35668. +}
  35669. +
  35670. +
  35671. +/*-------------------------------------------------------------------------*/
  35672. +
  35673. +/* All the following routines run in process context */
  35674. +
  35675. +
  35676. +/* Use this for bulk or interrupt transfers, not ep0 */
  35677. +static void start_transfer(struct fsg_dev *fsg, struct usb_ep *ep,
  35678. + struct usb_request *req, int *pbusy,
  35679. + enum fsg_buffer_state *state)
  35680. +{
  35681. + int rc;
  35682. +
  35683. + if (ep == fsg->bulk_in)
  35684. + dump_msg(fsg, "bulk-in", req->buf, req->length);
  35685. + else if (ep == fsg->intr_in)
  35686. + dump_msg(fsg, "intr-in", req->buf, req->length);
  35687. +
  35688. + spin_lock_irq(&fsg->lock);
  35689. + *pbusy = 1;
  35690. + *state = BUF_STATE_BUSY;
  35691. + spin_unlock_irq(&fsg->lock);
  35692. + rc = usb_ep_queue(ep, req, GFP_KERNEL);
  35693. + if (rc != 0) {
  35694. + *pbusy = 0;
  35695. + *state = BUF_STATE_EMPTY;
  35696. +
  35697. + /* We can't do much more than wait for a reset */
  35698. +
  35699. + /* Note: currently the net2280 driver fails zero-length
  35700. + * submissions if DMA is enabled. */
  35701. + if (rc != -ESHUTDOWN && !(rc == -EOPNOTSUPP &&
  35702. + req->length == 0))
  35703. + WARNING(fsg, "error in submission: %s --> %d\n",
  35704. + ep->name, rc);
  35705. + }
  35706. +}
  35707. +
  35708. +
  35709. +static int sleep_thread(struct fsg_dev *fsg)
  35710. +{
  35711. + int rc = 0;
  35712. +
  35713. + /* Wait until a signal arrives or we are woken up */
  35714. + for (;;) {
  35715. + try_to_freeze();
  35716. + set_current_state(TASK_INTERRUPTIBLE);
  35717. + if (signal_pending(current)) {
  35718. + rc = -EINTR;
  35719. + break;
  35720. + }
  35721. + if (fsg->thread_wakeup_needed)
  35722. + break;
  35723. + schedule();
  35724. + }
  35725. + __set_current_state(TASK_RUNNING);
  35726. + fsg->thread_wakeup_needed = 0;
  35727. + return rc;
  35728. +}
  35729. +
  35730. +
  35731. +/*-------------------------------------------------------------------------*/
  35732. +
  35733. +static int do_read(struct fsg_dev *fsg)
  35734. +{
  35735. + struct fsg_lun *curlun = fsg->curlun;
  35736. + u32 lba;
  35737. + struct fsg_buffhd *bh;
  35738. + int rc;
  35739. + u32 amount_left;
  35740. + loff_t file_offset, file_offset_tmp;
  35741. + unsigned int amount;
  35742. + ssize_t nread;
  35743. +
  35744. + /* Get the starting Logical Block Address and check that it's
  35745. + * not too big */
  35746. + if (fsg->cmnd[0] == READ_6)
  35747. + lba = get_unaligned_be24(&fsg->cmnd[1]);
  35748. + else {
  35749. + lba = get_unaligned_be32(&fsg->cmnd[2]);
  35750. +
  35751. + /* We allow DPO (Disable Page Out = don't save data in the
  35752. + * cache) and FUA (Force Unit Access = don't read from the
  35753. + * cache), but we don't implement them. */
  35754. + if ((fsg->cmnd[1] & ~0x18) != 0) {
  35755. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  35756. + return -EINVAL;
  35757. + }
  35758. + }
  35759. + if (lba >= curlun->num_sectors) {
  35760. + curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  35761. + return -EINVAL;
  35762. + }
  35763. + file_offset = ((loff_t) lba) << curlun->blkbits;
  35764. +
  35765. + /* Carry out the file reads */
  35766. + amount_left = fsg->data_size_from_cmnd;
  35767. + if (unlikely(amount_left == 0))
  35768. + return -EIO; // No default reply
  35769. +
  35770. + for (;;) {
  35771. +
  35772. + /* Figure out how much we need to read:
  35773. + * Try to read the remaining amount.
  35774. + * But don't read more than the buffer size.
  35775. + * And don't try to read past the end of the file.
  35776. + */
  35777. + amount = min((unsigned int) amount_left, mod_data.buflen);
  35778. + amount = min((loff_t) amount,
  35779. + curlun->file_length - file_offset);
  35780. +
  35781. + /* Wait for the next buffer to become available */
  35782. + bh = fsg->next_buffhd_to_fill;
  35783. + while (bh->state != BUF_STATE_EMPTY) {
  35784. + rc = sleep_thread(fsg);
  35785. + if (rc)
  35786. + return rc;
  35787. + }
  35788. +
  35789. + /* If we were asked to read past the end of file,
  35790. + * end with an empty buffer. */
  35791. + if (amount == 0) {
  35792. + curlun->sense_data =
  35793. + SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  35794. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  35795. + curlun->info_valid = 1;
  35796. + bh->inreq->length = 0;
  35797. + bh->state = BUF_STATE_FULL;
  35798. + break;
  35799. + }
  35800. +
  35801. + /* Perform the read */
  35802. + file_offset_tmp = file_offset;
  35803. + nread = vfs_read(curlun->filp,
  35804. + (char __user *) bh->buf,
  35805. + amount, &file_offset_tmp);
  35806. + VLDBG(curlun, "file read %u @ %llu -> %d\n", amount,
  35807. + (unsigned long long) file_offset,
  35808. + (int) nread);
  35809. + if (signal_pending(current))
  35810. + return -EINTR;
  35811. +
  35812. + if (nread < 0) {
  35813. + LDBG(curlun, "error in file read: %d\n",
  35814. + (int) nread);
  35815. + nread = 0;
  35816. + } else if (nread < amount) {
  35817. + LDBG(curlun, "partial file read: %d/%u\n",
  35818. + (int) nread, amount);
  35819. + nread = round_down(nread, curlun->blksize);
  35820. + }
  35821. + file_offset += nread;
  35822. + amount_left -= nread;
  35823. + fsg->residue -= nread;
  35824. +
  35825. + /* Except at the end of the transfer, nread will be
  35826. + * equal to the buffer size, which is divisible by the
  35827. + * bulk-in maxpacket size.
  35828. + */
  35829. + bh->inreq->length = nread;
  35830. + bh->state = BUF_STATE_FULL;
  35831. +
  35832. + /* If an error occurred, report it and its position */
  35833. + if (nread < amount) {
  35834. + curlun->sense_data = SS_UNRECOVERED_READ_ERROR;
  35835. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  35836. + curlun->info_valid = 1;
  35837. + break;
  35838. + }
  35839. +
  35840. + if (amount_left == 0)
  35841. + break; // No more left to read
  35842. +
  35843. + /* Send this buffer and go read some more */
  35844. + bh->inreq->zero = 0;
  35845. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  35846. + &bh->inreq_busy, &bh->state);
  35847. + fsg->next_buffhd_to_fill = bh->next;
  35848. + }
  35849. +
  35850. + return -EIO; // No default reply
  35851. +}
  35852. +
  35853. +
  35854. +/*-------------------------------------------------------------------------*/
  35855. +
  35856. +static int do_write(struct fsg_dev *fsg)
  35857. +{
  35858. + struct fsg_lun *curlun = fsg->curlun;
  35859. + u32 lba;
  35860. + struct fsg_buffhd *bh;
  35861. + int get_some_more;
  35862. + u32 amount_left_to_req, amount_left_to_write;
  35863. + loff_t usb_offset, file_offset, file_offset_tmp;
  35864. + unsigned int amount;
  35865. + ssize_t nwritten;
  35866. + int rc;
  35867. +
  35868. + if (curlun->ro) {
  35869. + curlun->sense_data = SS_WRITE_PROTECTED;
  35870. + return -EINVAL;
  35871. + }
  35872. + spin_lock(&curlun->filp->f_lock);
  35873. + curlun->filp->f_flags &= ~O_SYNC; // Default is not to wait
  35874. + spin_unlock(&curlun->filp->f_lock);
  35875. +
  35876. + /* Get the starting Logical Block Address and check that it's
  35877. + * not too big */
  35878. + if (fsg->cmnd[0] == WRITE_6)
  35879. + lba = get_unaligned_be24(&fsg->cmnd[1]);
  35880. + else {
  35881. + lba = get_unaligned_be32(&fsg->cmnd[2]);
  35882. +
  35883. + /* We allow DPO (Disable Page Out = don't save data in the
  35884. + * cache) and FUA (Force Unit Access = write directly to the
  35885. + * medium). We don't implement DPO; we implement FUA by
  35886. + * performing synchronous output. */
  35887. + if ((fsg->cmnd[1] & ~0x18) != 0) {
  35888. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  35889. + return -EINVAL;
  35890. + }
  35891. + /* FUA */
  35892. + if (!curlun->nofua && (fsg->cmnd[1] & 0x08)) {
  35893. + spin_lock(&curlun->filp->f_lock);
  35894. + curlun->filp->f_flags |= O_DSYNC;
  35895. + spin_unlock(&curlun->filp->f_lock);
  35896. + }
  35897. + }
  35898. + if (lba >= curlun->num_sectors) {
  35899. + curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  35900. + return -EINVAL;
  35901. + }
  35902. +
  35903. + /* Carry out the file writes */
  35904. + get_some_more = 1;
  35905. + file_offset = usb_offset = ((loff_t) lba) << curlun->blkbits;
  35906. + amount_left_to_req = amount_left_to_write = fsg->data_size_from_cmnd;
  35907. +
  35908. + while (amount_left_to_write > 0) {
  35909. +
  35910. + /* Queue a request for more data from the host */
  35911. + bh = fsg->next_buffhd_to_fill;
  35912. + if (bh->state == BUF_STATE_EMPTY && get_some_more) {
  35913. +
  35914. + /* Figure out how much we want to get:
  35915. + * Try to get the remaining amount,
  35916. + * but not more than the buffer size.
  35917. + */
  35918. + amount = min(amount_left_to_req, mod_data.buflen);
  35919. +
  35920. + /* Beyond the end of the backing file? */
  35921. + if (usb_offset >= curlun->file_length) {
  35922. + get_some_more = 0;
  35923. + curlun->sense_data =
  35924. + SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  35925. + curlun->sense_data_info = usb_offset >> curlun->blkbits;
  35926. + curlun->info_valid = 1;
  35927. + continue;
  35928. + }
  35929. +
  35930. + /* Get the next buffer */
  35931. + usb_offset += amount;
  35932. + fsg->usb_amount_left -= amount;
  35933. + amount_left_to_req -= amount;
  35934. + if (amount_left_to_req == 0)
  35935. + get_some_more = 0;
  35936. +
  35937. + /* Except at the end of the transfer, amount will be
  35938. + * equal to the buffer size, which is divisible by
  35939. + * the bulk-out maxpacket size.
  35940. + */
  35941. + set_bulk_out_req_length(fsg, bh, amount);
  35942. + start_transfer(fsg, fsg->bulk_out, bh->outreq,
  35943. + &bh->outreq_busy, &bh->state);
  35944. + fsg->next_buffhd_to_fill = bh->next;
  35945. + continue;
  35946. + }
  35947. +
  35948. + /* Write the received data to the backing file */
  35949. + bh = fsg->next_buffhd_to_drain;
  35950. + if (bh->state == BUF_STATE_EMPTY && !get_some_more)
  35951. + break; // We stopped early
  35952. + if (bh->state == BUF_STATE_FULL) {
  35953. + smp_rmb();
  35954. + fsg->next_buffhd_to_drain = bh->next;
  35955. + bh->state = BUF_STATE_EMPTY;
  35956. +
  35957. + /* Did something go wrong with the transfer? */
  35958. + if (bh->outreq->status != 0) {
  35959. + curlun->sense_data = SS_COMMUNICATION_FAILURE;
  35960. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  35961. + curlun->info_valid = 1;
  35962. + break;
  35963. + }
  35964. +
  35965. + amount = bh->outreq->actual;
  35966. + if (curlun->file_length - file_offset < amount) {
  35967. + LERROR(curlun,
  35968. + "write %u @ %llu beyond end %llu\n",
  35969. + amount, (unsigned long long) file_offset,
  35970. + (unsigned long long) curlun->file_length);
  35971. + amount = curlun->file_length - file_offset;
  35972. + }
  35973. +
  35974. + /* Don't accept excess data. The spec doesn't say
  35975. + * what to do in this case. We'll ignore the error.
  35976. + */
  35977. + amount = min(amount, bh->bulk_out_intended_length);
  35978. +
  35979. + /* Don't write a partial block */
  35980. + amount = round_down(amount, curlun->blksize);
  35981. + if (amount == 0)
  35982. + goto empty_write;
  35983. +
  35984. + /* Perform the write */
  35985. + file_offset_tmp = file_offset;
  35986. + nwritten = vfs_write(curlun->filp,
  35987. + (char __user *) bh->buf,
  35988. + amount, &file_offset_tmp);
  35989. + VLDBG(curlun, "file write %u @ %llu -> %d\n", amount,
  35990. + (unsigned long long) file_offset,
  35991. + (int) nwritten);
  35992. + if (signal_pending(current))
  35993. + return -EINTR; // Interrupted!
  35994. +
  35995. + if (nwritten < 0) {
  35996. + LDBG(curlun, "error in file write: %d\n",
  35997. + (int) nwritten);
  35998. + nwritten = 0;
  35999. + } else if (nwritten < amount) {
  36000. + LDBG(curlun, "partial file write: %d/%u\n",
  36001. + (int) nwritten, amount);
  36002. + nwritten = round_down(nwritten, curlun->blksize);
  36003. + }
  36004. + file_offset += nwritten;
  36005. + amount_left_to_write -= nwritten;
  36006. + fsg->residue -= nwritten;
  36007. +
  36008. + /* If an error occurred, report it and its position */
  36009. + if (nwritten < amount) {
  36010. + curlun->sense_data = SS_WRITE_ERROR;
  36011. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  36012. + curlun->info_valid = 1;
  36013. + break;
  36014. + }
  36015. +
  36016. + empty_write:
  36017. + /* Did the host decide to stop early? */
  36018. + if (bh->outreq->actual < bh->bulk_out_intended_length) {
  36019. + fsg->short_packet_received = 1;
  36020. + break;
  36021. + }
  36022. + continue;
  36023. + }
  36024. +
  36025. + /* Wait for something to happen */
  36026. + rc = sleep_thread(fsg);
  36027. + if (rc)
  36028. + return rc;
  36029. + }
  36030. +
  36031. + return -EIO; // No default reply
  36032. +}
  36033. +
  36034. +
  36035. +/*-------------------------------------------------------------------------*/
  36036. +
  36037. +static int do_synchronize_cache(struct fsg_dev *fsg)
  36038. +{
  36039. + struct fsg_lun *curlun = fsg->curlun;
  36040. + int rc;
  36041. +
  36042. + /* We ignore the requested LBA and write out all file's
  36043. + * dirty data buffers. */
  36044. + rc = fsg_lun_fsync_sub(curlun);
  36045. + if (rc)
  36046. + curlun->sense_data = SS_WRITE_ERROR;
  36047. + return 0;
  36048. +}
  36049. +
  36050. +
  36051. +/*-------------------------------------------------------------------------*/
  36052. +
  36053. +static void invalidate_sub(struct fsg_lun *curlun)
  36054. +{
  36055. + struct file *filp = curlun->filp;
  36056. + struct inode *inode = filp->f_path.dentry->d_inode;
  36057. + unsigned long rc;
  36058. +
  36059. + rc = invalidate_mapping_pages(inode->i_mapping, 0, -1);
  36060. + VLDBG(curlun, "invalidate_mapping_pages -> %ld\n", rc);
  36061. +}
  36062. +
  36063. +static int do_verify(struct fsg_dev *fsg)
  36064. +{
  36065. + struct fsg_lun *curlun = fsg->curlun;
  36066. + u32 lba;
  36067. + u32 verification_length;
  36068. + struct fsg_buffhd *bh = fsg->next_buffhd_to_fill;
  36069. + loff_t file_offset, file_offset_tmp;
  36070. + u32 amount_left;
  36071. + unsigned int amount;
  36072. + ssize_t nread;
  36073. +
  36074. + /* Get the starting Logical Block Address and check that it's
  36075. + * not too big */
  36076. + lba = get_unaligned_be32(&fsg->cmnd[2]);
  36077. + if (lba >= curlun->num_sectors) {
  36078. + curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  36079. + return -EINVAL;
  36080. + }
  36081. +
  36082. + /* We allow DPO (Disable Page Out = don't save data in the
  36083. + * cache) but we don't implement it. */
  36084. + if ((fsg->cmnd[1] & ~0x10) != 0) {
  36085. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  36086. + return -EINVAL;
  36087. + }
  36088. +
  36089. + verification_length = get_unaligned_be16(&fsg->cmnd[7]);
  36090. + if (unlikely(verification_length == 0))
  36091. + return -EIO; // No default reply
  36092. +
  36093. + /* Prepare to carry out the file verify */
  36094. + amount_left = verification_length << curlun->blkbits;
  36095. + file_offset = ((loff_t) lba) << curlun->blkbits;
  36096. +
  36097. + /* Write out all the dirty buffers before invalidating them */
  36098. + fsg_lun_fsync_sub(curlun);
  36099. + if (signal_pending(current))
  36100. + return -EINTR;
  36101. +
  36102. + invalidate_sub(curlun);
  36103. + if (signal_pending(current))
  36104. + return -EINTR;
  36105. +
  36106. + /* Just try to read the requested blocks */
  36107. + while (amount_left > 0) {
  36108. +
  36109. + /* Figure out how much we need to read:
  36110. + * Try to read the remaining amount, but not more than
  36111. + * the buffer size.
  36112. + * And don't try to read past the end of the file.
  36113. + */
  36114. + amount = min((unsigned int) amount_left, mod_data.buflen);
  36115. + amount = min((loff_t) amount,
  36116. + curlun->file_length - file_offset);
  36117. + if (amount == 0) {
  36118. + curlun->sense_data =
  36119. + SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  36120. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  36121. + curlun->info_valid = 1;
  36122. + break;
  36123. + }
  36124. +
  36125. + /* Perform the read */
  36126. + file_offset_tmp = file_offset;
  36127. + nread = vfs_read(curlun->filp,
  36128. + (char __user *) bh->buf,
  36129. + amount, &file_offset_tmp);
  36130. + VLDBG(curlun, "file read %u @ %llu -> %d\n", amount,
  36131. + (unsigned long long) file_offset,
  36132. + (int) nread);
  36133. + if (signal_pending(current))
  36134. + return -EINTR;
  36135. +
  36136. + if (nread < 0) {
  36137. + LDBG(curlun, "error in file verify: %d\n",
  36138. + (int) nread);
  36139. + nread = 0;
  36140. + } else if (nread < amount) {
  36141. + LDBG(curlun, "partial file verify: %d/%u\n",
  36142. + (int) nread, amount);
  36143. + nread = round_down(nread, curlun->blksize);
  36144. + }
  36145. + if (nread == 0) {
  36146. + curlun->sense_data = SS_UNRECOVERED_READ_ERROR;
  36147. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  36148. + curlun->info_valid = 1;
  36149. + break;
  36150. + }
  36151. + file_offset += nread;
  36152. + amount_left -= nread;
  36153. + }
  36154. + return 0;
  36155. +}
  36156. +
  36157. +
  36158. +/*-------------------------------------------------------------------------*/
  36159. +
  36160. +static int do_inquiry(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  36161. +{
  36162. + u8 *buf = (u8 *) bh->buf;
  36163. +
  36164. + static char vendor_id[] = "Linux ";
  36165. + static char product_disk_id[] = "File-Stor Gadget";
  36166. + static char product_cdrom_id[] = "File-CD Gadget ";
  36167. +
  36168. + if (!fsg->curlun) { // Unsupported LUNs are okay
  36169. + fsg->bad_lun_okay = 1;
  36170. + memset(buf, 0, 36);
  36171. + buf[0] = 0x7f; // Unsupported, no device-type
  36172. + buf[4] = 31; // Additional length
  36173. + return 36;
  36174. + }
  36175. +
  36176. + memset(buf, 0, 8);
  36177. + buf[0] = (mod_data.cdrom ? TYPE_ROM : TYPE_DISK);
  36178. + if (mod_data.removable)
  36179. + buf[1] = 0x80;
  36180. + buf[2] = 2; // ANSI SCSI level 2
  36181. + buf[3] = 2; // SCSI-2 INQUIRY data format
  36182. + buf[4] = 31; // Additional length
  36183. + // No special options
  36184. + sprintf(buf + 8, "%-8s%-16s%04x", vendor_id,
  36185. + (mod_data.cdrom ? product_cdrom_id :
  36186. + product_disk_id),
  36187. + mod_data.release);
  36188. + return 36;
  36189. +}
  36190. +
  36191. +
  36192. +static int do_request_sense(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  36193. +{
  36194. + struct fsg_lun *curlun = fsg->curlun;
  36195. + u8 *buf = (u8 *) bh->buf;
  36196. + u32 sd, sdinfo;
  36197. + int valid;
  36198. +
  36199. + /*
  36200. + * From the SCSI-2 spec., section 7.9 (Unit attention condition):
  36201. + *
  36202. + * If a REQUEST SENSE command is received from an initiator
  36203. + * with a pending unit attention condition (before the target
  36204. + * generates the contingent allegiance condition), then the
  36205. + * target shall either:
  36206. + * a) report any pending sense data and preserve the unit
  36207. + * attention condition on the logical unit, or,
  36208. + * b) report the unit attention condition, may discard any
  36209. + * pending sense data, and clear the unit attention
  36210. + * condition on the logical unit for that initiator.
  36211. + *
  36212. + * FSG normally uses option a); enable this code to use option b).
  36213. + */
  36214. +#if 0
  36215. + if (curlun && curlun->unit_attention_data != SS_NO_SENSE) {
  36216. + curlun->sense_data = curlun->unit_attention_data;
  36217. + curlun->unit_attention_data = SS_NO_SENSE;
  36218. + }
  36219. +#endif
  36220. +
  36221. + if (!curlun) { // Unsupported LUNs are okay
  36222. + fsg->bad_lun_okay = 1;
  36223. + sd = SS_LOGICAL_UNIT_NOT_SUPPORTED;
  36224. + sdinfo = 0;
  36225. + valid = 0;
  36226. + } else {
  36227. + sd = curlun->sense_data;
  36228. + sdinfo = curlun->sense_data_info;
  36229. + valid = curlun->info_valid << 7;
  36230. + curlun->sense_data = SS_NO_SENSE;
  36231. + curlun->sense_data_info = 0;
  36232. + curlun->info_valid = 0;
  36233. + }
  36234. +
  36235. + memset(buf, 0, 18);
  36236. + buf[0] = valid | 0x70; // Valid, current error
  36237. + buf[2] = SK(sd);
  36238. + put_unaligned_be32(sdinfo, &buf[3]); /* Sense information */
  36239. + buf[7] = 18 - 8; // Additional sense length
  36240. + buf[12] = ASC(sd);
  36241. + buf[13] = ASCQ(sd);
  36242. + return 18;
  36243. +}
  36244. +
  36245. +
  36246. +static int do_read_capacity(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  36247. +{
  36248. + struct fsg_lun *curlun = fsg->curlun;
  36249. + u32 lba = get_unaligned_be32(&fsg->cmnd[2]);
  36250. + int pmi = fsg->cmnd[8];
  36251. + u8 *buf = (u8 *) bh->buf;
  36252. +
  36253. + /* Check the PMI and LBA fields */
  36254. + if (pmi > 1 || (pmi == 0 && lba != 0)) {
  36255. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  36256. + return -EINVAL;
  36257. + }
  36258. +
  36259. + put_unaligned_be32(curlun->num_sectors - 1, &buf[0]);
  36260. + /* Max logical block */
  36261. + put_unaligned_be32(curlun->blksize, &buf[4]); /* Block length */
  36262. + return 8;
  36263. +}
  36264. +
  36265. +
  36266. +static int do_read_header(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  36267. +{
  36268. + struct fsg_lun *curlun = fsg->curlun;
  36269. + int msf = fsg->cmnd[1] & 0x02;
  36270. + u32 lba = get_unaligned_be32(&fsg->cmnd[2]);
  36271. + u8 *buf = (u8 *) bh->buf;
  36272. +
  36273. + if ((fsg->cmnd[1] & ~0x02) != 0) { /* Mask away MSF */
  36274. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  36275. + return -EINVAL;
  36276. + }
  36277. + if (lba >= curlun->num_sectors) {
  36278. + curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  36279. + return -EINVAL;
  36280. + }
  36281. +
  36282. + memset(buf, 0, 8);
  36283. + buf[0] = 0x01; /* 2048 bytes of user data, rest is EC */
  36284. + store_cdrom_address(&buf[4], msf, lba);
  36285. + return 8;
  36286. +}
  36287. +
  36288. +
  36289. +static int do_read_toc(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  36290. +{
  36291. + struct fsg_lun *curlun = fsg->curlun;
  36292. + int msf = fsg->cmnd[1] & 0x02;
  36293. + int start_track = fsg->cmnd[6];
  36294. + u8 *buf = (u8 *) bh->buf;
  36295. +
  36296. + if ((fsg->cmnd[1] & ~0x02) != 0 || /* Mask away MSF */
  36297. + start_track > 1) {
  36298. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  36299. + return -EINVAL;
  36300. + }
  36301. +
  36302. + memset(buf, 0, 20);
  36303. + buf[1] = (20-2); /* TOC data length */
  36304. + buf[2] = 1; /* First track number */
  36305. + buf[3] = 1; /* Last track number */
  36306. + buf[5] = 0x16; /* Data track, copying allowed */
  36307. + buf[6] = 0x01; /* Only track is number 1 */
  36308. + store_cdrom_address(&buf[8], msf, 0);
  36309. +
  36310. + buf[13] = 0x16; /* Lead-out track is data */
  36311. + buf[14] = 0xAA; /* Lead-out track number */
  36312. + store_cdrom_address(&buf[16], msf, curlun->num_sectors);
  36313. + return 20;
  36314. +}
  36315. +
  36316. +
  36317. +static int do_mode_sense(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  36318. +{
  36319. + struct fsg_lun *curlun = fsg->curlun;
  36320. + int mscmnd = fsg->cmnd[0];
  36321. + u8 *buf = (u8 *) bh->buf;
  36322. + u8 *buf0 = buf;
  36323. + int pc, page_code;
  36324. + int changeable_values, all_pages;
  36325. + int valid_page = 0;
  36326. + int len, limit;
  36327. +
  36328. + if ((fsg->cmnd[1] & ~0x08) != 0) { // Mask away DBD
  36329. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  36330. + return -EINVAL;
  36331. + }
  36332. + pc = fsg->cmnd[2] >> 6;
  36333. + page_code = fsg->cmnd[2] & 0x3f;
  36334. + if (pc == 3) {
  36335. + curlun->sense_data = SS_SAVING_PARAMETERS_NOT_SUPPORTED;
  36336. + return -EINVAL;
  36337. + }
  36338. + changeable_values = (pc == 1);
  36339. + all_pages = (page_code == 0x3f);
  36340. +
  36341. + /* Write the mode parameter header. Fixed values are: default
  36342. + * medium type, no cache control (DPOFUA), and no block descriptors.
  36343. + * The only variable value is the WriteProtect bit. We will fill in
  36344. + * the mode data length later. */
  36345. + memset(buf, 0, 8);
  36346. + if (mscmnd == MODE_SENSE) {
  36347. + buf[2] = (curlun->ro ? 0x80 : 0x00); // WP, DPOFUA
  36348. + buf += 4;
  36349. + limit = 255;
  36350. + } else { // MODE_SENSE_10
  36351. + buf[3] = (curlun->ro ? 0x80 : 0x00); // WP, DPOFUA
  36352. + buf += 8;
  36353. + limit = 65535; // Should really be mod_data.buflen
  36354. + }
  36355. +
  36356. + /* No block descriptors */
  36357. +
  36358. + /* The mode pages, in numerical order. The only page we support
  36359. + * is the Caching page. */
  36360. + if (page_code == 0x08 || all_pages) {
  36361. + valid_page = 1;
  36362. + buf[0] = 0x08; // Page code
  36363. + buf[1] = 10; // Page length
  36364. + memset(buf+2, 0, 10); // None of the fields are changeable
  36365. +
  36366. + if (!changeable_values) {
  36367. + buf[2] = 0x04; // Write cache enable,
  36368. + // Read cache not disabled
  36369. + // No cache retention priorities
  36370. + put_unaligned_be16(0xffff, &buf[4]);
  36371. + /* Don't disable prefetch */
  36372. + /* Minimum prefetch = 0 */
  36373. + put_unaligned_be16(0xffff, &buf[8]);
  36374. + /* Maximum prefetch */
  36375. + put_unaligned_be16(0xffff, &buf[10]);
  36376. + /* Maximum prefetch ceiling */
  36377. + }
  36378. + buf += 12;
  36379. + }
  36380. +
  36381. + /* Check that a valid page was requested and the mode data length
  36382. + * isn't too long. */
  36383. + len = buf - buf0;
  36384. + if (!valid_page || len > limit) {
  36385. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  36386. + return -EINVAL;
  36387. + }
  36388. +
  36389. + /* Store the mode data length */
  36390. + if (mscmnd == MODE_SENSE)
  36391. + buf0[0] = len - 1;
  36392. + else
  36393. + put_unaligned_be16(len - 2, buf0);
  36394. + return len;
  36395. +}
  36396. +
  36397. +
  36398. +static int do_start_stop(struct fsg_dev *fsg)
  36399. +{
  36400. + struct fsg_lun *curlun = fsg->curlun;
  36401. + int loej, start;
  36402. +
  36403. + if (!mod_data.removable) {
  36404. + curlun->sense_data = SS_INVALID_COMMAND;
  36405. + return -EINVAL;
  36406. + }
  36407. +
  36408. + // int immed = fsg->cmnd[1] & 0x01;
  36409. + loej = fsg->cmnd[4] & 0x02;
  36410. + start = fsg->cmnd[4] & 0x01;
  36411. +
  36412. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  36413. + if ((fsg->cmnd[1] & ~0x01) != 0 || // Mask away Immed
  36414. + (fsg->cmnd[4] & ~0x03) != 0) { // Mask LoEj, Start
  36415. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  36416. + return -EINVAL;
  36417. + }
  36418. +
  36419. + if (!start) {
  36420. +
  36421. + /* Are we allowed to unload the media? */
  36422. + if (curlun->prevent_medium_removal) {
  36423. + LDBG(curlun, "unload attempt prevented\n");
  36424. + curlun->sense_data = SS_MEDIUM_REMOVAL_PREVENTED;
  36425. + return -EINVAL;
  36426. + }
  36427. + if (loej) { // Simulate an unload/eject
  36428. + up_read(&fsg->filesem);
  36429. + down_write(&fsg->filesem);
  36430. + fsg_lun_close(curlun);
  36431. + up_write(&fsg->filesem);
  36432. + down_read(&fsg->filesem);
  36433. + }
  36434. + } else {
  36435. +
  36436. + /* Our emulation doesn't support mounting; the medium is
  36437. + * available for use as soon as it is loaded. */
  36438. + if (!fsg_lun_is_open(curlun)) {
  36439. + curlun->sense_data = SS_MEDIUM_NOT_PRESENT;
  36440. + return -EINVAL;
  36441. + }
  36442. + }
  36443. +#endif
  36444. + return 0;
  36445. +}
  36446. +
  36447. +
  36448. +static int do_prevent_allow(struct fsg_dev *fsg)
  36449. +{
  36450. + struct fsg_lun *curlun = fsg->curlun;
  36451. + int prevent;
  36452. +
  36453. + if (!mod_data.removable) {
  36454. + curlun->sense_data = SS_INVALID_COMMAND;
  36455. + return -EINVAL;
  36456. + }
  36457. +
  36458. + prevent = fsg->cmnd[4] & 0x01;
  36459. + if ((fsg->cmnd[4] & ~0x01) != 0) { // Mask away Prevent
  36460. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  36461. + return -EINVAL;
  36462. + }
  36463. +
  36464. + if (curlun->prevent_medium_removal && !prevent)
  36465. + fsg_lun_fsync_sub(curlun);
  36466. + curlun->prevent_medium_removal = prevent;
  36467. + return 0;
  36468. +}
  36469. +
  36470. +
  36471. +static int do_read_format_capacities(struct fsg_dev *fsg,
  36472. + struct fsg_buffhd *bh)
  36473. +{
  36474. + struct fsg_lun *curlun = fsg->curlun;
  36475. + u8 *buf = (u8 *) bh->buf;
  36476. +
  36477. + buf[0] = buf[1] = buf[2] = 0;
  36478. + buf[3] = 8; // Only the Current/Maximum Capacity Descriptor
  36479. + buf += 4;
  36480. +
  36481. + put_unaligned_be32(curlun->num_sectors, &buf[0]);
  36482. + /* Number of blocks */
  36483. + put_unaligned_be32(curlun->blksize, &buf[4]); /* Block length */
  36484. + buf[4] = 0x02; /* Current capacity */
  36485. + return 12;
  36486. +}
  36487. +
  36488. +
  36489. +static int do_mode_select(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  36490. +{
  36491. + struct fsg_lun *curlun = fsg->curlun;
  36492. +
  36493. + /* We don't support MODE SELECT */
  36494. + curlun->sense_data = SS_INVALID_COMMAND;
  36495. + return -EINVAL;
  36496. +}
  36497. +
  36498. +
  36499. +/*-------------------------------------------------------------------------*/
  36500. +
  36501. +static int halt_bulk_in_endpoint(struct fsg_dev *fsg)
  36502. +{
  36503. + int rc;
  36504. +
  36505. + rc = fsg_set_halt(fsg, fsg->bulk_in);
  36506. + if (rc == -EAGAIN)
  36507. + VDBG(fsg, "delayed bulk-in endpoint halt\n");
  36508. + while (rc != 0) {
  36509. + if (rc != -EAGAIN) {
  36510. + WARNING(fsg, "usb_ep_set_halt -> %d\n", rc);
  36511. + rc = 0;
  36512. + break;
  36513. + }
  36514. +
  36515. + /* Wait for a short time and then try again */
  36516. + if (msleep_interruptible(100) != 0)
  36517. + return -EINTR;
  36518. + rc = usb_ep_set_halt(fsg->bulk_in);
  36519. + }
  36520. + return rc;
  36521. +}
  36522. +
  36523. +static int wedge_bulk_in_endpoint(struct fsg_dev *fsg)
  36524. +{
  36525. + int rc;
  36526. +
  36527. + DBG(fsg, "bulk-in set wedge\n");
  36528. + rc = usb_ep_set_wedge(fsg->bulk_in);
  36529. + if (rc == -EAGAIN)
  36530. + VDBG(fsg, "delayed bulk-in endpoint wedge\n");
  36531. + while (rc != 0) {
  36532. + if (rc != -EAGAIN) {
  36533. + WARNING(fsg, "usb_ep_set_wedge -> %d\n", rc);
  36534. + rc = 0;
  36535. + break;
  36536. + }
  36537. +
  36538. + /* Wait for a short time and then try again */
  36539. + if (msleep_interruptible(100) != 0)
  36540. + return -EINTR;
  36541. + rc = usb_ep_set_wedge(fsg->bulk_in);
  36542. + }
  36543. + return rc;
  36544. +}
  36545. +
  36546. +static int throw_away_data(struct fsg_dev *fsg)
  36547. +{
  36548. + struct fsg_buffhd *bh;
  36549. + u32 amount;
  36550. + int rc;
  36551. +
  36552. + while ((bh = fsg->next_buffhd_to_drain)->state != BUF_STATE_EMPTY ||
  36553. + fsg->usb_amount_left > 0) {
  36554. +
  36555. + /* Throw away the data in a filled buffer */
  36556. + if (bh->state == BUF_STATE_FULL) {
  36557. + smp_rmb();
  36558. + bh->state = BUF_STATE_EMPTY;
  36559. + fsg->next_buffhd_to_drain = bh->next;
  36560. +
  36561. + /* A short packet or an error ends everything */
  36562. + if (bh->outreq->actual < bh->bulk_out_intended_length ||
  36563. + bh->outreq->status != 0) {
  36564. + raise_exception(fsg, FSG_STATE_ABORT_BULK_OUT);
  36565. + return -EINTR;
  36566. + }
  36567. + continue;
  36568. + }
  36569. +
  36570. + /* Try to submit another request if we need one */
  36571. + bh = fsg->next_buffhd_to_fill;
  36572. + if (bh->state == BUF_STATE_EMPTY && fsg->usb_amount_left > 0) {
  36573. + amount = min(fsg->usb_amount_left,
  36574. + (u32) mod_data.buflen);
  36575. +
  36576. + /* Except at the end of the transfer, amount will be
  36577. + * equal to the buffer size, which is divisible by
  36578. + * the bulk-out maxpacket size.
  36579. + */
  36580. + set_bulk_out_req_length(fsg, bh, amount);
  36581. + start_transfer(fsg, fsg->bulk_out, bh->outreq,
  36582. + &bh->outreq_busy, &bh->state);
  36583. + fsg->next_buffhd_to_fill = bh->next;
  36584. + fsg->usb_amount_left -= amount;
  36585. + continue;
  36586. + }
  36587. +
  36588. + /* Otherwise wait for something to happen */
  36589. + rc = sleep_thread(fsg);
  36590. + if (rc)
  36591. + return rc;
  36592. + }
  36593. + return 0;
  36594. +}
  36595. +
  36596. +
  36597. +static int finish_reply(struct fsg_dev *fsg)
  36598. +{
  36599. + struct fsg_buffhd *bh = fsg->next_buffhd_to_fill;
  36600. + int rc = 0;
  36601. +
  36602. + switch (fsg->data_dir) {
  36603. + case DATA_DIR_NONE:
  36604. + break; // Nothing to send
  36605. +
  36606. + /* If we don't know whether the host wants to read or write,
  36607. + * this must be CB or CBI with an unknown command. We mustn't
  36608. + * try to send or receive any data. So stall both bulk pipes
  36609. + * if we can and wait for a reset. */
  36610. + case DATA_DIR_UNKNOWN:
  36611. + if (mod_data.can_stall) {
  36612. + fsg_set_halt(fsg, fsg->bulk_out);
  36613. + rc = halt_bulk_in_endpoint(fsg);
  36614. + }
  36615. + break;
  36616. +
  36617. + /* All but the last buffer of data must have already been sent */
  36618. + case DATA_DIR_TO_HOST:
  36619. + if (fsg->data_size == 0)
  36620. + ; // Nothing to send
  36621. +
  36622. + /* If there's no residue, simply send the last buffer */
  36623. + else if (fsg->residue == 0) {
  36624. + bh->inreq->zero = 0;
  36625. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  36626. + &bh->inreq_busy, &bh->state);
  36627. + fsg->next_buffhd_to_fill = bh->next;
  36628. + }
  36629. +
  36630. + /* There is a residue. For CB and CBI, simply mark the end
  36631. + * of the data with a short packet. However, if we are
  36632. + * allowed to stall, there was no data at all (residue ==
  36633. + * data_size), and the command failed (invalid LUN or
  36634. + * sense data is set), then halt the bulk-in endpoint
  36635. + * instead. */
  36636. + else if (!transport_is_bbb()) {
  36637. + if (mod_data.can_stall &&
  36638. + fsg->residue == fsg->data_size &&
  36639. + (!fsg->curlun || fsg->curlun->sense_data != SS_NO_SENSE)) {
  36640. + bh->state = BUF_STATE_EMPTY;
  36641. + rc = halt_bulk_in_endpoint(fsg);
  36642. + } else {
  36643. + bh->inreq->zero = 1;
  36644. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  36645. + &bh->inreq_busy, &bh->state);
  36646. + fsg->next_buffhd_to_fill = bh->next;
  36647. + }
  36648. + }
  36649. +
  36650. + /*
  36651. + * For Bulk-only, mark the end of the data with a short
  36652. + * packet. If we are allowed to stall, halt the bulk-in
  36653. + * endpoint. (Note: This violates the Bulk-Only Transport
  36654. + * specification, which requires us to pad the data if we
  36655. + * don't halt the endpoint. Presumably nobody will mind.)
  36656. + */
  36657. + else {
  36658. + bh->inreq->zero = 1;
  36659. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  36660. + &bh->inreq_busy, &bh->state);
  36661. + fsg->next_buffhd_to_fill = bh->next;
  36662. + if (mod_data.can_stall)
  36663. + rc = halt_bulk_in_endpoint(fsg);
  36664. + }
  36665. + break;
  36666. +
  36667. + /* We have processed all we want from the data the host has sent.
  36668. + * There may still be outstanding bulk-out requests. */
  36669. + case DATA_DIR_FROM_HOST:
  36670. + if (fsg->residue == 0)
  36671. + ; // Nothing to receive
  36672. +
  36673. + /* Did the host stop sending unexpectedly early? */
  36674. + else if (fsg->short_packet_received) {
  36675. + raise_exception(fsg, FSG_STATE_ABORT_BULK_OUT);
  36676. + rc = -EINTR;
  36677. + }
  36678. +
  36679. + /* We haven't processed all the incoming data. Even though
  36680. + * we may be allowed to stall, doing so would cause a race.
  36681. + * The controller may already have ACK'ed all the remaining
  36682. + * bulk-out packets, in which case the host wouldn't see a
  36683. + * STALL. Not realizing the endpoint was halted, it wouldn't
  36684. + * clear the halt -- leading to problems later on. */
  36685. +#if 0
  36686. + else if (mod_data.can_stall) {
  36687. + fsg_set_halt(fsg, fsg->bulk_out);
  36688. + raise_exception(fsg, FSG_STATE_ABORT_BULK_OUT);
  36689. + rc = -EINTR;
  36690. + }
  36691. +#endif
  36692. +
  36693. + /* We can't stall. Read in the excess data and throw it
  36694. + * all away. */
  36695. + else
  36696. + rc = throw_away_data(fsg);
  36697. + break;
  36698. + }
  36699. + return rc;
  36700. +}
  36701. +
  36702. +
  36703. +static int send_status(struct fsg_dev *fsg)
  36704. +{
  36705. + struct fsg_lun *curlun = fsg->curlun;
  36706. + struct fsg_buffhd *bh;
  36707. + int rc;
  36708. + u8 status = US_BULK_STAT_OK;
  36709. + u32 sd, sdinfo = 0;
  36710. +
  36711. + /* Wait for the next buffer to become available */
  36712. + bh = fsg->next_buffhd_to_fill;
  36713. + while (bh->state != BUF_STATE_EMPTY) {
  36714. + rc = sleep_thread(fsg);
  36715. + if (rc)
  36716. + return rc;
  36717. + }
  36718. +
  36719. + if (curlun) {
  36720. + sd = curlun->sense_data;
  36721. + sdinfo = curlun->sense_data_info;
  36722. + } else if (fsg->bad_lun_okay)
  36723. + sd = SS_NO_SENSE;
  36724. + else
  36725. + sd = SS_LOGICAL_UNIT_NOT_SUPPORTED;
  36726. +
  36727. + if (fsg->phase_error) {
  36728. + DBG(fsg, "sending phase-error status\n");
  36729. + status = US_BULK_STAT_PHASE;
  36730. + sd = SS_INVALID_COMMAND;
  36731. + } else if (sd != SS_NO_SENSE) {
  36732. + DBG(fsg, "sending command-failure status\n");
  36733. + status = US_BULK_STAT_FAIL;
  36734. + VDBG(fsg, " sense data: SK x%02x, ASC x%02x, ASCQ x%02x;"
  36735. + " info x%x\n",
  36736. + SK(sd), ASC(sd), ASCQ(sd), sdinfo);
  36737. + }
  36738. +
  36739. + if (transport_is_bbb()) {
  36740. + struct bulk_cs_wrap *csw = bh->buf;
  36741. +
  36742. + /* Store and send the Bulk-only CSW */
  36743. + csw->Signature = cpu_to_le32(US_BULK_CS_SIGN);
  36744. + csw->Tag = fsg->tag;
  36745. + csw->Residue = cpu_to_le32(fsg->residue);
  36746. + csw->Status = status;
  36747. +
  36748. + bh->inreq->length = US_BULK_CS_WRAP_LEN;
  36749. + bh->inreq->zero = 0;
  36750. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  36751. + &bh->inreq_busy, &bh->state);
  36752. +
  36753. + } else if (mod_data.transport_type == USB_PR_CB) {
  36754. +
  36755. + /* Control-Bulk transport has no status phase! */
  36756. + return 0;
  36757. +
  36758. + } else { // USB_PR_CBI
  36759. + struct interrupt_data *buf = bh->buf;
  36760. +
  36761. + /* Store and send the Interrupt data. UFI sends the ASC
  36762. + * and ASCQ bytes. Everything else sends a Type (which
  36763. + * is always 0) and the status Value. */
  36764. + if (mod_data.protocol_type == USB_SC_UFI) {
  36765. + buf->bType = ASC(sd);
  36766. + buf->bValue = ASCQ(sd);
  36767. + } else {
  36768. + buf->bType = 0;
  36769. + buf->bValue = status;
  36770. + }
  36771. + fsg->intreq->length = CBI_INTERRUPT_DATA_LEN;
  36772. +
  36773. + fsg->intr_buffhd = bh; // Point to the right buffhd
  36774. + fsg->intreq->buf = bh->inreq->buf;
  36775. + fsg->intreq->context = bh;
  36776. + start_transfer(fsg, fsg->intr_in, fsg->intreq,
  36777. + &fsg->intreq_busy, &bh->state);
  36778. + }
  36779. +
  36780. + fsg->next_buffhd_to_fill = bh->next;
  36781. + return 0;
  36782. +}
  36783. +
  36784. +
  36785. +/*-------------------------------------------------------------------------*/
  36786. +
  36787. +/* Check whether the command is properly formed and whether its data size
  36788. + * and direction agree with the values we already have. */
  36789. +static int check_command(struct fsg_dev *fsg, int cmnd_size,
  36790. + enum data_direction data_dir, unsigned int mask,
  36791. + int needs_medium, const char *name)
  36792. +{
  36793. + int i;
  36794. + int lun = fsg->cmnd[1] >> 5;
  36795. + static const char dirletter[4] = {'u', 'o', 'i', 'n'};
  36796. + char hdlen[20];
  36797. + struct fsg_lun *curlun;
  36798. +
  36799. + /* Adjust the expected cmnd_size for protocol encapsulation padding.
  36800. + * Transparent SCSI doesn't pad. */
  36801. + if (protocol_is_scsi())
  36802. + ;
  36803. +
  36804. + /* There's some disagreement as to whether RBC pads commands or not.
  36805. + * We'll play it safe and accept either form. */
  36806. + else if (mod_data.protocol_type == USB_SC_RBC) {
  36807. + if (fsg->cmnd_size == 12)
  36808. + cmnd_size = 12;
  36809. +
  36810. + /* All the other protocols pad to 12 bytes */
  36811. + } else
  36812. + cmnd_size = 12;
  36813. +
  36814. + hdlen[0] = 0;
  36815. + if (fsg->data_dir != DATA_DIR_UNKNOWN)
  36816. + sprintf(hdlen, ", H%c=%u", dirletter[(int) fsg->data_dir],
  36817. + fsg->data_size);
  36818. + VDBG(fsg, "SCSI command: %s; Dc=%d, D%c=%u; Hc=%d%s\n",
  36819. + name, cmnd_size, dirletter[(int) data_dir],
  36820. + fsg->data_size_from_cmnd, fsg->cmnd_size, hdlen);
  36821. +
  36822. + /* We can't reply at all until we know the correct data direction
  36823. + * and size. */
  36824. + if (fsg->data_size_from_cmnd == 0)
  36825. + data_dir = DATA_DIR_NONE;
  36826. + if (fsg->data_dir == DATA_DIR_UNKNOWN) { // CB or CBI
  36827. + fsg->data_dir = data_dir;
  36828. + fsg->data_size = fsg->data_size_from_cmnd;
  36829. +
  36830. + } else { // Bulk-only
  36831. + if (fsg->data_size < fsg->data_size_from_cmnd) {
  36832. +
  36833. + /* Host data size < Device data size is a phase error.
  36834. + * Carry out the command, but only transfer as much
  36835. + * as we are allowed. */
  36836. + fsg->data_size_from_cmnd = fsg->data_size;
  36837. + fsg->phase_error = 1;
  36838. + }
  36839. + }
  36840. + fsg->residue = fsg->usb_amount_left = fsg->data_size;
  36841. +
  36842. + /* Conflicting data directions is a phase error */
  36843. + if (fsg->data_dir != data_dir && fsg->data_size_from_cmnd > 0) {
  36844. + fsg->phase_error = 1;
  36845. + return -EINVAL;
  36846. + }
  36847. +
  36848. + /* Verify the length of the command itself */
  36849. + if (cmnd_size != fsg->cmnd_size) {
  36850. +
  36851. + /* Special case workaround: There are plenty of buggy SCSI
  36852. + * implementations. Many have issues with cbw->Length
  36853. + * field passing a wrong command size. For those cases we
  36854. + * always try to work around the problem by using the length
  36855. + * sent by the host side provided it is at least as large
  36856. + * as the correct command length.
  36857. + * Examples of such cases would be MS-Windows, which issues
  36858. + * REQUEST SENSE with cbw->Length == 12 where it should
  36859. + * be 6, and xbox360 issuing INQUIRY, TEST UNIT READY and
  36860. + * REQUEST SENSE with cbw->Length == 10 where it should
  36861. + * be 6 as well.
  36862. + */
  36863. + if (cmnd_size <= fsg->cmnd_size) {
  36864. + DBG(fsg, "%s is buggy! Expected length %d "
  36865. + "but we got %d\n", name,
  36866. + cmnd_size, fsg->cmnd_size);
  36867. + cmnd_size = fsg->cmnd_size;
  36868. + } else {
  36869. + fsg->phase_error = 1;
  36870. + return -EINVAL;
  36871. + }
  36872. + }
  36873. +
  36874. + /* Check that the LUN values are consistent */
  36875. + if (transport_is_bbb()) {
  36876. + if (fsg->lun != lun)
  36877. + DBG(fsg, "using LUN %d from CBW, "
  36878. + "not LUN %d from CDB\n",
  36879. + fsg->lun, lun);
  36880. + }
  36881. +
  36882. + /* Check the LUN */
  36883. + curlun = fsg->curlun;
  36884. + if (curlun) {
  36885. + if (fsg->cmnd[0] != REQUEST_SENSE) {
  36886. + curlun->sense_data = SS_NO_SENSE;
  36887. + curlun->sense_data_info = 0;
  36888. + curlun->info_valid = 0;
  36889. + }
  36890. + } else {
  36891. + fsg->bad_lun_okay = 0;
  36892. +
  36893. + /* INQUIRY and REQUEST SENSE commands are explicitly allowed
  36894. + * to use unsupported LUNs; all others may not. */
  36895. + if (fsg->cmnd[0] != INQUIRY &&
  36896. + fsg->cmnd[0] != REQUEST_SENSE) {
  36897. + DBG(fsg, "unsupported LUN %d\n", fsg->lun);
  36898. + return -EINVAL;
  36899. + }
  36900. + }
  36901. +
  36902. + /* If a unit attention condition exists, only INQUIRY and
  36903. + * REQUEST SENSE commands are allowed; anything else must fail. */
  36904. + if (curlun && curlun->unit_attention_data != SS_NO_SENSE &&
  36905. + fsg->cmnd[0] != INQUIRY &&
  36906. + fsg->cmnd[0] != REQUEST_SENSE) {
  36907. + curlun->sense_data = curlun->unit_attention_data;
  36908. + curlun->unit_attention_data = SS_NO_SENSE;
  36909. + return -EINVAL;
  36910. + }
  36911. +
  36912. + /* Check that only command bytes listed in the mask are non-zero */
  36913. + fsg->cmnd[1] &= 0x1f; // Mask away the LUN
  36914. + for (i = 1; i < cmnd_size; ++i) {
  36915. + if (fsg->cmnd[i] && !(mask & (1 << i))) {
  36916. + if (curlun)
  36917. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  36918. + return -EINVAL;
  36919. + }
  36920. + }
  36921. +
  36922. + /* If the medium isn't mounted and the command needs to access
  36923. + * it, return an error. */
  36924. + if (curlun && !fsg_lun_is_open(curlun) && needs_medium) {
  36925. + curlun->sense_data = SS_MEDIUM_NOT_PRESENT;
  36926. + return -EINVAL;
  36927. + }
  36928. +
  36929. + return 0;
  36930. +}
  36931. +
  36932. +/* wrapper of check_command for data size in blocks handling */
  36933. +static int check_command_size_in_blocks(struct fsg_dev *fsg, int cmnd_size,
  36934. + enum data_direction data_dir, unsigned int mask,
  36935. + int needs_medium, const char *name)
  36936. +{
  36937. + if (fsg->curlun)
  36938. + fsg->data_size_from_cmnd <<= fsg->curlun->blkbits;
  36939. + return check_command(fsg, cmnd_size, data_dir,
  36940. + mask, needs_medium, name);
  36941. +}
  36942. +
  36943. +static int do_scsi_command(struct fsg_dev *fsg)
  36944. +{
  36945. + struct fsg_buffhd *bh;
  36946. + int rc;
  36947. + int reply = -EINVAL;
  36948. + int i;
  36949. + static char unknown[16];
  36950. +
  36951. + dump_cdb(fsg);
  36952. +
  36953. + /* Wait for the next buffer to become available for data or status */
  36954. + bh = fsg->next_buffhd_to_drain = fsg->next_buffhd_to_fill;
  36955. + while (bh->state != BUF_STATE_EMPTY) {
  36956. + rc = sleep_thread(fsg);
  36957. + if (rc)
  36958. + return rc;
  36959. + }
  36960. + fsg->phase_error = 0;
  36961. + fsg->short_packet_received = 0;
  36962. +
  36963. + down_read(&fsg->filesem); // We're using the backing file
  36964. + switch (fsg->cmnd[0]) {
  36965. +
  36966. + case INQUIRY:
  36967. + fsg->data_size_from_cmnd = fsg->cmnd[4];
  36968. + if ((reply = check_command(fsg, 6, DATA_DIR_TO_HOST,
  36969. + (1<<4), 0,
  36970. + "INQUIRY")) == 0)
  36971. + reply = do_inquiry(fsg, bh);
  36972. + break;
  36973. +
  36974. + case MODE_SELECT:
  36975. + fsg->data_size_from_cmnd = fsg->cmnd[4];
  36976. + if ((reply = check_command(fsg, 6, DATA_DIR_FROM_HOST,
  36977. + (1<<1) | (1<<4), 0,
  36978. + "MODE SELECT(6)")) == 0)
  36979. + reply = do_mode_select(fsg, bh);
  36980. + break;
  36981. +
  36982. + case MODE_SELECT_10:
  36983. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  36984. + if ((reply = check_command(fsg, 10, DATA_DIR_FROM_HOST,
  36985. + (1<<1) | (3<<7), 0,
  36986. + "MODE SELECT(10)")) == 0)
  36987. + reply = do_mode_select(fsg, bh);
  36988. + break;
  36989. +
  36990. + case MODE_SENSE:
  36991. + fsg->data_size_from_cmnd = fsg->cmnd[4];
  36992. + if ((reply = check_command(fsg, 6, DATA_DIR_TO_HOST,
  36993. + (1<<1) | (1<<2) | (1<<4), 0,
  36994. + "MODE SENSE(6)")) == 0)
  36995. + reply = do_mode_sense(fsg, bh);
  36996. + break;
  36997. +
  36998. + case MODE_SENSE_10:
  36999. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  37000. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  37001. + (1<<1) | (1<<2) | (3<<7), 0,
  37002. + "MODE SENSE(10)")) == 0)
  37003. + reply = do_mode_sense(fsg, bh);
  37004. + break;
  37005. +
  37006. + case ALLOW_MEDIUM_REMOVAL:
  37007. + fsg->data_size_from_cmnd = 0;
  37008. + if ((reply = check_command(fsg, 6, DATA_DIR_NONE,
  37009. + (1<<4), 0,
  37010. + "PREVENT-ALLOW MEDIUM REMOVAL")) == 0)
  37011. + reply = do_prevent_allow(fsg);
  37012. + break;
  37013. +
  37014. + case READ_6:
  37015. + i = fsg->cmnd[4];
  37016. + fsg->data_size_from_cmnd = (i == 0) ? 256 : i;
  37017. + if ((reply = check_command_size_in_blocks(fsg, 6,
  37018. + DATA_DIR_TO_HOST,
  37019. + (7<<1) | (1<<4), 1,
  37020. + "READ(6)")) == 0)
  37021. + reply = do_read(fsg);
  37022. + break;
  37023. +
  37024. + case READ_10:
  37025. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  37026. + if ((reply = check_command_size_in_blocks(fsg, 10,
  37027. + DATA_DIR_TO_HOST,
  37028. + (1<<1) | (0xf<<2) | (3<<7), 1,
  37029. + "READ(10)")) == 0)
  37030. + reply = do_read(fsg);
  37031. + break;
  37032. +
  37033. + case READ_12:
  37034. + fsg->data_size_from_cmnd = get_unaligned_be32(&fsg->cmnd[6]);
  37035. + if ((reply = check_command_size_in_blocks(fsg, 12,
  37036. + DATA_DIR_TO_HOST,
  37037. + (1<<1) | (0xf<<2) | (0xf<<6), 1,
  37038. + "READ(12)")) == 0)
  37039. + reply = do_read(fsg);
  37040. + break;
  37041. +
  37042. + case READ_CAPACITY:
  37043. + fsg->data_size_from_cmnd = 8;
  37044. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  37045. + (0xf<<2) | (1<<8), 1,
  37046. + "READ CAPACITY")) == 0)
  37047. + reply = do_read_capacity(fsg, bh);
  37048. + break;
  37049. +
  37050. + case READ_HEADER:
  37051. + if (!mod_data.cdrom)
  37052. + goto unknown_cmnd;
  37053. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  37054. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  37055. + (3<<7) | (0x1f<<1), 1,
  37056. + "READ HEADER")) == 0)
  37057. + reply = do_read_header(fsg, bh);
  37058. + break;
  37059. +
  37060. + case READ_TOC:
  37061. + if (!mod_data.cdrom)
  37062. + goto unknown_cmnd;
  37063. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  37064. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  37065. + (7<<6) | (1<<1), 1,
  37066. + "READ TOC")) == 0)
  37067. + reply = do_read_toc(fsg, bh);
  37068. + break;
  37069. +
  37070. + case READ_FORMAT_CAPACITIES:
  37071. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  37072. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  37073. + (3<<7), 1,
  37074. + "READ FORMAT CAPACITIES")) == 0)
  37075. + reply = do_read_format_capacities(fsg, bh);
  37076. + break;
  37077. +
  37078. + case REQUEST_SENSE:
  37079. + fsg->data_size_from_cmnd = fsg->cmnd[4];
  37080. + if ((reply = check_command(fsg, 6, DATA_DIR_TO_HOST,
  37081. + (1<<4), 0,
  37082. + "REQUEST SENSE")) == 0)
  37083. + reply = do_request_sense(fsg, bh);
  37084. + break;
  37085. +
  37086. + case START_STOP:
  37087. + fsg->data_size_from_cmnd = 0;
  37088. + if ((reply = check_command(fsg, 6, DATA_DIR_NONE,
  37089. + (1<<1) | (1<<4), 0,
  37090. + "START-STOP UNIT")) == 0)
  37091. + reply = do_start_stop(fsg);
  37092. + break;
  37093. +
  37094. + case SYNCHRONIZE_CACHE:
  37095. + fsg->data_size_from_cmnd = 0;
  37096. + if ((reply = check_command(fsg, 10, DATA_DIR_NONE,
  37097. + (0xf<<2) | (3<<7), 1,
  37098. + "SYNCHRONIZE CACHE")) == 0)
  37099. + reply = do_synchronize_cache(fsg);
  37100. + break;
  37101. +
  37102. + case TEST_UNIT_READY:
  37103. + fsg->data_size_from_cmnd = 0;
  37104. + reply = check_command(fsg, 6, DATA_DIR_NONE,
  37105. + 0, 1,
  37106. + "TEST UNIT READY");
  37107. + break;
  37108. +
  37109. + /* Although optional, this command is used by MS-Windows. We
  37110. + * support a minimal version: BytChk must be 0. */
  37111. + case VERIFY:
  37112. + fsg->data_size_from_cmnd = 0;
  37113. + if ((reply = check_command(fsg, 10, DATA_DIR_NONE,
  37114. + (1<<1) | (0xf<<2) | (3<<7), 1,
  37115. + "VERIFY")) == 0)
  37116. + reply = do_verify(fsg);
  37117. + break;
  37118. +
  37119. + case WRITE_6:
  37120. + i = fsg->cmnd[4];
  37121. + fsg->data_size_from_cmnd = (i == 0) ? 256 : i;
  37122. + if ((reply = check_command_size_in_blocks(fsg, 6,
  37123. + DATA_DIR_FROM_HOST,
  37124. + (7<<1) | (1<<4), 1,
  37125. + "WRITE(6)")) == 0)
  37126. + reply = do_write(fsg);
  37127. + break;
  37128. +
  37129. + case WRITE_10:
  37130. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  37131. + if ((reply = check_command_size_in_blocks(fsg, 10,
  37132. + DATA_DIR_FROM_HOST,
  37133. + (1<<1) | (0xf<<2) | (3<<7), 1,
  37134. + "WRITE(10)")) == 0)
  37135. + reply = do_write(fsg);
  37136. + break;
  37137. +
  37138. + case WRITE_12:
  37139. + fsg->data_size_from_cmnd = get_unaligned_be32(&fsg->cmnd[6]);
  37140. + if ((reply = check_command_size_in_blocks(fsg, 12,
  37141. + DATA_DIR_FROM_HOST,
  37142. + (1<<1) | (0xf<<2) | (0xf<<6), 1,
  37143. + "WRITE(12)")) == 0)
  37144. + reply = do_write(fsg);
  37145. + break;
  37146. +
  37147. + /* Some mandatory commands that we recognize but don't implement.
  37148. + * They don't mean much in this setting. It's left as an exercise
  37149. + * for anyone interested to implement RESERVE and RELEASE in terms
  37150. + * of Posix locks. */
  37151. + case FORMAT_UNIT:
  37152. + case RELEASE:
  37153. + case RESERVE:
  37154. + case SEND_DIAGNOSTIC:
  37155. + // Fall through
  37156. +
  37157. + default:
  37158. + unknown_cmnd:
  37159. + fsg->data_size_from_cmnd = 0;
  37160. + sprintf(unknown, "Unknown x%02x", fsg->cmnd[0]);
  37161. + if ((reply = check_command(fsg, fsg->cmnd_size,
  37162. + DATA_DIR_UNKNOWN, ~0, 0, unknown)) == 0) {
  37163. + fsg->curlun->sense_data = SS_INVALID_COMMAND;
  37164. + reply = -EINVAL;
  37165. + }
  37166. + break;
  37167. + }
  37168. + up_read(&fsg->filesem);
  37169. +
  37170. + if (reply == -EINTR || signal_pending(current))
  37171. + return -EINTR;
  37172. +
  37173. + /* Set up the single reply buffer for finish_reply() */
  37174. + if (reply == -EINVAL)
  37175. + reply = 0; // Error reply length
  37176. + if (reply >= 0 && fsg->data_dir == DATA_DIR_TO_HOST) {
  37177. + reply = min((u32) reply, fsg->data_size_from_cmnd);
  37178. + bh->inreq->length = reply;
  37179. + bh->state = BUF_STATE_FULL;
  37180. + fsg->residue -= reply;
  37181. + } // Otherwise it's already set
  37182. +
  37183. + return 0;
  37184. +}
  37185. +
  37186. +
  37187. +/*-------------------------------------------------------------------------*/
  37188. +
  37189. +static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  37190. +{
  37191. + struct usb_request *req = bh->outreq;
  37192. + struct bulk_cb_wrap *cbw = req->buf;
  37193. +
  37194. + /* Was this a real packet? Should it be ignored? */
  37195. + if (req->status || test_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags))
  37196. + return -EINVAL;
  37197. +
  37198. + /* Is the CBW valid? */
  37199. + if (req->actual != US_BULK_CB_WRAP_LEN ||
  37200. + cbw->Signature != cpu_to_le32(
  37201. + US_BULK_CB_SIGN)) {
  37202. + DBG(fsg, "invalid CBW: len %u sig 0x%x\n",
  37203. + req->actual,
  37204. + le32_to_cpu(cbw->Signature));
  37205. +
  37206. + /* The Bulk-only spec says we MUST stall the IN endpoint
  37207. + * (6.6.1), so it's unavoidable. It also says we must
  37208. + * retain this state until the next reset, but there's
  37209. + * no way to tell the controller driver it should ignore
  37210. + * Clear-Feature(HALT) requests.
  37211. + *
  37212. + * We aren't required to halt the OUT endpoint; instead
  37213. + * we can simply accept and discard any data received
  37214. + * until the next reset. */
  37215. + wedge_bulk_in_endpoint(fsg);
  37216. + set_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags);
  37217. + return -EINVAL;
  37218. + }
  37219. +
  37220. + /* Is the CBW meaningful? */
  37221. + if (cbw->Lun >= FSG_MAX_LUNS || cbw->Flags & ~US_BULK_FLAG_IN ||
  37222. + cbw->Length <= 0 || cbw->Length > MAX_COMMAND_SIZE) {
  37223. + DBG(fsg, "non-meaningful CBW: lun = %u, flags = 0x%x, "
  37224. + "cmdlen %u\n",
  37225. + cbw->Lun, cbw->Flags, cbw->Length);
  37226. +
  37227. + /* We can do anything we want here, so let's stall the
  37228. + * bulk pipes if we are allowed to. */
  37229. + if (mod_data.can_stall) {
  37230. + fsg_set_halt(fsg, fsg->bulk_out);
  37231. + halt_bulk_in_endpoint(fsg);
  37232. + }
  37233. + return -EINVAL;
  37234. + }
  37235. +
  37236. + /* Save the command for later */
  37237. + fsg->cmnd_size = cbw->Length;
  37238. + memcpy(fsg->cmnd, cbw->CDB, fsg->cmnd_size);
  37239. + if (cbw->Flags & US_BULK_FLAG_IN)
  37240. + fsg->data_dir = DATA_DIR_TO_HOST;
  37241. + else
  37242. + fsg->data_dir = DATA_DIR_FROM_HOST;
  37243. + fsg->data_size = le32_to_cpu(cbw->DataTransferLength);
  37244. + if (fsg->data_size == 0)
  37245. + fsg->data_dir = DATA_DIR_NONE;
  37246. + fsg->lun = cbw->Lun;
  37247. + fsg->tag = cbw->Tag;
  37248. + return 0;
  37249. +}
  37250. +
  37251. +
  37252. +static int get_next_command(struct fsg_dev *fsg)
  37253. +{
  37254. + struct fsg_buffhd *bh;
  37255. + int rc = 0;
  37256. +
  37257. + if (transport_is_bbb()) {
  37258. +
  37259. + /* Wait for the next buffer to become available */
  37260. + bh = fsg->next_buffhd_to_fill;
  37261. + while (bh->state != BUF_STATE_EMPTY) {
  37262. + rc = sleep_thread(fsg);
  37263. + if (rc)
  37264. + return rc;
  37265. + }
  37266. +
  37267. + /* Queue a request to read a Bulk-only CBW */
  37268. + set_bulk_out_req_length(fsg, bh, US_BULK_CB_WRAP_LEN);
  37269. + start_transfer(fsg, fsg->bulk_out, bh->outreq,
  37270. + &bh->outreq_busy, &bh->state);
  37271. +
  37272. + /* We will drain the buffer in software, which means we
  37273. + * can reuse it for the next filling. No need to advance
  37274. + * next_buffhd_to_fill. */
  37275. +
  37276. + /* Wait for the CBW to arrive */
  37277. + while (bh->state != BUF_STATE_FULL) {
  37278. + rc = sleep_thread(fsg);
  37279. + if (rc)
  37280. + return rc;
  37281. + }
  37282. + smp_rmb();
  37283. + rc = received_cbw(fsg, bh);
  37284. + bh->state = BUF_STATE_EMPTY;
  37285. +
  37286. + } else { // USB_PR_CB or USB_PR_CBI
  37287. +
  37288. + /* Wait for the next command to arrive */
  37289. + while (fsg->cbbuf_cmnd_size == 0) {
  37290. + rc = sleep_thread(fsg);
  37291. + if (rc)
  37292. + return rc;
  37293. + }
  37294. +
  37295. + /* Is the previous status interrupt request still busy?
  37296. + * The host is allowed to skip reading the status,
  37297. + * so we must cancel it. */
  37298. + if (fsg->intreq_busy)
  37299. + usb_ep_dequeue(fsg->intr_in, fsg->intreq);
  37300. +
  37301. + /* Copy the command and mark the buffer empty */
  37302. + fsg->data_dir = DATA_DIR_UNKNOWN;
  37303. + spin_lock_irq(&fsg->lock);
  37304. + fsg->cmnd_size = fsg->cbbuf_cmnd_size;
  37305. + memcpy(fsg->cmnd, fsg->cbbuf_cmnd, fsg->cmnd_size);
  37306. + fsg->cbbuf_cmnd_size = 0;
  37307. + spin_unlock_irq(&fsg->lock);
  37308. +
  37309. + /* Use LUN from the command */
  37310. + fsg->lun = fsg->cmnd[1] >> 5;
  37311. + }
  37312. +
  37313. + /* Update current lun */
  37314. + if (fsg->lun >= 0 && fsg->lun < fsg->nluns)
  37315. + fsg->curlun = &fsg->luns[fsg->lun];
  37316. + else
  37317. + fsg->curlun = NULL;
  37318. +
  37319. + return rc;
  37320. +}
  37321. +
  37322. +
  37323. +/*-------------------------------------------------------------------------*/
  37324. +
  37325. +static int enable_endpoint(struct fsg_dev *fsg, struct usb_ep *ep,
  37326. + const struct usb_endpoint_descriptor *d)
  37327. +{
  37328. + int rc;
  37329. +
  37330. + ep->driver_data = fsg;
  37331. + ep->desc = d;
  37332. + rc = usb_ep_enable(ep);
  37333. + if (rc)
  37334. + ERROR(fsg, "can't enable %s, result %d\n", ep->name, rc);
  37335. + return rc;
  37336. +}
  37337. +
  37338. +static int alloc_request(struct fsg_dev *fsg, struct usb_ep *ep,
  37339. + struct usb_request **preq)
  37340. +{
  37341. + *preq = usb_ep_alloc_request(ep, GFP_ATOMIC);
  37342. + if (*preq)
  37343. + return 0;
  37344. + ERROR(fsg, "can't allocate request for %s\n", ep->name);
  37345. + return -ENOMEM;
  37346. +}
  37347. +
  37348. +/*
  37349. + * Reset interface setting and re-init endpoint state (toggle etc).
  37350. + * Call with altsetting < 0 to disable the interface. The only other
  37351. + * available altsetting is 0, which enables the interface.
  37352. + */
  37353. +static int do_set_interface(struct fsg_dev *fsg, int altsetting)
  37354. +{
  37355. + int rc = 0;
  37356. + int i;
  37357. + const struct usb_endpoint_descriptor *d;
  37358. +
  37359. + if (fsg->running)
  37360. + DBG(fsg, "reset interface\n");
  37361. +
  37362. +reset:
  37363. + /* Deallocate the requests */
  37364. + for (i = 0; i < fsg_num_buffers; ++i) {
  37365. + struct fsg_buffhd *bh = &fsg->buffhds[i];
  37366. +
  37367. + if (bh->inreq) {
  37368. + usb_ep_free_request(fsg->bulk_in, bh->inreq);
  37369. + bh->inreq = NULL;
  37370. + }
  37371. + if (bh->outreq) {
  37372. + usb_ep_free_request(fsg->bulk_out, bh->outreq);
  37373. + bh->outreq = NULL;
  37374. + }
  37375. + }
  37376. + if (fsg->intreq) {
  37377. + usb_ep_free_request(fsg->intr_in, fsg->intreq);
  37378. + fsg->intreq = NULL;
  37379. + }
  37380. +
  37381. + /* Disable the endpoints */
  37382. + if (fsg->bulk_in_enabled) {
  37383. + usb_ep_disable(fsg->bulk_in);
  37384. + fsg->bulk_in_enabled = 0;
  37385. + }
  37386. + if (fsg->bulk_out_enabled) {
  37387. + usb_ep_disable(fsg->bulk_out);
  37388. + fsg->bulk_out_enabled = 0;
  37389. + }
  37390. + if (fsg->intr_in_enabled) {
  37391. + usb_ep_disable(fsg->intr_in);
  37392. + fsg->intr_in_enabled = 0;
  37393. + }
  37394. +
  37395. + fsg->running = 0;
  37396. + if (altsetting < 0 || rc != 0)
  37397. + return rc;
  37398. +
  37399. + DBG(fsg, "set interface %d\n", altsetting);
  37400. +
  37401. + /* Enable the endpoints */
  37402. + d = fsg_ep_desc(fsg->gadget,
  37403. + &fsg_fs_bulk_in_desc, &fsg_hs_bulk_in_desc,
  37404. + &fsg_ss_bulk_in_desc);
  37405. + if ((rc = enable_endpoint(fsg, fsg->bulk_in, d)) != 0)
  37406. + goto reset;
  37407. + fsg->bulk_in_enabled = 1;
  37408. +
  37409. + d = fsg_ep_desc(fsg->gadget,
  37410. + &fsg_fs_bulk_out_desc, &fsg_hs_bulk_out_desc,
  37411. + &fsg_ss_bulk_out_desc);
  37412. + if ((rc = enable_endpoint(fsg, fsg->bulk_out, d)) != 0)
  37413. + goto reset;
  37414. + fsg->bulk_out_enabled = 1;
  37415. + fsg->bulk_out_maxpacket = usb_endpoint_maxp(d);
  37416. + clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags);
  37417. +
  37418. + if (transport_is_cbi()) {
  37419. + d = fsg_ep_desc(fsg->gadget,
  37420. + &fsg_fs_intr_in_desc, &fsg_hs_intr_in_desc,
  37421. + &fsg_ss_intr_in_desc);
  37422. + if ((rc = enable_endpoint(fsg, fsg->intr_in, d)) != 0)
  37423. + goto reset;
  37424. + fsg->intr_in_enabled = 1;
  37425. + }
  37426. +
  37427. + /* Allocate the requests */
  37428. + for (i = 0; i < fsg_num_buffers; ++i) {
  37429. + struct fsg_buffhd *bh = &fsg->buffhds[i];
  37430. +
  37431. + if ((rc = alloc_request(fsg, fsg->bulk_in, &bh->inreq)) != 0)
  37432. + goto reset;
  37433. + if ((rc = alloc_request(fsg, fsg->bulk_out, &bh->outreq)) != 0)
  37434. + goto reset;
  37435. + bh->inreq->buf = bh->outreq->buf = bh->buf;
  37436. + bh->inreq->context = bh->outreq->context = bh;
  37437. + bh->inreq->complete = bulk_in_complete;
  37438. + bh->outreq->complete = bulk_out_complete;
  37439. + }
  37440. + if (transport_is_cbi()) {
  37441. + if ((rc = alloc_request(fsg, fsg->intr_in, &fsg->intreq)) != 0)
  37442. + goto reset;
  37443. + fsg->intreq->complete = intr_in_complete;
  37444. + }
  37445. +
  37446. + fsg->running = 1;
  37447. + for (i = 0; i < fsg->nluns; ++i)
  37448. + fsg->luns[i].unit_attention_data = SS_RESET_OCCURRED;
  37449. + return rc;
  37450. +}
  37451. +
  37452. +
  37453. +/*
  37454. + * Change our operational configuration. This code must agree with the code
  37455. + * that returns config descriptors, and with interface altsetting code.
  37456. + *
  37457. + * It's also responsible for power management interactions. Some
  37458. + * configurations might not work with our current power sources.
  37459. + * For now we just assume the gadget is always self-powered.
  37460. + */
  37461. +static int do_set_config(struct fsg_dev *fsg, u8 new_config)
  37462. +{
  37463. + int rc = 0;
  37464. +
  37465. + /* Disable the single interface */
  37466. + if (fsg->config != 0) {
  37467. + DBG(fsg, "reset config\n");
  37468. + fsg->config = 0;
  37469. + rc = do_set_interface(fsg, -1);
  37470. + }
  37471. +
  37472. + /* Enable the interface */
  37473. + if (new_config != 0) {
  37474. + fsg->config = new_config;
  37475. + if ((rc = do_set_interface(fsg, 0)) != 0)
  37476. + fsg->config = 0; // Reset on errors
  37477. + else
  37478. + INFO(fsg, "%s config #%d\n",
  37479. + usb_speed_string(fsg->gadget->speed),
  37480. + fsg->config);
  37481. + }
  37482. + return rc;
  37483. +}
  37484. +
  37485. +
  37486. +/*-------------------------------------------------------------------------*/
  37487. +
  37488. +static void handle_exception(struct fsg_dev *fsg)
  37489. +{
  37490. + siginfo_t info;
  37491. + int sig;
  37492. + int i;
  37493. + int num_active;
  37494. + struct fsg_buffhd *bh;
  37495. + enum fsg_state old_state;
  37496. + u8 new_config;
  37497. + struct fsg_lun *curlun;
  37498. + unsigned int exception_req_tag;
  37499. + int rc;
  37500. +
  37501. + /* Clear the existing signals. Anything but SIGUSR1 is converted
  37502. + * into a high-priority EXIT exception. */
  37503. + for (;;) {
  37504. + sig = dequeue_signal_lock(current, &current->blocked, &info);
  37505. + if (!sig)
  37506. + break;
  37507. + if (sig != SIGUSR1) {
  37508. + if (fsg->state < FSG_STATE_EXIT)
  37509. + DBG(fsg, "Main thread exiting on signal\n");
  37510. + raise_exception(fsg, FSG_STATE_EXIT);
  37511. + }
  37512. + }
  37513. +
  37514. + /* Cancel all the pending transfers */
  37515. + if (fsg->intreq_busy)
  37516. + usb_ep_dequeue(fsg->intr_in, fsg->intreq);
  37517. + for (i = 0; i < fsg_num_buffers; ++i) {
  37518. + bh = &fsg->buffhds[i];
  37519. + if (bh->inreq_busy)
  37520. + usb_ep_dequeue(fsg->bulk_in, bh->inreq);
  37521. + if (bh->outreq_busy)
  37522. + usb_ep_dequeue(fsg->bulk_out, bh->outreq);
  37523. + }
  37524. +
  37525. + /* Wait until everything is idle */
  37526. + for (;;) {
  37527. + num_active = fsg->intreq_busy;
  37528. + for (i = 0; i < fsg_num_buffers; ++i) {
  37529. + bh = &fsg->buffhds[i];
  37530. + num_active += bh->inreq_busy + bh->outreq_busy;
  37531. + }
  37532. + if (num_active == 0)
  37533. + break;
  37534. + if (sleep_thread(fsg))
  37535. + return;
  37536. + }
  37537. +
  37538. + /* Clear out the controller's fifos */
  37539. + if (fsg->bulk_in_enabled)
  37540. + usb_ep_fifo_flush(fsg->bulk_in);
  37541. + if (fsg->bulk_out_enabled)
  37542. + usb_ep_fifo_flush(fsg->bulk_out);
  37543. + if (fsg->intr_in_enabled)
  37544. + usb_ep_fifo_flush(fsg->intr_in);
  37545. +
  37546. + /* Reset the I/O buffer states and pointers, the SCSI
  37547. + * state, and the exception. Then invoke the handler. */
  37548. + spin_lock_irq(&fsg->lock);
  37549. +
  37550. + for (i = 0; i < fsg_num_buffers; ++i) {
  37551. + bh = &fsg->buffhds[i];
  37552. + bh->state = BUF_STATE_EMPTY;
  37553. + }
  37554. + fsg->next_buffhd_to_fill = fsg->next_buffhd_to_drain =
  37555. + &fsg->buffhds[0];
  37556. +
  37557. + exception_req_tag = fsg->exception_req_tag;
  37558. + new_config = fsg->new_config;
  37559. + old_state = fsg->state;
  37560. +
  37561. + if (old_state == FSG_STATE_ABORT_BULK_OUT)
  37562. + fsg->state = FSG_STATE_STATUS_PHASE;
  37563. + else {
  37564. + for (i = 0; i < fsg->nluns; ++i) {
  37565. + curlun = &fsg->luns[i];
  37566. + curlun->prevent_medium_removal = 0;
  37567. + curlun->sense_data = curlun->unit_attention_data =
  37568. + SS_NO_SENSE;
  37569. + curlun->sense_data_info = 0;
  37570. + curlun->info_valid = 0;
  37571. + }
  37572. + fsg->state = FSG_STATE_IDLE;
  37573. + }
  37574. + spin_unlock_irq(&fsg->lock);
  37575. +
  37576. + /* Carry out any extra actions required for the exception */
  37577. + switch (old_state) {
  37578. + default:
  37579. + break;
  37580. +
  37581. + case FSG_STATE_ABORT_BULK_OUT:
  37582. + send_status(fsg);
  37583. + spin_lock_irq(&fsg->lock);
  37584. + if (fsg->state == FSG_STATE_STATUS_PHASE)
  37585. + fsg->state = FSG_STATE_IDLE;
  37586. + spin_unlock_irq(&fsg->lock);
  37587. + break;
  37588. +
  37589. + case FSG_STATE_RESET:
  37590. + /* In case we were forced against our will to halt a
  37591. + * bulk endpoint, clear the halt now. (The SuperH UDC
  37592. + * requires this.) */
  37593. + if (test_and_clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags))
  37594. + usb_ep_clear_halt(fsg->bulk_in);
  37595. +
  37596. + if (transport_is_bbb()) {
  37597. + if (fsg->ep0_req_tag == exception_req_tag)
  37598. + ep0_queue(fsg); // Complete the status stage
  37599. +
  37600. + } else if (transport_is_cbi())
  37601. + send_status(fsg); // Status by interrupt pipe
  37602. +
  37603. + /* Technically this should go here, but it would only be
  37604. + * a waste of time. Ditto for the INTERFACE_CHANGE and
  37605. + * CONFIG_CHANGE cases. */
  37606. + // for (i = 0; i < fsg->nluns; ++i)
  37607. + // fsg->luns[i].unit_attention_data = SS_RESET_OCCURRED;
  37608. + break;
  37609. +
  37610. + case FSG_STATE_INTERFACE_CHANGE:
  37611. + rc = do_set_interface(fsg, 0);
  37612. + if (fsg->ep0_req_tag != exception_req_tag)
  37613. + break;
  37614. + if (rc != 0) // STALL on errors
  37615. + fsg_set_halt(fsg, fsg->ep0);
  37616. + else // Complete the status stage
  37617. + ep0_queue(fsg);
  37618. + break;
  37619. +
  37620. + case FSG_STATE_CONFIG_CHANGE:
  37621. + rc = do_set_config(fsg, new_config);
  37622. + if (fsg->ep0_req_tag != exception_req_tag)
  37623. + break;
  37624. + if (rc != 0) // STALL on errors
  37625. + fsg_set_halt(fsg, fsg->ep0);
  37626. + else // Complete the status stage
  37627. + ep0_queue(fsg);
  37628. + break;
  37629. +
  37630. + case FSG_STATE_DISCONNECT:
  37631. + for (i = 0; i < fsg->nluns; ++i)
  37632. + fsg_lun_fsync_sub(fsg->luns + i);
  37633. + do_set_config(fsg, 0); // Unconfigured state
  37634. + break;
  37635. +
  37636. + case FSG_STATE_EXIT:
  37637. + case FSG_STATE_TERMINATED:
  37638. + do_set_config(fsg, 0); // Free resources
  37639. + spin_lock_irq(&fsg->lock);
  37640. + fsg->state = FSG_STATE_TERMINATED; // Stop the thread
  37641. + spin_unlock_irq(&fsg->lock);
  37642. + break;
  37643. + }
  37644. +}
  37645. +
  37646. +
  37647. +/*-------------------------------------------------------------------------*/
  37648. +
  37649. +static int fsg_main_thread(void *fsg_)
  37650. +{
  37651. + struct fsg_dev *fsg = fsg_;
  37652. +
  37653. + /* Allow the thread to be killed by a signal, but set the signal mask
  37654. + * to block everything but INT, TERM, KILL, and USR1. */
  37655. + allow_signal(SIGINT);
  37656. + allow_signal(SIGTERM);
  37657. + allow_signal(SIGKILL);
  37658. + allow_signal(SIGUSR1);
  37659. +
  37660. + /* Allow the thread to be frozen */
  37661. + set_freezable();
  37662. +
  37663. + /* Arrange for userspace references to be interpreted as kernel
  37664. + * pointers. That way we can pass a kernel pointer to a routine
  37665. + * that expects a __user pointer and it will work okay. */
  37666. + set_fs(get_ds());
  37667. +
  37668. + /* The main loop */
  37669. + while (fsg->state != FSG_STATE_TERMINATED) {
  37670. + if (exception_in_progress(fsg) || signal_pending(current)) {
  37671. + handle_exception(fsg);
  37672. + continue;
  37673. + }
  37674. +
  37675. + if (!fsg->running) {
  37676. + sleep_thread(fsg);
  37677. + continue;
  37678. + }
  37679. +
  37680. + if (get_next_command(fsg))
  37681. + continue;
  37682. +
  37683. + spin_lock_irq(&fsg->lock);
  37684. + if (!exception_in_progress(fsg))
  37685. + fsg->state = FSG_STATE_DATA_PHASE;
  37686. + spin_unlock_irq(&fsg->lock);
  37687. +
  37688. + if (do_scsi_command(fsg) || finish_reply(fsg))
  37689. + continue;
  37690. +
  37691. + spin_lock_irq(&fsg->lock);
  37692. + if (!exception_in_progress(fsg))
  37693. + fsg->state = FSG_STATE_STATUS_PHASE;
  37694. + spin_unlock_irq(&fsg->lock);
  37695. +
  37696. + if (send_status(fsg))
  37697. + continue;
  37698. +
  37699. + spin_lock_irq(&fsg->lock);
  37700. + if (!exception_in_progress(fsg))
  37701. + fsg->state = FSG_STATE_IDLE;
  37702. + spin_unlock_irq(&fsg->lock);
  37703. + }
  37704. +
  37705. + spin_lock_irq(&fsg->lock);
  37706. + fsg->thread_task = NULL;
  37707. + spin_unlock_irq(&fsg->lock);
  37708. +
  37709. + /* If we are exiting because of a signal, unregister the
  37710. + * gadget driver. */
  37711. + if (test_and_clear_bit(REGISTERED, &fsg->atomic_bitflags))
  37712. + usb_gadget_unregister_driver(&fsg_driver);
  37713. +
  37714. + /* Let the unbind and cleanup routines know the thread has exited */
  37715. + complete_and_exit(&fsg->thread_notifier, 0);
  37716. +}
  37717. +
  37718. +
  37719. +/*-------------------------------------------------------------------------*/
  37720. +
  37721. +
  37722. +/* The write permissions and store_xxx pointers are set in fsg_bind() */
  37723. +static DEVICE_ATTR(ro, 0444, fsg_show_ro, NULL);
  37724. +static DEVICE_ATTR(nofua, 0644, fsg_show_nofua, NULL);
  37725. +static DEVICE_ATTR(file, 0444, fsg_show_file, NULL);
  37726. +
  37727. +
  37728. +/*-------------------------------------------------------------------------*/
  37729. +
  37730. +static void fsg_release(struct kref *ref)
  37731. +{
  37732. + struct fsg_dev *fsg = container_of(ref, struct fsg_dev, ref);
  37733. +
  37734. + kfree(fsg->luns);
  37735. + kfree(fsg);
  37736. +}
  37737. +
  37738. +static void lun_release(struct device *dev)
  37739. +{
  37740. + struct rw_semaphore *filesem = dev_get_drvdata(dev);
  37741. + struct fsg_dev *fsg =
  37742. + container_of(filesem, struct fsg_dev, filesem);
  37743. +
  37744. + kref_put(&fsg->ref, fsg_release);
  37745. +}
  37746. +
  37747. +static void /* __init_or_exit */ fsg_unbind(struct usb_gadget *gadget)
  37748. +{
  37749. + struct fsg_dev *fsg = get_gadget_data(gadget);
  37750. + int i;
  37751. + struct fsg_lun *curlun;
  37752. + struct usb_request *req = fsg->ep0req;
  37753. +
  37754. + DBG(fsg, "unbind\n");
  37755. + clear_bit(REGISTERED, &fsg->atomic_bitflags);
  37756. +
  37757. + /* If the thread isn't already dead, tell it to exit now */
  37758. + if (fsg->state != FSG_STATE_TERMINATED) {
  37759. + raise_exception(fsg, FSG_STATE_EXIT);
  37760. + wait_for_completion(&fsg->thread_notifier);
  37761. +
  37762. + /* The cleanup routine waits for this completion also */
  37763. + complete(&fsg->thread_notifier);
  37764. + }
  37765. +
  37766. + /* Unregister the sysfs attribute files and the LUNs */
  37767. + for (i = 0; i < fsg->nluns; ++i) {
  37768. + curlun = &fsg->luns[i];
  37769. + if (curlun->registered) {
  37770. + device_remove_file(&curlun->dev, &dev_attr_nofua);
  37771. + device_remove_file(&curlun->dev, &dev_attr_ro);
  37772. + device_remove_file(&curlun->dev, &dev_attr_file);
  37773. + fsg_lun_close(curlun);
  37774. + device_unregister(&curlun->dev);
  37775. + curlun->registered = 0;
  37776. + }
  37777. + }
  37778. +
  37779. + /* Free the data buffers */
  37780. + for (i = 0; i < fsg_num_buffers; ++i)
  37781. + kfree(fsg->buffhds[i].buf);
  37782. +
  37783. + /* Free the request and buffer for endpoint 0 */
  37784. + if (req) {
  37785. + kfree(req->buf);
  37786. + usb_ep_free_request(fsg->ep0, req);
  37787. + }
  37788. +
  37789. + set_gadget_data(gadget, NULL);
  37790. +}
  37791. +
  37792. +
  37793. +static int __init check_parameters(struct fsg_dev *fsg)
  37794. +{
  37795. + int prot;
  37796. + int gcnum;
  37797. +
  37798. + /* Store the default values */
  37799. + mod_data.transport_type = USB_PR_BULK;
  37800. + mod_data.transport_name = "Bulk-only";
  37801. + mod_data.protocol_type = USB_SC_SCSI;
  37802. + mod_data.protocol_name = "Transparent SCSI";
  37803. +
  37804. + /* Some peripheral controllers are known not to be able to
  37805. + * halt bulk endpoints correctly. If one of them is present,
  37806. + * disable stalls.
  37807. + */
  37808. + if (gadget_is_at91(fsg->gadget))
  37809. + mod_data.can_stall = 0;
  37810. +
  37811. + if (mod_data.release == 0xffff) { // Parameter wasn't set
  37812. + gcnum = usb_gadget_controller_number(fsg->gadget);
  37813. + if (gcnum >= 0)
  37814. + mod_data.release = 0x0300 + gcnum;
  37815. + else {
  37816. + WARNING(fsg, "controller '%s' not recognized\n",
  37817. + fsg->gadget->name);
  37818. + mod_data.release = 0x0399;
  37819. + }
  37820. + }
  37821. +
  37822. + prot = simple_strtol(mod_data.protocol_parm, NULL, 0);
  37823. +
  37824. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  37825. + if (strnicmp(mod_data.transport_parm, "BBB", 10) == 0) {
  37826. + ; // Use default setting
  37827. + } else if (strnicmp(mod_data.transport_parm, "CB", 10) == 0) {
  37828. + mod_data.transport_type = USB_PR_CB;
  37829. + mod_data.transport_name = "Control-Bulk";
  37830. + } else if (strnicmp(mod_data.transport_parm, "CBI", 10) == 0) {
  37831. + mod_data.transport_type = USB_PR_CBI;
  37832. + mod_data.transport_name = "Control-Bulk-Interrupt";
  37833. + } else {
  37834. + ERROR(fsg, "invalid transport: %s\n", mod_data.transport_parm);
  37835. + return -EINVAL;
  37836. + }
  37837. +
  37838. + if (strnicmp(mod_data.protocol_parm, "SCSI", 10) == 0 ||
  37839. + prot == USB_SC_SCSI) {
  37840. + ; // Use default setting
  37841. + } else if (strnicmp(mod_data.protocol_parm, "RBC", 10) == 0 ||
  37842. + prot == USB_SC_RBC) {
  37843. + mod_data.protocol_type = USB_SC_RBC;
  37844. + mod_data.protocol_name = "RBC";
  37845. + } else if (strnicmp(mod_data.protocol_parm, "8020", 4) == 0 ||
  37846. + strnicmp(mod_data.protocol_parm, "ATAPI", 10) == 0 ||
  37847. + prot == USB_SC_8020) {
  37848. + mod_data.protocol_type = USB_SC_8020;
  37849. + mod_data.protocol_name = "8020i (ATAPI)";
  37850. + } else if (strnicmp(mod_data.protocol_parm, "QIC", 3) == 0 ||
  37851. + prot == USB_SC_QIC) {
  37852. + mod_data.protocol_type = USB_SC_QIC;
  37853. + mod_data.protocol_name = "QIC-157";
  37854. + } else if (strnicmp(mod_data.protocol_parm, "UFI", 10) == 0 ||
  37855. + prot == USB_SC_UFI) {
  37856. + mod_data.protocol_type = USB_SC_UFI;
  37857. + mod_data.protocol_name = "UFI";
  37858. + } else if (strnicmp(mod_data.protocol_parm, "8070", 4) == 0 ||
  37859. + prot == USB_SC_8070) {
  37860. + mod_data.protocol_type = USB_SC_8070;
  37861. + mod_data.protocol_name = "8070i";
  37862. + } else {
  37863. + ERROR(fsg, "invalid protocol: %s\n", mod_data.protocol_parm);
  37864. + return -EINVAL;
  37865. + }
  37866. +
  37867. + mod_data.buflen &= PAGE_CACHE_MASK;
  37868. + if (mod_data.buflen <= 0) {
  37869. + ERROR(fsg, "invalid buflen\n");
  37870. + return -ETOOSMALL;
  37871. + }
  37872. +
  37873. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  37874. +
  37875. + /* Serial string handling.
  37876. + * On a real device, the serial string would be loaded
  37877. + * from permanent storage. */
  37878. + if (mod_data.serial) {
  37879. + const char *ch;
  37880. + unsigned len = 0;
  37881. +
  37882. + /* Sanity check :
  37883. + * The CB[I] specification limits the serial string to
  37884. + * 12 uppercase hexadecimal characters.
  37885. + * BBB need at least 12 uppercase hexadecimal characters,
  37886. + * with a maximum of 126. */
  37887. + for (ch = mod_data.serial; *ch; ++ch) {
  37888. + ++len;
  37889. + if ((*ch < '0' || *ch > '9') &&
  37890. + (*ch < 'A' || *ch > 'F')) { /* not uppercase hex */
  37891. + WARNING(fsg,
  37892. + "Invalid serial string character: %c\n",
  37893. + *ch);
  37894. + goto no_serial;
  37895. + }
  37896. + }
  37897. + if (len > 126 ||
  37898. + (mod_data.transport_type == USB_PR_BULK && len < 12) ||
  37899. + (mod_data.transport_type != USB_PR_BULK && len > 12)) {
  37900. + WARNING(fsg, "Invalid serial string length!\n");
  37901. + goto no_serial;
  37902. + }
  37903. + fsg_strings[FSG_STRING_SERIAL - 1].s = mod_data.serial;
  37904. + } else {
  37905. + WARNING(fsg, "No serial-number string provided!\n");
  37906. + no_serial:
  37907. + device_desc.iSerialNumber = 0;
  37908. + }
  37909. +
  37910. + return 0;
  37911. +}
  37912. +
  37913. +
  37914. +static int __init fsg_bind(struct usb_gadget *gadget)
  37915. +{
  37916. + struct fsg_dev *fsg = the_fsg;
  37917. + int rc;
  37918. + int i;
  37919. + struct fsg_lun *curlun;
  37920. + struct usb_ep *ep;
  37921. + struct usb_request *req;
  37922. + char *pathbuf, *p;
  37923. +
  37924. + fsg->gadget = gadget;
  37925. + set_gadget_data(gadget, fsg);
  37926. + fsg->ep0 = gadget->ep0;
  37927. + fsg->ep0->driver_data = fsg;
  37928. +
  37929. + if ((rc = check_parameters(fsg)) != 0)
  37930. + goto out;
  37931. +
  37932. + if (mod_data.removable) { // Enable the store_xxx attributes
  37933. + dev_attr_file.attr.mode = 0644;
  37934. + dev_attr_file.store = fsg_store_file;
  37935. + if (!mod_data.cdrom) {
  37936. + dev_attr_ro.attr.mode = 0644;
  37937. + dev_attr_ro.store = fsg_store_ro;
  37938. + }
  37939. + }
  37940. +
  37941. + /* Only for removable media? */
  37942. + dev_attr_nofua.attr.mode = 0644;
  37943. + dev_attr_nofua.store = fsg_store_nofua;
  37944. +
  37945. + /* Find out how many LUNs there should be */
  37946. + i = mod_data.nluns;
  37947. + if (i == 0)
  37948. + i = max(mod_data.num_filenames, 1u);
  37949. + if (i > FSG_MAX_LUNS) {
  37950. + ERROR(fsg, "invalid number of LUNs: %d\n", i);
  37951. + rc = -EINVAL;
  37952. + goto out;
  37953. + }
  37954. +
  37955. + /* Create the LUNs, open their backing files, and register the
  37956. + * LUN devices in sysfs. */
  37957. + fsg->luns = kzalloc(i * sizeof(struct fsg_lun), GFP_KERNEL);
  37958. + if (!fsg->luns) {
  37959. + rc = -ENOMEM;
  37960. + goto out;
  37961. + }
  37962. + fsg->nluns = i;
  37963. +
  37964. + for (i = 0; i < fsg->nluns; ++i) {
  37965. + curlun = &fsg->luns[i];
  37966. + curlun->cdrom = !!mod_data.cdrom;
  37967. + curlun->ro = mod_data.cdrom || mod_data.ro[i];
  37968. + curlun->initially_ro = curlun->ro;
  37969. + curlun->removable = mod_data.removable;
  37970. + curlun->nofua = mod_data.nofua[i];
  37971. + curlun->dev.release = lun_release;
  37972. + curlun->dev.parent = &gadget->dev;
  37973. + curlun->dev.driver = &fsg_driver.driver;
  37974. + dev_set_drvdata(&curlun->dev, &fsg->filesem);
  37975. + dev_set_name(&curlun->dev,"%s-lun%d",
  37976. + dev_name(&gadget->dev), i);
  37977. +
  37978. + kref_get(&fsg->ref);
  37979. + rc = device_register(&curlun->dev);
  37980. + if (rc) {
  37981. + INFO(fsg, "failed to register LUN%d: %d\n", i, rc);
  37982. + put_device(&curlun->dev);
  37983. + goto out;
  37984. + }
  37985. + curlun->registered = 1;
  37986. +
  37987. + rc = device_create_file(&curlun->dev, &dev_attr_ro);
  37988. + if (rc)
  37989. + goto out;
  37990. + rc = device_create_file(&curlun->dev, &dev_attr_nofua);
  37991. + if (rc)
  37992. + goto out;
  37993. + rc = device_create_file(&curlun->dev, &dev_attr_file);
  37994. + if (rc)
  37995. + goto out;
  37996. +
  37997. + if (mod_data.file[i] && *mod_data.file[i]) {
  37998. + rc = fsg_lun_open(curlun, mod_data.file[i]);
  37999. + if (rc)
  38000. + goto out;
  38001. + } else if (!mod_data.removable) {
  38002. + ERROR(fsg, "no file given for LUN%d\n", i);
  38003. + rc = -EINVAL;
  38004. + goto out;
  38005. + }
  38006. + }
  38007. +
  38008. + /* Find all the endpoints we will use */
  38009. + usb_ep_autoconfig_reset(gadget);
  38010. + ep = usb_ep_autoconfig(gadget, &fsg_fs_bulk_in_desc);
  38011. + if (!ep)
  38012. + goto autoconf_fail;
  38013. + ep->driver_data = fsg; // claim the endpoint
  38014. + fsg->bulk_in = ep;
  38015. +
  38016. + ep = usb_ep_autoconfig(gadget, &fsg_fs_bulk_out_desc);
  38017. + if (!ep)
  38018. + goto autoconf_fail;
  38019. + ep->driver_data = fsg; // claim the endpoint
  38020. + fsg->bulk_out = ep;
  38021. +
  38022. + if (transport_is_cbi()) {
  38023. + ep = usb_ep_autoconfig(gadget, &fsg_fs_intr_in_desc);
  38024. + if (!ep)
  38025. + goto autoconf_fail;
  38026. + ep->driver_data = fsg; // claim the endpoint
  38027. + fsg->intr_in = ep;
  38028. + }
  38029. +
  38030. + /* Fix up the descriptors */
  38031. + device_desc.idVendor = cpu_to_le16(mod_data.vendor);
  38032. + device_desc.idProduct = cpu_to_le16(mod_data.product);
  38033. + device_desc.bcdDevice = cpu_to_le16(mod_data.release);
  38034. +
  38035. + i = (transport_is_cbi() ? 3 : 2); // Number of endpoints
  38036. + fsg_intf_desc.bNumEndpoints = i;
  38037. + fsg_intf_desc.bInterfaceSubClass = mod_data.protocol_type;
  38038. + fsg_intf_desc.bInterfaceProtocol = mod_data.transport_type;
  38039. + fsg_fs_function[i + FSG_FS_FUNCTION_PRE_EP_ENTRIES] = NULL;
  38040. +
  38041. + if (gadget_is_dualspeed(gadget)) {
  38042. + fsg_hs_function[i + FSG_HS_FUNCTION_PRE_EP_ENTRIES] = NULL;
  38043. +
  38044. + /* Assume endpoint addresses are the same for both speeds */
  38045. + fsg_hs_bulk_in_desc.bEndpointAddress =
  38046. + fsg_fs_bulk_in_desc.bEndpointAddress;
  38047. + fsg_hs_bulk_out_desc.bEndpointAddress =
  38048. + fsg_fs_bulk_out_desc.bEndpointAddress;
  38049. + fsg_hs_intr_in_desc.bEndpointAddress =
  38050. + fsg_fs_intr_in_desc.bEndpointAddress;
  38051. + }
  38052. +
  38053. + if (gadget_is_superspeed(gadget)) {
  38054. + unsigned max_burst;
  38055. +
  38056. + fsg_ss_function[i + FSG_SS_FUNCTION_PRE_EP_ENTRIES] = NULL;
  38057. +
  38058. + /* Calculate bMaxBurst, we know packet size is 1024 */
  38059. + max_burst = min_t(unsigned, mod_data.buflen / 1024, 15);
  38060. +
  38061. + /* Assume endpoint addresses are the same for both speeds */
  38062. + fsg_ss_bulk_in_desc.bEndpointAddress =
  38063. + fsg_fs_bulk_in_desc.bEndpointAddress;
  38064. + fsg_ss_bulk_in_comp_desc.bMaxBurst = max_burst;
  38065. +
  38066. + fsg_ss_bulk_out_desc.bEndpointAddress =
  38067. + fsg_fs_bulk_out_desc.bEndpointAddress;
  38068. + fsg_ss_bulk_out_comp_desc.bMaxBurst = max_burst;
  38069. + }
  38070. +
  38071. + if (gadget_is_otg(gadget))
  38072. + fsg_otg_desc.bmAttributes |= USB_OTG_HNP;
  38073. +
  38074. + rc = -ENOMEM;
  38075. +
  38076. + /* Allocate the request and buffer for endpoint 0 */
  38077. + fsg->ep0req = req = usb_ep_alloc_request(fsg->ep0, GFP_KERNEL);
  38078. + if (!req)
  38079. + goto out;
  38080. + req->buf = kmalloc(EP0_BUFSIZE, GFP_KERNEL);
  38081. + if (!req->buf)
  38082. + goto out;
  38083. + req->complete = ep0_complete;
  38084. +
  38085. + /* Allocate the data buffers */
  38086. + for (i = 0; i < fsg_num_buffers; ++i) {
  38087. + struct fsg_buffhd *bh = &fsg->buffhds[i];
  38088. +
  38089. + /* Allocate for the bulk-in endpoint. We assume that
  38090. + * the buffer will also work with the bulk-out (and
  38091. + * interrupt-in) endpoint. */
  38092. + bh->buf = kmalloc(mod_data.buflen, GFP_KERNEL);
  38093. + if (!bh->buf)
  38094. + goto out;
  38095. + bh->next = bh + 1;
  38096. + }
  38097. + fsg->buffhds[fsg_num_buffers - 1].next = &fsg->buffhds[0];
  38098. +
  38099. + /* This should reflect the actual gadget power source */
  38100. + usb_gadget_set_selfpowered(gadget);
  38101. +
  38102. + snprintf(fsg_string_manufacturer, sizeof fsg_string_manufacturer,
  38103. + "%s %s with %s",
  38104. + init_utsname()->sysname, init_utsname()->release,
  38105. + gadget->name);
  38106. +
  38107. + fsg->thread_task = kthread_create(fsg_main_thread, fsg,
  38108. + "file-storage-gadget");
  38109. + if (IS_ERR(fsg->thread_task)) {
  38110. + rc = PTR_ERR(fsg->thread_task);
  38111. + goto out;
  38112. + }
  38113. +
  38114. + INFO(fsg, DRIVER_DESC ", version: " DRIVER_VERSION "\n");
  38115. + INFO(fsg, "NOTE: This driver is deprecated. "
  38116. + "Consider using g_mass_storage instead.\n");
  38117. + INFO(fsg, "Number of LUNs=%d\n", fsg->nluns);
  38118. +
  38119. + pathbuf = kmalloc(PATH_MAX, GFP_KERNEL);
  38120. + for (i = 0; i < fsg->nluns; ++i) {
  38121. + curlun = &fsg->luns[i];
  38122. + if (fsg_lun_is_open(curlun)) {
  38123. + p = NULL;
  38124. + if (pathbuf) {
  38125. + p = d_path(&curlun->filp->f_path,
  38126. + pathbuf, PATH_MAX);
  38127. + if (IS_ERR(p))
  38128. + p = NULL;
  38129. + }
  38130. + LINFO(curlun, "ro=%d, nofua=%d, file: %s\n",
  38131. + curlun->ro, curlun->nofua, (p ? p : "(error)"));
  38132. + }
  38133. + }
  38134. + kfree(pathbuf);
  38135. +
  38136. + DBG(fsg, "transport=%s (x%02x)\n",
  38137. + mod_data.transport_name, mod_data.transport_type);
  38138. + DBG(fsg, "protocol=%s (x%02x)\n",
  38139. + mod_data.protocol_name, mod_data.protocol_type);
  38140. + DBG(fsg, "VendorID=x%04x, ProductID=x%04x, Release=x%04x\n",
  38141. + mod_data.vendor, mod_data.product, mod_data.release);
  38142. + DBG(fsg, "removable=%d, stall=%d, cdrom=%d, buflen=%u\n",
  38143. + mod_data.removable, mod_data.can_stall,
  38144. + mod_data.cdrom, mod_data.buflen);
  38145. + DBG(fsg, "I/O thread pid: %d\n", task_pid_nr(fsg->thread_task));
  38146. +
  38147. + set_bit(REGISTERED, &fsg->atomic_bitflags);
  38148. +
  38149. + /* Tell the thread to start working */
  38150. + wake_up_process(fsg->thread_task);
  38151. + return 0;
  38152. +
  38153. +autoconf_fail:
  38154. + ERROR(fsg, "unable to autoconfigure all endpoints\n");
  38155. + rc = -ENOTSUPP;
  38156. +
  38157. +out:
  38158. + fsg->state = FSG_STATE_TERMINATED; // The thread is dead
  38159. + fsg_unbind(gadget);
  38160. + complete(&fsg->thread_notifier);
  38161. + return rc;
  38162. +}
  38163. +
  38164. +
  38165. +/*-------------------------------------------------------------------------*/
  38166. +
  38167. +static void fsg_suspend(struct usb_gadget *gadget)
  38168. +{
  38169. + struct fsg_dev *fsg = get_gadget_data(gadget);
  38170. +
  38171. + DBG(fsg, "suspend\n");
  38172. + set_bit(SUSPENDED, &fsg->atomic_bitflags);
  38173. +}
  38174. +
  38175. +static void fsg_resume(struct usb_gadget *gadget)
  38176. +{
  38177. + struct fsg_dev *fsg = get_gadget_data(gadget);
  38178. +
  38179. + DBG(fsg, "resume\n");
  38180. + clear_bit(SUSPENDED, &fsg->atomic_bitflags);
  38181. +}
  38182. +
  38183. +
  38184. +/*-------------------------------------------------------------------------*/
  38185. +
  38186. +static struct usb_gadget_driver fsg_driver = {
  38187. + .max_speed = USB_SPEED_SUPER,
  38188. + .function = (char *) fsg_string_product,
  38189. + .unbind = fsg_unbind,
  38190. + .disconnect = fsg_disconnect,
  38191. + .setup = fsg_setup,
  38192. + .suspend = fsg_suspend,
  38193. + .resume = fsg_resume,
  38194. +
  38195. + .driver = {
  38196. + .name = DRIVER_NAME,
  38197. + .owner = THIS_MODULE,
  38198. + // .release = ...
  38199. + // .suspend = ...
  38200. + // .resume = ...
  38201. + },
  38202. +};
  38203. +
  38204. +
  38205. +static int __init fsg_alloc(void)
  38206. +{
  38207. + struct fsg_dev *fsg;
  38208. +
  38209. + fsg = kzalloc(sizeof *fsg +
  38210. + fsg_num_buffers * sizeof *(fsg->buffhds), GFP_KERNEL);
  38211. +
  38212. + if (!fsg)
  38213. + return -ENOMEM;
  38214. + spin_lock_init(&fsg->lock);
  38215. + init_rwsem(&fsg->filesem);
  38216. + kref_init(&fsg->ref);
  38217. + init_completion(&fsg->thread_notifier);
  38218. +
  38219. + the_fsg = fsg;
  38220. + return 0;
  38221. +}
  38222. +
  38223. +
  38224. +static int __init fsg_init(void)
  38225. +{
  38226. + int rc;
  38227. + struct fsg_dev *fsg;
  38228. +
  38229. + rc = fsg_num_buffers_validate();
  38230. + if (rc != 0)
  38231. + return rc;
  38232. +
  38233. + if ((rc = fsg_alloc()) != 0)
  38234. + return rc;
  38235. + fsg = the_fsg;
  38236. + if ((rc = usb_gadget_probe_driver(&fsg_driver, fsg_bind)) != 0)
  38237. + kref_put(&fsg->ref, fsg_release);
  38238. + return rc;
  38239. +}
  38240. +module_init(fsg_init);
  38241. +
  38242. +
  38243. +static void __exit fsg_cleanup(void)
  38244. +{
  38245. + struct fsg_dev *fsg = the_fsg;
  38246. +
  38247. + /* Unregister the driver iff the thread hasn't already done so */
  38248. + if (test_and_clear_bit(REGISTERED, &fsg->atomic_bitflags))
  38249. + usb_gadget_unregister_driver(&fsg_driver);
  38250. +
  38251. + /* Wait for the thread to finish up */
  38252. + wait_for_completion(&fsg->thread_notifier);
  38253. +
  38254. + kref_put(&fsg->ref, fsg_release);
  38255. +}
  38256. +module_exit(fsg_cleanup);
  38257. diff -Nur linux-3.13.11/drivers/usb/gadget/u_serial.c linux-rpi/drivers/usb/gadget/u_serial.c
  38258. --- linux-3.13.11/drivers/usb/gadget/u_serial.c 2014-04-23 01:49:33.000000000 +0200
  38259. +++ linux-rpi/drivers/usb/gadget/u_serial.c 2014-04-24 15:35:04.165565687 +0200
  38260. @@ -549,8 +549,8 @@
  38261. port->read_started--;
  38262. }
  38263. - /* Push from tty to ldisc; this is handled by a workqueue,
  38264. - * so we won't get callbacks and can hold port_lock
  38265. + /* Push from tty to ldisc; without low_latency set this is handled by
  38266. + * a workqueue, so we won't get callbacks and can hold port_lock
  38267. */
  38268. if (do_push)
  38269. tty_flip_buffer_push(&port->port);
  38270. diff -Nur linux-3.13.11/drivers/usb/host/dwc_common_port/changes.txt linux-rpi/drivers/usb/host/dwc_common_port/changes.txt
  38271. --- linux-3.13.11/drivers/usb/host/dwc_common_port/changes.txt 1970-01-01 01:00:00.000000000 +0100
  38272. +++ linux-rpi/drivers/usb/host/dwc_common_port/changes.txt 2014-04-24 15:35:04.169565731 +0200
  38273. @@ -0,0 +1,174 @@
  38274. +
  38275. +dwc_read_reg32() and friends now take an additional parameter, a pointer to an
  38276. +IO context struct. The IO context struct should live in an os-dependent struct
  38277. +in your driver. As an example, the dwc_usb3 driver has an os-dependent struct
  38278. +named 'os_dep' embedded in the main device struct. So there these calls look
  38279. +like this:
  38280. +
  38281. + dwc_read_reg32(&usb3_dev->os_dep.ioctx, &pcd->dev_global_regs->dcfg);
  38282. +
  38283. + dwc_write_reg32(&usb3_dev->os_dep.ioctx,
  38284. + &pcd->dev_global_regs->dcfg, 0);
  38285. +
  38286. +Note that for the existing Linux driver ports, it is not necessary to actually
  38287. +define the 'ioctx' member in the os-dependent struct. Since Linux does not
  38288. +require an IO context, its macros for dwc_read_reg32() and friends do not
  38289. +use the context pointer, so it is optimized away by the compiler. But it is
  38290. +necessary to add the pointer parameter to all of the call sites, to be ready
  38291. +for any future ports (such as FreeBSD) which do require an IO context.
  38292. +
  38293. +
  38294. +Similarly, dwc_alloc(), dwc_alloc_atomic(), dwc_strdup(), and dwc_free() now
  38295. +take an additional parameter, a pointer to a memory context. Examples:
  38296. +
  38297. + addr = dwc_alloc(&usb3_dev->os_dep.memctx, size);
  38298. +
  38299. + dwc_free(&usb3_dev->os_dep.memctx, addr);
  38300. +
  38301. +Again, for the Linux ports, it is not necessary to actually define the memctx
  38302. +member, but it is necessary to add the pointer parameter to all of the call
  38303. +sites.
  38304. +
  38305. +
  38306. +Same for dwc_dma_alloc() and dwc_dma_free(). Examples:
  38307. +
  38308. + virt_addr = dwc_dma_alloc(&usb3_dev->os_dep.dmactx, size, &phys_addr);
  38309. +
  38310. + dwc_dma_free(&usb3_dev->os_dep.dmactx, size, virt_addr, phys_addr);
  38311. +
  38312. +
  38313. +Same for dwc_mutex_alloc() and dwc_mutex_free(). Examples:
  38314. +
  38315. + mutex = dwc_mutex_alloc(&usb3_dev->os_dep.mtxctx);
  38316. +
  38317. + dwc_mutex_free(&usb3_dev->os_dep.mtxctx, mutex);
  38318. +
  38319. +
  38320. +Same for dwc_spinlock_alloc() and dwc_spinlock_free(). Examples:
  38321. +
  38322. + lock = dwc_spinlock_alloc(&usb3_dev->osdep.splctx);
  38323. +
  38324. + dwc_spinlock_free(&usb3_dev->osdep.splctx, lock);
  38325. +
  38326. +
  38327. +Same for dwc_timer_alloc(). Example:
  38328. +
  38329. + timer = dwc_timer_alloc(&usb3_dev->os_dep.tmrctx, "dwc_usb3_tmr1",
  38330. + cb_func, cb_data);
  38331. +
  38332. +
  38333. +Same for dwc_waitq_alloc(). Example:
  38334. +
  38335. + waitq = dwc_waitq_alloc(&usb3_dev->os_dep.wtqctx);
  38336. +
  38337. +
  38338. +Same for dwc_thread_run(). Example:
  38339. +
  38340. + thread = dwc_thread_run(&usb3_dev->os_dep.thdctx, func,
  38341. + "dwc_usb3_thd1", data);
  38342. +
  38343. +
  38344. +Same for dwc_workq_alloc(). Example:
  38345. +
  38346. + workq = dwc_workq_alloc(&usb3_dev->osdep.wkqctx, "dwc_usb3_wkq1");
  38347. +
  38348. +
  38349. +Same for dwc_task_alloc(). Example:
  38350. +
  38351. + task = dwc_task_alloc(&usb3_dev->os_dep.tskctx, "dwc_usb3_tsk1",
  38352. + cb_func, cb_data);
  38353. +
  38354. +
  38355. +In addition to the context pointer additions, a few core functions have had
  38356. +other changes made to their parameters:
  38357. +
  38358. +The 'flags' parameter to dwc_spinlock_irqsave() and dwc_spinunlock_irqrestore()
  38359. +has been changed from a uint64_t to a dwc_irqflags_t.
  38360. +
  38361. +dwc_thread_should_stop() now takes a 'dwc_thread_t *' parameter, because the
  38362. +FreeBSD equivalent of that function requires it.
  38363. +
  38364. +And, in addition to the context pointer, dwc_task_alloc() also adds a
  38365. +'char *name' parameter, to be consistent with dwc_thread_run() and
  38366. +dwc_workq_alloc(), and because the FreeBSD equivalent of that function
  38367. +requires a unique name.
  38368. +
  38369. +
  38370. +Here is a complete list of the core functions that now take a pointer to a
  38371. +context as their first parameter:
  38372. +
  38373. + dwc_read_reg32
  38374. + dwc_read_reg64
  38375. + dwc_write_reg32
  38376. + dwc_write_reg64
  38377. + dwc_modify_reg32
  38378. + dwc_modify_reg64
  38379. + dwc_alloc
  38380. + dwc_alloc_atomic
  38381. + dwc_strdup
  38382. + dwc_free
  38383. + dwc_dma_alloc
  38384. + dwc_dma_free
  38385. + dwc_mutex_alloc
  38386. + dwc_mutex_free
  38387. + dwc_spinlock_alloc
  38388. + dwc_spinlock_free
  38389. + dwc_timer_alloc
  38390. + dwc_waitq_alloc
  38391. + dwc_thread_run
  38392. + dwc_workq_alloc
  38393. + dwc_task_alloc Also adds a 'char *name' as its 2nd parameter
  38394. +
  38395. +And here are the core functions that have other changes to their parameters:
  38396. +
  38397. + dwc_spinlock_irqsave 'flags' param is now a 'dwc_irqflags_t *'
  38398. + dwc_spinunlock_irqrestore 'flags' param is now a 'dwc_irqflags_t'
  38399. + dwc_thread_should_stop Adds a 'dwc_thread_t *' parameter
  38400. +
  38401. +
  38402. +
  38403. +The changes to the core functions also require some of the other library
  38404. +functions to change:
  38405. +
  38406. + dwc_cc_if_alloc() and dwc_cc_if_free() now take a 'void *memctx'
  38407. + (for memory allocation) as the 1st param and a 'void *mtxctx'
  38408. + (for mutex allocation) as the 2nd param.
  38409. +
  38410. + dwc_cc_clear(), dwc_cc_add(), dwc_cc_change(), dwc_cc_remove(),
  38411. + dwc_cc_data_for_save(), and dwc_cc_restore_from_data() now take a
  38412. + 'void *memctx' as the 1st param.
  38413. +
  38414. + dwc_dh_modpow(), dwc_dh_pk(), and dwc_dh_derive_keys() now take a
  38415. + 'void *memctx' as the 1st param.
  38416. +
  38417. + dwc_modpow() now takes a 'void *memctx' as the 1st param.
  38418. +
  38419. + dwc_alloc_notification_manager() now takes a 'void *memctx' as the
  38420. + 1st param and a 'void *wkqctx' (for work queue allocation) as the 2nd
  38421. + param, and also now returns an integer value that is non-zero if
  38422. + allocation of its data structures or work queue fails.
  38423. +
  38424. + dwc_register_notifier() now takes a 'void *memctx' as the 1st param.
  38425. +
  38426. + dwc_memory_debug_start() now takes a 'void *mem_ctx' as the first
  38427. + param, and also now returns an integer value that is non-zero if
  38428. + allocation of its data structures fails.
  38429. +
  38430. +
  38431. +
  38432. +Other miscellaneous changes:
  38433. +
  38434. +The DEBUG_MEMORY and DEBUG_REGS #define's have been renamed to
  38435. +DWC_DEBUG_MEMORY and DWC_DEBUG_REGS.
  38436. +
  38437. +The following #define's have been added to allow selectively compiling library
  38438. +features:
  38439. +
  38440. + DWC_CCLIB
  38441. + DWC_CRYPTOLIB
  38442. + DWC_NOTIFYLIB
  38443. + DWC_UTFLIB
  38444. +
  38445. +A DWC_LIBMODULE #define has also been added. If this is not defined, then the
  38446. +module code in dwc_common_linux.c is not compiled in. This allows linking the
  38447. +library code directly into a driver module, instead of as a standalone module.
  38448. diff -Nur linux-3.13.11/drivers/usb/host/dwc_common_port/doc/doxygen.cfg linux-rpi/drivers/usb/host/dwc_common_port/doc/doxygen.cfg
  38449. --- linux-3.13.11/drivers/usb/host/dwc_common_port/doc/doxygen.cfg 1970-01-01 01:00:00.000000000 +0100
  38450. +++ linux-rpi/drivers/usb/host/dwc_common_port/doc/doxygen.cfg 2014-04-24 15:37:13.306990445 +0200
  38451. @@ -0,0 +1,270 @@
  38452. +# Doxyfile 1.4.5
  38453. +
  38454. +#---------------------------------------------------------------------------
  38455. +# Project related configuration options
  38456. +#---------------------------------------------------------------------------
  38457. +PROJECT_NAME = "Synopsys DWC Portability and Common Library for UWB"
  38458. +PROJECT_NUMBER =
  38459. +OUTPUT_DIRECTORY = doc
  38460. +CREATE_SUBDIRS = NO
  38461. +OUTPUT_LANGUAGE = English
  38462. +BRIEF_MEMBER_DESC = YES
  38463. +REPEAT_BRIEF = YES
  38464. +ABBREVIATE_BRIEF = "The $name class" \
  38465. + "The $name widget" \
  38466. + "The $name file" \
  38467. + is \
  38468. + provides \
  38469. + specifies \
  38470. + contains \
  38471. + represents \
  38472. + a \
  38473. + an \
  38474. + the
  38475. +ALWAYS_DETAILED_SEC = YES
  38476. +INLINE_INHERITED_MEMB = NO
  38477. +FULL_PATH_NAMES = NO
  38478. +STRIP_FROM_PATH = ..
  38479. +STRIP_FROM_INC_PATH =
  38480. +SHORT_NAMES = NO
  38481. +JAVADOC_AUTOBRIEF = YES
  38482. +MULTILINE_CPP_IS_BRIEF = NO
  38483. +DETAILS_AT_TOP = YES
  38484. +INHERIT_DOCS = YES
  38485. +SEPARATE_MEMBER_PAGES = NO
  38486. +TAB_SIZE = 8
  38487. +ALIASES =
  38488. +OPTIMIZE_OUTPUT_FOR_C = YES
  38489. +OPTIMIZE_OUTPUT_JAVA = NO
  38490. +BUILTIN_STL_SUPPORT = NO
  38491. +DISTRIBUTE_GROUP_DOC = NO
  38492. +SUBGROUPING = NO
  38493. +#---------------------------------------------------------------------------
  38494. +# Build related configuration options
  38495. +#---------------------------------------------------------------------------
  38496. +EXTRACT_ALL = NO
  38497. +EXTRACT_PRIVATE = NO
  38498. +EXTRACT_STATIC = YES
  38499. +EXTRACT_LOCAL_CLASSES = NO
  38500. +EXTRACT_LOCAL_METHODS = NO
  38501. +HIDE_UNDOC_MEMBERS = NO
  38502. +HIDE_UNDOC_CLASSES = NO
  38503. +HIDE_FRIEND_COMPOUNDS = NO
  38504. +HIDE_IN_BODY_DOCS = NO
  38505. +INTERNAL_DOCS = NO
  38506. +CASE_SENSE_NAMES = YES
  38507. +HIDE_SCOPE_NAMES = NO
  38508. +SHOW_INCLUDE_FILES = NO
  38509. +INLINE_INFO = YES
  38510. +SORT_MEMBER_DOCS = NO
  38511. +SORT_BRIEF_DOCS = NO
  38512. +SORT_BY_SCOPE_NAME = NO
  38513. +GENERATE_TODOLIST = YES
  38514. +GENERATE_TESTLIST = YES
  38515. +GENERATE_BUGLIST = YES
  38516. +GENERATE_DEPRECATEDLIST= YES
  38517. +ENABLED_SECTIONS =
  38518. +MAX_INITIALIZER_LINES = 30
  38519. +SHOW_USED_FILES = YES
  38520. +SHOW_DIRECTORIES = YES
  38521. +FILE_VERSION_FILTER =
  38522. +#---------------------------------------------------------------------------
  38523. +# configuration options related to warning and progress messages
  38524. +#---------------------------------------------------------------------------
  38525. +QUIET = YES
  38526. +WARNINGS = YES
  38527. +WARN_IF_UNDOCUMENTED = NO
  38528. +WARN_IF_DOC_ERROR = YES
  38529. +WARN_NO_PARAMDOC = YES
  38530. +WARN_FORMAT = "$file:$line: $text"
  38531. +WARN_LOGFILE =
  38532. +#---------------------------------------------------------------------------
  38533. +# configuration options related to the input files
  38534. +#---------------------------------------------------------------------------
  38535. +INPUT = .
  38536. +FILE_PATTERNS = *.c \
  38537. + *.cc \
  38538. + *.cxx \
  38539. + *.cpp \
  38540. + *.c++ \
  38541. + *.d \
  38542. + *.java \
  38543. + *.ii \
  38544. + *.ixx \
  38545. + *.ipp \
  38546. + *.i++ \
  38547. + *.inl \
  38548. + *.h \
  38549. + *.hh \
  38550. + *.hxx \
  38551. + *.hpp \
  38552. + *.h++ \
  38553. + *.idl \
  38554. + *.odl \
  38555. + *.cs \
  38556. + *.php \
  38557. + *.php3 \
  38558. + *.inc \
  38559. + *.m \
  38560. + *.mm \
  38561. + *.dox \
  38562. + *.py \
  38563. + *.C \
  38564. + *.CC \
  38565. + *.C++ \
  38566. + *.II \
  38567. + *.I++ \
  38568. + *.H \
  38569. + *.HH \
  38570. + *.H++ \
  38571. + *.CS \
  38572. + *.PHP \
  38573. + *.PHP3 \
  38574. + *.M \
  38575. + *.MM \
  38576. + *.PY
  38577. +RECURSIVE = NO
  38578. +EXCLUDE =
  38579. +EXCLUDE_SYMLINKS = NO
  38580. +EXCLUDE_PATTERNS =
  38581. +EXAMPLE_PATH =
  38582. +EXAMPLE_PATTERNS = *
  38583. +EXAMPLE_RECURSIVE = NO
  38584. +IMAGE_PATH =
  38585. +INPUT_FILTER =
  38586. +FILTER_PATTERNS =
  38587. +FILTER_SOURCE_FILES = NO
  38588. +#---------------------------------------------------------------------------
  38589. +# configuration options related to source browsing
  38590. +#---------------------------------------------------------------------------
  38591. +SOURCE_BROWSER = NO
  38592. +INLINE_SOURCES = NO
  38593. +STRIP_CODE_COMMENTS = YES
  38594. +REFERENCED_BY_RELATION = YES
  38595. +REFERENCES_RELATION = YES
  38596. +USE_HTAGS = NO
  38597. +VERBATIM_HEADERS = NO
  38598. +#---------------------------------------------------------------------------
  38599. +# configuration options related to the alphabetical class index
  38600. +#---------------------------------------------------------------------------
  38601. +ALPHABETICAL_INDEX = NO
  38602. +COLS_IN_ALPHA_INDEX = 5
  38603. +IGNORE_PREFIX =
  38604. +#---------------------------------------------------------------------------
  38605. +# configuration options related to the HTML output
  38606. +#---------------------------------------------------------------------------
  38607. +GENERATE_HTML = YES
  38608. +HTML_OUTPUT = html
  38609. +HTML_FILE_EXTENSION = .html
  38610. +HTML_HEADER =
  38611. +HTML_FOOTER =
  38612. +HTML_STYLESHEET =
  38613. +HTML_ALIGN_MEMBERS = YES
  38614. +GENERATE_HTMLHELP = NO
  38615. +CHM_FILE =
  38616. +HHC_LOCATION =
  38617. +GENERATE_CHI = NO
  38618. +BINARY_TOC = NO
  38619. +TOC_EXPAND = NO
  38620. +DISABLE_INDEX = NO
  38621. +ENUM_VALUES_PER_LINE = 4
  38622. +GENERATE_TREEVIEW = YES
  38623. +TREEVIEW_WIDTH = 250
  38624. +#---------------------------------------------------------------------------
  38625. +# configuration options related to the LaTeX output
  38626. +#---------------------------------------------------------------------------
  38627. +GENERATE_LATEX = NO
  38628. +LATEX_OUTPUT = latex
  38629. +LATEX_CMD_NAME = latex
  38630. +MAKEINDEX_CMD_NAME = makeindex
  38631. +COMPACT_LATEX = NO
  38632. +PAPER_TYPE = a4wide
  38633. +EXTRA_PACKAGES =
  38634. +LATEX_HEADER =
  38635. +PDF_HYPERLINKS = NO
  38636. +USE_PDFLATEX = NO
  38637. +LATEX_BATCHMODE = NO
  38638. +LATEX_HIDE_INDICES = NO
  38639. +#---------------------------------------------------------------------------
  38640. +# configuration options related to the RTF output
  38641. +#---------------------------------------------------------------------------
  38642. +GENERATE_RTF = NO
  38643. +RTF_OUTPUT = rtf
  38644. +COMPACT_RTF = NO
  38645. +RTF_HYPERLINKS = NO
  38646. +RTF_STYLESHEET_FILE =
  38647. +RTF_EXTENSIONS_FILE =
  38648. +#---------------------------------------------------------------------------
  38649. +# configuration options related to the man page output
  38650. +#---------------------------------------------------------------------------
  38651. +GENERATE_MAN = NO
  38652. +MAN_OUTPUT = man
  38653. +MAN_EXTENSION = .3
  38654. +MAN_LINKS = NO
  38655. +#---------------------------------------------------------------------------
  38656. +# configuration options related to the XML output
  38657. +#---------------------------------------------------------------------------
  38658. +GENERATE_XML = NO
  38659. +XML_OUTPUT = xml
  38660. +XML_SCHEMA =
  38661. +XML_DTD =
  38662. +XML_PROGRAMLISTING = YES
  38663. +#---------------------------------------------------------------------------
  38664. +# configuration options for the AutoGen Definitions output
  38665. +#---------------------------------------------------------------------------
  38666. +GENERATE_AUTOGEN_DEF = NO
  38667. +#---------------------------------------------------------------------------
  38668. +# configuration options related to the Perl module output
  38669. +#---------------------------------------------------------------------------
  38670. +GENERATE_PERLMOD = NO
  38671. +PERLMOD_LATEX = NO
  38672. +PERLMOD_PRETTY = YES
  38673. +PERLMOD_MAKEVAR_PREFIX =
  38674. +#---------------------------------------------------------------------------
  38675. +# Configuration options related to the preprocessor
  38676. +#---------------------------------------------------------------------------
  38677. +ENABLE_PREPROCESSING = YES
  38678. +MACRO_EXPANSION = NO
  38679. +EXPAND_ONLY_PREDEF = NO
  38680. +SEARCH_INCLUDES = YES
  38681. +INCLUDE_PATH =
  38682. +INCLUDE_FILE_PATTERNS =
  38683. +PREDEFINED = DEBUG DEBUG_MEMORY
  38684. +EXPAND_AS_DEFINED =
  38685. +SKIP_FUNCTION_MACROS = YES
  38686. +#---------------------------------------------------------------------------
  38687. +# Configuration::additions related to external references
  38688. +#---------------------------------------------------------------------------
  38689. +TAGFILES =
  38690. +GENERATE_TAGFILE =
  38691. +ALLEXTERNALS = NO
  38692. +EXTERNAL_GROUPS = YES
  38693. +PERL_PATH = /usr/bin/perl
  38694. +#---------------------------------------------------------------------------
  38695. +# Configuration options related to the dot tool
  38696. +#---------------------------------------------------------------------------
  38697. +CLASS_DIAGRAMS = YES
  38698. +HIDE_UNDOC_RELATIONS = YES
  38699. +HAVE_DOT = NO
  38700. +CLASS_GRAPH = YES
  38701. +COLLABORATION_GRAPH = YES
  38702. +GROUP_GRAPHS = YES
  38703. +UML_LOOK = NO
  38704. +TEMPLATE_RELATIONS = NO
  38705. +INCLUDE_GRAPH = NO
  38706. +INCLUDED_BY_GRAPH = YES
  38707. +CALL_GRAPH = NO
  38708. +GRAPHICAL_HIERARCHY = YES
  38709. +DIRECTORY_GRAPH = YES
  38710. +DOT_IMAGE_FORMAT = png
  38711. +DOT_PATH =
  38712. +DOTFILE_DIRS =
  38713. +MAX_DOT_GRAPH_DEPTH = 1000
  38714. +DOT_TRANSPARENT = NO
  38715. +DOT_MULTI_TARGETS = NO
  38716. +GENERATE_LEGEND = YES
  38717. +DOT_CLEANUP = YES
  38718. +#---------------------------------------------------------------------------
  38719. +# Configuration::additions related to the search engine
  38720. +#---------------------------------------------------------------------------
  38721. +SEARCHENGINE = NO
  38722. diff -Nur linux-3.13.11/drivers/usb/host/dwc_common_port/dwc_cc.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_cc.c
  38723. --- linux-3.13.11/drivers/usb/host/dwc_common_port/dwc_cc.c 1970-01-01 01:00:00.000000000 +0100
  38724. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_cc.c 2014-04-24 15:37:13.306990445 +0200
  38725. @@ -0,0 +1,532 @@
  38726. +/* =========================================================================
  38727. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_cc.c $
  38728. + * $Revision: #4 $
  38729. + * $Date: 2010/11/04 $
  38730. + * $Change: 1621692 $
  38731. + *
  38732. + * Synopsys Portability Library Software and documentation
  38733. + * (hereinafter, "Software") is an Unsupported proprietary work of
  38734. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  38735. + * between Synopsys and you.
  38736. + *
  38737. + * The Software IS NOT an item of Licensed Software or Licensed Product
  38738. + * under any End User Software License Agreement or Agreement for
  38739. + * Licensed Product with Synopsys or any supplement thereto. You are
  38740. + * permitted to use and redistribute this Software in source and binary
  38741. + * forms, with or without modification, provided that redistributions
  38742. + * of source code must retain this notice. You may not view, use,
  38743. + * disclose, copy or distribute this file or any information contained
  38744. + * herein except pursuant to this license grant from Synopsys. If you
  38745. + * do not agree with this notice, including the disclaimer below, then
  38746. + * you are not authorized to use the Software.
  38747. + *
  38748. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  38749. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  38750. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  38751. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  38752. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  38753. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  38754. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  38755. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  38756. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  38757. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  38758. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  38759. + * DAMAGE.
  38760. + * ========================================================================= */
  38761. +#ifdef DWC_CCLIB
  38762. +
  38763. +#include "dwc_cc.h"
  38764. +
  38765. +typedef struct dwc_cc
  38766. +{
  38767. + uint32_t uid;
  38768. + uint8_t chid[16];
  38769. + uint8_t cdid[16];
  38770. + uint8_t ck[16];
  38771. + uint8_t *name;
  38772. + uint8_t length;
  38773. + DWC_CIRCLEQ_ENTRY(dwc_cc) list_entry;
  38774. +} dwc_cc_t;
  38775. +
  38776. +DWC_CIRCLEQ_HEAD(context_list, dwc_cc);
  38777. +
  38778. +/** The main structure for CC management. */
  38779. +struct dwc_cc_if
  38780. +{
  38781. + dwc_mutex_t *mutex;
  38782. + char *filename;
  38783. +
  38784. + unsigned is_host:1;
  38785. +
  38786. + dwc_notifier_t *notifier;
  38787. +
  38788. + struct context_list list;
  38789. +};
  38790. +
  38791. +#ifdef DEBUG
  38792. +static inline void dump_bytes(char *name, uint8_t *bytes, int len)
  38793. +{
  38794. + int i;
  38795. + DWC_PRINTF("%s: ", name);
  38796. + for (i=0; i<len; i++) {
  38797. + DWC_PRINTF("%02x ", bytes[i]);
  38798. + }
  38799. + DWC_PRINTF("\n");
  38800. +}
  38801. +#else
  38802. +#define dump_bytes(x...)
  38803. +#endif
  38804. +
  38805. +static dwc_cc_t *alloc_cc(void *mem_ctx, uint8_t *name, uint32_t length)
  38806. +{
  38807. + dwc_cc_t *cc = dwc_alloc(mem_ctx, sizeof(dwc_cc_t));
  38808. + if (!cc) {
  38809. + return NULL;
  38810. + }
  38811. + DWC_MEMSET(cc, 0, sizeof(dwc_cc_t));
  38812. +
  38813. + if (name) {
  38814. + cc->length = length;
  38815. + cc->name = dwc_alloc(mem_ctx, length);
  38816. + if (!cc->name) {
  38817. + dwc_free(mem_ctx, cc);
  38818. + return NULL;
  38819. + }
  38820. +
  38821. + DWC_MEMCPY(cc->name, name, length);
  38822. + }
  38823. +
  38824. + return cc;
  38825. +}
  38826. +
  38827. +static void free_cc(void *mem_ctx, dwc_cc_t *cc)
  38828. +{
  38829. + if (cc->name) {
  38830. + dwc_free(mem_ctx, cc->name);
  38831. + }
  38832. + dwc_free(mem_ctx, cc);
  38833. +}
  38834. +
  38835. +static uint32_t next_uid(dwc_cc_if_t *cc_if)
  38836. +{
  38837. + uint32_t uid = 0;
  38838. + dwc_cc_t *cc;
  38839. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  38840. + if (cc->uid > uid) {
  38841. + uid = cc->uid;
  38842. + }
  38843. + }
  38844. +
  38845. + if (uid == 0) {
  38846. + uid = 255;
  38847. + }
  38848. +
  38849. + return uid + 1;
  38850. +}
  38851. +
  38852. +static dwc_cc_t *cc_find(dwc_cc_if_t *cc_if, uint32_t uid)
  38853. +{
  38854. + dwc_cc_t *cc;
  38855. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  38856. + if (cc->uid == uid) {
  38857. + return cc;
  38858. + }
  38859. + }
  38860. + return NULL;
  38861. +}
  38862. +
  38863. +static unsigned int cc_data_size(dwc_cc_if_t *cc_if)
  38864. +{
  38865. + unsigned int size = 0;
  38866. + dwc_cc_t *cc;
  38867. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  38868. + size += (48 + 1);
  38869. + if (cc->name) {
  38870. + size += cc->length;
  38871. + }
  38872. + }
  38873. + return size;
  38874. +}
  38875. +
  38876. +static uint32_t cc_match_chid(dwc_cc_if_t *cc_if, uint8_t *chid)
  38877. +{
  38878. + uint32_t uid = 0;
  38879. + dwc_cc_t *cc;
  38880. +
  38881. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  38882. + if (DWC_MEMCMP(cc->chid, chid, 16) == 0) {
  38883. + uid = cc->uid;
  38884. + break;
  38885. + }
  38886. + }
  38887. + return uid;
  38888. +}
  38889. +static uint32_t cc_match_cdid(dwc_cc_if_t *cc_if, uint8_t *cdid)
  38890. +{
  38891. + uint32_t uid = 0;
  38892. + dwc_cc_t *cc;
  38893. +
  38894. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  38895. + if (DWC_MEMCMP(cc->cdid, cdid, 16) == 0) {
  38896. + uid = cc->uid;
  38897. + break;
  38898. + }
  38899. + }
  38900. + return uid;
  38901. +}
  38902. +
  38903. +/* Internal cc_add */
  38904. +static int32_t cc_add(void *mem_ctx, dwc_cc_if_t *cc_if, uint8_t *chid,
  38905. + uint8_t *cdid, uint8_t *ck, uint8_t *name, uint8_t length)
  38906. +{
  38907. + dwc_cc_t *cc;
  38908. + uint32_t uid;
  38909. +
  38910. + if (cc_if->is_host) {
  38911. + uid = cc_match_cdid(cc_if, cdid);
  38912. + }
  38913. + else {
  38914. + uid = cc_match_chid(cc_if, chid);
  38915. + }
  38916. +
  38917. + if (uid) {
  38918. + DWC_DEBUGC("Replacing previous connection context id=%d name=%p name_len=%d", uid, name, length);
  38919. + cc = cc_find(cc_if, uid);
  38920. + }
  38921. + else {
  38922. + cc = alloc_cc(mem_ctx, name, length);
  38923. + cc->uid = next_uid(cc_if);
  38924. + DWC_CIRCLEQ_INSERT_TAIL(&cc_if->list, cc, list_entry);
  38925. + }
  38926. +
  38927. + DWC_MEMCPY(&(cc->chid[0]), chid, 16);
  38928. + DWC_MEMCPY(&(cc->cdid[0]), cdid, 16);
  38929. + DWC_MEMCPY(&(cc->ck[0]), ck, 16);
  38930. +
  38931. + DWC_DEBUGC("Added connection context id=%d name=%p name_len=%d", cc->uid, name, length);
  38932. + dump_bytes("CHID", cc->chid, 16);
  38933. + dump_bytes("CDID", cc->cdid, 16);
  38934. + dump_bytes("CK", cc->ck, 16);
  38935. + return cc->uid;
  38936. +}
  38937. +
  38938. +/* Internal cc_clear */
  38939. +static void cc_clear(void *mem_ctx, dwc_cc_if_t *cc_if)
  38940. +{
  38941. + while (!DWC_CIRCLEQ_EMPTY(&cc_if->list)) {
  38942. + dwc_cc_t *cc = DWC_CIRCLEQ_FIRST(&cc_if->list);
  38943. + DWC_CIRCLEQ_REMOVE_INIT(&cc_if->list, cc, list_entry);
  38944. + free_cc(mem_ctx, cc);
  38945. + }
  38946. +}
  38947. +
  38948. +dwc_cc_if_t *dwc_cc_if_alloc(void *mem_ctx, void *mtx_ctx,
  38949. + dwc_notifier_t *notifier, unsigned is_host)
  38950. +{
  38951. + dwc_cc_if_t *cc_if = NULL;
  38952. +
  38953. + /* Allocate a common_cc_if structure */
  38954. + cc_if = dwc_alloc(mem_ctx, sizeof(dwc_cc_if_t));
  38955. +
  38956. + if (!cc_if)
  38957. + return NULL;
  38958. +
  38959. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  38960. + DWC_MUTEX_ALLOC_LINUX_DEBUG(cc_if->mutex);
  38961. +#else
  38962. + cc_if->mutex = dwc_mutex_alloc(mtx_ctx);
  38963. +#endif
  38964. + if (!cc_if->mutex) {
  38965. + dwc_free(mem_ctx, cc_if);
  38966. + return NULL;
  38967. + }
  38968. +
  38969. + DWC_CIRCLEQ_INIT(&cc_if->list);
  38970. + cc_if->is_host = is_host;
  38971. + cc_if->notifier = notifier;
  38972. + return cc_if;
  38973. +}
  38974. +
  38975. +void dwc_cc_if_free(void *mem_ctx, void *mtx_ctx, dwc_cc_if_t *cc_if)
  38976. +{
  38977. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  38978. + DWC_MUTEX_FREE(cc_if->mutex);
  38979. +#else
  38980. + dwc_mutex_free(mtx_ctx, cc_if->mutex);
  38981. +#endif
  38982. + cc_clear(mem_ctx, cc_if);
  38983. + dwc_free(mem_ctx, cc_if);
  38984. +}
  38985. +
  38986. +static void cc_changed(dwc_cc_if_t *cc_if)
  38987. +{
  38988. + if (cc_if->notifier) {
  38989. + dwc_notify(cc_if->notifier, DWC_CC_LIST_CHANGED_NOTIFICATION, cc_if);
  38990. + }
  38991. +}
  38992. +
  38993. +void dwc_cc_clear(void *mem_ctx, dwc_cc_if_t *cc_if)
  38994. +{
  38995. + DWC_MUTEX_LOCK(cc_if->mutex);
  38996. + cc_clear(mem_ctx, cc_if);
  38997. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  38998. + cc_changed(cc_if);
  38999. +}
  39000. +
  39001. +int32_t dwc_cc_add(void *mem_ctx, dwc_cc_if_t *cc_if, uint8_t *chid,
  39002. + uint8_t *cdid, uint8_t *ck, uint8_t *name, uint8_t length)
  39003. +{
  39004. + uint32_t uid;
  39005. +
  39006. + DWC_MUTEX_LOCK(cc_if->mutex);
  39007. + uid = cc_add(mem_ctx, cc_if, chid, cdid, ck, name, length);
  39008. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39009. + cc_changed(cc_if);
  39010. +
  39011. + return uid;
  39012. +}
  39013. +
  39014. +void dwc_cc_change(void *mem_ctx, dwc_cc_if_t *cc_if, int32_t id, uint8_t *chid,
  39015. + uint8_t *cdid, uint8_t *ck, uint8_t *name, uint8_t length)
  39016. +{
  39017. + dwc_cc_t* cc;
  39018. +
  39019. + DWC_DEBUGC("Change connection context %d", id);
  39020. +
  39021. + DWC_MUTEX_LOCK(cc_if->mutex);
  39022. + cc = cc_find(cc_if, id);
  39023. + if (!cc) {
  39024. + DWC_ERROR("Uid %d not found in cc list\n", id);
  39025. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39026. + return;
  39027. + }
  39028. +
  39029. + if (chid) {
  39030. + DWC_MEMCPY(&(cc->chid[0]), chid, 16);
  39031. + }
  39032. + if (cdid) {
  39033. + DWC_MEMCPY(&(cc->cdid[0]), cdid, 16);
  39034. + }
  39035. + if (ck) {
  39036. + DWC_MEMCPY(&(cc->ck[0]), ck, 16);
  39037. + }
  39038. +
  39039. + if (name) {
  39040. + if (cc->name) {
  39041. + dwc_free(mem_ctx, cc->name);
  39042. + }
  39043. + cc->name = dwc_alloc(mem_ctx, length);
  39044. + if (!cc->name) {
  39045. + DWC_ERROR("Out of memory in dwc_cc_change()\n");
  39046. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39047. + return;
  39048. + }
  39049. + cc->length = length;
  39050. + DWC_MEMCPY(cc->name, name, length);
  39051. + }
  39052. +
  39053. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39054. +
  39055. + cc_changed(cc_if);
  39056. +
  39057. + DWC_DEBUGC("Changed connection context id=%d\n", id);
  39058. + dump_bytes("New CHID", cc->chid, 16);
  39059. + dump_bytes("New CDID", cc->cdid, 16);
  39060. + dump_bytes("New CK", cc->ck, 16);
  39061. +}
  39062. +
  39063. +void dwc_cc_remove(void *mem_ctx, dwc_cc_if_t *cc_if, int32_t id)
  39064. +{
  39065. + dwc_cc_t *cc;
  39066. +
  39067. + DWC_DEBUGC("Removing connection context %d", id);
  39068. +
  39069. + DWC_MUTEX_LOCK(cc_if->mutex);
  39070. + cc = cc_find(cc_if, id);
  39071. + if (!cc) {
  39072. + DWC_ERROR("Uid %d not found in cc list\n", id);
  39073. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39074. + return;
  39075. + }
  39076. +
  39077. + DWC_CIRCLEQ_REMOVE_INIT(&cc_if->list, cc, list_entry);
  39078. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39079. + free_cc(mem_ctx, cc);
  39080. +
  39081. + cc_changed(cc_if);
  39082. +}
  39083. +
  39084. +uint8_t *dwc_cc_data_for_save(void *mem_ctx, dwc_cc_if_t *cc_if, unsigned int *length)
  39085. +{
  39086. + uint8_t *buf, *x;
  39087. + uint8_t zero = 0;
  39088. + dwc_cc_t *cc;
  39089. +
  39090. + DWC_MUTEX_LOCK(cc_if->mutex);
  39091. + *length = cc_data_size(cc_if);
  39092. + if (!(*length)) {
  39093. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39094. + return NULL;
  39095. + }
  39096. +
  39097. + DWC_DEBUGC("Creating data for saving (length=%d)", *length);
  39098. +
  39099. + buf = dwc_alloc(mem_ctx, *length);
  39100. + if (!buf) {
  39101. + *length = 0;
  39102. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39103. + return NULL;
  39104. + }
  39105. +
  39106. + x = buf;
  39107. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  39108. + DWC_MEMCPY(x, cc->chid, 16);
  39109. + x += 16;
  39110. + DWC_MEMCPY(x, cc->cdid, 16);
  39111. + x += 16;
  39112. + DWC_MEMCPY(x, cc->ck, 16);
  39113. + x += 16;
  39114. + if (cc->name) {
  39115. + DWC_MEMCPY(x, &cc->length, 1);
  39116. + x += 1;
  39117. + DWC_MEMCPY(x, cc->name, cc->length);
  39118. + x += cc->length;
  39119. + }
  39120. + else {
  39121. + DWC_MEMCPY(x, &zero, 1);
  39122. + x += 1;
  39123. + }
  39124. + }
  39125. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39126. +
  39127. + return buf;
  39128. +}
  39129. +
  39130. +void dwc_cc_restore_from_data(void *mem_ctx, dwc_cc_if_t *cc_if, uint8_t *data, uint32_t length)
  39131. +{
  39132. + uint8_t name_length;
  39133. + uint8_t *name;
  39134. + uint8_t *chid;
  39135. + uint8_t *cdid;
  39136. + uint8_t *ck;
  39137. + uint32_t i = 0;
  39138. +
  39139. + DWC_MUTEX_LOCK(cc_if->mutex);
  39140. + cc_clear(mem_ctx, cc_if);
  39141. +
  39142. + while (i < length) {
  39143. + chid = &data[i];
  39144. + i += 16;
  39145. + cdid = &data[i];
  39146. + i += 16;
  39147. + ck = &data[i];
  39148. + i += 16;
  39149. +
  39150. + name_length = data[i];
  39151. + i ++;
  39152. +
  39153. + if (name_length) {
  39154. + name = &data[i];
  39155. + i += name_length;
  39156. + }
  39157. + else {
  39158. + name = NULL;
  39159. + }
  39160. +
  39161. + /* check to see if we haven't overflown the buffer */
  39162. + if (i > length) {
  39163. + DWC_ERROR("Data format error while attempting to load CCs "
  39164. + "(nlen=%d, iter=%d, buflen=%d).\n", name_length, i, length);
  39165. + break;
  39166. + }
  39167. +
  39168. + cc_add(mem_ctx, cc_if, chid, cdid, ck, name, name_length);
  39169. + }
  39170. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39171. +
  39172. + cc_changed(cc_if);
  39173. +}
  39174. +
  39175. +uint32_t dwc_cc_match_chid(dwc_cc_if_t *cc_if, uint8_t *chid)
  39176. +{
  39177. + uint32_t uid = 0;
  39178. +
  39179. + DWC_MUTEX_LOCK(cc_if->mutex);
  39180. + uid = cc_match_chid(cc_if, chid);
  39181. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39182. + return uid;
  39183. +}
  39184. +uint32_t dwc_cc_match_cdid(dwc_cc_if_t *cc_if, uint8_t *cdid)
  39185. +{
  39186. + uint32_t uid = 0;
  39187. +
  39188. + DWC_MUTEX_LOCK(cc_if->mutex);
  39189. + uid = cc_match_cdid(cc_if, cdid);
  39190. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39191. + return uid;
  39192. +}
  39193. +
  39194. +uint8_t *dwc_cc_ck(dwc_cc_if_t *cc_if, int32_t id)
  39195. +{
  39196. + uint8_t *ck = NULL;
  39197. + dwc_cc_t *cc;
  39198. +
  39199. + DWC_MUTEX_LOCK(cc_if->mutex);
  39200. + cc = cc_find(cc_if, id);
  39201. + if (cc) {
  39202. + ck = cc->ck;
  39203. + }
  39204. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39205. +
  39206. + return ck;
  39207. +
  39208. +}
  39209. +
  39210. +uint8_t *dwc_cc_chid(dwc_cc_if_t *cc_if, int32_t id)
  39211. +{
  39212. + uint8_t *retval = NULL;
  39213. + dwc_cc_t *cc;
  39214. +
  39215. + DWC_MUTEX_LOCK(cc_if->mutex);
  39216. + cc = cc_find(cc_if, id);
  39217. + if (cc) {
  39218. + retval = cc->chid;
  39219. + }
  39220. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39221. +
  39222. + return retval;
  39223. +}
  39224. +
  39225. +uint8_t *dwc_cc_cdid(dwc_cc_if_t *cc_if, int32_t id)
  39226. +{
  39227. + uint8_t *retval = NULL;
  39228. + dwc_cc_t *cc;
  39229. +
  39230. + DWC_MUTEX_LOCK(cc_if->mutex);
  39231. + cc = cc_find(cc_if, id);
  39232. + if (cc) {
  39233. + retval = cc->cdid;
  39234. + }
  39235. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39236. +
  39237. + return retval;
  39238. +}
  39239. +
  39240. +uint8_t *dwc_cc_name(dwc_cc_if_t *cc_if, int32_t id, uint8_t *length)
  39241. +{
  39242. + uint8_t *retval = NULL;
  39243. + dwc_cc_t *cc;
  39244. +
  39245. + DWC_MUTEX_LOCK(cc_if->mutex);
  39246. + *length = 0;
  39247. + cc = cc_find(cc_if, id);
  39248. + if (cc) {
  39249. + *length = cc->length;
  39250. + retval = cc->name;
  39251. + }
  39252. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39253. +
  39254. + return retval;
  39255. +}
  39256. +
  39257. +#endif /* DWC_CCLIB */
  39258. diff -Nur linux-3.13.11/drivers/usb/host/dwc_common_port/dwc_cc.h linux-rpi/drivers/usb/host/dwc_common_port/dwc_cc.h
  39259. --- linux-3.13.11/drivers/usb/host/dwc_common_port/dwc_cc.h 1970-01-01 01:00:00.000000000 +0100
  39260. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_cc.h 2014-04-24 15:37:13.306990445 +0200
  39261. @@ -0,0 +1,224 @@
  39262. +/* =========================================================================
  39263. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_cc.h $
  39264. + * $Revision: #4 $
  39265. + * $Date: 2010/09/28 $
  39266. + * $Change: 1596182 $
  39267. + *
  39268. + * Synopsys Portability Library Software and documentation
  39269. + * (hereinafter, "Software") is an Unsupported proprietary work of
  39270. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  39271. + * between Synopsys and you.
  39272. + *
  39273. + * The Software IS NOT an item of Licensed Software or Licensed Product
  39274. + * under any End User Software License Agreement or Agreement for
  39275. + * Licensed Product with Synopsys or any supplement thereto. You are
  39276. + * permitted to use and redistribute this Software in source and binary
  39277. + * forms, with or without modification, provided that redistributions
  39278. + * of source code must retain this notice. You may not view, use,
  39279. + * disclose, copy or distribute this file or any information contained
  39280. + * herein except pursuant to this license grant from Synopsys. If you
  39281. + * do not agree with this notice, including the disclaimer below, then
  39282. + * you are not authorized to use the Software.
  39283. + *
  39284. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  39285. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  39286. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  39287. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  39288. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  39289. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  39290. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  39291. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  39292. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  39293. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  39294. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  39295. + * DAMAGE.
  39296. + * ========================================================================= */
  39297. +#ifndef _DWC_CC_H_
  39298. +#define _DWC_CC_H_
  39299. +
  39300. +#ifdef __cplusplus
  39301. +extern "C" {
  39302. +#endif
  39303. +
  39304. +/** @file
  39305. + *
  39306. + * This file defines the Context Context library.
  39307. + *
  39308. + * The main data structure is dwc_cc_if_t which is returned by either the
  39309. + * dwc_cc_if_alloc function or returned by the module to the user via a provided
  39310. + * function. The data structure is opaque and should only be manipulated via the
  39311. + * functions provied in this API.
  39312. + *
  39313. + * It manages a list of connection contexts and operations can be performed to
  39314. + * add, remove, query, search, and change, those contexts. Additionally,
  39315. + * a dwc_notifier_t object can be requested from the manager so that
  39316. + * the user can be notified whenever the context list has changed.
  39317. + */
  39318. +
  39319. +#include "dwc_os.h"
  39320. +#include "dwc_list.h"
  39321. +#include "dwc_notifier.h"
  39322. +
  39323. +
  39324. +/* Notifications */
  39325. +#define DWC_CC_LIST_CHANGED_NOTIFICATION "DWC_CC_LIST_CHANGED_NOTIFICATION"
  39326. +
  39327. +struct dwc_cc_if;
  39328. +typedef struct dwc_cc_if dwc_cc_if_t;
  39329. +
  39330. +
  39331. +/** @name Connection Context Operations */
  39332. +/** @{ */
  39333. +
  39334. +/** This function allocates memory for a dwc_cc_if_t structure, initializes
  39335. + * fields to default values, and returns a pointer to the structure or NULL on
  39336. + * error. */
  39337. +extern dwc_cc_if_t *dwc_cc_if_alloc(void *mem_ctx, void *mtx_ctx,
  39338. + dwc_notifier_t *notifier, unsigned is_host);
  39339. +
  39340. +/** Frees the memory for the specified CC structure allocated from
  39341. + * dwc_cc_if_alloc(). */
  39342. +extern void dwc_cc_if_free(void *mem_ctx, void *mtx_ctx, dwc_cc_if_t *cc_if);
  39343. +
  39344. +/** Removes all contexts from the connection context list */
  39345. +extern void dwc_cc_clear(void *mem_ctx, dwc_cc_if_t *cc_if);
  39346. +
  39347. +/** Adds a connection context (CHID, CK, CDID, Name) to the connection context list.
  39348. + * If a CHID already exists, the CK and name are overwritten. Statistics are
  39349. + * not overwritten.
  39350. + *
  39351. + * @param cc_if The cc_if structure.
  39352. + * @param chid A pointer to the 16-byte CHID. This value will be copied.
  39353. + * @param ck A pointer to the 16-byte CK. This value will be copied.
  39354. + * @param cdid A pointer to the 16-byte CDID. This value will be copied.
  39355. + * @param name An optional host friendly name as defined in the association model
  39356. + * spec. Must be a UTF16-LE unicode string. Can be NULL to indicated no name.
  39357. + * @param length The length othe unicode string.
  39358. + * @return A unique identifier used to refer to this context that is valid for
  39359. + * as long as this context is still in the list. */
  39360. +extern int32_t dwc_cc_add(void *mem_ctx, dwc_cc_if_t *cc_if, uint8_t *chid,
  39361. + uint8_t *cdid, uint8_t *ck, uint8_t *name,
  39362. + uint8_t length);
  39363. +
  39364. +/** Changes the CHID, CK, CDID, or Name values of a connection context in the
  39365. + * list, preserving any accumulated statistics. This would typically be called
  39366. + * if the host decideds to change the context with a SET_CONNECTION request.
  39367. + *
  39368. + * @param cc_if The cc_if structure.
  39369. + * @param id The identifier of the connection context.
  39370. + * @param chid A pointer to the 16-byte CHID. This value will be copied. NULL
  39371. + * indicates no change.
  39372. + * @param cdid A pointer to the 16-byte CDID. This value will be copied. NULL
  39373. + * indicates no change.
  39374. + * @param ck A pointer to the 16-byte CK. This value will be copied. NULL
  39375. + * indicates no change.
  39376. + * @param name Host friendly name UTF16-LE. NULL indicates no change.
  39377. + * @param length Length of name. */
  39378. +extern void dwc_cc_change(void *mem_ctx, dwc_cc_if_t *cc_if, int32_t id,
  39379. + uint8_t *chid, uint8_t *cdid, uint8_t *ck,
  39380. + uint8_t *name, uint8_t length);
  39381. +
  39382. +/** Remove the specified connection context.
  39383. + * @param cc_if The cc_if structure.
  39384. + * @param id The identifier of the connection context to remove. */
  39385. +extern void dwc_cc_remove(void *mem_ctx, dwc_cc_if_t *cc_if, int32_t id);
  39386. +
  39387. +/** Get a binary block of data for the connection context list and attributes.
  39388. + * This data can be used by the OS specific driver to save the connection
  39389. + * context list into non-volatile memory.
  39390. + *
  39391. + * @param cc_if The cc_if structure.
  39392. + * @param length Return the length of the data buffer.
  39393. + * @return A pointer to the data buffer. The memory for this buffer should be
  39394. + * freed with DWC_FREE() after use. */
  39395. +extern uint8_t *dwc_cc_data_for_save(void *mem_ctx, dwc_cc_if_t *cc_if,
  39396. + unsigned int *length);
  39397. +
  39398. +/** Restore the connection context list from the binary data that was previously
  39399. + * returned from a call to dwc_cc_data_for_save. This can be used by the OS specific
  39400. + * driver to load a connection context list from non-volatile memory.
  39401. + *
  39402. + * @param cc_if The cc_if structure.
  39403. + * @param data The data bytes as returned from dwc_cc_data_for_save.
  39404. + * @param length The length of the data. */
  39405. +extern void dwc_cc_restore_from_data(void *mem_ctx, dwc_cc_if_t *cc_if,
  39406. + uint8_t *data, unsigned int length);
  39407. +
  39408. +/** Find the connection context from the specified CHID.
  39409. + *
  39410. + * @param cc_if The cc_if structure.
  39411. + * @param chid A pointer to the CHID data.
  39412. + * @return A non-zero identifier of the connection context if the CHID matches.
  39413. + * Otherwise returns 0. */
  39414. +extern uint32_t dwc_cc_match_chid(dwc_cc_if_t *cc_if, uint8_t *chid);
  39415. +
  39416. +/** Find the connection context from the specified CDID.
  39417. + *
  39418. + * @param cc_if The cc_if structure.
  39419. + * @param cdid A pointer to the CDID data.
  39420. + * @return A non-zero identifier of the connection context if the CHID matches.
  39421. + * Otherwise returns 0. */
  39422. +extern uint32_t dwc_cc_match_cdid(dwc_cc_if_t *cc_if, uint8_t *cdid);
  39423. +
  39424. +/** Retrieve the CK from the specified connection context.
  39425. + *
  39426. + * @param cc_if The cc_if structure.
  39427. + * @param id The identifier of the connection context.
  39428. + * @return A pointer to the CK data. The memory does not need to be freed. */
  39429. +extern uint8_t *dwc_cc_ck(dwc_cc_if_t *cc_if, int32_t id);
  39430. +
  39431. +/** Retrieve the CHID from the specified connection context.
  39432. + *
  39433. + * @param cc_if The cc_if structure.
  39434. + * @param id The identifier of the connection context.
  39435. + * @return A pointer to the CHID data. The memory does not need to be freed. */
  39436. +extern uint8_t *dwc_cc_chid(dwc_cc_if_t *cc_if, int32_t id);
  39437. +
  39438. +/** Retrieve the CDID from the specified connection context.
  39439. + *
  39440. + * @param cc_if The cc_if structure.
  39441. + * @param id The identifier of the connection context.
  39442. + * @return A pointer to the CDID data. The memory does not need to be freed. */
  39443. +extern uint8_t *dwc_cc_cdid(dwc_cc_if_t *cc_if, int32_t id);
  39444. +
  39445. +extern uint8_t *dwc_cc_name(dwc_cc_if_t *cc_if, int32_t id, uint8_t *length);
  39446. +
  39447. +/** Checks a buffer for non-zero.
  39448. + * @param id A pointer to a 16 byte buffer.
  39449. + * @return true if the 16 byte value is non-zero. */
  39450. +static inline unsigned dwc_assoc_is_not_zero_id(uint8_t *id) {
  39451. + int i;
  39452. + for (i=0; i<16; i++) {
  39453. + if (id[i]) return 1;
  39454. + }
  39455. + return 0;
  39456. +}
  39457. +
  39458. +/** Checks a buffer for zero.
  39459. + * @param id A pointer to a 16 byte buffer.
  39460. + * @return true if the 16 byte value is zero. */
  39461. +static inline unsigned dwc_assoc_is_zero_id(uint8_t *id) {
  39462. + return !dwc_assoc_is_not_zero_id(id);
  39463. +}
  39464. +
  39465. +/** Prints an ASCII representation for the 16-byte chid, cdid, or ck, into
  39466. + * buffer. */
  39467. +static inline int dwc_print_id_string(char *buffer, uint8_t *id) {
  39468. + char *ptr = buffer;
  39469. + int i;
  39470. + for (i=0; i<16; i++) {
  39471. + ptr += DWC_SPRINTF(ptr, "%02x", id[i]);
  39472. + if (i < 15) {
  39473. + ptr += DWC_SPRINTF(ptr, " ");
  39474. + }
  39475. + }
  39476. + return ptr - buffer;
  39477. +}
  39478. +
  39479. +/** @} */
  39480. +
  39481. +#ifdef __cplusplus
  39482. +}
  39483. +#endif
  39484. +
  39485. +#endif /* _DWC_CC_H_ */
  39486. diff -Nur linux-3.13.11/drivers/usb/host/dwc_common_port/dwc_common_fbsd.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_common_fbsd.c
  39487. --- linux-3.13.11/drivers/usb/host/dwc_common_port/dwc_common_fbsd.c 1970-01-01 01:00:00.000000000 +0100
  39488. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_common_fbsd.c 2014-04-24 15:35:04.169565731 +0200
  39489. @@ -0,0 +1,1308 @@
  39490. +#include "dwc_os.h"
  39491. +#include "dwc_list.h"
  39492. +
  39493. +#ifdef DWC_CCLIB
  39494. +# include "dwc_cc.h"
  39495. +#endif
  39496. +
  39497. +#ifdef DWC_CRYPTOLIB
  39498. +# include "dwc_modpow.h"
  39499. +# include "dwc_dh.h"
  39500. +# include "dwc_crypto.h"
  39501. +#endif
  39502. +
  39503. +#ifdef DWC_NOTIFYLIB
  39504. +# include "dwc_notifier.h"
  39505. +#endif
  39506. +
  39507. +/* OS-Level Implementations */
  39508. +
  39509. +/* This is the FreeBSD 7.0 kernel implementation of the DWC platform library. */
  39510. +
  39511. +
  39512. +/* MISC */
  39513. +
  39514. +void *DWC_MEMSET(void *dest, uint8_t byte, uint32_t size)
  39515. +{
  39516. + return memset(dest, byte, size);
  39517. +}
  39518. +
  39519. +void *DWC_MEMCPY(void *dest, void const *src, uint32_t size)
  39520. +{
  39521. + return memcpy(dest, src, size);
  39522. +}
  39523. +
  39524. +void *DWC_MEMMOVE(void *dest, void *src, uint32_t size)
  39525. +{
  39526. + bcopy(src, dest, size);
  39527. + return dest;
  39528. +}
  39529. +
  39530. +int DWC_MEMCMP(void *m1, void *m2, uint32_t size)
  39531. +{
  39532. + return memcmp(m1, m2, size);
  39533. +}
  39534. +
  39535. +int DWC_STRNCMP(void *s1, void *s2, uint32_t size)
  39536. +{
  39537. + return strncmp(s1, s2, size);
  39538. +}
  39539. +
  39540. +int DWC_STRCMP(void *s1, void *s2)
  39541. +{
  39542. + return strcmp(s1, s2);
  39543. +}
  39544. +
  39545. +int DWC_STRLEN(char const *str)
  39546. +{
  39547. + return strlen(str);
  39548. +}
  39549. +
  39550. +char *DWC_STRCPY(char *to, char const *from)
  39551. +{
  39552. + return strcpy(to, from);
  39553. +}
  39554. +
  39555. +char *DWC_STRDUP(char const *str)
  39556. +{
  39557. + int len = DWC_STRLEN(str) + 1;
  39558. + char *new = DWC_ALLOC_ATOMIC(len);
  39559. +
  39560. + if (!new) {
  39561. + return NULL;
  39562. + }
  39563. +
  39564. + DWC_MEMCPY(new, str, len);
  39565. + return new;
  39566. +}
  39567. +
  39568. +int DWC_ATOI(char *str, int32_t *value)
  39569. +{
  39570. + char *end = NULL;
  39571. +
  39572. + *value = strtol(str, &end, 0);
  39573. + if (*end == '\0') {
  39574. + return 0;
  39575. + }
  39576. +
  39577. + return -1;
  39578. +}
  39579. +
  39580. +int DWC_ATOUI(char *str, uint32_t *value)
  39581. +{
  39582. + char *end = NULL;
  39583. +
  39584. + *value = strtoul(str, &end, 0);
  39585. + if (*end == '\0') {
  39586. + return 0;
  39587. + }
  39588. +
  39589. + return -1;
  39590. +}
  39591. +
  39592. +
  39593. +#ifdef DWC_UTFLIB
  39594. +/* From usbstring.c */
  39595. +
  39596. +int DWC_UTF8_TO_UTF16LE(uint8_t const *s, uint16_t *cp, unsigned len)
  39597. +{
  39598. + int count = 0;
  39599. + u8 c;
  39600. + u16 uchar;
  39601. +
  39602. + /* this insists on correct encodings, though not minimal ones.
  39603. + * BUT it currently rejects legit 4-byte UTF-8 code points,
  39604. + * which need surrogate pairs. (Unicode 3.1 can use them.)
  39605. + */
  39606. + while (len != 0 && (c = (u8) *s++) != 0) {
  39607. + if (unlikely(c & 0x80)) {
  39608. + // 2-byte sequence:
  39609. + // 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx
  39610. + if ((c & 0xe0) == 0xc0) {
  39611. + uchar = (c & 0x1f) << 6;
  39612. +
  39613. + c = (u8) *s++;
  39614. + if ((c & 0xc0) != 0xc0)
  39615. + goto fail;
  39616. + c &= 0x3f;
  39617. + uchar |= c;
  39618. +
  39619. + // 3-byte sequence (most CJKV characters):
  39620. + // zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx
  39621. + } else if ((c & 0xf0) == 0xe0) {
  39622. + uchar = (c & 0x0f) << 12;
  39623. +
  39624. + c = (u8) *s++;
  39625. + if ((c & 0xc0) != 0xc0)
  39626. + goto fail;
  39627. + c &= 0x3f;
  39628. + uchar |= c << 6;
  39629. +
  39630. + c = (u8) *s++;
  39631. + if ((c & 0xc0) != 0xc0)
  39632. + goto fail;
  39633. + c &= 0x3f;
  39634. + uchar |= c;
  39635. +
  39636. + /* no bogus surrogates */
  39637. + if (0xd800 <= uchar && uchar <= 0xdfff)
  39638. + goto fail;
  39639. +
  39640. + // 4-byte sequence (surrogate pairs, currently rare):
  39641. + // 11101110wwwwzzzzyy + 110111yyyyxxxxxx
  39642. + // = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx
  39643. + // (uuuuu = wwww + 1)
  39644. + // FIXME accept the surrogate code points (only)
  39645. + } else
  39646. + goto fail;
  39647. + } else
  39648. + uchar = c;
  39649. + put_unaligned (cpu_to_le16 (uchar), cp++);
  39650. + count++;
  39651. + len--;
  39652. + }
  39653. + return count;
  39654. +fail:
  39655. + return -1;
  39656. +}
  39657. +
  39658. +#endif /* DWC_UTFLIB */
  39659. +
  39660. +
  39661. +/* dwc_debug.h */
  39662. +
  39663. +dwc_bool_t DWC_IN_IRQ(void)
  39664. +{
  39665. +// return in_irq();
  39666. + return 0;
  39667. +}
  39668. +
  39669. +dwc_bool_t DWC_IN_BH(void)
  39670. +{
  39671. +// return in_softirq();
  39672. + return 0;
  39673. +}
  39674. +
  39675. +void DWC_VPRINTF(char *format, va_list args)
  39676. +{
  39677. + vprintf(format, args);
  39678. +}
  39679. +
  39680. +int DWC_VSNPRINTF(char *str, int size, char *format, va_list args)
  39681. +{
  39682. + return vsnprintf(str, size, format, args);
  39683. +}
  39684. +
  39685. +void DWC_PRINTF(char *format, ...)
  39686. +{
  39687. + va_list args;
  39688. +
  39689. + va_start(args, format);
  39690. + DWC_VPRINTF(format, args);
  39691. + va_end(args);
  39692. +}
  39693. +
  39694. +int DWC_SPRINTF(char *buffer, char *format, ...)
  39695. +{
  39696. + int retval;
  39697. + va_list args;
  39698. +
  39699. + va_start(args, format);
  39700. + retval = vsprintf(buffer, format, args);
  39701. + va_end(args);
  39702. + return retval;
  39703. +}
  39704. +
  39705. +int DWC_SNPRINTF(char *buffer, int size, char *format, ...)
  39706. +{
  39707. + int retval;
  39708. + va_list args;
  39709. +
  39710. + va_start(args, format);
  39711. + retval = vsnprintf(buffer, size, format, args);
  39712. + va_end(args);
  39713. + return retval;
  39714. +}
  39715. +
  39716. +void __DWC_WARN(char *format, ...)
  39717. +{
  39718. + va_list args;
  39719. +
  39720. + va_start(args, format);
  39721. + DWC_VPRINTF(format, args);
  39722. + va_end(args);
  39723. +}
  39724. +
  39725. +void __DWC_ERROR(char *format, ...)
  39726. +{
  39727. + va_list args;
  39728. +
  39729. + va_start(args, format);
  39730. + DWC_VPRINTF(format, args);
  39731. + va_end(args);
  39732. +}
  39733. +
  39734. +void DWC_EXCEPTION(char *format, ...)
  39735. +{
  39736. + va_list args;
  39737. +
  39738. + va_start(args, format);
  39739. + DWC_VPRINTF(format, args);
  39740. + va_end(args);
  39741. +// BUG_ON(1); ???
  39742. +}
  39743. +
  39744. +#ifdef DEBUG
  39745. +void __DWC_DEBUG(char *format, ...)
  39746. +{
  39747. + va_list args;
  39748. +
  39749. + va_start(args, format);
  39750. + DWC_VPRINTF(format, args);
  39751. + va_end(args);
  39752. +}
  39753. +#endif
  39754. +
  39755. +
  39756. +/* dwc_mem.h */
  39757. +
  39758. +#if 0
  39759. +dwc_pool_t *DWC_DMA_POOL_CREATE(uint32_t size,
  39760. + uint32_t align,
  39761. + uint32_t alloc)
  39762. +{
  39763. + struct dma_pool *pool = dma_pool_create("Pool", NULL,
  39764. + size, align, alloc);
  39765. + return (dwc_pool_t *)pool;
  39766. +}
  39767. +
  39768. +void DWC_DMA_POOL_DESTROY(dwc_pool_t *pool)
  39769. +{
  39770. + dma_pool_destroy((struct dma_pool *)pool);
  39771. +}
  39772. +
  39773. +void *DWC_DMA_POOL_ALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  39774. +{
  39775. +// return dma_pool_alloc((struct dma_pool *)pool, GFP_KERNEL, dma_addr);
  39776. + return dma_pool_alloc((struct dma_pool *)pool, M_WAITOK, dma_addr);
  39777. +}
  39778. +
  39779. +void *DWC_DMA_POOL_ZALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  39780. +{
  39781. + void *vaddr = DWC_DMA_POOL_ALLOC(pool, dma_addr);
  39782. + memset(..);
  39783. +}
  39784. +
  39785. +void DWC_DMA_POOL_FREE(dwc_pool_t *pool, void *vaddr, void *daddr)
  39786. +{
  39787. + dma_pool_free(pool, vaddr, daddr);
  39788. +}
  39789. +#endif
  39790. +
  39791. +static void dmamap_cb(void *arg, bus_dma_segment_t *segs, int nseg, int error)
  39792. +{
  39793. + if (error)
  39794. + return;
  39795. + *(bus_addr_t *)arg = segs[0].ds_addr;
  39796. +}
  39797. +
  39798. +void *__DWC_DMA_ALLOC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr)
  39799. +{
  39800. + dwc_dmactx_t *dma = (dwc_dmactx_t *)dma_ctx;
  39801. + int error;
  39802. +
  39803. + error = bus_dma_tag_create(
  39804. +#if __FreeBSD_version >= 700000
  39805. + bus_get_dma_tag(dma->dev), /* parent */
  39806. +#else
  39807. + NULL, /* parent */
  39808. +#endif
  39809. + 4, 0, /* alignment, bounds */
  39810. + BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
  39811. + BUS_SPACE_MAXADDR, /* highaddr */
  39812. + NULL, NULL, /* filter, filterarg */
  39813. + size, /* maxsize */
  39814. + 1, /* nsegments */
  39815. + size, /* maxsegsize */
  39816. + 0, /* flags */
  39817. + NULL, /* lockfunc */
  39818. + NULL, /* lockarg */
  39819. + &dma->dma_tag);
  39820. + if (error) {
  39821. + device_printf(dma->dev, "%s: bus_dma_tag_create failed: %d\n",
  39822. + __func__, error);
  39823. + goto fail_0;
  39824. + }
  39825. +
  39826. + error = bus_dmamem_alloc(dma->dma_tag, &dma->dma_vaddr,
  39827. + BUS_DMA_NOWAIT | BUS_DMA_COHERENT, &dma->dma_map);
  39828. + if (error) {
  39829. + device_printf(dma->dev, "%s: bus_dmamem_alloc(%ju) failed: %d\n",
  39830. + __func__, (uintmax_t)size, error);
  39831. + goto fail_1;
  39832. + }
  39833. +
  39834. + dma->dma_paddr = 0;
  39835. + error = bus_dmamap_load(dma->dma_tag, dma->dma_map, dma->dma_vaddr, size,
  39836. + dmamap_cb, &dma->dma_paddr, BUS_DMA_NOWAIT);
  39837. + if (error || dma->dma_paddr == 0) {
  39838. + device_printf(dma->dev, "%s: bus_dmamap_load failed: %d\n",
  39839. + __func__, error);
  39840. + goto fail_2;
  39841. + }
  39842. +
  39843. + *dma_addr = dma->dma_paddr;
  39844. + return dma->dma_vaddr;
  39845. +
  39846. +fail_2:
  39847. + bus_dmamap_unload(dma->dma_tag, dma->dma_map);
  39848. +fail_1:
  39849. + bus_dmamem_free(dma->dma_tag, dma->dma_vaddr, dma->dma_map);
  39850. + bus_dma_tag_destroy(dma->dma_tag);
  39851. +fail_0:
  39852. + dma->dma_map = NULL;
  39853. + dma->dma_tag = NULL;
  39854. +
  39855. + return NULL;
  39856. +}
  39857. +
  39858. +void __DWC_DMA_FREE(void *dma_ctx, uint32_t size, void *virt_addr, dwc_dma_t dma_addr)
  39859. +{
  39860. + dwc_dmactx_t *dma = (dwc_dmactx_t *)dma_ctx;
  39861. +
  39862. + if (dma->dma_tag == NULL)
  39863. + return;
  39864. + if (dma->dma_map != NULL) {
  39865. + bus_dmamap_sync(dma->dma_tag, dma->dma_map,
  39866. + BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
  39867. + bus_dmamap_unload(dma->dma_tag, dma->dma_map);
  39868. + bus_dmamem_free(dma->dma_tag, dma->dma_vaddr, dma->dma_map);
  39869. + dma->dma_map = NULL;
  39870. + }
  39871. +
  39872. + bus_dma_tag_destroy(dma->dma_tag);
  39873. + dma->dma_tag = NULL;
  39874. +}
  39875. +
  39876. +void *__DWC_ALLOC(void *mem_ctx, uint32_t size)
  39877. +{
  39878. + return malloc(size, M_DEVBUF, M_WAITOK | M_ZERO);
  39879. +}
  39880. +
  39881. +void *__DWC_ALLOC_ATOMIC(void *mem_ctx, uint32_t size)
  39882. +{
  39883. + return malloc(size, M_DEVBUF, M_NOWAIT | M_ZERO);
  39884. +}
  39885. +
  39886. +void __DWC_FREE(void *mem_ctx, void *addr)
  39887. +{
  39888. + free(addr, M_DEVBUF);
  39889. +}
  39890. +
  39891. +
  39892. +#ifdef DWC_CRYPTOLIB
  39893. +/* dwc_crypto.h */
  39894. +
  39895. +void DWC_RANDOM_BYTES(uint8_t *buffer, uint32_t length)
  39896. +{
  39897. + get_random_bytes(buffer, length);
  39898. +}
  39899. +
  39900. +int DWC_AES_CBC(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t iv[16], uint8_t *out)
  39901. +{
  39902. + struct crypto_blkcipher *tfm;
  39903. + struct blkcipher_desc desc;
  39904. + struct scatterlist sgd;
  39905. + struct scatterlist sgs;
  39906. +
  39907. + tfm = crypto_alloc_blkcipher("cbc(aes)", 0, CRYPTO_ALG_ASYNC);
  39908. + if (tfm == NULL) {
  39909. + printk("failed to load transform for aes CBC\n");
  39910. + return -1;
  39911. + }
  39912. +
  39913. + crypto_blkcipher_setkey(tfm, key, keylen);
  39914. + crypto_blkcipher_set_iv(tfm, iv, 16);
  39915. +
  39916. + sg_init_one(&sgd, out, messagelen);
  39917. + sg_init_one(&sgs, message, messagelen);
  39918. +
  39919. + desc.tfm = tfm;
  39920. + desc.flags = 0;
  39921. +
  39922. + if (crypto_blkcipher_encrypt(&desc, &sgd, &sgs, messagelen)) {
  39923. + crypto_free_blkcipher(tfm);
  39924. + DWC_ERROR("AES CBC encryption failed");
  39925. + return -1;
  39926. + }
  39927. +
  39928. + crypto_free_blkcipher(tfm);
  39929. + return 0;
  39930. +}
  39931. +
  39932. +int DWC_SHA256(uint8_t *message, uint32_t len, uint8_t *out)
  39933. +{
  39934. + struct crypto_hash *tfm;
  39935. + struct hash_desc desc;
  39936. + struct scatterlist sg;
  39937. +
  39938. + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
  39939. + if (IS_ERR(tfm)) {
  39940. + DWC_ERROR("Failed to load transform for sha256: %ld", PTR_ERR(tfm));
  39941. + return 0;
  39942. + }
  39943. + desc.tfm = tfm;
  39944. + desc.flags = 0;
  39945. +
  39946. + sg_init_one(&sg, message, len);
  39947. + crypto_hash_digest(&desc, &sg, len, out);
  39948. + crypto_free_hash(tfm);
  39949. +
  39950. + return 1;
  39951. +}
  39952. +
  39953. +int DWC_HMAC_SHA256(uint8_t *message, uint32_t messagelen,
  39954. + uint8_t *key, uint32_t keylen, uint8_t *out)
  39955. +{
  39956. + struct crypto_hash *tfm;
  39957. + struct hash_desc desc;
  39958. + struct scatterlist sg;
  39959. +
  39960. + tfm = crypto_alloc_hash("hmac(sha256)", 0, CRYPTO_ALG_ASYNC);
  39961. + if (IS_ERR(tfm)) {
  39962. + DWC_ERROR("Failed to load transform for hmac(sha256): %ld", PTR_ERR(tfm));
  39963. + return 0;
  39964. + }
  39965. + desc.tfm = tfm;
  39966. + desc.flags = 0;
  39967. +
  39968. + sg_init_one(&sg, message, messagelen);
  39969. + crypto_hash_setkey(tfm, key, keylen);
  39970. + crypto_hash_digest(&desc, &sg, messagelen, out);
  39971. + crypto_free_hash(tfm);
  39972. +
  39973. + return 1;
  39974. +}
  39975. +
  39976. +#endif /* DWC_CRYPTOLIB */
  39977. +
  39978. +
  39979. +/* Byte Ordering Conversions */
  39980. +
  39981. +uint32_t DWC_CPU_TO_LE32(uint32_t *p)
  39982. +{
  39983. +#ifdef __LITTLE_ENDIAN
  39984. + return *p;
  39985. +#else
  39986. + uint8_t *u_p = (uint8_t *)p;
  39987. +
  39988. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  39989. +#endif
  39990. +}
  39991. +
  39992. +uint32_t DWC_CPU_TO_BE32(uint32_t *p)
  39993. +{
  39994. +#ifdef __BIG_ENDIAN
  39995. + return *p;
  39996. +#else
  39997. + uint8_t *u_p = (uint8_t *)p;
  39998. +
  39999. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  40000. +#endif
  40001. +}
  40002. +
  40003. +uint32_t DWC_LE32_TO_CPU(uint32_t *p)
  40004. +{
  40005. +#ifdef __LITTLE_ENDIAN
  40006. + return *p;
  40007. +#else
  40008. + uint8_t *u_p = (uint8_t *)p;
  40009. +
  40010. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  40011. +#endif
  40012. +}
  40013. +
  40014. +uint32_t DWC_BE32_TO_CPU(uint32_t *p)
  40015. +{
  40016. +#ifdef __BIG_ENDIAN
  40017. + return *p;
  40018. +#else
  40019. + uint8_t *u_p = (uint8_t *)p;
  40020. +
  40021. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  40022. +#endif
  40023. +}
  40024. +
  40025. +uint16_t DWC_CPU_TO_LE16(uint16_t *p)
  40026. +{
  40027. +#ifdef __LITTLE_ENDIAN
  40028. + return *p;
  40029. +#else
  40030. + uint8_t *u_p = (uint8_t *)p;
  40031. + return (u_p[1] | (u_p[0] << 8));
  40032. +#endif
  40033. +}
  40034. +
  40035. +uint16_t DWC_CPU_TO_BE16(uint16_t *p)
  40036. +{
  40037. +#ifdef __BIG_ENDIAN
  40038. + return *p;
  40039. +#else
  40040. + uint8_t *u_p = (uint8_t *)p;
  40041. + return (u_p[1] | (u_p[0] << 8));
  40042. +#endif
  40043. +}
  40044. +
  40045. +uint16_t DWC_LE16_TO_CPU(uint16_t *p)
  40046. +{
  40047. +#ifdef __LITTLE_ENDIAN
  40048. + return *p;
  40049. +#else
  40050. + uint8_t *u_p = (uint8_t *)p;
  40051. + return (u_p[1] | (u_p[0] << 8));
  40052. +#endif
  40053. +}
  40054. +
  40055. +uint16_t DWC_BE16_TO_CPU(uint16_t *p)
  40056. +{
  40057. +#ifdef __BIG_ENDIAN
  40058. + return *p;
  40059. +#else
  40060. + uint8_t *u_p = (uint8_t *)p;
  40061. + return (u_p[1] | (u_p[0] << 8));
  40062. +#endif
  40063. +}
  40064. +
  40065. +
  40066. +/* Registers */
  40067. +
  40068. +uint32_t DWC_READ_REG32(void *io_ctx, uint32_t volatile *reg)
  40069. +{
  40070. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  40071. + bus_size_t ior = (bus_size_t)reg;
  40072. +
  40073. + return bus_space_read_4(io->iot, io->ioh, ior);
  40074. +}
  40075. +
  40076. +#if 0
  40077. +uint64_t DWC_READ_REG64(void *io_ctx, uint64_t volatile *reg)
  40078. +{
  40079. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  40080. + bus_size_t ior = (bus_size_t)reg;
  40081. +
  40082. + return bus_space_read_8(io->iot, io->ioh, ior);
  40083. +}
  40084. +#endif
  40085. +
  40086. +void DWC_WRITE_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t value)
  40087. +{
  40088. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  40089. + bus_size_t ior = (bus_size_t)reg;
  40090. +
  40091. + bus_space_write_4(io->iot, io->ioh, ior, value);
  40092. +}
  40093. +
  40094. +#if 0
  40095. +void DWC_WRITE_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t value)
  40096. +{
  40097. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  40098. + bus_size_t ior = (bus_size_t)reg;
  40099. +
  40100. + bus_space_write_8(io->iot, io->ioh, ior, value);
  40101. +}
  40102. +#endif
  40103. +
  40104. +void DWC_MODIFY_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t clear_mask,
  40105. + uint32_t set_mask)
  40106. +{
  40107. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  40108. + bus_size_t ior = (bus_size_t)reg;
  40109. +
  40110. + bus_space_write_4(io->iot, io->ioh, ior,
  40111. + (bus_space_read_4(io->iot, io->ioh, ior) &
  40112. + ~clear_mask) | set_mask);
  40113. +}
  40114. +
  40115. +#if 0
  40116. +void DWC_MODIFY_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t clear_mask,
  40117. + uint64_t set_mask)
  40118. +{
  40119. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  40120. + bus_size_t ior = (bus_size_t)reg;
  40121. +
  40122. + bus_space_write_8(io->iot, io->ioh, ior,
  40123. + (bus_space_read_8(io->iot, io->ioh, ior) &
  40124. + ~clear_mask) | set_mask);
  40125. +}
  40126. +#endif
  40127. +
  40128. +
  40129. +/* Locking */
  40130. +
  40131. +dwc_spinlock_t *DWC_SPINLOCK_ALLOC(void)
  40132. +{
  40133. + struct mtx *sl = DWC_ALLOC(sizeof(*sl));
  40134. +
  40135. + if (!sl) {
  40136. + DWC_ERROR("Cannot allocate memory for spinlock");
  40137. + return NULL;
  40138. + }
  40139. +
  40140. + mtx_init(sl, "dw3spn", NULL, MTX_SPIN);
  40141. + return (dwc_spinlock_t *)sl;
  40142. +}
  40143. +
  40144. +void DWC_SPINLOCK_FREE(dwc_spinlock_t *lock)
  40145. +{
  40146. + struct mtx *sl = (struct mtx *)lock;
  40147. +
  40148. + mtx_destroy(sl);
  40149. + DWC_FREE(sl);
  40150. +}
  40151. +
  40152. +void DWC_SPINLOCK(dwc_spinlock_t *lock)
  40153. +{
  40154. + mtx_lock_spin((struct mtx *)lock); // ???
  40155. +}
  40156. +
  40157. +void DWC_SPINUNLOCK(dwc_spinlock_t *lock)
  40158. +{
  40159. + mtx_unlock_spin((struct mtx *)lock); // ???
  40160. +}
  40161. +
  40162. +void DWC_SPINLOCK_IRQSAVE(dwc_spinlock_t *lock, dwc_irqflags_t *flags)
  40163. +{
  40164. + mtx_lock_spin((struct mtx *)lock);
  40165. +}
  40166. +
  40167. +void DWC_SPINUNLOCK_IRQRESTORE(dwc_spinlock_t *lock, dwc_irqflags_t flags)
  40168. +{
  40169. + mtx_unlock_spin((struct mtx *)lock);
  40170. +}
  40171. +
  40172. +dwc_mutex_t *DWC_MUTEX_ALLOC(void)
  40173. +{
  40174. + struct mtx *m;
  40175. + dwc_mutex_t *mutex = (dwc_mutex_t *)DWC_ALLOC(sizeof(struct mtx));
  40176. +
  40177. + if (!mutex) {
  40178. + DWC_ERROR("Cannot allocate memory for mutex");
  40179. + return NULL;
  40180. + }
  40181. +
  40182. + m = (struct mtx *)mutex;
  40183. + mtx_init(m, "dw3mtx", NULL, MTX_DEF);
  40184. + return mutex;
  40185. +}
  40186. +
  40187. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  40188. +#else
  40189. +void DWC_MUTEX_FREE(dwc_mutex_t *mutex)
  40190. +{
  40191. + mtx_destroy((struct mtx *)mutex);
  40192. + DWC_FREE(mutex);
  40193. +}
  40194. +#endif
  40195. +
  40196. +void DWC_MUTEX_LOCK(dwc_mutex_t *mutex)
  40197. +{
  40198. + struct mtx *m = (struct mtx *)mutex;
  40199. +
  40200. + mtx_lock(m);
  40201. +}
  40202. +
  40203. +int DWC_MUTEX_TRYLOCK(dwc_mutex_t *mutex)
  40204. +{
  40205. + struct mtx *m = (struct mtx *)mutex;
  40206. +
  40207. + return mtx_trylock(m);
  40208. +}
  40209. +
  40210. +void DWC_MUTEX_UNLOCK(dwc_mutex_t *mutex)
  40211. +{
  40212. + struct mtx *m = (struct mtx *)mutex;
  40213. +
  40214. + mtx_unlock(m);
  40215. +}
  40216. +
  40217. +
  40218. +/* Timing */
  40219. +
  40220. +void DWC_UDELAY(uint32_t usecs)
  40221. +{
  40222. + DELAY(usecs);
  40223. +}
  40224. +
  40225. +void DWC_MDELAY(uint32_t msecs)
  40226. +{
  40227. + do {
  40228. + DELAY(1000);
  40229. + } while (--msecs);
  40230. +}
  40231. +
  40232. +void DWC_MSLEEP(uint32_t msecs)
  40233. +{
  40234. + struct timeval tv;
  40235. +
  40236. + tv.tv_sec = msecs / 1000;
  40237. + tv.tv_usec = (msecs - tv.tv_sec * 1000) * 1000;
  40238. + pause("dw3slp", tvtohz(&tv));
  40239. +}
  40240. +
  40241. +uint32_t DWC_TIME(void)
  40242. +{
  40243. + struct timeval tv;
  40244. +
  40245. + microuptime(&tv); // or getmicrouptime? (less precise, but faster)
  40246. + return tv.tv_sec * 1000 + tv.tv_usec / 1000;
  40247. +}
  40248. +
  40249. +
  40250. +/* Timers */
  40251. +
  40252. +struct dwc_timer {
  40253. + struct callout t;
  40254. + char *name;
  40255. + dwc_spinlock_t *lock;
  40256. + dwc_timer_callback_t cb;
  40257. + void *data;
  40258. +};
  40259. +
  40260. +dwc_timer_t *DWC_TIMER_ALLOC(char *name, dwc_timer_callback_t cb, void *data)
  40261. +{
  40262. + dwc_timer_t *t = DWC_ALLOC(sizeof(*t));
  40263. +
  40264. + if (!t) {
  40265. + DWC_ERROR("Cannot allocate memory for timer");
  40266. + return NULL;
  40267. + }
  40268. +
  40269. + callout_init(&t->t, 1);
  40270. +
  40271. + t->name = DWC_STRDUP(name);
  40272. + if (!t->name) {
  40273. + DWC_ERROR("Cannot allocate memory for timer->name");
  40274. + goto no_name;
  40275. + }
  40276. +
  40277. + t->lock = DWC_SPINLOCK_ALLOC();
  40278. + if (!t->lock) {
  40279. + DWC_ERROR("Cannot allocate memory for lock");
  40280. + goto no_lock;
  40281. + }
  40282. +
  40283. + t->cb = cb;
  40284. + t->data = data;
  40285. +
  40286. + return t;
  40287. +
  40288. + no_lock:
  40289. + DWC_FREE(t->name);
  40290. + no_name:
  40291. + DWC_FREE(t);
  40292. +
  40293. + return NULL;
  40294. +}
  40295. +
  40296. +void DWC_TIMER_FREE(dwc_timer_t *timer)
  40297. +{
  40298. + callout_stop(&timer->t);
  40299. + DWC_SPINLOCK_FREE(timer->lock);
  40300. + DWC_FREE(timer->name);
  40301. + DWC_FREE(timer);
  40302. +}
  40303. +
  40304. +void DWC_TIMER_SCHEDULE(dwc_timer_t *timer, uint32_t time)
  40305. +{
  40306. + struct timeval tv;
  40307. +
  40308. + tv.tv_sec = time / 1000;
  40309. + tv.tv_usec = (time - tv.tv_sec * 1000) * 1000;
  40310. + callout_reset(&timer->t, tvtohz(&tv), timer->cb, timer->data);
  40311. +}
  40312. +
  40313. +void DWC_TIMER_CANCEL(dwc_timer_t *timer)
  40314. +{
  40315. + callout_stop(&timer->t);
  40316. +}
  40317. +
  40318. +
  40319. +/* Wait Queues */
  40320. +
  40321. +struct dwc_waitq {
  40322. + struct mtx lock;
  40323. + int abort;
  40324. +};
  40325. +
  40326. +dwc_waitq_t *DWC_WAITQ_ALLOC(void)
  40327. +{
  40328. + dwc_waitq_t *wq = DWC_ALLOC(sizeof(*wq));
  40329. +
  40330. + if (!wq) {
  40331. + DWC_ERROR("Cannot allocate memory for waitqueue");
  40332. + return NULL;
  40333. + }
  40334. +
  40335. + mtx_init(&wq->lock, "dw3wtq", NULL, MTX_DEF);
  40336. + wq->abort = 0;
  40337. +
  40338. + return wq;
  40339. +}
  40340. +
  40341. +void DWC_WAITQ_FREE(dwc_waitq_t *wq)
  40342. +{
  40343. + mtx_destroy(&wq->lock);
  40344. + DWC_FREE(wq);
  40345. +}
  40346. +
  40347. +int32_t DWC_WAITQ_WAIT(dwc_waitq_t *wq, dwc_waitq_condition_t cond, void *data)
  40348. +{
  40349. +// intrmask_t ipl;
  40350. + int result = 0;
  40351. +
  40352. + mtx_lock(&wq->lock);
  40353. +// ipl = splbio();
  40354. +
  40355. + /* Skip the sleep if already aborted or triggered */
  40356. + if (!wq->abort && !cond(data)) {
  40357. +// splx(ipl);
  40358. + result = msleep(wq, &wq->lock, PCATCH, "dw3wat", 0); // infinite timeout
  40359. +// ipl = splbio();
  40360. + }
  40361. +
  40362. + if (result == ERESTART) { // signaled - restart
  40363. + result = -DWC_E_RESTART;
  40364. +
  40365. + } else if (result == EINTR) { // signaled - interrupt
  40366. + result = -DWC_E_ABORT;
  40367. +
  40368. + } else if (wq->abort) {
  40369. + result = -DWC_E_ABORT;
  40370. +
  40371. + } else {
  40372. + result = 0;
  40373. + }
  40374. +
  40375. + wq->abort = 0;
  40376. +// splx(ipl);
  40377. + mtx_unlock(&wq->lock);
  40378. + return result;
  40379. +}
  40380. +
  40381. +int32_t DWC_WAITQ_WAIT_TIMEOUT(dwc_waitq_t *wq, dwc_waitq_condition_t cond,
  40382. + void *data, int32_t msecs)
  40383. +{
  40384. + struct timeval tv, tv1, tv2;
  40385. +// intrmask_t ipl;
  40386. + int result = 0;
  40387. +
  40388. + tv.tv_sec = msecs / 1000;
  40389. + tv.tv_usec = (msecs - tv.tv_sec * 1000) * 1000;
  40390. +
  40391. + mtx_lock(&wq->lock);
  40392. +// ipl = splbio();
  40393. +
  40394. + /* Skip the sleep if already aborted or triggered */
  40395. + if (!wq->abort && !cond(data)) {
  40396. +// splx(ipl);
  40397. + getmicrouptime(&tv1);
  40398. + result = msleep(wq, &wq->lock, PCATCH, "dw3wto", tvtohz(&tv));
  40399. + getmicrouptime(&tv2);
  40400. +// ipl = splbio();
  40401. + }
  40402. +
  40403. + if (result == 0) { // awoken
  40404. + if (wq->abort) {
  40405. + result = -DWC_E_ABORT;
  40406. + } else {
  40407. + tv2.tv_usec -= tv1.tv_usec;
  40408. + if (tv2.tv_usec < 0) {
  40409. + tv2.tv_usec += 1000000;
  40410. + tv2.tv_sec--;
  40411. + }
  40412. +
  40413. + tv2.tv_sec -= tv1.tv_sec;
  40414. + result = tv2.tv_sec * 1000 + tv2.tv_usec / 1000;
  40415. + result = msecs - result;
  40416. + if (result <= 0)
  40417. + result = 1;
  40418. + }
  40419. + } else if (result == ERESTART) { // signaled - restart
  40420. + result = -DWC_E_RESTART;
  40421. +
  40422. + } else if (result == EINTR) { // signaled - interrupt
  40423. + result = -DWC_E_ABORT;
  40424. +
  40425. + } else { // timed out
  40426. + result = -DWC_E_TIMEOUT;
  40427. + }
  40428. +
  40429. + wq->abort = 0;
  40430. +// splx(ipl);
  40431. + mtx_unlock(&wq->lock);
  40432. + return result;
  40433. +}
  40434. +
  40435. +void DWC_WAITQ_TRIGGER(dwc_waitq_t *wq)
  40436. +{
  40437. + wakeup(wq);
  40438. +}
  40439. +
  40440. +void DWC_WAITQ_ABORT(dwc_waitq_t *wq)
  40441. +{
  40442. +// intrmask_t ipl;
  40443. +
  40444. + mtx_lock(&wq->lock);
  40445. +// ipl = splbio();
  40446. + wq->abort = 1;
  40447. + wakeup(wq);
  40448. +// splx(ipl);
  40449. + mtx_unlock(&wq->lock);
  40450. +}
  40451. +
  40452. +
  40453. +/* Threading */
  40454. +
  40455. +struct dwc_thread {
  40456. + struct proc *proc;
  40457. + int abort;
  40458. +};
  40459. +
  40460. +dwc_thread_t *DWC_THREAD_RUN(dwc_thread_function_t func, char *name, void *data)
  40461. +{
  40462. + int retval;
  40463. + dwc_thread_t *thread = DWC_ALLOC(sizeof(*thread));
  40464. +
  40465. + if (!thread) {
  40466. + return NULL;
  40467. + }
  40468. +
  40469. + thread->abort = 0;
  40470. + retval = kthread_create((void (*)(void *))func, data, &thread->proc,
  40471. + RFPROC | RFNOWAIT, 0, "%s", name);
  40472. + if (retval) {
  40473. + DWC_FREE(thread);
  40474. + return NULL;
  40475. + }
  40476. +
  40477. + return thread;
  40478. +}
  40479. +
  40480. +int DWC_THREAD_STOP(dwc_thread_t *thread)
  40481. +{
  40482. + int retval;
  40483. +
  40484. + thread->abort = 1;
  40485. + retval = tsleep(&thread->abort, 0, "dw3stp", 60 * hz);
  40486. +
  40487. + if (retval == 0) {
  40488. + /* DWC_THREAD_EXIT() will free the thread struct */
  40489. + return 0;
  40490. + }
  40491. +
  40492. + /* NOTE: We leak the thread struct if thread doesn't die */
  40493. +
  40494. + if (retval == EWOULDBLOCK) {
  40495. + return -DWC_E_TIMEOUT;
  40496. + }
  40497. +
  40498. + return -DWC_E_UNKNOWN;
  40499. +}
  40500. +
  40501. +dwc_bool_t DWC_THREAD_SHOULD_STOP(dwc_thread_t *thread)
  40502. +{
  40503. + return thread->abort;
  40504. +}
  40505. +
  40506. +void DWC_THREAD_EXIT(dwc_thread_t *thread)
  40507. +{
  40508. + wakeup(&thread->abort);
  40509. + DWC_FREE(thread);
  40510. + kthread_exit(0);
  40511. +}
  40512. +
  40513. +
  40514. +/* tasklets
  40515. + - Runs in interrupt context (cannot sleep)
  40516. + - Each tasklet runs on a single CPU [ How can we ensure this on FreeBSD? Does it matter? ]
  40517. + - Different tasklets can be running simultaneously on different CPUs [ shouldn't matter ]
  40518. + */
  40519. +struct dwc_tasklet {
  40520. + struct task t;
  40521. + dwc_tasklet_callback_t cb;
  40522. + void *data;
  40523. +};
  40524. +
  40525. +static void tasklet_callback(void *data, int pending) // what to do with pending ???
  40526. +{
  40527. + dwc_tasklet_t *task = (dwc_tasklet_t *)data;
  40528. +
  40529. + task->cb(task->data);
  40530. +}
  40531. +
  40532. +dwc_tasklet_t *DWC_TASK_ALLOC(char *name, dwc_tasklet_callback_t cb, void *data)
  40533. +{
  40534. + dwc_tasklet_t *task = DWC_ALLOC(sizeof(*task));
  40535. +
  40536. + if (task) {
  40537. + task->cb = cb;
  40538. + task->data = data;
  40539. + TASK_INIT(&task->t, 0, tasklet_callback, task);
  40540. + } else {
  40541. + DWC_ERROR("Cannot allocate memory for tasklet");
  40542. + }
  40543. +
  40544. + return task;
  40545. +}
  40546. +
  40547. +void DWC_TASK_FREE(dwc_tasklet_t *task)
  40548. +{
  40549. + taskqueue_drain(taskqueue_fast, &task->t); // ???
  40550. + DWC_FREE(task);
  40551. +}
  40552. +
  40553. +void DWC_TASK_SCHEDULE(dwc_tasklet_t *task)
  40554. +{
  40555. + /* Uses predefined system queue */
  40556. + taskqueue_enqueue_fast(taskqueue_fast, &task->t);
  40557. +}
  40558. +
  40559. +
  40560. +/* workqueues
  40561. + - Runs in process context (can sleep)
  40562. + */
  40563. +typedef struct work_container {
  40564. + dwc_work_callback_t cb;
  40565. + void *data;
  40566. + dwc_workq_t *wq;
  40567. + char *name;
  40568. + int hz;
  40569. +
  40570. +#ifdef DEBUG
  40571. + DWC_CIRCLEQ_ENTRY(work_container) entry;
  40572. +#endif
  40573. + struct task task;
  40574. +} work_container_t;
  40575. +
  40576. +#ifdef DEBUG
  40577. +DWC_CIRCLEQ_HEAD(work_container_queue, work_container);
  40578. +#endif
  40579. +
  40580. +struct dwc_workq {
  40581. + struct taskqueue *taskq;
  40582. + dwc_spinlock_t *lock;
  40583. + dwc_waitq_t *waitq;
  40584. + int pending;
  40585. +
  40586. +#ifdef DEBUG
  40587. + struct work_container_queue entries;
  40588. +#endif
  40589. +};
  40590. +
  40591. +static void do_work(void *data, int pending) // what to do with pending ???
  40592. +{
  40593. + work_container_t *container = (work_container_t *)data;
  40594. + dwc_workq_t *wq = container->wq;
  40595. + dwc_irqflags_t flags;
  40596. +
  40597. + if (container->hz) {
  40598. + pause("dw3wrk", container->hz);
  40599. + }
  40600. +
  40601. + container->cb(container->data);
  40602. + DWC_DEBUG("Work done: %s, container=%p", container->name, container);
  40603. +
  40604. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  40605. +
  40606. +#ifdef DEBUG
  40607. + DWC_CIRCLEQ_REMOVE(&wq->entries, container, entry);
  40608. +#endif
  40609. + if (container->name)
  40610. + DWC_FREE(container->name);
  40611. + DWC_FREE(container);
  40612. + wq->pending--;
  40613. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  40614. + DWC_WAITQ_TRIGGER(wq->waitq);
  40615. +}
  40616. +
  40617. +static int work_done(void *data)
  40618. +{
  40619. + dwc_workq_t *workq = (dwc_workq_t *)data;
  40620. +
  40621. + return workq->pending == 0;
  40622. +}
  40623. +
  40624. +int DWC_WORKQ_WAIT_WORK_DONE(dwc_workq_t *workq, int timeout)
  40625. +{
  40626. + return DWC_WAITQ_WAIT_TIMEOUT(workq->waitq, work_done, workq, timeout);
  40627. +}
  40628. +
  40629. +dwc_workq_t *DWC_WORKQ_ALLOC(char *name)
  40630. +{
  40631. + dwc_workq_t *wq = DWC_ALLOC(sizeof(*wq));
  40632. +
  40633. + if (!wq) {
  40634. + DWC_ERROR("Cannot allocate memory for workqueue");
  40635. + return NULL;
  40636. + }
  40637. +
  40638. + wq->taskq = taskqueue_create(name, M_NOWAIT, taskqueue_thread_enqueue, &wq->taskq);
  40639. + if (!wq->taskq) {
  40640. + DWC_ERROR("Cannot allocate memory for taskqueue");
  40641. + goto no_taskq;
  40642. + }
  40643. +
  40644. + wq->pending = 0;
  40645. +
  40646. + wq->lock = DWC_SPINLOCK_ALLOC();
  40647. + if (!wq->lock) {
  40648. + DWC_ERROR("Cannot allocate memory for spinlock");
  40649. + goto no_lock;
  40650. + }
  40651. +
  40652. + wq->waitq = DWC_WAITQ_ALLOC();
  40653. + if (!wq->waitq) {
  40654. + DWC_ERROR("Cannot allocate memory for waitqueue");
  40655. + goto no_waitq;
  40656. + }
  40657. +
  40658. + taskqueue_start_threads(&wq->taskq, 1, PWAIT, "%s taskq", "dw3tsk");
  40659. +
  40660. +#ifdef DEBUG
  40661. + DWC_CIRCLEQ_INIT(&wq->entries);
  40662. +#endif
  40663. + return wq;
  40664. +
  40665. + no_waitq:
  40666. + DWC_SPINLOCK_FREE(wq->lock);
  40667. + no_lock:
  40668. + taskqueue_free(wq->taskq);
  40669. + no_taskq:
  40670. + DWC_FREE(wq);
  40671. +
  40672. + return NULL;
  40673. +}
  40674. +
  40675. +void DWC_WORKQ_FREE(dwc_workq_t *wq)
  40676. +{
  40677. +#ifdef DEBUG
  40678. + dwc_irqflags_t flags;
  40679. +
  40680. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  40681. +
  40682. + if (wq->pending != 0) {
  40683. + struct work_container *container;
  40684. +
  40685. + DWC_ERROR("Destroying work queue with pending work");
  40686. +
  40687. + DWC_CIRCLEQ_FOREACH(container, &wq->entries, entry) {
  40688. + DWC_ERROR("Work %s still pending", container->name);
  40689. + }
  40690. + }
  40691. +
  40692. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  40693. +#endif
  40694. + DWC_WAITQ_FREE(wq->waitq);
  40695. + DWC_SPINLOCK_FREE(wq->lock);
  40696. + taskqueue_free(wq->taskq);
  40697. + DWC_FREE(wq);
  40698. +}
  40699. +
  40700. +void DWC_WORKQ_SCHEDULE(dwc_workq_t *wq, dwc_work_callback_t cb, void *data,
  40701. + char *format, ...)
  40702. +{
  40703. + dwc_irqflags_t flags;
  40704. + work_container_t *container;
  40705. + static char name[128];
  40706. + va_list args;
  40707. +
  40708. + va_start(args, format);
  40709. + DWC_VSNPRINTF(name, 128, format, args);
  40710. + va_end(args);
  40711. +
  40712. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  40713. + wq->pending++;
  40714. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  40715. + DWC_WAITQ_TRIGGER(wq->waitq);
  40716. +
  40717. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  40718. + if (!container) {
  40719. + DWC_ERROR("Cannot allocate memory for container");
  40720. + return;
  40721. + }
  40722. +
  40723. + container->name = DWC_STRDUP(name);
  40724. + if (!container->name) {
  40725. + DWC_ERROR("Cannot allocate memory for container->name");
  40726. + DWC_FREE(container);
  40727. + return;
  40728. + }
  40729. +
  40730. + container->cb = cb;
  40731. + container->data = data;
  40732. + container->wq = wq;
  40733. + container->hz = 0;
  40734. +
  40735. + DWC_DEBUG("Queueing work: %s, container=%p", container->name, container);
  40736. +
  40737. + TASK_INIT(&container->task, 0, do_work, container);
  40738. +
  40739. +#ifdef DEBUG
  40740. + DWC_CIRCLEQ_INSERT_TAIL(&wq->entries, container, entry);
  40741. +#endif
  40742. + taskqueue_enqueue_fast(wq->taskq, &container->task);
  40743. +}
  40744. +
  40745. +void DWC_WORKQ_SCHEDULE_DELAYED(dwc_workq_t *wq, dwc_work_callback_t cb,
  40746. + void *data, uint32_t time, char *format, ...)
  40747. +{
  40748. + dwc_irqflags_t flags;
  40749. + work_container_t *container;
  40750. + static char name[128];
  40751. + struct timeval tv;
  40752. + va_list args;
  40753. +
  40754. + va_start(args, format);
  40755. + DWC_VSNPRINTF(name, 128, format, args);
  40756. + va_end(args);
  40757. +
  40758. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  40759. + wq->pending++;
  40760. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  40761. + DWC_WAITQ_TRIGGER(wq->waitq);
  40762. +
  40763. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  40764. + if (!container) {
  40765. + DWC_ERROR("Cannot allocate memory for container");
  40766. + return;
  40767. + }
  40768. +
  40769. + container->name = DWC_STRDUP(name);
  40770. + if (!container->name) {
  40771. + DWC_ERROR("Cannot allocate memory for container->name");
  40772. + DWC_FREE(container);
  40773. + return;
  40774. + }
  40775. +
  40776. + container->cb = cb;
  40777. + container->data = data;
  40778. + container->wq = wq;
  40779. +
  40780. + tv.tv_sec = time / 1000;
  40781. + tv.tv_usec = (time - tv.tv_sec * 1000) * 1000;
  40782. + container->hz = tvtohz(&tv);
  40783. +
  40784. + DWC_DEBUG("Queueing work: %s, container=%p", container->name, container);
  40785. +
  40786. + TASK_INIT(&container->task, 0, do_work, container);
  40787. +
  40788. +#ifdef DEBUG
  40789. + DWC_CIRCLEQ_INSERT_TAIL(&wq->entries, container, entry);
  40790. +#endif
  40791. + taskqueue_enqueue_fast(wq->taskq, &container->task);
  40792. +}
  40793. +
  40794. +int DWC_WORKQ_PENDING(dwc_workq_t *wq)
  40795. +{
  40796. + return wq->pending;
  40797. +}
  40798. diff -Nur linux-3.13.11/drivers/usb/host/dwc_common_port/dwc_common_linux.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_common_linux.c
  40799. --- linux-3.13.11/drivers/usb/host/dwc_common_port/dwc_common_linux.c 1970-01-01 01:00:00.000000000 +0100
  40800. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_common_linux.c 2014-04-24 15:37:13.306990445 +0200
  40801. @@ -0,0 +1,1432 @@
  40802. +#include <linux/kernel.h>
  40803. +#include <linux/init.h>
  40804. +#include <linux/module.h>
  40805. +#include <linux/kthread.h>
  40806. +
  40807. +#ifdef DWC_CCLIB
  40808. +# include "dwc_cc.h"
  40809. +#endif
  40810. +
  40811. +#ifdef DWC_CRYPTOLIB
  40812. +# include "dwc_modpow.h"
  40813. +# include "dwc_dh.h"
  40814. +# include "dwc_crypto.h"
  40815. +#endif
  40816. +
  40817. +#ifdef DWC_NOTIFYLIB
  40818. +# include "dwc_notifier.h"
  40819. +#endif
  40820. +
  40821. +/* OS-Level Implementations */
  40822. +
  40823. +/* This is the Linux kernel implementation of the DWC platform library. */
  40824. +#include <linux/moduleparam.h>
  40825. +#include <linux/ctype.h>
  40826. +#include <linux/crypto.h>
  40827. +#include <linux/delay.h>
  40828. +#include <linux/device.h>
  40829. +#include <linux/dma-mapping.h>
  40830. +#include <linux/cdev.h>
  40831. +#include <linux/errno.h>
  40832. +#include <linux/interrupt.h>
  40833. +#include <linux/jiffies.h>
  40834. +#include <linux/list.h>
  40835. +#include <linux/pci.h>
  40836. +#include <linux/random.h>
  40837. +#include <linux/scatterlist.h>
  40838. +#include <linux/slab.h>
  40839. +#include <linux/stat.h>
  40840. +#include <linux/string.h>
  40841. +#include <linux/timer.h>
  40842. +#include <linux/usb.h>
  40843. +
  40844. +#include <linux/version.h>
  40845. +
  40846. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
  40847. +# include <linux/usb/gadget.h>
  40848. +#else
  40849. +# include <linux/usb_gadget.h>
  40850. +#endif
  40851. +
  40852. +#include <asm/io.h>
  40853. +#include <asm/page.h>
  40854. +#include <asm/uaccess.h>
  40855. +#include <asm/unaligned.h>
  40856. +
  40857. +#include "dwc_os.h"
  40858. +#include "dwc_list.h"
  40859. +
  40860. +
  40861. +/* MISC */
  40862. +
  40863. +void *DWC_MEMSET(void *dest, uint8_t byte, uint32_t size)
  40864. +{
  40865. + return memset(dest, byte, size);
  40866. +}
  40867. +
  40868. +void *DWC_MEMCPY(void *dest, void const *src, uint32_t size)
  40869. +{
  40870. + return memcpy(dest, src, size);
  40871. +}
  40872. +
  40873. +void *DWC_MEMMOVE(void *dest, void *src, uint32_t size)
  40874. +{
  40875. + return memmove(dest, src, size);
  40876. +}
  40877. +
  40878. +int DWC_MEMCMP(void *m1, void *m2, uint32_t size)
  40879. +{
  40880. + return memcmp(m1, m2, size);
  40881. +}
  40882. +
  40883. +int DWC_STRNCMP(void *s1, void *s2, uint32_t size)
  40884. +{
  40885. + return strncmp(s1, s2, size);
  40886. +}
  40887. +
  40888. +int DWC_STRCMP(void *s1, void *s2)
  40889. +{
  40890. + return strcmp(s1, s2);
  40891. +}
  40892. +
  40893. +int DWC_STRLEN(char const *str)
  40894. +{
  40895. + return strlen(str);
  40896. +}
  40897. +
  40898. +char *DWC_STRCPY(char *to, char const *from)
  40899. +{
  40900. + return strcpy(to, from);
  40901. +}
  40902. +
  40903. +char *DWC_STRDUP(char const *str)
  40904. +{
  40905. + int len = DWC_STRLEN(str) + 1;
  40906. + char *new = DWC_ALLOC_ATOMIC(len);
  40907. +
  40908. + if (!new) {
  40909. + return NULL;
  40910. + }
  40911. +
  40912. + DWC_MEMCPY(new, str, len);
  40913. + return new;
  40914. +}
  40915. +
  40916. +int DWC_ATOI(const char *str, int32_t *value)
  40917. +{
  40918. + char *end = NULL;
  40919. +
  40920. + *value = simple_strtol(str, &end, 0);
  40921. + if (*end == '\0') {
  40922. + return 0;
  40923. + }
  40924. +
  40925. + return -1;
  40926. +}
  40927. +
  40928. +int DWC_ATOUI(const char *str, uint32_t *value)
  40929. +{
  40930. + char *end = NULL;
  40931. +
  40932. + *value = simple_strtoul(str, &end, 0);
  40933. + if (*end == '\0') {
  40934. + return 0;
  40935. + }
  40936. +
  40937. + return -1;
  40938. +}
  40939. +
  40940. +
  40941. +#ifdef DWC_UTFLIB
  40942. +/* From usbstring.c */
  40943. +
  40944. +int DWC_UTF8_TO_UTF16LE(uint8_t const *s, uint16_t *cp, unsigned len)
  40945. +{
  40946. + int count = 0;
  40947. + u8 c;
  40948. + u16 uchar;
  40949. +
  40950. + /* this insists on correct encodings, though not minimal ones.
  40951. + * BUT it currently rejects legit 4-byte UTF-8 code points,
  40952. + * which need surrogate pairs. (Unicode 3.1 can use them.)
  40953. + */
  40954. + while (len != 0 && (c = (u8) *s++) != 0) {
  40955. + if (unlikely(c & 0x80)) {
  40956. + // 2-byte sequence:
  40957. + // 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx
  40958. + if ((c & 0xe0) == 0xc0) {
  40959. + uchar = (c & 0x1f) << 6;
  40960. +
  40961. + c = (u8) *s++;
  40962. + if ((c & 0xc0) != 0xc0)
  40963. + goto fail;
  40964. + c &= 0x3f;
  40965. + uchar |= c;
  40966. +
  40967. + // 3-byte sequence (most CJKV characters):
  40968. + // zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx
  40969. + } else if ((c & 0xf0) == 0xe0) {
  40970. + uchar = (c & 0x0f) << 12;
  40971. +
  40972. + c = (u8) *s++;
  40973. + if ((c & 0xc0) != 0xc0)
  40974. + goto fail;
  40975. + c &= 0x3f;
  40976. + uchar |= c << 6;
  40977. +
  40978. + c = (u8) *s++;
  40979. + if ((c & 0xc0) != 0xc0)
  40980. + goto fail;
  40981. + c &= 0x3f;
  40982. + uchar |= c;
  40983. +
  40984. + /* no bogus surrogates */
  40985. + if (0xd800 <= uchar && uchar <= 0xdfff)
  40986. + goto fail;
  40987. +
  40988. + // 4-byte sequence (surrogate pairs, currently rare):
  40989. + // 11101110wwwwzzzzyy + 110111yyyyxxxxxx
  40990. + // = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx
  40991. + // (uuuuu = wwww + 1)
  40992. + // FIXME accept the surrogate code points (only)
  40993. + } else
  40994. + goto fail;
  40995. + } else
  40996. + uchar = c;
  40997. + put_unaligned (cpu_to_le16 (uchar), cp++);
  40998. + count++;
  40999. + len--;
  41000. + }
  41001. + return count;
  41002. +fail:
  41003. + return -1;
  41004. +}
  41005. +#endif /* DWC_UTFLIB */
  41006. +
  41007. +
  41008. +/* dwc_debug.h */
  41009. +
  41010. +dwc_bool_t DWC_IN_IRQ(void)
  41011. +{
  41012. + return in_irq();
  41013. +}
  41014. +
  41015. +dwc_bool_t DWC_IN_BH(void)
  41016. +{
  41017. + return in_softirq();
  41018. +}
  41019. +
  41020. +void DWC_VPRINTF(char *format, va_list args)
  41021. +{
  41022. + vprintk(format, args);
  41023. +}
  41024. +
  41025. +int DWC_VSNPRINTF(char *str, int size, char *format, va_list args)
  41026. +{
  41027. + return vsnprintf(str, size, format, args);
  41028. +}
  41029. +
  41030. +void DWC_PRINTF(char *format, ...)
  41031. +{
  41032. + va_list args;
  41033. +
  41034. + va_start(args, format);
  41035. + DWC_VPRINTF(format, args);
  41036. + va_end(args);
  41037. +}
  41038. +
  41039. +int DWC_SPRINTF(char *buffer, char *format, ...)
  41040. +{
  41041. + int retval;
  41042. + va_list args;
  41043. +
  41044. + va_start(args, format);
  41045. + retval = vsprintf(buffer, format, args);
  41046. + va_end(args);
  41047. + return retval;
  41048. +}
  41049. +
  41050. +int DWC_SNPRINTF(char *buffer, int size, char *format, ...)
  41051. +{
  41052. + int retval;
  41053. + va_list args;
  41054. +
  41055. + va_start(args, format);
  41056. + retval = vsnprintf(buffer, size, format, args);
  41057. + va_end(args);
  41058. + return retval;
  41059. +}
  41060. +
  41061. +void __DWC_WARN(char *format, ...)
  41062. +{
  41063. + va_list args;
  41064. +
  41065. + va_start(args, format);
  41066. + DWC_PRINTF(KERN_WARNING);
  41067. + DWC_VPRINTF(format, args);
  41068. + va_end(args);
  41069. +}
  41070. +
  41071. +void __DWC_ERROR(char *format, ...)
  41072. +{
  41073. + va_list args;
  41074. +
  41075. + va_start(args, format);
  41076. + DWC_PRINTF(KERN_ERR);
  41077. + DWC_VPRINTF(format, args);
  41078. + va_end(args);
  41079. +}
  41080. +
  41081. +void DWC_EXCEPTION(char *format, ...)
  41082. +{
  41083. + va_list args;
  41084. +
  41085. + va_start(args, format);
  41086. + DWC_PRINTF(KERN_ERR);
  41087. + DWC_VPRINTF(format, args);
  41088. + va_end(args);
  41089. + BUG_ON(1);
  41090. +}
  41091. +
  41092. +#ifdef DEBUG
  41093. +void __DWC_DEBUG(char *format, ...)
  41094. +{
  41095. + va_list args;
  41096. +
  41097. + va_start(args, format);
  41098. + DWC_PRINTF(KERN_DEBUG);
  41099. + DWC_VPRINTF(format, args);
  41100. + va_end(args);
  41101. +}
  41102. +#endif
  41103. +
  41104. +
  41105. +/* dwc_mem.h */
  41106. +
  41107. +#if 0
  41108. +dwc_pool_t *DWC_DMA_POOL_CREATE(uint32_t size,
  41109. + uint32_t align,
  41110. + uint32_t alloc)
  41111. +{
  41112. + struct dma_pool *pool = dma_pool_create("Pool", NULL,
  41113. + size, align, alloc);
  41114. + return (dwc_pool_t *)pool;
  41115. +}
  41116. +
  41117. +void DWC_DMA_POOL_DESTROY(dwc_pool_t *pool)
  41118. +{
  41119. + dma_pool_destroy((struct dma_pool *)pool);
  41120. +}
  41121. +
  41122. +void *DWC_DMA_POOL_ALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  41123. +{
  41124. + return dma_pool_alloc((struct dma_pool *)pool, GFP_KERNEL, dma_addr);
  41125. +}
  41126. +
  41127. +void *DWC_DMA_POOL_ZALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  41128. +{
  41129. + void *vaddr = DWC_DMA_POOL_ALLOC(pool, dma_addr);
  41130. + memset(..);
  41131. +}
  41132. +
  41133. +void DWC_DMA_POOL_FREE(dwc_pool_t *pool, void *vaddr, void *daddr)
  41134. +{
  41135. + dma_pool_free(pool, vaddr, daddr);
  41136. +}
  41137. +#endif
  41138. +
  41139. +void *__DWC_DMA_ALLOC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr)
  41140. +{
  41141. +#ifdef xxCOSIM /* Only works for 32-bit cosim */
  41142. + void *buf = dma_alloc_coherent(dma_ctx, (size_t)size, dma_addr, GFP_KERNEL);
  41143. +#else
  41144. + void *buf = dma_alloc_coherent(dma_ctx, (size_t)size, dma_addr, GFP_KERNEL | GFP_DMA32);
  41145. +#endif
  41146. + if (!buf) {
  41147. + return NULL;
  41148. + }
  41149. +
  41150. + memset(buf, 0, (size_t)size);
  41151. + return buf;
  41152. +}
  41153. +
  41154. +void *__DWC_DMA_ALLOC_ATOMIC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr)
  41155. +{
  41156. + void *buf = dma_alloc_coherent(NULL, (size_t)size, dma_addr, GFP_ATOMIC);
  41157. + if (!buf) {
  41158. + return NULL;
  41159. + }
  41160. + memset(buf, 0, (size_t)size);
  41161. + return buf;
  41162. +}
  41163. +
  41164. +void __DWC_DMA_FREE(void *dma_ctx, uint32_t size, void *virt_addr, dwc_dma_t dma_addr)
  41165. +{
  41166. + dma_free_coherent(dma_ctx, size, virt_addr, dma_addr);
  41167. +}
  41168. +
  41169. +void *__DWC_ALLOC(void *mem_ctx, uint32_t size)
  41170. +{
  41171. + return kzalloc(size, GFP_KERNEL);
  41172. +}
  41173. +
  41174. +void *__DWC_ALLOC_ATOMIC(void *mem_ctx, uint32_t size)
  41175. +{
  41176. + return kzalloc(size, GFP_ATOMIC);
  41177. +}
  41178. +
  41179. +void __DWC_FREE(void *mem_ctx, void *addr)
  41180. +{
  41181. + kfree(addr);
  41182. +}
  41183. +
  41184. +
  41185. +#ifdef DWC_CRYPTOLIB
  41186. +/* dwc_crypto.h */
  41187. +
  41188. +void DWC_RANDOM_BYTES(uint8_t *buffer, uint32_t length)
  41189. +{
  41190. + get_random_bytes(buffer, length);
  41191. +}
  41192. +
  41193. +int DWC_AES_CBC(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t iv[16], uint8_t *out)
  41194. +{
  41195. + struct crypto_blkcipher *tfm;
  41196. + struct blkcipher_desc desc;
  41197. + struct scatterlist sgd;
  41198. + struct scatterlist sgs;
  41199. +
  41200. + tfm = crypto_alloc_blkcipher("cbc(aes)", 0, CRYPTO_ALG_ASYNC);
  41201. + if (tfm == NULL) {
  41202. + printk("failed to load transform for aes CBC\n");
  41203. + return -1;
  41204. + }
  41205. +
  41206. + crypto_blkcipher_setkey(tfm, key, keylen);
  41207. + crypto_blkcipher_set_iv(tfm, iv, 16);
  41208. +
  41209. + sg_init_one(&sgd, out, messagelen);
  41210. + sg_init_one(&sgs, message, messagelen);
  41211. +
  41212. + desc.tfm = tfm;
  41213. + desc.flags = 0;
  41214. +
  41215. + if (crypto_blkcipher_encrypt(&desc, &sgd, &sgs, messagelen)) {
  41216. + crypto_free_blkcipher(tfm);
  41217. + DWC_ERROR("AES CBC encryption failed");
  41218. + return -1;
  41219. + }
  41220. +
  41221. + crypto_free_blkcipher(tfm);
  41222. + return 0;
  41223. +}
  41224. +
  41225. +int DWC_SHA256(uint8_t *message, uint32_t len, uint8_t *out)
  41226. +{
  41227. + struct crypto_hash *tfm;
  41228. + struct hash_desc desc;
  41229. + struct scatterlist sg;
  41230. +
  41231. + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
  41232. + if (IS_ERR(tfm)) {
  41233. + DWC_ERROR("Failed to load transform for sha256: %ld\n", PTR_ERR(tfm));
  41234. + return 0;
  41235. + }
  41236. + desc.tfm = tfm;
  41237. + desc.flags = 0;
  41238. +
  41239. + sg_init_one(&sg, message, len);
  41240. + crypto_hash_digest(&desc, &sg, len, out);
  41241. + crypto_free_hash(tfm);
  41242. +
  41243. + return 1;
  41244. +}
  41245. +
  41246. +int DWC_HMAC_SHA256(uint8_t *message, uint32_t messagelen,
  41247. + uint8_t *key, uint32_t keylen, uint8_t *out)
  41248. +{
  41249. + struct crypto_hash *tfm;
  41250. + struct hash_desc desc;
  41251. + struct scatterlist sg;
  41252. +
  41253. + tfm = crypto_alloc_hash("hmac(sha256)", 0, CRYPTO_ALG_ASYNC);
  41254. + if (IS_ERR(tfm)) {
  41255. + DWC_ERROR("Failed to load transform for hmac(sha256): %ld\n", PTR_ERR(tfm));
  41256. + return 0;
  41257. + }
  41258. + desc.tfm = tfm;
  41259. + desc.flags = 0;
  41260. +
  41261. + sg_init_one(&sg, message, messagelen);
  41262. + crypto_hash_setkey(tfm, key, keylen);
  41263. + crypto_hash_digest(&desc, &sg, messagelen, out);
  41264. + crypto_free_hash(tfm);
  41265. +
  41266. + return 1;
  41267. +}
  41268. +#endif /* DWC_CRYPTOLIB */
  41269. +
  41270. +
  41271. +/* Byte Ordering Conversions */
  41272. +
  41273. +uint32_t DWC_CPU_TO_LE32(uint32_t *p)
  41274. +{
  41275. +#ifdef __LITTLE_ENDIAN
  41276. + return *p;
  41277. +#else
  41278. + uint8_t *u_p = (uint8_t *)p;
  41279. +
  41280. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  41281. +#endif
  41282. +}
  41283. +
  41284. +uint32_t DWC_CPU_TO_BE32(uint32_t *p)
  41285. +{
  41286. +#ifdef __BIG_ENDIAN
  41287. + return *p;
  41288. +#else
  41289. + uint8_t *u_p = (uint8_t *)p;
  41290. +
  41291. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  41292. +#endif
  41293. +}
  41294. +
  41295. +uint32_t DWC_LE32_TO_CPU(uint32_t *p)
  41296. +{
  41297. +#ifdef __LITTLE_ENDIAN
  41298. + return *p;
  41299. +#else
  41300. + uint8_t *u_p = (uint8_t *)p;
  41301. +
  41302. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  41303. +#endif
  41304. +}
  41305. +
  41306. +uint32_t DWC_BE32_TO_CPU(uint32_t *p)
  41307. +{
  41308. +#ifdef __BIG_ENDIAN
  41309. + return *p;
  41310. +#else
  41311. + uint8_t *u_p = (uint8_t *)p;
  41312. +
  41313. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  41314. +#endif
  41315. +}
  41316. +
  41317. +uint16_t DWC_CPU_TO_LE16(uint16_t *p)
  41318. +{
  41319. +#ifdef __LITTLE_ENDIAN
  41320. + return *p;
  41321. +#else
  41322. + uint8_t *u_p = (uint8_t *)p;
  41323. + return (u_p[1] | (u_p[0] << 8));
  41324. +#endif
  41325. +}
  41326. +
  41327. +uint16_t DWC_CPU_TO_BE16(uint16_t *p)
  41328. +{
  41329. +#ifdef __BIG_ENDIAN
  41330. + return *p;
  41331. +#else
  41332. + uint8_t *u_p = (uint8_t *)p;
  41333. + return (u_p[1] | (u_p[0] << 8));
  41334. +#endif
  41335. +}
  41336. +
  41337. +uint16_t DWC_LE16_TO_CPU(uint16_t *p)
  41338. +{
  41339. +#ifdef __LITTLE_ENDIAN
  41340. + return *p;
  41341. +#else
  41342. + uint8_t *u_p = (uint8_t *)p;
  41343. + return (u_p[1] | (u_p[0] << 8));
  41344. +#endif
  41345. +}
  41346. +
  41347. +uint16_t DWC_BE16_TO_CPU(uint16_t *p)
  41348. +{
  41349. +#ifdef __BIG_ENDIAN
  41350. + return *p;
  41351. +#else
  41352. + uint8_t *u_p = (uint8_t *)p;
  41353. + return (u_p[1] | (u_p[0] << 8));
  41354. +#endif
  41355. +}
  41356. +
  41357. +
  41358. +/* Registers */
  41359. +
  41360. +uint32_t DWC_READ_REG32(uint32_t volatile *reg)
  41361. +{
  41362. + return readl(reg);
  41363. +}
  41364. +
  41365. +#if 0
  41366. +uint64_t DWC_READ_REG64(uint64_t volatile *reg)
  41367. +{
  41368. +}
  41369. +#endif
  41370. +
  41371. +void DWC_WRITE_REG32(uint32_t volatile *reg, uint32_t value)
  41372. +{
  41373. + writel(value, reg);
  41374. +}
  41375. +
  41376. +#if 0
  41377. +void DWC_WRITE_REG64(uint64_t volatile *reg, uint64_t value)
  41378. +{
  41379. +}
  41380. +#endif
  41381. +
  41382. +void DWC_MODIFY_REG32(uint32_t volatile *reg, uint32_t clear_mask, uint32_t set_mask)
  41383. +{
  41384. + unsigned long flags;
  41385. +
  41386. + local_irq_save(flags);
  41387. + local_fiq_disable();
  41388. + writel((readl(reg) & ~clear_mask) | set_mask, reg);
  41389. + local_fiq_enable();
  41390. + local_irq_restore(flags);
  41391. +}
  41392. +
  41393. +#if 0
  41394. +void DWC_MODIFY_REG64(uint64_t volatile *reg, uint64_t clear_mask, uint64_t set_mask)
  41395. +{
  41396. +}
  41397. +#endif
  41398. +
  41399. +
  41400. +/* Locking */
  41401. +
  41402. +dwc_spinlock_t *DWC_SPINLOCK_ALLOC(void)
  41403. +{
  41404. + spinlock_t *sl = (spinlock_t *)1;
  41405. +
  41406. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  41407. + sl = DWC_ALLOC(sizeof(*sl));
  41408. + if (!sl) {
  41409. + DWC_ERROR("Cannot allocate memory for spinlock\n");
  41410. + return NULL;
  41411. + }
  41412. +
  41413. + spin_lock_init(sl);
  41414. +#endif
  41415. + return (dwc_spinlock_t *)sl;
  41416. +}
  41417. +
  41418. +void DWC_SPINLOCK_FREE(dwc_spinlock_t *lock)
  41419. +{
  41420. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  41421. + DWC_FREE(lock);
  41422. +#endif
  41423. +}
  41424. +
  41425. +void DWC_SPINLOCK(dwc_spinlock_t *lock)
  41426. +{
  41427. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  41428. + spin_lock((spinlock_t *)lock);
  41429. +#endif
  41430. +}
  41431. +
  41432. +void DWC_SPINUNLOCK(dwc_spinlock_t *lock)
  41433. +{
  41434. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  41435. + spin_unlock((spinlock_t *)lock);
  41436. +#endif
  41437. +}
  41438. +
  41439. +void DWC_SPINLOCK_IRQSAVE(dwc_spinlock_t *lock, dwc_irqflags_t *flags)
  41440. +{
  41441. + dwc_irqflags_t f;
  41442. +
  41443. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  41444. + spin_lock_irqsave((spinlock_t *)lock, f);
  41445. +#else
  41446. + local_irq_save(f);
  41447. +#endif
  41448. + *flags = f;
  41449. +}
  41450. +
  41451. +void DWC_SPINUNLOCK_IRQRESTORE(dwc_spinlock_t *lock, dwc_irqflags_t flags)
  41452. +{
  41453. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  41454. + spin_unlock_irqrestore((spinlock_t *)lock, flags);
  41455. +#else
  41456. + local_irq_restore(flags);
  41457. +#endif
  41458. +}
  41459. +
  41460. +dwc_mutex_t *DWC_MUTEX_ALLOC(void)
  41461. +{
  41462. + struct mutex *m;
  41463. + dwc_mutex_t *mutex = (dwc_mutex_t *)DWC_ALLOC(sizeof(struct mutex));
  41464. +
  41465. + if (!mutex) {
  41466. + DWC_ERROR("Cannot allocate memory for mutex\n");
  41467. + return NULL;
  41468. + }
  41469. +
  41470. + m = (struct mutex *)mutex;
  41471. + mutex_init(m);
  41472. + return mutex;
  41473. +}
  41474. +
  41475. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  41476. +#else
  41477. +void DWC_MUTEX_FREE(dwc_mutex_t *mutex)
  41478. +{
  41479. + mutex_destroy((struct mutex *)mutex);
  41480. + DWC_FREE(mutex);
  41481. +}
  41482. +#endif
  41483. +
  41484. +void DWC_MUTEX_LOCK(dwc_mutex_t *mutex)
  41485. +{
  41486. + struct mutex *m = (struct mutex *)mutex;
  41487. + mutex_lock(m);
  41488. +}
  41489. +
  41490. +int DWC_MUTEX_TRYLOCK(dwc_mutex_t *mutex)
  41491. +{
  41492. + struct mutex *m = (struct mutex *)mutex;
  41493. + return mutex_trylock(m);
  41494. +}
  41495. +
  41496. +void DWC_MUTEX_UNLOCK(dwc_mutex_t *mutex)
  41497. +{
  41498. + struct mutex *m = (struct mutex *)mutex;
  41499. + mutex_unlock(m);
  41500. +}
  41501. +
  41502. +
  41503. +/* Timing */
  41504. +
  41505. +void DWC_UDELAY(uint32_t usecs)
  41506. +{
  41507. + udelay(usecs);
  41508. +}
  41509. +
  41510. +void DWC_MDELAY(uint32_t msecs)
  41511. +{
  41512. + mdelay(msecs);
  41513. +}
  41514. +
  41515. +void DWC_MSLEEP(uint32_t msecs)
  41516. +{
  41517. + msleep(msecs);
  41518. +}
  41519. +
  41520. +uint32_t DWC_TIME(void)
  41521. +{
  41522. + return jiffies_to_msecs(jiffies);
  41523. +}
  41524. +
  41525. +
  41526. +/* Timers */
  41527. +
  41528. +struct dwc_timer {
  41529. + struct timer_list *t;
  41530. + char *name;
  41531. + dwc_timer_callback_t cb;
  41532. + void *data;
  41533. + uint8_t scheduled;
  41534. + dwc_spinlock_t *lock;
  41535. +};
  41536. +
  41537. +static void timer_callback(unsigned long data)
  41538. +{
  41539. + dwc_timer_t *timer = (dwc_timer_t *)data;
  41540. + dwc_irqflags_t flags;
  41541. +
  41542. + DWC_SPINLOCK_IRQSAVE(timer->lock, &flags);
  41543. + timer->scheduled = 0;
  41544. + DWC_SPINUNLOCK_IRQRESTORE(timer->lock, flags);
  41545. + DWC_DEBUGC("Timer %s callback", timer->name);
  41546. + timer->cb(timer->data);
  41547. +}
  41548. +
  41549. +dwc_timer_t *DWC_TIMER_ALLOC(char *name, dwc_timer_callback_t cb, void *data)
  41550. +{
  41551. + dwc_timer_t *t = DWC_ALLOC(sizeof(*t));
  41552. +
  41553. + if (!t) {
  41554. + DWC_ERROR("Cannot allocate memory for timer");
  41555. + return NULL;
  41556. + }
  41557. +
  41558. + t->t = DWC_ALLOC(sizeof(*t->t));
  41559. + if (!t->t) {
  41560. + DWC_ERROR("Cannot allocate memory for timer->t");
  41561. + goto no_timer;
  41562. + }
  41563. +
  41564. + t->name = DWC_STRDUP(name);
  41565. + if (!t->name) {
  41566. + DWC_ERROR("Cannot allocate memory for timer->name");
  41567. + goto no_name;
  41568. + }
  41569. +
  41570. + t->lock = DWC_SPINLOCK_ALLOC();
  41571. + if (!t->lock) {
  41572. + DWC_ERROR("Cannot allocate memory for lock");
  41573. + goto no_lock;
  41574. + }
  41575. +
  41576. + t->scheduled = 0;
  41577. + t->t->base = &boot_tvec_bases;
  41578. + t->t->expires = jiffies;
  41579. + setup_timer(t->t, timer_callback, (unsigned long)t);
  41580. +
  41581. + t->cb = cb;
  41582. + t->data = data;
  41583. +
  41584. + return t;
  41585. +
  41586. + no_lock:
  41587. + DWC_FREE(t->name);
  41588. + no_name:
  41589. + DWC_FREE(t->t);
  41590. + no_timer:
  41591. + DWC_FREE(t);
  41592. + return NULL;
  41593. +}
  41594. +
  41595. +void DWC_TIMER_FREE(dwc_timer_t *timer)
  41596. +{
  41597. + dwc_irqflags_t flags;
  41598. +
  41599. + DWC_SPINLOCK_IRQSAVE(timer->lock, &flags);
  41600. +
  41601. + if (timer->scheduled) {
  41602. + del_timer(timer->t);
  41603. + timer->scheduled = 0;
  41604. + }
  41605. +
  41606. + DWC_SPINUNLOCK_IRQRESTORE(timer->lock, flags);
  41607. + DWC_SPINLOCK_FREE(timer->lock);
  41608. + DWC_FREE(timer->t);
  41609. + DWC_FREE(timer->name);
  41610. + DWC_FREE(timer);
  41611. +}
  41612. +
  41613. +void DWC_TIMER_SCHEDULE(dwc_timer_t *timer, uint32_t time)
  41614. +{
  41615. + dwc_irqflags_t flags;
  41616. +
  41617. + DWC_SPINLOCK_IRQSAVE(timer->lock, &flags);
  41618. +
  41619. + if (!timer->scheduled) {
  41620. + timer->scheduled = 1;
  41621. + DWC_DEBUGC("Scheduling timer %s to expire in +%d msec", timer->name, time);
  41622. + timer->t->expires = jiffies + msecs_to_jiffies(time);
  41623. + add_timer(timer->t);
  41624. + } else {
  41625. + DWC_DEBUGC("Modifying timer %s to expire in +%d msec", timer->name, time);
  41626. + mod_timer(timer->t, jiffies + msecs_to_jiffies(time));
  41627. + }
  41628. +
  41629. + DWC_SPINUNLOCK_IRQRESTORE(timer->lock, flags);
  41630. +}
  41631. +
  41632. +void DWC_TIMER_CANCEL(dwc_timer_t *timer)
  41633. +{
  41634. + del_timer(timer->t);
  41635. +}
  41636. +
  41637. +
  41638. +/* Wait Queues */
  41639. +
  41640. +struct dwc_waitq {
  41641. + wait_queue_head_t queue;
  41642. + int abort;
  41643. +};
  41644. +
  41645. +dwc_waitq_t *DWC_WAITQ_ALLOC(void)
  41646. +{
  41647. + dwc_waitq_t *wq = DWC_ALLOC(sizeof(*wq));
  41648. +
  41649. + if (!wq) {
  41650. + DWC_ERROR("Cannot allocate memory for waitqueue\n");
  41651. + return NULL;
  41652. + }
  41653. +
  41654. + init_waitqueue_head(&wq->queue);
  41655. + wq->abort = 0;
  41656. + return wq;
  41657. +}
  41658. +
  41659. +void DWC_WAITQ_FREE(dwc_waitq_t *wq)
  41660. +{
  41661. + DWC_FREE(wq);
  41662. +}
  41663. +
  41664. +int32_t DWC_WAITQ_WAIT(dwc_waitq_t *wq, dwc_waitq_condition_t cond, void *data)
  41665. +{
  41666. + int result = wait_event_interruptible(wq->queue,
  41667. + cond(data) || wq->abort);
  41668. + if (result == -ERESTARTSYS) {
  41669. + wq->abort = 0;
  41670. + return -DWC_E_RESTART;
  41671. + }
  41672. +
  41673. + if (wq->abort == 1) {
  41674. + wq->abort = 0;
  41675. + return -DWC_E_ABORT;
  41676. + }
  41677. +
  41678. + wq->abort = 0;
  41679. +
  41680. + if (result == 0) {
  41681. + return 0;
  41682. + }
  41683. +
  41684. + return -DWC_E_UNKNOWN;
  41685. +}
  41686. +
  41687. +int32_t DWC_WAITQ_WAIT_TIMEOUT(dwc_waitq_t *wq, dwc_waitq_condition_t cond,
  41688. + void *data, int32_t msecs)
  41689. +{
  41690. + int32_t tmsecs;
  41691. + int result = wait_event_interruptible_timeout(wq->queue,
  41692. + cond(data) || wq->abort,
  41693. + msecs_to_jiffies(msecs));
  41694. + if (result == -ERESTARTSYS) {
  41695. + wq->abort = 0;
  41696. + return -DWC_E_RESTART;
  41697. + }
  41698. +
  41699. + if (wq->abort == 1) {
  41700. + wq->abort = 0;
  41701. + return -DWC_E_ABORT;
  41702. + }
  41703. +
  41704. + wq->abort = 0;
  41705. +
  41706. + if (result > 0) {
  41707. + tmsecs = jiffies_to_msecs(result);
  41708. + if (!tmsecs) {
  41709. + return 1;
  41710. + }
  41711. +
  41712. + return tmsecs;
  41713. + }
  41714. +
  41715. + if (result == 0) {
  41716. + return -DWC_E_TIMEOUT;
  41717. + }
  41718. +
  41719. + return -DWC_E_UNKNOWN;
  41720. +}
  41721. +
  41722. +void DWC_WAITQ_TRIGGER(dwc_waitq_t *wq)
  41723. +{
  41724. + wq->abort = 0;
  41725. + wake_up_interruptible(&wq->queue);
  41726. +}
  41727. +
  41728. +void DWC_WAITQ_ABORT(dwc_waitq_t *wq)
  41729. +{
  41730. + wq->abort = 1;
  41731. + wake_up_interruptible(&wq->queue);
  41732. +}
  41733. +
  41734. +
  41735. +/* Threading */
  41736. +
  41737. +dwc_thread_t *DWC_THREAD_RUN(dwc_thread_function_t func, char *name, void *data)
  41738. +{
  41739. + struct task_struct *thread = kthread_run(func, data, name);
  41740. +
  41741. + if (thread == ERR_PTR(-ENOMEM)) {
  41742. + return NULL;
  41743. + }
  41744. +
  41745. + return (dwc_thread_t *)thread;
  41746. +}
  41747. +
  41748. +int DWC_THREAD_STOP(dwc_thread_t *thread)
  41749. +{
  41750. + return kthread_stop((struct task_struct *)thread);
  41751. +}
  41752. +
  41753. +dwc_bool_t DWC_THREAD_SHOULD_STOP(void)
  41754. +{
  41755. + return kthread_should_stop();
  41756. +}
  41757. +
  41758. +
  41759. +/* tasklets
  41760. + - run in interrupt context (cannot sleep)
  41761. + - each tasklet runs on a single CPU
  41762. + - different tasklets can be running simultaneously on different CPUs
  41763. + */
  41764. +struct dwc_tasklet {
  41765. + struct tasklet_struct t;
  41766. + dwc_tasklet_callback_t cb;
  41767. + void *data;
  41768. +};
  41769. +
  41770. +static void tasklet_callback(unsigned long data)
  41771. +{
  41772. + dwc_tasklet_t *t = (dwc_tasklet_t *)data;
  41773. + t->cb(t->data);
  41774. +}
  41775. +
  41776. +dwc_tasklet_t *DWC_TASK_ALLOC(char *name, dwc_tasklet_callback_t cb, void *data)
  41777. +{
  41778. + dwc_tasklet_t *t = DWC_ALLOC(sizeof(*t));
  41779. +
  41780. + if (t) {
  41781. + t->cb = cb;
  41782. + t->data = data;
  41783. + tasklet_init(&t->t, tasklet_callback, (unsigned long)t);
  41784. + } else {
  41785. + DWC_ERROR("Cannot allocate memory for tasklet\n");
  41786. + }
  41787. +
  41788. + return t;
  41789. +}
  41790. +
  41791. +void DWC_TASK_FREE(dwc_tasklet_t *task)
  41792. +{
  41793. + DWC_FREE(task);
  41794. +}
  41795. +
  41796. +void DWC_TASK_SCHEDULE(dwc_tasklet_t *task)
  41797. +{
  41798. + tasklet_schedule(&task->t);
  41799. +}
  41800. +
  41801. +void DWC_TASK_HI_SCHEDULE(dwc_tasklet_t *task)
  41802. +{
  41803. + tasklet_hi_schedule(&task->t);
  41804. +}
  41805. +
  41806. +
  41807. +/* workqueues
  41808. + - run in process context (can sleep)
  41809. + */
  41810. +typedef struct work_container {
  41811. + dwc_work_callback_t cb;
  41812. + void *data;
  41813. + dwc_workq_t *wq;
  41814. + char *name;
  41815. +
  41816. +#ifdef DEBUG
  41817. + DWC_CIRCLEQ_ENTRY(work_container) entry;
  41818. +#endif
  41819. + struct delayed_work work;
  41820. +} work_container_t;
  41821. +
  41822. +#ifdef DEBUG
  41823. +DWC_CIRCLEQ_HEAD(work_container_queue, work_container);
  41824. +#endif
  41825. +
  41826. +struct dwc_workq {
  41827. + struct workqueue_struct *wq;
  41828. + dwc_spinlock_t *lock;
  41829. + dwc_waitq_t *waitq;
  41830. + int pending;
  41831. +
  41832. +#ifdef DEBUG
  41833. + struct work_container_queue entries;
  41834. +#endif
  41835. +};
  41836. +
  41837. +static void do_work(struct work_struct *work)
  41838. +{
  41839. + dwc_irqflags_t flags;
  41840. + struct delayed_work *dw = container_of(work, struct delayed_work, work);
  41841. + work_container_t *container = container_of(dw, struct work_container, work);
  41842. + dwc_workq_t *wq = container->wq;
  41843. +
  41844. + container->cb(container->data);
  41845. +
  41846. +#ifdef DEBUG
  41847. + DWC_CIRCLEQ_REMOVE(&wq->entries, container, entry);
  41848. +#endif
  41849. + DWC_DEBUGC("Work done: %s, container=%p", container->name, container);
  41850. + if (container->name) {
  41851. + DWC_FREE(container->name);
  41852. + }
  41853. + DWC_FREE(container);
  41854. +
  41855. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  41856. + wq->pending--;
  41857. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  41858. + DWC_WAITQ_TRIGGER(wq->waitq);
  41859. +}
  41860. +
  41861. +static int work_done(void *data)
  41862. +{
  41863. + dwc_workq_t *workq = (dwc_workq_t *)data;
  41864. + return workq->pending == 0;
  41865. +}
  41866. +
  41867. +int DWC_WORKQ_WAIT_WORK_DONE(dwc_workq_t *workq, int timeout)
  41868. +{
  41869. + return DWC_WAITQ_WAIT_TIMEOUT(workq->waitq, work_done, workq, timeout);
  41870. +}
  41871. +
  41872. +dwc_workq_t *DWC_WORKQ_ALLOC(char *name)
  41873. +{
  41874. + dwc_workq_t *wq = DWC_ALLOC(sizeof(*wq));
  41875. +
  41876. + if (!wq) {
  41877. + return NULL;
  41878. + }
  41879. +
  41880. + wq->wq = create_singlethread_workqueue(name);
  41881. + if (!wq->wq) {
  41882. + goto no_wq;
  41883. + }
  41884. +
  41885. + wq->pending = 0;
  41886. +
  41887. + wq->lock = DWC_SPINLOCK_ALLOC();
  41888. + if (!wq->lock) {
  41889. + goto no_lock;
  41890. + }
  41891. +
  41892. + wq->waitq = DWC_WAITQ_ALLOC();
  41893. + if (!wq->waitq) {
  41894. + goto no_waitq;
  41895. + }
  41896. +
  41897. +#ifdef DEBUG
  41898. + DWC_CIRCLEQ_INIT(&wq->entries);
  41899. +#endif
  41900. + return wq;
  41901. +
  41902. + no_waitq:
  41903. + DWC_SPINLOCK_FREE(wq->lock);
  41904. + no_lock:
  41905. + destroy_workqueue(wq->wq);
  41906. + no_wq:
  41907. + DWC_FREE(wq);
  41908. +
  41909. + return NULL;
  41910. +}
  41911. +
  41912. +void DWC_WORKQ_FREE(dwc_workq_t *wq)
  41913. +{
  41914. +#ifdef DEBUG
  41915. + if (wq->pending != 0) {
  41916. + struct work_container *wc;
  41917. + DWC_ERROR("Destroying work queue with pending work");
  41918. + DWC_CIRCLEQ_FOREACH(wc, &wq->entries, entry) {
  41919. + DWC_ERROR("Work %s still pending", wc->name);
  41920. + }
  41921. + }
  41922. +#endif
  41923. + destroy_workqueue(wq->wq);
  41924. + DWC_SPINLOCK_FREE(wq->lock);
  41925. + DWC_WAITQ_FREE(wq->waitq);
  41926. + DWC_FREE(wq);
  41927. +}
  41928. +
  41929. +void DWC_WORKQ_SCHEDULE(dwc_workq_t *wq, dwc_work_callback_t cb, void *data,
  41930. + char *format, ...)
  41931. +{
  41932. + dwc_irqflags_t flags;
  41933. + work_container_t *container;
  41934. + static char name[128];
  41935. + va_list args;
  41936. +
  41937. + va_start(args, format);
  41938. + DWC_VSNPRINTF(name, 128, format, args);
  41939. + va_end(args);
  41940. +
  41941. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  41942. + wq->pending++;
  41943. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  41944. + DWC_WAITQ_TRIGGER(wq->waitq);
  41945. +
  41946. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  41947. + if (!container) {
  41948. + DWC_ERROR("Cannot allocate memory for container\n");
  41949. + return;
  41950. + }
  41951. +
  41952. + container->name = DWC_STRDUP(name);
  41953. + if (!container->name) {
  41954. + DWC_ERROR("Cannot allocate memory for container->name\n");
  41955. + DWC_FREE(container);
  41956. + return;
  41957. + }
  41958. +
  41959. + container->cb = cb;
  41960. + container->data = data;
  41961. + container->wq = wq;
  41962. + DWC_DEBUGC("Queueing work: %s, container=%p", container->name, container);
  41963. + INIT_WORK(&container->work.work, do_work);
  41964. +
  41965. +#ifdef DEBUG
  41966. + DWC_CIRCLEQ_INSERT_TAIL(&wq->entries, container, entry);
  41967. +#endif
  41968. + queue_work(wq->wq, &container->work.work);
  41969. +}
  41970. +
  41971. +void DWC_WORKQ_SCHEDULE_DELAYED(dwc_workq_t *wq, dwc_work_callback_t cb,
  41972. + void *data, uint32_t time, char *format, ...)
  41973. +{
  41974. + dwc_irqflags_t flags;
  41975. + work_container_t *container;
  41976. + static char name[128];
  41977. + va_list args;
  41978. +
  41979. + va_start(args, format);
  41980. + DWC_VSNPRINTF(name, 128, format, args);
  41981. + va_end(args);
  41982. +
  41983. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  41984. + wq->pending++;
  41985. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  41986. + DWC_WAITQ_TRIGGER(wq->waitq);
  41987. +
  41988. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  41989. + if (!container) {
  41990. + DWC_ERROR("Cannot allocate memory for container\n");
  41991. + return;
  41992. + }
  41993. +
  41994. + container->name = DWC_STRDUP(name);
  41995. + if (!container->name) {
  41996. + DWC_ERROR("Cannot allocate memory for container->name\n");
  41997. + DWC_FREE(container);
  41998. + return;
  41999. + }
  42000. +
  42001. + container->cb = cb;
  42002. + container->data = data;
  42003. + container->wq = wq;
  42004. + DWC_DEBUGC("Queueing work: %s, container=%p", container->name, container);
  42005. + INIT_DELAYED_WORK(&container->work, do_work);
  42006. +
  42007. +#ifdef DEBUG
  42008. + DWC_CIRCLEQ_INSERT_TAIL(&wq->entries, container, entry);
  42009. +#endif
  42010. + queue_delayed_work(wq->wq, &container->work, msecs_to_jiffies(time));
  42011. +}
  42012. +
  42013. +int DWC_WORKQ_PENDING(dwc_workq_t *wq)
  42014. +{
  42015. + return wq->pending;
  42016. +}
  42017. +
  42018. +
  42019. +#ifdef DWC_LIBMODULE
  42020. +
  42021. +#ifdef DWC_CCLIB
  42022. +/* CC */
  42023. +EXPORT_SYMBOL(dwc_cc_if_alloc);
  42024. +EXPORT_SYMBOL(dwc_cc_if_free);
  42025. +EXPORT_SYMBOL(dwc_cc_clear);
  42026. +EXPORT_SYMBOL(dwc_cc_add);
  42027. +EXPORT_SYMBOL(dwc_cc_remove);
  42028. +EXPORT_SYMBOL(dwc_cc_change);
  42029. +EXPORT_SYMBOL(dwc_cc_data_for_save);
  42030. +EXPORT_SYMBOL(dwc_cc_restore_from_data);
  42031. +EXPORT_SYMBOL(dwc_cc_match_chid);
  42032. +EXPORT_SYMBOL(dwc_cc_match_cdid);
  42033. +EXPORT_SYMBOL(dwc_cc_ck);
  42034. +EXPORT_SYMBOL(dwc_cc_chid);
  42035. +EXPORT_SYMBOL(dwc_cc_cdid);
  42036. +EXPORT_SYMBOL(dwc_cc_name);
  42037. +#endif /* DWC_CCLIB */
  42038. +
  42039. +#ifdef DWC_CRYPTOLIB
  42040. +# ifndef CONFIG_MACH_IPMATE
  42041. +/* Modpow */
  42042. +EXPORT_SYMBOL(dwc_modpow);
  42043. +
  42044. +/* DH */
  42045. +EXPORT_SYMBOL(dwc_dh_modpow);
  42046. +EXPORT_SYMBOL(dwc_dh_derive_keys);
  42047. +EXPORT_SYMBOL(dwc_dh_pk);
  42048. +# endif /* CONFIG_MACH_IPMATE */
  42049. +
  42050. +/* Crypto */
  42051. +EXPORT_SYMBOL(dwc_wusb_aes_encrypt);
  42052. +EXPORT_SYMBOL(dwc_wusb_cmf);
  42053. +EXPORT_SYMBOL(dwc_wusb_prf);
  42054. +EXPORT_SYMBOL(dwc_wusb_fill_ccm_nonce);
  42055. +EXPORT_SYMBOL(dwc_wusb_gen_nonce);
  42056. +EXPORT_SYMBOL(dwc_wusb_gen_key);
  42057. +EXPORT_SYMBOL(dwc_wusb_gen_mic);
  42058. +#endif /* DWC_CRYPTOLIB */
  42059. +
  42060. +/* Notification */
  42061. +#ifdef DWC_NOTIFYLIB
  42062. +EXPORT_SYMBOL(dwc_alloc_notification_manager);
  42063. +EXPORT_SYMBOL(dwc_free_notification_manager);
  42064. +EXPORT_SYMBOL(dwc_register_notifier);
  42065. +EXPORT_SYMBOL(dwc_unregister_notifier);
  42066. +EXPORT_SYMBOL(dwc_add_observer);
  42067. +EXPORT_SYMBOL(dwc_remove_observer);
  42068. +EXPORT_SYMBOL(dwc_notify);
  42069. +#endif
  42070. +
  42071. +/* Memory Debugging Routines */
  42072. +#ifdef DWC_DEBUG_MEMORY
  42073. +EXPORT_SYMBOL(dwc_alloc_debug);
  42074. +EXPORT_SYMBOL(dwc_alloc_atomic_debug);
  42075. +EXPORT_SYMBOL(dwc_free_debug);
  42076. +EXPORT_SYMBOL(dwc_dma_alloc_debug);
  42077. +EXPORT_SYMBOL(dwc_dma_free_debug);
  42078. +#endif
  42079. +
  42080. +EXPORT_SYMBOL(DWC_MEMSET);
  42081. +EXPORT_SYMBOL(DWC_MEMCPY);
  42082. +EXPORT_SYMBOL(DWC_MEMMOVE);
  42083. +EXPORT_SYMBOL(DWC_MEMCMP);
  42084. +EXPORT_SYMBOL(DWC_STRNCMP);
  42085. +EXPORT_SYMBOL(DWC_STRCMP);
  42086. +EXPORT_SYMBOL(DWC_STRLEN);
  42087. +EXPORT_SYMBOL(DWC_STRCPY);
  42088. +EXPORT_SYMBOL(DWC_STRDUP);
  42089. +EXPORT_SYMBOL(DWC_ATOI);
  42090. +EXPORT_SYMBOL(DWC_ATOUI);
  42091. +
  42092. +#ifdef DWC_UTFLIB
  42093. +EXPORT_SYMBOL(DWC_UTF8_TO_UTF16LE);
  42094. +#endif /* DWC_UTFLIB */
  42095. +
  42096. +EXPORT_SYMBOL(DWC_IN_IRQ);
  42097. +EXPORT_SYMBOL(DWC_IN_BH);
  42098. +EXPORT_SYMBOL(DWC_VPRINTF);
  42099. +EXPORT_SYMBOL(DWC_VSNPRINTF);
  42100. +EXPORT_SYMBOL(DWC_PRINTF);
  42101. +EXPORT_SYMBOL(DWC_SPRINTF);
  42102. +EXPORT_SYMBOL(DWC_SNPRINTF);
  42103. +EXPORT_SYMBOL(__DWC_WARN);
  42104. +EXPORT_SYMBOL(__DWC_ERROR);
  42105. +EXPORT_SYMBOL(DWC_EXCEPTION);
  42106. +
  42107. +#ifdef DEBUG
  42108. +EXPORT_SYMBOL(__DWC_DEBUG);
  42109. +#endif
  42110. +
  42111. +EXPORT_SYMBOL(__DWC_DMA_ALLOC);
  42112. +EXPORT_SYMBOL(__DWC_DMA_ALLOC_ATOMIC);
  42113. +EXPORT_SYMBOL(__DWC_DMA_FREE);
  42114. +EXPORT_SYMBOL(__DWC_ALLOC);
  42115. +EXPORT_SYMBOL(__DWC_ALLOC_ATOMIC);
  42116. +EXPORT_SYMBOL(__DWC_FREE);
  42117. +
  42118. +#ifdef DWC_CRYPTOLIB
  42119. +EXPORT_SYMBOL(DWC_RANDOM_BYTES);
  42120. +EXPORT_SYMBOL(DWC_AES_CBC);
  42121. +EXPORT_SYMBOL(DWC_SHA256);
  42122. +EXPORT_SYMBOL(DWC_HMAC_SHA256);
  42123. +#endif
  42124. +
  42125. +EXPORT_SYMBOL(DWC_CPU_TO_LE32);
  42126. +EXPORT_SYMBOL(DWC_CPU_TO_BE32);
  42127. +EXPORT_SYMBOL(DWC_LE32_TO_CPU);
  42128. +EXPORT_SYMBOL(DWC_BE32_TO_CPU);
  42129. +EXPORT_SYMBOL(DWC_CPU_TO_LE16);
  42130. +EXPORT_SYMBOL(DWC_CPU_TO_BE16);
  42131. +EXPORT_SYMBOL(DWC_LE16_TO_CPU);
  42132. +EXPORT_SYMBOL(DWC_BE16_TO_CPU);
  42133. +EXPORT_SYMBOL(DWC_READ_REG32);
  42134. +EXPORT_SYMBOL(DWC_WRITE_REG32);
  42135. +EXPORT_SYMBOL(DWC_MODIFY_REG32);
  42136. +
  42137. +#if 0
  42138. +EXPORT_SYMBOL(DWC_READ_REG64);
  42139. +EXPORT_SYMBOL(DWC_WRITE_REG64);
  42140. +EXPORT_SYMBOL(DWC_MODIFY_REG64);
  42141. +#endif
  42142. +
  42143. +EXPORT_SYMBOL(DWC_SPINLOCK_ALLOC);
  42144. +EXPORT_SYMBOL(DWC_SPINLOCK_FREE);
  42145. +EXPORT_SYMBOL(DWC_SPINLOCK);
  42146. +EXPORT_SYMBOL(DWC_SPINUNLOCK);
  42147. +EXPORT_SYMBOL(DWC_SPINLOCK_IRQSAVE);
  42148. +EXPORT_SYMBOL(DWC_SPINUNLOCK_IRQRESTORE);
  42149. +EXPORT_SYMBOL(DWC_MUTEX_ALLOC);
  42150. +
  42151. +#if (!defined(DWC_LINUX) || !defined(CONFIG_DEBUG_MUTEXES))
  42152. +EXPORT_SYMBOL(DWC_MUTEX_FREE);
  42153. +#endif
  42154. +
  42155. +EXPORT_SYMBOL(DWC_MUTEX_LOCK);
  42156. +EXPORT_SYMBOL(DWC_MUTEX_TRYLOCK);
  42157. +EXPORT_SYMBOL(DWC_MUTEX_UNLOCK);
  42158. +EXPORT_SYMBOL(DWC_UDELAY);
  42159. +EXPORT_SYMBOL(DWC_MDELAY);
  42160. +EXPORT_SYMBOL(DWC_MSLEEP);
  42161. +EXPORT_SYMBOL(DWC_TIME);
  42162. +EXPORT_SYMBOL(DWC_TIMER_ALLOC);
  42163. +EXPORT_SYMBOL(DWC_TIMER_FREE);
  42164. +EXPORT_SYMBOL(DWC_TIMER_SCHEDULE);
  42165. +EXPORT_SYMBOL(DWC_TIMER_CANCEL);
  42166. +EXPORT_SYMBOL(DWC_WAITQ_ALLOC);
  42167. +EXPORT_SYMBOL(DWC_WAITQ_FREE);
  42168. +EXPORT_SYMBOL(DWC_WAITQ_WAIT);
  42169. +EXPORT_SYMBOL(DWC_WAITQ_WAIT_TIMEOUT);
  42170. +EXPORT_SYMBOL(DWC_WAITQ_TRIGGER);
  42171. +EXPORT_SYMBOL(DWC_WAITQ_ABORT);
  42172. +EXPORT_SYMBOL(DWC_THREAD_RUN);
  42173. +EXPORT_SYMBOL(DWC_THREAD_STOP);
  42174. +EXPORT_SYMBOL(DWC_THREAD_SHOULD_STOP);
  42175. +EXPORT_SYMBOL(DWC_TASK_ALLOC);
  42176. +EXPORT_SYMBOL(DWC_TASK_FREE);
  42177. +EXPORT_SYMBOL(DWC_TASK_SCHEDULE);
  42178. +EXPORT_SYMBOL(DWC_WORKQ_WAIT_WORK_DONE);
  42179. +EXPORT_SYMBOL(DWC_WORKQ_ALLOC);
  42180. +EXPORT_SYMBOL(DWC_WORKQ_FREE);
  42181. +EXPORT_SYMBOL(DWC_WORKQ_SCHEDULE);
  42182. +EXPORT_SYMBOL(DWC_WORKQ_SCHEDULE_DELAYED);
  42183. +EXPORT_SYMBOL(DWC_WORKQ_PENDING);
  42184. +
  42185. +static int dwc_common_port_init_module(void)
  42186. +{
  42187. + int result = 0;
  42188. +
  42189. + printk(KERN_DEBUG "Module dwc_common_port init\n" );
  42190. +
  42191. +#ifdef DWC_DEBUG_MEMORY
  42192. + result = dwc_memory_debug_start(NULL);
  42193. + if (result) {
  42194. + printk(KERN_ERR
  42195. + "dwc_memory_debug_start() failed with error %d\n",
  42196. + result);
  42197. + return result;
  42198. + }
  42199. +#endif
  42200. +
  42201. +#ifdef DWC_NOTIFYLIB
  42202. + result = dwc_alloc_notification_manager(NULL, NULL);
  42203. + if (result) {
  42204. + printk(KERN_ERR
  42205. + "dwc_alloc_notification_manager() failed with error %d\n",
  42206. + result);
  42207. + return result;
  42208. + }
  42209. +#endif
  42210. + return result;
  42211. +}
  42212. +
  42213. +static void dwc_common_port_exit_module(void)
  42214. +{
  42215. + printk(KERN_DEBUG "Module dwc_common_port exit\n" );
  42216. +
  42217. +#ifdef DWC_NOTIFYLIB
  42218. + dwc_free_notification_manager();
  42219. +#endif
  42220. +
  42221. +#ifdef DWC_DEBUG_MEMORY
  42222. + dwc_memory_debug_stop();
  42223. +#endif
  42224. +}
  42225. +
  42226. +module_init(dwc_common_port_init_module);
  42227. +module_exit(dwc_common_port_exit_module);
  42228. +
  42229. +MODULE_DESCRIPTION("DWC Common Library - Portable version");
  42230. +MODULE_AUTHOR("Synopsys Inc.");
  42231. +MODULE_LICENSE ("GPL");
  42232. +
  42233. +#endif /* DWC_LIBMODULE */
  42234. diff -Nur linux-3.13.11/drivers/usb/host/dwc_common_port/dwc_common_nbsd.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_common_nbsd.c
  42235. --- linux-3.13.11/drivers/usb/host/dwc_common_port/dwc_common_nbsd.c 1970-01-01 01:00:00.000000000 +0100
  42236. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_common_nbsd.c 2014-04-24 15:35:04.169565731 +0200
  42237. @@ -0,0 +1,1275 @@
  42238. +#include "dwc_os.h"
  42239. +#include "dwc_list.h"
  42240. +
  42241. +#ifdef DWC_CCLIB
  42242. +# include "dwc_cc.h"
  42243. +#endif
  42244. +
  42245. +#ifdef DWC_CRYPTOLIB
  42246. +# include "dwc_modpow.h"
  42247. +# include "dwc_dh.h"
  42248. +# include "dwc_crypto.h"
  42249. +#endif
  42250. +
  42251. +#ifdef DWC_NOTIFYLIB
  42252. +# include "dwc_notifier.h"
  42253. +#endif
  42254. +
  42255. +/* OS-Level Implementations */
  42256. +
  42257. +/* This is the NetBSD 4.0.1 kernel implementation of the DWC platform library. */
  42258. +
  42259. +
  42260. +/* MISC */
  42261. +
  42262. +void *DWC_MEMSET(void *dest, uint8_t byte, uint32_t size)
  42263. +{
  42264. + return memset(dest, byte, size);
  42265. +}
  42266. +
  42267. +void *DWC_MEMCPY(void *dest, void const *src, uint32_t size)
  42268. +{
  42269. + return memcpy(dest, src, size);
  42270. +}
  42271. +
  42272. +void *DWC_MEMMOVE(void *dest, void *src, uint32_t size)
  42273. +{
  42274. + bcopy(src, dest, size);
  42275. + return dest;
  42276. +}
  42277. +
  42278. +int DWC_MEMCMP(void *m1, void *m2, uint32_t size)
  42279. +{
  42280. + return memcmp(m1, m2, size);
  42281. +}
  42282. +
  42283. +int DWC_STRNCMP(void *s1, void *s2, uint32_t size)
  42284. +{
  42285. + return strncmp(s1, s2, size);
  42286. +}
  42287. +
  42288. +int DWC_STRCMP(void *s1, void *s2)
  42289. +{
  42290. + return strcmp(s1, s2);
  42291. +}
  42292. +
  42293. +int DWC_STRLEN(char const *str)
  42294. +{
  42295. + return strlen(str);
  42296. +}
  42297. +
  42298. +char *DWC_STRCPY(char *to, char const *from)
  42299. +{
  42300. + return strcpy(to, from);
  42301. +}
  42302. +
  42303. +char *DWC_STRDUP(char const *str)
  42304. +{
  42305. + int len = DWC_STRLEN(str) + 1;
  42306. + char *new = DWC_ALLOC_ATOMIC(len);
  42307. +
  42308. + if (!new) {
  42309. + return NULL;
  42310. + }
  42311. +
  42312. + DWC_MEMCPY(new, str, len);
  42313. + return new;
  42314. +}
  42315. +
  42316. +int DWC_ATOI(char *str, int32_t *value)
  42317. +{
  42318. + char *end = NULL;
  42319. +
  42320. + /* NetBSD doesn't have 'strtol' in the kernel, but 'strtoul'
  42321. + * should be equivalent on 2's complement machines
  42322. + */
  42323. + *value = strtoul(str, &end, 0);
  42324. + if (*end == '\0') {
  42325. + return 0;
  42326. + }
  42327. +
  42328. + return -1;
  42329. +}
  42330. +
  42331. +int DWC_ATOUI(char *str, uint32_t *value)
  42332. +{
  42333. + char *end = NULL;
  42334. +
  42335. + *value = strtoul(str, &end, 0);
  42336. + if (*end == '\0') {
  42337. + return 0;
  42338. + }
  42339. +
  42340. + return -1;
  42341. +}
  42342. +
  42343. +
  42344. +#ifdef DWC_UTFLIB
  42345. +/* From usbstring.c */
  42346. +
  42347. +int DWC_UTF8_TO_UTF16LE(uint8_t const *s, uint16_t *cp, unsigned len)
  42348. +{
  42349. + int count = 0;
  42350. + u8 c;
  42351. + u16 uchar;
  42352. +
  42353. + /* this insists on correct encodings, though not minimal ones.
  42354. + * BUT it currently rejects legit 4-byte UTF-8 code points,
  42355. + * which need surrogate pairs. (Unicode 3.1 can use them.)
  42356. + */
  42357. + while (len != 0 && (c = (u8) *s++) != 0) {
  42358. + if (unlikely(c & 0x80)) {
  42359. + // 2-byte sequence:
  42360. + // 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx
  42361. + if ((c & 0xe0) == 0xc0) {
  42362. + uchar = (c & 0x1f) << 6;
  42363. +
  42364. + c = (u8) *s++;
  42365. + if ((c & 0xc0) != 0xc0)
  42366. + goto fail;
  42367. + c &= 0x3f;
  42368. + uchar |= c;
  42369. +
  42370. + // 3-byte sequence (most CJKV characters):
  42371. + // zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx
  42372. + } else if ((c & 0xf0) == 0xe0) {
  42373. + uchar = (c & 0x0f) << 12;
  42374. +
  42375. + c = (u8) *s++;
  42376. + if ((c & 0xc0) != 0xc0)
  42377. + goto fail;
  42378. + c &= 0x3f;
  42379. + uchar |= c << 6;
  42380. +
  42381. + c = (u8) *s++;
  42382. + if ((c & 0xc0) != 0xc0)
  42383. + goto fail;
  42384. + c &= 0x3f;
  42385. + uchar |= c;
  42386. +
  42387. + /* no bogus surrogates */
  42388. + if (0xd800 <= uchar && uchar <= 0xdfff)
  42389. + goto fail;
  42390. +
  42391. + // 4-byte sequence (surrogate pairs, currently rare):
  42392. + // 11101110wwwwzzzzyy + 110111yyyyxxxxxx
  42393. + // = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx
  42394. + // (uuuuu = wwww + 1)
  42395. + // FIXME accept the surrogate code points (only)
  42396. + } else
  42397. + goto fail;
  42398. + } else
  42399. + uchar = c;
  42400. + put_unaligned (cpu_to_le16 (uchar), cp++);
  42401. + count++;
  42402. + len--;
  42403. + }
  42404. + return count;
  42405. +fail:
  42406. + return -1;
  42407. +}
  42408. +
  42409. +#endif /* DWC_UTFLIB */
  42410. +
  42411. +
  42412. +/* dwc_debug.h */
  42413. +
  42414. +dwc_bool_t DWC_IN_IRQ(void)
  42415. +{
  42416. +// return in_irq();
  42417. + return 0;
  42418. +}
  42419. +
  42420. +dwc_bool_t DWC_IN_BH(void)
  42421. +{
  42422. +// return in_softirq();
  42423. + return 0;
  42424. +}
  42425. +
  42426. +void DWC_VPRINTF(char *format, va_list args)
  42427. +{
  42428. + vprintf(format, args);
  42429. +}
  42430. +
  42431. +int DWC_VSNPRINTF(char *str, int size, char *format, va_list args)
  42432. +{
  42433. + return vsnprintf(str, size, format, args);
  42434. +}
  42435. +
  42436. +void DWC_PRINTF(char *format, ...)
  42437. +{
  42438. + va_list args;
  42439. +
  42440. + va_start(args, format);
  42441. + DWC_VPRINTF(format, args);
  42442. + va_end(args);
  42443. +}
  42444. +
  42445. +int DWC_SPRINTF(char *buffer, char *format, ...)
  42446. +{
  42447. + int retval;
  42448. + va_list args;
  42449. +
  42450. + va_start(args, format);
  42451. + retval = vsprintf(buffer, format, args);
  42452. + va_end(args);
  42453. + return retval;
  42454. +}
  42455. +
  42456. +int DWC_SNPRINTF(char *buffer, int size, char *format, ...)
  42457. +{
  42458. + int retval;
  42459. + va_list args;
  42460. +
  42461. + va_start(args, format);
  42462. + retval = vsnprintf(buffer, size, format, args);
  42463. + va_end(args);
  42464. + return retval;
  42465. +}
  42466. +
  42467. +void __DWC_WARN(char *format, ...)
  42468. +{
  42469. + va_list args;
  42470. +
  42471. + va_start(args, format);
  42472. + DWC_VPRINTF(format, args);
  42473. + va_end(args);
  42474. +}
  42475. +
  42476. +void __DWC_ERROR(char *format, ...)
  42477. +{
  42478. + va_list args;
  42479. +
  42480. + va_start(args, format);
  42481. + DWC_VPRINTF(format, args);
  42482. + va_end(args);
  42483. +}
  42484. +
  42485. +void DWC_EXCEPTION(char *format, ...)
  42486. +{
  42487. + va_list args;
  42488. +
  42489. + va_start(args, format);
  42490. + DWC_VPRINTF(format, args);
  42491. + va_end(args);
  42492. +// BUG_ON(1); ???
  42493. +}
  42494. +
  42495. +#ifdef DEBUG
  42496. +void __DWC_DEBUG(char *format, ...)
  42497. +{
  42498. + va_list args;
  42499. +
  42500. + va_start(args, format);
  42501. + DWC_VPRINTF(format, args);
  42502. + va_end(args);
  42503. +}
  42504. +#endif
  42505. +
  42506. +
  42507. +/* dwc_mem.h */
  42508. +
  42509. +#if 0
  42510. +dwc_pool_t *DWC_DMA_POOL_CREATE(uint32_t size,
  42511. + uint32_t align,
  42512. + uint32_t alloc)
  42513. +{
  42514. + struct dma_pool *pool = dma_pool_create("Pool", NULL,
  42515. + size, align, alloc);
  42516. + return (dwc_pool_t *)pool;
  42517. +}
  42518. +
  42519. +void DWC_DMA_POOL_DESTROY(dwc_pool_t *pool)
  42520. +{
  42521. + dma_pool_destroy((struct dma_pool *)pool);
  42522. +}
  42523. +
  42524. +void *DWC_DMA_POOL_ALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  42525. +{
  42526. +// return dma_pool_alloc((struct dma_pool *)pool, GFP_KERNEL, dma_addr);
  42527. + return dma_pool_alloc((struct dma_pool *)pool, M_WAITOK, dma_addr);
  42528. +}
  42529. +
  42530. +void *DWC_DMA_POOL_ZALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  42531. +{
  42532. + void *vaddr = DWC_DMA_POOL_ALLOC(pool, dma_addr);
  42533. + memset(..);
  42534. +}
  42535. +
  42536. +void DWC_DMA_POOL_FREE(dwc_pool_t *pool, void *vaddr, void *daddr)
  42537. +{
  42538. + dma_pool_free(pool, vaddr, daddr);
  42539. +}
  42540. +#endif
  42541. +
  42542. +void *__DWC_DMA_ALLOC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr)
  42543. +{
  42544. + dwc_dmactx_t *dma = (dwc_dmactx_t *)dma_ctx;
  42545. + int error;
  42546. +
  42547. + error = bus_dmamem_alloc(dma->dma_tag, size, 1, size, dma->segs,
  42548. + sizeof(dma->segs) / sizeof(dma->segs[0]),
  42549. + &dma->nsegs, BUS_DMA_NOWAIT);
  42550. + if (error) {
  42551. + printf("%s: bus_dmamem_alloc(%ju) failed: %d\n", __func__,
  42552. + (uintmax_t)size, error);
  42553. + goto fail_0;
  42554. + }
  42555. +
  42556. + error = bus_dmamem_map(dma->dma_tag, dma->segs, dma->nsegs, size,
  42557. + (caddr_t *)&dma->dma_vaddr,
  42558. + BUS_DMA_NOWAIT | BUS_DMA_COHERENT);
  42559. + if (error) {
  42560. + printf("%s: bus_dmamem_map failed: %d\n", __func__, error);
  42561. + goto fail_1;
  42562. + }
  42563. +
  42564. + error = bus_dmamap_create(dma->dma_tag, size, 1, size, 0,
  42565. + BUS_DMA_NOWAIT, &dma->dma_map);
  42566. + if (error) {
  42567. + printf("%s: bus_dmamap_create failed: %d\n", __func__, error);
  42568. + goto fail_2;
  42569. + }
  42570. +
  42571. + error = bus_dmamap_load(dma->dma_tag, dma->dma_map, dma->dma_vaddr,
  42572. + size, NULL, BUS_DMA_NOWAIT);
  42573. + if (error) {
  42574. + printf("%s: bus_dmamap_load failed: %d\n", __func__, error);
  42575. + goto fail_3;
  42576. + }
  42577. +
  42578. + dma->dma_paddr = (bus_addr_t)dma->segs[0].ds_addr;
  42579. + *dma_addr = dma->dma_paddr;
  42580. + return dma->dma_vaddr;
  42581. +
  42582. +fail_3:
  42583. + bus_dmamap_destroy(dma->dma_tag, dma->dma_map);
  42584. +fail_2:
  42585. + bus_dmamem_unmap(dma->dma_tag, dma->dma_vaddr, size);
  42586. +fail_1:
  42587. + bus_dmamem_free(dma->dma_tag, dma->segs, dma->nsegs);
  42588. +fail_0:
  42589. + dma->dma_map = NULL;
  42590. + dma->dma_vaddr = NULL;
  42591. + dma->nsegs = 0;
  42592. +
  42593. + return NULL;
  42594. +}
  42595. +
  42596. +void __DWC_DMA_FREE(void *dma_ctx, uint32_t size, void *virt_addr, dwc_dma_t dma_addr)
  42597. +{
  42598. + dwc_dmactx_t *dma = (dwc_dmactx_t *)dma_ctx;
  42599. +
  42600. + if (dma->dma_map != NULL) {
  42601. + bus_dmamap_sync(dma->dma_tag, dma->dma_map, 0, size,
  42602. + BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
  42603. + bus_dmamap_unload(dma->dma_tag, dma->dma_map);
  42604. + bus_dmamap_destroy(dma->dma_tag, dma->dma_map);
  42605. + bus_dmamem_unmap(dma->dma_tag, dma->dma_vaddr, size);
  42606. + bus_dmamem_free(dma->dma_tag, dma->segs, dma->nsegs);
  42607. + dma->dma_paddr = 0;
  42608. + dma->dma_map = NULL;
  42609. + dma->dma_vaddr = NULL;
  42610. + dma->nsegs = 0;
  42611. + }
  42612. +}
  42613. +
  42614. +void *__DWC_ALLOC(void *mem_ctx, uint32_t size)
  42615. +{
  42616. + return malloc(size, M_DEVBUF, M_WAITOK | M_ZERO);
  42617. +}
  42618. +
  42619. +void *__DWC_ALLOC_ATOMIC(void *mem_ctx, uint32_t size)
  42620. +{
  42621. + return malloc(size, M_DEVBUF, M_NOWAIT | M_ZERO);
  42622. +}
  42623. +
  42624. +void __DWC_FREE(void *mem_ctx, void *addr)
  42625. +{
  42626. + free(addr, M_DEVBUF);
  42627. +}
  42628. +
  42629. +
  42630. +#ifdef DWC_CRYPTOLIB
  42631. +/* dwc_crypto.h */
  42632. +
  42633. +void DWC_RANDOM_BYTES(uint8_t *buffer, uint32_t length)
  42634. +{
  42635. + get_random_bytes(buffer, length);
  42636. +}
  42637. +
  42638. +int DWC_AES_CBC(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t iv[16], uint8_t *out)
  42639. +{
  42640. + struct crypto_blkcipher *tfm;
  42641. + struct blkcipher_desc desc;
  42642. + struct scatterlist sgd;
  42643. + struct scatterlist sgs;
  42644. +
  42645. + tfm = crypto_alloc_blkcipher("cbc(aes)", 0, CRYPTO_ALG_ASYNC);
  42646. + if (tfm == NULL) {
  42647. + printk("failed to load transform for aes CBC\n");
  42648. + return -1;
  42649. + }
  42650. +
  42651. + crypto_blkcipher_setkey(tfm, key, keylen);
  42652. + crypto_blkcipher_set_iv(tfm, iv, 16);
  42653. +
  42654. + sg_init_one(&sgd, out, messagelen);
  42655. + sg_init_one(&sgs, message, messagelen);
  42656. +
  42657. + desc.tfm = tfm;
  42658. + desc.flags = 0;
  42659. +
  42660. + if (crypto_blkcipher_encrypt(&desc, &sgd, &sgs, messagelen)) {
  42661. + crypto_free_blkcipher(tfm);
  42662. + DWC_ERROR("AES CBC encryption failed");
  42663. + return -1;
  42664. + }
  42665. +
  42666. + crypto_free_blkcipher(tfm);
  42667. + return 0;
  42668. +}
  42669. +
  42670. +int DWC_SHA256(uint8_t *message, uint32_t len, uint8_t *out)
  42671. +{
  42672. + struct crypto_hash *tfm;
  42673. + struct hash_desc desc;
  42674. + struct scatterlist sg;
  42675. +
  42676. + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
  42677. + if (IS_ERR(tfm)) {
  42678. + DWC_ERROR("Failed to load transform for sha256: %ld", PTR_ERR(tfm));
  42679. + return 0;
  42680. + }
  42681. + desc.tfm = tfm;
  42682. + desc.flags = 0;
  42683. +
  42684. + sg_init_one(&sg, message, len);
  42685. + crypto_hash_digest(&desc, &sg, len, out);
  42686. + crypto_free_hash(tfm);
  42687. +
  42688. + return 1;
  42689. +}
  42690. +
  42691. +int DWC_HMAC_SHA256(uint8_t *message, uint32_t messagelen,
  42692. + uint8_t *key, uint32_t keylen, uint8_t *out)
  42693. +{
  42694. + struct crypto_hash *tfm;
  42695. + struct hash_desc desc;
  42696. + struct scatterlist sg;
  42697. +
  42698. + tfm = crypto_alloc_hash("hmac(sha256)", 0, CRYPTO_ALG_ASYNC);
  42699. + if (IS_ERR(tfm)) {
  42700. + DWC_ERROR("Failed to load transform for hmac(sha256): %ld", PTR_ERR(tfm));
  42701. + return 0;
  42702. + }
  42703. + desc.tfm = tfm;
  42704. + desc.flags = 0;
  42705. +
  42706. + sg_init_one(&sg, message, messagelen);
  42707. + crypto_hash_setkey(tfm, key, keylen);
  42708. + crypto_hash_digest(&desc, &sg, messagelen, out);
  42709. + crypto_free_hash(tfm);
  42710. +
  42711. + return 1;
  42712. +}
  42713. +
  42714. +#endif /* DWC_CRYPTOLIB */
  42715. +
  42716. +
  42717. +/* Byte Ordering Conversions */
  42718. +
  42719. +uint32_t DWC_CPU_TO_LE32(uint32_t *p)
  42720. +{
  42721. +#ifdef __LITTLE_ENDIAN
  42722. + return *p;
  42723. +#else
  42724. + uint8_t *u_p = (uint8_t *)p;
  42725. +
  42726. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  42727. +#endif
  42728. +}
  42729. +
  42730. +uint32_t DWC_CPU_TO_BE32(uint32_t *p)
  42731. +{
  42732. +#ifdef __BIG_ENDIAN
  42733. + return *p;
  42734. +#else
  42735. + uint8_t *u_p = (uint8_t *)p;
  42736. +
  42737. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  42738. +#endif
  42739. +}
  42740. +
  42741. +uint32_t DWC_LE32_TO_CPU(uint32_t *p)
  42742. +{
  42743. +#ifdef __LITTLE_ENDIAN
  42744. + return *p;
  42745. +#else
  42746. + uint8_t *u_p = (uint8_t *)p;
  42747. +
  42748. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  42749. +#endif
  42750. +}
  42751. +
  42752. +uint32_t DWC_BE32_TO_CPU(uint32_t *p)
  42753. +{
  42754. +#ifdef __BIG_ENDIAN
  42755. + return *p;
  42756. +#else
  42757. + uint8_t *u_p = (uint8_t *)p;
  42758. +
  42759. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  42760. +#endif
  42761. +}
  42762. +
  42763. +uint16_t DWC_CPU_TO_LE16(uint16_t *p)
  42764. +{
  42765. +#ifdef __LITTLE_ENDIAN
  42766. + return *p;
  42767. +#else
  42768. + uint8_t *u_p = (uint8_t *)p;
  42769. + return (u_p[1] | (u_p[0] << 8));
  42770. +#endif
  42771. +}
  42772. +
  42773. +uint16_t DWC_CPU_TO_BE16(uint16_t *p)
  42774. +{
  42775. +#ifdef __BIG_ENDIAN
  42776. + return *p;
  42777. +#else
  42778. + uint8_t *u_p = (uint8_t *)p;
  42779. + return (u_p[1] | (u_p[0] << 8));
  42780. +#endif
  42781. +}
  42782. +
  42783. +uint16_t DWC_LE16_TO_CPU(uint16_t *p)
  42784. +{
  42785. +#ifdef __LITTLE_ENDIAN
  42786. + return *p;
  42787. +#else
  42788. + uint8_t *u_p = (uint8_t *)p;
  42789. + return (u_p[1] | (u_p[0] << 8));
  42790. +#endif
  42791. +}
  42792. +
  42793. +uint16_t DWC_BE16_TO_CPU(uint16_t *p)
  42794. +{
  42795. +#ifdef __BIG_ENDIAN
  42796. + return *p;
  42797. +#else
  42798. + uint8_t *u_p = (uint8_t *)p;
  42799. + return (u_p[1] | (u_p[0] << 8));
  42800. +#endif
  42801. +}
  42802. +
  42803. +
  42804. +/* Registers */
  42805. +
  42806. +uint32_t DWC_READ_REG32(void *io_ctx, uint32_t volatile *reg)
  42807. +{
  42808. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  42809. + bus_size_t ior = (bus_size_t)reg;
  42810. +
  42811. + return bus_space_read_4(io->iot, io->ioh, ior);
  42812. +}
  42813. +
  42814. +#if 0
  42815. +uint64_t DWC_READ_REG64(void *io_ctx, uint64_t volatile *reg)
  42816. +{
  42817. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  42818. + bus_size_t ior = (bus_size_t)reg;
  42819. +
  42820. + return bus_space_read_8(io->iot, io->ioh, ior);
  42821. +}
  42822. +#endif
  42823. +
  42824. +void DWC_WRITE_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t value)
  42825. +{
  42826. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  42827. + bus_size_t ior = (bus_size_t)reg;
  42828. +
  42829. + bus_space_write_4(io->iot, io->ioh, ior, value);
  42830. +}
  42831. +
  42832. +#if 0
  42833. +void DWC_WRITE_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t value)
  42834. +{
  42835. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  42836. + bus_size_t ior = (bus_size_t)reg;
  42837. +
  42838. + bus_space_write_8(io->iot, io->ioh, ior, value);
  42839. +}
  42840. +#endif
  42841. +
  42842. +void DWC_MODIFY_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t clear_mask,
  42843. + uint32_t set_mask)
  42844. +{
  42845. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  42846. + bus_size_t ior = (bus_size_t)reg;
  42847. +
  42848. + bus_space_write_4(io->iot, io->ioh, ior,
  42849. + (bus_space_read_4(io->iot, io->ioh, ior) &
  42850. + ~clear_mask) | set_mask);
  42851. +}
  42852. +
  42853. +#if 0
  42854. +void DWC_MODIFY_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t clear_mask,
  42855. + uint64_t set_mask)
  42856. +{
  42857. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  42858. + bus_size_t ior = (bus_size_t)reg;
  42859. +
  42860. + bus_space_write_8(io->iot, io->ioh, ior,
  42861. + (bus_space_read_8(io->iot, io->ioh, ior) &
  42862. + ~clear_mask) | set_mask);
  42863. +}
  42864. +#endif
  42865. +
  42866. +
  42867. +/* Locking */
  42868. +
  42869. +dwc_spinlock_t *DWC_SPINLOCK_ALLOC(void)
  42870. +{
  42871. + struct simplelock *sl = DWC_ALLOC(sizeof(*sl));
  42872. +
  42873. + if (!sl) {
  42874. + DWC_ERROR("Cannot allocate memory for spinlock");
  42875. + return NULL;
  42876. + }
  42877. +
  42878. + simple_lock_init(sl);
  42879. + return (dwc_spinlock_t *)sl;
  42880. +}
  42881. +
  42882. +void DWC_SPINLOCK_FREE(dwc_spinlock_t *lock)
  42883. +{
  42884. + struct simplelock *sl = (struct simplelock *)lock;
  42885. +
  42886. + DWC_FREE(sl);
  42887. +}
  42888. +
  42889. +void DWC_SPINLOCK(dwc_spinlock_t *lock)
  42890. +{
  42891. + simple_lock((struct simplelock *)lock);
  42892. +}
  42893. +
  42894. +void DWC_SPINUNLOCK(dwc_spinlock_t *lock)
  42895. +{
  42896. + simple_unlock((struct simplelock *)lock);
  42897. +}
  42898. +
  42899. +void DWC_SPINLOCK_IRQSAVE(dwc_spinlock_t *lock, dwc_irqflags_t *flags)
  42900. +{
  42901. + simple_lock((struct simplelock *)lock);
  42902. + *flags = splbio();
  42903. +}
  42904. +
  42905. +void DWC_SPINUNLOCK_IRQRESTORE(dwc_spinlock_t *lock, dwc_irqflags_t flags)
  42906. +{
  42907. + splx(flags);
  42908. + simple_unlock((struct simplelock *)lock);
  42909. +}
  42910. +
  42911. +dwc_mutex_t *DWC_MUTEX_ALLOC(void)
  42912. +{
  42913. + dwc_mutex_t *mutex = DWC_ALLOC(sizeof(struct lock));
  42914. +
  42915. + if (!mutex) {
  42916. + DWC_ERROR("Cannot allocate memory for mutex");
  42917. + return NULL;
  42918. + }
  42919. +
  42920. + lockinit((struct lock *)mutex, 0, "dw3mtx", 0, 0);
  42921. + return mutex;
  42922. +}
  42923. +
  42924. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  42925. +#else
  42926. +void DWC_MUTEX_FREE(dwc_mutex_t *mutex)
  42927. +{
  42928. + DWC_FREE(mutex);
  42929. +}
  42930. +#endif
  42931. +
  42932. +void DWC_MUTEX_LOCK(dwc_mutex_t *mutex)
  42933. +{
  42934. + lockmgr((struct lock *)mutex, LK_EXCLUSIVE, NULL);
  42935. +}
  42936. +
  42937. +int DWC_MUTEX_TRYLOCK(dwc_mutex_t *mutex)
  42938. +{
  42939. + int status;
  42940. +
  42941. + status = lockmgr((struct lock *)mutex, LK_EXCLUSIVE | LK_NOWAIT, NULL);
  42942. + return status == 0;
  42943. +}
  42944. +
  42945. +void DWC_MUTEX_UNLOCK(dwc_mutex_t *mutex)
  42946. +{
  42947. + lockmgr((struct lock *)mutex, LK_RELEASE, NULL);
  42948. +}
  42949. +
  42950. +
  42951. +/* Timing */
  42952. +
  42953. +void DWC_UDELAY(uint32_t usecs)
  42954. +{
  42955. + DELAY(usecs);
  42956. +}
  42957. +
  42958. +void DWC_MDELAY(uint32_t msecs)
  42959. +{
  42960. + do {
  42961. + DELAY(1000);
  42962. + } while (--msecs);
  42963. +}
  42964. +
  42965. +void DWC_MSLEEP(uint32_t msecs)
  42966. +{
  42967. + struct timeval tv;
  42968. +
  42969. + tv.tv_sec = msecs / 1000;
  42970. + tv.tv_usec = (msecs - tv.tv_sec * 1000) * 1000;
  42971. + tsleep(&tv, 0, "dw3slp", tvtohz(&tv));
  42972. +}
  42973. +
  42974. +uint32_t DWC_TIME(void)
  42975. +{
  42976. + struct timeval tv;
  42977. +
  42978. + microuptime(&tv); // or getmicrouptime? (less precise, but faster)
  42979. + return tv.tv_sec * 1000 + tv.tv_usec / 1000;
  42980. +}
  42981. +
  42982. +
  42983. +/* Timers */
  42984. +
  42985. +struct dwc_timer {
  42986. + struct callout t;
  42987. + char *name;
  42988. + dwc_spinlock_t *lock;
  42989. + dwc_timer_callback_t cb;
  42990. + void *data;
  42991. +};
  42992. +
  42993. +dwc_timer_t *DWC_TIMER_ALLOC(char *name, dwc_timer_callback_t cb, void *data)
  42994. +{
  42995. + dwc_timer_t *t = DWC_ALLOC(sizeof(*t));
  42996. +
  42997. + if (!t) {
  42998. + DWC_ERROR("Cannot allocate memory for timer");
  42999. + return NULL;
  43000. + }
  43001. +
  43002. + callout_init(&t->t);
  43003. +
  43004. + t->name = DWC_STRDUP(name);
  43005. + if (!t->name) {
  43006. + DWC_ERROR("Cannot allocate memory for timer->name");
  43007. + goto no_name;
  43008. + }
  43009. +
  43010. + t->lock = DWC_SPINLOCK_ALLOC();
  43011. + if (!t->lock) {
  43012. + DWC_ERROR("Cannot allocate memory for timer->lock");
  43013. + goto no_lock;
  43014. + }
  43015. +
  43016. + t->cb = cb;
  43017. + t->data = data;
  43018. +
  43019. + return t;
  43020. +
  43021. + no_lock:
  43022. + DWC_FREE(t->name);
  43023. + no_name:
  43024. + DWC_FREE(t);
  43025. +
  43026. + return NULL;
  43027. +}
  43028. +
  43029. +void DWC_TIMER_FREE(dwc_timer_t *timer)
  43030. +{
  43031. + callout_stop(&timer->t);
  43032. + DWC_SPINLOCK_FREE(timer->lock);
  43033. + DWC_FREE(timer->name);
  43034. + DWC_FREE(timer);
  43035. +}
  43036. +
  43037. +void DWC_TIMER_SCHEDULE(dwc_timer_t *timer, uint32_t time)
  43038. +{
  43039. + struct timeval tv;
  43040. +
  43041. + tv.tv_sec = time / 1000;
  43042. + tv.tv_usec = (time - tv.tv_sec * 1000) * 1000;
  43043. + callout_reset(&timer->t, tvtohz(&tv), timer->cb, timer->data);
  43044. +}
  43045. +
  43046. +void DWC_TIMER_CANCEL(dwc_timer_t *timer)
  43047. +{
  43048. + callout_stop(&timer->t);
  43049. +}
  43050. +
  43051. +
  43052. +/* Wait Queues */
  43053. +
  43054. +struct dwc_waitq {
  43055. + struct simplelock lock;
  43056. + int abort;
  43057. +};
  43058. +
  43059. +dwc_waitq_t *DWC_WAITQ_ALLOC(void)
  43060. +{
  43061. + dwc_waitq_t *wq = DWC_ALLOC(sizeof(*wq));
  43062. +
  43063. + if (!wq) {
  43064. + DWC_ERROR("Cannot allocate memory for waitqueue");
  43065. + return NULL;
  43066. + }
  43067. +
  43068. + simple_lock_init(&wq->lock);
  43069. + wq->abort = 0;
  43070. +
  43071. + return wq;
  43072. +}
  43073. +
  43074. +void DWC_WAITQ_FREE(dwc_waitq_t *wq)
  43075. +{
  43076. + DWC_FREE(wq);
  43077. +}
  43078. +
  43079. +int32_t DWC_WAITQ_WAIT(dwc_waitq_t *wq, dwc_waitq_condition_t cond, void *data)
  43080. +{
  43081. + int ipl;
  43082. + int result = 0;
  43083. +
  43084. + simple_lock(&wq->lock);
  43085. + ipl = splbio();
  43086. +
  43087. + /* Skip the sleep if already aborted or triggered */
  43088. + if (!wq->abort && !cond(data)) {
  43089. + splx(ipl);
  43090. + result = ltsleep(wq, PCATCH, "dw3wat", 0, &wq->lock); // infinite timeout
  43091. + ipl = splbio();
  43092. + }
  43093. +
  43094. + if (result == 0) { // awoken
  43095. + if (wq->abort) {
  43096. + wq->abort = 0;
  43097. + result = -DWC_E_ABORT;
  43098. + } else {
  43099. + result = 0;
  43100. + }
  43101. +
  43102. + splx(ipl);
  43103. + simple_unlock(&wq->lock);
  43104. + } else {
  43105. + wq->abort = 0;
  43106. + splx(ipl);
  43107. + simple_unlock(&wq->lock);
  43108. +
  43109. + if (result == ERESTART) { // signaled - restart
  43110. + result = -DWC_E_RESTART;
  43111. + } else { // signaled - must be EINTR
  43112. + result = -DWC_E_ABORT;
  43113. + }
  43114. + }
  43115. +
  43116. + return result;
  43117. +}
  43118. +
  43119. +int32_t DWC_WAITQ_WAIT_TIMEOUT(dwc_waitq_t *wq, dwc_waitq_condition_t cond,
  43120. + void *data, int32_t msecs)
  43121. +{
  43122. + struct timeval tv, tv1, tv2;
  43123. + int ipl;
  43124. + int result = 0;
  43125. +
  43126. + tv.tv_sec = msecs / 1000;
  43127. + tv.tv_usec = (msecs - tv.tv_sec * 1000) * 1000;
  43128. +
  43129. + simple_lock(&wq->lock);
  43130. + ipl = splbio();
  43131. +
  43132. + /* Skip the sleep if already aborted or triggered */
  43133. + if (!wq->abort && !cond(data)) {
  43134. + splx(ipl);
  43135. + getmicrouptime(&tv1);
  43136. + result = ltsleep(wq, PCATCH, "dw3wto", tvtohz(&tv), &wq->lock);
  43137. + getmicrouptime(&tv2);
  43138. + ipl = splbio();
  43139. + }
  43140. +
  43141. + if (result == 0) { // awoken
  43142. + if (wq->abort) {
  43143. + wq->abort = 0;
  43144. + splx(ipl);
  43145. + simple_unlock(&wq->lock);
  43146. + result = -DWC_E_ABORT;
  43147. + } else {
  43148. + splx(ipl);
  43149. + simple_unlock(&wq->lock);
  43150. +
  43151. + tv2.tv_usec -= tv1.tv_usec;
  43152. + if (tv2.tv_usec < 0) {
  43153. + tv2.tv_usec += 1000000;
  43154. + tv2.tv_sec--;
  43155. + }
  43156. +
  43157. + tv2.tv_sec -= tv1.tv_sec;
  43158. + result = tv2.tv_sec * 1000 + tv2.tv_usec / 1000;
  43159. + result = msecs - result;
  43160. + if (result <= 0)
  43161. + result = 1;
  43162. + }
  43163. + } else {
  43164. + wq->abort = 0;
  43165. + splx(ipl);
  43166. + simple_unlock(&wq->lock);
  43167. +
  43168. + if (result == ERESTART) { // signaled - restart
  43169. + result = -DWC_E_RESTART;
  43170. +
  43171. + } else if (result == EINTR) { // signaled - interrupt
  43172. + result = -DWC_E_ABORT;
  43173. +
  43174. + } else { // timed out
  43175. + result = -DWC_E_TIMEOUT;
  43176. + }
  43177. + }
  43178. +
  43179. + return result;
  43180. +}
  43181. +
  43182. +void DWC_WAITQ_TRIGGER(dwc_waitq_t *wq)
  43183. +{
  43184. + wakeup(wq);
  43185. +}
  43186. +
  43187. +void DWC_WAITQ_ABORT(dwc_waitq_t *wq)
  43188. +{
  43189. + int ipl;
  43190. +
  43191. + simple_lock(&wq->lock);
  43192. + ipl = splbio();
  43193. + wq->abort = 1;
  43194. + wakeup(wq);
  43195. + splx(ipl);
  43196. + simple_unlock(&wq->lock);
  43197. +}
  43198. +
  43199. +
  43200. +/* Threading */
  43201. +
  43202. +struct dwc_thread {
  43203. + struct proc *proc;
  43204. + int abort;
  43205. +};
  43206. +
  43207. +dwc_thread_t *DWC_THREAD_RUN(dwc_thread_function_t func, char *name, void *data)
  43208. +{
  43209. + int retval;
  43210. + dwc_thread_t *thread = DWC_ALLOC(sizeof(*thread));
  43211. +
  43212. + if (!thread) {
  43213. + return NULL;
  43214. + }
  43215. +
  43216. + thread->abort = 0;
  43217. + retval = kthread_create1((void (*)(void *))func, data, &thread->proc,
  43218. + "%s", name);
  43219. + if (retval) {
  43220. + DWC_FREE(thread);
  43221. + return NULL;
  43222. + }
  43223. +
  43224. + return thread;
  43225. +}
  43226. +
  43227. +int DWC_THREAD_STOP(dwc_thread_t *thread)
  43228. +{
  43229. + int retval;
  43230. +
  43231. + thread->abort = 1;
  43232. + retval = tsleep(&thread->abort, 0, "dw3stp", 60 * hz);
  43233. +
  43234. + if (retval == 0) {
  43235. + /* DWC_THREAD_EXIT() will free the thread struct */
  43236. + return 0;
  43237. + }
  43238. +
  43239. + /* NOTE: We leak the thread struct if thread doesn't die */
  43240. +
  43241. + if (retval == EWOULDBLOCK) {
  43242. + return -DWC_E_TIMEOUT;
  43243. + }
  43244. +
  43245. + return -DWC_E_UNKNOWN;
  43246. +}
  43247. +
  43248. +dwc_bool_t DWC_THREAD_SHOULD_STOP(dwc_thread_t *thread)
  43249. +{
  43250. + return thread->abort;
  43251. +}
  43252. +
  43253. +void DWC_THREAD_EXIT(dwc_thread_t *thread)
  43254. +{
  43255. + wakeup(&thread->abort);
  43256. + DWC_FREE(thread);
  43257. + kthread_exit(0);
  43258. +}
  43259. +
  43260. +/* tasklets
  43261. + - Runs in interrupt context (cannot sleep)
  43262. + - Each tasklet runs on a single CPU
  43263. + - Different tasklets can be running simultaneously on different CPUs
  43264. + [ On NetBSD there is no corresponding mechanism, drivers don't have bottom-
  43265. + halves. So we just call the callback directly from DWC_TASK_SCHEDULE() ]
  43266. + */
  43267. +struct dwc_tasklet {
  43268. + dwc_tasklet_callback_t cb;
  43269. + void *data;
  43270. +};
  43271. +
  43272. +static void tasklet_callback(void *data)
  43273. +{
  43274. + dwc_tasklet_t *task = (dwc_tasklet_t *)data;
  43275. +
  43276. + task->cb(task->data);
  43277. +}
  43278. +
  43279. +dwc_tasklet_t *DWC_TASK_ALLOC(char *name, dwc_tasklet_callback_t cb, void *data)
  43280. +{
  43281. + dwc_tasklet_t *task = DWC_ALLOC(sizeof(*task));
  43282. +
  43283. + if (task) {
  43284. + task->cb = cb;
  43285. + task->data = data;
  43286. + } else {
  43287. + DWC_ERROR("Cannot allocate memory for tasklet");
  43288. + }
  43289. +
  43290. + return task;
  43291. +}
  43292. +
  43293. +void DWC_TASK_FREE(dwc_tasklet_t *task)
  43294. +{
  43295. + DWC_FREE(task);
  43296. +}
  43297. +
  43298. +void DWC_TASK_SCHEDULE(dwc_tasklet_t *task)
  43299. +{
  43300. + tasklet_callback(task);
  43301. +}
  43302. +
  43303. +
  43304. +/* workqueues
  43305. + - Runs in process context (can sleep)
  43306. + */
  43307. +typedef struct work_container {
  43308. + dwc_work_callback_t cb;
  43309. + void *data;
  43310. + dwc_workq_t *wq;
  43311. + char *name;
  43312. + int hz;
  43313. + struct work task;
  43314. +} work_container_t;
  43315. +
  43316. +struct dwc_workq {
  43317. + struct workqueue *taskq;
  43318. + dwc_spinlock_t *lock;
  43319. + dwc_waitq_t *waitq;
  43320. + int pending;
  43321. + struct work_container *container;
  43322. +};
  43323. +
  43324. +static void do_work(struct work *task, void *data)
  43325. +{
  43326. + dwc_workq_t *wq = (dwc_workq_t *)data;
  43327. + work_container_t *container = wq->container;
  43328. + dwc_irqflags_t flags;
  43329. +
  43330. + if (container->hz) {
  43331. + tsleep(container, 0, "dw3wrk", container->hz);
  43332. + }
  43333. +
  43334. + container->cb(container->data);
  43335. + DWC_DEBUG("Work done: %s, container=%p", container->name, container);
  43336. +
  43337. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  43338. + if (container->name)
  43339. + DWC_FREE(container->name);
  43340. + DWC_FREE(container);
  43341. + wq->pending--;
  43342. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  43343. + DWC_WAITQ_TRIGGER(wq->waitq);
  43344. +}
  43345. +
  43346. +static int work_done(void *data)
  43347. +{
  43348. + dwc_workq_t *workq = (dwc_workq_t *)data;
  43349. +
  43350. + return workq->pending == 0;
  43351. +}
  43352. +
  43353. +int DWC_WORKQ_WAIT_WORK_DONE(dwc_workq_t *workq, int timeout)
  43354. +{
  43355. + return DWC_WAITQ_WAIT_TIMEOUT(workq->waitq, work_done, workq, timeout);
  43356. +}
  43357. +
  43358. +dwc_workq_t *DWC_WORKQ_ALLOC(char *name)
  43359. +{
  43360. + int result;
  43361. + dwc_workq_t *wq = DWC_ALLOC(sizeof(*wq));
  43362. +
  43363. + if (!wq) {
  43364. + DWC_ERROR("Cannot allocate memory for workqueue");
  43365. + return NULL;
  43366. + }
  43367. +
  43368. + result = workqueue_create(&wq->taskq, name, do_work, wq, 0 /*PWAIT*/,
  43369. + IPL_BIO, 0);
  43370. + if (result) {
  43371. + DWC_ERROR("Cannot create workqueue");
  43372. + goto no_taskq;
  43373. + }
  43374. +
  43375. + wq->pending = 0;
  43376. +
  43377. + wq->lock = DWC_SPINLOCK_ALLOC();
  43378. + if (!wq->lock) {
  43379. + DWC_ERROR("Cannot allocate memory for spinlock");
  43380. + goto no_lock;
  43381. + }
  43382. +
  43383. + wq->waitq = DWC_WAITQ_ALLOC();
  43384. + if (!wq->waitq) {
  43385. + DWC_ERROR("Cannot allocate memory for waitqueue");
  43386. + goto no_waitq;
  43387. + }
  43388. +
  43389. + return wq;
  43390. +
  43391. + no_waitq:
  43392. + DWC_SPINLOCK_FREE(wq->lock);
  43393. + no_lock:
  43394. + workqueue_destroy(wq->taskq);
  43395. + no_taskq:
  43396. + DWC_FREE(wq);
  43397. +
  43398. + return NULL;
  43399. +}
  43400. +
  43401. +void DWC_WORKQ_FREE(dwc_workq_t *wq)
  43402. +{
  43403. +#ifdef DEBUG
  43404. + dwc_irqflags_t flags;
  43405. +
  43406. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  43407. +
  43408. + if (wq->pending != 0) {
  43409. + struct work_container *container = wq->container;
  43410. +
  43411. + DWC_ERROR("Destroying work queue with pending work");
  43412. +
  43413. + if (container && container->name) {
  43414. + DWC_ERROR("Work %s still pending", container->name);
  43415. + }
  43416. + }
  43417. +
  43418. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  43419. +#endif
  43420. + DWC_WAITQ_FREE(wq->waitq);
  43421. + DWC_SPINLOCK_FREE(wq->lock);
  43422. + workqueue_destroy(wq->taskq);
  43423. + DWC_FREE(wq);
  43424. +}
  43425. +
  43426. +void DWC_WORKQ_SCHEDULE(dwc_workq_t *wq, dwc_work_callback_t cb, void *data,
  43427. + char *format, ...)
  43428. +{
  43429. + dwc_irqflags_t flags;
  43430. + work_container_t *container;
  43431. + static char name[128];
  43432. + va_list args;
  43433. +
  43434. + va_start(args, format);
  43435. + DWC_VSNPRINTF(name, 128, format, args);
  43436. + va_end(args);
  43437. +
  43438. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  43439. + wq->pending++;
  43440. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  43441. + DWC_WAITQ_TRIGGER(wq->waitq);
  43442. +
  43443. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  43444. + if (!container) {
  43445. + DWC_ERROR("Cannot allocate memory for container");
  43446. + return;
  43447. + }
  43448. +
  43449. + container->name = DWC_STRDUP(name);
  43450. + if (!container->name) {
  43451. + DWC_ERROR("Cannot allocate memory for container->name");
  43452. + DWC_FREE(container);
  43453. + return;
  43454. + }
  43455. +
  43456. + container->cb = cb;
  43457. + container->data = data;
  43458. + container->wq = wq;
  43459. + container->hz = 0;
  43460. + wq->container = container;
  43461. +
  43462. + DWC_DEBUG("Queueing work: %s, container=%p", container->name, container);
  43463. + workqueue_enqueue(wq->taskq, &container->task);
  43464. +}
  43465. +
  43466. +void DWC_WORKQ_SCHEDULE_DELAYED(dwc_workq_t *wq, dwc_work_callback_t cb,
  43467. + void *data, uint32_t time, char *format, ...)
  43468. +{
  43469. + dwc_irqflags_t flags;
  43470. + work_container_t *container;
  43471. + static char name[128];
  43472. + struct timeval tv;
  43473. + va_list args;
  43474. +
  43475. + va_start(args, format);
  43476. + DWC_VSNPRINTF(name, 128, format, args);
  43477. + va_end(args);
  43478. +
  43479. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  43480. + wq->pending++;
  43481. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  43482. + DWC_WAITQ_TRIGGER(wq->waitq);
  43483. +
  43484. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  43485. + if (!container) {
  43486. + DWC_ERROR("Cannot allocate memory for container");
  43487. + return;
  43488. + }
  43489. +
  43490. + container->name = DWC_STRDUP(name);
  43491. + if (!container->name) {
  43492. + DWC_ERROR("Cannot allocate memory for container->name");
  43493. + DWC_FREE(container);
  43494. + return;
  43495. + }
  43496. +
  43497. + container->cb = cb;
  43498. + container->data = data;
  43499. + container->wq = wq;
  43500. + tv.tv_sec = time / 1000;
  43501. + tv.tv_usec = (time - tv.tv_sec * 1000) * 1000;
  43502. + container->hz = tvtohz(&tv);
  43503. + wq->container = container;
  43504. +
  43505. + DWC_DEBUG("Queueing work: %s, container=%p", container->name, container);
  43506. + workqueue_enqueue(wq->taskq, &container->task);
  43507. +}
  43508. +
  43509. +int DWC_WORKQ_PENDING(dwc_workq_t *wq)
  43510. +{
  43511. + return wq->pending;
  43512. +}
  43513. diff -Nur linux-3.13.11/drivers/usb/host/dwc_common_port/dwc_crypto.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_crypto.c
  43514. --- linux-3.13.11/drivers/usb/host/dwc_common_port/dwc_crypto.c 1970-01-01 01:00:00.000000000 +0100
  43515. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_crypto.c 2014-04-24 15:35:04.169565731 +0200
  43516. @@ -0,0 +1,308 @@
  43517. +/* =========================================================================
  43518. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_crypto.c $
  43519. + * $Revision: #5 $
  43520. + * $Date: 2010/09/28 $
  43521. + * $Change: 1596182 $
  43522. + *
  43523. + * Synopsys Portability Library Software and documentation
  43524. + * (hereinafter, "Software") is an Unsupported proprietary work of
  43525. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  43526. + * between Synopsys and you.
  43527. + *
  43528. + * The Software IS NOT an item of Licensed Software or Licensed Product
  43529. + * under any End User Software License Agreement or Agreement for
  43530. + * Licensed Product with Synopsys or any supplement thereto. You are
  43531. + * permitted to use and redistribute this Software in source and binary
  43532. + * forms, with or without modification, provided that redistributions
  43533. + * of source code must retain this notice. You may not view, use,
  43534. + * disclose, copy or distribute this file or any information contained
  43535. + * herein except pursuant to this license grant from Synopsys. If you
  43536. + * do not agree with this notice, including the disclaimer below, then
  43537. + * you are not authorized to use the Software.
  43538. + *
  43539. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  43540. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  43541. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  43542. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  43543. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  43544. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  43545. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  43546. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  43547. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  43548. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  43549. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  43550. + * DAMAGE.
  43551. + * ========================================================================= */
  43552. +
  43553. +/** @file
  43554. + * This file contains the WUSB cryptographic routines.
  43555. + */
  43556. +
  43557. +#ifdef DWC_CRYPTOLIB
  43558. +
  43559. +#include "dwc_crypto.h"
  43560. +#include "usb.h"
  43561. +
  43562. +#ifdef DEBUG
  43563. +static inline void dump_bytes(char *name, uint8_t *bytes, int len)
  43564. +{
  43565. + int i;
  43566. + DWC_PRINTF("%s: ", name);
  43567. + for (i=0; i<len; i++) {
  43568. + DWC_PRINTF("%02x ", bytes[i]);
  43569. + }
  43570. + DWC_PRINTF("\n");
  43571. +}
  43572. +#else
  43573. +#define dump_bytes(x...)
  43574. +#endif
  43575. +
  43576. +/* Display a block */
  43577. +void show_block(const u8 *blk, const char *prefix, const char *suffix, int a)
  43578. +{
  43579. +#ifdef DWC_DEBUG_CRYPTO
  43580. + int i, blksize = 16;
  43581. +
  43582. + DWC_DEBUG("%s", prefix);
  43583. +
  43584. + if (suffix == NULL) {
  43585. + suffix = "\n";
  43586. + blksize = a;
  43587. + }
  43588. +
  43589. + for (i = 0; i < blksize; i++)
  43590. + DWC_PRINT("%02x%s", *blk++, ((i & 3) == 3) ? " " : " ");
  43591. + DWC_PRINT(suffix);
  43592. +#endif
  43593. +}
  43594. +
  43595. +/**
  43596. + * Encrypts an array of bytes using the AES encryption engine.
  43597. + * If <code>dst</code> == <code>src</code>, then the bytes will be encrypted
  43598. + * in-place.
  43599. + *
  43600. + * @return 0 on success, negative error code on error.
  43601. + */
  43602. +int dwc_wusb_aes_encrypt(u8 *src, u8 *key, u8 *dst)
  43603. +{
  43604. + u8 block_t[16];
  43605. + DWC_MEMSET(block_t, 0, 16);
  43606. +
  43607. + return DWC_AES_CBC(src, 16, key, 16, block_t, dst);
  43608. +}
  43609. +
  43610. +/**
  43611. + * The CCM-MAC-FUNCTION described in section 6.5 of the WUSB spec.
  43612. + * This function takes a data string and returns the encrypted CBC
  43613. + * Counter-mode MIC.
  43614. + *
  43615. + * @param key The 128-bit symmetric key.
  43616. + * @param nonce The CCM nonce.
  43617. + * @param label The unique 14-byte ASCII text label.
  43618. + * @param bytes The byte array to be encrypted.
  43619. + * @param len Length of the byte array.
  43620. + * @param result Byte array to receive the 8-byte encrypted MIC.
  43621. + */
  43622. +void dwc_wusb_cmf(u8 *key, u8 *nonce,
  43623. + char *label, u8 *bytes, int len, u8 *result)
  43624. +{
  43625. + u8 block_m[16];
  43626. + u8 block_x[16];
  43627. + u8 block_t[8];
  43628. + int idx, blkNum;
  43629. + u16 la = (u16)(len + 14);
  43630. +
  43631. + /* Set the AES-128 key */
  43632. + //dwc_aes_setkey(tfm, key, 16);
  43633. +
  43634. + /* Fill block B0 from flags = 0x59, N, and l(m) = 0 */
  43635. + block_m[0] = 0x59;
  43636. + for (idx = 0; idx < 13; idx++)
  43637. + block_m[idx + 1] = nonce[idx];
  43638. + block_m[14] = 0;
  43639. + block_m[15] = 0;
  43640. +
  43641. + /* Produce the CBC IV */
  43642. + dwc_wusb_aes_encrypt(block_m, key, block_x);
  43643. + show_block(block_m, "CBC IV in: ", "\n", 0);
  43644. + show_block(block_x, "CBC IV out:", "\n", 0);
  43645. +
  43646. + /* Fill block B1 from l(a) = Blen + 14, and A */
  43647. + block_x[0] ^= (u8)(la >> 8);
  43648. + block_x[1] ^= (u8)la;
  43649. + for (idx = 0; idx < 14; idx++)
  43650. + block_x[idx + 2] ^= label[idx];
  43651. + show_block(block_x, "After xor: ", "b1\n", 16);
  43652. +
  43653. + dwc_wusb_aes_encrypt(block_x, key, block_x);
  43654. + show_block(block_x, "After AES: ", "b1\n", 16);
  43655. +
  43656. + idx = 0;
  43657. + blkNum = 0;
  43658. +
  43659. + /* Fill remaining blocks with B */
  43660. + while (len-- > 0) {
  43661. + block_x[idx] ^= *bytes++;
  43662. + if (++idx >= 16) {
  43663. + idx = 0;
  43664. + show_block(block_x, "After xor: ", "\n", blkNum);
  43665. + dwc_wusb_aes_encrypt(block_x, key, block_x);
  43666. + show_block(block_x, "After AES: ", "\n", blkNum);
  43667. + blkNum++;
  43668. + }
  43669. + }
  43670. +
  43671. + /* Handle partial last block */
  43672. + if (idx > 0) {
  43673. + show_block(block_x, "After xor: ", "\n", blkNum);
  43674. + dwc_wusb_aes_encrypt(block_x, key, block_x);
  43675. + show_block(block_x, "After AES: ", "\n", blkNum);
  43676. + }
  43677. +
  43678. + /* Save the MIC tag */
  43679. + DWC_MEMCPY(block_t, block_x, 8);
  43680. + show_block(block_t, "MIC tag : ", NULL, 8);
  43681. +
  43682. + /* Fill block A0 from flags = 0x01, N, and counter = 0 */
  43683. + block_m[0] = 0x01;
  43684. + block_m[14] = 0;
  43685. + block_m[15] = 0;
  43686. +
  43687. + /* Encrypt the counter */
  43688. + dwc_wusb_aes_encrypt(block_m, key, block_x);
  43689. + show_block(block_x, "CTR[MIC] : ", NULL, 8);
  43690. +
  43691. + /* XOR with MIC tag */
  43692. + for (idx = 0; idx < 8; idx++) {
  43693. + block_t[idx] ^= block_x[idx];
  43694. + }
  43695. +
  43696. + /* Return result to caller */
  43697. + DWC_MEMCPY(result, block_t, 8);
  43698. + show_block(result, "CCM-MIC : ", NULL, 8);
  43699. +
  43700. +}
  43701. +
  43702. +/**
  43703. + * The PRF function described in section 6.5 of the WUSB spec. This function
  43704. + * concatenates MIC values returned from dwc_cmf() to create a value of
  43705. + * the requested length.
  43706. + *
  43707. + * @param prf_len Length of the PRF function in bits (64, 128, or 256).
  43708. + * @param key, nonce, label, bytes, len Same as for dwc_cmf().
  43709. + * @param result Byte array to receive the result.
  43710. + */
  43711. +void dwc_wusb_prf(int prf_len, u8 *key,
  43712. + u8 *nonce, char *label, u8 *bytes, int len, u8 *result)
  43713. +{
  43714. + int i;
  43715. +
  43716. + nonce[0] = 0;
  43717. + for (i = 0; i < prf_len >> 6; i++, nonce[0]++) {
  43718. + dwc_wusb_cmf(key, nonce, label, bytes, len, result);
  43719. + result += 8;
  43720. + }
  43721. +}
  43722. +
  43723. +/**
  43724. + * Fills in CCM Nonce per the WUSB spec.
  43725. + *
  43726. + * @param[in] haddr Host address.
  43727. + * @param[in] daddr Device address.
  43728. + * @param[in] tkid Session Key(PTK) identifier.
  43729. + * @param[out] nonce Pointer to where the CCM Nonce output is to be written.
  43730. + */
  43731. +void dwc_wusb_fill_ccm_nonce(uint16_t haddr, uint16_t daddr, uint8_t *tkid,
  43732. + uint8_t *nonce)
  43733. +{
  43734. +
  43735. + DWC_DEBUG("%s %x %x\n", __func__, daddr, haddr);
  43736. +
  43737. + DWC_MEMSET(&nonce[0], 0, 16);
  43738. +
  43739. + DWC_MEMCPY(&nonce[6], tkid, 3);
  43740. + nonce[9] = daddr & 0xFF;
  43741. + nonce[10] = (daddr >> 8) & 0xFF;
  43742. + nonce[11] = haddr & 0xFF;
  43743. + nonce[12] = (haddr >> 8) & 0xFF;
  43744. +
  43745. + dump_bytes("CCM nonce", nonce, 16);
  43746. +}
  43747. +
  43748. +/**
  43749. + * Generates a 16-byte cryptographic-grade random number for the Host/Device
  43750. + * Nonce.
  43751. + */
  43752. +void dwc_wusb_gen_nonce(uint16_t addr, uint8_t *nonce)
  43753. +{
  43754. + uint8_t inonce[16];
  43755. + uint32_t temp[4];
  43756. +
  43757. + /* Fill in the Nonce */
  43758. + DWC_MEMSET(&inonce[0], 0, sizeof(inonce));
  43759. + inonce[9] = addr & 0xFF;
  43760. + inonce[10] = (addr >> 8) & 0xFF;
  43761. + inonce[11] = inonce[9];
  43762. + inonce[12] = inonce[10];
  43763. +
  43764. + /* Collect "randomness samples" */
  43765. + DWC_RANDOM_BYTES((uint8_t *)temp, 16);
  43766. +
  43767. + dwc_wusb_prf_128((uint8_t *)temp, nonce,
  43768. + "Random Numbers", (uint8_t *)temp, sizeof(temp),
  43769. + nonce);
  43770. +}
  43771. +
  43772. +/**
  43773. + * Generates the Session Key (PTK) and Key Confirmation Key (KCK) per the
  43774. + * WUSB spec.
  43775. + *
  43776. + * @param[in] ccm_nonce Pointer to CCM Nonce.
  43777. + * @param[in] mk Master Key to derive the session from
  43778. + * @param[in] hnonce Pointer to Host Nonce.
  43779. + * @param[in] dnonce Pointer to Device Nonce.
  43780. + * @param[out] kck Pointer to where the KCK output is to be written.
  43781. + * @param[out] ptk Pointer to where the PTK output is to be written.
  43782. + */
  43783. +void dwc_wusb_gen_key(uint8_t *ccm_nonce, uint8_t *mk, uint8_t *hnonce,
  43784. + uint8_t *dnonce, uint8_t *kck, uint8_t *ptk)
  43785. +{
  43786. + uint8_t idata[32];
  43787. + uint8_t odata[32];
  43788. +
  43789. + dump_bytes("ck", mk, 16);
  43790. + dump_bytes("hnonce", hnonce, 16);
  43791. + dump_bytes("dnonce", dnonce, 16);
  43792. +
  43793. + /* The data is the HNonce and DNonce concatenated */
  43794. + DWC_MEMCPY(&idata[0], hnonce, 16);
  43795. + DWC_MEMCPY(&idata[16], dnonce, 16);
  43796. +
  43797. + dwc_wusb_prf_256(mk, ccm_nonce, "Pair-wise keys", idata, 32, odata);
  43798. +
  43799. + /* Low 16 bytes of the result is the KCK, high 16 is the PTK */
  43800. + DWC_MEMCPY(kck, &odata[0], 16);
  43801. + DWC_MEMCPY(ptk, &odata[16], 16);
  43802. +
  43803. + dump_bytes("kck", kck, 16);
  43804. + dump_bytes("ptk", ptk, 16);
  43805. +}
  43806. +
  43807. +/**
  43808. + * Generates the Message Integrity Code over the Handshake data per the
  43809. + * WUSB spec.
  43810. + *
  43811. + * @param ccm_nonce Pointer to CCM Nonce.
  43812. + * @param kck Pointer to Key Confirmation Key.
  43813. + * @param data Pointer to Handshake data to be checked.
  43814. + * @param mic Pointer to where the MIC output is to be written.
  43815. + */
  43816. +void dwc_wusb_gen_mic(uint8_t *ccm_nonce, uint8_t *kck,
  43817. + uint8_t *data, uint8_t *mic)
  43818. +{
  43819. +
  43820. + dwc_wusb_prf_64(kck, ccm_nonce, "out-of-bandMIC",
  43821. + data, WUSB_HANDSHAKE_LEN_FOR_MIC, mic);
  43822. +}
  43823. +
  43824. +#endif /* DWC_CRYPTOLIB */
  43825. diff -Nur linux-3.13.11/drivers/usb/host/dwc_common_port/dwc_crypto.h linux-rpi/drivers/usb/host/dwc_common_port/dwc_crypto.h
  43826. --- linux-3.13.11/drivers/usb/host/dwc_common_port/dwc_crypto.h 1970-01-01 01:00:00.000000000 +0100
  43827. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_crypto.h 2014-04-24 15:35:04.169565731 +0200
  43828. @@ -0,0 +1,111 @@
  43829. +/* =========================================================================
  43830. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_crypto.h $
  43831. + * $Revision: #3 $
  43832. + * $Date: 2010/09/28 $
  43833. + * $Change: 1596182 $
  43834. + *
  43835. + * Synopsys Portability Library Software and documentation
  43836. + * (hereinafter, "Software") is an Unsupported proprietary work of
  43837. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  43838. + * between Synopsys and you.
  43839. + *
  43840. + * The Software IS NOT an item of Licensed Software or Licensed Product
  43841. + * under any End User Software License Agreement or Agreement for
  43842. + * Licensed Product with Synopsys or any supplement thereto. You are
  43843. + * permitted to use and redistribute this Software in source and binary
  43844. + * forms, with or without modification, provided that redistributions
  43845. + * of source code must retain this notice. You may not view, use,
  43846. + * disclose, copy or distribute this file or any information contained
  43847. + * herein except pursuant to this license grant from Synopsys. If you
  43848. + * do not agree with this notice, including the disclaimer below, then
  43849. + * you are not authorized to use the Software.
  43850. + *
  43851. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  43852. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  43853. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  43854. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  43855. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  43856. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  43857. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  43858. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  43859. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  43860. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  43861. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  43862. + * DAMAGE.
  43863. + * ========================================================================= */
  43864. +
  43865. +#ifndef _DWC_CRYPTO_H_
  43866. +#define _DWC_CRYPTO_H_
  43867. +
  43868. +#ifdef __cplusplus
  43869. +extern "C" {
  43870. +#endif
  43871. +
  43872. +/** @file
  43873. + *
  43874. + * This file contains declarations for the WUSB Cryptographic routines as
  43875. + * defined in the WUSB spec. They are only to be used internally by the DWC UWB
  43876. + * modules.
  43877. + */
  43878. +
  43879. +#include "dwc_os.h"
  43880. +
  43881. +int dwc_wusb_aes_encrypt(u8 *src, u8 *key, u8 *dst);
  43882. +
  43883. +void dwc_wusb_cmf(u8 *key, u8 *nonce,
  43884. + char *label, u8 *bytes, int len, u8 *result);
  43885. +void dwc_wusb_prf(int prf_len, u8 *key,
  43886. + u8 *nonce, char *label, u8 *bytes, int len, u8 *result);
  43887. +
  43888. +/**
  43889. + * The PRF-64 function described in section 6.5 of the WUSB spec.
  43890. + *
  43891. + * @param key, nonce, label, bytes, len, result Same as for dwc_prf().
  43892. + */
  43893. +static inline void dwc_wusb_prf_64(u8 *key, u8 *nonce,
  43894. + char *label, u8 *bytes, int len, u8 *result)
  43895. +{
  43896. + dwc_wusb_prf(64, key, nonce, label, bytes, len, result);
  43897. +}
  43898. +
  43899. +/**
  43900. + * The PRF-128 function described in section 6.5 of the WUSB spec.
  43901. + *
  43902. + * @param key, nonce, label, bytes, len, result Same as for dwc_prf().
  43903. + */
  43904. +static inline void dwc_wusb_prf_128(u8 *key, u8 *nonce,
  43905. + char *label, u8 *bytes, int len, u8 *result)
  43906. +{
  43907. + dwc_wusb_prf(128, key, nonce, label, bytes, len, result);
  43908. +}
  43909. +
  43910. +/**
  43911. + * The PRF-256 function described in section 6.5 of the WUSB spec.
  43912. + *
  43913. + * @param key, nonce, label, bytes, len, result Same as for dwc_prf().
  43914. + */
  43915. +static inline void dwc_wusb_prf_256(u8 *key, u8 *nonce,
  43916. + char *label, u8 *bytes, int len, u8 *result)
  43917. +{
  43918. + dwc_wusb_prf(256, key, nonce, label, bytes, len, result);
  43919. +}
  43920. +
  43921. +
  43922. +void dwc_wusb_fill_ccm_nonce(uint16_t haddr, uint16_t daddr, uint8_t *tkid,
  43923. + uint8_t *nonce);
  43924. +void dwc_wusb_gen_nonce(uint16_t addr,
  43925. + uint8_t *nonce);
  43926. +
  43927. +void dwc_wusb_gen_key(uint8_t *ccm_nonce, uint8_t *mk,
  43928. + uint8_t *hnonce, uint8_t *dnonce,
  43929. + uint8_t *kck, uint8_t *ptk);
  43930. +
  43931. +
  43932. +void dwc_wusb_gen_mic(uint8_t *ccm_nonce, uint8_t
  43933. + *kck, uint8_t *data, uint8_t *mic);
  43934. +
  43935. +#ifdef __cplusplus
  43936. +}
  43937. +#endif
  43938. +
  43939. +#endif /* _DWC_CRYPTO_H_ */
  43940. diff -Nur linux-3.13.11/drivers/usb/host/dwc_common_port/dwc_dh.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_dh.c
  43941. --- linux-3.13.11/drivers/usb/host/dwc_common_port/dwc_dh.c 1970-01-01 01:00:00.000000000 +0100
  43942. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_dh.c 2014-04-24 15:37:13.306990445 +0200
  43943. @@ -0,0 +1,291 @@
  43944. +/* =========================================================================
  43945. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_dh.c $
  43946. + * $Revision: #3 $
  43947. + * $Date: 2010/09/28 $
  43948. + * $Change: 1596182 $
  43949. + *
  43950. + * Synopsys Portability Library Software and documentation
  43951. + * (hereinafter, "Software") is an Unsupported proprietary work of
  43952. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  43953. + * between Synopsys and you.
  43954. + *
  43955. + * The Software IS NOT an item of Licensed Software or Licensed Product
  43956. + * under any End User Software License Agreement or Agreement for
  43957. + * Licensed Product with Synopsys or any supplement thereto. You are
  43958. + * permitted to use and redistribute this Software in source and binary
  43959. + * forms, with or without modification, provided that redistributions
  43960. + * of source code must retain this notice. You may not view, use,
  43961. + * disclose, copy or distribute this file or any information contained
  43962. + * herein except pursuant to this license grant from Synopsys. If you
  43963. + * do not agree with this notice, including the disclaimer below, then
  43964. + * you are not authorized to use the Software.
  43965. + *
  43966. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  43967. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  43968. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  43969. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  43970. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  43971. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  43972. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  43973. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  43974. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  43975. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  43976. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  43977. + * DAMAGE.
  43978. + * ========================================================================= */
  43979. +#ifdef DWC_CRYPTOLIB
  43980. +
  43981. +#ifndef CONFIG_MACH_IPMATE
  43982. +
  43983. +#include "dwc_dh.h"
  43984. +#include "dwc_modpow.h"
  43985. +
  43986. +#ifdef DEBUG
  43987. +/* This function prints out a buffer in the format described in the Association
  43988. + * Model specification. */
  43989. +static void dh_dump(char *str, void *_num, int len)
  43990. +{
  43991. + uint8_t *num = _num;
  43992. + int i;
  43993. + DWC_PRINTF("%s\n", str);
  43994. + for (i = 0; i < len; i ++) {
  43995. + DWC_PRINTF("%02x", num[i]);
  43996. + if (((i + 1) % 2) == 0) DWC_PRINTF(" ");
  43997. + if (((i + 1) % 26) == 0) DWC_PRINTF("\n");
  43998. + }
  43999. +
  44000. + DWC_PRINTF("\n");
  44001. +}
  44002. +#else
  44003. +#define dh_dump(_x...) do {; } while(0)
  44004. +#endif
  44005. +
  44006. +/* Constant g value */
  44007. +static __u32 dh_g[] = {
  44008. + 0x02000000,
  44009. +};
  44010. +
  44011. +/* Constant p value */
  44012. +static __u32 dh_p[] = {
  44013. + 0xFFFFFFFF, 0xFFFFFFFF, 0xA2DA0FC9, 0x34C26821, 0x8B62C6C4, 0xD11CDC80, 0x084E0229, 0x74CC678A,
  44014. + 0xA6BE0B02, 0x229B133B, 0x79084A51, 0xDD04348E, 0xB31995EF, 0x1B433ACD, 0x6D0A2B30, 0x37145FF2,
  44015. + 0x6D35E14F, 0x45C2516D, 0x76B585E4, 0xC67E5E62, 0xE9424CF4, 0x6BED37A6, 0xB65CFF0B, 0xEDB706F4,
  44016. + 0xFB6B38EE, 0xA59F895A, 0x11249FAE, 0xE61F4B7C, 0x51662849, 0x3D5BE4EC, 0xB87C00C2, 0x05BF63A1,
  44017. + 0x3648DA98, 0x9AD3551C, 0xA83F1669, 0x5FCF24FD, 0x235D6583, 0x96ADA3DC, 0x56F3621C, 0xBB528520,
  44018. + 0x0729D59E, 0x6D969670, 0x4E350C67, 0x0498BC4A, 0x086C74F1, 0x7C2118CA, 0x465E9032, 0x3BCE362E,
  44019. + 0x2C779EE3, 0x03860E18, 0xA283279B, 0x8FA207EC, 0xF05DC5B5, 0xC9524C6F, 0xF6CB2BDE, 0x18175895,
  44020. + 0x7C499539, 0xE56A95EA, 0x1826D215, 0x1005FA98, 0x5A8E7215, 0x2DC4AA8A, 0x0D1733AD, 0x337A5004,
  44021. + 0xAB2155A8, 0x64BA1CDF, 0x0485FBEC, 0x0AEFDB58, 0x5771EA8A, 0x7D0C065D, 0x850F97B3, 0xC7E4E1A6,
  44022. + 0x8CAEF5AB, 0xD73309DB, 0xE0948C1E, 0x9D61254A, 0x26D2E3CE, 0x6BEED21A, 0x06FA2FF1, 0x64088AD9,
  44023. + 0x730276D8, 0x646AC83E, 0x182B1F52, 0x0C207B17, 0x5717E1BB, 0x6C5D617A, 0xC0880977, 0xE246D9BA,
  44024. + 0xA04FE208, 0x31ABE574, 0xFC5BDB43, 0x8E10FDE0, 0x20D1824B, 0xCAD23AA9, 0xFFFFFFFF, 0xFFFFFFFF,
  44025. +};
  44026. +
  44027. +static void dh_swap_bytes(void *_in, void *_out, uint32_t len)
  44028. +{
  44029. + uint8_t *in = _in;
  44030. + uint8_t *out = _out;
  44031. + int i;
  44032. + for (i=0; i<len; i++) {
  44033. + out[i] = in[len-1-i];
  44034. + }
  44035. +}
  44036. +
  44037. +/* Computes the modular exponentiation (num^exp % mod). num, exp, and mod are
  44038. + * big endian numbers of size len, in bytes. Each len value must be a multiple
  44039. + * of 4. */
  44040. +int dwc_dh_modpow(void *mem_ctx, void *num, uint32_t num_len,
  44041. + void *exp, uint32_t exp_len,
  44042. + void *mod, uint32_t mod_len,
  44043. + void *out)
  44044. +{
  44045. + /* modpow() takes little endian numbers. AM uses big-endian. This
  44046. + * function swaps bytes of numbers before passing onto modpow. */
  44047. +
  44048. + int retval = 0;
  44049. + uint32_t *result;
  44050. +
  44051. + uint32_t *bignum_num = dwc_alloc(mem_ctx, num_len + 4);
  44052. + uint32_t *bignum_exp = dwc_alloc(mem_ctx, exp_len + 4);
  44053. + uint32_t *bignum_mod = dwc_alloc(mem_ctx, mod_len + 4);
  44054. +
  44055. + dh_swap_bytes(num, &bignum_num[1], num_len);
  44056. + bignum_num[0] = num_len / 4;
  44057. +
  44058. + dh_swap_bytes(exp, &bignum_exp[1], exp_len);
  44059. + bignum_exp[0] = exp_len / 4;
  44060. +
  44061. + dh_swap_bytes(mod, &bignum_mod[1], mod_len);
  44062. + bignum_mod[0] = mod_len / 4;
  44063. +
  44064. + result = dwc_modpow(mem_ctx, bignum_num, bignum_exp, bignum_mod);
  44065. + if (!result) {
  44066. + retval = -1;
  44067. + goto dh_modpow_nomem;
  44068. + }
  44069. +
  44070. + dh_swap_bytes(&result[1], out, result[0] * 4);
  44071. + dwc_free(mem_ctx, result);
  44072. +
  44073. + dh_modpow_nomem:
  44074. + dwc_free(mem_ctx, bignum_num);
  44075. + dwc_free(mem_ctx, bignum_exp);
  44076. + dwc_free(mem_ctx, bignum_mod);
  44077. + return retval;
  44078. +}
  44079. +
  44080. +
  44081. +int dwc_dh_pk(void *mem_ctx, uint8_t nd, uint8_t *exp, uint8_t *pk, uint8_t *hash)
  44082. +{
  44083. + int retval;
  44084. + uint8_t m3[385];
  44085. +
  44086. +#ifndef DH_TEST_VECTORS
  44087. + DWC_RANDOM_BYTES(exp, 32);
  44088. +#endif
  44089. +
  44090. + /* Compute the pkd */
  44091. + if ((retval = dwc_dh_modpow(mem_ctx, dh_g, 4,
  44092. + exp, 32,
  44093. + dh_p, 384, pk))) {
  44094. + return retval;
  44095. + }
  44096. +
  44097. + m3[384] = nd;
  44098. + DWC_MEMCPY(&m3[0], pk, 384);
  44099. + DWC_SHA256(m3, 385, hash);
  44100. +
  44101. + dh_dump("PK", pk, 384);
  44102. + dh_dump("SHA-256(M3)", hash, 32);
  44103. + return 0;
  44104. +}
  44105. +
  44106. +int dwc_dh_derive_keys(void *mem_ctx, uint8_t nd, uint8_t *pkh, uint8_t *pkd,
  44107. + uint8_t *exp, int is_host,
  44108. + char *dd, uint8_t *ck, uint8_t *kdk)
  44109. +{
  44110. + int retval;
  44111. + uint8_t mv[784];
  44112. + uint8_t sha_result[32];
  44113. + uint8_t dhkey[384];
  44114. + uint8_t shared_secret[384];
  44115. + char *message;
  44116. + uint32_t vd;
  44117. +
  44118. + uint8_t *pk;
  44119. +
  44120. + if (is_host) {
  44121. + pk = pkd;
  44122. + }
  44123. + else {
  44124. + pk = pkh;
  44125. + }
  44126. +
  44127. + if ((retval = dwc_dh_modpow(mem_ctx, pk, 384,
  44128. + exp, 32,
  44129. + dh_p, 384, shared_secret))) {
  44130. + return retval;
  44131. + }
  44132. + dh_dump("Shared Secret", shared_secret, 384);
  44133. +
  44134. + DWC_SHA256(shared_secret, 384, dhkey);
  44135. + dh_dump("DHKEY", dhkey, 384);
  44136. +
  44137. + DWC_MEMCPY(&mv[0], pkd, 384);
  44138. + DWC_MEMCPY(&mv[384], pkh, 384);
  44139. + DWC_MEMCPY(&mv[768], "displayed digest", 16);
  44140. + dh_dump("MV", mv, 784);
  44141. +
  44142. + DWC_SHA256(mv, 784, sha_result);
  44143. + dh_dump("SHA-256(MV)", sha_result, 32);
  44144. + dh_dump("First 32-bits of SHA-256(MV)", sha_result, 4);
  44145. +
  44146. + dh_swap_bytes(sha_result, &vd, 4);
  44147. +#ifdef DEBUG
  44148. + DWC_PRINTF("Vd (decimal) = %d\n", vd);
  44149. +#endif
  44150. +
  44151. + switch (nd) {
  44152. + case 2:
  44153. + vd = vd % 100;
  44154. + DWC_SPRINTF(dd, "%02d", vd);
  44155. + break;
  44156. + case 3:
  44157. + vd = vd % 1000;
  44158. + DWC_SPRINTF(dd, "%03d", vd);
  44159. + break;
  44160. + case 4:
  44161. + vd = vd % 10000;
  44162. + DWC_SPRINTF(dd, "%04d", vd);
  44163. + break;
  44164. + }
  44165. +#ifdef DEBUG
  44166. + DWC_PRINTF("Display Digits: %s\n", dd);
  44167. +#endif
  44168. +
  44169. + message = "connection key";
  44170. + DWC_HMAC_SHA256(message, DWC_STRLEN(message), dhkey, 32, sha_result);
  44171. + dh_dump("HMAC(SHA-256, DHKey, connection key)", sha_result, 32);
  44172. + DWC_MEMCPY(ck, sha_result, 16);
  44173. +
  44174. + message = "key derivation key";
  44175. + DWC_HMAC_SHA256(message, DWC_STRLEN(message), dhkey, 32, sha_result);
  44176. + dh_dump("HMAC(SHA-256, DHKey, key derivation key)", sha_result, 32);
  44177. + DWC_MEMCPY(kdk, sha_result, 32);
  44178. +
  44179. + return 0;
  44180. +}
  44181. +
  44182. +
  44183. +#ifdef DH_TEST_VECTORS
  44184. +
  44185. +static __u8 dh_a[] = {
  44186. + 0x44, 0x00, 0x51, 0xd6,
  44187. + 0xf0, 0xb5, 0x5e, 0xa9,
  44188. + 0x67, 0xab, 0x31, 0xc6,
  44189. + 0x8a, 0x8b, 0x5e, 0x37,
  44190. + 0xd9, 0x10, 0xda, 0xe0,
  44191. + 0xe2, 0xd4, 0x59, 0xa4,
  44192. + 0x86, 0x45, 0x9c, 0xaa,
  44193. + 0xdf, 0x36, 0x75, 0x16,
  44194. +};
  44195. +
  44196. +static __u8 dh_b[] = {
  44197. + 0x5d, 0xae, 0xc7, 0x86,
  44198. + 0x79, 0x80, 0xa3, 0x24,
  44199. + 0x8c, 0xe3, 0x57, 0x8f,
  44200. + 0xc7, 0x5f, 0x1b, 0x0f,
  44201. + 0x2d, 0xf8, 0x9d, 0x30,
  44202. + 0x6f, 0xa4, 0x52, 0xcd,
  44203. + 0xe0, 0x7a, 0x04, 0x8a,
  44204. + 0xde, 0xd9, 0x26, 0x56,
  44205. +};
  44206. +
  44207. +void dwc_run_dh_test_vectors(void *mem_ctx)
  44208. +{
  44209. + uint8_t pkd[384];
  44210. + uint8_t pkh[384];
  44211. + uint8_t hashd[32];
  44212. + uint8_t hashh[32];
  44213. + uint8_t ck[16];
  44214. + uint8_t kdk[32];
  44215. + char dd[5];
  44216. +
  44217. + DWC_PRINTF("\n\n\nDH_TEST_VECTORS\n\n");
  44218. +
  44219. + /* compute the PKd and SHA-256(PKd || Nd) */
  44220. + DWC_PRINTF("Computing PKd\n");
  44221. + dwc_dh_pk(mem_ctx, 2, dh_a, pkd, hashd);
  44222. +
  44223. + /* compute the PKd and SHA-256(PKh || Nd) */
  44224. + DWC_PRINTF("Computing PKh\n");
  44225. + dwc_dh_pk(mem_ctx, 2, dh_b, pkh, hashh);
  44226. +
  44227. + /* compute the dhkey */
  44228. + dwc_dh_derive_keys(mem_ctx, 2, pkh, pkd, dh_a, 0, dd, ck, kdk);
  44229. +}
  44230. +#endif /* DH_TEST_VECTORS */
  44231. +
  44232. +#endif /* !CONFIG_MACH_IPMATE */
  44233. +
  44234. +#endif /* DWC_CRYPTOLIB */
  44235. diff -Nur linux-3.13.11/drivers/usb/host/dwc_common_port/dwc_dh.h linux-rpi/drivers/usb/host/dwc_common_port/dwc_dh.h
  44236. --- linux-3.13.11/drivers/usb/host/dwc_common_port/dwc_dh.h 1970-01-01 01:00:00.000000000 +0100
  44237. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_dh.h 2014-04-24 15:35:04.169565731 +0200
  44238. @@ -0,0 +1,106 @@
  44239. +/* =========================================================================
  44240. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_dh.h $
  44241. + * $Revision: #4 $
  44242. + * $Date: 2010/09/28 $
  44243. + * $Change: 1596182 $
  44244. + *
  44245. + * Synopsys Portability Library Software and documentation
  44246. + * (hereinafter, "Software") is an Unsupported proprietary work of
  44247. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  44248. + * between Synopsys and you.
  44249. + *
  44250. + * The Software IS NOT an item of Licensed Software or Licensed Product
  44251. + * under any End User Software License Agreement or Agreement for
  44252. + * Licensed Product with Synopsys or any supplement thereto. You are
  44253. + * permitted to use and redistribute this Software in source and binary
  44254. + * forms, with or without modification, provided that redistributions
  44255. + * of source code must retain this notice. You may not view, use,
  44256. + * disclose, copy or distribute this file or any information contained
  44257. + * herein except pursuant to this license grant from Synopsys. If you
  44258. + * do not agree with this notice, including the disclaimer below, then
  44259. + * you are not authorized to use the Software.
  44260. + *
  44261. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  44262. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  44263. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  44264. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  44265. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  44266. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  44267. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  44268. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  44269. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  44270. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  44271. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  44272. + * DAMAGE.
  44273. + * ========================================================================= */
  44274. +#ifndef _DWC_DH_H_
  44275. +#define _DWC_DH_H_
  44276. +
  44277. +#ifdef __cplusplus
  44278. +extern "C" {
  44279. +#endif
  44280. +
  44281. +#include "dwc_os.h"
  44282. +
  44283. +/** @file
  44284. + *
  44285. + * This file defines the common functions on device and host for performing
  44286. + * numeric association as defined in the WUSB spec. They are only to be
  44287. + * used internally by the DWC UWB modules. */
  44288. +
  44289. +extern int dwc_dh_sha256(uint8_t *message, uint32_t len, uint8_t *out);
  44290. +extern int dwc_dh_hmac_sha256(uint8_t *message, uint32_t messagelen,
  44291. + uint8_t *key, uint32_t keylen,
  44292. + uint8_t *out);
  44293. +extern int dwc_dh_modpow(void *mem_ctx, void *num, uint32_t num_len,
  44294. + void *exp, uint32_t exp_len,
  44295. + void *mod, uint32_t mod_len,
  44296. + void *out);
  44297. +
  44298. +/** Computes PKD or PKH, and SHA-256(PKd || Nd)
  44299. + *
  44300. + * PK = g^exp mod p.
  44301. + *
  44302. + * Input:
  44303. + * Nd = Number of digits on the device.
  44304. + *
  44305. + * Output:
  44306. + * exp = A 32-byte buffer to be filled with a randomly generated number.
  44307. + * used as either A or B.
  44308. + * pk = A 384-byte buffer to be filled with the PKH or PKD.
  44309. + * hash = A 32-byte buffer to be filled with SHA-256(PK || ND).
  44310. + */
  44311. +extern int dwc_dh_pk(void *mem_ctx, uint8_t nd, uint8_t *exp, uint8_t *pkd, uint8_t *hash);
  44312. +
  44313. +/** Computes the DHKEY, and VD.
  44314. + *
  44315. + * If called from host, then it will comput DHKEY=PKD^exp % p.
  44316. + * If called from device, then it will comput DHKEY=PKH^exp % p.
  44317. + *
  44318. + * Input:
  44319. + * pkd = The PKD value.
  44320. + * pkh = The PKH value.
  44321. + * exp = The A value (if device) or B value (if host) generated in dwc_wudev_dh_pk.
  44322. + * is_host = Set to non zero if a WUSB host is calling this function.
  44323. + *
  44324. + * Output:
  44325. +
  44326. + * dd = A pointer to an buffer to be set to the displayed digits string to be shown
  44327. + * to the user. This buffer should be at 5 bytes long to hold 4 digits plus a
  44328. + * null termination character. This buffer can be used directly for display.
  44329. + * ck = A 16-byte buffer to be filled with the CK.
  44330. + * kdk = A 32-byte buffer to be filled with the KDK.
  44331. + */
  44332. +extern int dwc_dh_derive_keys(void *mem_ctx, uint8_t nd, uint8_t *pkh, uint8_t *pkd,
  44333. + uint8_t *exp, int is_host,
  44334. + char *dd, uint8_t *ck, uint8_t *kdk);
  44335. +
  44336. +#ifdef DH_TEST_VECTORS
  44337. +extern void dwc_run_dh_test_vectors(void);
  44338. +#endif
  44339. +
  44340. +#ifdef __cplusplus
  44341. +}
  44342. +#endif
  44343. +
  44344. +#endif /* _DWC_DH_H_ */
  44345. diff -Nur linux-3.13.11/drivers/usb/host/dwc_common_port/dwc_list.h linux-rpi/drivers/usb/host/dwc_common_port/dwc_list.h
  44346. --- linux-3.13.11/drivers/usb/host/dwc_common_port/dwc_list.h 1970-01-01 01:00:00.000000000 +0100
  44347. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_list.h 2014-04-24 15:35:04.169565731 +0200
  44348. @@ -0,0 +1,594 @@
  44349. +/* $OpenBSD: queue.h,v 1.26 2004/05/04 16:59:32 grange Exp $ */
  44350. +/* $NetBSD: queue.h,v 1.11 1996/05/16 05:17:14 mycroft Exp $ */
  44351. +
  44352. +/*
  44353. + * Copyright (c) 1991, 1993
  44354. + * The Regents of the University of California. All rights reserved.
  44355. + *
  44356. + * Redistribution and use in source and binary forms, with or without
  44357. + * modification, are permitted provided that the following conditions
  44358. + * are met:
  44359. + * 1. Redistributions of source code must retain the above copyright
  44360. + * notice, this list of conditions and the following disclaimer.
  44361. + * 2. Redistributions in binary form must reproduce the above copyright
  44362. + * notice, this list of conditions and the following disclaimer in the
  44363. + * documentation and/or other materials provided with the distribution.
  44364. + * 3. Neither the name of the University nor the names of its contributors
  44365. + * may be used to endorse or promote products derived from this software
  44366. + * without specific prior written permission.
  44367. + *
  44368. + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  44369. + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  44370. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  44371. + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  44372. + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  44373. + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  44374. + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  44375. + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  44376. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  44377. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  44378. + * SUCH DAMAGE.
  44379. + *
  44380. + * @(#)queue.h 8.5 (Berkeley) 8/20/94
  44381. + */
  44382. +
  44383. +#ifndef _DWC_LIST_H_
  44384. +#define _DWC_LIST_H_
  44385. +
  44386. +#ifdef __cplusplus
  44387. +extern "C" {
  44388. +#endif
  44389. +
  44390. +/** @file
  44391. + *
  44392. + * This file defines linked list operations. It is derived from BSD with
  44393. + * only the MACRO names being prefixed with DWC_. This is because a few of
  44394. + * these names conflict with those on Linux. For documentation on use, see the
  44395. + * inline comments in the source code. The original license for this source
  44396. + * code applies and is preserved in the dwc_list.h source file.
  44397. + */
  44398. +
  44399. +/*
  44400. + * This file defines five types of data structures: singly-linked lists,
  44401. + * lists, simple queues, tail queues, and circular queues.
  44402. + *
  44403. + *
  44404. + * A singly-linked list is headed by a single forward pointer. The elements
  44405. + * are singly linked for minimum space and pointer manipulation overhead at
  44406. + * the expense of O(n) removal for arbitrary elements. New elements can be
  44407. + * added to the list after an existing element or at the head of the list.
  44408. + * Elements being removed from the head of the list should use the explicit
  44409. + * macro for this purpose for optimum efficiency. A singly-linked list may
  44410. + * only be traversed in the forward direction. Singly-linked lists are ideal
  44411. + * for applications with large datasets and few or no removals or for
  44412. + * implementing a LIFO queue.
  44413. + *
  44414. + * A list is headed by a single forward pointer (or an array of forward
  44415. + * pointers for a hash table header). The elements are doubly linked
  44416. + * so that an arbitrary element can be removed without a need to
  44417. + * traverse the list. New elements can be added to the list before
  44418. + * or after an existing element or at the head of the list. A list
  44419. + * may only be traversed in the forward direction.
  44420. + *
  44421. + * A simple queue is headed by a pair of pointers, one the head of the
  44422. + * list and the other to the tail of the list. The elements are singly
  44423. + * linked to save space, so elements can only be removed from the
  44424. + * head of the list. New elements can be added to the list before or after
  44425. + * an existing element, at the head of the list, or at the end of the
  44426. + * list. A simple queue may only be traversed in the forward direction.
  44427. + *
  44428. + * A tail queue is headed by a pair of pointers, one to the head of the
  44429. + * list and the other to the tail of the list. The elements are doubly
  44430. + * linked so that an arbitrary element can be removed without a need to
  44431. + * traverse the list. New elements can be added to the list before or
  44432. + * after an existing element, at the head of the list, or at the end of
  44433. + * the list. A tail queue may be traversed in either direction.
  44434. + *
  44435. + * A circle queue is headed by a pair of pointers, one to the head of the
  44436. + * list and the other to the tail of the list. The elements are doubly
  44437. + * linked so that an arbitrary element can be removed without a need to
  44438. + * traverse the list. New elements can be added to the list before or after
  44439. + * an existing element, at the head of the list, or at the end of the list.
  44440. + * A circle queue may be traversed in either direction, but has a more
  44441. + * complex end of list detection.
  44442. + *
  44443. + * For details on the use of these macros, see the queue(3) manual page.
  44444. + */
  44445. +
  44446. +/*
  44447. + * Double-linked List.
  44448. + */
  44449. +
  44450. +typedef struct dwc_list_link {
  44451. + struct dwc_list_link *next;
  44452. + struct dwc_list_link *prev;
  44453. +} dwc_list_link_t;
  44454. +
  44455. +#define DWC_LIST_INIT(link) do { \
  44456. + (link)->next = (link); \
  44457. + (link)->prev = (link); \
  44458. +} while (0)
  44459. +
  44460. +#define DWC_LIST_FIRST(link) ((link)->next)
  44461. +#define DWC_LIST_LAST(link) ((link)->prev)
  44462. +#define DWC_LIST_END(link) (link)
  44463. +#define DWC_LIST_NEXT(link) ((link)->next)
  44464. +#define DWC_LIST_PREV(link) ((link)->prev)
  44465. +#define DWC_LIST_EMPTY(link) \
  44466. + (DWC_LIST_FIRST(link) == DWC_LIST_END(link))
  44467. +#define DWC_LIST_ENTRY(link, type, field) \
  44468. + (type *)((uint8_t *)(link) - (size_t)(&((type *)0)->field))
  44469. +
  44470. +#if 0
  44471. +#define DWC_LIST_INSERT_HEAD(list, link) do { \
  44472. + (link)->next = (list)->next; \
  44473. + (link)->prev = (list); \
  44474. + (list)->next->prev = (link); \
  44475. + (list)->next = (link); \
  44476. +} while (0)
  44477. +
  44478. +#define DWC_LIST_INSERT_TAIL(list, link) do { \
  44479. + (link)->next = (list); \
  44480. + (link)->prev = (list)->prev; \
  44481. + (list)->prev->next = (link); \
  44482. + (list)->prev = (link); \
  44483. +} while (0)
  44484. +#else
  44485. +#define DWC_LIST_INSERT_HEAD(list, link) do { \
  44486. + dwc_list_link_t *__next__ = (list)->next; \
  44487. + __next__->prev = (link); \
  44488. + (link)->next = __next__; \
  44489. + (link)->prev = (list); \
  44490. + (list)->next = (link); \
  44491. +} while (0)
  44492. +
  44493. +#define DWC_LIST_INSERT_TAIL(list, link) do { \
  44494. + dwc_list_link_t *__prev__ = (list)->prev; \
  44495. + (list)->prev = (link); \
  44496. + (link)->next = (list); \
  44497. + (link)->prev = __prev__; \
  44498. + __prev__->next = (link); \
  44499. +} while (0)
  44500. +#endif
  44501. +
  44502. +#if 0
  44503. +static inline void __list_add(struct list_head *new,
  44504. + struct list_head *prev,
  44505. + struct list_head *next)
  44506. +{
  44507. + next->prev = new;
  44508. + new->next = next;
  44509. + new->prev = prev;
  44510. + prev->next = new;
  44511. +}
  44512. +
  44513. +static inline void list_add(struct list_head *new, struct list_head *head)
  44514. +{
  44515. + __list_add(new, head, head->next);
  44516. +}
  44517. +
  44518. +static inline void list_add_tail(struct list_head *new, struct list_head *head)
  44519. +{
  44520. + __list_add(new, head->prev, head);
  44521. +}
  44522. +
  44523. +static inline void __list_del(struct list_head * prev, struct list_head * next)
  44524. +{
  44525. + next->prev = prev;
  44526. + prev->next = next;
  44527. +}
  44528. +
  44529. +static inline void list_del(struct list_head *entry)
  44530. +{
  44531. + __list_del(entry->prev, entry->next);
  44532. + entry->next = LIST_POISON1;
  44533. + entry->prev = LIST_POISON2;
  44534. +}
  44535. +#endif
  44536. +
  44537. +#define DWC_LIST_REMOVE(link) do { \
  44538. + (link)->next->prev = (link)->prev; \
  44539. + (link)->prev->next = (link)->next; \
  44540. +} while (0)
  44541. +
  44542. +#define DWC_LIST_REMOVE_INIT(link) do { \
  44543. + DWC_LIST_REMOVE(link); \
  44544. + DWC_LIST_INIT(link); \
  44545. +} while (0)
  44546. +
  44547. +#define DWC_LIST_MOVE_HEAD(list, link) do { \
  44548. + DWC_LIST_REMOVE(link); \
  44549. + DWC_LIST_INSERT_HEAD(list, link); \
  44550. +} while (0)
  44551. +
  44552. +#define DWC_LIST_MOVE_TAIL(list, link) do { \
  44553. + DWC_LIST_REMOVE(link); \
  44554. + DWC_LIST_INSERT_TAIL(list, link); \
  44555. +} while (0)
  44556. +
  44557. +#define DWC_LIST_FOREACH(var, list) \
  44558. + for((var) = DWC_LIST_FIRST(list); \
  44559. + (var) != DWC_LIST_END(list); \
  44560. + (var) = DWC_LIST_NEXT(var))
  44561. +
  44562. +#define DWC_LIST_FOREACH_SAFE(var, var2, list) \
  44563. + for((var) = DWC_LIST_FIRST(list), (var2) = DWC_LIST_NEXT(var); \
  44564. + (var) != DWC_LIST_END(list); \
  44565. + (var) = (var2), (var2) = DWC_LIST_NEXT(var2))
  44566. +
  44567. +#define DWC_LIST_FOREACH_REVERSE(var, list) \
  44568. + for((var) = DWC_LIST_LAST(list); \
  44569. + (var) != DWC_LIST_END(list); \
  44570. + (var) = DWC_LIST_PREV(var))
  44571. +
  44572. +/*
  44573. + * Singly-linked List definitions.
  44574. + */
  44575. +#define DWC_SLIST_HEAD(name, type) \
  44576. +struct name { \
  44577. + struct type *slh_first; /* first element */ \
  44578. +}
  44579. +
  44580. +#define DWC_SLIST_HEAD_INITIALIZER(head) \
  44581. + { NULL }
  44582. +
  44583. +#define DWC_SLIST_ENTRY(type) \
  44584. +struct { \
  44585. + struct type *sle_next; /* next element */ \
  44586. +}
  44587. +
  44588. +/*
  44589. + * Singly-linked List access methods.
  44590. + */
  44591. +#define DWC_SLIST_FIRST(head) ((head)->slh_first)
  44592. +#define DWC_SLIST_END(head) NULL
  44593. +#define DWC_SLIST_EMPTY(head) (SLIST_FIRST(head) == SLIST_END(head))
  44594. +#define DWC_SLIST_NEXT(elm, field) ((elm)->field.sle_next)
  44595. +
  44596. +#define DWC_SLIST_FOREACH(var, head, field) \
  44597. + for((var) = SLIST_FIRST(head); \
  44598. + (var) != SLIST_END(head); \
  44599. + (var) = SLIST_NEXT(var, field))
  44600. +
  44601. +#define DWC_SLIST_FOREACH_PREVPTR(var, varp, head, field) \
  44602. + for((varp) = &SLIST_FIRST((head)); \
  44603. + ((var) = *(varp)) != SLIST_END(head); \
  44604. + (varp) = &SLIST_NEXT((var), field))
  44605. +
  44606. +/*
  44607. + * Singly-linked List functions.
  44608. + */
  44609. +#define DWC_SLIST_INIT(head) { \
  44610. + SLIST_FIRST(head) = SLIST_END(head); \
  44611. +}
  44612. +
  44613. +#define DWC_SLIST_INSERT_AFTER(slistelm, elm, field) do { \
  44614. + (elm)->field.sle_next = (slistelm)->field.sle_next; \
  44615. + (slistelm)->field.sle_next = (elm); \
  44616. +} while (0)
  44617. +
  44618. +#define DWC_SLIST_INSERT_HEAD(head, elm, field) do { \
  44619. + (elm)->field.sle_next = (head)->slh_first; \
  44620. + (head)->slh_first = (elm); \
  44621. +} while (0)
  44622. +
  44623. +#define DWC_SLIST_REMOVE_NEXT(head, elm, field) do { \
  44624. + (elm)->field.sle_next = (elm)->field.sle_next->field.sle_next; \
  44625. +} while (0)
  44626. +
  44627. +#define DWC_SLIST_REMOVE_HEAD(head, field) do { \
  44628. + (head)->slh_first = (head)->slh_first->field.sle_next; \
  44629. +} while (0)
  44630. +
  44631. +#define DWC_SLIST_REMOVE(head, elm, type, field) do { \
  44632. + if ((head)->slh_first == (elm)) { \
  44633. + SLIST_REMOVE_HEAD((head), field); \
  44634. + } \
  44635. + else { \
  44636. + struct type *curelm = (head)->slh_first; \
  44637. + while( curelm->field.sle_next != (elm) ) \
  44638. + curelm = curelm->field.sle_next; \
  44639. + curelm->field.sle_next = \
  44640. + curelm->field.sle_next->field.sle_next; \
  44641. + } \
  44642. +} while (0)
  44643. +
  44644. +/*
  44645. + * Simple queue definitions.
  44646. + */
  44647. +#define DWC_SIMPLEQ_HEAD(name, type) \
  44648. +struct name { \
  44649. + struct type *sqh_first; /* first element */ \
  44650. + struct type **sqh_last; /* addr of last next element */ \
  44651. +}
  44652. +
  44653. +#define DWC_SIMPLEQ_HEAD_INITIALIZER(head) \
  44654. + { NULL, &(head).sqh_first }
  44655. +
  44656. +#define DWC_SIMPLEQ_ENTRY(type) \
  44657. +struct { \
  44658. + struct type *sqe_next; /* next element */ \
  44659. +}
  44660. +
  44661. +/*
  44662. + * Simple queue access methods.
  44663. + */
  44664. +#define DWC_SIMPLEQ_FIRST(head) ((head)->sqh_first)
  44665. +#define DWC_SIMPLEQ_END(head) NULL
  44666. +#define DWC_SIMPLEQ_EMPTY(head) (SIMPLEQ_FIRST(head) == SIMPLEQ_END(head))
  44667. +#define DWC_SIMPLEQ_NEXT(elm, field) ((elm)->field.sqe_next)
  44668. +
  44669. +#define DWC_SIMPLEQ_FOREACH(var, head, field) \
  44670. + for((var) = SIMPLEQ_FIRST(head); \
  44671. + (var) != SIMPLEQ_END(head); \
  44672. + (var) = SIMPLEQ_NEXT(var, field))
  44673. +
  44674. +/*
  44675. + * Simple queue functions.
  44676. + */
  44677. +#define DWC_SIMPLEQ_INIT(head) do { \
  44678. + (head)->sqh_first = NULL; \
  44679. + (head)->sqh_last = &(head)->sqh_first; \
  44680. +} while (0)
  44681. +
  44682. +#define DWC_SIMPLEQ_INSERT_HEAD(head, elm, field) do { \
  44683. + if (((elm)->field.sqe_next = (head)->sqh_first) == NULL) \
  44684. + (head)->sqh_last = &(elm)->field.sqe_next; \
  44685. + (head)->sqh_first = (elm); \
  44686. +} while (0)
  44687. +
  44688. +#define DWC_SIMPLEQ_INSERT_TAIL(head, elm, field) do { \
  44689. + (elm)->field.sqe_next = NULL; \
  44690. + *(head)->sqh_last = (elm); \
  44691. + (head)->sqh_last = &(elm)->field.sqe_next; \
  44692. +} while (0)
  44693. +
  44694. +#define DWC_SIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
  44695. + if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL)\
  44696. + (head)->sqh_last = &(elm)->field.sqe_next; \
  44697. + (listelm)->field.sqe_next = (elm); \
  44698. +} while (0)
  44699. +
  44700. +#define DWC_SIMPLEQ_REMOVE_HEAD(head, field) do { \
  44701. + if (((head)->sqh_first = (head)->sqh_first->field.sqe_next) == NULL) \
  44702. + (head)->sqh_last = &(head)->sqh_first; \
  44703. +} while (0)
  44704. +
  44705. +/*
  44706. + * Tail queue definitions.
  44707. + */
  44708. +#define DWC_TAILQ_HEAD(name, type) \
  44709. +struct name { \
  44710. + struct type *tqh_first; /* first element */ \
  44711. + struct type **tqh_last; /* addr of last next element */ \
  44712. +}
  44713. +
  44714. +#define DWC_TAILQ_HEAD_INITIALIZER(head) \
  44715. + { NULL, &(head).tqh_first }
  44716. +
  44717. +#define DWC_TAILQ_ENTRY(type) \
  44718. +struct { \
  44719. + struct type *tqe_next; /* next element */ \
  44720. + struct type **tqe_prev; /* address of previous next element */ \
  44721. +}
  44722. +
  44723. +/*
  44724. + * tail queue access methods
  44725. + */
  44726. +#define DWC_TAILQ_FIRST(head) ((head)->tqh_first)
  44727. +#define DWC_TAILQ_END(head) NULL
  44728. +#define DWC_TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
  44729. +#define DWC_TAILQ_LAST(head, headname) \
  44730. + (*(((struct headname *)((head)->tqh_last))->tqh_last))
  44731. +/* XXX */
  44732. +#define DWC_TAILQ_PREV(elm, headname, field) \
  44733. + (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
  44734. +#define DWC_TAILQ_EMPTY(head) \
  44735. + (DWC_TAILQ_FIRST(head) == DWC_TAILQ_END(head))
  44736. +
  44737. +#define DWC_TAILQ_FOREACH(var, head, field) \
  44738. + for ((var) = DWC_TAILQ_FIRST(head); \
  44739. + (var) != DWC_TAILQ_END(head); \
  44740. + (var) = DWC_TAILQ_NEXT(var, field))
  44741. +
  44742. +#define DWC_TAILQ_FOREACH_REVERSE(var, head, headname, field) \
  44743. + for ((var) = DWC_TAILQ_LAST(head, headname); \
  44744. + (var) != DWC_TAILQ_END(head); \
  44745. + (var) = DWC_TAILQ_PREV(var, headname, field))
  44746. +
  44747. +/*
  44748. + * Tail queue functions.
  44749. + */
  44750. +#define DWC_TAILQ_INIT(head) do { \
  44751. + (head)->tqh_first = NULL; \
  44752. + (head)->tqh_last = &(head)->tqh_first; \
  44753. +} while (0)
  44754. +
  44755. +#define DWC_TAILQ_INSERT_HEAD(head, elm, field) do { \
  44756. + if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \
  44757. + (head)->tqh_first->field.tqe_prev = \
  44758. + &(elm)->field.tqe_next; \
  44759. + else \
  44760. + (head)->tqh_last = &(elm)->field.tqe_next; \
  44761. + (head)->tqh_first = (elm); \
  44762. + (elm)->field.tqe_prev = &(head)->tqh_first; \
  44763. +} while (0)
  44764. +
  44765. +#define DWC_TAILQ_INSERT_TAIL(head, elm, field) do { \
  44766. + (elm)->field.tqe_next = NULL; \
  44767. + (elm)->field.tqe_prev = (head)->tqh_last; \
  44768. + *(head)->tqh_last = (elm); \
  44769. + (head)->tqh_last = &(elm)->field.tqe_next; \
  44770. +} while (0)
  44771. +
  44772. +#define DWC_TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
  44773. + if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\
  44774. + (elm)->field.tqe_next->field.tqe_prev = \
  44775. + &(elm)->field.tqe_next; \
  44776. + else \
  44777. + (head)->tqh_last = &(elm)->field.tqe_next; \
  44778. + (listelm)->field.tqe_next = (elm); \
  44779. + (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \
  44780. +} while (0)
  44781. +
  44782. +#define DWC_TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
  44783. + (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
  44784. + (elm)->field.tqe_next = (listelm); \
  44785. + *(listelm)->field.tqe_prev = (elm); \
  44786. + (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \
  44787. +} while (0)
  44788. +
  44789. +#define DWC_TAILQ_REMOVE(head, elm, field) do { \
  44790. + if (((elm)->field.tqe_next) != NULL) \
  44791. + (elm)->field.tqe_next->field.tqe_prev = \
  44792. + (elm)->field.tqe_prev; \
  44793. + else \
  44794. + (head)->tqh_last = (elm)->field.tqe_prev; \
  44795. + *(elm)->field.tqe_prev = (elm)->field.tqe_next; \
  44796. +} while (0)
  44797. +
  44798. +#define DWC_TAILQ_REPLACE(head, elm, elm2, field) do { \
  44799. + if (((elm2)->field.tqe_next = (elm)->field.tqe_next) != NULL) \
  44800. + (elm2)->field.tqe_next->field.tqe_prev = \
  44801. + &(elm2)->field.tqe_next; \
  44802. + else \
  44803. + (head)->tqh_last = &(elm2)->field.tqe_next; \
  44804. + (elm2)->field.tqe_prev = (elm)->field.tqe_prev; \
  44805. + *(elm2)->field.tqe_prev = (elm2); \
  44806. +} while (0)
  44807. +
  44808. +/*
  44809. + * Circular queue definitions.
  44810. + */
  44811. +#define DWC_CIRCLEQ_HEAD(name, type) \
  44812. +struct name { \
  44813. + struct type *cqh_first; /* first element */ \
  44814. + struct type *cqh_last; /* last element */ \
  44815. +}
  44816. +
  44817. +#define DWC_CIRCLEQ_HEAD_INITIALIZER(head) \
  44818. + { DWC_CIRCLEQ_END(&head), DWC_CIRCLEQ_END(&head) }
  44819. +
  44820. +#define DWC_CIRCLEQ_ENTRY(type) \
  44821. +struct { \
  44822. + struct type *cqe_next; /* next element */ \
  44823. + struct type *cqe_prev; /* previous element */ \
  44824. +}
  44825. +
  44826. +/*
  44827. + * Circular queue access methods
  44828. + */
  44829. +#define DWC_CIRCLEQ_FIRST(head) ((head)->cqh_first)
  44830. +#define DWC_CIRCLEQ_LAST(head) ((head)->cqh_last)
  44831. +#define DWC_CIRCLEQ_END(head) ((void *)(head))
  44832. +#define DWC_CIRCLEQ_NEXT(elm, field) ((elm)->field.cqe_next)
  44833. +#define DWC_CIRCLEQ_PREV(elm, field) ((elm)->field.cqe_prev)
  44834. +#define DWC_CIRCLEQ_EMPTY(head) \
  44835. + (DWC_CIRCLEQ_FIRST(head) == DWC_CIRCLEQ_END(head))
  44836. +
  44837. +#define DWC_CIRCLEQ_EMPTY_ENTRY(elm, field) (((elm)->field.cqe_next == NULL) && ((elm)->field.cqe_prev == NULL))
  44838. +
  44839. +#define DWC_CIRCLEQ_FOREACH(var, head, field) \
  44840. + for((var) = DWC_CIRCLEQ_FIRST(head); \
  44841. + (var) != DWC_CIRCLEQ_END(head); \
  44842. + (var) = DWC_CIRCLEQ_NEXT(var, field))
  44843. +
  44844. +#define DWC_CIRCLEQ_FOREACH_SAFE(var, var2, head, field) \
  44845. + for((var) = DWC_CIRCLEQ_FIRST(head), var2 = DWC_CIRCLEQ_NEXT(var, field); \
  44846. + (var) != DWC_CIRCLEQ_END(head); \
  44847. + (var) = var2, var2 = DWC_CIRCLEQ_NEXT(var, field))
  44848. +
  44849. +#define DWC_CIRCLEQ_FOREACH_REVERSE(var, head, field) \
  44850. + for((var) = DWC_CIRCLEQ_LAST(head); \
  44851. + (var) != DWC_CIRCLEQ_END(head); \
  44852. + (var) = DWC_CIRCLEQ_PREV(var, field))
  44853. +
  44854. +/*
  44855. + * Circular queue functions.
  44856. + */
  44857. +#define DWC_CIRCLEQ_INIT(head) do { \
  44858. + (head)->cqh_first = DWC_CIRCLEQ_END(head); \
  44859. + (head)->cqh_last = DWC_CIRCLEQ_END(head); \
  44860. +} while (0)
  44861. +
  44862. +#define DWC_CIRCLEQ_INIT_ENTRY(elm, field) do { \
  44863. + (elm)->field.cqe_next = NULL; \
  44864. + (elm)->field.cqe_prev = NULL; \
  44865. +} while (0)
  44866. +
  44867. +#define DWC_CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
  44868. + (elm)->field.cqe_next = (listelm)->field.cqe_next; \
  44869. + (elm)->field.cqe_prev = (listelm); \
  44870. + if ((listelm)->field.cqe_next == DWC_CIRCLEQ_END(head)) \
  44871. + (head)->cqh_last = (elm); \
  44872. + else \
  44873. + (listelm)->field.cqe_next->field.cqe_prev = (elm); \
  44874. + (listelm)->field.cqe_next = (elm); \
  44875. +} while (0)
  44876. +
  44877. +#define DWC_CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do { \
  44878. + (elm)->field.cqe_next = (listelm); \
  44879. + (elm)->field.cqe_prev = (listelm)->field.cqe_prev; \
  44880. + if ((listelm)->field.cqe_prev == DWC_CIRCLEQ_END(head)) \
  44881. + (head)->cqh_first = (elm); \
  44882. + else \
  44883. + (listelm)->field.cqe_prev->field.cqe_next = (elm); \
  44884. + (listelm)->field.cqe_prev = (elm); \
  44885. +} while (0)
  44886. +
  44887. +#define DWC_CIRCLEQ_INSERT_HEAD(head, elm, field) do { \
  44888. + (elm)->field.cqe_next = (head)->cqh_first; \
  44889. + (elm)->field.cqe_prev = DWC_CIRCLEQ_END(head); \
  44890. + if ((head)->cqh_last == DWC_CIRCLEQ_END(head)) \
  44891. + (head)->cqh_last = (elm); \
  44892. + else \
  44893. + (head)->cqh_first->field.cqe_prev = (elm); \
  44894. + (head)->cqh_first = (elm); \
  44895. +} while (0)
  44896. +
  44897. +#define DWC_CIRCLEQ_INSERT_TAIL(head, elm, field) do { \
  44898. + (elm)->field.cqe_next = DWC_CIRCLEQ_END(head); \
  44899. + (elm)->field.cqe_prev = (head)->cqh_last; \
  44900. + if ((head)->cqh_first == DWC_CIRCLEQ_END(head)) \
  44901. + (head)->cqh_first = (elm); \
  44902. + else \
  44903. + (head)->cqh_last->field.cqe_next = (elm); \
  44904. + (head)->cqh_last = (elm); \
  44905. +} while (0)
  44906. +
  44907. +#define DWC_CIRCLEQ_REMOVE(head, elm, field) do { \
  44908. + if ((elm)->field.cqe_next == DWC_CIRCLEQ_END(head)) \
  44909. + (head)->cqh_last = (elm)->field.cqe_prev; \
  44910. + else \
  44911. + (elm)->field.cqe_next->field.cqe_prev = \
  44912. + (elm)->field.cqe_prev; \
  44913. + if ((elm)->field.cqe_prev == DWC_CIRCLEQ_END(head)) \
  44914. + (head)->cqh_first = (elm)->field.cqe_next; \
  44915. + else \
  44916. + (elm)->field.cqe_prev->field.cqe_next = \
  44917. + (elm)->field.cqe_next; \
  44918. +} while (0)
  44919. +
  44920. +#define DWC_CIRCLEQ_REMOVE_INIT(head, elm, field) do { \
  44921. + DWC_CIRCLEQ_REMOVE(head, elm, field); \
  44922. + DWC_CIRCLEQ_INIT_ENTRY(elm, field); \
  44923. +} while (0)
  44924. +
  44925. +#define DWC_CIRCLEQ_REPLACE(head, elm, elm2, field) do { \
  44926. + if (((elm2)->field.cqe_next = (elm)->field.cqe_next) == \
  44927. + DWC_CIRCLEQ_END(head)) \
  44928. + (head).cqh_last = (elm2); \
  44929. + else \
  44930. + (elm2)->field.cqe_next->field.cqe_prev = (elm2); \
  44931. + if (((elm2)->field.cqe_prev = (elm)->field.cqe_prev) == \
  44932. + DWC_CIRCLEQ_END(head)) \
  44933. + (head).cqh_first = (elm2); \
  44934. + else \
  44935. + (elm2)->field.cqe_prev->field.cqe_next = (elm2); \
  44936. +} while (0)
  44937. +
  44938. +#ifdef __cplusplus
  44939. +}
  44940. +#endif
  44941. +
  44942. +#endif /* _DWC_LIST_H_ */
  44943. diff -Nur linux-3.13.11/drivers/usb/host/dwc_common_port/dwc_mem.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_mem.c
  44944. --- linux-3.13.11/drivers/usb/host/dwc_common_port/dwc_mem.c 1970-01-01 01:00:00.000000000 +0100
  44945. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_mem.c 2014-04-24 15:35:04.169565731 +0200
  44946. @@ -0,0 +1,245 @@
  44947. +/* Memory Debugging */
  44948. +#ifdef DWC_DEBUG_MEMORY
  44949. +
  44950. +#include "dwc_os.h"
  44951. +#include "dwc_list.h"
  44952. +
  44953. +struct allocation {
  44954. + void *addr;
  44955. + void *ctx;
  44956. + char *func;
  44957. + int line;
  44958. + uint32_t size;
  44959. + int dma;
  44960. + DWC_CIRCLEQ_ENTRY(allocation) entry;
  44961. +};
  44962. +
  44963. +DWC_CIRCLEQ_HEAD(allocation_queue, allocation);
  44964. +
  44965. +struct allocation_manager {
  44966. + void *mem_ctx;
  44967. + struct allocation_queue allocations;
  44968. +
  44969. + /* statistics */
  44970. + int num;
  44971. + int num_freed;
  44972. + int num_active;
  44973. + uint32_t total;
  44974. + uint32_t cur;
  44975. + uint32_t max;
  44976. +};
  44977. +
  44978. +static struct allocation_manager *manager = NULL;
  44979. +
  44980. +static int add_allocation(void *ctx, uint32_t size, char const *func, int line, void *addr,
  44981. + int dma)
  44982. +{
  44983. + struct allocation *a;
  44984. +
  44985. + DWC_ASSERT(manager != NULL, "manager not allocated");
  44986. +
  44987. + a = __DWC_ALLOC_ATOMIC(manager->mem_ctx, sizeof(*a));
  44988. + if (!a) {
  44989. + return -DWC_E_NO_MEMORY;
  44990. + }
  44991. +
  44992. + a->func = __DWC_ALLOC_ATOMIC(manager->mem_ctx, DWC_STRLEN(func) + 1);
  44993. + if (!a->func) {
  44994. + __DWC_FREE(manager->mem_ctx, a);
  44995. + return -DWC_E_NO_MEMORY;
  44996. + }
  44997. +
  44998. + DWC_MEMCPY(a->func, func, DWC_STRLEN(func) + 1);
  44999. + a->addr = addr;
  45000. + a->ctx = ctx;
  45001. + a->line = line;
  45002. + a->size = size;
  45003. + a->dma = dma;
  45004. + DWC_CIRCLEQ_INSERT_TAIL(&manager->allocations, a, entry);
  45005. +
  45006. + /* Update stats */
  45007. + manager->num++;
  45008. + manager->num_active++;
  45009. + manager->total += size;
  45010. + manager->cur += size;
  45011. +
  45012. + if (manager->max < manager->cur) {
  45013. + manager->max = manager->cur;
  45014. + }
  45015. +
  45016. + return 0;
  45017. +}
  45018. +
  45019. +static struct allocation *find_allocation(void *ctx, void *addr)
  45020. +{
  45021. + struct allocation *a;
  45022. +
  45023. + DWC_CIRCLEQ_FOREACH(a, &manager->allocations, entry) {
  45024. + if (a->ctx == ctx && a->addr == addr) {
  45025. + return a;
  45026. + }
  45027. + }
  45028. +
  45029. + return NULL;
  45030. +}
  45031. +
  45032. +static void free_allocation(void *ctx, void *addr, char const *func, int line)
  45033. +{
  45034. + struct allocation *a = find_allocation(ctx, addr);
  45035. +
  45036. + if (!a) {
  45037. + DWC_ASSERT(0,
  45038. + "Free of address %p that was never allocated or already freed %s:%d",
  45039. + addr, func, line);
  45040. + return;
  45041. + }
  45042. +
  45043. + DWC_CIRCLEQ_REMOVE(&manager->allocations, a, entry);
  45044. +
  45045. + manager->num_active--;
  45046. + manager->num_freed++;
  45047. + manager->cur -= a->size;
  45048. + __DWC_FREE(manager->mem_ctx, a->func);
  45049. + __DWC_FREE(manager->mem_ctx, a);
  45050. +}
  45051. +
  45052. +int dwc_memory_debug_start(void *mem_ctx)
  45053. +{
  45054. + DWC_ASSERT(manager == NULL, "Memory debugging has already started\n");
  45055. +
  45056. + if (manager) {
  45057. + return -DWC_E_BUSY;
  45058. + }
  45059. +
  45060. + manager = __DWC_ALLOC(mem_ctx, sizeof(*manager));
  45061. + if (!manager) {
  45062. + return -DWC_E_NO_MEMORY;
  45063. + }
  45064. +
  45065. + DWC_CIRCLEQ_INIT(&manager->allocations);
  45066. + manager->mem_ctx = mem_ctx;
  45067. + manager->num = 0;
  45068. + manager->num_freed = 0;
  45069. + manager->num_active = 0;
  45070. + manager->total = 0;
  45071. + manager->cur = 0;
  45072. + manager->max = 0;
  45073. +
  45074. + return 0;
  45075. +}
  45076. +
  45077. +void dwc_memory_debug_stop(void)
  45078. +{
  45079. + struct allocation *a;
  45080. +
  45081. + dwc_memory_debug_report();
  45082. +
  45083. + DWC_CIRCLEQ_FOREACH(a, &manager->allocations, entry) {
  45084. + DWC_ERROR("Memory leaked from %s:%d\n", a->func, a->line);
  45085. + free_allocation(a->ctx, a->addr, NULL, -1);
  45086. + }
  45087. +
  45088. + __DWC_FREE(manager->mem_ctx, manager);
  45089. +}
  45090. +
  45091. +void dwc_memory_debug_report(void)
  45092. +{
  45093. + struct allocation *a;
  45094. +
  45095. + DWC_PRINTF("\n\n\n----------------- Memory Debugging Report -----------------\n\n");
  45096. + DWC_PRINTF("Num Allocations = %d\n", manager->num);
  45097. + DWC_PRINTF("Freed = %d\n", manager->num_freed);
  45098. + DWC_PRINTF("Active = %d\n", manager->num_active);
  45099. + DWC_PRINTF("Current Memory Used = %d\n", manager->cur);
  45100. + DWC_PRINTF("Total Memory Used = %d\n", manager->total);
  45101. + DWC_PRINTF("Maximum Memory Used at Once = %d\n", manager->max);
  45102. + DWC_PRINTF("Unfreed allocations:\n");
  45103. +
  45104. + DWC_CIRCLEQ_FOREACH(a, &manager->allocations, entry) {
  45105. + DWC_PRINTF(" addr=%p, size=%d from %s:%d, DMA=%d\n",
  45106. + a->addr, a->size, a->func, a->line, a->dma);
  45107. + }
  45108. +}
  45109. +
  45110. +/* The replacement functions */
  45111. +void *dwc_alloc_debug(void *mem_ctx, uint32_t size, char const *func, int line)
  45112. +{
  45113. + void *addr = __DWC_ALLOC(mem_ctx, size);
  45114. +
  45115. + if (!addr) {
  45116. + return NULL;
  45117. + }
  45118. +
  45119. + if (add_allocation(mem_ctx, size, func, line, addr, 0)) {
  45120. + __DWC_FREE(mem_ctx, addr);
  45121. + return NULL;
  45122. + }
  45123. +
  45124. + return addr;
  45125. +}
  45126. +
  45127. +void *dwc_alloc_atomic_debug(void *mem_ctx, uint32_t size, char const *func,
  45128. + int line)
  45129. +{
  45130. + void *addr = __DWC_ALLOC_ATOMIC(mem_ctx, size);
  45131. +
  45132. + if (!addr) {
  45133. + return NULL;
  45134. + }
  45135. +
  45136. + if (add_allocation(mem_ctx, size, func, line, addr, 0)) {
  45137. + __DWC_FREE(mem_ctx, addr);
  45138. + return NULL;
  45139. + }
  45140. +
  45141. + return addr;
  45142. +}
  45143. +
  45144. +void dwc_free_debug(void *mem_ctx, void *addr, char const *func, int line)
  45145. +{
  45146. + free_allocation(mem_ctx, addr, func, line);
  45147. + __DWC_FREE(mem_ctx, addr);
  45148. +}
  45149. +
  45150. +void *dwc_dma_alloc_debug(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr,
  45151. + char const *func, int line)
  45152. +{
  45153. + void *addr = __DWC_DMA_ALLOC(dma_ctx, size, dma_addr);
  45154. +
  45155. + if (!addr) {
  45156. + return NULL;
  45157. + }
  45158. +
  45159. + if (add_allocation(dma_ctx, size, func, line, addr, 1)) {
  45160. + __DWC_DMA_FREE(dma_ctx, size, addr, *dma_addr);
  45161. + return NULL;
  45162. + }
  45163. +
  45164. + return addr;
  45165. +}
  45166. +
  45167. +void *dwc_dma_alloc_atomic_debug(void *dma_ctx, uint32_t size,
  45168. + dwc_dma_t *dma_addr, char const *func, int line)
  45169. +{
  45170. + void *addr = __DWC_DMA_ALLOC_ATOMIC(dma_ctx, size, dma_addr);
  45171. +
  45172. + if (!addr) {
  45173. + return NULL;
  45174. + }
  45175. +
  45176. + if (add_allocation(dma_ctx, size, func, line, addr, 1)) {
  45177. + __DWC_DMA_FREE(dma_ctx, size, addr, *dma_addr);
  45178. + return NULL;
  45179. + }
  45180. +
  45181. + return addr;
  45182. +}
  45183. +
  45184. +void dwc_dma_free_debug(void *dma_ctx, uint32_t size, void *virt_addr,
  45185. + dwc_dma_t dma_addr, char const *func, int line)
  45186. +{
  45187. + free_allocation(dma_ctx, virt_addr, func, line);
  45188. + __DWC_DMA_FREE(dma_ctx, size, virt_addr, dma_addr);
  45189. +}
  45190. +
  45191. +#endif /* DWC_DEBUG_MEMORY */
  45192. diff -Nur linux-3.13.11/drivers/usb/host/dwc_common_port/dwc_modpow.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_modpow.c
  45193. --- linux-3.13.11/drivers/usb/host/dwc_common_port/dwc_modpow.c 1970-01-01 01:00:00.000000000 +0100
  45194. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_modpow.c 2014-04-24 15:37:13.306990445 +0200
  45195. @@ -0,0 +1,636 @@
  45196. +/* Bignum routines adapted from PUTTY sources. PuTTY copyright notice follows.
  45197. + *
  45198. + * PuTTY is copyright 1997-2007 Simon Tatham.
  45199. + *
  45200. + * Portions copyright Robert de Bath, Joris van Rantwijk, Delian
  45201. + * Delchev, Andreas Schultz, Jeroen Massar, Wez Furlong, Nicolas Barry,
  45202. + * Justin Bradford, Ben Harris, Malcolm Smith, Ahmad Khalifa, Markus
  45203. + * Kuhn, and CORE SDI S.A.
  45204. + *
  45205. + * Permission is hereby granted, free of charge, to any person
  45206. + * obtaining a copy of this software and associated documentation files
  45207. + * (the "Software"), to deal in the Software without restriction,
  45208. + * including without limitation the rights to use, copy, modify, merge,
  45209. + * publish, distribute, sublicense, and/or sell copies of the Software,
  45210. + * and to permit persons to whom the Software is furnished to do so,
  45211. + * subject to the following conditions:
  45212. + *
  45213. + * The above copyright notice and this permission notice shall be
  45214. + * included in all copies or substantial portions of the Software.
  45215. +
  45216. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  45217. + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  45218. + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  45219. + * NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE
  45220. + * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  45221. + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  45222. + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  45223. + *
  45224. + */
  45225. +#ifdef DWC_CRYPTOLIB
  45226. +
  45227. +#ifndef CONFIG_MACH_IPMATE
  45228. +
  45229. +#include "dwc_modpow.h"
  45230. +
  45231. +#define BIGNUM_INT_MASK 0xFFFFFFFFUL
  45232. +#define BIGNUM_TOP_BIT 0x80000000UL
  45233. +#define BIGNUM_INT_BITS 32
  45234. +
  45235. +
  45236. +static void *snmalloc(void *mem_ctx, size_t n, size_t size)
  45237. +{
  45238. + void *p;
  45239. + size *= n;
  45240. + if (size == 0) size = 1;
  45241. + p = dwc_alloc(mem_ctx, size);
  45242. + return p;
  45243. +}
  45244. +
  45245. +#define snewn(ctx, n, type) ((type *)snmalloc((ctx), (n), sizeof(type)))
  45246. +#define sfree dwc_free
  45247. +
  45248. +/*
  45249. + * Usage notes:
  45250. + * * Do not call the DIVMOD_WORD macro with expressions such as array
  45251. + * subscripts, as some implementations object to this (see below).
  45252. + * * Note that none of the division methods below will cope if the
  45253. + * quotient won't fit into BIGNUM_INT_BITS. Callers should be careful
  45254. + * to avoid this case.
  45255. + * If this condition occurs, in the case of the x86 DIV instruction,
  45256. + * an overflow exception will occur, which (according to a correspondent)
  45257. + * will manifest on Windows as something like
  45258. + * 0xC0000095: Integer overflow
  45259. + * The C variant won't give the right answer, either.
  45260. + */
  45261. +
  45262. +#define MUL_WORD(w1, w2) ((BignumDblInt)w1 * w2)
  45263. +
  45264. +#if defined __GNUC__ && defined __i386__
  45265. +#define DIVMOD_WORD(q, r, hi, lo, w) \
  45266. + __asm__("div %2" : \
  45267. + "=d" (r), "=a" (q) : \
  45268. + "r" (w), "d" (hi), "a" (lo))
  45269. +#else
  45270. +#define DIVMOD_WORD(q, r, hi, lo, w) do { \
  45271. + BignumDblInt n = (((BignumDblInt)hi) << BIGNUM_INT_BITS) | lo; \
  45272. + q = n / w; \
  45273. + r = n % w; \
  45274. +} while (0)
  45275. +#endif
  45276. +
  45277. +// q = n / w;
  45278. +// r = n % w;
  45279. +
  45280. +#define BIGNUM_INT_BYTES (BIGNUM_INT_BITS / 8)
  45281. +
  45282. +#define BIGNUM_INTERNAL
  45283. +
  45284. +static Bignum newbn(void *mem_ctx, int length)
  45285. +{
  45286. + Bignum b = snewn(mem_ctx, length + 1, BignumInt);
  45287. + //if (!b)
  45288. + //abort(); /* FIXME */
  45289. + DWC_MEMSET(b, 0, (length + 1) * sizeof(*b));
  45290. + b[0] = length;
  45291. + return b;
  45292. +}
  45293. +
  45294. +void freebn(void *mem_ctx, Bignum b)
  45295. +{
  45296. + /*
  45297. + * Burn the evidence, just in case.
  45298. + */
  45299. + DWC_MEMSET(b, 0, sizeof(b[0]) * (b[0] + 1));
  45300. + sfree(mem_ctx, b);
  45301. +}
  45302. +
  45303. +/*
  45304. + * Compute c = a * b.
  45305. + * Input is in the first len words of a and b.
  45306. + * Result is returned in the first 2*len words of c.
  45307. + */
  45308. +static void internal_mul(BignumInt *a, BignumInt *b,
  45309. + BignumInt *c, int len)
  45310. +{
  45311. + int i, j;
  45312. + BignumDblInt t;
  45313. +
  45314. + for (j = 0; j < 2 * len; j++)
  45315. + c[j] = 0;
  45316. +
  45317. + for (i = len - 1; i >= 0; i--) {
  45318. + t = 0;
  45319. + for (j = len - 1; j >= 0; j--) {
  45320. + t += MUL_WORD(a[i], (BignumDblInt) b[j]);
  45321. + t += (BignumDblInt) c[i + j + 1];
  45322. + c[i + j + 1] = (BignumInt) t;
  45323. + t = t >> BIGNUM_INT_BITS;
  45324. + }
  45325. + c[i] = (BignumInt) t;
  45326. + }
  45327. +}
  45328. +
  45329. +static void internal_add_shifted(BignumInt *number,
  45330. + unsigned n, int shift)
  45331. +{
  45332. + int word = 1 + (shift / BIGNUM_INT_BITS);
  45333. + int bshift = shift % BIGNUM_INT_BITS;
  45334. + BignumDblInt addend;
  45335. +
  45336. + addend = (BignumDblInt)n << bshift;
  45337. +
  45338. + while (addend) {
  45339. + addend += number[word];
  45340. + number[word] = (BignumInt) addend & BIGNUM_INT_MASK;
  45341. + addend >>= BIGNUM_INT_BITS;
  45342. + word++;
  45343. + }
  45344. +}
  45345. +
  45346. +/*
  45347. + * Compute a = a % m.
  45348. + * Input in first alen words of a and first mlen words of m.
  45349. + * Output in first alen words of a
  45350. + * (of which first alen-mlen words will be zero).
  45351. + * The MSW of m MUST have its high bit set.
  45352. + * Quotient is accumulated in the `quotient' array, which is a Bignum
  45353. + * rather than the internal bigendian format. Quotient parts are shifted
  45354. + * left by `qshift' before adding into quot.
  45355. + */
  45356. +static void internal_mod(BignumInt *a, int alen,
  45357. + BignumInt *m, int mlen,
  45358. + BignumInt *quot, int qshift)
  45359. +{
  45360. + BignumInt m0, m1;
  45361. + unsigned int h;
  45362. + int i, k;
  45363. +
  45364. + m0 = m[0];
  45365. + if (mlen > 1)
  45366. + m1 = m[1];
  45367. + else
  45368. + m1 = 0;
  45369. +
  45370. + for (i = 0; i <= alen - mlen; i++) {
  45371. + BignumDblInt t;
  45372. + unsigned int q, r, c, ai1;
  45373. +
  45374. + if (i == 0) {
  45375. + h = 0;
  45376. + } else {
  45377. + h = a[i - 1];
  45378. + a[i - 1] = 0;
  45379. + }
  45380. +
  45381. + if (i == alen - 1)
  45382. + ai1 = 0;
  45383. + else
  45384. + ai1 = a[i + 1];
  45385. +
  45386. + /* Find q = h:a[i] / m0 */
  45387. + if (h >= m0) {
  45388. + /*
  45389. + * Special case.
  45390. + *
  45391. + * To illustrate it, suppose a BignumInt is 8 bits, and
  45392. + * we are dividing (say) A1:23:45:67 by A1:B2:C3. Then
  45393. + * our initial division will be 0xA123 / 0xA1, which
  45394. + * will give a quotient of 0x100 and a divide overflow.
  45395. + * However, the invariants in this division algorithm
  45396. + * are not violated, since the full number A1:23:... is
  45397. + * _less_ than the quotient prefix A1:B2:... and so the
  45398. + * following correction loop would have sorted it out.
  45399. + *
  45400. + * In this situation we set q to be the largest
  45401. + * quotient we _can_ stomach (0xFF, of course).
  45402. + */
  45403. + q = BIGNUM_INT_MASK;
  45404. + } else {
  45405. + /* Macro doesn't want an array subscript expression passed
  45406. + * into it (see definition), so use a temporary. */
  45407. + BignumInt tmplo = a[i];
  45408. + DIVMOD_WORD(q, r, h, tmplo, m0);
  45409. +
  45410. + /* Refine our estimate of q by looking at
  45411. + h:a[i]:a[i+1] / m0:m1 */
  45412. + t = MUL_WORD(m1, q);
  45413. + if (t > ((BignumDblInt) r << BIGNUM_INT_BITS) + ai1) {
  45414. + q--;
  45415. + t -= m1;
  45416. + r = (r + m0) & BIGNUM_INT_MASK; /* overflow? */
  45417. + if (r >= (BignumDblInt) m0 &&
  45418. + t > ((BignumDblInt) r << BIGNUM_INT_BITS) + ai1) q--;
  45419. + }
  45420. + }
  45421. +
  45422. + /* Subtract q * m from a[i...] */
  45423. + c = 0;
  45424. + for (k = mlen - 1; k >= 0; k--) {
  45425. + t = MUL_WORD(q, m[k]);
  45426. + t += c;
  45427. + c = (unsigned)(t >> BIGNUM_INT_BITS);
  45428. + if ((BignumInt) t > a[i + k])
  45429. + c++;
  45430. + a[i + k] -= (BignumInt) t;
  45431. + }
  45432. +
  45433. + /* Add back m in case of borrow */
  45434. + if (c != h) {
  45435. + t = 0;
  45436. + for (k = mlen - 1; k >= 0; k--) {
  45437. + t += m[k];
  45438. + t += a[i + k];
  45439. + a[i + k] = (BignumInt) t;
  45440. + t = t >> BIGNUM_INT_BITS;
  45441. + }
  45442. + q--;
  45443. + }
  45444. + if (quot)
  45445. + internal_add_shifted(quot, q, qshift + BIGNUM_INT_BITS * (alen - mlen - i));
  45446. + }
  45447. +}
  45448. +
  45449. +/*
  45450. + * Compute p % mod.
  45451. + * The most significant word of mod MUST be non-zero.
  45452. + * We assume that the result array is the same size as the mod array.
  45453. + * We optionally write out a quotient if `quotient' is non-NULL.
  45454. + * We can avoid writing out the result if `result' is NULL.
  45455. + */
  45456. +void bigdivmod(void *mem_ctx, Bignum p, Bignum mod, Bignum result, Bignum quotient)
  45457. +{
  45458. + BignumInt *n, *m;
  45459. + int mshift;
  45460. + int plen, mlen, i, j;
  45461. +
  45462. + /* Allocate m of size mlen, copy mod to m */
  45463. + /* We use big endian internally */
  45464. + mlen = mod[0];
  45465. + m = snewn(mem_ctx, mlen, BignumInt);
  45466. + //if (!m)
  45467. + //abort(); /* FIXME */
  45468. + for (j = 0; j < mlen; j++)
  45469. + m[j] = mod[mod[0] - j];
  45470. +
  45471. + /* Shift m left to make msb bit set */
  45472. + for (mshift = 0; mshift < BIGNUM_INT_BITS-1; mshift++)
  45473. + if ((m[0] << mshift) & BIGNUM_TOP_BIT)
  45474. + break;
  45475. + if (mshift) {
  45476. + for (i = 0; i < mlen - 1; i++)
  45477. + m[i] = (m[i] << mshift) | (m[i + 1] >> (BIGNUM_INT_BITS - mshift));
  45478. + m[mlen - 1] = m[mlen - 1] << mshift;
  45479. + }
  45480. +
  45481. + plen = p[0];
  45482. + /* Ensure plen > mlen */
  45483. + if (plen <= mlen)
  45484. + plen = mlen + 1;
  45485. +
  45486. + /* Allocate n of size plen, copy p to n */
  45487. + n = snewn(mem_ctx, plen, BignumInt);
  45488. + //if (!n)
  45489. + //abort(); /* FIXME */
  45490. + for (j = 0; j < plen; j++)
  45491. + n[j] = 0;
  45492. + for (j = 1; j <= (int)p[0]; j++)
  45493. + n[plen - j] = p[j];
  45494. +
  45495. + /* Main computation */
  45496. + internal_mod(n, plen, m, mlen, quotient, mshift);
  45497. +
  45498. + /* Fixup result in case the modulus was shifted */
  45499. + if (mshift) {
  45500. + for (i = plen - mlen - 1; i < plen - 1; i++)
  45501. + n[i] = (n[i] << mshift) | (n[i + 1] >> (BIGNUM_INT_BITS - mshift));
  45502. + n[plen - 1] = n[plen - 1] << mshift;
  45503. + internal_mod(n, plen, m, mlen, quotient, 0);
  45504. + for (i = plen - 1; i >= plen - mlen; i--)
  45505. + n[i] = (n[i] >> mshift) | (n[i - 1] << (BIGNUM_INT_BITS - mshift));
  45506. + }
  45507. +
  45508. + /* Copy result to buffer */
  45509. + if (result) {
  45510. + for (i = 1; i <= (int)result[0]; i++) {
  45511. + int j = plen - i;
  45512. + result[i] = j >= 0 ? n[j] : 0;
  45513. + }
  45514. + }
  45515. +
  45516. + /* Free temporary arrays */
  45517. + for (i = 0; i < mlen; i++)
  45518. + m[i] = 0;
  45519. + sfree(mem_ctx, m);
  45520. + for (i = 0; i < plen; i++)
  45521. + n[i] = 0;
  45522. + sfree(mem_ctx, n);
  45523. +}
  45524. +
  45525. +/*
  45526. + * Simple remainder.
  45527. + */
  45528. +Bignum bigmod(void *mem_ctx, Bignum a, Bignum b)
  45529. +{
  45530. + Bignum r = newbn(mem_ctx, b[0]);
  45531. + bigdivmod(mem_ctx, a, b, r, NULL);
  45532. + return r;
  45533. +}
  45534. +
  45535. +/*
  45536. + * Compute (base ^ exp) % mod.
  45537. + */
  45538. +Bignum dwc_modpow(void *mem_ctx, Bignum base_in, Bignum exp, Bignum mod)
  45539. +{
  45540. + BignumInt *a, *b, *n, *m;
  45541. + int mshift;
  45542. + int mlen, i, j;
  45543. + Bignum base, result;
  45544. +
  45545. + /*
  45546. + * The most significant word of mod needs to be non-zero. It
  45547. + * should already be, but let's make sure.
  45548. + */
  45549. + //assert(mod[mod[0]] != 0);
  45550. +
  45551. + /*
  45552. + * Make sure the base is smaller than the modulus, by reducing
  45553. + * it modulo the modulus if not.
  45554. + */
  45555. + base = bigmod(mem_ctx, base_in, mod);
  45556. +
  45557. + /* Allocate m of size mlen, copy mod to m */
  45558. + /* We use big endian internally */
  45559. + mlen = mod[0];
  45560. + m = snewn(mem_ctx, mlen, BignumInt);
  45561. + //if (!m)
  45562. + //abort(); /* FIXME */
  45563. + for (j = 0; j < mlen; j++)
  45564. + m[j] = mod[mod[0] - j];
  45565. +
  45566. + /* Shift m left to make msb bit set */
  45567. + for (mshift = 0; mshift < BIGNUM_INT_BITS - 1; mshift++)
  45568. + if ((m[0] << mshift) & BIGNUM_TOP_BIT)
  45569. + break;
  45570. + if (mshift) {
  45571. + for (i = 0; i < mlen - 1; i++)
  45572. + m[i] =
  45573. + (m[i] << mshift) | (m[i + 1] >>
  45574. + (BIGNUM_INT_BITS - mshift));
  45575. + m[mlen - 1] = m[mlen - 1] << mshift;
  45576. + }
  45577. +
  45578. + /* Allocate n of size mlen, copy base to n */
  45579. + n = snewn(mem_ctx, mlen, BignumInt);
  45580. + //if (!n)
  45581. + //abort(); /* FIXME */
  45582. + i = mlen - base[0];
  45583. + for (j = 0; j < i; j++)
  45584. + n[j] = 0;
  45585. + for (j = 0; j < base[0]; j++)
  45586. + n[i + j] = base[base[0] - j];
  45587. +
  45588. + /* Allocate a and b of size 2*mlen. Set a = 1 */
  45589. + a = snewn(mem_ctx, 2 * mlen, BignumInt);
  45590. + //if (!a)
  45591. + //abort(); /* FIXME */
  45592. + b = snewn(mem_ctx, 2 * mlen, BignumInt);
  45593. + //if (!b)
  45594. + //abort(); /* FIXME */
  45595. + for (i = 0; i < 2 * mlen; i++)
  45596. + a[i] = 0;
  45597. + a[2 * mlen - 1] = 1;
  45598. +
  45599. + /* Skip leading zero bits of exp. */
  45600. + i = 0;
  45601. + j = BIGNUM_INT_BITS - 1;
  45602. + while (i < exp[0] && (exp[exp[0] - i] & (1 << j)) == 0) {
  45603. + j--;
  45604. + if (j < 0) {
  45605. + i++;
  45606. + j = BIGNUM_INT_BITS - 1;
  45607. + }
  45608. + }
  45609. +
  45610. + /* Main computation */
  45611. + while (i < exp[0]) {
  45612. + while (j >= 0) {
  45613. + internal_mul(a + mlen, a + mlen, b, mlen);
  45614. + internal_mod(b, mlen * 2, m, mlen, NULL, 0);
  45615. + if ((exp[exp[0] - i] & (1 << j)) != 0) {
  45616. + internal_mul(b + mlen, n, a, mlen);
  45617. + internal_mod(a, mlen * 2, m, mlen, NULL, 0);
  45618. + } else {
  45619. + BignumInt *t;
  45620. + t = a;
  45621. + a = b;
  45622. + b = t;
  45623. + }
  45624. + j--;
  45625. + }
  45626. + i++;
  45627. + j = BIGNUM_INT_BITS - 1;
  45628. + }
  45629. +
  45630. + /* Fixup result in case the modulus was shifted */
  45631. + if (mshift) {
  45632. + for (i = mlen - 1; i < 2 * mlen - 1; i++)
  45633. + a[i] =
  45634. + (a[i] << mshift) | (a[i + 1] >>
  45635. + (BIGNUM_INT_BITS - mshift));
  45636. + a[2 * mlen - 1] = a[2 * mlen - 1] << mshift;
  45637. + internal_mod(a, mlen * 2, m, mlen, NULL, 0);
  45638. + for (i = 2 * mlen - 1; i >= mlen; i--)
  45639. + a[i] =
  45640. + (a[i] >> mshift) | (a[i - 1] <<
  45641. + (BIGNUM_INT_BITS - mshift));
  45642. + }
  45643. +
  45644. + /* Copy result to buffer */
  45645. + result = newbn(mem_ctx, mod[0]);
  45646. + for (i = 0; i < mlen; i++)
  45647. + result[result[0] - i] = a[i + mlen];
  45648. + while (result[0] > 1 && result[result[0]] == 0)
  45649. + result[0]--;
  45650. +
  45651. + /* Free temporary arrays */
  45652. + for (i = 0; i < 2 * mlen; i++)
  45653. + a[i] = 0;
  45654. + sfree(mem_ctx, a);
  45655. + for (i = 0; i < 2 * mlen; i++)
  45656. + b[i] = 0;
  45657. + sfree(mem_ctx, b);
  45658. + for (i = 0; i < mlen; i++)
  45659. + m[i] = 0;
  45660. + sfree(mem_ctx, m);
  45661. + for (i = 0; i < mlen; i++)
  45662. + n[i] = 0;
  45663. + sfree(mem_ctx, n);
  45664. +
  45665. + freebn(mem_ctx, base);
  45666. +
  45667. + return result;
  45668. +}
  45669. +
  45670. +
  45671. +#ifdef UNITTEST
  45672. +
  45673. +static __u32 dh_p[] = {
  45674. + 96,
  45675. + 0xFFFFFFFF,
  45676. + 0xFFFFFFFF,
  45677. + 0xA93AD2CA,
  45678. + 0x4B82D120,
  45679. + 0xE0FD108E,
  45680. + 0x43DB5BFC,
  45681. + 0x74E5AB31,
  45682. + 0x08E24FA0,
  45683. + 0xBAD946E2,
  45684. + 0x770988C0,
  45685. + 0x7A615D6C,
  45686. + 0xBBE11757,
  45687. + 0x177B200C,
  45688. + 0x521F2B18,
  45689. + 0x3EC86A64,
  45690. + 0xD8760273,
  45691. + 0xD98A0864,
  45692. + 0xF12FFA06,
  45693. + 0x1AD2EE6B,
  45694. + 0xCEE3D226,
  45695. + 0x4A25619D,
  45696. + 0x1E8C94E0,
  45697. + 0xDB0933D7,
  45698. + 0xABF5AE8C,
  45699. + 0xA6E1E4C7,
  45700. + 0xB3970F85,
  45701. + 0x5D060C7D,
  45702. + 0x8AEA7157,
  45703. + 0x58DBEF0A,
  45704. + 0xECFB8504,
  45705. + 0xDF1CBA64,
  45706. + 0xA85521AB,
  45707. + 0x04507A33,
  45708. + 0xAD33170D,
  45709. + 0x8AAAC42D,
  45710. + 0x15728E5A,
  45711. + 0x98FA0510,
  45712. + 0x15D22618,
  45713. + 0xEA956AE5,
  45714. + 0x3995497C,
  45715. + 0x95581718,
  45716. + 0xDE2BCBF6,
  45717. + 0x6F4C52C9,
  45718. + 0xB5C55DF0,
  45719. + 0xEC07A28F,
  45720. + 0x9B2783A2,
  45721. + 0x180E8603,
  45722. + 0xE39E772C,
  45723. + 0x2E36CE3B,
  45724. + 0x32905E46,
  45725. + 0xCA18217C,
  45726. + 0xF1746C08,
  45727. + 0x4ABC9804,
  45728. + 0x670C354E,
  45729. + 0x7096966D,
  45730. + 0x9ED52907,
  45731. + 0x208552BB,
  45732. + 0x1C62F356,
  45733. + 0xDCA3AD96,
  45734. + 0x83655D23,
  45735. + 0xFD24CF5F,
  45736. + 0x69163FA8,
  45737. + 0x1C55D39A,
  45738. + 0x98DA4836,
  45739. + 0xA163BF05,
  45740. + 0xC2007CB8,
  45741. + 0xECE45B3D,
  45742. + 0x49286651,
  45743. + 0x7C4B1FE6,
  45744. + 0xAE9F2411,
  45745. + 0x5A899FA5,
  45746. + 0xEE386BFB,
  45747. + 0xF406B7ED,
  45748. + 0x0BFF5CB6,
  45749. + 0xA637ED6B,
  45750. + 0xF44C42E9,
  45751. + 0x625E7EC6,
  45752. + 0xE485B576,
  45753. + 0x6D51C245,
  45754. + 0x4FE1356D,
  45755. + 0xF25F1437,
  45756. + 0x302B0A6D,
  45757. + 0xCD3A431B,
  45758. + 0xEF9519B3,
  45759. + 0x8E3404DD,
  45760. + 0x514A0879,
  45761. + 0x3B139B22,
  45762. + 0x020BBEA6,
  45763. + 0x8A67CC74,
  45764. + 0x29024E08,
  45765. + 0x80DC1CD1,
  45766. + 0xC4C6628B,
  45767. + 0x2168C234,
  45768. + 0xC90FDAA2,
  45769. + 0xFFFFFFFF,
  45770. + 0xFFFFFFFF,
  45771. +};
  45772. +
  45773. +static __u32 dh_a[] = {
  45774. + 8,
  45775. + 0xdf367516,
  45776. + 0x86459caa,
  45777. + 0xe2d459a4,
  45778. + 0xd910dae0,
  45779. + 0x8a8b5e37,
  45780. + 0x67ab31c6,
  45781. + 0xf0b55ea9,
  45782. + 0x440051d6,
  45783. +};
  45784. +
  45785. +static __u32 dh_b[] = {
  45786. + 8,
  45787. + 0xded92656,
  45788. + 0xe07a048a,
  45789. + 0x6fa452cd,
  45790. + 0x2df89d30,
  45791. + 0xc75f1b0f,
  45792. + 0x8ce3578f,
  45793. + 0x7980a324,
  45794. + 0x5daec786,
  45795. +};
  45796. +
  45797. +static __u32 dh_g[] = {
  45798. + 1,
  45799. + 2,
  45800. +};
  45801. +
  45802. +int main(void)
  45803. +{
  45804. + int i;
  45805. + __u32 *k;
  45806. + k = dwc_modpow(NULL, dh_g, dh_a, dh_p);
  45807. +
  45808. + printf("\n\n");
  45809. + for (i=0; i<k[0]; i++) {
  45810. + __u32 word32 = k[k[0] - i];
  45811. + __u16 l = word32 & 0xffff;
  45812. + __u16 m = (word32 & 0xffff0000) >> 16;
  45813. + printf("%04x %04x ", m, l);
  45814. + if (!((i + 1)%13)) printf("\n");
  45815. + }
  45816. + printf("\n\n");
  45817. +
  45818. + if ((k[0] == 0x60) && (k[1] == 0x28e490e5) && (k[0x60] == 0x5a0d3d4e)) {
  45819. + printf("PASS\n\n");
  45820. + }
  45821. + else {
  45822. + printf("FAIL\n\n");
  45823. + }
  45824. +
  45825. +}
  45826. +
  45827. +#endif /* UNITTEST */
  45828. +
  45829. +#endif /* CONFIG_MACH_IPMATE */
  45830. +
  45831. +#endif /*DWC_CRYPTOLIB */
  45832. diff -Nur linux-3.13.11/drivers/usb/host/dwc_common_port/dwc_modpow.h linux-rpi/drivers/usb/host/dwc_common_port/dwc_modpow.h
  45833. --- linux-3.13.11/drivers/usb/host/dwc_common_port/dwc_modpow.h 1970-01-01 01:00:00.000000000 +0100
  45834. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_modpow.h 2014-04-24 15:35:04.169565731 +0200
  45835. @@ -0,0 +1,34 @@
  45836. +/*
  45837. + * dwc_modpow.h
  45838. + * See dwc_modpow.c for license and changes
  45839. + */
  45840. +#ifndef _DWC_MODPOW_H
  45841. +#define _DWC_MODPOW_H
  45842. +
  45843. +#ifdef __cplusplus
  45844. +extern "C" {
  45845. +#endif
  45846. +
  45847. +#include "dwc_os.h"
  45848. +
  45849. +/** @file
  45850. + *
  45851. + * This file defines the module exponentiation function which is only used
  45852. + * internally by the DWC UWB modules for calculation of PKs during numeric
  45853. + * association. The routine is taken from the PUTTY, an open source terminal
  45854. + * emulator. The PUTTY License is preserved in the dwc_modpow.c file.
  45855. + *
  45856. + */
  45857. +
  45858. +typedef uint32_t BignumInt;
  45859. +typedef uint64_t BignumDblInt;
  45860. +typedef BignumInt *Bignum;
  45861. +
  45862. +/* Compute modular exponentiaion */
  45863. +extern Bignum dwc_modpow(void *mem_ctx, Bignum base_in, Bignum exp, Bignum mod);
  45864. +
  45865. +#ifdef __cplusplus
  45866. +}
  45867. +#endif
  45868. +
  45869. +#endif /* _LINUX_BIGNUM_H */
  45870. diff -Nur linux-3.13.11/drivers/usb/host/dwc_common_port/dwc_notifier.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_notifier.c
  45871. --- linux-3.13.11/drivers/usb/host/dwc_common_port/dwc_notifier.c 1970-01-01 01:00:00.000000000 +0100
  45872. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_notifier.c 2014-04-24 15:35:04.169565731 +0200
  45873. @@ -0,0 +1,319 @@
  45874. +#ifdef DWC_NOTIFYLIB
  45875. +
  45876. +#include "dwc_notifier.h"
  45877. +#include "dwc_list.h"
  45878. +
  45879. +typedef struct dwc_observer {
  45880. + void *observer;
  45881. + dwc_notifier_callback_t callback;
  45882. + void *data;
  45883. + char *notification;
  45884. + DWC_CIRCLEQ_ENTRY(dwc_observer) list_entry;
  45885. +} observer_t;
  45886. +
  45887. +DWC_CIRCLEQ_HEAD(observer_queue, dwc_observer);
  45888. +
  45889. +typedef struct dwc_notifier {
  45890. + void *mem_ctx;
  45891. + void *object;
  45892. + struct observer_queue observers;
  45893. + DWC_CIRCLEQ_ENTRY(dwc_notifier) list_entry;
  45894. +} notifier_t;
  45895. +
  45896. +DWC_CIRCLEQ_HEAD(notifier_queue, dwc_notifier);
  45897. +
  45898. +typedef struct manager {
  45899. + void *mem_ctx;
  45900. + void *wkq_ctx;
  45901. + dwc_workq_t *wq;
  45902. +// dwc_mutex_t *mutex;
  45903. + struct notifier_queue notifiers;
  45904. +} manager_t;
  45905. +
  45906. +static manager_t *manager = NULL;
  45907. +
  45908. +static int create_manager(void *mem_ctx, void *wkq_ctx)
  45909. +{
  45910. + manager = dwc_alloc(mem_ctx, sizeof(manager_t));
  45911. + if (!manager) {
  45912. + return -DWC_E_NO_MEMORY;
  45913. + }
  45914. +
  45915. + DWC_CIRCLEQ_INIT(&manager->notifiers);
  45916. +
  45917. + manager->wq = dwc_workq_alloc(wkq_ctx, "DWC Notification WorkQ");
  45918. + if (!manager->wq) {
  45919. + return -DWC_E_NO_MEMORY;
  45920. + }
  45921. +
  45922. + return 0;
  45923. +}
  45924. +
  45925. +static void free_manager(void)
  45926. +{
  45927. + dwc_workq_free(manager->wq);
  45928. +
  45929. + /* All notifiers must have unregistered themselves before this module
  45930. + * can be removed. Hitting this assertion indicates a programmer
  45931. + * error. */
  45932. + DWC_ASSERT(DWC_CIRCLEQ_EMPTY(&manager->notifiers),
  45933. + "Notification manager being freed before all notifiers have been removed");
  45934. + dwc_free(manager->mem_ctx, manager);
  45935. +}
  45936. +
  45937. +#ifdef DEBUG
  45938. +static void dump_manager(void)
  45939. +{
  45940. + notifier_t *n;
  45941. + observer_t *o;
  45942. +
  45943. + DWC_ASSERT(manager, "Notification manager not found");
  45944. +
  45945. + DWC_DEBUG("List of all notifiers and observers:\n");
  45946. + DWC_CIRCLEQ_FOREACH(n, &manager->notifiers, list_entry) {
  45947. + DWC_DEBUG("Notifier %p has observers:\n", n->object);
  45948. + DWC_CIRCLEQ_FOREACH(o, &n->observers, list_entry) {
  45949. + DWC_DEBUG(" %p watching %s\n", o->observer, o->notification);
  45950. + }
  45951. + }
  45952. +}
  45953. +#else
  45954. +#define dump_manager(...)
  45955. +#endif
  45956. +
  45957. +static observer_t *alloc_observer(void *mem_ctx, void *observer, char *notification,
  45958. + dwc_notifier_callback_t callback, void *data)
  45959. +{
  45960. + observer_t *new_observer = dwc_alloc(mem_ctx, sizeof(observer_t));
  45961. +
  45962. + if (!new_observer) {
  45963. + return NULL;
  45964. + }
  45965. +
  45966. + DWC_CIRCLEQ_INIT_ENTRY(new_observer, list_entry);
  45967. + new_observer->observer = observer;
  45968. + new_observer->notification = notification;
  45969. + new_observer->callback = callback;
  45970. + new_observer->data = data;
  45971. + return new_observer;
  45972. +}
  45973. +
  45974. +static void free_observer(void *mem_ctx, observer_t *observer)
  45975. +{
  45976. + dwc_free(mem_ctx, observer);
  45977. +}
  45978. +
  45979. +static notifier_t *alloc_notifier(void *mem_ctx, void *object)
  45980. +{
  45981. + notifier_t *notifier;
  45982. +
  45983. + if (!object) {
  45984. + return NULL;
  45985. + }
  45986. +
  45987. + notifier = dwc_alloc(mem_ctx, sizeof(notifier_t));
  45988. + if (!notifier) {
  45989. + return NULL;
  45990. + }
  45991. +
  45992. + DWC_CIRCLEQ_INIT(&notifier->observers);
  45993. + DWC_CIRCLEQ_INIT_ENTRY(notifier, list_entry);
  45994. +
  45995. + notifier->mem_ctx = mem_ctx;
  45996. + notifier->object = object;
  45997. + return notifier;
  45998. +}
  45999. +
  46000. +static void free_notifier(notifier_t *notifier)
  46001. +{
  46002. + observer_t *observer;
  46003. +
  46004. + DWC_CIRCLEQ_FOREACH(observer, &notifier->observers, list_entry) {
  46005. + free_observer(notifier->mem_ctx, observer);
  46006. + }
  46007. +
  46008. + dwc_free(notifier->mem_ctx, notifier);
  46009. +}
  46010. +
  46011. +static notifier_t *find_notifier(void *object)
  46012. +{
  46013. + notifier_t *notifier;
  46014. +
  46015. + DWC_ASSERT(manager, "Notification manager not found");
  46016. +
  46017. + if (!object) {
  46018. + return NULL;
  46019. + }
  46020. +
  46021. + DWC_CIRCLEQ_FOREACH(notifier, &manager->notifiers, list_entry) {
  46022. + if (notifier->object == object) {
  46023. + return notifier;
  46024. + }
  46025. + }
  46026. +
  46027. + return NULL;
  46028. +}
  46029. +
  46030. +int dwc_alloc_notification_manager(void *mem_ctx, void *wkq_ctx)
  46031. +{
  46032. + return create_manager(mem_ctx, wkq_ctx);
  46033. +}
  46034. +
  46035. +void dwc_free_notification_manager(void)
  46036. +{
  46037. + free_manager();
  46038. +}
  46039. +
  46040. +dwc_notifier_t *dwc_register_notifier(void *mem_ctx, void *object)
  46041. +{
  46042. + notifier_t *notifier;
  46043. +
  46044. + DWC_ASSERT(manager, "Notification manager not found");
  46045. +
  46046. + notifier = find_notifier(object);
  46047. + if (notifier) {
  46048. + DWC_ERROR("Notifier %p is already registered\n", object);
  46049. + return NULL;
  46050. + }
  46051. +
  46052. + notifier = alloc_notifier(mem_ctx, object);
  46053. + if (!notifier) {
  46054. + return NULL;
  46055. + }
  46056. +
  46057. + DWC_CIRCLEQ_INSERT_TAIL(&manager->notifiers, notifier, list_entry);
  46058. +
  46059. + DWC_INFO("Notifier %p registered", object);
  46060. + dump_manager();
  46061. +
  46062. + return notifier;
  46063. +}
  46064. +
  46065. +void dwc_unregister_notifier(dwc_notifier_t *notifier)
  46066. +{
  46067. + DWC_ASSERT(manager, "Notification manager not found");
  46068. +
  46069. + if (!DWC_CIRCLEQ_EMPTY(&notifier->observers)) {
  46070. + observer_t *o;
  46071. +
  46072. + DWC_ERROR("Notifier %p has active observers when removing\n", notifier->object);
  46073. + DWC_CIRCLEQ_FOREACH(o, &notifier->observers, list_entry) {
  46074. + DWC_DEBUGC(" %p watching %s\n", o->observer, o->notification);
  46075. + }
  46076. +
  46077. + DWC_ASSERT(DWC_CIRCLEQ_EMPTY(&notifier->observers),
  46078. + "Notifier %p has active observers when removing", notifier);
  46079. + }
  46080. +
  46081. + DWC_CIRCLEQ_REMOVE_INIT(&manager->notifiers, notifier, list_entry);
  46082. + free_notifier(notifier);
  46083. +
  46084. + DWC_INFO("Notifier unregistered");
  46085. + dump_manager();
  46086. +}
  46087. +
  46088. +/* Add an observer to observe the notifier for a particular state, event, or notification. */
  46089. +int dwc_add_observer(void *observer, void *object, char *notification,
  46090. + dwc_notifier_callback_t callback, void *data)
  46091. +{
  46092. + notifier_t *notifier = find_notifier(object);
  46093. + observer_t *new_observer;
  46094. +
  46095. + if (!notifier) {
  46096. + DWC_ERROR("Notifier %p is not found when adding observer\n", object);
  46097. + return -DWC_E_INVALID;
  46098. + }
  46099. +
  46100. + new_observer = alloc_observer(notifier->mem_ctx, observer, notification, callback, data);
  46101. + if (!new_observer) {
  46102. + return -DWC_E_NO_MEMORY;
  46103. + }
  46104. +
  46105. + DWC_CIRCLEQ_INSERT_TAIL(&notifier->observers, new_observer, list_entry);
  46106. +
  46107. + DWC_INFO("Added observer %p to notifier %p observing notification %s, callback=%p, data=%p",
  46108. + observer, object, notification, callback, data);
  46109. +
  46110. + dump_manager();
  46111. + return 0;
  46112. +}
  46113. +
  46114. +int dwc_remove_observer(void *observer)
  46115. +{
  46116. + notifier_t *n;
  46117. +
  46118. + DWC_ASSERT(manager, "Notification manager not found");
  46119. +
  46120. + DWC_CIRCLEQ_FOREACH(n, &manager->notifiers, list_entry) {
  46121. + observer_t *o;
  46122. + observer_t *o2;
  46123. +
  46124. + DWC_CIRCLEQ_FOREACH_SAFE(o, o2, &n->observers, list_entry) {
  46125. + if (o->observer == observer) {
  46126. + DWC_CIRCLEQ_REMOVE_INIT(&n->observers, o, list_entry);
  46127. + DWC_INFO("Removing observer %p from notifier %p watching notification %s:",
  46128. + o->observer, n->object, o->notification);
  46129. + free_observer(n->mem_ctx, o);
  46130. + }
  46131. + }
  46132. + }
  46133. +
  46134. + dump_manager();
  46135. + return 0;
  46136. +}
  46137. +
  46138. +typedef struct callback_data {
  46139. + void *mem_ctx;
  46140. + dwc_notifier_callback_t cb;
  46141. + void *observer;
  46142. + void *data;
  46143. + void *object;
  46144. + char *notification;
  46145. + void *notification_data;
  46146. +} cb_data_t;
  46147. +
  46148. +static void cb_task(void *data)
  46149. +{
  46150. + cb_data_t *cb = (cb_data_t *)data;
  46151. +
  46152. + cb->cb(cb->object, cb->notification, cb->observer, cb->notification_data, cb->data);
  46153. + dwc_free(cb->mem_ctx, cb);
  46154. +}
  46155. +
  46156. +void dwc_notify(dwc_notifier_t *notifier, char *notification, void *notification_data)
  46157. +{
  46158. + observer_t *o;
  46159. +
  46160. + DWC_ASSERT(manager, "Notification manager not found");
  46161. +
  46162. + DWC_CIRCLEQ_FOREACH(o, &notifier->observers, list_entry) {
  46163. + int len = DWC_STRLEN(notification);
  46164. +
  46165. + if (DWC_STRLEN(o->notification) != len) {
  46166. + continue;
  46167. + }
  46168. +
  46169. + if (DWC_STRNCMP(o->notification, notification, len) == 0) {
  46170. + cb_data_t *cb_data = dwc_alloc(notifier->mem_ctx, sizeof(cb_data_t));
  46171. +
  46172. + if (!cb_data) {
  46173. + DWC_ERROR("Failed to allocate callback data\n");
  46174. + return;
  46175. + }
  46176. +
  46177. + cb_data->mem_ctx = notifier->mem_ctx;
  46178. + cb_data->cb = o->callback;
  46179. + cb_data->observer = o->observer;
  46180. + cb_data->data = o->data;
  46181. + cb_data->object = notifier->object;
  46182. + cb_data->notification = notification;
  46183. + cb_data->notification_data = notification_data;
  46184. + DWC_DEBUGC("Observer found %p for notification %s\n", o->observer, notification);
  46185. + DWC_WORKQ_SCHEDULE(manager->wq, cb_task, cb_data,
  46186. + "Notify callback from %p for Notification %s, to observer %p",
  46187. + cb_data->object, notification, cb_data->observer);
  46188. + }
  46189. + }
  46190. +}
  46191. +
  46192. +#endif /* DWC_NOTIFYLIB */
  46193. diff -Nur linux-3.13.11/drivers/usb/host/dwc_common_port/dwc_notifier.h linux-rpi/drivers/usb/host/dwc_common_port/dwc_notifier.h
  46194. --- linux-3.13.11/drivers/usb/host/dwc_common_port/dwc_notifier.h 1970-01-01 01:00:00.000000000 +0100
  46195. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_notifier.h 2014-04-24 15:35:04.169565731 +0200
  46196. @@ -0,0 +1,122 @@
  46197. +
  46198. +#ifndef __DWC_NOTIFIER_H__
  46199. +#define __DWC_NOTIFIER_H__
  46200. +
  46201. +#ifdef __cplusplus
  46202. +extern "C" {
  46203. +#endif
  46204. +
  46205. +#include "dwc_os.h"
  46206. +
  46207. +/** @file
  46208. + *
  46209. + * A simple implementation of the Observer pattern. Any "module" can
  46210. + * register as an observer or notifier. The notion of "module" is abstract and
  46211. + * can mean anything used to identify either an observer or notifier. Usually
  46212. + * it will be a pointer to a data structure which contains some state, ie an
  46213. + * object.
  46214. + *
  46215. + * Before any notifiers can be added, the global notification manager must be
  46216. + * brought up with dwc_alloc_notification_manager().
  46217. + * dwc_free_notification_manager() will bring it down and free all resources.
  46218. + * These would typically be called upon module load and unload. The
  46219. + * notification manager is a single global instance that handles all registered
  46220. + * observable modules and observers so this should be done only once.
  46221. + *
  46222. + * A module can be observable by using Notifications to publicize some general
  46223. + * information about it's state or operation. It does not care who listens, or
  46224. + * even if anyone listens, or what they do with the information. The observable
  46225. + * modules do not need to know any information about it's observers or their
  46226. + * interface, or their state or data.
  46227. + *
  46228. + * Any module can register to emit Notifications. It should publish a list of
  46229. + * notifications that it can emit and their behavior, such as when they will get
  46230. + * triggered, and what information will be provided to the observer. Then it
  46231. + * should register itself as an observable module. See dwc_register_notifier().
  46232. + *
  46233. + * Any module can observe any observable, registered module, provided it has a
  46234. + * handle to the other module and knows what notifications to observe. See
  46235. + * dwc_add_observer().
  46236. + *
  46237. + * A function of type dwc_notifier_callback_t is called whenever a notification
  46238. + * is triggered with one or more observers observing it. This function is
  46239. + * called in it's own process so it may sleep or block if needed. It is
  46240. + * guaranteed to be called sometime after the notification has occurred and will
  46241. + * be called once per each time the notification is triggered. It will NOT be
  46242. + * called in the same process context used to trigger the notification.
  46243. + *
  46244. + * @section Limitiations
  46245. + *
  46246. + * Keep in mind that Notifications that can be triggered in rapid sucession may
  46247. + * schedule too many processes too handle. Be aware of this limitation when
  46248. + * designing to use notifications, and only add notifications for appropriate
  46249. + * observable information.
  46250. + *
  46251. + * Also Notification callbacks are not synchronous. If you need to synchronize
  46252. + * the behavior between module/observer you must use other means. And perhaps
  46253. + * that will mean Notifications are not the proper solution.
  46254. + */
  46255. +
  46256. +struct dwc_notifier;
  46257. +typedef struct dwc_notifier dwc_notifier_t;
  46258. +
  46259. +/** The callback function must be of this type.
  46260. + *
  46261. + * @param object This is the object that is being observed.
  46262. + * @param notification This is the notification that was triggered.
  46263. + * @param observer This is the observer
  46264. + * @param notification_data This is notification-specific data that the notifier
  46265. + * has included in this notification. The value of this should be published in
  46266. + * the documentation of the observable module with the notifications.
  46267. + * @param user_data This is any custom data that the observer provided when
  46268. + * adding itself as an observer to the notification. */
  46269. +typedef void (*dwc_notifier_callback_t)(void *object, char *notification, void *observer,
  46270. + void *notification_data, void *user_data);
  46271. +
  46272. +/** Brings up the notification manager. */
  46273. +extern int dwc_alloc_notification_manager(void *mem_ctx, void *wkq_ctx);
  46274. +/** Brings down the notification manager. */
  46275. +extern void dwc_free_notification_manager(void);
  46276. +
  46277. +/** This function registers an observable module. A dwc_notifier_t object is
  46278. + * returned to the observable module. This is an opaque object that is used by
  46279. + * the observable module to trigger notifications. This object should only be
  46280. + * accessible to functions that are authorized to trigger notifications for this
  46281. + * module. Observers do not need this object. */
  46282. +extern dwc_notifier_t *dwc_register_notifier(void *mem_ctx, void *object);
  46283. +
  46284. +/** This function unregisters an observable module. All observers have to be
  46285. + * removed prior to unregistration. */
  46286. +extern void dwc_unregister_notifier(dwc_notifier_t *notifier);
  46287. +
  46288. +/** Add a module as an observer to the observable module. The observable module
  46289. + * needs to have previously registered with the notification manager.
  46290. + *
  46291. + * @param observer The observer module
  46292. + * @param object The module to observe
  46293. + * @param notification The notification to observe
  46294. + * @param callback The callback function to call
  46295. + * @param user_data Any additional user data to pass into the callback function */
  46296. +extern int dwc_add_observer(void *observer, void *object, char *notification,
  46297. + dwc_notifier_callback_t callback, void *user_data);
  46298. +
  46299. +/** Removes the specified observer from all notifications that it is currently
  46300. + * observing. */
  46301. +extern int dwc_remove_observer(void *observer);
  46302. +
  46303. +/** This function triggers a Notification. It should be called by the
  46304. + * observable module, or any module or library which the observable module
  46305. + * allows to trigger notification on it's behalf. Such as the dwc_cc_t.
  46306. + *
  46307. + * dwc_notify is a non-blocking function. Callbacks are scheduled called in
  46308. + * their own process context for each trigger. Callbacks can be blocking.
  46309. + * dwc_notify can be called from interrupt context if needed.
  46310. + *
  46311. + */
  46312. +void dwc_notify(dwc_notifier_t *notifier, char *notification, void *notification_data);
  46313. +
  46314. +#ifdef __cplusplus
  46315. +}
  46316. +#endif
  46317. +
  46318. +#endif /* __DWC_NOTIFIER_H__ */
  46319. diff -Nur linux-3.13.11/drivers/usb/host/dwc_common_port/dwc_os.h linux-rpi/drivers/usb/host/dwc_common_port/dwc_os.h
  46320. --- linux-3.13.11/drivers/usb/host/dwc_common_port/dwc_os.h 1970-01-01 01:00:00.000000000 +0100
  46321. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_os.h 2014-04-24 15:37:13.306990445 +0200
  46322. @@ -0,0 +1,1262 @@
  46323. +/* =========================================================================
  46324. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_os.h $
  46325. + * $Revision: #14 $
  46326. + * $Date: 2010/11/04 $
  46327. + * $Change: 1621695 $
  46328. + *
  46329. + * Synopsys Portability Library Software and documentation
  46330. + * (hereinafter, "Software") is an Unsupported proprietary work of
  46331. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  46332. + * between Synopsys and you.
  46333. + *
  46334. + * The Software IS NOT an item of Licensed Software or Licensed Product
  46335. + * under any End User Software License Agreement or Agreement for
  46336. + * Licensed Product with Synopsys or any supplement thereto. You are
  46337. + * permitted to use and redistribute this Software in source and binary
  46338. + * forms, with or without modification, provided that redistributions
  46339. + * of source code must retain this notice. You may not view, use,
  46340. + * disclose, copy or distribute this file or any information contained
  46341. + * herein except pursuant to this license grant from Synopsys. If you
  46342. + * do not agree with this notice, including the disclaimer below, then
  46343. + * you are not authorized to use the Software.
  46344. + *
  46345. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  46346. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  46347. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  46348. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  46349. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  46350. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  46351. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  46352. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  46353. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  46354. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  46355. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  46356. + * DAMAGE.
  46357. + * ========================================================================= */
  46358. +#ifndef _DWC_OS_H_
  46359. +#define _DWC_OS_H_
  46360. +
  46361. +#ifdef __cplusplus
  46362. +extern "C" {
  46363. +#endif
  46364. +
  46365. +/** @file
  46366. + *
  46367. + * DWC portability library, low level os-wrapper functions
  46368. + *
  46369. + */
  46370. +
  46371. +/* These basic types need to be defined by some OS header file or custom header
  46372. + * file for your specific target architecture.
  46373. + *
  46374. + * uint8_t, int8_t, uint16_t, int16_t, uint32_t, int32_t, uint64_t, int64_t
  46375. + *
  46376. + * Any custom or alternate header file must be added and enabled here.
  46377. + */
  46378. +
  46379. +#ifdef DWC_LINUX
  46380. +# include <linux/types.h>
  46381. +# ifdef CONFIG_DEBUG_MUTEXES
  46382. +# include <linux/mutex.h>
  46383. +# endif
  46384. +# include <linux/errno.h>
  46385. +# include <stdarg.h>
  46386. +#endif
  46387. +
  46388. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  46389. +# include <os_dep.h>
  46390. +#endif
  46391. +
  46392. +
  46393. +/** @name Primitive Types and Values */
  46394. +
  46395. +/** We define a boolean type for consistency. Can be either YES or NO */
  46396. +typedef uint8_t dwc_bool_t;
  46397. +#define YES 1
  46398. +#define NO 0
  46399. +
  46400. +#ifdef DWC_LINUX
  46401. +
  46402. +/** @name Error Codes */
  46403. +#define DWC_E_INVALID EINVAL
  46404. +#define DWC_E_NO_MEMORY ENOMEM
  46405. +#define DWC_E_NO_DEVICE ENODEV
  46406. +#define DWC_E_NOT_SUPPORTED EOPNOTSUPP
  46407. +#define DWC_E_TIMEOUT ETIMEDOUT
  46408. +#define DWC_E_BUSY EBUSY
  46409. +#define DWC_E_AGAIN EAGAIN
  46410. +#define DWC_E_RESTART ERESTART
  46411. +#define DWC_E_ABORT ECONNABORTED
  46412. +#define DWC_E_SHUTDOWN ESHUTDOWN
  46413. +#define DWC_E_NO_DATA ENODATA
  46414. +#define DWC_E_DISCONNECT ECONNRESET
  46415. +#define DWC_E_UNKNOWN EINVAL
  46416. +#define DWC_E_NO_STREAM_RES ENOSR
  46417. +#define DWC_E_COMMUNICATION ECOMM
  46418. +#define DWC_E_OVERFLOW EOVERFLOW
  46419. +#define DWC_E_PROTOCOL EPROTO
  46420. +#define DWC_E_IN_PROGRESS EINPROGRESS
  46421. +#define DWC_E_PIPE EPIPE
  46422. +#define DWC_E_IO EIO
  46423. +#define DWC_E_NO_SPACE ENOSPC
  46424. +
  46425. +#else
  46426. +
  46427. +/** @name Error Codes */
  46428. +#define DWC_E_INVALID 1001
  46429. +#define DWC_E_NO_MEMORY 1002
  46430. +#define DWC_E_NO_DEVICE 1003
  46431. +#define DWC_E_NOT_SUPPORTED 1004
  46432. +#define DWC_E_TIMEOUT 1005
  46433. +#define DWC_E_BUSY 1006
  46434. +#define DWC_E_AGAIN 1007
  46435. +#define DWC_E_RESTART 1008
  46436. +#define DWC_E_ABORT 1009
  46437. +#define DWC_E_SHUTDOWN 1010
  46438. +#define DWC_E_NO_DATA 1011
  46439. +#define DWC_E_DISCONNECT 2000
  46440. +#define DWC_E_UNKNOWN 3000
  46441. +#define DWC_E_NO_STREAM_RES 4001
  46442. +#define DWC_E_COMMUNICATION 4002
  46443. +#define DWC_E_OVERFLOW 4003
  46444. +#define DWC_E_PROTOCOL 4004
  46445. +#define DWC_E_IN_PROGRESS 4005
  46446. +#define DWC_E_PIPE 4006
  46447. +#define DWC_E_IO 4007
  46448. +#define DWC_E_NO_SPACE 4008
  46449. +
  46450. +#endif
  46451. +
  46452. +
  46453. +/** @name Tracing/Logging Functions
  46454. + *
  46455. + * These function provide the capability to add tracing, debugging, and error
  46456. + * messages, as well exceptions as assertions. The WUDEV uses these
  46457. + * extensively. These could be logged to the main console, the serial port, an
  46458. + * internal buffer, etc. These functions could also be no-op if they are too
  46459. + * expensive on your system. By default undefining the DEBUG macro already
  46460. + * no-ops some of these functions. */
  46461. +
  46462. +/** Returns non-zero if in interrupt context. */
  46463. +extern dwc_bool_t DWC_IN_IRQ(void);
  46464. +#define dwc_in_irq DWC_IN_IRQ
  46465. +
  46466. +/** Returns "IRQ" if DWC_IN_IRQ is true. */
  46467. +static inline char *dwc_irq(void) {
  46468. + return DWC_IN_IRQ() ? "IRQ" : "";
  46469. +}
  46470. +
  46471. +/** Returns non-zero if in bottom-half context. */
  46472. +extern dwc_bool_t DWC_IN_BH(void);
  46473. +#define dwc_in_bh DWC_IN_BH
  46474. +
  46475. +/** Returns "BH" if DWC_IN_BH is true. */
  46476. +static inline char *dwc_bh(void) {
  46477. + return DWC_IN_BH() ? "BH" : "";
  46478. +}
  46479. +
  46480. +/**
  46481. + * A vprintf() clone. Just call vprintf if you've got it.
  46482. + */
  46483. +extern void DWC_VPRINTF(char *format, va_list args);
  46484. +#define dwc_vprintf DWC_VPRINTF
  46485. +
  46486. +/**
  46487. + * A vsnprintf() clone. Just call vprintf if you've got it.
  46488. + */
  46489. +extern int DWC_VSNPRINTF(char *str, int size, char *format, va_list args);
  46490. +#define dwc_vsnprintf DWC_VSNPRINTF
  46491. +
  46492. +/**
  46493. + * printf() clone. Just call printf if you've go it.
  46494. + */
  46495. +extern void DWC_PRINTF(char *format, ...)
  46496. +/* This provides compiler level static checking of the parameters if you're
  46497. + * using GCC. */
  46498. +#ifdef __GNUC__
  46499. + __attribute__ ((format(printf, 1, 2)));
  46500. +#else
  46501. + ;
  46502. +#endif
  46503. +#define dwc_printf DWC_PRINTF
  46504. +
  46505. +/**
  46506. + * sprintf() clone. Just call sprintf if you've got it.
  46507. + */
  46508. +extern int DWC_SPRINTF(char *string, char *format, ...)
  46509. +#ifdef __GNUC__
  46510. + __attribute__ ((format(printf, 2, 3)));
  46511. +#else
  46512. + ;
  46513. +#endif
  46514. +#define dwc_sprintf DWC_SPRINTF
  46515. +
  46516. +/**
  46517. + * snprintf() clone. Just call snprintf if you've got it.
  46518. + */
  46519. +extern int DWC_SNPRINTF(char *string, int size, char *format, ...)
  46520. +#ifdef __GNUC__
  46521. + __attribute__ ((format(printf, 3, 4)));
  46522. +#else
  46523. + ;
  46524. +#endif
  46525. +#define dwc_snprintf DWC_SNPRINTF
  46526. +
  46527. +/**
  46528. + * Prints a WARNING message. On systems that don't differentiate between
  46529. + * warnings and regular log messages, just print it. Indicates that something
  46530. + * may be wrong with the driver. Works like printf().
  46531. + *
  46532. + * Use the DWC_WARN macro to call this function.
  46533. + */
  46534. +extern void __DWC_WARN(char *format, ...)
  46535. +#ifdef __GNUC__
  46536. + __attribute__ ((format(printf, 1, 2)));
  46537. +#else
  46538. + ;
  46539. +#endif
  46540. +
  46541. +/**
  46542. + * Prints an error message. On systems that don't differentiate between errors
  46543. + * and regular log messages, just print it. Indicates that something went wrong
  46544. + * with the driver. Works like printf().
  46545. + *
  46546. + * Use the DWC_ERROR macro to call this function.
  46547. + */
  46548. +extern void __DWC_ERROR(char *format, ...)
  46549. +#ifdef __GNUC__
  46550. + __attribute__ ((format(printf, 1, 2)));
  46551. +#else
  46552. + ;
  46553. +#endif
  46554. +
  46555. +/**
  46556. + * Prints an exception error message and takes some user-defined action such as
  46557. + * print out a backtrace or trigger a breakpoint. Indicates that something went
  46558. + * abnormally wrong with the driver such as programmer error, or other
  46559. + * exceptional condition. It should not be ignored so even on systems without
  46560. + * printing capability, some action should be taken to notify the developer of
  46561. + * it. Works like printf().
  46562. + */
  46563. +extern void DWC_EXCEPTION(char *format, ...)
  46564. +#ifdef __GNUC__
  46565. + __attribute__ ((format(printf, 1, 2)));
  46566. +#else
  46567. + ;
  46568. +#endif
  46569. +#define dwc_exception DWC_EXCEPTION
  46570. +
  46571. +#ifndef DWC_OTG_DEBUG_LEV
  46572. +#define DWC_OTG_DEBUG_LEV 0
  46573. +#endif
  46574. +
  46575. +#ifdef DEBUG
  46576. +/**
  46577. + * Prints out a debug message. Used for logging/trace messages.
  46578. + *
  46579. + * Use the DWC_DEBUG macro to call this function
  46580. + */
  46581. +extern void __DWC_DEBUG(char *format, ...)
  46582. +#ifdef __GNUC__
  46583. + __attribute__ ((format(printf, 1, 2)));
  46584. +#else
  46585. + ;
  46586. +#endif
  46587. +#else
  46588. +#define __DWC_DEBUG printk
  46589. +#endif
  46590. +
  46591. +/**
  46592. + * Prints out a Debug message.
  46593. + */
  46594. +#define DWC_DEBUG(_format, _args...) __DWC_DEBUG("DEBUG:%s:%s: " _format "\n", \
  46595. + __func__, dwc_irq(), ## _args)
  46596. +#define dwc_debug DWC_DEBUG
  46597. +/**
  46598. + * Prints out a Debug message if enabled at compile time.
  46599. + */
  46600. +#if DWC_OTG_DEBUG_LEV > 0
  46601. +#define DWC_DEBUGC(_format, _args...) DWC_DEBUG(_format, ##_args )
  46602. +#else
  46603. +#define DWC_DEBUGC(_format, _args...)
  46604. +#endif
  46605. +#define dwc_debugc DWC_DEBUGC
  46606. +/**
  46607. + * Prints out an informative message.
  46608. + */
  46609. +#define DWC_INFO(_format, _args...) DWC_PRINTF("INFO:%s: " _format "\n", \
  46610. + dwc_irq(), ## _args)
  46611. +#define dwc_info DWC_INFO
  46612. +/**
  46613. + * Prints out an informative message if enabled at compile time.
  46614. + */
  46615. +#if DWC_OTG_DEBUG_LEV > 1
  46616. +#define DWC_INFOC(_format, _args...) DWC_INFO(_format, ##_args )
  46617. +#else
  46618. +#define DWC_INFOC(_format, _args...)
  46619. +#endif
  46620. +#define dwc_infoc DWC_INFOC
  46621. +/**
  46622. + * Prints out a warning message.
  46623. + */
  46624. +#define DWC_WARN(_format, _args...) __DWC_WARN("WARN:%s:%s:%d: " _format "\n", \
  46625. + dwc_irq(), __func__, __LINE__, ## _args)
  46626. +#define dwc_warn DWC_WARN
  46627. +/**
  46628. + * Prints out an error message.
  46629. + */
  46630. +#define DWC_ERROR(_format, _args...) __DWC_ERROR("ERROR:%s:%s:%d: " _format "\n", \
  46631. + dwc_irq(), __func__, __LINE__, ## _args)
  46632. +#define dwc_error DWC_ERROR
  46633. +
  46634. +#define DWC_PROTO_ERROR(_format, _args...) __DWC_WARN("ERROR:%s:%s:%d: " _format "\n", \
  46635. + dwc_irq(), __func__, __LINE__, ## _args)
  46636. +#define dwc_proto_error DWC_PROTO_ERROR
  46637. +
  46638. +#ifdef DEBUG
  46639. +/** Prints out a exception error message if the _expr expression fails. Disabled
  46640. + * if DEBUG is not enabled. */
  46641. +#define DWC_ASSERT(_expr, _format, _args...) do { \
  46642. + if (!(_expr)) { DWC_EXCEPTION("%s:%s:%d: " _format "\n", dwc_irq(), \
  46643. + __FILE__, __LINE__, ## _args); } \
  46644. + } while (0)
  46645. +#else
  46646. +#define DWC_ASSERT(_x...)
  46647. +#endif
  46648. +#define dwc_assert DWC_ASSERT
  46649. +
  46650. +
  46651. +/** @name Byte Ordering
  46652. + * The following functions are for conversions between processor's byte ordering
  46653. + * and specific ordering you want.
  46654. + */
  46655. +
  46656. +/** Converts 32 bit data in CPU byte ordering to little endian. */
  46657. +extern uint32_t DWC_CPU_TO_LE32(uint32_t *p);
  46658. +#define dwc_cpu_to_le32 DWC_CPU_TO_LE32
  46659. +
  46660. +/** Converts 32 bit data in CPU byte orderint to big endian. */
  46661. +extern uint32_t DWC_CPU_TO_BE32(uint32_t *p);
  46662. +#define dwc_cpu_to_be32 DWC_CPU_TO_BE32
  46663. +
  46664. +/** Converts 32 bit little endian data to CPU byte ordering. */
  46665. +extern uint32_t DWC_LE32_TO_CPU(uint32_t *p);
  46666. +#define dwc_le32_to_cpu DWC_LE32_TO_CPU
  46667. +
  46668. +/** Converts 32 bit big endian data to CPU byte ordering. */
  46669. +extern uint32_t DWC_BE32_TO_CPU(uint32_t *p);
  46670. +#define dwc_be32_to_cpu DWC_BE32_TO_CPU
  46671. +
  46672. +/** Converts 16 bit data in CPU byte ordering to little endian. */
  46673. +extern uint16_t DWC_CPU_TO_LE16(uint16_t *p);
  46674. +#define dwc_cpu_to_le16 DWC_CPU_TO_LE16
  46675. +
  46676. +/** Converts 16 bit data in CPU byte orderint to big endian. */
  46677. +extern uint16_t DWC_CPU_TO_BE16(uint16_t *p);
  46678. +#define dwc_cpu_to_be16 DWC_CPU_TO_BE16
  46679. +
  46680. +/** Converts 16 bit little endian data to CPU byte ordering. */
  46681. +extern uint16_t DWC_LE16_TO_CPU(uint16_t *p);
  46682. +#define dwc_le16_to_cpu DWC_LE16_TO_CPU
  46683. +
  46684. +/** Converts 16 bit bi endian data to CPU byte ordering. */
  46685. +extern uint16_t DWC_BE16_TO_CPU(uint16_t *p);
  46686. +#define dwc_be16_to_cpu DWC_BE16_TO_CPU
  46687. +
  46688. +
  46689. +/** @name Register Read/Write
  46690. + *
  46691. + * The following six functions should be implemented to read/write registers of
  46692. + * 32-bit and 64-bit sizes. All modules use this to read/write register values.
  46693. + * The reg value is a pointer to the register calculated from the void *base
  46694. + * variable passed into the driver when it is started. */
  46695. +
  46696. +#ifdef DWC_LINUX
  46697. +/* Linux doesn't need any extra parameters for register read/write, so we
  46698. + * just throw away the IO context parameter.
  46699. + */
  46700. +/** Reads the content of a 32-bit register. */
  46701. +extern uint32_t DWC_READ_REG32(uint32_t volatile *reg);
  46702. +#define dwc_read_reg32(_ctx_,_reg_) DWC_READ_REG32(_reg_)
  46703. +
  46704. +/** Reads the content of a 64-bit register. */
  46705. +extern uint64_t DWC_READ_REG64(uint64_t volatile *reg);
  46706. +#define dwc_read_reg64(_ctx_,_reg_) DWC_READ_REG64(_reg_)
  46707. +
  46708. +/** Writes to a 32-bit register. */
  46709. +extern void DWC_WRITE_REG32(uint32_t volatile *reg, uint32_t value);
  46710. +#define dwc_write_reg32(_ctx_,_reg_,_val_) DWC_WRITE_REG32(_reg_, _val_)
  46711. +
  46712. +/** Writes to a 64-bit register. */
  46713. +extern void DWC_WRITE_REG64(uint64_t volatile *reg, uint64_t value);
  46714. +#define dwc_write_reg64(_ctx_,_reg_,_val_) DWC_WRITE_REG64(_reg_, _val_)
  46715. +
  46716. +/**
  46717. + * Modify bit values in a register. Using the
  46718. + * algorithm: (reg_contents & ~clear_mask) | set_mask.
  46719. + */
  46720. +extern void DWC_MODIFY_REG32(uint32_t volatile *reg, uint32_t clear_mask, uint32_t set_mask);
  46721. +#define dwc_modify_reg32(_ctx_,_reg_,_cmsk_,_smsk_) DWC_MODIFY_REG32(_reg_,_cmsk_,_smsk_)
  46722. +extern void DWC_MODIFY_REG64(uint64_t volatile *reg, uint64_t clear_mask, uint64_t set_mask);
  46723. +#define dwc_modify_reg64(_ctx_,_reg_,_cmsk_,_smsk_) DWC_MODIFY_REG64(_reg_,_cmsk_,_smsk_)
  46724. +
  46725. +#endif /* DWC_LINUX */
  46726. +
  46727. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  46728. +typedef struct dwc_ioctx {
  46729. + struct device *dev;
  46730. + bus_space_tag_t iot;
  46731. + bus_space_handle_t ioh;
  46732. +} dwc_ioctx_t;
  46733. +
  46734. +/** BSD needs two extra parameters for register read/write, so we pass
  46735. + * them in using the IO context parameter.
  46736. + */
  46737. +/** Reads the content of a 32-bit register. */
  46738. +extern uint32_t DWC_READ_REG32(void *io_ctx, uint32_t volatile *reg);
  46739. +#define dwc_read_reg32 DWC_READ_REG32
  46740. +
  46741. +/** Reads the content of a 64-bit register. */
  46742. +extern uint64_t DWC_READ_REG64(void *io_ctx, uint64_t volatile *reg);
  46743. +#define dwc_read_reg64 DWC_READ_REG64
  46744. +
  46745. +/** Writes to a 32-bit register. */
  46746. +extern void DWC_WRITE_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t value);
  46747. +#define dwc_write_reg32 DWC_WRITE_REG32
  46748. +
  46749. +/** Writes to a 64-bit register. */
  46750. +extern void DWC_WRITE_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t value);
  46751. +#define dwc_write_reg64 DWC_WRITE_REG64
  46752. +
  46753. +/**
  46754. + * Modify bit values in a register. Using the
  46755. + * algorithm: (reg_contents & ~clear_mask) | set_mask.
  46756. + */
  46757. +extern void DWC_MODIFY_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t clear_mask, uint32_t set_mask);
  46758. +#define dwc_modify_reg32 DWC_MODIFY_REG32
  46759. +extern void DWC_MODIFY_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t clear_mask, uint64_t set_mask);
  46760. +#define dwc_modify_reg64 DWC_MODIFY_REG64
  46761. +
  46762. +#endif /* DWC_FREEBSD || DWC_NETBSD */
  46763. +
  46764. +/** @cond */
  46765. +
  46766. +/** @name Some convenience MACROS used internally. Define DWC_DEBUG_REGS to log the
  46767. + * register writes. */
  46768. +
  46769. +#ifdef DWC_LINUX
  46770. +
  46771. +# ifdef DWC_DEBUG_REGS
  46772. +
  46773. +#define dwc_define_read_write_reg_n(_reg,_container_type) \
  46774. +static inline uint32_t dwc_read_##_reg##_n(_container_type *container, int num) { \
  46775. + return DWC_READ_REG32(&container->regs->_reg[num]); \
  46776. +} \
  46777. +static inline void dwc_write_##_reg##_n(_container_type *container, int num, uint32_t data) { \
  46778. + DWC_DEBUG("WRITING %8s[%d]: %p: %08x", #_reg, num, \
  46779. + &(((uint32_t*)container->regs->_reg)[num]), data); \
  46780. + DWC_WRITE_REG32(&(((uint32_t*)container->regs->_reg)[num]), data); \
  46781. +}
  46782. +
  46783. +#define dwc_define_read_write_reg(_reg,_container_type) \
  46784. +static inline uint32_t dwc_read_##_reg(_container_type *container) { \
  46785. + return DWC_READ_REG32(&container->regs->_reg); \
  46786. +} \
  46787. +static inline void dwc_write_##_reg(_container_type *container, uint32_t data) { \
  46788. + DWC_DEBUG("WRITING %11s: %p: %08x", #_reg, &container->regs->_reg, data); \
  46789. + DWC_WRITE_REG32(&container->regs->_reg, data); \
  46790. +}
  46791. +
  46792. +# else /* DWC_DEBUG_REGS */
  46793. +
  46794. +#define dwc_define_read_write_reg_n(_reg,_container_type) \
  46795. +static inline uint32_t dwc_read_##_reg##_n(_container_type *container, int num) { \
  46796. + return DWC_READ_REG32(&container->regs->_reg[num]); \
  46797. +} \
  46798. +static inline void dwc_write_##_reg##_n(_container_type *container, int num, uint32_t data) { \
  46799. + DWC_WRITE_REG32(&(((uint32_t*)container->regs->_reg)[num]), data); \
  46800. +}
  46801. +
  46802. +#define dwc_define_read_write_reg(_reg,_container_type) \
  46803. +static inline uint32_t dwc_read_##_reg(_container_type *container) { \
  46804. + return DWC_READ_REG32(&container->regs->_reg); \
  46805. +} \
  46806. +static inline void dwc_write_##_reg(_container_type *container, uint32_t data) { \
  46807. + DWC_WRITE_REG32(&container->regs->_reg, data); \
  46808. +}
  46809. +
  46810. +# endif /* DWC_DEBUG_REGS */
  46811. +
  46812. +#endif /* DWC_LINUX */
  46813. +
  46814. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  46815. +
  46816. +# ifdef DWC_DEBUG_REGS
  46817. +
  46818. +#define dwc_define_read_write_reg_n(_reg,_container_type) \
  46819. +static inline uint32_t dwc_read_##_reg##_n(void *io_ctx, _container_type *container, int num) { \
  46820. + return DWC_READ_REG32(io_ctx, &container->regs->_reg[num]); \
  46821. +} \
  46822. +static inline void dwc_write_##_reg##_n(void *io_ctx, _container_type *container, int num, uint32_t data) { \
  46823. + DWC_DEBUG("WRITING %8s[%d]: %p: %08x", #_reg, num, \
  46824. + &(((uint32_t*)container->regs->_reg)[num]), data); \
  46825. + DWC_WRITE_REG32(io_ctx, &(((uint32_t*)container->regs->_reg)[num]), data); \
  46826. +}
  46827. +
  46828. +#define dwc_define_read_write_reg(_reg,_container_type) \
  46829. +static inline uint32_t dwc_read_##_reg(void *io_ctx, _container_type *container) { \
  46830. + return DWC_READ_REG32(io_ctx, &container->regs->_reg); \
  46831. +} \
  46832. +static inline void dwc_write_##_reg(void *io_ctx, _container_type *container, uint32_t data) { \
  46833. + DWC_DEBUG("WRITING %11s: %p: %08x", #_reg, &container->regs->_reg, data); \
  46834. + DWC_WRITE_REG32(io_ctx, &container->regs->_reg, data); \
  46835. +}
  46836. +
  46837. +# else /* DWC_DEBUG_REGS */
  46838. +
  46839. +#define dwc_define_read_write_reg_n(_reg,_container_type) \
  46840. +static inline uint32_t dwc_read_##_reg##_n(void *io_ctx, _container_type *container, int num) { \
  46841. + return DWC_READ_REG32(io_ctx, &container->regs->_reg[num]); \
  46842. +} \
  46843. +static inline void dwc_write_##_reg##_n(void *io_ctx, _container_type *container, int num, uint32_t data) { \
  46844. + DWC_WRITE_REG32(io_ctx, &(((uint32_t*)container->regs->_reg)[num]), data); \
  46845. +}
  46846. +
  46847. +#define dwc_define_read_write_reg(_reg,_container_type) \
  46848. +static inline uint32_t dwc_read_##_reg(void *io_ctx, _container_type *container) { \
  46849. + return DWC_READ_REG32(io_ctx, &container->regs->_reg); \
  46850. +} \
  46851. +static inline void dwc_write_##_reg(void *io_ctx, _container_type *container, uint32_t data) { \
  46852. + DWC_WRITE_REG32(io_ctx, &container->regs->_reg, data); \
  46853. +}
  46854. +
  46855. +# endif /* DWC_DEBUG_REGS */
  46856. +
  46857. +#endif /* DWC_FREEBSD || DWC_NETBSD */
  46858. +
  46859. +/** @endcond */
  46860. +
  46861. +
  46862. +#ifdef DWC_CRYPTOLIB
  46863. +/** @name Crypto Functions
  46864. + *
  46865. + * These are the low-level cryptographic functions used by the driver. */
  46866. +
  46867. +/** Perform AES CBC */
  46868. +extern int DWC_AES_CBC(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t iv[16], uint8_t *out);
  46869. +#define dwc_aes_cbc DWC_AES_CBC
  46870. +
  46871. +/** Fill the provided buffer with random bytes. These should be cryptographic grade random numbers. */
  46872. +extern void DWC_RANDOM_BYTES(uint8_t *buffer, uint32_t length);
  46873. +#define dwc_random_bytes DWC_RANDOM_BYTES
  46874. +
  46875. +/** Perform the SHA-256 hash function */
  46876. +extern int DWC_SHA256(uint8_t *message, uint32_t len, uint8_t *out);
  46877. +#define dwc_sha256 DWC_SHA256
  46878. +
  46879. +/** Calculated the HMAC-SHA256 */
  46880. +extern int DWC_HMAC_SHA256(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t *out);
  46881. +#define dwc_hmac_sha256 DWC_HMAC_SHA256
  46882. +
  46883. +#endif /* DWC_CRYPTOLIB */
  46884. +
  46885. +
  46886. +/** @name Memory Allocation
  46887. + *
  46888. + * These function provide access to memory allocation. There are only 2 DMA
  46889. + * functions and 3 Regular memory functions that need to be implemented. None
  46890. + * of the memory debugging routines need to be implemented. The allocation
  46891. + * routines all ZERO the contents of the memory.
  46892. + *
  46893. + * Defining DWC_DEBUG_MEMORY turns on memory debugging and statistic gathering.
  46894. + * This checks for memory leaks, keeping track of alloc/free pairs. It also
  46895. + * keeps track of how much memory the driver is using at any given time. */
  46896. +
  46897. +#define DWC_PAGE_SIZE 4096
  46898. +#define DWC_PAGE_OFFSET(addr) (((uint32_t)addr) & 0xfff)
  46899. +#define DWC_PAGE_ALIGNED(addr) ((((uint32_t)addr) & 0xfff) == 0)
  46900. +
  46901. +#define DWC_INVALID_DMA_ADDR 0x0
  46902. +
  46903. +#ifdef DWC_LINUX
  46904. +/** Type for a DMA address */
  46905. +typedef dma_addr_t dwc_dma_t;
  46906. +#endif
  46907. +
  46908. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  46909. +typedef bus_addr_t dwc_dma_t;
  46910. +#endif
  46911. +
  46912. +#ifdef DWC_FREEBSD
  46913. +typedef struct dwc_dmactx {
  46914. + struct device *dev;
  46915. + bus_dma_tag_t dma_tag;
  46916. + bus_dmamap_t dma_map;
  46917. + bus_addr_t dma_paddr;
  46918. + void *dma_vaddr;
  46919. +} dwc_dmactx_t;
  46920. +#endif
  46921. +
  46922. +#ifdef DWC_NETBSD
  46923. +typedef struct dwc_dmactx {
  46924. + struct device *dev;
  46925. + bus_dma_tag_t dma_tag;
  46926. + bus_dmamap_t dma_map;
  46927. + bus_dma_segment_t segs[1];
  46928. + int nsegs;
  46929. + bus_addr_t dma_paddr;
  46930. + void *dma_vaddr;
  46931. +} dwc_dmactx_t;
  46932. +#endif
  46933. +
  46934. +/* @todo these functions will be added in the future */
  46935. +#if 0
  46936. +/**
  46937. + * Creates a DMA pool from which you can allocate DMA buffers. Buffers
  46938. + * allocated from this pool will be guaranteed to meet the size, alignment, and
  46939. + * boundary requirements specified.
  46940. + *
  46941. + * @param[in] size Specifies the size of the buffers that will be allocated from
  46942. + * this pool.
  46943. + * @param[in] align Specifies the byte alignment requirements of the buffers
  46944. + * allocated from this pool. Must be a power of 2.
  46945. + * @param[in] boundary Specifies the N-byte boundary that buffers allocated from
  46946. + * this pool must not cross.
  46947. + *
  46948. + * @returns A pointer to an internal opaque structure which is not to be
  46949. + * accessed outside of these library functions. Use this handle to specify
  46950. + * which pools to allocate/free DMA buffers from and also to destroy the pool,
  46951. + * when you are done with it.
  46952. + */
  46953. +extern dwc_pool_t *DWC_DMA_POOL_CREATE(uint32_t size, uint32_t align, uint32_t boundary);
  46954. +
  46955. +/**
  46956. + * Destroy a DMA pool. All buffers allocated from that pool must be freed first.
  46957. + */
  46958. +extern void DWC_DMA_POOL_DESTROY(dwc_pool_t *pool);
  46959. +
  46960. +/**
  46961. + * Allocate a buffer from the specified DMA pool and zeros its contents.
  46962. + */
  46963. +extern void *DWC_DMA_POOL_ALLOC(dwc_pool_t *pool, uint64_t *dma_addr);
  46964. +
  46965. +/**
  46966. + * Free a previously allocated buffer from the DMA pool.
  46967. + */
  46968. +extern void DWC_DMA_POOL_FREE(dwc_pool_t *pool, void *vaddr, void *daddr);
  46969. +#endif
  46970. +
  46971. +/** Allocates a DMA capable buffer and zeroes its contents. */
  46972. +extern void *__DWC_DMA_ALLOC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr);
  46973. +
  46974. +/** Allocates a DMA capable buffer and zeroes its contents in atomic contest */
  46975. +extern void *__DWC_DMA_ALLOC_ATOMIC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr);
  46976. +
  46977. +/** Frees a previously allocated buffer. */
  46978. +extern void __DWC_DMA_FREE(void *dma_ctx, uint32_t size, void *virt_addr, dwc_dma_t dma_addr);
  46979. +
  46980. +/** Allocates a block of memory and zeroes its contents. */
  46981. +extern void *__DWC_ALLOC(void *mem_ctx, uint32_t size);
  46982. +
  46983. +/** Allocates a block of memory and zeroes its contents, in an atomic manner
  46984. + * which can be used inside interrupt context. The size should be sufficiently
  46985. + * small, a few KB at most, such that failures are not likely to occur. Can just call
  46986. + * __DWC_ALLOC if it is atomic. */
  46987. +extern void *__DWC_ALLOC_ATOMIC(void *mem_ctx, uint32_t size);
  46988. +
  46989. +/** Frees a previously allocated buffer. */
  46990. +extern void __DWC_FREE(void *mem_ctx, void *addr);
  46991. +
  46992. +#ifndef DWC_DEBUG_MEMORY
  46993. +
  46994. +#define DWC_ALLOC(_size_) __DWC_ALLOC(NULL, _size_)
  46995. +#define DWC_ALLOC_ATOMIC(_size_) __DWC_ALLOC_ATOMIC(NULL, _size_)
  46996. +#define DWC_FREE(_addr_) __DWC_FREE(NULL, _addr_)
  46997. +
  46998. +# ifdef DWC_LINUX
  46999. +#define DWC_DMA_ALLOC(_size_,_dma_) __DWC_DMA_ALLOC(NULL, _size_, _dma_)
  47000. +#define DWC_DMA_ALLOC_ATOMIC(_size_,_dma_) __DWC_DMA_ALLOC_ATOMIC(NULL, _size_,_dma_)
  47001. +#define DWC_DMA_FREE(_size_,_virt_,_dma_) __DWC_DMA_FREE(NULL, _size_, _virt_, _dma_)
  47002. +# endif
  47003. +
  47004. +# if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  47005. +#define DWC_DMA_ALLOC __DWC_DMA_ALLOC
  47006. +#define DWC_DMA_FREE __DWC_DMA_FREE
  47007. +# endif
  47008. +extern void *dwc_dma_alloc_atomic_debug(uint32_t size, dwc_dma_t *dma_addr, char const *func, int line);
  47009. +
  47010. +#else /* DWC_DEBUG_MEMORY */
  47011. +
  47012. +extern void *dwc_alloc_debug(void *mem_ctx, uint32_t size, char const *func, int line);
  47013. +extern void *dwc_alloc_atomic_debug(void *mem_ctx, uint32_t size, char const *func, int line);
  47014. +extern void dwc_free_debug(void *mem_ctx, void *addr, char const *func, int line);
  47015. +extern void *dwc_dma_alloc_debug(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr,
  47016. + char const *func, int line);
  47017. +extern void *dwc_dma_alloc_atomic_debug(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr,
  47018. + char const *func, int line);
  47019. +extern void dwc_dma_free_debug(void *dma_ctx, uint32_t size, void *virt_addr,
  47020. + dwc_dma_t dma_addr, char const *func, int line);
  47021. +
  47022. +extern int dwc_memory_debug_start(void *mem_ctx);
  47023. +extern void dwc_memory_debug_stop(void);
  47024. +extern void dwc_memory_debug_report(void);
  47025. +
  47026. +#define DWC_ALLOC(_size_) dwc_alloc_debug(NULL, _size_, __func__, __LINE__)
  47027. +#define DWC_ALLOC_ATOMIC(_size_) dwc_alloc_atomic_debug(NULL, _size_, \
  47028. + __func__, __LINE__)
  47029. +#define DWC_FREE(_addr_) dwc_free_debug(NULL, _addr_, __func__, __LINE__)
  47030. +
  47031. +# ifdef DWC_LINUX
  47032. +#define DWC_DMA_ALLOC(_size_,_dma_) dwc_dma_alloc_debug(NULL, _size_, \
  47033. + _dma_, __func__, __LINE__)
  47034. +#define DWC_DMA_ALLOC_ATOMIC(_size_,_dma_) dwc_dma_alloc_atomic_debug(NULL, _size_, \
  47035. + _dma_, __func__, __LINE__)
  47036. +#define DWC_DMA_FREE(_size_,_virt_,_dma_) dwc_dma_free_debug(NULL, _size_, \
  47037. + _virt_, _dma_, __func__, __LINE__)
  47038. +# endif
  47039. +
  47040. +# if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  47041. +#define DWC_DMA_ALLOC(_ctx_,_size_,_dma_) dwc_dma_alloc_debug(_ctx_, _size_, \
  47042. + _dma_, __func__, __LINE__)
  47043. +#define DWC_DMA_FREE(_ctx_,_size_,_virt_,_dma_) dwc_dma_free_debug(_ctx_, _size_, \
  47044. + _virt_, _dma_, __func__, __LINE__)
  47045. +# endif
  47046. +
  47047. +#endif /* DWC_DEBUG_MEMORY */
  47048. +
  47049. +#define dwc_alloc(_ctx_,_size_) DWC_ALLOC(_size_)
  47050. +#define dwc_alloc_atomic(_ctx_,_size_) DWC_ALLOC_ATOMIC(_size_)
  47051. +#define dwc_free(_ctx_,_addr_) DWC_FREE(_addr_)
  47052. +
  47053. +#ifdef DWC_LINUX
  47054. +/* Linux doesn't need any extra parameters for DMA buffer allocation, so we
  47055. + * just throw away the DMA context parameter.
  47056. + */
  47057. +#define dwc_dma_alloc(_ctx_,_size_,_dma_) DWC_DMA_ALLOC(_size_, _dma_)
  47058. +#define dwc_dma_alloc_atomic(_ctx_,_size_,_dma_) DWC_DMA_ALLOC_ATOMIC(_size_, _dma_)
  47059. +#define dwc_dma_free(_ctx_,_size_,_virt_,_dma_) DWC_DMA_FREE(_size_, _virt_, _dma_)
  47060. +#endif
  47061. +
  47062. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  47063. +/** BSD needs several extra parameters for DMA buffer allocation, so we pass
  47064. + * them in using the DMA context parameter.
  47065. + */
  47066. +#define dwc_dma_alloc DWC_DMA_ALLOC
  47067. +#define dwc_dma_free DWC_DMA_FREE
  47068. +#endif
  47069. +
  47070. +
  47071. +/** @name Memory and String Processing */
  47072. +
  47073. +/** memset() clone */
  47074. +extern void *DWC_MEMSET(void *dest, uint8_t byte, uint32_t size);
  47075. +#define dwc_memset DWC_MEMSET
  47076. +
  47077. +/** memcpy() clone */
  47078. +extern void *DWC_MEMCPY(void *dest, void const *src, uint32_t size);
  47079. +#define dwc_memcpy DWC_MEMCPY
  47080. +
  47081. +/** memmove() clone */
  47082. +extern void *DWC_MEMMOVE(void *dest, void *src, uint32_t size);
  47083. +#define dwc_memmove DWC_MEMMOVE
  47084. +
  47085. +/** memcmp() clone */
  47086. +extern int DWC_MEMCMP(void *m1, void *m2, uint32_t size);
  47087. +#define dwc_memcmp DWC_MEMCMP
  47088. +
  47089. +/** strcmp() clone */
  47090. +extern int DWC_STRCMP(void *s1, void *s2);
  47091. +#define dwc_strcmp DWC_STRCMP
  47092. +
  47093. +/** strncmp() clone */
  47094. +extern int DWC_STRNCMP(void *s1, void *s2, uint32_t size);
  47095. +#define dwc_strncmp DWC_STRNCMP
  47096. +
  47097. +/** strlen() clone, for NULL terminated ASCII strings */
  47098. +extern int DWC_STRLEN(char const *str);
  47099. +#define dwc_strlen DWC_STRLEN
  47100. +
  47101. +/** strcpy() clone, for NULL terminated ASCII strings */
  47102. +extern char *DWC_STRCPY(char *to, const char *from);
  47103. +#define dwc_strcpy DWC_STRCPY
  47104. +
  47105. +/** strdup() clone. If you wish to use memory allocation debugging, this
  47106. + * implementation of strdup should use the DWC_* memory routines instead of
  47107. + * calling a predefined strdup. Otherwise the memory allocated by this routine
  47108. + * will not be seen by the debugging routines. */
  47109. +extern char *DWC_STRDUP(char const *str);
  47110. +#define dwc_strdup(_ctx_,_str_) DWC_STRDUP(_str_)
  47111. +
  47112. +/** NOT an atoi() clone. Read the description carefully. Returns an integer
  47113. + * converted from the string str in base 10 unless the string begins with a "0x"
  47114. + * in which case it is base 16. String must be a NULL terminated sequence of
  47115. + * ASCII characters and may optionally begin with whitespace, a + or -, and a
  47116. + * "0x" prefix if base 16. The remaining characters must be valid digits for
  47117. + * the number and end with a NULL character. If any invalid characters are
  47118. + * encountered or it returns with a negative error code and the results of the
  47119. + * conversion are undefined. On sucess it returns 0. Overflow conditions are
  47120. + * undefined. An example implementation using atoi() can be referenced from the
  47121. + * Linux implementation. */
  47122. +extern int DWC_ATOI(const char *str, int32_t *value);
  47123. +#define dwc_atoi DWC_ATOI
  47124. +
  47125. +/** Same as above but for unsigned. */
  47126. +extern int DWC_ATOUI(const char *str, uint32_t *value);
  47127. +#define dwc_atoui DWC_ATOUI
  47128. +
  47129. +#ifdef DWC_UTFLIB
  47130. +/** This routine returns a UTF16LE unicode encoded string from a UTF8 string. */
  47131. +extern int DWC_UTF8_TO_UTF16LE(uint8_t const *utf8string, uint16_t *utf16string, unsigned len);
  47132. +#define dwc_utf8_to_utf16le DWC_UTF8_TO_UTF16LE
  47133. +#endif
  47134. +
  47135. +
  47136. +/** @name Wait queues
  47137. + *
  47138. + * Wait queues provide a means of synchronizing between threads or processes. A
  47139. + * process can block on a waitq if some condition is not true, waiting for it to
  47140. + * become true. When the waitq is triggered all waiting process will get
  47141. + * unblocked and the condition will be check again. Waitqs should be triggered
  47142. + * every time a condition can potentially change.*/
  47143. +struct dwc_waitq;
  47144. +
  47145. +/** Type for a waitq */
  47146. +typedef struct dwc_waitq dwc_waitq_t;
  47147. +
  47148. +/** The type of waitq condition callback function. This is called every time
  47149. + * condition is evaluated. */
  47150. +typedef int (*dwc_waitq_condition_t)(void *data);
  47151. +
  47152. +/** Allocate a waitq */
  47153. +extern dwc_waitq_t *DWC_WAITQ_ALLOC(void);
  47154. +#define dwc_waitq_alloc(_ctx_) DWC_WAITQ_ALLOC()
  47155. +
  47156. +/** Free a waitq */
  47157. +extern void DWC_WAITQ_FREE(dwc_waitq_t *wq);
  47158. +#define dwc_waitq_free DWC_WAITQ_FREE
  47159. +
  47160. +/** Check the condition and if it is false, block on the waitq. When unblocked, check the
  47161. + * condition again. The function returns when the condition becomes true. The return value
  47162. + * is 0 on condition true, DWC_WAITQ_ABORTED on abort or killed, or DWC_WAITQ_UNKNOWN on error. */
  47163. +extern int32_t DWC_WAITQ_WAIT(dwc_waitq_t *wq, dwc_waitq_condition_t cond, void *data);
  47164. +#define dwc_waitq_wait DWC_WAITQ_WAIT
  47165. +
  47166. +/** Check the condition and if it is false, block on the waitq. When unblocked,
  47167. + * check the condition again. The function returns when the condition become
  47168. + * true or the timeout has passed. The return value is 0 on condition true or
  47169. + * DWC_TIMED_OUT on timeout, or DWC_WAITQ_ABORTED, or DWC_WAITQ_UNKNOWN on
  47170. + * error. */
  47171. +extern int32_t DWC_WAITQ_WAIT_TIMEOUT(dwc_waitq_t *wq, dwc_waitq_condition_t cond,
  47172. + void *data, int32_t msecs);
  47173. +#define dwc_waitq_wait_timeout DWC_WAITQ_WAIT_TIMEOUT
  47174. +
  47175. +/** Trigger a waitq, unblocking all processes. This should be called whenever a condition
  47176. + * has potentially changed. */
  47177. +extern void DWC_WAITQ_TRIGGER(dwc_waitq_t *wq);
  47178. +#define dwc_waitq_trigger DWC_WAITQ_TRIGGER
  47179. +
  47180. +/** Unblock all processes waiting on the waitq with an ABORTED result. */
  47181. +extern void DWC_WAITQ_ABORT(dwc_waitq_t *wq);
  47182. +#define dwc_waitq_abort DWC_WAITQ_ABORT
  47183. +
  47184. +
  47185. +/** @name Threads
  47186. + *
  47187. + * A thread must be explicitly stopped. It must check DWC_THREAD_SHOULD_STOP
  47188. + * whenever it is woken up, and then return. The DWC_THREAD_STOP function
  47189. + * returns the value from the thread.
  47190. + */
  47191. +
  47192. +struct dwc_thread;
  47193. +
  47194. +/** Type for a thread */
  47195. +typedef struct dwc_thread dwc_thread_t;
  47196. +
  47197. +/** The thread function */
  47198. +typedef int (*dwc_thread_function_t)(void *data);
  47199. +
  47200. +/** Create a thread and start it running the thread_function. Returns a handle
  47201. + * to the thread */
  47202. +extern dwc_thread_t *DWC_THREAD_RUN(dwc_thread_function_t func, char *name, void *data);
  47203. +#define dwc_thread_run(_ctx_,_func_,_name_,_data_) DWC_THREAD_RUN(_func_, _name_, _data_)
  47204. +
  47205. +/** Stops a thread. Return the value returned by the thread. Or will return
  47206. + * DWC_ABORT if the thread never started. */
  47207. +extern int DWC_THREAD_STOP(dwc_thread_t *thread);
  47208. +#define dwc_thread_stop DWC_THREAD_STOP
  47209. +
  47210. +/** Signifies to the thread that it must stop. */
  47211. +#ifdef DWC_LINUX
  47212. +/* Linux doesn't need any parameters for kthread_should_stop() */
  47213. +extern dwc_bool_t DWC_THREAD_SHOULD_STOP(void);
  47214. +#define dwc_thread_should_stop(_thrd_) DWC_THREAD_SHOULD_STOP()
  47215. +
  47216. +/* No thread_exit function in Linux */
  47217. +#define dwc_thread_exit(_thrd_)
  47218. +#endif
  47219. +
  47220. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  47221. +/** BSD needs the thread pointer for kthread_suspend_check() */
  47222. +extern dwc_bool_t DWC_THREAD_SHOULD_STOP(dwc_thread_t *thread);
  47223. +#define dwc_thread_should_stop DWC_THREAD_SHOULD_STOP
  47224. +
  47225. +/** The thread must call this to exit. */
  47226. +extern void DWC_THREAD_EXIT(dwc_thread_t *thread);
  47227. +#define dwc_thread_exit DWC_THREAD_EXIT
  47228. +#endif
  47229. +
  47230. +
  47231. +/** @name Work queues
  47232. + *
  47233. + * Workqs are used to queue a callback function to be called at some later time,
  47234. + * in another thread. */
  47235. +struct dwc_workq;
  47236. +
  47237. +/** Type for a workq */
  47238. +typedef struct dwc_workq dwc_workq_t;
  47239. +
  47240. +/** The type of the callback function to be called. */
  47241. +typedef void (*dwc_work_callback_t)(void *data);
  47242. +
  47243. +/** Allocate a workq */
  47244. +extern dwc_workq_t *DWC_WORKQ_ALLOC(char *name);
  47245. +#define dwc_workq_alloc(_ctx_,_name_) DWC_WORKQ_ALLOC(_name_)
  47246. +
  47247. +/** Free a workq. All work must be completed before being freed. */
  47248. +extern void DWC_WORKQ_FREE(dwc_workq_t *workq);
  47249. +#define dwc_workq_free DWC_WORKQ_FREE
  47250. +
  47251. +/** Schedule a callback on the workq, passing in data. The function will be
  47252. + * scheduled at some later time. */
  47253. +extern void DWC_WORKQ_SCHEDULE(dwc_workq_t *workq, dwc_work_callback_t cb,
  47254. + void *data, char *format, ...)
  47255. +#ifdef __GNUC__
  47256. + __attribute__ ((format(printf, 4, 5)));
  47257. +#else
  47258. + ;
  47259. +#endif
  47260. +#define dwc_workq_schedule DWC_WORKQ_SCHEDULE
  47261. +
  47262. +/** Schedule a callback on the workq, that will be called until at least
  47263. + * given number miliseconds have passed. */
  47264. +extern void DWC_WORKQ_SCHEDULE_DELAYED(dwc_workq_t *workq, dwc_work_callback_t cb,
  47265. + void *data, uint32_t time, char *format, ...)
  47266. +#ifdef __GNUC__
  47267. + __attribute__ ((format(printf, 5, 6)));
  47268. +#else
  47269. + ;
  47270. +#endif
  47271. +#define dwc_workq_schedule_delayed DWC_WORKQ_SCHEDULE_DELAYED
  47272. +
  47273. +/** The number of processes in the workq */
  47274. +extern int DWC_WORKQ_PENDING(dwc_workq_t *workq);
  47275. +#define dwc_workq_pending DWC_WORKQ_PENDING
  47276. +
  47277. +/** Blocks until all the work in the workq is complete or timed out. Returns <
  47278. + * 0 on timeout. */
  47279. +extern int DWC_WORKQ_WAIT_WORK_DONE(dwc_workq_t *workq, int timeout);
  47280. +#define dwc_workq_wait_work_done DWC_WORKQ_WAIT_WORK_DONE
  47281. +
  47282. +
  47283. +/** @name Tasklets
  47284. + *
  47285. + */
  47286. +struct dwc_tasklet;
  47287. +
  47288. +/** Type for a tasklet */
  47289. +typedef struct dwc_tasklet dwc_tasklet_t;
  47290. +
  47291. +/** The type of the callback function to be called */
  47292. +typedef void (*dwc_tasklet_callback_t)(void *data);
  47293. +
  47294. +/** Allocates a tasklet */
  47295. +extern dwc_tasklet_t *DWC_TASK_ALLOC(char *name, dwc_tasklet_callback_t cb, void *data);
  47296. +#define dwc_task_alloc(_ctx_,_name_,_cb_,_data_) DWC_TASK_ALLOC(_name_, _cb_, _data_)
  47297. +
  47298. +/** Frees a tasklet */
  47299. +extern void DWC_TASK_FREE(dwc_tasklet_t *task);
  47300. +#define dwc_task_free DWC_TASK_FREE
  47301. +
  47302. +/** Schedules a tasklet to run */
  47303. +extern void DWC_TASK_SCHEDULE(dwc_tasklet_t *task);
  47304. +#define dwc_task_schedule DWC_TASK_SCHEDULE
  47305. +
  47306. +extern void DWC_TASK_HI_SCHEDULE(dwc_tasklet_t *task);
  47307. +#define dwc_task_hi_schedule DWC_TASK_HI_SCHEDULE
  47308. +
  47309. +/** @name Timer
  47310. + *
  47311. + * Callbacks must be small and atomic.
  47312. + */
  47313. +struct dwc_timer;
  47314. +
  47315. +/** Type for a timer */
  47316. +typedef struct dwc_timer dwc_timer_t;
  47317. +
  47318. +/** The type of the callback function to be called */
  47319. +typedef void (*dwc_timer_callback_t)(void *data);
  47320. +
  47321. +/** Allocates a timer */
  47322. +extern dwc_timer_t *DWC_TIMER_ALLOC(char *name, dwc_timer_callback_t cb, void *data);
  47323. +#define dwc_timer_alloc(_ctx_,_name_,_cb_,_data_) DWC_TIMER_ALLOC(_name_,_cb_,_data_)
  47324. +
  47325. +/** Frees a timer */
  47326. +extern void DWC_TIMER_FREE(dwc_timer_t *timer);
  47327. +#define dwc_timer_free DWC_TIMER_FREE
  47328. +
  47329. +/** Schedules the timer to run at time ms from now. And will repeat at every
  47330. + * repeat_interval msec therafter
  47331. + *
  47332. + * Modifies a timer that is still awaiting execution to a new expiration time.
  47333. + * The mod_time is added to the old time. */
  47334. +extern void DWC_TIMER_SCHEDULE(dwc_timer_t *timer, uint32_t time);
  47335. +#define dwc_timer_schedule DWC_TIMER_SCHEDULE
  47336. +
  47337. +/** Disables the timer from execution. */
  47338. +extern void DWC_TIMER_CANCEL(dwc_timer_t *timer);
  47339. +#define dwc_timer_cancel DWC_TIMER_CANCEL
  47340. +
  47341. +
  47342. +/** @name Spinlocks
  47343. + *
  47344. + * These locks are used when the work between the lock/unlock is atomic and
  47345. + * short. Interrupts are also disabled during the lock/unlock and thus they are
  47346. + * suitable to lock between interrupt/non-interrupt context. They also lock
  47347. + * between processes if you have multiple CPUs or Preemption. If you don't have
  47348. + * multiple CPUS or Preemption, then the you can simply implement the
  47349. + * DWC_SPINLOCK and DWC_SPINUNLOCK to disable and enable interrupts. Because
  47350. + * the work between the lock/unlock is atomic, the process context will never
  47351. + * change, and so you never have to lock between processes. */
  47352. +
  47353. +struct dwc_spinlock;
  47354. +
  47355. +/** Type for a spinlock */
  47356. +typedef struct dwc_spinlock dwc_spinlock_t;
  47357. +
  47358. +/** Type for the 'flags' argument to spinlock funtions */
  47359. +typedef unsigned long dwc_irqflags_t;
  47360. +
  47361. +/** Returns an initialized lock variable. This function should allocate and
  47362. + * initialize the OS-specific data structure used for locking. This data
  47363. + * structure is to be used for the DWC_LOCK and DWC_UNLOCK functions and should
  47364. + * be freed by the DWC_FREE_LOCK when it is no longer used. */
  47365. +extern dwc_spinlock_t *DWC_SPINLOCK_ALLOC(void);
  47366. +#define dwc_spinlock_alloc(_ctx_) DWC_SPINLOCK_ALLOC()
  47367. +
  47368. +/** Frees an initialized lock variable. */
  47369. +extern void DWC_SPINLOCK_FREE(dwc_spinlock_t *lock);
  47370. +#define dwc_spinlock_free(_ctx_,_lock_) DWC_SPINLOCK_FREE(_lock_)
  47371. +
  47372. +/** Disables interrupts and blocks until it acquires the lock.
  47373. + *
  47374. + * @param lock Pointer to the spinlock.
  47375. + * @param flags Unsigned long for irq flags storage.
  47376. + */
  47377. +extern void DWC_SPINLOCK_IRQSAVE(dwc_spinlock_t *lock, dwc_irqflags_t *flags);
  47378. +#define dwc_spinlock_irqsave DWC_SPINLOCK_IRQSAVE
  47379. +
  47380. +/** Re-enables the interrupt and releases the lock.
  47381. + *
  47382. + * @param lock Pointer to the spinlock.
  47383. + * @param flags Unsigned long for irq flags storage. Must be the same as was
  47384. + * passed into DWC_LOCK.
  47385. + */
  47386. +extern void DWC_SPINUNLOCK_IRQRESTORE(dwc_spinlock_t *lock, dwc_irqflags_t flags);
  47387. +#define dwc_spinunlock_irqrestore DWC_SPINUNLOCK_IRQRESTORE
  47388. +
  47389. +/** Blocks until it acquires the lock.
  47390. + *
  47391. + * @param lock Pointer to the spinlock.
  47392. + */
  47393. +extern void DWC_SPINLOCK(dwc_spinlock_t *lock);
  47394. +#define dwc_spinlock DWC_SPINLOCK
  47395. +
  47396. +/** Releases the lock.
  47397. + *
  47398. + * @param lock Pointer to the spinlock.
  47399. + */
  47400. +extern void DWC_SPINUNLOCK(dwc_spinlock_t *lock);
  47401. +#define dwc_spinunlock DWC_SPINUNLOCK
  47402. +
  47403. +
  47404. +/** @name Mutexes
  47405. + *
  47406. + * Unlike spinlocks Mutexes lock only between processes and the work between the
  47407. + * lock/unlock CAN block, therefore it CANNOT be called from interrupt context.
  47408. + */
  47409. +
  47410. +struct dwc_mutex;
  47411. +
  47412. +/** Type for a mutex */
  47413. +typedef struct dwc_mutex dwc_mutex_t;
  47414. +
  47415. +/* For Linux Mutex Debugging make it inline because the debugging routines use
  47416. + * the symbol to determine recursive locking. This makes it falsely think
  47417. + * recursive locking occurs. */
  47418. +#if defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES)
  47419. +#define DWC_MUTEX_ALLOC_LINUX_DEBUG(__mutexp) ({ \
  47420. + __mutexp = (dwc_mutex_t *)DWC_ALLOC(sizeof(struct mutex)); \
  47421. + mutex_init((struct mutex *)__mutexp); \
  47422. +})
  47423. +#endif
  47424. +
  47425. +/** Allocate a mutex */
  47426. +extern dwc_mutex_t *DWC_MUTEX_ALLOC(void);
  47427. +#define dwc_mutex_alloc(_ctx_) DWC_MUTEX_ALLOC()
  47428. +
  47429. +/* For memory leak debugging when using Linux Mutex Debugging */
  47430. +#if defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES)
  47431. +#define DWC_MUTEX_FREE(__mutexp) do { \
  47432. + mutex_destroy((struct mutex *)__mutexp); \
  47433. + DWC_FREE(__mutexp); \
  47434. +} while(0)
  47435. +#else
  47436. +/** Free a mutex */
  47437. +extern void DWC_MUTEX_FREE(dwc_mutex_t *mutex);
  47438. +#define dwc_mutex_free(_ctx_,_mutex_) DWC_MUTEX_FREE(_mutex_)
  47439. +#endif
  47440. +
  47441. +/** Lock a mutex */
  47442. +extern void DWC_MUTEX_LOCK(dwc_mutex_t *mutex);
  47443. +#define dwc_mutex_lock DWC_MUTEX_LOCK
  47444. +
  47445. +/** Non-blocking lock returns 1 on successful lock. */
  47446. +extern int DWC_MUTEX_TRYLOCK(dwc_mutex_t *mutex);
  47447. +#define dwc_mutex_trylock DWC_MUTEX_TRYLOCK
  47448. +
  47449. +/** Unlock a mutex */
  47450. +extern void DWC_MUTEX_UNLOCK(dwc_mutex_t *mutex);
  47451. +#define dwc_mutex_unlock DWC_MUTEX_UNLOCK
  47452. +
  47453. +
  47454. +/** @name Time */
  47455. +
  47456. +/** Microsecond delay.
  47457. + *
  47458. + * @param usecs Microseconds to delay.
  47459. + */
  47460. +extern void DWC_UDELAY(uint32_t usecs);
  47461. +#define dwc_udelay DWC_UDELAY
  47462. +
  47463. +/** Millisecond delay.
  47464. + *
  47465. + * @param msecs Milliseconds to delay.
  47466. + */
  47467. +extern void DWC_MDELAY(uint32_t msecs);
  47468. +#define dwc_mdelay DWC_MDELAY
  47469. +
  47470. +/** Non-busy waiting.
  47471. + * Sleeps for specified number of milliseconds.
  47472. + *
  47473. + * @param msecs Milliseconds to sleep.
  47474. + */
  47475. +extern void DWC_MSLEEP(uint32_t msecs);
  47476. +#define dwc_msleep DWC_MSLEEP
  47477. +
  47478. +/**
  47479. + * Returns number of milliseconds since boot.
  47480. + */
  47481. +extern uint32_t DWC_TIME(void);
  47482. +#define dwc_time DWC_TIME
  47483. +
  47484. +
  47485. +
  47486. +
  47487. +/* @mainpage DWC Portability and Common Library
  47488. + *
  47489. + * This is the documentation for the DWC Portability and Common Library.
  47490. + *
  47491. + * @section intro Introduction
  47492. + *
  47493. + * The DWC Portability library consists of wrapper calls and data structures to
  47494. + * all low-level functions which are typically provided by the OS. The WUDEV
  47495. + * driver uses only these functions. In order to port the WUDEV driver, only
  47496. + * the functions in this library need to be re-implemented, with the same
  47497. + * behavior as documented here.
  47498. + *
  47499. + * The Common library consists of higher level functions, which rely only on
  47500. + * calling the functions from the DWC Portability library. These common
  47501. + * routines are shared across modules. Some of the common libraries need to be
  47502. + * used directly by the driver programmer when porting WUDEV. Such as the
  47503. + * parameter and notification libraries.
  47504. + *
  47505. + * @section low Portability Library OS Wrapper Functions
  47506. + *
  47507. + * Any function starting with DWC and in all CAPS is a low-level OS-wrapper that
  47508. + * needs to be implemented when porting, for example DWC_MUTEX_ALLOC(). All of
  47509. + * these functions are included in the dwc_os.h file.
  47510. + *
  47511. + * There are many functions here covering a wide array of OS services. Please
  47512. + * see dwc_os.h for details, and implementation notes for each function.
  47513. + *
  47514. + * @section common Common Library Functions
  47515. + *
  47516. + * Any function starting with dwc and in all lowercase is a common library
  47517. + * routine. These functions have a portable implementation and do not need to
  47518. + * be reimplemented when porting. The common routines can be used by any
  47519. + * driver, and some must be used by the end user to control the drivers. For
  47520. + * example, you must use the Parameter common library in order to set the
  47521. + * parameters in the WUDEV module.
  47522. + *
  47523. + * The common libraries consist of the following:
  47524. + *
  47525. + * - Connection Contexts - Used internally and can be used by end-user. See dwc_cc.h
  47526. + * - Parameters - Used internally and can be used by end-user. See dwc_params.h
  47527. + * - Notifications - Used internally and can be used by end-user. See dwc_notifier.h
  47528. + * - Lists - Used internally and can be used by end-user. See dwc_list.h
  47529. + * - Memory Debugging - Used internally and can be used by end-user. See dwc_os.h
  47530. + * - Modpow - Used internally only. See dwc_modpow.h
  47531. + * - DH - Used internally only. See dwc_dh.h
  47532. + * - Crypto - Used internally only. See dwc_crypto.h
  47533. + *
  47534. + *
  47535. + * @section prereq Prerequistes For dwc_os.h
  47536. + * @subsection types Data Types
  47537. + *
  47538. + * The dwc_os.h file assumes that several low-level data types are pre defined for the
  47539. + * compilation environment. These data types are:
  47540. + *
  47541. + * - uint8_t - unsigned 8-bit data type
  47542. + * - int8_t - signed 8-bit data type
  47543. + * - uint16_t - unsigned 16-bit data type
  47544. + * - int16_t - signed 16-bit data type
  47545. + * - uint32_t - unsigned 32-bit data type
  47546. + * - int32_t - signed 32-bit data type
  47547. + * - uint64_t - unsigned 64-bit data type
  47548. + * - int64_t - signed 64-bit data type
  47549. + *
  47550. + * Ensure that these are defined before using dwc_os.h. The easiest way to do
  47551. + * that is to modify the top of the file to include the appropriate header.
  47552. + * This is already done for the Linux environment. If the DWC_LINUX macro is
  47553. + * defined, the correct header will be added. A standard header <stdint.h> is
  47554. + * also used for environments where standard C headers are available.
  47555. + *
  47556. + * @subsection stdarg Variable Arguments
  47557. + *
  47558. + * Variable arguments are provided by a standard C header <stdarg.h>. it is
  47559. + * available in Both the Linux and ANSI C enviornment. An equivalent must be
  47560. + * provided in your enviornment in order to use dwc_os.h with the debug and
  47561. + * tracing message functionality.
  47562. + *
  47563. + * @subsection thread Threading
  47564. + *
  47565. + * WUDEV Core must be run on an operating system that provides for multiple
  47566. + * threads/processes. Threading can be implemented in many ways, even in
  47567. + * embedded systems without an operating system. At the bare minimum, the
  47568. + * system should be able to start any number of processes at any time to handle
  47569. + * special work. It need not be a pre-emptive system. Process context can
  47570. + * change upon a call to a blocking function. The hardware interrupt context
  47571. + * that calls the module's ISR() function must be differentiable from process
  47572. + * context, even if your processes are impemented via a hardware interrupt.
  47573. + * Further locking mechanism between process must exist (or be implemented), and
  47574. + * process context must have a way to disable interrupts for a period of time to
  47575. + * lock them out. If all of this exists, the functions in dwc_os.h related to
  47576. + * threading should be able to be implemented with the defined behavior.
  47577. + *
  47578. + */
  47579. +
  47580. +#ifdef __cplusplus
  47581. +}
  47582. +#endif
  47583. +
  47584. +#endif /* _DWC_OS_H_ */
  47585. diff -Nur linux-3.13.11/drivers/usb/host/dwc_common_port/Makefile linux-rpi/drivers/usb/host/dwc_common_port/Makefile
  47586. --- linux-3.13.11/drivers/usb/host/dwc_common_port/Makefile 1970-01-01 01:00:00.000000000 +0100
  47587. +++ linux-rpi/drivers/usb/host/dwc_common_port/Makefile 2014-04-24 15:37:13.306990445 +0200
  47588. @@ -0,0 +1,58 @@
  47589. +#
  47590. +# Makefile for DWC_common library
  47591. +#
  47592. +
  47593. +ifneq ($(KERNELRELEASE),)
  47594. +
  47595. +ccflags-y += -DDWC_LINUX
  47596. +#ccflags-y += -DDEBUG
  47597. +#ccflags-y += -DDWC_DEBUG_REGS
  47598. +#ccflags-y += -DDWC_DEBUG_MEMORY
  47599. +
  47600. +ccflags-y += -DDWC_LIBMODULE
  47601. +ccflags-y += -DDWC_CCLIB
  47602. +#ccflags-y += -DDWC_CRYPTOLIB
  47603. +ccflags-y += -DDWC_NOTIFYLIB
  47604. +ccflags-y += -DDWC_UTFLIB
  47605. +
  47606. +obj-$(CONFIG_USB_DWCOTG) += dwc_common_port_lib.o
  47607. +dwc_common_port_lib-objs := dwc_cc.o dwc_modpow.o dwc_dh.o \
  47608. + dwc_crypto.o dwc_notifier.o \
  47609. + dwc_common_linux.o dwc_mem.o
  47610. +
  47611. +kernrelwd := $(subst ., ,$(KERNELRELEASE))
  47612. +kernrel3 := $(word 1,$(kernrelwd)).$(word 2,$(kernrelwd)).$(word 3,$(kernrelwd))
  47613. +
  47614. +ifneq ($(kernrel3),2.6.20)
  47615. +# grayg - I only know that we use ccflags-y in 2.6.31 actually
  47616. +ccflags-y += $(CPPFLAGS)
  47617. +endif
  47618. +
  47619. +else
  47620. +
  47621. +#ifeq ($(KDIR),)
  47622. +#$(error Must give "KDIR=/path/to/kernel/source" on command line or in environment)
  47623. +#endif
  47624. +
  47625. +ifeq ($(ARCH),)
  47626. +$(error Must give "ARCH=<arch>" on command line or in environment. Also, if \
  47627. + cross-compiling, must give "CROSS_COMPILE=/path/to/compiler/plus/tool-prefix-")
  47628. +endif
  47629. +
  47630. +ifeq ($(DOXYGEN),)
  47631. +DOXYGEN := doxygen
  47632. +endif
  47633. +
  47634. +default:
  47635. + $(MAKE) -C$(KDIR) M=$(PWD) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules
  47636. +
  47637. +docs: $(wildcard *.[hc]) doc/doxygen.cfg
  47638. + $(DOXYGEN) doc/doxygen.cfg
  47639. +
  47640. +tags: $(wildcard *.[hc])
  47641. + $(CTAGS) -e $(wildcard *.[hc]) $(wildcard linux/*.[hc]) $(wildcard $(KDIR)/include/linux/usb*.h)
  47642. +
  47643. +endif
  47644. +
  47645. +clean:
  47646. + rm -rf *.o *.ko .*.cmd *.mod.c .*.o.d .*.o.tmp modules.order Module.markers Module.symvers .tmp_versions/
  47647. diff -Nur linux-3.13.11/drivers/usb/host/dwc_common_port/Makefile.fbsd linux-rpi/drivers/usb/host/dwc_common_port/Makefile.fbsd
  47648. --- linux-3.13.11/drivers/usb/host/dwc_common_port/Makefile.fbsd 1970-01-01 01:00:00.000000000 +0100
  47649. +++ linux-rpi/drivers/usb/host/dwc_common_port/Makefile.fbsd 2014-04-24 15:35:04.169565731 +0200
  47650. @@ -0,0 +1,17 @@
  47651. +CFLAGS += -I/sys/i386/compile/GENERIC -I/sys/i386/include -I/usr/include
  47652. +CFLAGS += -DDWC_FREEBSD
  47653. +CFLAGS += -DDEBUG
  47654. +#CFLAGS += -DDWC_DEBUG_REGS
  47655. +#CFLAGS += -DDWC_DEBUG_MEMORY
  47656. +
  47657. +#CFLAGS += -DDWC_LIBMODULE
  47658. +#CFLAGS += -DDWC_CCLIB
  47659. +#CFLAGS += -DDWC_CRYPTOLIB
  47660. +#CFLAGS += -DDWC_NOTIFYLIB
  47661. +#CFLAGS += -DDWC_UTFLIB
  47662. +
  47663. +KMOD = dwc_common_port_lib
  47664. +SRCS = dwc_cc.c dwc_modpow.c dwc_dh.c dwc_crypto.c dwc_notifier.c \
  47665. + dwc_common_fbsd.c dwc_mem.c
  47666. +
  47667. +.include <bsd.kmod.mk>
  47668. diff -Nur linux-3.13.11/drivers/usb/host/dwc_common_port/Makefile.linux linux-rpi/drivers/usb/host/dwc_common_port/Makefile.linux
  47669. --- linux-3.13.11/drivers/usb/host/dwc_common_port/Makefile.linux 1970-01-01 01:00:00.000000000 +0100
  47670. +++ linux-rpi/drivers/usb/host/dwc_common_port/Makefile.linux 2014-04-24 15:35:04.169565731 +0200
  47671. @@ -0,0 +1,49 @@
  47672. +#
  47673. +# Makefile for DWC_common library
  47674. +#
  47675. +ifneq ($(KERNELRELEASE),)
  47676. +
  47677. +ccflags-y += -DDWC_LINUX
  47678. +#ccflags-y += -DDEBUG
  47679. +#ccflags-y += -DDWC_DEBUG_REGS
  47680. +#ccflags-y += -DDWC_DEBUG_MEMORY
  47681. +
  47682. +ccflags-y += -DDWC_LIBMODULE
  47683. +ccflags-y += -DDWC_CCLIB
  47684. +ccflags-y += -DDWC_CRYPTOLIB
  47685. +ccflags-y += -DDWC_NOTIFYLIB
  47686. +ccflags-y += -DDWC_UTFLIB
  47687. +
  47688. +obj-m := dwc_common_port_lib.o
  47689. +dwc_common_port_lib-objs := dwc_cc.o dwc_modpow.o dwc_dh.o \
  47690. + dwc_crypto.o dwc_notifier.o \
  47691. + dwc_common_linux.o dwc_mem.o
  47692. +
  47693. +else
  47694. +
  47695. +ifeq ($(KDIR),)
  47696. +$(error Must give "KDIR=/path/to/kernel/source" on command line or in environment)
  47697. +endif
  47698. +
  47699. +ifeq ($(ARCH),)
  47700. +$(error Must give "ARCH=<arch>" on command line or in environment. Also, if \
  47701. + cross-compiling, must give "CROSS_COMPILE=/path/to/compiler/plus/tool-prefix-")
  47702. +endif
  47703. +
  47704. +ifeq ($(DOXYGEN),)
  47705. +DOXYGEN := doxygen
  47706. +endif
  47707. +
  47708. +default:
  47709. + $(MAKE) -C$(KDIR) M=$(PWD) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules
  47710. +
  47711. +docs: $(wildcard *.[hc]) doc/doxygen.cfg
  47712. + $(DOXYGEN) doc/doxygen.cfg
  47713. +
  47714. +tags: $(wildcard *.[hc])
  47715. + $(CTAGS) -e $(wildcard *.[hc]) $(wildcard linux/*.[hc]) $(wildcard $(KDIR)/include/linux/usb*.h)
  47716. +
  47717. +endif
  47718. +
  47719. +clean:
  47720. + rm -rf *.o *.ko .*.cmd *.mod.c .*.o.d .*.o.tmp modules.order Module.markers Module.symvers .tmp_versions/
  47721. diff -Nur linux-3.13.11/drivers/usb/host/dwc_common_port/usb.h linux-rpi/drivers/usb/host/dwc_common_port/usb.h
  47722. --- linux-3.13.11/drivers/usb/host/dwc_common_port/usb.h 1970-01-01 01:00:00.000000000 +0100
  47723. +++ linux-rpi/drivers/usb/host/dwc_common_port/usb.h 2014-04-24 15:35:04.169565731 +0200
  47724. @@ -0,0 +1,946 @@
  47725. +/*
  47726. + * Copyright (c) 1998 The NetBSD Foundation, Inc.
  47727. + * All rights reserved.
  47728. + *
  47729. + * This code is derived from software contributed to The NetBSD Foundation
  47730. + * by Lennart Augustsson (lennart@augustsson.net) at
  47731. + * Carlstedt Research & Technology.
  47732. + *
  47733. + * Redistribution and use in source and binary forms, with or without
  47734. + * modification, are permitted provided that the following conditions
  47735. + * are met:
  47736. + * 1. Redistributions of source code must retain the above copyright
  47737. + * notice, this list of conditions and the following disclaimer.
  47738. + * 2. Redistributions in binary form must reproduce the above copyright
  47739. + * notice, this list of conditions and the following disclaimer in the
  47740. + * documentation and/or other materials provided with the distribution.
  47741. + * 3. All advertising materials mentioning features or use of this software
  47742. + * must display the following acknowledgement:
  47743. + * This product includes software developed by the NetBSD
  47744. + * Foundation, Inc. and its contributors.
  47745. + * 4. Neither the name of The NetBSD Foundation nor the names of its
  47746. + * contributors may be used to endorse or promote products derived
  47747. + * from this software without specific prior written permission.
  47748. + *
  47749. + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  47750. + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  47751. + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  47752. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
  47753. + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  47754. + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  47755. + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  47756. + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  47757. + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  47758. + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  47759. + * POSSIBILITY OF SUCH DAMAGE.
  47760. + */
  47761. +
  47762. +/* Modified by Synopsys, Inc, 12/12/2007 */
  47763. +
  47764. +
  47765. +#ifndef _USB_H_
  47766. +#define _USB_H_
  47767. +
  47768. +#ifdef __cplusplus
  47769. +extern "C" {
  47770. +#endif
  47771. +
  47772. +/*
  47773. + * The USB records contain some unaligned little-endian word
  47774. + * components. The U[SG]ETW macros take care of both the alignment
  47775. + * and endian problem and should always be used to access non-byte
  47776. + * values.
  47777. + */
  47778. +typedef u_int8_t uByte;
  47779. +typedef u_int8_t uWord[2];
  47780. +typedef u_int8_t uDWord[4];
  47781. +
  47782. +#define USETW2(w,h,l) ((w)[0] = (u_int8_t)(l), (w)[1] = (u_int8_t)(h))
  47783. +#define UCONSTW(x) { (x) & 0xff, ((x) >> 8) & 0xff }
  47784. +#define UCONSTDW(x) { (x) & 0xff, ((x) >> 8) & 0xff, \
  47785. + ((x) >> 16) & 0xff, ((x) >> 24) & 0xff }
  47786. +
  47787. +#if 1
  47788. +#define UGETW(w) ((w)[0] | ((w)[1] << 8))
  47789. +#define USETW(w,v) ((w)[0] = (u_int8_t)(v), (w)[1] = (u_int8_t)((v) >> 8))
  47790. +#define UGETDW(w) ((w)[0] | ((w)[1] << 8) | ((w)[2] << 16) | ((w)[3] << 24))
  47791. +#define USETDW(w,v) ((w)[0] = (u_int8_t)(v), \
  47792. + (w)[1] = (u_int8_t)((v) >> 8), \
  47793. + (w)[2] = (u_int8_t)((v) >> 16), \
  47794. + (w)[3] = (u_int8_t)((v) >> 24))
  47795. +#else
  47796. +/*
  47797. + * On little-endian machines that can handle unanliged accesses
  47798. + * (e.g. i386) these macros can be replaced by the following.
  47799. + */
  47800. +#define UGETW(w) (*(u_int16_t *)(w))
  47801. +#define USETW(w,v) (*(u_int16_t *)(w) = (v))
  47802. +#define UGETDW(w) (*(u_int32_t *)(w))
  47803. +#define USETDW(w,v) (*(u_int32_t *)(w) = (v))
  47804. +#endif
  47805. +
  47806. +/*
  47807. + * Macros for accessing UAS IU fields, which are big-endian
  47808. + */
  47809. +#define IUSETW2(w,h,l) ((w)[0] = (u_int8_t)(h), (w)[1] = (u_int8_t)(l))
  47810. +#define IUCONSTW(x) { ((x) >> 8) & 0xff, (x) & 0xff }
  47811. +#define IUCONSTDW(x) { ((x) >> 24) & 0xff, ((x) >> 16) & 0xff, \
  47812. + ((x) >> 8) & 0xff, (x) & 0xff }
  47813. +#define IUGETW(w) (((w)[0] << 8) | (w)[1])
  47814. +#define IUSETW(w,v) ((w)[0] = (u_int8_t)((v) >> 8), (w)[1] = (u_int8_t)(v))
  47815. +#define IUGETDW(w) (((w)[0] << 24) | ((w)[1] << 16) | ((w)[2] << 8) | (w)[3])
  47816. +#define IUSETDW(w,v) ((w)[0] = (u_int8_t)((v) >> 24), \
  47817. + (w)[1] = (u_int8_t)((v) >> 16), \
  47818. + (w)[2] = (u_int8_t)((v) >> 8), \
  47819. + (w)[3] = (u_int8_t)(v))
  47820. +
  47821. +#define UPACKED __attribute__((__packed__))
  47822. +
  47823. +typedef struct {
  47824. + uByte bmRequestType;
  47825. + uByte bRequest;
  47826. + uWord wValue;
  47827. + uWord wIndex;
  47828. + uWord wLength;
  47829. +} UPACKED usb_device_request_t;
  47830. +
  47831. +#define UT_GET_DIR(a) ((a) & 0x80)
  47832. +#define UT_WRITE 0x00
  47833. +#define UT_READ 0x80
  47834. +
  47835. +#define UT_GET_TYPE(a) ((a) & 0x60)
  47836. +#define UT_STANDARD 0x00
  47837. +#define UT_CLASS 0x20
  47838. +#define UT_VENDOR 0x40
  47839. +
  47840. +#define UT_GET_RECIPIENT(a) ((a) & 0x1f)
  47841. +#define UT_DEVICE 0x00
  47842. +#define UT_INTERFACE 0x01
  47843. +#define UT_ENDPOINT 0x02
  47844. +#define UT_OTHER 0x03
  47845. +
  47846. +#define UT_READ_DEVICE (UT_READ | UT_STANDARD | UT_DEVICE)
  47847. +#define UT_READ_INTERFACE (UT_READ | UT_STANDARD | UT_INTERFACE)
  47848. +#define UT_READ_ENDPOINT (UT_READ | UT_STANDARD | UT_ENDPOINT)
  47849. +#define UT_WRITE_DEVICE (UT_WRITE | UT_STANDARD | UT_DEVICE)
  47850. +#define UT_WRITE_INTERFACE (UT_WRITE | UT_STANDARD | UT_INTERFACE)
  47851. +#define UT_WRITE_ENDPOINT (UT_WRITE | UT_STANDARD | UT_ENDPOINT)
  47852. +#define UT_READ_CLASS_DEVICE (UT_READ | UT_CLASS | UT_DEVICE)
  47853. +#define UT_READ_CLASS_INTERFACE (UT_READ | UT_CLASS | UT_INTERFACE)
  47854. +#define UT_READ_CLASS_OTHER (UT_READ | UT_CLASS | UT_OTHER)
  47855. +#define UT_READ_CLASS_ENDPOINT (UT_READ | UT_CLASS | UT_ENDPOINT)
  47856. +#define UT_WRITE_CLASS_DEVICE (UT_WRITE | UT_CLASS | UT_DEVICE)
  47857. +#define UT_WRITE_CLASS_INTERFACE (UT_WRITE | UT_CLASS | UT_INTERFACE)
  47858. +#define UT_WRITE_CLASS_OTHER (UT_WRITE | UT_CLASS | UT_OTHER)
  47859. +#define UT_WRITE_CLASS_ENDPOINT (UT_WRITE | UT_CLASS | UT_ENDPOINT)
  47860. +#define UT_READ_VENDOR_DEVICE (UT_READ | UT_VENDOR | UT_DEVICE)
  47861. +#define UT_READ_VENDOR_INTERFACE (UT_READ | UT_VENDOR | UT_INTERFACE)
  47862. +#define UT_READ_VENDOR_OTHER (UT_READ | UT_VENDOR | UT_OTHER)
  47863. +#define UT_READ_VENDOR_ENDPOINT (UT_READ | UT_VENDOR | UT_ENDPOINT)
  47864. +#define UT_WRITE_VENDOR_DEVICE (UT_WRITE | UT_VENDOR | UT_DEVICE)
  47865. +#define UT_WRITE_VENDOR_INTERFACE (UT_WRITE | UT_VENDOR | UT_INTERFACE)
  47866. +#define UT_WRITE_VENDOR_OTHER (UT_WRITE | UT_VENDOR | UT_OTHER)
  47867. +#define UT_WRITE_VENDOR_ENDPOINT (UT_WRITE | UT_VENDOR | UT_ENDPOINT)
  47868. +
  47869. +/* Requests */
  47870. +#define UR_GET_STATUS 0x00
  47871. +#define USTAT_STANDARD_STATUS 0x00
  47872. +#define WUSTAT_WUSB_FEATURE 0x01
  47873. +#define WUSTAT_CHANNEL_INFO 0x02
  47874. +#define WUSTAT_RECEIVED_DATA 0x03
  47875. +#define WUSTAT_MAS_AVAILABILITY 0x04
  47876. +#define WUSTAT_CURRENT_TRANSMIT_POWER 0x05
  47877. +#define UR_CLEAR_FEATURE 0x01
  47878. +#define UR_SET_FEATURE 0x03
  47879. +#define UR_SET_AND_TEST_FEATURE 0x0c
  47880. +#define UR_SET_ADDRESS 0x05
  47881. +#define UR_GET_DESCRIPTOR 0x06
  47882. +#define UDESC_DEVICE 0x01
  47883. +#define UDESC_CONFIG 0x02
  47884. +#define UDESC_STRING 0x03
  47885. +#define UDESC_INTERFACE 0x04
  47886. +#define UDESC_ENDPOINT 0x05
  47887. +#define UDESC_SS_USB_COMPANION 0x30
  47888. +#define UDESC_DEVICE_QUALIFIER 0x06
  47889. +#define UDESC_OTHER_SPEED_CONFIGURATION 0x07
  47890. +#define UDESC_INTERFACE_POWER 0x08
  47891. +#define UDESC_OTG 0x09
  47892. +#define WUDESC_SECURITY 0x0c
  47893. +#define WUDESC_KEY 0x0d
  47894. +#define WUD_GET_KEY_INDEX(_wValue_) ((_wValue_) & 0xf)
  47895. +#define WUD_GET_KEY_TYPE(_wValue_) (((_wValue_) & 0x30) >> 4)
  47896. +#define WUD_KEY_TYPE_ASSOC 0x01
  47897. +#define WUD_KEY_TYPE_GTK 0x02
  47898. +#define WUD_GET_KEY_ORIGIN(_wValue_) (((_wValue_) & 0x40) >> 6)
  47899. +#define WUD_KEY_ORIGIN_HOST 0x00
  47900. +#define WUD_KEY_ORIGIN_DEVICE 0x01
  47901. +#define WUDESC_ENCRYPTION_TYPE 0x0e
  47902. +#define WUDESC_BOS 0x0f
  47903. +#define WUDESC_DEVICE_CAPABILITY 0x10
  47904. +#define WUDESC_WIRELESS_ENDPOINT_COMPANION 0x11
  47905. +#define UDESC_BOS 0x0f
  47906. +#define UDESC_DEVICE_CAPABILITY 0x10
  47907. +#define UDESC_CS_DEVICE 0x21 /* class specific */
  47908. +#define UDESC_CS_CONFIG 0x22
  47909. +#define UDESC_CS_STRING 0x23
  47910. +#define UDESC_CS_INTERFACE 0x24
  47911. +#define UDESC_CS_ENDPOINT 0x25
  47912. +#define UDESC_HUB 0x29
  47913. +#define UR_SET_DESCRIPTOR 0x07
  47914. +#define UR_GET_CONFIG 0x08
  47915. +#define UR_SET_CONFIG 0x09
  47916. +#define UR_GET_INTERFACE 0x0a
  47917. +#define UR_SET_INTERFACE 0x0b
  47918. +#define UR_SYNCH_FRAME 0x0c
  47919. +#define WUR_SET_ENCRYPTION 0x0d
  47920. +#define WUR_GET_ENCRYPTION 0x0e
  47921. +#define WUR_SET_HANDSHAKE 0x0f
  47922. +#define WUR_GET_HANDSHAKE 0x10
  47923. +#define WUR_SET_CONNECTION 0x11
  47924. +#define WUR_SET_SECURITY_DATA 0x12
  47925. +#define WUR_GET_SECURITY_DATA 0x13
  47926. +#define WUR_SET_WUSB_DATA 0x14
  47927. +#define WUDATA_DRPIE_INFO 0x01
  47928. +#define WUDATA_TRANSMIT_DATA 0x02
  47929. +#define WUDATA_TRANSMIT_PARAMS 0x03
  47930. +#define WUDATA_RECEIVE_PARAMS 0x04
  47931. +#define WUDATA_TRANSMIT_POWER 0x05
  47932. +#define WUR_LOOPBACK_DATA_WRITE 0x15
  47933. +#define WUR_LOOPBACK_DATA_READ 0x16
  47934. +#define WUR_SET_INTERFACE_DS 0x17
  47935. +
  47936. +/* Feature numbers */
  47937. +#define UF_ENDPOINT_HALT 0
  47938. +#define UF_DEVICE_REMOTE_WAKEUP 1
  47939. +#define UF_TEST_MODE 2
  47940. +#define UF_DEVICE_B_HNP_ENABLE 3
  47941. +#define UF_DEVICE_A_HNP_SUPPORT 4
  47942. +#define UF_DEVICE_A_ALT_HNP_SUPPORT 5
  47943. +#define WUF_WUSB 3
  47944. +#define WUF_TX_DRPIE 0x0
  47945. +#define WUF_DEV_XMIT_PACKET 0x1
  47946. +#define WUF_COUNT_PACKETS 0x2
  47947. +#define WUF_CAPTURE_PACKETS 0x3
  47948. +#define UF_FUNCTION_SUSPEND 0
  47949. +#define UF_U1_ENABLE 48
  47950. +#define UF_U2_ENABLE 49
  47951. +#define UF_LTM_ENABLE 50
  47952. +
  47953. +/* Class requests from the USB 2.0 hub spec, table 11-15 */
  47954. +#define UCR_CLEAR_HUB_FEATURE (0x2000 | UR_CLEAR_FEATURE)
  47955. +#define UCR_CLEAR_PORT_FEATURE (0x2300 | UR_CLEAR_FEATURE)
  47956. +#define UCR_GET_HUB_DESCRIPTOR (0xa000 | UR_GET_DESCRIPTOR)
  47957. +#define UCR_GET_HUB_STATUS (0xa000 | UR_GET_STATUS)
  47958. +#define UCR_GET_PORT_STATUS (0xa300 | UR_GET_STATUS)
  47959. +#define UCR_SET_HUB_FEATURE (0x2000 | UR_SET_FEATURE)
  47960. +#define UCR_SET_PORT_FEATURE (0x2300 | UR_SET_FEATURE)
  47961. +#define UCR_SET_AND_TEST_PORT_FEATURE (0xa300 | UR_SET_AND_TEST_FEATURE)
  47962. +
  47963. +#ifdef _MSC_VER
  47964. +#include <pshpack1.h>
  47965. +#endif
  47966. +
  47967. +typedef struct {
  47968. + uByte bLength;
  47969. + uByte bDescriptorType;
  47970. + uByte bDescriptorSubtype;
  47971. +} UPACKED usb_descriptor_t;
  47972. +
  47973. +typedef struct {
  47974. + uByte bLength;
  47975. + uByte bDescriptorType;
  47976. +} UPACKED usb_descriptor_header_t;
  47977. +
  47978. +typedef struct {
  47979. + uByte bLength;
  47980. + uByte bDescriptorType;
  47981. + uWord bcdUSB;
  47982. +#define UD_USB_2_0 0x0200
  47983. +#define UD_IS_USB2(d) (UGETW((d)->bcdUSB) >= UD_USB_2_0)
  47984. + uByte bDeviceClass;
  47985. + uByte bDeviceSubClass;
  47986. + uByte bDeviceProtocol;
  47987. + uByte bMaxPacketSize;
  47988. + /* The fields below are not part of the initial descriptor. */
  47989. + uWord idVendor;
  47990. + uWord idProduct;
  47991. + uWord bcdDevice;
  47992. + uByte iManufacturer;
  47993. + uByte iProduct;
  47994. + uByte iSerialNumber;
  47995. + uByte bNumConfigurations;
  47996. +} UPACKED usb_device_descriptor_t;
  47997. +#define USB_DEVICE_DESCRIPTOR_SIZE 18
  47998. +
  47999. +typedef struct {
  48000. + uByte bLength;
  48001. + uByte bDescriptorType;
  48002. + uWord wTotalLength;
  48003. + uByte bNumInterface;
  48004. + uByte bConfigurationValue;
  48005. + uByte iConfiguration;
  48006. +#define UC_ATT_ONE (1 << 7) /* must be set */
  48007. +#define UC_ATT_SELFPOWER (1 << 6) /* self powered */
  48008. +#define UC_ATT_WAKEUP (1 << 5) /* can wakeup */
  48009. +#define UC_ATT_BATTERY (1 << 4) /* battery powered */
  48010. + uByte bmAttributes;
  48011. +#define UC_BUS_POWERED 0x80
  48012. +#define UC_SELF_POWERED 0x40
  48013. +#define UC_REMOTE_WAKEUP 0x20
  48014. + uByte bMaxPower; /* max current in 2 mA units */
  48015. +#define UC_POWER_FACTOR 2
  48016. +} UPACKED usb_config_descriptor_t;
  48017. +#define USB_CONFIG_DESCRIPTOR_SIZE 9
  48018. +
  48019. +typedef struct {
  48020. + uByte bLength;
  48021. + uByte bDescriptorType;
  48022. + uByte bInterfaceNumber;
  48023. + uByte bAlternateSetting;
  48024. + uByte bNumEndpoints;
  48025. + uByte bInterfaceClass;
  48026. + uByte bInterfaceSubClass;
  48027. + uByte bInterfaceProtocol;
  48028. + uByte iInterface;
  48029. +} UPACKED usb_interface_descriptor_t;
  48030. +#define USB_INTERFACE_DESCRIPTOR_SIZE 9
  48031. +
  48032. +typedef struct {
  48033. + uByte bLength;
  48034. + uByte bDescriptorType;
  48035. + uByte bEndpointAddress;
  48036. +#define UE_GET_DIR(a) ((a) & 0x80)
  48037. +#define UE_SET_DIR(a,d) ((a) | (((d)&1) << 7))
  48038. +#define UE_DIR_IN 0x80
  48039. +#define UE_DIR_OUT 0x00
  48040. +#define UE_ADDR 0x0f
  48041. +#define UE_GET_ADDR(a) ((a) & UE_ADDR)
  48042. + uByte bmAttributes;
  48043. +#define UE_XFERTYPE 0x03
  48044. +#define UE_CONTROL 0x00
  48045. +#define UE_ISOCHRONOUS 0x01
  48046. +#define UE_BULK 0x02
  48047. +#define UE_INTERRUPT 0x03
  48048. +#define UE_GET_XFERTYPE(a) ((a) & UE_XFERTYPE)
  48049. +#define UE_ISO_TYPE 0x0c
  48050. +#define UE_ISO_ASYNC 0x04
  48051. +#define UE_ISO_ADAPT 0x08
  48052. +#define UE_ISO_SYNC 0x0c
  48053. +#define UE_GET_ISO_TYPE(a) ((a) & UE_ISO_TYPE)
  48054. + uWord wMaxPacketSize;
  48055. + uByte bInterval;
  48056. +} UPACKED usb_endpoint_descriptor_t;
  48057. +#define USB_ENDPOINT_DESCRIPTOR_SIZE 7
  48058. +
  48059. +typedef struct ss_endpoint_companion_descriptor {
  48060. + uByte bLength;
  48061. + uByte bDescriptorType;
  48062. + uByte bMaxBurst;
  48063. +#define USSE_GET_MAX_STREAMS(a) ((a) & 0x1f)
  48064. +#define USSE_SET_MAX_STREAMS(a, b) ((a) | ((b) & 0x1f))
  48065. +#define USSE_GET_MAX_PACKET_NUM(a) ((a) & 0x03)
  48066. +#define USSE_SET_MAX_PACKET_NUM(a, b) ((a) | ((b) & 0x03))
  48067. + uByte bmAttributes;
  48068. + uWord wBytesPerInterval;
  48069. +} UPACKED ss_endpoint_companion_descriptor_t;
  48070. +#define USB_SS_ENDPOINT_COMPANION_DESCRIPTOR_SIZE 6
  48071. +
  48072. +typedef struct {
  48073. + uByte bLength;
  48074. + uByte bDescriptorType;
  48075. + uWord bString[127];
  48076. +} UPACKED usb_string_descriptor_t;
  48077. +#define USB_MAX_STRING_LEN 128
  48078. +#define USB_LANGUAGE_TABLE 0 /* # of the string language id table */
  48079. +
  48080. +/* Hub specific request */
  48081. +#define UR_GET_BUS_STATE 0x02
  48082. +#define UR_CLEAR_TT_BUFFER 0x08
  48083. +#define UR_RESET_TT 0x09
  48084. +#define UR_GET_TT_STATE 0x0a
  48085. +#define UR_STOP_TT 0x0b
  48086. +
  48087. +/* Hub features */
  48088. +#define UHF_C_HUB_LOCAL_POWER 0
  48089. +#define UHF_C_HUB_OVER_CURRENT 1
  48090. +#define UHF_PORT_CONNECTION 0
  48091. +#define UHF_PORT_ENABLE 1
  48092. +#define UHF_PORT_SUSPEND 2
  48093. +#define UHF_PORT_OVER_CURRENT 3
  48094. +#define UHF_PORT_RESET 4
  48095. +#define UHF_PORT_L1 5
  48096. +#define UHF_PORT_POWER 8
  48097. +#define UHF_PORT_LOW_SPEED 9
  48098. +#define UHF_PORT_HIGH_SPEED 10
  48099. +#define UHF_C_PORT_CONNECTION 16
  48100. +#define UHF_C_PORT_ENABLE 17
  48101. +#define UHF_C_PORT_SUSPEND 18
  48102. +#define UHF_C_PORT_OVER_CURRENT 19
  48103. +#define UHF_C_PORT_RESET 20
  48104. +#define UHF_C_PORT_L1 23
  48105. +#define UHF_PORT_TEST 21
  48106. +#define UHF_PORT_INDICATOR 22
  48107. +
  48108. +typedef struct {
  48109. + uByte bDescLength;
  48110. + uByte bDescriptorType;
  48111. + uByte bNbrPorts;
  48112. + uWord wHubCharacteristics;
  48113. +#define UHD_PWR 0x0003
  48114. +#define UHD_PWR_GANGED 0x0000
  48115. +#define UHD_PWR_INDIVIDUAL 0x0001
  48116. +#define UHD_PWR_NO_SWITCH 0x0002
  48117. +#define UHD_COMPOUND 0x0004
  48118. +#define UHD_OC 0x0018
  48119. +#define UHD_OC_GLOBAL 0x0000
  48120. +#define UHD_OC_INDIVIDUAL 0x0008
  48121. +#define UHD_OC_NONE 0x0010
  48122. +#define UHD_TT_THINK 0x0060
  48123. +#define UHD_TT_THINK_8 0x0000
  48124. +#define UHD_TT_THINK_16 0x0020
  48125. +#define UHD_TT_THINK_24 0x0040
  48126. +#define UHD_TT_THINK_32 0x0060
  48127. +#define UHD_PORT_IND 0x0080
  48128. + uByte bPwrOn2PwrGood; /* delay in 2 ms units */
  48129. +#define UHD_PWRON_FACTOR 2
  48130. + uByte bHubContrCurrent;
  48131. + uByte DeviceRemovable[32]; /* max 255 ports */
  48132. +#define UHD_NOT_REMOV(desc, i) \
  48133. + (((desc)->DeviceRemovable[(i)/8] >> ((i) % 8)) & 1)
  48134. + /* deprecated */ uByte PortPowerCtrlMask[1];
  48135. +} UPACKED usb_hub_descriptor_t;
  48136. +#define USB_HUB_DESCRIPTOR_SIZE 9 /* includes deprecated PortPowerCtrlMask */
  48137. +
  48138. +typedef struct {
  48139. + uByte bLength;
  48140. + uByte bDescriptorType;
  48141. + uWord bcdUSB;
  48142. + uByte bDeviceClass;
  48143. + uByte bDeviceSubClass;
  48144. + uByte bDeviceProtocol;
  48145. + uByte bMaxPacketSize0;
  48146. + uByte bNumConfigurations;
  48147. + uByte bReserved;
  48148. +} UPACKED usb_device_qualifier_t;
  48149. +#define USB_DEVICE_QUALIFIER_SIZE 10
  48150. +
  48151. +typedef struct {
  48152. + uByte bLength;
  48153. + uByte bDescriptorType;
  48154. + uByte bmAttributes;
  48155. +#define UOTG_SRP 0x01
  48156. +#define UOTG_HNP 0x02
  48157. +} UPACKED usb_otg_descriptor_t;
  48158. +
  48159. +/* OTG feature selectors */
  48160. +#define UOTG_B_HNP_ENABLE 3
  48161. +#define UOTG_A_HNP_SUPPORT 4
  48162. +#define UOTG_A_ALT_HNP_SUPPORT 5
  48163. +
  48164. +typedef struct {
  48165. + uWord wStatus;
  48166. +/* Device status flags */
  48167. +#define UDS_SELF_POWERED 0x0001
  48168. +#define UDS_REMOTE_WAKEUP 0x0002
  48169. +/* Endpoint status flags */
  48170. +#define UES_HALT 0x0001
  48171. +} UPACKED usb_status_t;
  48172. +
  48173. +typedef struct {
  48174. + uWord wHubStatus;
  48175. +#define UHS_LOCAL_POWER 0x0001
  48176. +#define UHS_OVER_CURRENT 0x0002
  48177. + uWord wHubChange;
  48178. +} UPACKED usb_hub_status_t;
  48179. +
  48180. +typedef struct {
  48181. + uWord wPortStatus;
  48182. +#define UPS_CURRENT_CONNECT_STATUS 0x0001
  48183. +#define UPS_PORT_ENABLED 0x0002
  48184. +#define UPS_SUSPEND 0x0004
  48185. +#define UPS_OVERCURRENT_INDICATOR 0x0008
  48186. +#define UPS_RESET 0x0010
  48187. +#define UPS_PORT_POWER 0x0100
  48188. +#define UPS_LOW_SPEED 0x0200
  48189. +#define UPS_HIGH_SPEED 0x0400
  48190. +#define UPS_PORT_TEST 0x0800
  48191. +#define UPS_PORT_INDICATOR 0x1000
  48192. + uWord wPortChange;
  48193. +#define UPS_C_CONNECT_STATUS 0x0001
  48194. +#define UPS_C_PORT_ENABLED 0x0002
  48195. +#define UPS_C_SUSPEND 0x0004
  48196. +#define UPS_C_OVERCURRENT_INDICATOR 0x0008
  48197. +#define UPS_C_PORT_RESET 0x0010
  48198. +} UPACKED usb_port_status_t;
  48199. +
  48200. +#ifdef _MSC_VER
  48201. +#include <poppack.h>
  48202. +#endif
  48203. +
  48204. +/* Device class codes */
  48205. +#define UDCLASS_IN_INTERFACE 0x00
  48206. +#define UDCLASS_COMM 0x02
  48207. +#define UDCLASS_HUB 0x09
  48208. +#define UDSUBCLASS_HUB 0x00
  48209. +#define UDPROTO_FSHUB 0x00
  48210. +#define UDPROTO_HSHUBSTT 0x01
  48211. +#define UDPROTO_HSHUBMTT 0x02
  48212. +#define UDCLASS_DIAGNOSTIC 0xdc
  48213. +#define UDCLASS_WIRELESS 0xe0
  48214. +#define UDSUBCLASS_RF 0x01
  48215. +#define UDPROTO_BLUETOOTH 0x01
  48216. +#define UDCLASS_VENDOR 0xff
  48217. +
  48218. +/* Interface class codes */
  48219. +#define UICLASS_UNSPEC 0x00
  48220. +
  48221. +#define UICLASS_AUDIO 0x01
  48222. +#define UISUBCLASS_AUDIOCONTROL 1
  48223. +#define UISUBCLASS_AUDIOSTREAM 2
  48224. +#define UISUBCLASS_MIDISTREAM 3
  48225. +
  48226. +#define UICLASS_CDC 0x02 /* communication */
  48227. +#define UISUBCLASS_DIRECT_LINE_CONTROL_MODEL 1
  48228. +#define UISUBCLASS_ABSTRACT_CONTROL_MODEL 2
  48229. +#define UISUBCLASS_TELEPHONE_CONTROL_MODEL 3
  48230. +#define UISUBCLASS_MULTICHANNEL_CONTROL_MODEL 4
  48231. +#define UISUBCLASS_CAPI_CONTROLMODEL 5
  48232. +#define UISUBCLASS_ETHERNET_NETWORKING_CONTROL_MODEL 6
  48233. +#define UISUBCLASS_ATM_NETWORKING_CONTROL_MODEL 7
  48234. +#define UIPROTO_CDC_AT 1
  48235. +
  48236. +#define UICLASS_HID 0x03
  48237. +#define UISUBCLASS_BOOT 1
  48238. +#define UIPROTO_BOOT_KEYBOARD 1
  48239. +
  48240. +#define UICLASS_PHYSICAL 0x05
  48241. +
  48242. +#define UICLASS_IMAGE 0x06
  48243. +
  48244. +#define UICLASS_PRINTER 0x07
  48245. +#define UISUBCLASS_PRINTER 1
  48246. +#define UIPROTO_PRINTER_UNI 1
  48247. +#define UIPROTO_PRINTER_BI 2
  48248. +#define UIPROTO_PRINTER_1284 3
  48249. +
  48250. +#define UICLASS_MASS 0x08
  48251. +#define UISUBCLASS_RBC 1
  48252. +#define UISUBCLASS_SFF8020I 2
  48253. +#define UISUBCLASS_QIC157 3
  48254. +#define UISUBCLASS_UFI 4
  48255. +#define UISUBCLASS_SFF8070I 5
  48256. +#define UISUBCLASS_SCSI 6
  48257. +#define UIPROTO_MASS_CBI_I 0
  48258. +#define UIPROTO_MASS_CBI 1
  48259. +#define UIPROTO_MASS_BBB_OLD 2 /* Not in the spec anymore */
  48260. +#define UIPROTO_MASS_BBB 80 /* 'P' for the Iomega Zip drive */
  48261. +
  48262. +#define UICLASS_HUB 0x09
  48263. +#define UISUBCLASS_HUB 0
  48264. +#define UIPROTO_FSHUB 0
  48265. +#define UIPROTO_HSHUBSTT 0 /* Yes, same as previous */
  48266. +#define UIPROTO_HSHUBMTT 1
  48267. +
  48268. +#define UICLASS_CDC_DATA 0x0a
  48269. +#define UISUBCLASS_DATA 0
  48270. +#define UIPROTO_DATA_ISDNBRI 0x30 /* Physical iface */
  48271. +#define UIPROTO_DATA_HDLC 0x31 /* HDLC */
  48272. +#define UIPROTO_DATA_TRANSPARENT 0x32 /* Transparent */
  48273. +#define UIPROTO_DATA_Q921M 0x50 /* Management for Q921 */
  48274. +#define UIPROTO_DATA_Q921 0x51 /* Data for Q921 */
  48275. +#define UIPROTO_DATA_Q921TM 0x52 /* TEI multiplexer for Q921 */
  48276. +#define UIPROTO_DATA_V42BIS 0x90 /* Data compression */
  48277. +#define UIPROTO_DATA_Q931 0x91 /* Euro-ISDN */
  48278. +#define UIPROTO_DATA_V120 0x92 /* V.24 rate adaption */
  48279. +#define UIPROTO_DATA_CAPI 0x93 /* CAPI 2.0 commands */
  48280. +#define UIPROTO_DATA_HOST_BASED 0xfd /* Host based driver */
  48281. +#define UIPROTO_DATA_PUF 0xfe /* see Prot. Unit Func. Desc.*/
  48282. +#define UIPROTO_DATA_VENDOR 0xff /* Vendor specific */
  48283. +
  48284. +#define UICLASS_SMARTCARD 0x0b
  48285. +
  48286. +/*#define UICLASS_FIRM_UPD 0x0c*/
  48287. +
  48288. +#define UICLASS_SECURITY 0x0d
  48289. +
  48290. +#define UICLASS_DIAGNOSTIC 0xdc
  48291. +
  48292. +#define UICLASS_WIRELESS 0xe0
  48293. +#define UISUBCLASS_RF 0x01
  48294. +#define UIPROTO_BLUETOOTH 0x01
  48295. +
  48296. +#define UICLASS_APPL_SPEC 0xfe
  48297. +#define UISUBCLASS_FIRMWARE_DOWNLOAD 1
  48298. +#define UISUBCLASS_IRDA 2
  48299. +#define UIPROTO_IRDA 0
  48300. +
  48301. +#define UICLASS_VENDOR 0xff
  48302. +
  48303. +#define USB_HUB_MAX_DEPTH 5
  48304. +
  48305. +/*
  48306. + * Minimum time a device needs to be powered down to go through
  48307. + * a power cycle. XXX Are these time in the spec?
  48308. + */
  48309. +#define USB_POWER_DOWN_TIME 200 /* ms */
  48310. +#define USB_PORT_POWER_DOWN_TIME 100 /* ms */
  48311. +
  48312. +#if 0
  48313. +/* These are the values from the spec. */
  48314. +#define USB_PORT_RESET_DELAY 10 /* ms */
  48315. +#define USB_PORT_ROOT_RESET_DELAY 50 /* ms */
  48316. +#define USB_PORT_RESET_RECOVERY 10 /* ms */
  48317. +#define USB_PORT_POWERUP_DELAY 100 /* ms */
  48318. +#define USB_SET_ADDRESS_SETTLE 2 /* ms */
  48319. +#define USB_RESUME_DELAY (20*5) /* ms */
  48320. +#define USB_RESUME_WAIT 10 /* ms */
  48321. +#define USB_RESUME_RECOVERY 10 /* ms */
  48322. +#define USB_EXTRA_POWER_UP_TIME 0 /* ms */
  48323. +#else
  48324. +/* Allow for marginal (i.e. non-conforming) devices. */
  48325. +#define USB_PORT_RESET_DELAY 50 /* ms */
  48326. +#define USB_PORT_ROOT_RESET_DELAY 250 /* ms */
  48327. +#define USB_PORT_RESET_RECOVERY 250 /* ms */
  48328. +#define USB_PORT_POWERUP_DELAY 300 /* ms */
  48329. +#define USB_SET_ADDRESS_SETTLE 10 /* ms */
  48330. +#define USB_RESUME_DELAY (50*5) /* ms */
  48331. +#define USB_RESUME_WAIT 50 /* ms */
  48332. +#define USB_RESUME_RECOVERY 50 /* ms */
  48333. +#define USB_EXTRA_POWER_UP_TIME 20 /* ms */
  48334. +#endif
  48335. +
  48336. +#define USB_MIN_POWER 100 /* mA */
  48337. +#define USB_MAX_POWER 500 /* mA */
  48338. +
  48339. +#define USB_BUS_RESET_DELAY 100 /* ms XXX?*/
  48340. +
  48341. +#define USB_UNCONFIG_NO 0
  48342. +#define USB_UNCONFIG_INDEX (-1)
  48343. +
  48344. +/*** ioctl() related stuff ***/
  48345. +
  48346. +struct usb_ctl_request {
  48347. + int ucr_addr;
  48348. + usb_device_request_t ucr_request;
  48349. + void *ucr_data;
  48350. + int ucr_flags;
  48351. +#define USBD_SHORT_XFER_OK 0x04 /* allow short reads */
  48352. + int ucr_actlen; /* actual length transferred */
  48353. +};
  48354. +
  48355. +struct usb_alt_interface {
  48356. + int uai_config_index;
  48357. + int uai_interface_index;
  48358. + int uai_alt_no;
  48359. +};
  48360. +
  48361. +#define USB_CURRENT_CONFIG_INDEX (-1)
  48362. +#define USB_CURRENT_ALT_INDEX (-1)
  48363. +
  48364. +struct usb_config_desc {
  48365. + int ucd_config_index;
  48366. + usb_config_descriptor_t ucd_desc;
  48367. +};
  48368. +
  48369. +struct usb_interface_desc {
  48370. + int uid_config_index;
  48371. + int uid_interface_index;
  48372. + int uid_alt_index;
  48373. + usb_interface_descriptor_t uid_desc;
  48374. +};
  48375. +
  48376. +struct usb_endpoint_desc {
  48377. + int ued_config_index;
  48378. + int ued_interface_index;
  48379. + int ued_alt_index;
  48380. + int ued_endpoint_index;
  48381. + usb_endpoint_descriptor_t ued_desc;
  48382. +};
  48383. +
  48384. +struct usb_full_desc {
  48385. + int ufd_config_index;
  48386. + u_int ufd_size;
  48387. + u_char *ufd_data;
  48388. +};
  48389. +
  48390. +struct usb_string_desc {
  48391. + int usd_string_index;
  48392. + int usd_language_id;
  48393. + usb_string_descriptor_t usd_desc;
  48394. +};
  48395. +
  48396. +struct usb_ctl_report_desc {
  48397. + int ucrd_size;
  48398. + u_char ucrd_data[1024]; /* filled data size will vary */
  48399. +};
  48400. +
  48401. +typedef struct { u_int32_t cookie; } usb_event_cookie_t;
  48402. +
  48403. +#define USB_MAX_DEVNAMES 4
  48404. +#define USB_MAX_DEVNAMELEN 16
  48405. +struct usb_device_info {
  48406. + u_int8_t udi_bus;
  48407. + u_int8_t udi_addr; /* device address */
  48408. + usb_event_cookie_t udi_cookie;
  48409. + char udi_product[USB_MAX_STRING_LEN];
  48410. + char udi_vendor[USB_MAX_STRING_LEN];
  48411. + char udi_release[8];
  48412. + u_int16_t udi_productNo;
  48413. + u_int16_t udi_vendorNo;
  48414. + u_int16_t udi_releaseNo;
  48415. + u_int8_t udi_class;
  48416. + u_int8_t udi_subclass;
  48417. + u_int8_t udi_protocol;
  48418. + u_int8_t udi_config;
  48419. + u_int8_t udi_speed;
  48420. +#define USB_SPEED_UNKNOWN 0
  48421. +#define USB_SPEED_LOW 1
  48422. +#define USB_SPEED_FULL 2
  48423. +#define USB_SPEED_HIGH 3
  48424. +#define USB_SPEED_VARIABLE 4
  48425. +#define USB_SPEED_SUPER 5
  48426. + int udi_power; /* power consumption in mA, 0 if selfpowered */
  48427. + int udi_nports;
  48428. + char udi_devnames[USB_MAX_DEVNAMES][USB_MAX_DEVNAMELEN];
  48429. + u_int8_t udi_ports[16];/* hub only: addresses of devices on ports */
  48430. +#define USB_PORT_ENABLED 0xff
  48431. +#define USB_PORT_SUSPENDED 0xfe
  48432. +#define USB_PORT_POWERED 0xfd
  48433. +#define USB_PORT_DISABLED 0xfc
  48434. +};
  48435. +
  48436. +struct usb_ctl_report {
  48437. + int ucr_report;
  48438. + u_char ucr_data[1024]; /* filled data size will vary */
  48439. +};
  48440. +
  48441. +struct usb_device_stats {
  48442. + u_long uds_requests[4]; /* indexed by transfer type UE_* */
  48443. +};
  48444. +
  48445. +#define WUSB_MIN_IE 0x80
  48446. +#define WUSB_WCTA_IE 0x80
  48447. +#define WUSB_WCONNECTACK_IE 0x81
  48448. +#define WUSB_WHOSTINFO_IE 0x82
  48449. +#define WUHI_GET_CA(_bmAttributes_) ((_bmAttributes_) & 0x3)
  48450. +#define WUHI_CA_RECONN 0x00
  48451. +#define WUHI_CA_LIMITED 0x01
  48452. +#define WUHI_CA_ALL 0x03
  48453. +#define WUHI_GET_MLSI(_bmAttributes_) (((_bmAttributes_) & 0x38) >> 3)
  48454. +#define WUSB_WCHCHANGEANNOUNCE_IE 0x83
  48455. +#define WUSB_WDEV_DISCONNECT_IE 0x84
  48456. +#define WUSB_WHOST_DISCONNECT_IE 0x85
  48457. +#define WUSB_WRELEASE_CHANNEL_IE 0x86
  48458. +#define WUSB_WWORK_IE 0x87
  48459. +#define WUSB_WCHANNEL_STOP_IE 0x88
  48460. +#define WUSB_WDEV_KEEPALIVE_IE 0x89
  48461. +#define WUSB_WISOCH_DISCARD_IE 0x8A
  48462. +#define WUSB_WRESETDEVICE_IE 0x8B
  48463. +#define WUSB_WXMIT_PACKET_ADJUST_IE 0x8C
  48464. +#define WUSB_MAX_IE 0x8C
  48465. +
  48466. +/* Device Notification Types */
  48467. +
  48468. +#define WUSB_DN_MIN 0x01
  48469. +#define WUSB_DN_CONNECT 0x01
  48470. +# define WUSB_DA_OLDCONN 0x00
  48471. +# define WUSB_DA_NEWCONN 0x01
  48472. +# define WUSB_DA_SELF_BEACON 0x02
  48473. +# define WUSB_DA_DIR_BEACON 0x04
  48474. +# define WUSB_DA_NO_BEACON 0x06
  48475. +#define WUSB_DN_DISCONNECT 0x02
  48476. +#define WUSB_DN_EPRDY 0x03
  48477. +#define WUSB_DN_MASAVAILCHANGED 0x04
  48478. +#define WUSB_DN_REMOTEWAKEUP 0x05
  48479. +#define WUSB_DN_SLEEP 0x06
  48480. +#define WUSB_DN_ALIVE 0x07
  48481. +#define WUSB_DN_MAX 0x07
  48482. +
  48483. +#ifdef _MSC_VER
  48484. +#include <pshpack1.h>
  48485. +#endif
  48486. +
  48487. +/* WUSB Handshake Data. Used during the SET/GET HANDSHAKE requests */
  48488. +typedef struct wusb_hndshk_data {
  48489. + uByte bMessageNumber;
  48490. + uByte bStatus;
  48491. + uByte tTKID[3];
  48492. + uByte bReserved;
  48493. + uByte CDID[16];
  48494. + uByte Nonce[16];
  48495. + uByte MIC[8];
  48496. +} UPACKED wusb_hndshk_data_t;
  48497. +#define WUSB_HANDSHAKE_LEN_FOR_MIC 38
  48498. +
  48499. +/* WUSB Connection Context */
  48500. +typedef struct wusb_conn_context {
  48501. + uByte CHID [16];
  48502. + uByte CDID [16];
  48503. + uByte CK [16];
  48504. +} UPACKED wusb_conn_context_t;
  48505. +
  48506. +/* WUSB Security Descriptor */
  48507. +typedef struct wusb_security_desc {
  48508. + uByte bLength;
  48509. + uByte bDescriptorType;
  48510. + uWord wTotalLength;
  48511. + uByte bNumEncryptionTypes;
  48512. +} UPACKED wusb_security_desc_t;
  48513. +
  48514. +/* WUSB Encryption Type Descriptor */
  48515. +typedef struct wusb_encrypt_type_desc {
  48516. + uByte bLength;
  48517. + uByte bDescriptorType;
  48518. +
  48519. + uByte bEncryptionType;
  48520. +#define WUETD_UNSECURE 0
  48521. +#define WUETD_WIRED 1
  48522. +#define WUETD_CCM_1 2
  48523. +#define WUETD_RSA_1 3
  48524. +
  48525. + uByte bEncryptionValue;
  48526. + uByte bAuthKeyIndex;
  48527. +} UPACKED wusb_encrypt_type_desc_t;
  48528. +
  48529. +/* WUSB Key Descriptor */
  48530. +typedef struct wusb_key_desc {
  48531. + uByte bLength;
  48532. + uByte bDescriptorType;
  48533. + uByte tTKID[3];
  48534. + uByte bReserved;
  48535. + uByte KeyData[1]; /* variable length */
  48536. +} UPACKED wusb_key_desc_t;
  48537. +
  48538. +/* WUSB BOS Descriptor (Binary device Object Store) */
  48539. +typedef struct wusb_bos_desc {
  48540. + uByte bLength;
  48541. + uByte bDescriptorType;
  48542. + uWord wTotalLength;
  48543. + uByte bNumDeviceCaps;
  48544. +} UPACKED wusb_bos_desc_t;
  48545. +
  48546. +#define USB_DEVICE_CAPABILITY_20_EXTENSION 0x02
  48547. +typedef struct usb_dev_cap_20_ext_desc {
  48548. + uByte bLength;
  48549. + uByte bDescriptorType;
  48550. + uByte bDevCapabilityType;
  48551. +#define USB_20_EXT_LPM 0x02
  48552. + uDWord bmAttributes;
  48553. +} UPACKED usb_dev_cap_20_ext_desc_t;
  48554. +
  48555. +#define USB_DEVICE_CAPABILITY_SS_USB 0x03
  48556. +typedef struct usb_dev_cap_ss_usb {
  48557. + uByte bLength;
  48558. + uByte bDescriptorType;
  48559. + uByte bDevCapabilityType;
  48560. +#define USB_DC_SS_USB_LTM_CAPABLE 0x02
  48561. + uByte bmAttributes;
  48562. +#define USB_DC_SS_USB_SPEED_SUPPORT_LOW 0x01
  48563. +#define USB_DC_SS_USB_SPEED_SUPPORT_FULL 0x02
  48564. +#define USB_DC_SS_USB_SPEED_SUPPORT_HIGH 0x04
  48565. +#define USB_DC_SS_USB_SPEED_SUPPORT_SS 0x08
  48566. + uWord wSpeedsSupported;
  48567. + uByte bFunctionalitySupport;
  48568. + uByte bU1DevExitLat;
  48569. + uWord wU2DevExitLat;
  48570. +} UPACKED usb_dev_cap_ss_usb_t;
  48571. +
  48572. +#define USB_DEVICE_CAPABILITY_CONTAINER_ID 0x04
  48573. +typedef struct usb_dev_cap_container_id {
  48574. + uByte bLength;
  48575. + uByte bDescriptorType;
  48576. + uByte bDevCapabilityType;
  48577. + uByte bReserved;
  48578. + uByte containerID[16];
  48579. +} UPACKED usb_dev_cap_container_id_t;
  48580. +
  48581. +/* Device Capability Type Codes */
  48582. +#define WUSB_DEVICE_CAPABILITY_WIRELESS_USB 0x01
  48583. +
  48584. +/* Device Capability Descriptor */
  48585. +typedef struct wusb_dev_cap_desc {
  48586. + uByte bLength;
  48587. + uByte bDescriptorType;
  48588. + uByte bDevCapabilityType;
  48589. + uByte caps[1]; /* Variable length */
  48590. +} UPACKED wusb_dev_cap_desc_t;
  48591. +
  48592. +/* Device Capability Descriptor */
  48593. +typedef struct wusb_dev_cap_uwb_desc {
  48594. + uByte bLength;
  48595. + uByte bDescriptorType;
  48596. + uByte bDevCapabilityType;
  48597. + uByte bmAttributes;
  48598. + uWord wPHYRates; /* Bitmap */
  48599. + uByte bmTFITXPowerInfo;
  48600. + uByte bmFFITXPowerInfo;
  48601. + uWord bmBandGroup;
  48602. + uByte bReserved;
  48603. +} UPACKED wusb_dev_cap_uwb_desc_t;
  48604. +
  48605. +/* Wireless USB Endpoint Companion Descriptor */
  48606. +typedef struct wusb_endpoint_companion_desc {
  48607. + uByte bLength;
  48608. + uByte bDescriptorType;
  48609. + uByte bMaxBurst;
  48610. + uByte bMaxSequence;
  48611. + uWord wMaxStreamDelay;
  48612. + uWord wOverTheAirPacketSize;
  48613. + uByte bOverTheAirInterval;
  48614. + uByte bmCompAttributes;
  48615. +} UPACKED wusb_endpoint_companion_desc_t;
  48616. +
  48617. +/* Wireless USB Numeric Association M1 Data Structure */
  48618. +typedef struct wusb_m1_data {
  48619. + uByte version;
  48620. + uWord langId;
  48621. + uByte deviceFriendlyNameLength;
  48622. + uByte sha_256_m3[32];
  48623. + uByte deviceFriendlyName[256];
  48624. +} UPACKED wusb_m1_data_t;
  48625. +
  48626. +typedef struct wusb_m2_data {
  48627. + uByte version;
  48628. + uWord langId;
  48629. + uByte hostFriendlyNameLength;
  48630. + uByte pkh[384];
  48631. + uByte hostFriendlyName[256];
  48632. +} UPACKED wusb_m2_data_t;
  48633. +
  48634. +typedef struct wusb_m3_data {
  48635. + uByte pkd[384];
  48636. + uByte nd;
  48637. +} UPACKED wusb_m3_data_t;
  48638. +
  48639. +typedef struct wusb_m4_data {
  48640. + uDWord _attributeTypeIdAndLength_1;
  48641. + uWord associationTypeId;
  48642. +
  48643. + uDWord _attributeTypeIdAndLength_2;
  48644. + uWord associationSubTypeId;
  48645. +
  48646. + uDWord _attributeTypeIdAndLength_3;
  48647. + uDWord length;
  48648. +
  48649. + uDWord _attributeTypeIdAndLength_4;
  48650. + uDWord associationStatus;
  48651. +
  48652. + uDWord _attributeTypeIdAndLength_5;
  48653. + uByte chid[16];
  48654. +
  48655. + uDWord _attributeTypeIdAndLength_6;
  48656. + uByte cdid[16];
  48657. +
  48658. + uDWord _attributeTypeIdAndLength_7;
  48659. + uByte bandGroups[2];
  48660. +} UPACKED wusb_m4_data_t;
  48661. +
  48662. +#ifdef _MSC_VER
  48663. +#include <poppack.h>
  48664. +#endif
  48665. +
  48666. +#ifdef __cplusplus
  48667. +}
  48668. +#endif
  48669. +
  48670. +#endif /* _USB_H_ */
  48671. diff -Nur linux-3.13.11/drivers/usb/host/dwc_otg/doc/doxygen.cfg linux-rpi/drivers/usb/host/dwc_otg/doc/doxygen.cfg
  48672. --- linux-3.13.11/drivers/usb/host/dwc_otg/doc/doxygen.cfg 1970-01-01 01:00:00.000000000 +0100
  48673. +++ linux-rpi/drivers/usb/host/dwc_otg/doc/doxygen.cfg 2014-04-24 15:37:13.306990445 +0200
  48674. @@ -0,0 +1,224 @@
  48675. +# Doxyfile 1.3.9.1
  48676. +
  48677. +#---------------------------------------------------------------------------
  48678. +# Project related configuration options
  48679. +#---------------------------------------------------------------------------
  48680. +PROJECT_NAME = "DesignWare USB 2.0 OTG Controller (DWC_otg) Device Driver"
  48681. +PROJECT_NUMBER = v3.00a
  48682. +OUTPUT_DIRECTORY = ./doc/
  48683. +CREATE_SUBDIRS = NO
  48684. +OUTPUT_LANGUAGE = English
  48685. +BRIEF_MEMBER_DESC = YES
  48686. +REPEAT_BRIEF = YES
  48687. +ABBREVIATE_BRIEF = "The $name class" \
  48688. + "The $name widget" \
  48689. + "The $name file" \
  48690. + is \
  48691. + provides \
  48692. + specifies \
  48693. + contains \
  48694. + represents \
  48695. + a \
  48696. + an \
  48697. + the
  48698. +ALWAYS_DETAILED_SEC = NO
  48699. +INLINE_INHERITED_MEMB = NO
  48700. +FULL_PATH_NAMES = NO
  48701. +STRIP_FROM_PATH =
  48702. +STRIP_FROM_INC_PATH =
  48703. +SHORT_NAMES = NO
  48704. +JAVADOC_AUTOBRIEF = YES
  48705. +MULTILINE_CPP_IS_BRIEF = NO
  48706. +INHERIT_DOCS = YES
  48707. +DISTRIBUTE_GROUP_DOC = NO
  48708. +TAB_SIZE = 8
  48709. +ALIASES =
  48710. +OPTIMIZE_OUTPUT_FOR_C = YES
  48711. +OPTIMIZE_OUTPUT_JAVA = NO
  48712. +SUBGROUPING = YES
  48713. +#---------------------------------------------------------------------------
  48714. +# Build related configuration options
  48715. +#---------------------------------------------------------------------------
  48716. +EXTRACT_ALL = NO
  48717. +EXTRACT_PRIVATE = YES
  48718. +EXTRACT_STATIC = YES
  48719. +EXTRACT_LOCAL_CLASSES = YES
  48720. +EXTRACT_LOCAL_METHODS = NO
  48721. +HIDE_UNDOC_MEMBERS = NO
  48722. +HIDE_UNDOC_CLASSES = NO
  48723. +HIDE_FRIEND_COMPOUNDS = NO
  48724. +HIDE_IN_BODY_DOCS = NO
  48725. +INTERNAL_DOCS = NO
  48726. +CASE_SENSE_NAMES = NO
  48727. +HIDE_SCOPE_NAMES = NO
  48728. +SHOW_INCLUDE_FILES = YES
  48729. +INLINE_INFO = YES
  48730. +SORT_MEMBER_DOCS = NO
  48731. +SORT_BRIEF_DOCS = NO
  48732. +SORT_BY_SCOPE_NAME = NO
  48733. +GENERATE_TODOLIST = YES
  48734. +GENERATE_TESTLIST = YES
  48735. +GENERATE_BUGLIST = YES
  48736. +GENERATE_DEPRECATEDLIST= YES
  48737. +ENABLED_SECTIONS =
  48738. +MAX_INITIALIZER_LINES = 30
  48739. +SHOW_USED_FILES = YES
  48740. +SHOW_DIRECTORIES = YES
  48741. +#---------------------------------------------------------------------------
  48742. +# configuration options related to warning and progress messages
  48743. +#---------------------------------------------------------------------------
  48744. +QUIET = YES
  48745. +WARNINGS = YES
  48746. +WARN_IF_UNDOCUMENTED = NO
  48747. +WARN_IF_DOC_ERROR = YES
  48748. +WARN_FORMAT = "$file:$line: $text"
  48749. +WARN_LOGFILE =
  48750. +#---------------------------------------------------------------------------
  48751. +# configuration options related to the input files
  48752. +#---------------------------------------------------------------------------
  48753. +INPUT = .
  48754. +FILE_PATTERNS = *.c \
  48755. + *.h \
  48756. + ./linux/*.c \
  48757. + ./linux/*.h
  48758. +RECURSIVE = NO
  48759. +EXCLUDE = ./test/ \
  48760. + ./dwc_otg/.AppleDouble/
  48761. +EXCLUDE_SYMLINKS = YES
  48762. +EXCLUDE_PATTERNS = *.mod.*
  48763. +EXAMPLE_PATH =
  48764. +EXAMPLE_PATTERNS = *
  48765. +EXAMPLE_RECURSIVE = NO
  48766. +IMAGE_PATH =
  48767. +INPUT_FILTER =
  48768. +FILTER_PATTERNS =
  48769. +FILTER_SOURCE_FILES = NO
  48770. +#---------------------------------------------------------------------------
  48771. +# configuration options related to source browsing
  48772. +#---------------------------------------------------------------------------
  48773. +SOURCE_BROWSER = YES
  48774. +INLINE_SOURCES = NO
  48775. +STRIP_CODE_COMMENTS = YES
  48776. +REFERENCED_BY_RELATION = NO
  48777. +REFERENCES_RELATION = NO
  48778. +VERBATIM_HEADERS = NO
  48779. +#---------------------------------------------------------------------------
  48780. +# configuration options related to the alphabetical class index
  48781. +#---------------------------------------------------------------------------
  48782. +ALPHABETICAL_INDEX = NO
  48783. +COLS_IN_ALPHA_INDEX = 5
  48784. +IGNORE_PREFIX =
  48785. +#---------------------------------------------------------------------------
  48786. +# configuration options related to the HTML output
  48787. +#---------------------------------------------------------------------------
  48788. +GENERATE_HTML = YES
  48789. +HTML_OUTPUT = html
  48790. +HTML_FILE_EXTENSION = .html
  48791. +HTML_HEADER =
  48792. +HTML_FOOTER =
  48793. +HTML_STYLESHEET =
  48794. +HTML_ALIGN_MEMBERS = YES
  48795. +GENERATE_HTMLHELP = NO
  48796. +CHM_FILE =
  48797. +HHC_LOCATION =
  48798. +GENERATE_CHI = NO
  48799. +BINARY_TOC = NO
  48800. +TOC_EXPAND = NO
  48801. +DISABLE_INDEX = NO
  48802. +ENUM_VALUES_PER_LINE = 4
  48803. +GENERATE_TREEVIEW = YES
  48804. +TREEVIEW_WIDTH = 250
  48805. +#---------------------------------------------------------------------------
  48806. +# configuration options related to the LaTeX output
  48807. +#---------------------------------------------------------------------------
  48808. +GENERATE_LATEX = NO
  48809. +LATEX_OUTPUT = latex
  48810. +LATEX_CMD_NAME = latex
  48811. +MAKEINDEX_CMD_NAME = makeindex
  48812. +COMPACT_LATEX = NO
  48813. +PAPER_TYPE = a4wide
  48814. +EXTRA_PACKAGES =
  48815. +LATEX_HEADER =
  48816. +PDF_HYPERLINKS = NO
  48817. +USE_PDFLATEX = NO
  48818. +LATEX_BATCHMODE = NO
  48819. +LATEX_HIDE_INDICES = NO
  48820. +#---------------------------------------------------------------------------
  48821. +# configuration options related to the RTF output
  48822. +#---------------------------------------------------------------------------
  48823. +GENERATE_RTF = NO
  48824. +RTF_OUTPUT = rtf
  48825. +COMPACT_RTF = NO
  48826. +RTF_HYPERLINKS = NO
  48827. +RTF_STYLESHEET_FILE =
  48828. +RTF_EXTENSIONS_FILE =
  48829. +#---------------------------------------------------------------------------
  48830. +# configuration options related to the man page output
  48831. +#---------------------------------------------------------------------------
  48832. +GENERATE_MAN = NO
  48833. +MAN_OUTPUT = man
  48834. +MAN_EXTENSION = .3
  48835. +MAN_LINKS = NO
  48836. +#---------------------------------------------------------------------------
  48837. +# configuration options related to the XML output
  48838. +#---------------------------------------------------------------------------
  48839. +GENERATE_XML = NO
  48840. +XML_OUTPUT = xml
  48841. +XML_SCHEMA =
  48842. +XML_DTD =
  48843. +XML_PROGRAMLISTING = YES
  48844. +#---------------------------------------------------------------------------
  48845. +# configuration options for the AutoGen Definitions output
  48846. +#---------------------------------------------------------------------------
  48847. +GENERATE_AUTOGEN_DEF = NO
  48848. +#---------------------------------------------------------------------------
  48849. +# configuration options related to the Perl module output
  48850. +#---------------------------------------------------------------------------
  48851. +GENERATE_PERLMOD = NO
  48852. +PERLMOD_LATEX = NO
  48853. +PERLMOD_PRETTY = YES
  48854. +PERLMOD_MAKEVAR_PREFIX =
  48855. +#---------------------------------------------------------------------------
  48856. +# Configuration options related to the preprocessor
  48857. +#---------------------------------------------------------------------------
  48858. +ENABLE_PREPROCESSING = YES
  48859. +MACRO_EXPANSION = YES
  48860. +EXPAND_ONLY_PREDEF = YES
  48861. +SEARCH_INCLUDES = YES
  48862. +INCLUDE_PATH =
  48863. +INCLUDE_FILE_PATTERNS =
  48864. +PREDEFINED = DEVICE_ATTR DWC_EN_ISOC
  48865. +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
  48866. +SKIP_FUNCTION_MACROS = NO
  48867. +#---------------------------------------------------------------------------
  48868. +# Configuration::additions related to external references
  48869. +#---------------------------------------------------------------------------
  48870. +TAGFILES =
  48871. +GENERATE_TAGFILE =
  48872. +ALLEXTERNALS = NO
  48873. +EXTERNAL_GROUPS = YES
  48874. +PERL_PATH = /usr/bin/perl
  48875. +#---------------------------------------------------------------------------
  48876. +# Configuration options related to the dot tool
  48877. +#---------------------------------------------------------------------------
  48878. +CLASS_DIAGRAMS = YES
  48879. +HIDE_UNDOC_RELATIONS = YES
  48880. +HAVE_DOT = NO
  48881. +CLASS_GRAPH = YES
  48882. +COLLABORATION_GRAPH = YES
  48883. +UML_LOOK = NO
  48884. +TEMPLATE_RELATIONS = NO
  48885. +INCLUDE_GRAPH = YES
  48886. +INCLUDED_BY_GRAPH = YES
  48887. +CALL_GRAPH = NO
  48888. +GRAPHICAL_HIERARCHY = YES
  48889. +DOT_IMAGE_FORMAT = png
  48890. +DOT_PATH =
  48891. +DOTFILE_DIRS =
  48892. +MAX_DOT_GRAPH_DEPTH = 1000
  48893. +GENERATE_LEGEND = YES
  48894. +DOT_CLEANUP = YES
  48895. +#---------------------------------------------------------------------------
  48896. +# Configuration::additions related to the search engine
  48897. +#---------------------------------------------------------------------------
  48898. +SEARCHENGINE = NO
  48899. diff -Nur linux-3.13.11/drivers/usb/host/dwc_otg/dummy_audio.c linux-rpi/drivers/usb/host/dwc_otg/dummy_audio.c
  48900. --- linux-3.13.11/drivers/usb/host/dwc_otg/dummy_audio.c 1970-01-01 01:00:00.000000000 +0100
  48901. +++ linux-rpi/drivers/usb/host/dwc_otg/dummy_audio.c 2014-04-24 15:37:13.310990489 +0200
  48902. @@ -0,0 +1,1575 @@
  48903. +/*
  48904. + * zero.c -- Gadget Zero, for USB development
  48905. + *
  48906. + * Copyright (C) 2003-2004 David Brownell
  48907. + * All rights reserved.
  48908. + *
  48909. + * Redistribution and use in source and binary forms, with or without
  48910. + * modification, are permitted provided that the following conditions
  48911. + * are met:
  48912. + * 1. Redistributions of source code must retain the above copyright
  48913. + * notice, this list of conditions, and the following disclaimer,
  48914. + * without modification.
  48915. + * 2. Redistributions in binary form must reproduce the above copyright
  48916. + * notice, this list of conditions and the following disclaimer in the
  48917. + * documentation and/or other materials provided with the distribution.
  48918. + * 3. The names of the above-listed copyright holders may not be used
  48919. + * to endorse or promote products derived from this software without
  48920. + * specific prior written permission.
  48921. + *
  48922. + * ALTERNATIVELY, this software may be distributed under the terms of the
  48923. + * GNU General Public License ("GPL") as published by the Free Software
  48924. + * Foundation, either version 2 of that License or (at your option) any
  48925. + * later version.
  48926. + *
  48927. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  48928. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  48929. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  48930. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  48931. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  48932. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  48933. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  48934. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  48935. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  48936. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  48937. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  48938. + */
  48939. +
  48940. +
  48941. +/*
  48942. + * Gadget Zero only needs two bulk endpoints, and is an example of how you
  48943. + * can write a hardware-agnostic gadget driver running inside a USB device.
  48944. + *
  48945. + * Hardware details are visible (see CONFIG_USB_ZERO_* below) but don't
  48946. + * affect most of the driver.
  48947. + *
  48948. + * Use it with the Linux host/master side "usbtest" driver to get a basic
  48949. + * functional test of your device-side usb stack, or with "usb-skeleton".
  48950. + *
  48951. + * It supports two similar configurations. One sinks whatever the usb host
  48952. + * writes, and in return sources zeroes. The other loops whatever the host
  48953. + * writes back, so the host can read it. Module options include:
  48954. + *
  48955. + * buflen=N default N=4096, buffer size used
  48956. + * qlen=N default N=32, how many buffers in the loopback queue
  48957. + * loopdefault default false, list loopback config first
  48958. + *
  48959. + * Many drivers will only have one configuration, letting them be much
  48960. + * simpler if they also don't support high speed operation (like this
  48961. + * driver does).
  48962. + */
  48963. +
  48964. +#include <linux/config.h>
  48965. +#include <linux/module.h>
  48966. +#include <linux/kernel.h>
  48967. +#include <linux/delay.h>
  48968. +#include <linux/ioport.h>
  48969. +#include <linux/sched.h>
  48970. +#include <linux/slab.h>
  48971. +#include <linux/smp_lock.h>
  48972. +#include <linux/errno.h>
  48973. +#include <linux/init.h>
  48974. +#include <linux/timer.h>
  48975. +#include <linux/list.h>
  48976. +#include <linux/interrupt.h>
  48977. +#include <linux/uts.h>
  48978. +#include <linux/version.h>
  48979. +#include <linux/device.h>
  48980. +#include <linux/moduleparam.h>
  48981. +#include <linux/proc_fs.h>
  48982. +
  48983. +#include <asm/byteorder.h>
  48984. +#include <asm/io.h>
  48985. +#include <asm/irq.h>
  48986. +#include <asm/system.h>
  48987. +#include <asm/unaligned.h>
  48988. +
  48989. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21)
  48990. +# include <linux/usb/ch9.h>
  48991. +#else
  48992. +# include <linux/usb_ch9.h>
  48993. +#endif
  48994. +
  48995. +#include <linux/usb_gadget.h>
  48996. +
  48997. +
  48998. +/*-------------------------------------------------------------------------*/
  48999. +/*-------------------------------------------------------------------------*/
  49000. +
  49001. +
  49002. +static int utf8_to_utf16le(const char *s, u16 *cp, unsigned len)
  49003. +{
  49004. + int count = 0;
  49005. + u8 c;
  49006. + u16 uchar;
  49007. +
  49008. + /* this insists on correct encodings, though not minimal ones.
  49009. + * BUT it currently rejects legit 4-byte UTF-8 code points,
  49010. + * which need surrogate pairs. (Unicode 3.1 can use them.)
  49011. + */
  49012. + while (len != 0 && (c = (u8) *s++) != 0) {
  49013. + if (unlikely(c & 0x80)) {
  49014. + // 2-byte sequence:
  49015. + // 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx
  49016. + if ((c & 0xe0) == 0xc0) {
  49017. + uchar = (c & 0x1f) << 6;
  49018. +
  49019. + c = (u8) *s++;
  49020. + if ((c & 0xc0) != 0xc0)
  49021. + goto fail;
  49022. + c &= 0x3f;
  49023. + uchar |= c;
  49024. +
  49025. + // 3-byte sequence (most CJKV characters):
  49026. + // zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx
  49027. + } else if ((c & 0xf0) == 0xe0) {
  49028. + uchar = (c & 0x0f) << 12;
  49029. +
  49030. + c = (u8) *s++;
  49031. + if ((c & 0xc0) != 0xc0)
  49032. + goto fail;
  49033. + c &= 0x3f;
  49034. + uchar |= c << 6;
  49035. +
  49036. + c = (u8) *s++;
  49037. + if ((c & 0xc0) != 0xc0)
  49038. + goto fail;
  49039. + c &= 0x3f;
  49040. + uchar |= c;
  49041. +
  49042. + /* no bogus surrogates */
  49043. + if (0xd800 <= uchar && uchar <= 0xdfff)
  49044. + goto fail;
  49045. +
  49046. + // 4-byte sequence (surrogate pairs, currently rare):
  49047. + // 11101110wwwwzzzzyy + 110111yyyyxxxxxx
  49048. + // = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx
  49049. + // (uuuuu = wwww + 1)
  49050. + // FIXME accept the surrogate code points (only)
  49051. +
  49052. + } else
  49053. + goto fail;
  49054. + } else
  49055. + uchar = c;
  49056. + put_unaligned (cpu_to_le16 (uchar), cp++);
  49057. + count++;
  49058. + len--;
  49059. + }
  49060. + return count;
  49061. +fail:
  49062. + return -1;
  49063. +}
  49064. +
  49065. +
  49066. +/**
  49067. + * usb_gadget_get_string - fill out a string descriptor
  49068. + * @table: of c strings encoded using UTF-8
  49069. + * @id: string id, from low byte of wValue in get string descriptor
  49070. + * @buf: at least 256 bytes
  49071. + *
  49072. + * Finds the UTF-8 string matching the ID, and converts it into a
  49073. + * string descriptor in utf16-le.
  49074. + * Returns length of descriptor (always even) or negative errno
  49075. + *
  49076. + * If your driver needs stings in multiple languages, you'll probably
  49077. + * "switch (wIndex) { ... }" in your ep0 string descriptor logic,
  49078. + * using this routine after choosing which set of UTF-8 strings to use.
  49079. + * Note that US-ASCII is a strict subset of UTF-8; any string bytes with
  49080. + * the eighth bit set will be multibyte UTF-8 characters, not ISO-8859/1
  49081. + * characters (which are also widely used in C strings).
  49082. + */
  49083. +int
  49084. +usb_gadget_get_string (struct usb_gadget_strings *table, int id, u8 *buf)
  49085. +{
  49086. + struct usb_string *s;
  49087. + int len;
  49088. +
  49089. + /* descriptor 0 has the language id */
  49090. + if (id == 0) {
  49091. + buf [0] = 4;
  49092. + buf [1] = USB_DT_STRING;
  49093. + buf [2] = (u8) table->language;
  49094. + buf [3] = (u8) (table->language >> 8);
  49095. + return 4;
  49096. + }
  49097. + for (s = table->strings; s && s->s; s++)
  49098. + if (s->id == id)
  49099. + break;
  49100. +
  49101. + /* unrecognized: stall. */
  49102. + if (!s || !s->s)
  49103. + return -EINVAL;
  49104. +
  49105. + /* string descriptors have length, tag, then UTF16-LE text */
  49106. + len = min ((size_t) 126, strlen (s->s));
  49107. + memset (buf + 2, 0, 2 * len); /* zero all the bytes */
  49108. + len = utf8_to_utf16le(s->s, (u16 *)&buf[2], len);
  49109. + if (len < 0)
  49110. + return -EINVAL;
  49111. + buf [0] = (len + 1) * 2;
  49112. + buf [1] = USB_DT_STRING;
  49113. + return buf [0];
  49114. +}
  49115. +
  49116. +
  49117. +/*-------------------------------------------------------------------------*/
  49118. +/*-------------------------------------------------------------------------*/
  49119. +
  49120. +
  49121. +/**
  49122. + * usb_descriptor_fillbuf - fill buffer with descriptors
  49123. + * @buf: Buffer to be filled
  49124. + * @buflen: Size of buf
  49125. + * @src: Array of descriptor pointers, terminated by null pointer.
  49126. + *
  49127. + * Copies descriptors into the buffer, returning the length or a
  49128. + * negative error code if they can't all be copied. Useful when
  49129. + * assembling descriptors for an associated set of interfaces used
  49130. + * as part of configuring a composite device; or in other cases where
  49131. + * sets of descriptors need to be marshaled.
  49132. + */
  49133. +int
  49134. +usb_descriptor_fillbuf(void *buf, unsigned buflen,
  49135. + const struct usb_descriptor_header **src)
  49136. +{
  49137. + u8 *dest = buf;
  49138. +
  49139. + if (!src)
  49140. + return -EINVAL;
  49141. +
  49142. + /* fill buffer from src[] until null descriptor ptr */
  49143. + for (; 0 != *src; src++) {
  49144. + unsigned len = (*src)->bLength;
  49145. +
  49146. + if (len > buflen)
  49147. + return -EINVAL;
  49148. + memcpy(dest, *src, len);
  49149. + buflen -= len;
  49150. + dest += len;
  49151. + }
  49152. + return dest - (u8 *)buf;
  49153. +}
  49154. +
  49155. +
  49156. +/**
  49157. + * usb_gadget_config_buf - builts a complete configuration descriptor
  49158. + * @config: Header for the descriptor, including characteristics such
  49159. + * as power requirements and number of interfaces.
  49160. + * @desc: Null-terminated vector of pointers to the descriptors (interface,
  49161. + * endpoint, etc) defining all functions in this device configuration.
  49162. + * @buf: Buffer for the resulting configuration descriptor.
  49163. + * @length: Length of buffer. If this is not big enough to hold the
  49164. + * entire configuration descriptor, an error code will be returned.
  49165. + *
  49166. + * This copies descriptors into the response buffer, building a descriptor
  49167. + * for that configuration. It returns the buffer length or a negative
  49168. + * status code. The config.wTotalLength field is set to match the length
  49169. + * of the result, but other descriptor fields (including power usage and
  49170. + * interface count) must be set by the caller.
  49171. + *
  49172. + * Gadget drivers could use this when constructing a config descriptor
  49173. + * in response to USB_REQ_GET_DESCRIPTOR. They will need to patch the
  49174. + * resulting bDescriptorType value if USB_DT_OTHER_SPEED_CONFIG is needed.
  49175. + */
  49176. +int usb_gadget_config_buf(
  49177. + const struct usb_config_descriptor *config,
  49178. + void *buf,
  49179. + unsigned length,
  49180. + const struct usb_descriptor_header **desc
  49181. +)
  49182. +{
  49183. + struct usb_config_descriptor *cp = buf;
  49184. + int len;
  49185. +
  49186. + /* config descriptor first */
  49187. + if (length < USB_DT_CONFIG_SIZE || !desc)
  49188. + return -EINVAL;
  49189. + *cp = *config;
  49190. +
  49191. + /* then interface/endpoint/class/vendor/... */
  49192. + len = usb_descriptor_fillbuf(USB_DT_CONFIG_SIZE + (u8*)buf,
  49193. + length - USB_DT_CONFIG_SIZE, desc);
  49194. + if (len < 0)
  49195. + return len;
  49196. + len += USB_DT_CONFIG_SIZE;
  49197. + if (len > 0xffff)
  49198. + return -EINVAL;
  49199. +
  49200. + /* patch up the config descriptor */
  49201. + cp->bLength = USB_DT_CONFIG_SIZE;
  49202. + cp->bDescriptorType = USB_DT_CONFIG;
  49203. + cp->wTotalLength = cpu_to_le16(len);
  49204. + cp->bmAttributes |= USB_CONFIG_ATT_ONE;
  49205. + return len;
  49206. +}
  49207. +
  49208. +/*-------------------------------------------------------------------------*/
  49209. +/*-------------------------------------------------------------------------*/
  49210. +
  49211. +
  49212. +#define RBUF_LEN (1024*1024)
  49213. +static int rbuf_start;
  49214. +static int rbuf_len;
  49215. +static __u8 rbuf[RBUF_LEN];
  49216. +
  49217. +/*-------------------------------------------------------------------------*/
  49218. +
  49219. +#define DRIVER_VERSION "St Patrick's Day 2004"
  49220. +
  49221. +static const char shortname [] = "zero";
  49222. +static const char longname [] = "YAMAHA YST-MS35D USB Speaker ";
  49223. +
  49224. +static const char source_sink [] = "source and sink data";
  49225. +static const char loopback [] = "loop input to output";
  49226. +
  49227. +/*-------------------------------------------------------------------------*/
  49228. +
  49229. +/*
  49230. + * driver assumes self-powered hardware, and
  49231. + * has no way for users to trigger remote wakeup.
  49232. + *
  49233. + * this version autoconfigures as much as possible,
  49234. + * which is reasonable for most "bulk-only" drivers.
  49235. + */
  49236. +static const char *EP_IN_NAME; /* source */
  49237. +static const char *EP_OUT_NAME; /* sink */
  49238. +
  49239. +/*-------------------------------------------------------------------------*/
  49240. +
  49241. +/* big enough to hold our biggest descriptor */
  49242. +#define USB_BUFSIZ 512
  49243. +
  49244. +struct zero_dev {
  49245. + spinlock_t lock;
  49246. + struct usb_gadget *gadget;
  49247. + struct usb_request *req; /* for control responses */
  49248. +
  49249. + /* when configured, we have one of two configs:
  49250. + * - source data (in to host) and sink it (out from host)
  49251. + * - or loop it back (out from host back in to host)
  49252. + */
  49253. + u8 config;
  49254. + struct usb_ep *in_ep, *out_ep;
  49255. +
  49256. + /* autoresume timer */
  49257. + struct timer_list resume;
  49258. +};
  49259. +
  49260. +#define xprintk(d,level,fmt,args...) \
  49261. + dev_printk(level , &(d)->gadget->dev , fmt , ## args)
  49262. +
  49263. +#ifdef DEBUG
  49264. +#define DBG(dev,fmt,args...) \
  49265. + xprintk(dev , KERN_DEBUG , fmt , ## args)
  49266. +#else
  49267. +#define DBG(dev,fmt,args...) \
  49268. + do { } while (0)
  49269. +#endif /* DEBUG */
  49270. +
  49271. +#ifdef VERBOSE
  49272. +#define VDBG DBG
  49273. +#else
  49274. +#define VDBG(dev,fmt,args...) \
  49275. + do { } while (0)
  49276. +#endif /* VERBOSE */
  49277. +
  49278. +#define ERROR(dev,fmt,args...) \
  49279. + xprintk(dev , KERN_ERR , fmt , ## args)
  49280. +#define WARN(dev,fmt,args...) \
  49281. + xprintk(dev , KERN_WARNING , fmt , ## args)
  49282. +#define INFO(dev,fmt,args...) \
  49283. + xprintk(dev , KERN_INFO , fmt , ## args)
  49284. +
  49285. +/*-------------------------------------------------------------------------*/
  49286. +
  49287. +static unsigned buflen = 4096;
  49288. +static unsigned qlen = 32;
  49289. +static unsigned pattern = 0;
  49290. +
  49291. +module_param (buflen, uint, S_IRUGO|S_IWUSR);
  49292. +module_param (qlen, uint, S_IRUGO|S_IWUSR);
  49293. +module_param (pattern, uint, S_IRUGO|S_IWUSR);
  49294. +
  49295. +/*
  49296. + * if it's nonzero, autoresume says how many seconds to wait
  49297. + * before trying to wake up the host after suspend.
  49298. + */
  49299. +static unsigned autoresume = 0;
  49300. +module_param (autoresume, uint, 0);
  49301. +
  49302. +/*
  49303. + * Normally the "loopback" configuration is second (index 1) so
  49304. + * it's not the default. Here's where to change that order, to
  49305. + * work better with hosts where config changes are problematic.
  49306. + * Or controllers (like superh) that only support one config.
  49307. + */
  49308. +static int loopdefault = 0;
  49309. +
  49310. +module_param (loopdefault, bool, S_IRUGO|S_IWUSR);
  49311. +
  49312. +/*-------------------------------------------------------------------------*/
  49313. +
  49314. +/* Thanks to NetChip Technologies for donating this product ID.
  49315. + *
  49316. + * DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!!
  49317. + * Instead: allocate your own, using normal USB-IF procedures.
  49318. + */
  49319. +#ifndef CONFIG_USB_ZERO_HNPTEST
  49320. +#define DRIVER_VENDOR_NUM 0x0525 /* NetChip */
  49321. +#define DRIVER_PRODUCT_NUM 0xa4a0 /* Linux-USB "Gadget Zero" */
  49322. +#else
  49323. +#define DRIVER_VENDOR_NUM 0x1a0a /* OTG test device IDs */
  49324. +#define DRIVER_PRODUCT_NUM 0xbadd
  49325. +#endif
  49326. +
  49327. +/*-------------------------------------------------------------------------*/
  49328. +
  49329. +/*
  49330. + * DESCRIPTORS ... most are static, but strings and (full)
  49331. + * configuration descriptors are built on demand.
  49332. + */
  49333. +
  49334. +/*
  49335. +#define STRING_MANUFACTURER 25
  49336. +#define STRING_PRODUCT 42
  49337. +#define STRING_SERIAL 101
  49338. +*/
  49339. +#define STRING_MANUFACTURER 1
  49340. +#define STRING_PRODUCT 2
  49341. +#define STRING_SERIAL 3
  49342. +
  49343. +#define STRING_SOURCE_SINK 250
  49344. +#define STRING_LOOPBACK 251
  49345. +
  49346. +/*
  49347. + * This device advertises two configurations; these numbers work
  49348. + * on a pxa250 as well as more flexible hardware.
  49349. + */
  49350. +#define CONFIG_SOURCE_SINK 3
  49351. +#define CONFIG_LOOPBACK 2
  49352. +
  49353. +/*
  49354. +static struct usb_device_descriptor
  49355. +device_desc = {
  49356. + .bLength = sizeof device_desc,
  49357. + .bDescriptorType = USB_DT_DEVICE,
  49358. +
  49359. + .bcdUSB = __constant_cpu_to_le16 (0x0200),
  49360. + .bDeviceClass = USB_CLASS_VENDOR_SPEC,
  49361. +
  49362. + .idVendor = __constant_cpu_to_le16 (DRIVER_VENDOR_NUM),
  49363. + .idProduct = __constant_cpu_to_le16 (DRIVER_PRODUCT_NUM),
  49364. + .iManufacturer = STRING_MANUFACTURER,
  49365. + .iProduct = STRING_PRODUCT,
  49366. + .iSerialNumber = STRING_SERIAL,
  49367. + .bNumConfigurations = 2,
  49368. +};
  49369. +*/
  49370. +static struct usb_device_descriptor
  49371. +device_desc = {
  49372. + .bLength = sizeof device_desc,
  49373. + .bDescriptorType = USB_DT_DEVICE,
  49374. + .bcdUSB = __constant_cpu_to_le16 (0x0100),
  49375. + .bDeviceClass = USB_CLASS_PER_INTERFACE,
  49376. + .bDeviceSubClass = 0,
  49377. + .bDeviceProtocol = 0,
  49378. + .bMaxPacketSize0 = 64,
  49379. + .bcdDevice = __constant_cpu_to_le16 (0x0100),
  49380. + .idVendor = __constant_cpu_to_le16 (0x0499),
  49381. + .idProduct = __constant_cpu_to_le16 (0x3002),
  49382. + .iManufacturer = STRING_MANUFACTURER,
  49383. + .iProduct = STRING_PRODUCT,
  49384. + .iSerialNumber = STRING_SERIAL,
  49385. + .bNumConfigurations = 1,
  49386. +};
  49387. +
  49388. +static struct usb_config_descriptor
  49389. +z_config = {
  49390. + .bLength = sizeof z_config,
  49391. + .bDescriptorType = USB_DT_CONFIG,
  49392. +
  49393. + /* compute wTotalLength on the fly */
  49394. + .bNumInterfaces = 2,
  49395. + .bConfigurationValue = 1,
  49396. + .iConfiguration = 0,
  49397. + .bmAttributes = 0x40,
  49398. + .bMaxPower = 0, /* self-powered */
  49399. +};
  49400. +
  49401. +
  49402. +static struct usb_otg_descriptor
  49403. +otg_descriptor = {
  49404. + .bLength = sizeof otg_descriptor,
  49405. + .bDescriptorType = USB_DT_OTG,
  49406. +
  49407. + .bmAttributes = USB_OTG_SRP,
  49408. +};
  49409. +
  49410. +/* one interface in each configuration */
  49411. +#ifdef CONFIG_USB_GADGET_DUALSPEED
  49412. +
  49413. +/*
  49414. + * usb 2.0 devices need to expose both high speed and full speed
  49415. + * descriptors, unless they only run at full speed.
  49416. + *
  49417. + * that means alternate endpoint descriptors (bigger packets)
  49418. + * and a "device qualifier" ... plus more construction options
  49419. + * for the config descriptor.
  49420. + */
  49421. +
  49422. +static struct usb_qualifier_descriptor
  49423. +dev_qualifier = {
  49424. + .bLength = sizeof dev_qualifier,
  49425. + .bDescriptorType = USB_DT_DEVICE_QUALIFIER,
  49426. +
  49427. + .bcdUSB = __constant_cpu_to_le16 (0x0200),
  49428. + .bDeviceClass = USB_CLASS_VENDOR_SPEC,
  49429. +
  49430. + .bNumConfigurations = 2,
  49431. +};
  49432. +
  49433. +
  49434. +struct usb_cs_as_general_descriptor {
  49435. + __u8 bLength;
  49436. + __u8 bDescriptorType;
  49437. +
  49438. + __u8 bDescriptorSubType;
  49439. + __u8 bTerminalLink;
  49440. + __u8 bDelay;
  49441. + __u16 wFormatTag;
  49442. +} __attribute__ ((packed));
  49443. +
  49444. +struct usb_cs_as_format_descriptor {
  49445. + __u8 bLength;
  49446. + __u8 bDescriptorType;
  49447. +
  49448. + __u8 bDescriptorSubType;
  49449. + __u8 bFormatType;
  49450. + __u8 bNrChannels;
  49451. + __u8 bSubframeSize;
  49452. + __u8 bBitResolution;
  49453. + __u8 bSamfreqType;
  49454. + __u8 tLowerSamFreq[3];
  49455. + __u8 tUpperSamFreq[3];
  49456. +} __attribute__ ((packed));
  49457. +
  49458. +static const struct usb_interface_descriptor
  49459. +z_audio_control_if_desc = {
  49460. + .bLength = sizeof z_audio_control_if_desc,
  49461. + .bDescriptorType = USB_DT_INTERFACE,
  49462. + .bInterfaceNumber = 0,
  49463. + .bAlternateSetting = 0,
  49464. + .bNumEndpoints = 0,
  49465. + .bInterfaceClass = USB_CLASS_AUDIO,
  49466. + .bInterfaceSubClass = 0x1,
  49467. + .bInterfaceProtocol = 0,
  49468. + .iInterface = 0,
  49469. +};
  49470. +
  49471. +static const struct usb_interface_descriptor
  49472. +z_audio_if_desc = {
  49473. + .bLength = sizeof z_audio_if_desc,
  49474. + .bDescriptorType = USB_DT_INTERFACE,
  49475. + .bInterfaceNumber = 1,
  49476. + .bAlternateSetting = 0,
  49477. + .bNumEndpoints = 0,
  49478. + .bInterfaceClass = USB_CLASS_AUDIO,
  49479. + .bInterfaceSubClass = 0x2,
  49480. + .bInterfaceProtocol = 0,
  49481. + .iInterface = 0,
  49482. +};
  49483. +
  49484. +static const struct usb_interface_descriptor
  49485. +z_audio_if_desc2 = {
  49486. + .bLength = sizeof z_audio_if_desc,
  49487. + .bDescriptorType = USB_DT_INTERFACE,
  49488. + .bInterfaceNumber = 1,
  49489. + .bAlternateSetting = 1,
  49490. + .bNumEndpoints = 1,
  49491. + .bInterfaceClass = USB_CLASS_AUDIO,
  49492. + .bInterfaceSubClass = 0x2,
  49493. + .bInterfaceProtocol = 0,
  49494. + .iInterface = 0,
  49495. +};
  49496. +
  49497. +static const struct usb_cs_as_general_descriptor
  49498. +z_audio_cs_as_if_desc = {
  49499. + .bLength = 7,
  49500. + .bDescriptorType = 0x24,
  49501. +
  49502. + .bDescriptorSubType = 0x01,
  49503. + .bTerminalLink = 0x01,
  49504. + .bDelay = 0x0,
  49505. + .wFormatTag = __constant_cpu_to_le16 (0x0001)
  49506. +};
  49507. +
  49508. +
  49509. +static const struct usb_cs_as_format_descriptor
  49510. +z_audio_cs_as_format_desc = {
  49511. + .bLength = 0xe,
  49512. + .bDescriptorType = 0x24,
  49513. +
  49514. + .bDescriptorSubType = 2,
  49515. + .bFormatType = 1,
  49516. + .bNrChannels = 1,
  49517. + .bSubframeSize = 1,
  49518. + .bBitResolution = 8,
  49519. + .bSamfreqType = 0,
  49520. + .tLowerSamFreq = {0x7e, 0x13, 0x00},
  49521. + .tUpperSamFreq = {0xe2, 0xd6, 0x00},
  49522. +};
  49523. +
  49524. +static const struct usb_endpoint_descriptor
  49525. +z_iso_ep = {
  49526. + .bLength = 0x09,
  49527. + .bDescriptorType = 0x05,
  49528. + .bEndpointAddress = 0x04,
  49529. + .bmAttributes = 0x09,
  49530. + .wMaxPacketSize = 0x0038,
  49531. + .bInterval = 0x01,
  49532. + .bRefresh = 0x00,
  49533. + .bSynchAddress = 0x00,
  49534. +};
  49535. +
  49536. +static char z_iso_ep2[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  49537. +
  49538. +// 9 bytes
  49539. +static char z_ac_interface_header_desc[] =
  49540. +{ 0x09, 0x24, 0x01, 0x00, 0x01, 0x2b, 0x00, 0x01, 0x01 };
  49541. +
  49542. +// 12 bytes
  49543. +static char z_0[] = {0x0c, 0x24, 0x02, 0x01, 0x01, 0x01, 0x00, 0x02,
  49544. + 0x03, 0x00, 0x00, 0x00};
  49545. +// 13 bytes
  49546. +static char z_1[] = {0x0d, 0x24, 0x06, 0x02, 0x01, 0x02, 0x15, 0x00,
  49547. + 0x02, 0x00, 0x02, 0x00, 0x00};
  49548. +// 9 bytes
  49549. +static char z_2[] = {0x09, 0x24, 0x03, 0x03, 0x01, 0x03, 0x00, 0x02,
  49550. + 0x00};
  49551. +
  49552. +static char za_0[] = {0x09, 0x04, 0x01, 0x02, 0x01, 0x01, 0x02, 0x00,
  49553. + 0x00};
  49554. +
  49555. +static char za_1[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  49556. +
  49557. +static char za_2[] = {0x0e, 0x24, 0x02, 0x01, 0x02, 0x01, 0x08, 0x00,
  49558. + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  49559. +
  49560. +static char za_3[] = {0x09, 0x05, 0x04, 0x09, 0x70, 0x00, 0x01, 0x00,
  49561. + 0x00};
  49562. +
  49563. +static char za_4[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  49564. +
  49565. +static char za_5[] = {0x09, 0x04, 0x01, 0x03, 0x01, 0x01, 0x02, 0x00,
  49566. + 0x00};
  49567. +
  49568. +static char za_6[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  49569. +
  49570. +static char za_7[] = {0x0e, 0x24, 0x02, 0x01, 0x01, 0x02, 0x10, 0x00,
  49571. + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  49572. +
  49573. +static char za_8[] = {0x09, 0x05, 0x04, 0x09, 0x70, 0x00, 0x01, 0x00,
  49574. + 0x00};
  49575. +
  49576. +static char za_9[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  49577. +
  49578. +static char za_10[] = {0x09, 0x04, 0x01, 0x04, 0x01, 0x01, 0x02, 0x00,
  49579. + 0x00};
  49580. +
  49581. +static char za_11[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  49582. +
  49583. +static char za_12[] = {0x0e, 0x24, 0x02, 0x01, 0x02, 0x02, 0x10, 0x00,
  49584. + 0x73, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  49585. +
  49586. +static char za_13[] = {0x09, 0x05, 0x04, 0x09, 0xe0, 0x00, 0x01, 0x00,
  49587. + 0x00};
  49588. +
  49589. +static char za_14[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  49590. +
  49591. +static char za_15[] = {0x09, 0x04, 0x01, 0x05, 0x01, 0x01, 0x02, 0x00,
  49592. + 0x00};
  49593. +
  49594. +static char za_16[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  49595. +
  49596. +static char za_17[] = {0x0e, 0x24, 0x02, 0x01, 0x01, 0x03, 0x14, 0x00,
  49597. + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  49598. +
  49599. +static char za_18[] = {0x09, 0x05, 0x04, 0x09, 0xa8, 0x00, 0x01, 0x00,
  49600. + 0x00};
  49601. +
  49602. +static char za_19[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  49603. +
  49604. +static char za_20[] = {0x09, 0x04, 0x01, 0x06, 0x01, 0x01, 0x02, 0x00,
  49605. + 0x00};
  49606. +
  49607. +static char za_21[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  49608. +
  49609. +static char za_22[] = {0x0e, 0x24, 0x02, 0x01, 0x02, 0x03, 0x14, 0x00,
  49610. + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  49611. +
  49612. +static char za_23[] = {0x09, 0x05, 0x04, 0x09, 0x50, 0x01, 0x01, 0x00,
  49613. + 0x00};
  49614. +
  49615. +static char za_24[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  49616. +
  49617. +
  49618. +
  49619. +static const struct usb_descriptor_header *z_function [] = {
  49620. + (struct usb_descriptor_header *) &z_audio_control_if_desc,
  49621. + (struct usb_descriptor_header *) &z_ac_interface_header_desc,
  49622. + (struct usb_descriptor_header *) &z_0,
  49623. + (struct usb_descriptor_header *) &z_1,
  49624. + (struct usb_descriptor_header *) &z_2,
  49625. + (struct usb_descriptor_header *) &z_audio_if_desc,
  49626. + (struct usb_descriptor_header *) &z_audio_if_desc2,
  49627. + (struct usb_descriptor_header *) &z_audio_cs_as_if_desc,
  49628. + (struct usb_descriptor_header *) &z_audio_cs_as_format_desc,
  49629. + (struct usb_descriptor_header *) &z_iso_ep,
  49630. + (struct usb_descriptor_header *) &z_iso_ep2,
  49631. + (struct usb_descriptor_header *) &za_0,
  49632. + (struct usb_descriptor_header *) &za_1,
  49633. + (struct usb_descriptor_header *) &za_2,
  49634. + (struct usb_descriptor_header *) &za_3,
  49635. + (struct usb_descriptor_header *) &za_4,
  49636. + (struct usb_descriptor_header *) &za_5,
  49637. + (struct usb_descriptor_header *) &za_6,
  49638. + (struct usb_descriptor_header *) &za_7,
  49639. + (struct usb_descriptor_header *) &za_8,
  49640. + (struct usb_descriptor_header *) &za_9,
  49641. + (struct usb_descriptor_header *) &za_10,
  49642. + (struct usb_descriptor_header *) &za_11,
  49643. + (struct usb_descriptor_header *) &za_12,
  49644. + (struct usb_descriptor_header *) &za_13,
  49645. + (struct usb_descriptor_header *) &za_14,
  49646. + (struct usb_descriptor_header *) &za_15,
  49647. + (struct usb_descriptor_header *) &za_16,
  49648. + (struct usb_descriptor_header *) &za_17,
  49649. + (struct usb_descriptor_header *) &za_18,
  49650. + (struct usb_descriptor_header *) &za_19,
  49651. + (struct usb_descriptor_header *) &za_20,
  49652. + (struct usb_descriptor_header *) &za_21,
  49653. + (struct usb_descriptor_header *) &za_22,
  49654. + (struct usb_descriptor_header *) &za_23,
  49655. + (struct usb_descriptor_header *) &za_24,
  49656. + NULL,
  49657. +};
  49658. +
  49659. +/* maxpacket and other transfer characteristics vary by speed. */
  49660. +#define ep_desc(g,hs,fs) (((g)->speed==USB_SPEED_HIGH)?(hs):(fs))
  49661. +
  49662. +#else
  49663. +
  49664. +/* if there's no high speed support, maxpacket doesn't change. */
  49665. +#define ep_desc(g,hs,fs) fs
  49666. +
  49667. +#endif /* !CONFIG_USB_GADGET_DUALSPEED */
  49668. +
  49669. +static char manufacturer [40];
  49670. +//static char serial [40];
  49671. +static char serial [] = "Ser 00 em";
  49672. +
  49673. +/* static strings, in UTF-8 */
  49674. +static struct usb_string strings [] = {
  49675. + { STRING_MANUFACTURER, manufacturer, },
  49676. + { STRING_PRODUCT, longname, },
  49677. + { STRING_SERIAL, serial, },
  49678. + { STRING_LOOPBACK, loopback, },
  49679. + { STRING_SOURCE_SINK, source_sink, },
  49680. + { } /* end of list */
  49681. +};
  49682. +
  49683. +static struct usb_gadget_strings stringtab = {
  49684. + .language = 0x0409, /* en-us */
  49685. + .strings = strings,
  49686. +};
  49687. +
  49688. +/*
  49689. + * config descriptors are also handcrafted. these must agree with code
  49690. + * that sets configurations, and with code managing interfaces and their
  49691. + * altsettings. other complexity may come from:
  49692. + *
  49693. + * - high speed support, including "other speed config" rules
  49694. + * - multiple configurations
  49695. + * - interfaces with alternate settings
  49696. + * - embedded class or vendor-specific descriptors
  49697. + *
  49698. + * this handles high speed, and has a second config that could as easily
  49699. + * have been an alternate interface setting (on most hardware).
  49700. + *
  49701. + * NOTE: to demonstrate (and test) more USB capabilities, this driver
  49702. + * should include an altsetting to test interrupt transfers, including
  49703. + * high bandwidth modes at high speed. (Maybe work like Intel's test
  49704. + * device?)
  49705. + */
  49706. +static int
  49707. +config_buf (struct usb_gadget *gadget, u8 *buf, u8 type, unsigned index)
  49708. +{
  49709. + int len;
  49710. + const struct usb_descriptor_header **function;
  49711. +
  49712. + function = z_function;
  49713. + len = usb_gadget_config_buf (&z_config, buf, USB_BUFSIZ, function);
  49714. + if (len < 0)
  49715. + return len;
  49716. + ((struct usb_config_descriptor *) buf)->bDescriptorType = type;
  49717. + return len;
  49718. +}
  49719. +
  49720. +/*-------------------------------------------------------------------------*/
  49721. +
  49722. +static struct usb_request *
  49723. +alloc_ep_req (struct usb_ep *ep, unsigned length)
  49724. +{
  49725. + struct usb_request *req;
  49726. +
  49727. + req = usb_ep_alloc_request (ep, GFP_ATOMIC);
  49728. + if (req) {
  49729. + req->length = length;
  49730. + req->buf = usb_ep_alloc_buffer (ep, length,
  49731. + &req->dma, GFP_ATOMIC);
  49732. + if (!req->buf) {
  49733. + usb_ep_free_request (ep, req);
  49734. + req = NULL;
  49735. + }
  49736. + }
  49737. + return req;
  49738. +}
  49739. +
  49740. +static void free_ep_req (struct usb_ep *ep, struct usb_request *req)
  49741. +{
  49742. + if (req->buf)
  49743. + usb_ep_free_buffer (ep, req->buf, req->dma, req->length);
  49744. + usb_ep_free_request (ep, req);
  49745. +}
  49746. +
  49747. +/*-------------------------------------------------------------------------*/
  49748. +
  49749. +/* optionally require specific source/sink data patterns */
  49750. +
  49751. +static int
  49752. +check_read_data (
  49753. + struct zero_dev *dev,
  49754. + struct usb_ep *ep,
  49755. + struct usb_request *req
  49756. +)
  49757. +{
  49758. + unsigned i;
  49759. + u8 *buf = req->buf;
  49760. +
  49761. + for (i = 0; i < req->actual; i++, buf++) {
  49762. + switch (pattern) {
  49763. + /* all-zeroes has no synchronization issues */
  49764. + case 0:
  49765. + if (*buf == 0)
  49766. + continue;
  49767. + break;
  49768. + /* mod63 stays in sync with short-terminated transfers,
  49769. + * or otherwise when host and gadget agree on how large
  49770. + * each usb transfer request should be. resync is done
  49771. + * with set_interface or set_config.
  49772. + */
  49773. + case 1:
  49774. + if (*buf == (u8)(i % 63))
  49775. + continue;
  49776. + break;
  49777. + }
  49778. + ERROR (dev, "bad OUT byte, buf [%d] = %d\n", i, *buf);
  49779. + usb_ep_set_halt (ep);
  49780. + return -EINVAL;
  49781. + }
  49782. + return 0;
  49783. +}
  49784. +
  49785. +/*-------------------------------------------------------------------------*/
  49786. +
  49787. +static void zero_reset_config (struct zero_dev *dev)
  49788. +{
  49789. + if (dev->config == 0)
  49790. + return;
  49791. +
  49792. + DBG (dev, "reset config\n");
  49793. +
  49794. + /* just disable endpoints, forcing completion of pending i/o.
  49795. + * all our completion handlers free their requests in this case.
  49796. + */
  49797. + if (dev->in_ep) {
  49798. + usb_ep_disable (dev->in_ep);
  49799. + dev->in_ep = NULL;
  49800. + }
  49801. + if (dev->out_ep) {
  49802. + usb_ep_disable (dev->out_ep);
  49803. + dev->out_ep = NULL;
  49804. + }
  49805. + dev->config = 0;
  49806. + del_timer (&dev->resume);
  49807. +}
  49808. +
  49809. +#define _write(f, buf, sz) (f->f_op->write(f, buf, sz, &f->f_pos))
  49810. +
  49811. +static void
  49812. +zero_isoc_complete (struct usb_ep *ep, struct usb_request *req)
  49813. +{
  49814. + struct zero_dev *dev = ep->driver_data;
  49815. + int status = req->status;
  49816. + int i, j;
  49817. +
  49818. + switch (status) {
  49819. +
  49820. + case 0: /* normal completion? */
  49821. + //printk ("\nzero ---------------> isoc normal completion %d bytes\n", req->actual);
  49822. + for (i=0, j=rbuf_start; i<req->actual; i++) {
  49823. + //printk ("%02x ", ((__u8*)req->buf)[i]);
  49824. + rbuf[j] = ((__u8*)req->buf)[i];
  49825. + j++;
  49826. + if (j >= RBUF_LEN) j=0;
  49827. + }
  49828. + rbuf_start = j;
  49829. + //printk ("\n\n");
  49830. +
  49831. + if (rbuf_len < RBUF_LEN) {
  49832. + rbuf_len += req->actual;
  49833. + if (rbuf_len > RBUF_LEN) {
  49834. + rbuf_len = RBUF_LEN;
  49835. + }
  49836. + }
  49837. +
  49838. + break;
  49839. +
  49840. + /* this endpoint is normally active while we're configured */
  49841. + case -ECONNABORTED: /* hardware forced ep reset */
  49842. + case -ECONNRESET: /* request dequeued */
  49843. + case -ESHUTDOWN: /* disconnect from host */
  49844. + VDBG (dev, "%s gone (%d), %d/%d\n", ep->name, status,
  49845. + req->actual, req->length);
  49846. + if (ep == dev->out_ep)
  49847. + check_read_data (dev, ep, req);
  49848. + free_ep_req (ep, req);
  49849. + return;
  49850. +
  49851. + case -EOVERFLOW: /* buffer overrun on read means that
  49852. + * we didn't provide a big enough
  49853. + * buffer.
  49854. + */
  49855. + default:
  49856. +#if 1
  49857. + DBG (dev, "%s complete --> %d, %d/%d\n", ep->name,
  49858. + status, req->actual, req->length);
  49859. +#endif
  49860. + case -EREMOTEIO: /* short read */
  49861. + break;
  49862. + }
  49863. +
  49864. + status = usb_ep_queue (ep, req, GFP_ATOMIC);
  49865. + if (status) {
  49866. + ERROR (dev, "kill %s: resubmit %d bytes --> %d\n",
  49867. + ep->name, req->length, status);
  49868. + usb_ep_set_halt (ep);
  49869. + /* FIXME recover later ... somehow */
  49870. + }
  49871. +}
  49872. +
  49873. +static struct usb_request *
  49874. +zero_start_isoc_ep (struct usb_ep *ep, int gfp_flags)
  49875. +{
  49876. + struct usb_request *req;
  49877. + int status;
  49878. +
  49879. + req = alloc_ep_req (ep, 512);
  49880. + if (!req)
  49881. + return NULL;
  49882. +
  49883. + req->complete = zero_isoc_complete;
  49884. +
  49885. + status = usb_ep_queue (ep, req, gfp_flags);
  49886. + if (status) {
  49887. + struct zero_dev *dev = ep->driver_data;
  49888. +
  49889. + ERROR (dev, "start %s --> %d\n", ep->name, status);
  49890. + free_ep_req (ep, req);
  49891. + req = NULL;
  49892. + }
  49893. +
  49894. + return req;
  49895. +}
  49896. +
  49897. +/* change our operational config. this code must agree with the code
  49898. + * that returns config descriptors, and altsetting code.
  49899. + *
  49900. + * it's also responsible for power management interactions. some
  49901. + * configurations might not work with our current power sources.
  49902. + *
  49903. + * note that some device controller hardware will constrain what this
  49904. + * code can do, perhaps by disallowing more than one configuration or
  49905. + * by limiting configuration choices (like the pxa2xx).
  49906. + */
  49907. +static int
  49908. +zero_set_config (struct zero_dev *dev, unsigned number, int gfp_flags)
  49909. +{
  49910. + int result = 0;
  49911. + struct usb_gadget *gadget = dev->gadget;
  49912. + const struct usb_endpoint_descriptor *d;
  49913. + struct usb_ep *ep;
  49914. +
  49915. + if (number == dev->config)
  49916. + return 0;
  49917. +
  49918. + zero_reset_config (dev);
  49919. +
  49920. + gadget_for_each_ep (ep, gadget) {
  49921. +
  49922. + if (strcmp (ep->name, "ep4") == 0) {
  49923. +
  49924. + d = (struct usb_endpoint_descripter *)&za_23; // isoc ep desc for audio i/f alt setting 6
  49925. + result = usb_ep_enable (ep, d);
  49926. +
  49927. + if (result == 0) {
  49928. + ep->driver_data = dev;
  49929. + dev->in_ep = ep;
  49930. +
  49931. + if (zero_start_isoc_ep (ep, gfp_flags) != 0) {
  49932. +
  49933. + dev->in_ep = ep;
  49934. + continue;
  49935. + }
  49936. +
  49937. + usb_ep_disable (ep);
  49938. + result = -EIO;
  49939. + }
  49940. + }
  49941. +
  49942. + }
  49943. +
  49944. + dev->config = number;
  49945. + return result;
  49946. +}
  49947. +
  49948. +/*-------------------------------------------------------------------------*/
  49949. +
  49950. +static void zero_setup_complete (struct usb_ep *ep, struct usb_request *req)
  49951. +{
  49952. + if (req->status || req->actual != req->length)
  49953. + DBG ((struct zero_dev *) ep->driver_data,
  49954. + "setup complete --> %d, %d/%d\n",
  49955. + req->status, req->actual, req->length);
  49956. +}
  49957. +
  49958. +/*
  49959. + * The setup() callback implements all the ep0 functionality that's
  49960. + * not handled lower down, in hardware or the hardware driver (like
  49961. + * device and endpoint feature flags, and their status). It's all
  49962. + * housekeeping for the gadget function we're implementing. Most of
  49963. + * the work is in config-specific setup.
  49964. + */
  49965. +static int
  49966. +zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
  49967. +{
  49968. + struct zero_dev *dev = get_gadget_data (gadget);
  49969. + struct usb_request *req = dev->req;
  49970. + int value = -EOPNOTSUPP;
  49971. +
  49972. + /* usually this stores reply data in the pre-allocated ep0 buffer,
  49973. + * but config change events will reconfigure hardware.
  49974. + */
  49975. + req->zero = 0;
  49976. + switch (ctrl->bRequest) {
  49977. +
  49978. + case USB_REQ_GET_DESCRIPTOR:
  49979. +
  49980. + switch (ctrl->wValue >> 8) {
  49981. +
  49982. + case USB_DT_DEVICE:
  49983. + value = min (ctrl->wLength, (u16) sizeof device_desc);
  49984. + memcpy (req->buf, &device_desc, value);
  49985. + break;
  49986. +#ifdef CONFIG_USB_GADGET_DUALSPEED
  49987. + case USB_DT_DEVICE_QUALIFIER:
  49988. + if (!gadget->is_dualspeed)
  49989. + break;
  49990. + value = min (ctrl->wLength, (u16) sizeof dev_qualifier);
  49991. + memcpy (req->buf, &dev_qualifier, value);
  49992. + break;
  49993. +
  49994. + case USB_DT_OTHER_SPEED_CONFIG:
  49995. + if (!gadget->is_dualspeed)
  49996. + break;
  49997. + // FALLTHROUGH
  49998. +#endif /* CONFIG_USB_GADGET_DUALSPEED */
  49999. + case USB_DT_CONFIG:
  50000. + value = config_buf (gadget, req->buf,
  50001. + ctrl->wValue >> 8,
  50002. + ctrl->wValue & 0xff);
  50003. + if (value >= 0)
  50004. + value = min (ctrl->wLength, (u16) value);
  50005. + break;
  50006. +
  50007. + case USB_DT_STRING:
  50008. + /* wIndex == language code.
  50009. + * this driver only handles one language, you can
  50010. + * add string tables for other languages, using
  50011. + * any UTF-8 characters
  50012. + */
  50013. + value = usb_gadget_get_string (&stringtab,
  50014. + ctrl->wValue & 0xff, req->buf);
  50015. + if (value >= 0) {
  50016. + value = min (ctrl->wLength, (u16) value);
  50017. + }
  50018. + break;
  50019. + }
  50020. + break;
  50021. +
  50022. + /* currently two configs, two speeds */
  50023. + case USB_REQ_SET_CONFIGURATION:
  50024. + if (ctrl->bRequestType != 0)
  50025. + goto unknown;
  50026. +
  50027. + spin_lock (&dev->lock);
  50028. + value = zero_set_config (dev, ctrl->wValue, GFP_ATOMIC);
  50029. + spin_unlock (&dev->lock);
  50030. + break;
  50031. + case USB_REQ_GET_CONFIGURATION:
  50032. + if (ctrl->bRequestType != USB_DIR_IN)
  50033. + goto unknown;
  50034. + *(u8 *)req->buf = dev->config;
  50035. + value = min (ctrl->wLength, (u16) 1);
  50036. + break;
  50037. +
  50038. + /* until we add altsetting support, or other interfaces,
  50039. + * only 0/0 are possible. pxa2xx only supports 0/0 (poorly)
  50040. + * and already killed pending endpoint I/O.
  50041. + */
  50042. + case USB_REQ_SET_INTERFACE:
  50043. +
  50044. + if (ctrl->bRequestType != USB_RECIP_INTERFACE)
  50045. + goto unknown;
  50046. + spin_lock (&dev->lock);
  50047. + if (dev->config) {
  50048. + u8 config = dev->config;
  50049. +
  50050. + /* resets interface configuration, forgets about
  50051. + * previous transaction state (queued bufs, etc)
  50052. + * and re-inits endpoint state (toggle etc)
  50053. + * no response queued, just zero status == success.
  50054. + * if we had more than one interface we couldn't
  50055. + * use this "reset the config" shortcut.
  50056. + */
  50057. + zero_reset_config (dev);
  50058. + zero_set_config (dev, config, GFP_ATOMIC);
  50059. + value = 0;
  50060. + }
  50061. + spin_unlock (&dev->lock);
  50062. + break;
  50063. + case USB_REQ_GET_INTERFACE:
  50064. + if ((ctrl->bRequestType == 0x21) && (ctrl->wIndex == 0x02)) {
  50065. + value = ctrl->wLength;
  50066. + break;
  50067. + }
  50068. + else {
  50069. + if (ctrl->bRequestType != (USB_DIR_IN|USB_RECIP_INTERFACE))
  50070. + goto unknown;
  50071. + if (!dev->config)
  50072. + break;
  50073. + if (ctrl->wIndex != 0) {
  50074. + value = -EDOM;
  50075. + break;
  50076. + }
  50077. + *(u8 *)req->buf = 0;
  50078. + value = min (ctrl->wLength, (u16) 1);
  50079. + }
  50080. + break;
  50081. +
  50082. + /*
  50083. + * These are the same vendor-specific requests supported by
  50084. + * Intel's USB 2.0 compliance test devices. We exceed that
  50085. + * device spec by allowing multiple-packet requests.
  50086. + */
  50087. + case 0x5b: /* control WRITE test -- fill the buffer */
  50088. + if (ctrl->bRequestType != (USB_DIR_OUT|USB_TYPE_VENDOR))
  50089. + goto unknown;
  50090. + if (ctrl->wValue || ctrl->wIndex)
  50091. + break;
  50092. + /* just read that many bytes into the buffer */
  50093. + if (ctrl->wLength > USB_BUFSIZ)
  50094. + break;
  50095. + value = ctrl->wLength;
  50096. + break;
  50097. + case 0x5c: /* control READ test -- return the buffer */
  50098. + if (ctrl->bRequestType != (USB_DIR_IN|USB_TYPE_VENDOR))
  50099. + goto unknown;
  50100. + if (ctrl->wValue || ctrl->wIndex)
  50101. + break;
  50102. + /* expect those bytes are still in the buffer; send back */
  50103. + if (ctrl->wLength > USB_BUFSIZ
  50104. + || ctrl->wLength != req->length)
  50105. + break;
  50106. + value = ctrl->wLength;
  50107. + break;
  50108. +
  50109. + case 0x01: // SET_CUR
  50110. + case 0x02:
  50111. + case 0x03:
  50112. + case 0x04:
  50113. + case 0x05:
  50114. + value = ctrl->wLength;
  50115. + break;
  50116. + case 0x81:
  50117. + switch (ctrl->wValue) {
  50118. + case 0x0201:
  50119. + case 0x0202:
  50120. + ((u8*)req->buf)[0] = 0x00;
  50121. + ((u8*)req->buf)[1] = 0xe3;
  50122. + break;
  50123. + case 0x0300:
  50124. + case 0x0500:
  50125. + ((u8*)req->buf)[0] = 0x00;
  50126. + break;
  50127. + }
  50128. + //((u8*)req->buf)[0] = 0x81;
  50129. + //((u8*)req->buf)[1] = 0x81;
  50130. + value = ctrl->wLength;
  50131. + break;
  50132. + case 0x82:
  50133. + switch (ctrl->wValue) {
  50134. + case 0x0201:
  50135. + case 0x0202:
  50136. + ((u8*)req->buf)[0] = 0x00;
  50137. + ((u8*)req->buf)[1] = 0xc3;
  50138. + break;
  50139. + case 0x0300:
  50140. + case 0x0500:
  50141. + ((u8*)req->buf)[0] = 0x00;
  50142. + break;
  50143. + }
  50144. + //((u8*)req->buf)[0] = 0x82;
  50145. + //((u8*)req->buf)[1] = 0x82;
  50146. + value = ctrl->wLength;
  50147. + break;
  50148. + case 0x83:
  50149. + switch (ctrl->wValue) {
  50150. + case 0x0201:
  50151. + case 0x0202:
  50152. + ((u8*)req->buf)[0] = 0x00;
  50153. + ((u8*)req->buf)[1] = 0x00;
  50154. + break;
  50155. + case 0x0300:
  50156. + ((u8*)req->buf)[0] = 0x60;
  50157. + break;
  50158. + case 0x0500:
  50159. + ((u8*)req->buf)[0] = 0x18;
  50160. + break;
  50161. + }
  50162. + //((u8*)req->buf)[0] = 0x83;
  50163. + //((u8*)req->buf)[1] = 0x83;
  50164. + value = ctrl->wLength;
  50165. + break;
  50166. + case 0x84:
  50167. + switch (ctrl->wValue) {
  50168. + case 0x0201:
  50169. + case 0x0202:
  50170. + ((u8*)req->buf)[0] = 0x00;
  50171. + ((u8*)req->buf)[1] = 0x01;
  50172. + break;
  50173. + case 0x0300:
  50174. + case 0x0500:
  50175. + ((u8*)req->buf)[0] = 0x08;
  50176. + break;
  50177. + }
  50178. + //((u8*)req->buf)[0] = 0x84;
  50179. + //((u8*)req->buf)[1] = 0x84;
  50180. + value = ctrl->wLength;
  50181. + break;
  50182. + case 0x85:
  50183. + ((u8*)req->buf)[0] = 0x85;
  50184. + ((u8*)req->buf)[1] = 0x85;
  50185. + value = ctrl->wLength;
  50186. + break;
  50187. +
  50188. +
  50189. + default:
  50190. +unknown:
  50191. + printk("unknown control req%02x.%02x v%04x i%04x l%d\n",
  50192. + ctrl->bRequestType, ctrl->bRequest,
  50193. + ctrl->wValue, ctrl->wIndex, ctrl->wLength);
  50194. + }
  50195. +
  50196. + /* respond with data transfer before status phase? */
  50197. + if (value >= 0) {
  50198. + req->length = value;
  50199. + req->zero = value < ctrl->wLength
  50200. + && (value % gadget->ep0->maxpacket) == 0;
  50201. + value = usb_ep_queue (gadget->ep0, req, GFP_ATOMIC);
  50202. + if (value < 0) {
  50203. + DBG (dev, "ep_queue < 0 --> %d\n", value);
  50204. + req->status = 0;
  50205. + zero_setup_complete (gadget->ep0, req);
  50206. + }
  50207. + }
  50208. +
  50209. + /* device either stalls (value < 0) or reports success */
  50210. + return value;
  50211. +}
  50212. +
  50213. +static void
  50214. +zero_disconnect (struct usb_gadget *gadget)
  50215. +{
  50216. + struct zero_dev *dev = get_gadget_data (gadget);
  50217. + unsigned long flags;
  50218. +
  50219. + spin_lock_irqsave (&dev->lock, flags);
  50220. + zero_reset_config (dev);
  50221. +
  50222. + /* a more significant application might have some non-usb
  50223. + * activities to quiesce here, saving resources like power
  50224. + * or pushing the notification up a network stack.
  50225. + */
  50226. + spin_unlock_irqrestore (&dev->lock, flags);
  50227. +
  50228. + /* next we may get setup() calls to enumerate new connections;
  50229. + * or an unbind() during shutdown (including removing module).
  50230. + */
  50231. +}
  50232. +
  50233. +static void
  50234. +zero_autoresume (unsigned long _dev)
  50235. +{
  50236. + struct zero_dev *dev = (struct zero_dev *) _dev;
  50237. + int status;
  50238. +
  50239. + /* normally the host would be woken up for something
  50240. + * more significant than just a timer firing...
  50241. + */
  50242. + if (dev->gadget->speed != USB_SPEED_UNKNOWN) {
  50243. + status = usb_gadget_wakeup (dev->gadget);
  50244. + DBG (dev, "wakeup --> %d\n", status);
  50245. + }
  50246. +}
  50247. +
  50248. +/*-------------------------------------------------------------------------*/
  50249. +
  50250. +static void
  50251. +zero_unbind (struct usb_gadget *gadget)
  50252. +{
  50253. + struct zero_dev *dev = get_gadget_data (gadget);
  50254. +
  50255. + DBG (dev, "unbind\n");
  50256. +
  50257. + /* we've already been disconnected ... no i/o is active */
  50258. + if (dev->req)
  50259. + free_ep_req (gadget->ep0, dev->req);
  50260. + del_timer_sync (&dev->resume);
  50261. + kfree (dev);
  50262. + set_gadget_data (gadget, NULL);
  50263. +}
  50264. +
  50265. +static int
  50266. +zero_bind (struct usb_gadget *gadget)
  50267. +{
  50268. + struct zero_dev *dev;
  50269. + //struct usb_ep *ep;
  50270. +
  50271. + printk("binding\n");
  50272. + /*
  50273. + * DRIVER POLICY CHOICE: you may want to do this differently.
  50274. + * One thing to avoid is reusing a bcdDevice revision code
  50275. + * with different host-visible configurations or behavior
  50276. + * restrictions -- using ep1in/ep2out vs ep1out/ep3in, etc
  50277. + */
  50278. + //device_desc.bcdDevice = __constant_cpu_to_le16 (0x0201);
  50279. +
  50280. +
  50281. + /* ok, we made sense of the hardware ... */
  50282. + dev = kmalloc (sizeof *dev, SLAB_KERNEL);
  50283. + if (!dev)
  50284. + return -ENOMEM;
  50285. + memset (dev, 0, sizeof *dev);
  50286. + spin_lock_init (&dev->lock);
  50287. + dev->gadget = gadget;
  50288. + set_gadget_data (gadget, dev);
  50289. +
  50290. + /* preallocate control response and buffer */
  50291. + dev->req = usb_ep_alloc_request (gadget->ep0, GFP_KERNEL);
  50292. + if (!dev->req)
  50293. + goto enomem;
  50294. + dev->req->buf = usb_ep_alloc_buffer (gadget->ep0, USB_BUFSIZ,
  50295. + &dev->req->dma, GFP_KERNEL);
  50296. + if (!dev->req->buf)
  50297. + goto enomem;
  50298. +
  50299. + dev->req->complete = zero_setup_complete;
  50300. +
  50301. + device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
  50302. +
  50303. +#ifdef CONFIG_USB_GADGET_DUALSPEED
  50304. + /* assume ep0 uses the same value for both speeds ... */
  50305. + dev_qualifier.bMaxPacketSize0 = device_desc.bMaxPacketSize0;
  50306. +
  50307. + /* and that all endpoints are dual-speed */
  50308. + //hs_source_desc.bEndpointAddress = fs_source_desc.bEndpointAddress;
  50309. + //hs_sink_desc.bEndpointAddress = fs_sink_desc.bEndpointAddress;
  50310. +#endif
  50311. +
  50312. + usb_gadget_set_selfpowered (gadget);
  50313. +
  50314. + init_timer (&dev->resume);
  50315. + dev->resume.function = zero_autoresume;
  50316. + dev->resume.data = (unsigned long) dev;
  50317. +
  50318. + gadget->ep0->driver_data = dev;
  50319. +
  50320. + INFO (dev, "%s, version: " DRIVER_VERSION "\n", longname);
  50321. + INFO (dev, "using %s, OUT %s IN %s\n", gadget->name,
  50322. + EP_OUT_NAME, EP_IN_NAME);
  50323. +
  50324. + snprintf (manufacturer, sizeof manufacturer,
  50325. + UTS_SYSNAME " " UTS_RELEASE " with %s",
  50326. + gadget->name);
  50327. +
  50328. + return 0;
  50329. +
  50330. +enomem:
  50331. + zero_unbind (gadget);
  50332. + return -ENOMEM;
  50333. +}
  50334. +
  50335. +/*-------------------------------------------------------------------------*/
  50336. +
  50337. +static void
  50338. +zero_suspend (struct usb_gadget *gadget)
  50339. +{
  50340. + struct zero_dev *dev = get_gadget_data (gadget);
  50341. +
  50342. + if (gadget->speed == USB_SPEED_UNKNOWN)
  50343. + return;
  50344. +
  50345. + if (autoresume) {
  50346. + mod_timer (&dev->resume, jiffies + (HZ * autoresume));
  50347. + DBG (dev, "suspend, wakeup in %d seconds\n", autoresume);
  50348. + } else
  50349. + DBG (dev, "suspend\n");
  50350. +}
  50351. +
  50352. +static void
  50353. +zero_resume (struct usb_gadget *gadget)
  50354. +{
  50355. + struct zero_dev *dev = get_gadget_data (gadget);
  50356. +
  50357. + DBG (dev, "resume\n");
  50358. + del_timer (&dev->resume);
  50359. +}
  50360. +
  50361. +
  50362. +/*-------------------------------------------------------------------------*/
  50363. +
  50364. +static struct usb_gadget_driver zero_driver = {
  50365. +#ifdef CONFIG_USB_GADGET_DUALSPEED
  50366. + .speed = USB_SPEED_HIGH,
  50367. +#else
  50368. + .speed = USB_SPEED_FULL,
  50369. +#endif
  50370. + .function = (char *) longname,
  50371. + .bind = zero_bind,
  50372. + .unbind = zero_unbind,
  50373. +
  50374. + .setup = zero_setup,
  50375. + .disconnect = zero_disconnect,
  50376. +
  50377. + .suspend = zero_suspend,
  50378. + .resume = zero_resume,
  50379. +
  50380. + .driver = {
  50381. + .name = (char *) shortname,
  50382. + // .shutdown = ...
  50383. + // .suspend = ...
  50384. + // .resume = ...
  50385. + },
  50386. +};
  50387. +
  50388. +MODULE_AUTHOR ("David Brownell");
  50389. +MODULE_LICENSE ("Dual BSD/GPL");
  50390. +
  50391. +static struct proc_dir_entry *pdir, *pfile;
  50392. +
  50393. +static int isoc_read_data (char *page, char **start,
  50394. + off_t off, int count,
  50395. + int *eof, void *data)
  50396. +{
  50397. + int i;
  50398. + static int c = 0;
  50399. + static int done = 0;
  50400. + static int s = 0;
  50401. +
  50402. +/*
  50403. + printk ("\ncount: %d\n", count);
  50404. + printk ("rbuf_start: %d\n", rbuf_start);
  50405. + printk ("rbuf_len: %d\n", rbuf_len);
  50406. + printk ("off: %d\n", off);
  50407. + printk ("start: %p\n\n", *start);
  50408. +*/
  50409. + if (done) {
  50410. + c = 0;
  50411. + done = 0;
  50412. + *eof = 1;
  50413. + return 0;
  50414. + }
  50415. +
  50416. + if (c == 0) {
  50417. + if (rbuf_len == RBUF_LEN)
  50418. + s = rbuf_start;
  50419. + else s = 0;
  50420. + }
  50421. +
  50422. + for (i=0; i<count && c<rbuf_len; i++, c++) {
  50423. + page[i] = rbuf[(c+s) % RBUF_LEN];
  50424. + }
  50425. + *start = page;
  50426. +
  50427. + if (c >= rbuf_len) {
  50428. + *eof = 1;
  50429. + done = 1;
  50430. + }
  50431. +
  50432. +
  50433. + return i;
  50434. +}
  50435. +
  50436. +static int __init init (void)
  50437. +{
  50438. +
  50439. + int retval = 0;
  50440. +
  50441. + pdir = proc_mkdir("isoc_test", NULL);
  50442. + if(pdir == NULL) {
  50443. + retval = -ENOMEM;
  50444. + printk("Error creating dir\n");
  50445. + goto done;
  50446. + }
  50447. + pdir->owner = THIS_MODULE;
  50448. +
  50449. + pfile = create_proc_read_entry("isoc_data",
  50450. + 0444, pdir,
  50451. + isoc_read_data,
  50452. + NULL);
  50453. + if (pfile == NULL) {
  50454. + retval = -ENOMEM;
  50455. + printk("Error creating file\n");
  50456. + goto no_file;
  50457. + }
  50458. + pfile->owner = THIS_MODULE;
  50459. +
  50460. + return usb_gadget_register_driver (&zero_driver);
  50461. +
  50462. + no_file:
  50463. + remove_proc_entry("isoc_data", NULL);
  50464. + done:
  50465. + return retval;
  50466. +}
  50467. +module_init (init);
  50468. +
  50469. +static void __exit cleanup (void)
  50470. +{
  50471. +
  50472. + usb_gadget_unregister_driver (&zero_driver);
  50473. +
  50474. + remove_proc_entry("isoc_data", pdir);
  50475. + remove_proc_entry("isoc_test", NULL);
  50476. +}
  50477. +module_exit (cleanup);
  50478. diff -Nur linux-3.13.11/drivers/usb/host/dwc_otg/dwc_cfi_common.h linux-rpi/drivers/usb/host/dwc_otg/dwc_cfi_common.h
  50479. --- linux-3.13.11/drivers/usb/host/dwc_otg/dwc_cfi_common.h 1970-01-01 01:00:00.000000000 +0100
  50480. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_cfi_common.h 2014-04-24 15:37:13.310990489 +0200
  50481. @@ -0,0 +1,142 @@
  50482. +/* ==========================================================================
  50483. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  50484. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  50485. + * otherwise expressly agreed to in writing between Synopsys and you.
  50486. + *
  50487. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  50488. + * any End User Software License Agreement or Agreement for Licensed Product
  50489. + * with Synopsys or any supplement thereto. You are permitted to use and
  50490. + * redistribute this Software in source and binary forms, with or without
  50491. + * modification, provided that redistributions of source code must retain this
  50492. + * notice. You may not view, use, disclose, copy or distribute this file or
  50493. + * any information contained herein except pursuant to this license grant from
  50494. + * Synopsys. If you do not agree with this notice, including the disclaimer
  50495. + * below, then you are not authorized to use the Software.
  50496. + *
  50497. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  50498. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  50499. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  50500. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  50501. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  50502. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  50503. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  50504. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  50505. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  50506. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  50507. + * DAMAGE.
  50508. + * ========================================================================== */
  50509. +
  50510. +#if !defined(__DWC_CFI_COMMON_H__)
  50511. +#define __DWC_CFI_COMMON_H__
  50512. +
  50513. +//#include <linux/types.h>
  50514. +
  50515. +/**
  50516. + * @file
  50517. + *
  50518. + * This file contains the CFI specific common constants, interfaces
  50519. + * (functions and macros) and structures for Linux. No PCD specific
  50520. + * data structure or definition is to be included in this file.
  50521. + *
  50522. + */
  50523. +
  50524. +/** This is a request for all Core Features */
  50525. +#define VEN_CORE_GET_FEATURES 0xB1
  50526. +
  50527. +/** This is a request to get the value of a specific Core Feature */
  50528. +#define VEN_CORE_GET_FEATURE 0xB2
  50529. +
  50530. +/** This command allows the host to set the value of a specific Core Feature */
  50531. +#define VEN_CORE_SET_FEATURE 0xB3
  50532. +
  50533. +/** This command allows the host to set the default values of
  50534. + * either all or any specific Core Feature
  50535. + */
  50536. +#define VEN_CORE_RESET_FEATURES 0xB4
  50537. +
  50538. +/** This command forces the PCD to write the deferred values of a Core Features */
  50539. +#define VEN_CORE_ACTIVATE_FEATURES 0xB5
  50540. +
  50541. +/** This request reads a DWORD value from a register at the specified offset */
  50542. +#define VEN_CORE_READ_REGISTER 0xB6
  50543. +
  50544. +/** This request writes a DWORD value into a register at the specified offset */
  50545. +#define VEN_CORE_WRITE_REGISTER 0xB7
  50546. +
  50547. +/** This structure is the header of the Core Features dataset returned to
  50548. + * the Host
  50549. + */
  50550. +struct cfi_all_features_header {
  50551. +/** The features header structure length is */
  50552. +#define CFI_ALL_FEATURES_HDR_LEN 8
  50553. + /**
  50554. + * The total length of the features dataset returned to the Host
  50555. + */
  50556. + uint16_t wTotalLen;
  50557. +
  50558. + /**
  50559. + * CFI version number inBinary-Coded Decimal (i.e., 1.00 is 100H).
  50560. + * This field identifies the version of the CFI Specification with which
  50561. + * the device is compliant.
  50562. + */
  50563. + uint16_t wVersion;
  50564. +
  50565. + /** The ID of the Core */
  50566. + uint16_t wCoreID;
  50567. +#define CFI_CORE_ID_UDC 1
  50568. +#define CFI_CORE_ID_OTG 2
  50569. +#define CFI_CORE_ID_WUDEV 3
  50570. +
  50571. + /** Number of features returned by VEN_CORE_GET_FEATURES request */
  50572. + uint16_t wNumFeatures;
  50573. +} UPACKED;
  50574. +
  50575. +typedef struct cfi_all_features_header cfi_all_features_header_t;
  50576. +
  50577. +/** This structure is a header of the Core Feature descriptor dataset returned to
  50578. + * the Host after the VEN_CORE_GET_FEATURES request
  50579. + */
  50580. +struct cfi_feature_desc_header {
  50581. +#define CFI_FEATURE_DESC_HDR_LEN 8
  50582. +
  50583. + /** The feature ID */
  50584. + uint16_t wFeatureID;
  50585. +
  50586. + /** Length of this feature descriptor in bytes - including the
  50587. + * length of the feature name string
  50588. + */
  50589. + uint16_t wLength;
  50590. +
  50591. + /** The data length of this feature in bytes */
  50592. + uint16_t wDataLength;
  50593. +
  50594. + /**
  50595. + * Attributes of this features
  50596. + * D0: Access rights
  50597. + * 0 - Read/Write
  50598. + * 1 - Read only
  50599. + */
  50600. + uint8_t bmAttributes;
  50601. +#define CFI_FEATURE_ATTR_RO 1
  50602. +#define CFI_FEATURE_ATTR_RW 0
  50603. +
  50604. + /** Length of the feature name in bytes */
  50605. + uint8_t bNameLen;
  50606. +
  50607. + /** The feature name buffer */
  50608. + //uint8_t *name;
  50609. +} UPACKED;
  50610. +
  50611. +typedef struct cfi_feature_desc_header cfi_feature_desc_header_t;
  50612. +
  50613. +/**
  50614. + * This structure describes a NULL terminated string referenced by its id field.
  50615. + * It is very similar to usb_string structure but has the id field type set to 16-bit.
  50616. + */
  50617. +struct cfi_string {
  50618. + uint16_t id;
  50619. + const uint8_t *s;
  50620. +};
  50621. +typedef struct cfi_string cfi_string_t;
  50622. +
  50623. +#endif
  50624. diff -Nur linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_adp.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_adp.c
  50625. --- linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_adp.c 1970-01-01 01:00:00.000000000 +0100
  50626. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_adp.c 2014-04-24 15:37:13.310990489 +0200
  50627. @@ -0,0 +1,854 @@
  50628. +/* ==========================================================================
  50629. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_adp.c $
  50630. + * $Revision: #12 $
  50631. + * $Date: 2011/10/26 $
  50632. + * $Change: 1873028 $
  50633. + *
  50634. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  50635. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  50636. + * otherwise expressly agreed to in writing between Synopsys and you.
  50637. + *
  50638. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  50639. + * any End User Software License Agreement or Agreement for Licensed Product
  50640. + * with Synopsys or any supplement thereto. You are permitted to use and
  50641. + * redistribute this Software in source and binary forms, with or without
  50642. + * modification, provided that redistributions of source code must retain this
  50643. + * notice. You may not view, use, disclose, copy or distribute this file or
  50644. + * any information contained herein except pursuant to this license grant from
  50645. + * Synopsys. If you do not agree with this notice, including the disclaimer
  50646. + * below, then you are not authorized to use the Software.
  50647. + *
  50648. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  50649. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  50650. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  50651. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  50652. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  50653. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  50654. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  50655. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  50656. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  50657. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  50658. + * DAMAGE.
  50659. + * ========================================================================== */
  50660. +
  50661. +#include "dwc_os.h"
  50662. +#include "dwc_otg_regs.h"
  50663. +#include "dwc_otg_cil.h"
  50664. +#include "dwc_otg_adp.h"
  50665. +
  50666. +/** @file
  50667. + *
  50668. + * This file contains the most of the Attach Detect Protocol implementation for
  50669. + * the driver to support OTG Rev2.0.
  50670. + *
  50671. + */
  50672. +
  50673. +void dwc_otg_adp_write_reg(dwc_otg_core_if_t * core_if, uint32_t value)
  50674. +{
  50675. + adpctl_data_t adpctl;
  50676. +
  50677. + adpctl.d32 = value;
  50678. + adpctl.b.ar = 0x2;
  50679. +
  50680. + DWC_WRITE_REG32(&core_if->core_global_regs->adpctl, adpctl.d32);
  50681. +
  50682. + while (adpctl.b.ar) {
  50683. + adpctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->adpctl);
  50684. + }
  50685. +
  50686. +}
  50687. +
  50688. +/**
  50689. + * Function is called to read ADP registers
  50690. + */
  50691. +uint32_t dwc_otg_adp_read_reg(dwc_otg_core_if_t * core_if)
  50692. +{
  50693. + adpctl_data_t adpctl;
  50694. +
  50695. + adpctl.d32 = 0;
  50696. + adpctl.b.ar = 0x1;
  50697. +
  50698. + DWC_WRITE_REG32(&core_if->core_global_regs->adpctl, adpctl.d32);
  50699. +
  50700. + while (adpctl.b.ar) {
  50701. + adpctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->adpctl);
  50702. + }
  50703. +
  50704. + return adpctl.d32;
  50705. +}
  50706. +
  50707. +/**
  50708. + * Function is called to read ADPCTL register and filter Write-clear bits
  50709. + */
  50710. +uint32_t dwc_otg_adp_read_reg_filter(dwc_otg_core_if_t * core_if)
  50711. +{
  50712. + adpctl_data_t adpctl;
  50713. +
  50714. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  50715. + adpctl.b.adp_tmout_int = 0;
  50716. + adpctl.b.adp_prb_int = 0;
  50717. + adpctl.b.adp_tmout_int = 0;
  50718. +
  50719. + return adpctl.d32;
  50720. +}
  50721. +
  50722. +/**
  50723. + * Function is called to write ADP registers
  50724. + */
  50725. +void dwc_otg_adp_modify_reg(dwc_otg_core_if_t * core_if, uint32_t clr,
  50726. + uint32_t set)
  50727. +{
  50728. + dwc_otg_adp_write_reg(core_if,
  50729. + (dwc_otg_adp_read_reg(core_if) & (~clr)) | set);
  50730. +}
  50731. +
  50732. +static void adp_sense_timeout(void *ptr)
  50733. +{
  50734. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) ptr;
  50735. + core_if->adp.sense_timer_started = 0;
  50736. + DWC_PRINTF("ADP SENSE TIMEOUT\n");
  50737. + if (core_if->adp_enable) {
  50738. + dwc_otg_adp_sense_stop(core_if);
  50739. + dwc_otg_adp_probe_start(core_if);
  50740. + }
  50741. +}
  50742. +
  50743. +/**
  50744. + * This function is called when the ADP vbus timer expires. Timeout is 1.1s.
  50745. + */
  50746. +static void adp_vbuson_timeout(void *ptr)
  50747. +{
  50748. + gpwrdn_data_t gpwrdn;
  50749. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) ptr;
  50750. + hprt0_data_t hprt0 = {.d32 = 0 };
  50751. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  50752. + DWC_PRINTF("%s: 1.1 seconds expire after turning on VBUS\n",__FUNCTION__);
  50753. + if (core_if) {
  50754. + core_if->adp.vbuson_timer_started = 0;
  50755. + /* Turn off vbus */
  50756. + hprt0.b.prtpwr = 1;
  50757. + DWC_MODIFY_REG32(core_if->host_if->hprt0, hprt0.d32, 0);
  50758. + gpwrdn.d32 = 0;
  50759. +
  50760. + /* Power off the core */
  50761. + if (core_if->power_down == 2) {
  50762. + /* Enable Wakeup Logic */
  50763. +// gpwrdn.b.wkupactiv = 1;
  50764. + gpwrdn.b.pmuactv = 0;
  50765. + gpwrdn.b.pwrdnrstn = 1;
  50766. + gpwrdn.b.pwrdnclmp = 1;
  50767. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0,
  50768. + gpwrdn.d32);
  50769. +
  50770. + /* Suspend the Phy Clock */
  50771. + pcgcctl.b.stoppclk = 1;
  50772. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  50773. +
  50774. + /* Switch on VDD */
  50775. +// gpwrdn.b.wkupactiv = 1;
  50776. + gpwrdn.b.pmuactv = 1;
  50777. + gpwrdn.b.pwrdnrstn = 1;
  50778. + gpwrdn.b.pwrdnclmp = 1;
  50779. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0,
  50780. + gpwrdn.d32);
  50781. + } else {
  50782. + /* Enable Power Down Logic */
  50783. + gpwrdn.b.pmuintsel = 1;
  50784. + gpwrdn.b.pmuactv = 1;
  50785. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  50786. + }
  50787. +
  50788. + /* Power off the core */
  50789. + if (core_if->power_down == 2) {
  50790. + gpwrdn.d32 = 0;
  50791. + gpwrdn.b.pwrdnswtch = 1;
  50792. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn,
  50793. + gpwrdn.d32, 0);
  50794. + }
  50795. +
  50796. + /* Unmask SRP detected interrupt from Power Down Logic */
  50797. + gpwrdn.d32 = 0;
  50798. + gpwrdn.b.srp_det_msk = 1;
  50799. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  50800. +
  50801. + dwc_otg_adp_probe_start(core_if);
  50802. + dwc_otg_dump_global_registers(core_if);
  50803. + dwc_otg_dump_host_registers(core_if);
  50804. + }
  50805. +
  50806. +}
  50807. +
  50808. +/**
  50809. + * Start the ADP Initial Probe timer to detect if Port Connected interrupt is
  50810. + * not asserted within 1.1 seconds.
  50811. + *
  50812. + * @param core_if the pointer to core_if strucure.
  50813. + */
  50814. +void dwc_otg_adp_vbuson_timer_start(dwc_otg_core_if_t * core_if)
  50815. +{
  50816. + core_if->adp.vbuson_timer_started = 1;
  50817. + if (core_if->adp.vbuson_timer)
  50818. + {
  50819. + DWC_PRINTF("SCHEDULING VBUSON TIMER\n");
  50820. + /* 1.1 secs + 60ms necessary for cil_hcd_start*/
  50821. + DWC_TIMER_SCHEDULE(core_if->adp.vbuson_timer, 1160);
  50822. + } else {
  50823. + DWC_WARN("VBUSON_TIMER = %p\n",core_if->adp.vbuson_timer);
  50824. + }
  50825. +}
  50826. +
  50827. +#if 0
  50828. +/**
  50829. + * Masks all DWC OTG core interrupts
  50830. + *
  50831. + */
  50832. +static void mask_all_interrupts(dwc_otg_core_if_t * core_if)
  50833. +{
  50834. + int i;
  50835. + gahbcfg_data_t ahbcfg = {.d32 = 0 };
  50836. +
  50837. + /* Mask Host Interrupts */
  50838. +
  50839. + /* Clear and disable HCINTs */
  50840. + for (i = 0; i < core_if->core_params->host_channels; i++) {
  50841. + DWC_WRITE_REG32(&core_if->host_if->hc_regs[i]->hcintmsk, 0);
  50842. + DWC_WRITE_REG32(&core_if->host_if->hc_regs[i]->hcint, 0xFFFFFFFF);
  50843. +
  50844. + }
  50845. +
  50846. + /* Clear and disable HAINT */
  50847. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->haintmsk, 0x0000);
  50848. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->haint, 0xFFFFFFFF);
  50849. +
  50850. + /* Mask Device Interrupts */
  50851. + if (!core_if->multiproc_int_enable) {
  50852. + /* Clear and disable IN Endpoint interrupts */
  50853. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->diepmsk, 0);
  50854. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  50855. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->
  50856. + diepint, 0xFFFFFFFF);
  50857. + }
  50858. +
  50859. + /* Clear and disable OUT Endpoint interrupts */
  50860. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->doepmsk, 0);
  50861. + for (i = 0; i <= core_if->dev_if->num_out_eps; i++) {
  50862. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[i]->
  50863. + doepint, 0xFFFFFFFF);
  50864. + }
  50865. +
  50866. + /* Clear and disable DAINT */
  50867. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->daint,
  50868. + 0xFFFFFFFF);
  50869. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->daintmsk, 0);
  50870. + } else {
  50871. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  50872. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->
  50873. + diepeachintmsk[i], 0);
  50874. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->
  50875. + diepint, 0xFFFFFFFF);
  50876. + }
  50877. +
  50878. + for (i = 0; i < core_if->dev_if->num_out_eps; ++i) {
  50879. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->
  50880. + doepeachintmsk[i], 0);
  50881. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[i]->
  50882. + doepint, 0xFFFFFFFF);
  50883. + }
  50884. +
  50885. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->deachintmsk,
  50886. + 0);
  50887. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->deachint,
  50888. + 0xFFFFFFFF);
  50889. +
  50890. + }
  50891. +
  50892. + /* Disable interrupts */
  50893. + ahbcfg.b.glblintrmsk = 1;
  50894. + DWC_MODIFY_REG32(&core_if->core_global_regs->gahbcfg, ahbcfg.d32, 0);
  50895. +
  50896. + /* Disable all interrupts. */
  50897. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, 0);
  50898. +
  50899. + /* Clear any pending interrupts */
  50900. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  50901. +
  50902. + /* Clear any pending OTG Interrupts */
  50903. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgint, 0xFFFFFFFF);
  50904. +}
  50905. +
  50906. +/**
  50907. + * Unmask Port Connection Detected interrupt
  50908. + *
  50909. + */
  50910. +static void unmask_conn_det_intr(dwc_otg_core_if_t * core_if)
  50911. +{
  50912. + gintmsk_data_t gintmsk = {.d32 = 0,.b.portintr = 1 };
  50913. +
  50914. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gintmsk.d32);
  50915. +}
  50916. +#endif
  50917. +
  50918. +/**
  50919. + * Starts the ADP Probing
  50920. + *
  50921. + * @param core_if the pointer to core_if structure.
  50922. + */
  50923. +uint32_t dwc_otg_adp_probe_start(dwc_otg_core_if_t * core_if)
  50924. +{
  50925. +
  50926. + adpctl_data_t adpctl = {.d32 = 0};
  50927. + gpwrdn_data_t gpwrdn;
  50928. +#if 0
  50929. + adpctl_data_t adpctl_int = {.d32 = 0, .b.adp_prb_int = 1,
  50930. + .b.adp_sns_int = 1, b.adp_tmout_int};
  50931. +#endif
  50932. + dwc_otg_disable_global_interrupts(core_if);
  50933. + DWC_PRINTF("ADP Probe Start\n");
  50934. + core_if->adp.probe_enabled = 1;
  50935. +
  50936. + adpctl.b.adpres = 1;
  50937. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  50938. +
  50939. + while (adpctl.b.adpres) {
  50940. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  50941. + }
  50942. +
  50943. + adpctl.d32 = 0;
  50944. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  50945. +
  50946. + /* In Host mode unmask SRP detected interrupt */
  50947. + gpwrdn.d32 = 0;
  50948. + gpwrdn.b.sts_chngint_msk = 1;
  50949. + if (!gpwrdn.b.idsts) {
  50950. + gpwrdn.b.srp_det_msk = 1;
  50951. + }
  50952. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  50953. +
  50954. + adpctl.b.adp_tmout_int_msk = 1;
  50955. + adpctl.b.adp_prb_int_msk = 1;
  50956. + adpctl.b.prb_dschg = 1;
  50957. + adpctl.b.prb_delta = 1;
  50958. + adpctl.b.prb_per = 1;
  50959. + adpctl.b.adpen = 1;
  50960. + adpctl.b.enaprb = 1;
  50961. +
  50962. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  50963. + DWC_PRINTF("ADP Probe Finish\n");
  50964. + return 0;
  50965. +}
  50966. +
  50967. +/**
  50968. + * Starts the ADP Sense timer to detect if ADP Sense interrupt is not asserted
  50969. + * within 3 seconds.
  50970. + *
  50971. + * @param core_if the pointer to core_if strucure.
  50972. + */
  50973. +void dwc_otg_adp_sense_timer_start(dwc_otg_core_if_t * core_if)
  50974. +{
  50975. + core_if->adp.sense_timer_started = 1;
  50976. + DWC_TIMER_SCHEDULE(core_if->adp.sense_timer, 3000 /* 3 secs */ );
  50977. +}
  50978. +
  50979. +/**
  50980. + * Starts the ADP Sense
  50981. + *
  50982. + * @param core_if the pointer to core_if strucure.
  50983. + */
  50984. +uint32_t dwc_otg_adp_sense_start(dwc_otg_core_if_t * core_if)
  50985. +{
  50986. + adpctl_data_t adpctl;
  50987. +
  50988. + DWC_PRINTF("ADP Sense Start\n");
  50989. +
  50990. + /* Unmask ADP sense interrupt and mask all other from the core */
  50991. + adpctl.d32 = dwc_otg_adp_read_reg_filter(core_if);
  50992. + adpctl.b.adp_sns_int_msk = 1;
  50993. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  50994. + dwc_otg_disable_global_interrupts(core_if); // vahrama
  50995. +
  50996. + /* Set ADP reset bit*/
  50997. + adpctl.d32 = dwc_otg_adp_read_reg_filter(core_if);
  50998. + adpctl.b.adpres = 1;
  50999. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  51000. +
  51001. + while (adpctl.b.adpres) {
  51002. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  51003. + }
  51004. +
  51005. + adpctl.b.adpres = 0;
  51006. + adpctl.b.adpen = 1;
  51007. + adpctl.b.enasns = 1;
  51008. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  51009. +
  51010. + dwc_otg_adp_sense_timer_start(core_if);
  51011. +
  51012. + return 0;
  51013. +}
  51014. +
  51015. +/**
  51016. + * Stops the ADP Probing
  51017. + *
  51018. + * @param core_if the pointer to core_if strucure.
  51019. + */
  51020. +uint32_t dwc_otg_adp_probe_stop(dwc_otg_core_if_t * core_if)
  51021. +{
  51022. +
  51023. + adpctl_data_t adpctl;
  51024. + DWC_PRINTF("Stop ADP probe\n");
  51025. + core_if->adp.probe_enabled = 0;
  51026. + core_if->adp.probe_counter = 0;
  51027. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  51028. +
  51029. + adpctl.b.adpen = 0;
  51030. + adpctl.b.adp_prb_int = 1;
  51031. + adpctl.b.adp_tmout_int = 1;
  51032. + adpctl.b.adp_sns_int = 1;
  51033. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  51034. +
  51035. + return 0;
  51036. +}
  51037. +
  51038. +/**
  51039. + * Stops the ADP Sensing
  51040. + *
  51041. + * @param core_if the pointer to core_if strucure.
  51042. + */
  51043. +uint32_t dwc_otg_adp_sense_stop(dwc_otg_core_if_t * core_if)
  51044. +{
  51045. + adpctl_data_t adpctl;
  51046. +
  51047. + core_if->adp.sense_enabled = 0;
  51048. +
  51049. + adpctl.d32 = dwc_otg_adp_read_reg_filter(core_if);
  51050. + adpctl.b.enasns = 0;
  51051. + adpctl.b.adp_sns_int = 1;
  51052. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  51053. +
  51054. + return 0;
  51055. +}
  51056. +
  51057. +/**
  51058. + * Called to turn on the VBUS after initial ADP probe in host mode.
  51059. + * If port power was already enabled in cil_hcd_start function then
  51060. + * only schedule a timer.
  51061. + *
  51062. + * @param core_if the pointer to core_if structure.
  51063. + */
  51064. +void dwc_otg_adp_turnon_vbus(dwc_otg_core_if_t * core_if)
  51065. +{
  51066. + hprt0_data_t hprt0 = {.d32 = 0 };
  51067. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  51068. + DWC_PRINTF("Turn on VBUS for 1.1s, port power is %d\n", hprt0.b.prtpwr);
  51069. +
  51070. + if (hprt0.b.prtpwr == 0) {
  51071. + hprt0.b.prtpwr = 1;
  51072. + //DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  51073. + }
  51074. +
  51075. + dwc_otg_adp_vbuson_timer_start(core_if);
  51076. +}
  51077. +
  51078. +/**
  51079. + * Called right after driver is loaded
  51080. + * to perform initial actions for ADP
  51081. + *
  51082. + * @param core_if the pointer to core_if structure.
  51083. + * @param is_host - flag for current mode of operation either from GINTSTS or GPWRDN
  51084. + */
  51085. +void dwc_otg_adp_start(dwc_otg_core_if_t * core_if, uint8_t is_host)
  51086. +{
  51087. + gpwrdn_data_t gpwrdn;
  51088. +
  51089. + DWC_PRINTF("ADP Initial Start\n");
  51090. + core_if->adp.adp_started = 1;
  51091. +
  51092. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  51093. + dwc_otg_disable_global_interrupts(core_if);
  51094. + if (is_host) {
  51095. + DWC_PRINTF("HOST MODE\n");
  51096. + /* Enable Power Down Logic Interrupt*/
  51097. + gpwrdn.d32 = 0;
  51098. + gpwrdn.b.pmuintsel = 1;
  51099. + gpwrdn.b.pmuactv = 1;
  51100. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  51101. + /* Initialize first ADP probe to obtain Ramp Time value */
  51102. + core_if->adp.initial_probe = 1;
  51103. + dwc_otg_adp_probe_start(core_if);
  51104. + } else {
  51105. + gotgctl_data_t gotgctl;
  51106. + gotgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  51107. + DWC_PRINTF("DEVICE MODE\n");
  51108. + if (gotgctl.b.bsesvld == 0) {
  51109. + /* Enable Power Down Logic Interrupt*/
  51110. + gpwrdn.d32 = 0;
  51111. + DWC_PRINTF("VBUS is not valid - start ADP probe\n");
  51112. + gpwrdn.b.pmuintsel = 1;
  51113. + gpwrdn.b.pmuactv = 1;
  51114. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  51115. + core_if->adp.initial_probe = 1;
  51116. + dwc_otg_adp_probe_start(core_if);
  51117. + } else {
  51118. + DWC_PRINTF("VBUS is valid - initialize core as a Device\n");
  51119. + core_if->op_state = B_PERIPHERAL;
  51120. + dwc_otg_core_init(core_if);
  51121. + dwc_otg_enable_global_interrupts(core_if);
  51122. + cil_pcd_start(core_if);
  51123. + dwc_otg_dump_global_registers(core_if);
  51124. + dwc_otg_dump_dev_registers(core_if);
  51125. + }
  51126. + }
  51127. +}
  51128. +
  51129. +void dwc_otg_adp_init(dwc_otg_core_if_t * core_if)
  51130. +{
  51131. + core_if->adp.adp_started = 0;
  51132. + core_if->adp.initial_probe = 0;
  51133. + core_if->adp.probe_timer_values[0] = -1;
  51134. + core_if->adp.probe_timer_values[1] = -1;
  51135. + core_if->adp.probe_enabled = 0;
  51136. + core_if->adp.sense_enabled = 0;
  51137. + core_if->adp.sense_timer_started = 0;
  51138. + core_if->adp.vbuson_timer_started = 0;
  51139. + core_if->adp.probe_counter = 0;
  51140. + core_if->adp.gpwrdn = 0;
  51141. + core_if->adp.attached = DWC_OTG_ADP_UNKOWN;
  51142. + /* Initialize timers */
  51143. + core_if->adp.sense_timer =
  51144. + DWC_TIMER_ALLOC("ADP SENSE TIMER", adp_sense_timeout, core_if);
  51145. + core_if->adp.vbuson_timer =
  51146. + DWC_TIMER_ALLOC("ADP VBUS ON TIMER", adp_vbuson_timeout, core_if);
  51147. + if (!core_if->adp.sense_timer || !core_if->adp.vbuson_timer)
  51148. + {
  51149. + DWC_ERROR("Could not allocate memory for ADP timers\n");
  51150. + }
  51151. +}
  51152. +
  51153. +void dwc_otg_adp_remove(dwc_otg_core_if_t * core_if)
  51154. +{
  51155. + gpwrdn_data_t gpwrdn = { .d32 = 0 };
  51156. + gpwrdn.b.pmuintsel = 1;
  51157. + gpwrdn.b.pmuactv = 1;
  51158. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  51159. +
  51160. + if (core_if->adp.probe_enabled)
  51161. + dwc_otg_adp_probe_stop(core_if);
  51162. + if (core_if->adp.sense_enabled)
  51163. + dwc_otg_adp_sense_stop(core_if);
  51164. + if (core_if->adp.sense_timer_started)
  51165. + DWC_TIMER_CANCEL(core_if->adp.sense_timer);
  51166. + if (core_if->adp.vbuson_timer_started)
  51167. + DWC_TIMER_CANCEL(core_if->adp.vbuson_timer);
  51168. + DWC_TIMER_FREE(core_if->adp.sense_timer);
  51169. + DWC_TIMER_FREE(core_if->adp.vbuson_timer);
  51170. +}
  51171. +
  51172. +/////////////////////////////////////////////////////////////////////
  51173. +////////////// ADP Interrupt Handlers ///////////////////////////////
  51174. +/////////////////////////////////////////////////////////////////////
  51175. +/**
  51176. + * This function sets Ramp Timer values
  51177. + */
  51178. +static uint32_t set_timer_value(dwc_otg_core_if_t * core_if, uint32_t val)
  51179. +{
  51180. + if (core_if->adp.probe_timer_values[0] == -1) {
  51181. + core_if->adp.probe_timer_values[0] = val;
  51182. + core_if->adp.probe_timer_values[1] = -1;
  51183. + return 1;
  51184. + } else {
  51185. + core_if->adp.probe_timer_values[1] =
  51186. + core_if->adp.probe_timer_values[0];
  51187. + core_if->adp.probe_timer_values[0] = val;
  51188. + return 0;
  51189. + }
  51190. +}
  51191. +
  51192. +/**
  51193. + * This function compares Ramp Timer values
  51194. + */
  51195. +static uint32_t compare_timer_values(dwc_otg_core_if_t * core_if)
  51196. +{
  51197. + uint32_t diff;
  51198. + if (core_if->adp.probe_timer_values[0]>=core_if->adp.probe_timer_values[1])
  51199. + diff = core_if->adp.probe_timer_values[0]-core_if->adp.probe_timer_values[1];
  51200. + else
  51201. + diff = core_if->adp.probe_timer_values[1]-core_if->adp.probe_timer_values[0];
  51202. + if(diff < 2) {
  51203. + return 0;
  51204. + } else {
  51205. + return 1;
  51206. + }
  51207. +}
  51208. +
  51209. +/**
  51210. + * This function handles ADP Probe Interrupts
  51211. + */
  51212. +static int32_t dwc_otg_adp_handle_prb_intr(dwc_otg_core_if_t * core_if,
  51213. + uint32_t val)
  51214. +{
  51215. + adpctl_data_t adpctl = {.d32 = 0 };
  51216. + gpwrdn_data_t gpwrdn, temp;
  51217. + adpctl.d32 = val;
  51218. +
  51219. + temp.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  51220. + core_if->adp.probe_counter++;
  51221. + core_if->adp.gpwrdn = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  51222. + if (adpctl.b.rtim == 0 && !temp.b.idsts){
  51223. + DWC_PRINTF("RTIM value is 0\n");
  51224. + goto exit;
  51225. + }
  51226. + if (set_timer_value(core_if, adpctl.b.rtim) &&
  51227. + core_if->adp.initial_probe) {
  51228. + core_if->adp.initial_probe = 0;
  51229. + dwc_otg_adp_probe_stop(core_if);
  51230. + gpwrdn.d32 = 0;
  51231. + gpwrdn.b.pmuactv = 1;
  51232. + gpwrdn.b.pmuintsel = 1;
  51233. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  51234. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  51235. +
  51236. + /* check which value is for device mode and which for Host mode */
  51237. + if (!temp.b.idsts) { /* considered host mode value is 0 */
  51238. + /*
  51239. + * Turn on VBUS after initial ADP probe.
  51240. + */
  51241. + core_if->op_state = A_HOST;
  51242. + dwc_otg_enable_global_interrupts(core_if);
  51243. + DWC_SPINUNLOCK(core_if->lock);
  51244. + cil_hcd_start(core_if);
  51245. + dwc_otg_adp_turnon_vbus(core_if);
  51246. + DWC_SPINLOCK(core_if->lock);
  51247. + } else {
  51248. + /*
  51249. + * Initiate SRP after initial ADP probe.
  51250. + */
  51251. + dwc_otg_enable_global_interrupts(core_if);
  51252. + dwc_otg_initiate_srp(core_if);
  51253. + }
  51254. + } else if (core_if->adp.probe_counter > 2){
  51255. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  51256. + if (compare_timer_values(core_if)) {
  51257. + DWC_PRINTF("Difference in timer values !!! \n");
  51258. +// core_if->adp.attached = DWC_OTG_ADP_ATTACHED;
  51259. + dwc_otg_adp_probe_stop(core_if);
  51260. +
  51261. + /* Power on the core */
  51262. + if (core_if->power_down == 2) {
  51263. + gpwrdn.b.pwrdnswtch = 1;
  51264. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  51265. + gpwrdn, 0, gpwrdn.d32);
  51266. + }
  51267. +
  51268. + /* check which value is for device mode and which for Host mode */
  51269. + if (!temp.b.idsts) { /* considered host mode value is 0 */
  51270. + /* Disable Interrupt from Power Down Logic */
  51271. + gpwrdn.d32 = 0;
  51272. + gpwrdn.b.pmuintsel = 1;
  51273. + gpwrdn.b.pmuactv = 1;
  51274. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  51275. + gpwrdn, gpwrdn.d32, 0);
  51276. +
  51277. + /*
  51278. + * Initialize the Core for Host mode.
  51279. + */
  51280. + core_if->op_state = A_HOST;
  51281. + dwc_otg_core_init(core_if);
  51282. + dwc_otg_enable_global_interrupts(core_if);
  51283. + cil_hcd_start(core_if);
  51284. + } else {
  51285. + gotgctl_data_t gotgctl;
  51286. + /* Mask SRP detected interrupt from Power Down Logic */
  51287. + gpwrdn.d32 = 0;
  51288. + gpwrdn.b.srp_det_msk = 1;
  51289. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  51290. + gpwrdn, gpwrdn.d32, 0);
  51291. +
  51292. + /* Disable Power Down Logic */
  51293. + gpwrdn.d32 = 0;
  51294. + gpwrdn.b.pmuintsel = 1;
  51295. + gpwrdn.b.pmuactv = 1;
  51296. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  51297. + gpwrdn, gpwrdn.d32, 0);
  51298. +
  51299. + /*
  51300. + * Initialize the Core for Device mode.
  51301. + */
  51302. + core_if->op_state = B_PERIPHERAL;
  51303. + dwc_otg_core_init(core_if);
  51304. + dwc_otg_enable_global_interrupts(core_if);
  51305. + cil_pcd_start(core_if);
  51306. +
  51307. + gotgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  51308. + if (!gotgctl.b.bsesvld) {
  51309. + dwc_otg_initiate_srp(core_if);
  51310. + }
  51311. + }
  51312. + }
  51313. + if (core_if->power_down == 2) {
  51314. + if (gpwrdn.b.bsessvld) {
  51315. + /* Mask SRP detected interrupt from Power Down Logic */
  51316. + gpwrdn.d32 = 0;
  51317. + gpwrdn.b.srp_det_msk = 1;
  51318. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  51319. +
  51320. + /* Disable Power Down Logic */
  51321. + gpwrdn.d32 = 0;
  51322. + gpwrdn.b.pmuactv = 1;
  51323. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  51324. +
  51325. + /*
  51326. + * Initialize the Core for Device mode.
  51327. + */
  51328. + core_if->op_state = B_PERIPHERAL;
  51329. + dwc_otg_core_init(core_if);
  51330. + dwc_otg_enable_global_interrupts(core_if);
  51331. + cil_pcd_start(core_if);
  51332. + }
  51333. + }
  51334. + }
  51335. +exit:
  51336. + /* Clear interrupt */
  51337. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  51338. + adpctl.b.adp_prb_int = 1;
  51339. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  51340. +
  51341. + return 0;
  51342. +}
  51343. +
  51344. +/**
  51345. + * This function hadles ADP Sense Interrupt
  51346. + */
  51347. +static int32_t dwc_otg_adp_handle_sns_intr(dwc_otg_core_if_t * core_if)
  51348. +{
  51349. + adpctl_data_t adpctl;
  51350. + /* Stop ADP Sense timer */
  51351. + DWC_TIMER_CANCEL(core_if->adp.sense_timer);
  51352. +
  51353. + /* Restart ADP Sense timer */
  51354. + dwc_otg_adp_sense_timer_start(core_if);
  51355. +
  51356. + /* Clear interrupt */
  51357. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  51358. + adpctl.b.adp_sns_int = 1;
  51359. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  51360. +
  51361. + return 0;
  51362. +}
  51363. +
  51364. +/**
  51365. + * This function handles ADP Probe Interrupts
  51366. + */
  51367. +static int32_t dwc_otg_adp_handle_prb_tmout_intr(dwc_otg_core_if_t * core_if,
  51368. + uint32_t val)
  51369. +{
  51370. + adpctl_data_t adpctl = {.d32 = 0 };
  51371. + adpctl.d32 = val;
  51372. + set_timer_value(core_if, adpctl.b.rtim);
  51373. +
  51374. + /* Clear interrupt */
  51375. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  51376. + adpctl.b.adp_tmout_int = 1;
  51377. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  51378. +
  51379. + return 0;
  51380. +}
  51381. +
  51382. +/**
  51383. + * ADP Interrupt handler.
  51384. + *
  51385. + */
  51386. +int32_t dwc_otg_adp_handle_intr(dwc_otg_core_if_t * core_if)
  51387. +{
  51388. + int retval = 0;
  51389. + adpctl_data_t adpctl = {.d32 = 0};
  51390. +
  51391. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  51392. + DWC_PRINTF("ADPCTL = %08x\n",adpctl.d32);
  51393. +
  51394. + if (adpctl.b.adp_sns_int & adpctl.b.adp_sns_int_msk) {
  51395. + DWC_PRINTF("ADP Sense interrupt\n");
  51396. + retval |= dwc_otg_adp_handle_sns_intr(core_if);
  51397. + }
  51398. + if (adpctl.b.adp_tmout_int & adpctl.b.adp_tmout_int_msk) {
  51399. + DWC_PRINTF("ADP timeout interrupt\n");
  51400. + retval |= dwc_otg_adp_handle_prb_tmout_intr(core_if, adpctl.d32);
  51401. + }
  51402. + if (adpctl.b.adp_prb_int & adpctl.b.adp_prb_int_msk) {
  51403. + DWC_PRINTF("ADP Probe interrupt\n");
  51404. + adpctl.b.adp_prb_int = 1;
  51405. + retval |= dwc_otg_adp_handle_prb_intr(core_if, adpctl.d32);
  51406. + }
  51407. +
  51408. +// dwc_otg_adp_modify_reg(core_if, adpctl.d32, 0);
  51409. + //dwc_otg_adp_write_reg(core_if, adpctl.d32);
  51410. + DWC_PRINTF("RETURN FROM ADP ISR\n");
  51411. +
  51412. + return retval;
  51413. +}
  51414. +
  51415. +/**
  51416. + *
  51417. + * @param core_if Programming view of DWC_otg controller.
  51418. + */
  51419. +int32_t dwc_otg_adp_handle_srp_intr(dwc_otg_core_if_t * core_if)
  51420. +{
  51421. +
  51422. +#ifndef DWC_HOST_ONLY
  51423. + hprt0_data_t hprt0;
  51424. + gpwrdn_data_t gpwrdn;
  51425. + DWC_DEBUGPL(DBG_ANY, "++ Power Down Logic Session Request Interrupt++\n");
  51426. +
  51427. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  51428. + /* check which value is for device mode and which for Host mode */
  51429. + if (!gpwrdn.b.idsts) { /* considered host mode value is 0 */
  51430. + DWC_PRINTF("SRP: Host mode\n");
  51431. +
  51432. + if (core_if->adp_enable) {
  51433. + dwc_otg_adp_probe_stop(core_if);
  51434. +
  51435. + /* Power on the core */
  51436. + if (core_if->power_down == 2) {
  51437. + gpwrdn.b.pwrdnswtch = 1;
  51438. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  51439. + gpwrdn, 0, gpwrdn.d32);
  51440. + }
  51441. +
  51442. + core_if->op_state = A_HOST;
  51443. + dwc_otg_core_init(core_if);
  51444. + dwc_otg_enable_global_interrupts(core_if);
  51445. + cil_hcd_start(core_if);
  51446. + }
  51447. +
  51448. + /* Turn on the port power bit. */
  51449. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  51450. + hprt0.b.prtpwr = 1;
  51451. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  51452. +
  51453. + /* Start the Connection timer. So a message can be displayed
  51454. + * if connect does not occur within 10 seconds. */
  51455. + cil_hcd_session_start(core_if);
  51456. + } else {
  51457. + DWC_PRINTF("SRP: Device mode %s\n", __FUNCTION__);
  51458. + if (core_if->adp_enable) {
  51459. + dwc_otg_adp_probe_stop(core_if);
  51460. +
  51461. + /* Power on the core */
  51462. + if (core_if->power_down == 2) {
  51463. + gpwrdn.b.pwrdnswtch = 1;
  51464. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  51465. + gpwrdn, 0, gpwrdn.d32);
  51466. + }
  51467. +
  51468. + gpwrdn.d32 = 0;
  51469. + gpwrdn.b.pmuactv = 0;
  51470. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0,
  51471. + gpwrdn.d32);
  51472. +
  51473. + core_if->op_state = B_PERIPHERAL;
  51474. + dwc_otg_core_init(core_if);
  51475. + dwc_otg_enable_global_interrupts(core_if);
  51476. + cil_pcd_start(core_if);
  51477. + }
  51478. + }
  51479. +#endif
  51480. + return 1;
  51481. +}
  51482. diff -Nur linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_adp.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_adp.h
  51483. --- linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_adp.h 1970-01-01 01:00:00.000000000 +0100
  51484. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_adp.h 2014-04-24 15:37:13.310990489 +0200
  51485. @@ -0,0 +1,80 @@
  51486. +/* ==========================================================================
  51487. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_adp.h $
  51488. + * $Revision: #7 $
  51489. + * $Date: 2011/10/24 $
  51490. + * $Change: 1871159 $
  51491. + *
  51492. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  51493. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  51494. + * otherwise expressly agreed to in writing between Synopsys and you.
  51495. + *
  51496. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  51497. + * any End User Software License Agreement or Agreement for Licensed Product
  51498. + * with Synopsys or any supplement thereto. You are permitted to use and
  51499. + * redistribute this Software in source and binary forms, with or without
  51500. + * modification, provided that redistributions of source code must retain this
  51501. + * notice. You may not view, use, disclose, copy or distribute this file or
  51502. + * any information contained herein except pursuant to this license grant from
  51503. + * Synopsys. If you do not agree with this notice, including the disclaimer
  51504. + * below, then you are not authorized to use the Software.
  51505. + *
  51506. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  51507. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  51508. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  51509. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  51510. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  51511. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  51512. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  51513. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  51514. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  51515. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  51516. + * DAMAGE.
  51517. + * ========================================================================== */
  51518. +
  51519. +#ifndef __DWC_OTG_ADP_H__
  51520. +#define __DWC_OTG_ADP_H__
  51521. +
  51522. +/**
  51523. + * @file
  51524. + *
  51525. + * This file contains the Attach Detect Protocol interfaces and defines
  51526. + * (functions) and structures for Linux.
  51527. + *
  51528. + */
  51529. +
  51530. +#define DWC_OTG_ADP_UNATTACHED 0
  51531. +#define DWC_OTG_ADP_ATTACHED 1
  51532. +#define DWC_OTG_ADP_UNKOWN 2
  51533. +
  51534. +typedef struct dwc_otg_adp {
  51535. + uint32_t adp_started;
  51536. + uint32_t initial_probe;
  51537. + int32_t probe_timer_values[2];
  51538. + uint32_t probe_enabled;
  51539. + uint32_t sense_enabled;
  51540. + dwc_timer_t *sense_timer;
  51541. + uint32_t sense_timer_started;
  51542. + dwc_timer_t *vbuson_timer;
  51543. + uint32_t vbuson_timer_started;
  51544. + uint32_t attached;
  51545. + uint32_t probe_counter;
  51546. + uint32_t gpwrdn;
  51547. +} dwc_otg_adp_t;
  51548. +
  51549. +/**
  51550. + * Attach Detect Protocol functions
  51551. + */
  51552. +
  51553. +extern void dwc_otg_adp_write_reg(dwc_otg_core_if_t * core_if, uint32_t value);
  51554. +extern uint32_t dwc_otg_adp_read_reg(dwc_otg_core_if_t * core_if);
  51555. +extern uint32_t dwc_otg_adp_probe_start(dwc_otg_core_if_t * core_if);
  51556. +extern uint32_t dwc_otg_adp_sense_start(dwc_otg_core_if_t * core_if);
  51557. +extern uint32_t dwc_otg_adp_probe_stop(dwc_otg_core_if_t * core_if);
  51558. +extern uint32_t dwc_otg_adp_sense_stop(dwc_otg_core_if_t * core_if);
  51559. +extern void dwc_otg_adp_start(dwc_otg_core_if_t * core_if, uint8_t is_host);
  51560. +extern void dwc_otg_adp_init(dwc_otg_core_if_t * core_if);
  51561. +extern void dwc_otg_adp_remove(dwc_otg_core_if_t * core_if);
  51562. +extern int32_t dwc_otg_adp_handle_intr(dwc_otg_core_if_t * core_if);
  51563. +extern int32_t dwc_otg_adp_handle_srp_intr(dwc_otg_core_if_t * core_if);
  51564. +
  51565. +#endif //__DWC_OTG_ADP_H__
  51566. diff -Nur linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_attr.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_attr.c
  51567. --- linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_attr.c 1970-01-01 01:00:00.000000000 +0100
  51568. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_attr.c 2014-04-24 15:37:13.310990489 +0200
  51569. @@ -0,0 +1,1210 @@
  51570. +/* ==========================================================================
  51571. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_attr.c $
  51572. + * $Revision: #44 $
  51573. + * $Date: 2010/11/29 $
  51574. + * $Change: 1636033 $
  51575. + *
  51576. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  51577. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  51578. + * otherwise expressly agreed to in writing between Synopsys and you.
  51579. + *
  51580. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  51581. + * any End User Software License Agreement or Agreement for Licensed Product
  51582. + * with Synopsys or any supplement thereto. You are permitted to use and
  51583. + * redistribute this Software in source and binary forms, with or without
  51584. + * modification, provided that redistributions of source code must retain this
  51585. + * notice. You may not view, use, disclose, copy or distribute this file or
  51586. + * any information contained herein except pursuant to this license grant from
  51587. + * Synopsys. If you do not agree with this notice, including the disclaimer
  51588. + * below, then you are not authorized to use the Software.
  51589. + *
  51590. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  51591. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  51592. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  51593. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  51594. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  51595. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  51596. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  51597. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  51598. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  51599. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  51600. + * DAMAGE.
  51601. + * ========================================================================== */
  51602. +
  51603. +/** @file
  51604. + *
  51605. + * The diagnostic interface will provide access to the controller for
  51606. + * bringing up the hardware and testing. The Linux driver attributes
  51607. + * feature will be used to provide the Linux Diagnostic
  51608. + * Interface. These attributes are accessed through sysfs.
  51609. + */
  51610. +
  51611. +/** @page "Linux Module Attributes"
  51612. + *
  51613. + * The Linux module attributes feature is used to provide the Linux
  51614. + * Diagnostic Interface. These attributes are accessed through sysfs.
  51615. + * The diagnostic interface will provide access to the controller for
  51616. + * bringing up the hardware and testing.
  51617. +
  51618. + The following table shows the attributes.
  51619. + <table>
  51620. + <tr>
  51621. + <td><b> Name</b></td>
  51622. + <td><b> Description</b></td>
  51623. + <td><b> Access</b></td>
  51624. + </tr>
  51625. +
  51626. + <tr>
  51627. + <td> mode </td>
  51628. + <td> Returns the current mode: 0 for device mode, 1 for host mode</td>
  51629. + <td> Read</td>
  51630. + </tr>
  51631. +
  51632. + <tr>
  51633. + <td> hnpcapable </td>
  51634. + <td> Gets or sets the "HNP-capable" bit in the Core USB Configuraton Register.
  51635. + Read returns the current value.</td>
  51636. + <td> Read/Write</td>
  51637. + </tr>
  51638. +
  51639. + <tr>
  51640. + <td> srpcapable </td>
  51641. + <td> Gets or sets the "SRP-capable" bit in the Core USB Configuraton Register.
  51642. + Read returns the current value.</td>
  51643. + <td> Read/Write</td>
  51644. + </tr>
  51645. +
  51646. + <tr>
  51647. + <td> hsic_connect </td>
  51648. + <td> Gets or sets the "HSIC-Connect" bit in the GLPMCFG Register.
  51649. + Read returns the current value.</td>
  51650. + <td> Read/Write</td>
  51651. + </tr>
  51652. +
  51653. + <tr>
  51654. + <td> inv_sel_hsic </td>
  51655. + <td> Gets or sets the "Invert Select HSIC" bit in the GLPMFG Register.
  51656. + Read returns the current value.</td>
  51657. + <td> Read/Write</td>
  51658. + </tr>
  51659. +
  51660. + <tr>
  51661. + <td> hnp </td>
  51662. + <td> Initiates the Host Negotiation Protocol. Read returns the status.</td>
  51663. + <td> Read/Write</td>
  51664. + </tr>
  51665. +
  51666. + <tr>
  51667. + <td> srp </td>
  51668. + <td> Initiates the Session Request Protocol. Read returns the status.</td>
  51669. + <td> Read/Write</td>
  51670. + </tr>
  51671. +
  51672. + <tr>
  51673. + <td> buspower </td>
  51674. + <td> Gets or sets the Power State of the bus (0 - Off or 1 - On)</td>
  51675. + <td> Read/Write</td>
  51676. + </tr>
  51677. +
  51678. + <tr>
  51679. + <td> bussuspend </td>
  51680. + <td> Suspends the USB bus.</td>
  51681. + <td> Read/Write</td>
  51682. + </tr>
  51683. +
  51684. + <tr>
  51685. + <td> busconnected </td>
  51686. + <td> Gets the connection status of the bus</td>
  51687. + <td> Read</td>
  51688. + </tr>
  51689. +
  51690. + <tr>
  51691. + <td> gotgctl </td>
  51692. + <td> Gets or sets the Core Control Status Register.</td>
  51693. + <td> Read/Write</td>
  51694. + </tr>
  51695. +
  51696. + <tr>
  51697. + <td> gusbcfg </td>
  51698. + <td> Gets or sets the Core USB Configuration Register</td>
  51699. + <td> Read/Write</td>
  51700. + </tr>
  51701. +
  51702. + <tr>
  51703. + <td> grxfsiz </td>
  51704. + <td> Gets or sets the Receive FIFO Size Register</td>
  51705. + <td> Read/Write</td>
  51706. + </tr>
  51707. +
  51708. + <tr>
  51709. + <td> gnptxfsiz </td>
  51710. + <td> Gets or sets the non-periodic Transmit Size Register</td>
  51711. + <td> Read/Write</td>
  51712. + </tr>
  51713. +
  51714. + <tr>
  51715. + <td> gpvndctl </td>
  51716. + <td> Gets or sets the PHY Vendor Control Register</td>
  51717. + <td> Read/Write</td>
  51718. + </tr>
  51719. +
  51720. + <tr>
  51721. + <td> ggpio </td>
  51722. + <td> Gets the value in the lower 16-bits of the General Purpose IO Register
  51723. + or sets the upper 16 bits.</td>
  51724. + <td> Read/Write</td>
  51725. + </tr>
  51726. +
  51727. + <tr>
  51728. + <td> guid </td>
  51729. + <td> Gets or sets the value of the User ID Register</td>
  51730. + <td> Read/Write</td>
  51731. + </tr>
  51732. +
  51733. + <tr>
  51734. + <td> gsnpsid </td>
  51735. + <td> Gets the value of the Synopsys ID Regester</td>
  51736. + <td> Read</td>
  51737. + </tr>
  51738. +
  51739. + <tr>
  51740. + <td> devspeed </td>
  51741. + <td> Gets or sets the device speed setting in the DCFG register</td>
  51742. + <td> Read/Write</td>
  51743. + </tr>
  51744. +
  51745. + <tr>
  51746. + <td> enumspeed </td>
  51747. + <td> Gets the device enumeration Speed.</td>
  51748. + <td> Read</td>
  51749. + </tr>
  51750. +
  51751. + <tr>
  51752. + <td> hptxfsiz </td>
  51753. + <td> Gets the value of the Host Periodic Transmit FIFO</td>
  51754. + <td> Read</td>
  51755. + </tr>
  51756. +
  51757. + <tr>
  51758. + <td> hprt0 </td>
  51759. + <td> Gets or sets the value in the Host Port Control and Status Register</td>
  51760. + <td> Read/Write</td>
  51761. + </tr>
  51762. +
  51763. + <tr>
  51764. + <td> regoffset </td>
  51765. + <td> Sets the register offset for the next Register Access</td>
  51766. + <td> Read/Write</td>
  51767. + </tr>
  51768. +
  51769. + <tr>
  51770. + <td> regvalue </td>
  51771. + <td> Gets or sets the value of the register at the offset in the regoffset attribute.</td>
  51772. + <td> Read/Write</td>
  51773. + </tr>
  51774. +
  51775. + <tr>
  51776. + <td> remote_wakeup </td>
  51777. + <td> On read, shows the status of Remote Wakeup. On write, initiates a remote
  51778. + wakeup of the host. When bit 0 is 1 and Remote Wakeup is enabled, the Remote
  51779. + Wakeup signalling bit in the Device Control Register is set for 1
  51780. + milli-second.</td>
  51781. + <td> Read/Write</td>
  51782. + </tr>
  51783. +
  51784. + <tr>
  51785. + <td> rem_wakeup_pwrdn </td>
  51786. + <td> On read, shows the status core - hibernated or not. On write, initiates
  51787. + a remote wakeup of the device from Hibernation. </td>
  51788. + <td> Read/Write</td>
  51789. + </tr>
  51790. +
  51791. + <tr>
  51792. + <td> mode_ch_tim_en </td>
  51793. + <td> This bit is used to enable or disable the host core to wait for 200 PHY
  51794. + clock cycles at the end of Resume to change the opmode signal to the PHY to 00
  51795. + after Suspend or LPM. </td>
  51796. + <td> Read/Write</td>
  51797. + </tr>
  51798. +
  51799. + <tr>
  51800. + <td> fr_interval </td>
  51801. + <td> On read, shows the value of HFIR Frame Interval. On write, dynamically
  51802. + reload HFIR register during runtime. The application can write a value to this
  51803. + register only after the Port Enable bit of the Host Port Control and Status
  51804. + register (HPRT.PrtEnaPort) has been set </td>
  51805. + <td> Read/Write</td>
  51806. + </tr>
  51807. +
  51808. + <tr>
  51809. + <td> disconnect_us </td>
  51810. + <td> On read, shows the status of disconnect_device_us. On write, sets disconnect_us
  51811. + which causes soft disconnect for 100us. Applicable only for device mode of operation.</td>
  51812. + <td> Read/Write</td>
  51813. + </tr>
  51814. +
  51815. + <tr>
  51816. + <td> regdump </td>
  51817. + <td> Dumps the contents of core registers.</td>
  51818. + <td> Read</td>
  51819. + </tr>
  51820. +
  51821. + <tr>
  51822. + <td> spramdump </td>
  51823. + <td> Dumps the contents of core registers.</td>
  51824. + <td> Read</td>
  51825. + </tr>
  51826. +
  51827. + <tr>
  51828. + <td> hcddump </td>
  51829. + <td> Dumps the current HCD state.</td>
  51830. + <td> Read</td>
  51831. + </tr>
  51832. +
  51833. + <tr>
  51834. + <td> hcd_frrem </td>
  51835. + <td> Shows the average value of the Frame Remaining
  51836. + field in the Host Frame Number/Frame Remaining register when an SOF interrupt
  51837. + occurs. This can be used to determine the average interrupt latency. Also
  51838. + shows the average Frame Remaining value for start_transfer and the "a" and
  51839. + "b" sample points. The "a" and "b" sample points may be used during debugging
  51840. + bto determine how long it takes to execute a section of the HCD code.</td>
  51841. + <td> Read</td>
  51842. + </tr>
  51843. +
  51844. + <tr>
  51845. + <td> rd_reg_test </td>
  51846. + <td> Displays the time required to read the GNPTXFSIZ register many times
  51847. + (the output shows the number of times the register is read).
  51848. + <td> Read</td>
  51849. + </tr>
  51850. +
  51851. + <tr>
  51852. + <td> wr_reg_test </td>
  51853. + <td> Displays the time required to write the GNPTXFSIZ register many times
  51854. + (the output shows the number of times the register is written).
  51855. + <td> Read</td>
  51856. + </tr>
  51857. +
  51858. + <tr>
  51859. + <td> lpm_response </td>
  51860. + <td> Gets or sets lpm_response mode. Applicable only in device mode.
  51861. + <td> Write</td>
  51862. + </tr>
  51863. +
  51864. + <tr>
  51865. + <td> sleep_status </td>
  51866. + <td> Shows sleep status of device.
  51867. + <td> Read</td>
  51868. + </tr>
  51869. +
  51870. + </table>
  51871. +
  51872. + Example usage:
  51873. + To get the current mode:
  51874. + cat /sys/devices/lm0/mode
  51875. +
  51876. + To power down the USB:
  51877. + echo 0 > /sys/devices/lm0/buspower
  51878. + */
  51879. +
  51880. +#include "dwc_otg_os_dep.h"
  51881. +#include "dwc_os.h"
  51882. +#include "dwc_otg_driver.h"
  51883. +#include "dwc_otg_attr.h"
  51884. +#include "dwc_otg_core_if.h"
  51885. +#include "dwc_otg_pcd_if.h"
  51886. +#include "dwc_otg_hcd_if.h"
  51887. +
  51888. +/*
  51889. + * MACROs for defining sysfs attribute
  51890. + */
  51891. +#ifdef LM_INTERFACE
  51892. +
  51893. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  51894. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  51895. +{ \
  51896. + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
  51897. + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
  51898. + uint32_t val; \
  51899. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  51900. + return sprintf (buf, "%s = 0x%x\n", _string_, val); \
  51901. +}
  51902. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
  51903. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  51904. + const char *buf, size_t count) \
  51905. +{ \
  51906. + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
  51907. + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
  51908. + uint32_t set = simple_strtoul(buf, NULL, 16); \
  51909. + dwc_otg_set_##_otg_attr_name_(otg_dev->core_if, set);\
  51910. + return count; \
  51911. +}
  51912. +
  51913. +#elif defined(PCI_INTERFACE)
  51914. +
  51915. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  51916. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  51917. +{ \
  51918. + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
  51919. + uint32_t val; \
  51920. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  51921. + return sprintf (buf, "%s = 0x%x\n", _string_, val); \
  51922. +}
  51923. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
  51924. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  51925. + const char *buf, size_t count) \
  51926. +{ \
  51927. + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
  51928. + uint32_t set = simple_strtoul(buf, NULL, 16); \
  51929. + dwc_otg_set_##_otg_attr_name_(otg_dev->core_if, set);\
  51930. + return count; \
  51931. +}
  51932. +
  51933. +#elif defined(PLATFORM_INTERFACE)
  51934. +
  51935. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  51936. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  51937. +{ \
  51938. + struct platform_device *platform_dev = \
  51939. + container_of(_dev, struct platform_device, dev); \
  51940. + dwc_otg_device_t *otg_dev = platform_get_drvdata(platform_dev); \
  51941. + uint32_t val; \
  51942. + DWC_PRINTF("%s(%p) -> platform_dev %p, otg_dev %p\n", \
  51943. + __func__, _dev, platform_dev, otg_dev); \
  51944. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  51945. + return sprintf (buf, "%s = 0x%x\n", _string_, val); \
  51946. +}
  51947. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
  51948. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  51949. + const char *buf, size_t count) \
  51950. +{ \
  51951. + struct platform_device *platform_dev = container_of(_dev, struct platform_device, dev); \
  51952. + dwc_otg_device_t *otg_dev = platform_get_drvdata(platform_dev); \
  51953. + uint32_t set = simple_strtoul(buf, NULL, 16); \
  51954. + dwc_otg_set_##_otg_attr_name_(otg_dev->core_if, set);\
  51955. + return count; \
  51956. +}
  51957. +#endif
  51958. +
  51959. +/*
  51960. + * MACROs for defining sysfs attribute for 32-bit registers
  51961. + */
  51962. +#ifdef LM_INTERFACE
  51963. +#define DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  51964. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  51965. +{ \
  51966. + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
  51967. + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
  51968. + uint32_t val; \
  51969. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  51970. + return sprintf (buf, "%s = 0x%08x\n", _string_, val); \
  51971. +}
  51972. +#define DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
  51973. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  51974. + const char *buf, size_t count) \
  51975. +{ \
  51976. + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
  51977. + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
  51978. + uint32_t val = simple_strtoul(buf, NULL, 16); \
  51979. + dwc_otg_set_##_otg_attr_name_ (otg_dev->core_if, val); \
  51980. + return count; \
  51981. +}
  51982. +#elif defined(PCI_INTERFACE)
  51983. +#define DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  51984. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  51985. +{ \
  51986. + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
  51987. + uint32_t val; \
  51988. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  51989. + return sprintf (buf, "%s = 0x%08x\n", _string_, val); \
  51990. +}
  51991. +#define DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
  51992. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  51993. + const char *buf, size_t count) \
  51994. +{ \
  51995. + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
  51996. + uint32_t val = simple_strtoul(buf, NULL, 16); \
  51997. + dwc_otg_set_##_otg_attr_name_ (otg_dev->core_if, val); \
  51998. + return count; \
  51999. +}
  52000. +
  52001. +#elif defined(PLATFORM_INTERFACE)
  52002. +#include "dwc_otg_dbg.h"
  52003. +#define DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  52004. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  52005. +{ \
  52006. + struct platform_device *platform_dev = container_of(_dev, struct platform_device, dev); \
  52007. + dwc_otg_device_t *otg_dev = platform_get_drvdata(platform_dev); \
  52008. + uint32_t val; \
  52009. + DWC_PRINTF("%s(%p) -> platform_dev %p, otg_dev %p\n", \
  52010. + __func__, _dev, platform_dev, otg_dev); \
  52011. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  52012. + return sprintf (buf, "%s = 0x%08x\n", _string_, val); \
  52013. +}
  52014. +#define DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
  52015. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  52016. + const char *buf, size_t count) \
  52017. +{ \
  52018. + struct platform_device *platform_dev = container_of(_dev, struct platform_device, dev); \
  52019. + dwc_otg_device_t *otg_dev = platform_get_drvdata(platform_dev); \
  52020. + uint32_t val = simple_strtoul(buf, NULL, 16); \
  52021. + dwc_otg_set_##_otg_attr_name_ (otg_dev->core_if, val); \
  52022. + return count; \
  52023. +}
  52024. +
  52025. +#endif
  52026. +
  52027. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_RW(_otg_attr_name_,_string_) \
  52028. +DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  52029. +DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
  52030. +DEVICE_ATTR(_otg_attr_name_,0644,_otg_attr_name_##_show,_otg_attr_name_##_store);
  52031. +
  52032. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_RO(_otg_attr_name_,_string_) \
  52033. +DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  52034. +DEVICE_ATTR(_otg_attr_name_,0444,_otg_attr_name_##_show,NULL);
  52035. +
  52036. +#define DWC_OTG_DEVICE_ATTR_REG32_RW(_otg_attr_name_,_addr_,_string_) \
  52037. +DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  52038. +DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
  52039. +DEVICE_ATTR(_otg_attr_name_,0644,_otg_attr_name_##_show,_otg_attr_name_##_store);
  52040. +
  52041. +#define DWC_OTG_DEVICE_ATTR_REG32_RO(_otg_attr_name_,_addr_,_string_) \
  52042. +DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  52043. +DEVICE_ATTR(_otg_attr_name_,0444,_otg_attr_name_##_show,NULL);
  52044. +
  52045. +/** @name Functions for Show/Store of Attributes */
  52046. +/**@{*/
  52047. +
  52048. +/**
  52049. + * Helper function returning the otg_device structure of the given device
  52050. + */
  52051. +static dwc_otg_device_t *dwc_otg_drvdev(struct device *_dev)
  52052. +{
  52053. + dwc_otg_device_t *otg_dev;
  52054. + DWC_OTG_GETDRVDEV(otg_dev, _dev);
  52055. + return otg_dev;
  52056. +}
  52057. +
  52058. +/**
  52059. + * Show the register offset of the Register Access.
  52060. + */
  52061. +static ssize_t regoffset_show(struct device *_dev,
  52062. + struct device_attribute *attr, char *buf)
  52063. +{
  52064. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52065. + return snprintf(buf, sizeof("0xFFFFFFFF\n") + 1, "0x%08x\n",
  52066. + otg_dev->os_dep.reg_offset);
  52067. +}
  52068. +
  52069. +/**
  52070. + * Set the register offset for the next Register Access Read/Write
  52071. + */
  52072. +static ssize_t regoffset_store(struct device *_dev,
  52073. + struct device_attribute *attr,
  52074. + const char *buf, size_t count)
  52075. +{
  52076. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52077. + uint32_t offset = simple_strtoul(buf, NULL, 16);
  52078. +#if defined(LM_INTERFACE) || defined(PLATFORM_INTERFACE)
  52079. + if (offset < SZ_256K) {
  52080. +#elif defined(PCI_INTERFACE)
  52081. + if (offset < 0x00040000) {
  52082. +#endif
  52083. + otg_dev->os_dep.reg_offset = offset;
  52084. + } else {
  52085. + dev_err(_dev, "invalid offset\n");
  52086. + }
  52087. +
  52088. + return count;
  52089. +}
  52090. +
  52091. +DEVICE_ATTR(regoffset, S_IRUGO | S_IWUSR, regoffset_show, regoffset_store);
  52092. +
  52093. +/**
  52094. + * Show the value of the register at the offset in the reg_offset
  52095. + * attribute.
  52096. + */
  52097. +static ssize_t regvalue_show(struct device *_dev,
  52098. + struct device_attribute *attr, char *buf)
  52099. +{
  52100. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52101. + uint32_t val;
  52102. + volatile uint32_t *addr;
  52103. +
  52104. + if (otg_dev->os_dep.reg_offset != 0xFFFFFFFF && 0 != otg_dev->os_dep.base) {
  52105. + /* Calculate the address */
  52106. + addr = (uint32_t *) (otg_dev->os_dep.reg_offset +
  52107. + (uint8_t *) otg_dev->os_dep.base);
  52108. + val = DWC_READ_REG32(addr);
  52109. + return snprintf(buf,
  52110. + sizeof("Reg@0xFFFFFFFF = 0xFFFFFFFF\n") + 1,
  52111. + "Reg@0x%06x = 0x%08x\n", otg_dev->os_dep.reg_offset,
  52112. + val);
  52113. + } else {
  52114. + dev_err(_dev, "Invalid offset (0x%0x)\n", otg_dev->os_dep.reg_offset);
  52115. + return sprintf(buf, "invalid offset\n");
  52116. + }
  52117. +}
  52118. +
  52119. +/**
  52120. + * Store the value in the register at the offset in the reg_offset
  52121. + * attribute.
  52122. + *
  52123. + */
  52124. +static ssize_t regvalue_store(struct device *_dev,
  52125. + struct device_attribute *attr,
  52126. + const char *buf, size_t count)
  52127. +{
  52128. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52129. + volatile uint32_t *addr;
  52130. + uint32_t val = simple_strtoul(buf, NULL, 16);
  52131. + //dev_dbg(_dev, "Offset=0x%08x Val=0x%08x\n", otg_dev->reg_offset, val);
  52132. + if (otg_dev->os_dep.reg_offset != 0xFFFFFFFF && 0 != otg_dev->os_dep.base) {
  52133. + /* Calculate the address */
  52134. + addr = (uint32_t *) (otg_dev->os_dep.reg_offset +
  52135. + (uint8_t *) otg_dev->os_dep.base);
  52136. + DWC_WRITE_REG32(addr, val);
  52137. + } else {
  52138. + dev_err(_dev, "Invalid Register Offset (0x%08x)\n",
  52139. + otg_dev->os_dep.reg_offset);
  52140. + }
  52141. + return count;
  52142. +}
  52143. +
  52144. +DEVICE_ATTR(regvalue, S_IRUGO | S_IWUSR, regvalue_show, regvalue_store);
  52145. +
  52146. +/*
  52147. + * Attributes
  52148. + */
  52149. +DWC_OTG_DEVICE_ATTR_BITFIELD_RO(mode, "Mode");
  52150. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(hnpcapable, "HNPCapable");
  52151. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(srpcapable, "SRPCapable");
  52152. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(hsic_connect, "HSIC Connect");
  52153. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(inv_sel_hsic, "Invert Select HSIC");
  52154. +
  52155. +//DWC_OTG_DEVICE_ATTR_BITFIELD_RW(buspower,&(otg_dev->core_if->core_global_regs->gotgctl),(1<<8),8,"Mode");
  52156. +//DWC_OTG_DEVICE_ATTR_BITFIELD_RW(bussuspend,&(otg_dev->core_if->core_global_regs->gotgctl),(1<<8),8,"Mode");
  52157. +DWC_OTG_DEVICE_ATTR_BITFIELD_RO(busconnected, "Bus Connected");
  52158. +
  52159. +DWC_OTG_DEVICE_ATTR_REG32_RW(gotgctl, 0, "GOTGCTL");
  52160. +DWC_OTG_DEVICE_ATTR_REG32_RW(gusbcfg,
  52161. + &(otg_dev->core_if->core_global_regs->gusbcfg),
  52162. + "GUSBCFG");
  52163. +DWC_OTG_DEVICE_ATTR_REG32_RW(grxfsiz,
  52164. + &(otg_dev->core_if->core_global_regs->grxfsiz),
  52165. + "GRXFSIZ");
  52166. +DWC_OTG_DEVICE_ATTR_REG32_RW(gnptxfsiz,
  52167. + &(otg_dev->core_if->core_global_regs->gnptxfsiz),
  52168. + "GNPTXFSIZ");
  52169. +DWC_OTG_DEVICE_ATTR_REG32_RW(gpvndctl,
  52170. + &(otg_dev->core_if->core_global_regs->gpvndctl),
  52171. + "GPVNDCTL");
  52172. +DWC_OTG_DEVICE_ATTR_REG32_RW(ggpio,
  52173. + &(otg_dev->core_if->core_global_regs->ggpio),
  52174. + "GGPIO");
  52175. +DWC_OTG_DEVICE_ATTR_REG32_RW(guid, &(otg_dev->core_if->core_global_regs->guid),
  52176. + "GUID");
  52177. +DWC_OTG_DEVICE_ATTR_REG32_RO(gsnpsid,
  52178. + &(otg_dev->core_if->core_global_regs->gsnpsid),
  52179. + "GSNPSID");
  52180. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(devspeed, "Device Speed");
  52181. +DWC_OTG_DEVICE_ATTR_BITFIELD_RO(enumspeed, "Device Enumeration Speed");
  52182. +
  52183. +DWC_OTG_DEVICE_ATTR_REG32_RO(hptxfsiz,
  52184. + &(otg_dev->core_if->core_global_regs->hptxfsiz),
  52185. + "HPTXFSIZ");
  52186. +DWC_OTG_DEVICE_ATTR_REG32_RW(hprt0, otg_dev->core_if->host_if->hprt0, "HPRT0");
  52187. +
  52188. +/**
  52189. + * @todo Add code to initiate the HNP.
  52190. + */
  52191. +/**
  52192. + * Show the HNP status bit
  52193. + */
  52194. +static ssize_t hnp_show(struct device *_dev,
  52195. + struct device_attribute *attr, char *buf)
  52196. +{
  52197. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52198. + return sprintf(buf, "HstNegScs = 0x%x\n",
  52199. + dwc_otg_get_hnpstatus(otg_dev->core_if));
  52200. +}
  52201. +
  52202. +/**
  52203. + * Set the HNP Request bit
  52204. + */
  52205. +static ssize_t hnp_store(struct device *_dev,
  52206. + struct device_attribute *attr,
  52207. + const char *buf, size_t count)
  52208. +{
  52209. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52210. + uint32_t in = simple_strtoul(buf, NULL, 16);
  52211. + dwc_otg_set_hnpreq(otg_dev->core_if, in);
  52212. + return count;
  52213. +}
  52214. +
  52215. +DEVICE_ATTR(hnp, 0644, hnp_show, hnp_store);
  52216. +
  52217. +/**
  52218. + * @todo Add code to initiate the SRP.
  52219. + */
  52220. +/**
  52221. + * Show the SRP status bit
  52222. + */
  52223. +static ssize_t srp_show(struct device *_dev,
  52224. + struct device_attribute *attr, char *buf)
  52225. +{
  52226. +#ifndef DWC_HOST_ONLY
  52227. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52228. + return sprintf(buf, "SesReqScs = 0x%x\n",
  52229. + dwc_otg_get_srpstatus(otg_dev->core_if));
  52230. +#else
  52231. + return sprintf(buf, "Host Only Mode!\n");
  52232. +#endif
  52233. +}
  52234. +
  52235. +/**
  52236. + * Set the SRP Request bit
  52237. + */
  52238. +static ssize_t srp_store(struct device *_dev,
  52239. + struct device_attribute *attr,
  52240. + const char *buf, size_t count)
  52241. +{
  52242. +#ifndef DWC_HOST_ONLY
  52243. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52244. + dwc_otg_pcd_initiate_srp(otg_dev->pcd);
  52245. +#endif
  52246. + return count;
  52247. +}
  52248. +
  52249. +DEVICE_ATTR(srp, 0644, srp_show, srp_store);
  52250. +
  52251. +/**
  52252. + * @todo Need to do more for power on/off?
  52253. + */
  52254. +/**
  52255. + * Show the Bus Power status
  52256. + */
  52257. +static ssize_t buspower_show(struct device *_dev,
  52258. + struct device_attribute *attr, char *buf)
  52259. +{
  52260. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52261. + return sprintf(buf, "Bus Power = 0x%x\n",
  52262. + dwc_otg_get_prtpower(otg_dev->core_if));
  52263. +}
  52264. +
  52265. +/**
  52266. + * Set the Bus Power status
  52267. + */
  52268. +static ssize_t buspower_store(struct device *_dev,
  52269. + struct device_attribute *attr,
  52270. + const char *buf, size_t count)
  52271. +{
  52272. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52273. + uint32_t on = simple_strtoul(buf, NULL, 16);
  52274. + dwc_otg_set_prtpower(otg_dev->core_if, on);
  52275. + return count;
  52276. +}
  52277. +
  52278. +DEVICE_ATTR(buspower, 0644, buspower_show, buspower_store);
  52279. +
  52280. +/**
  52281. + * @todo Need to do more for suspend?
  52282. + */
  52283. +/**
  52284. + * Show the Bus Suspend status
  52285. + */
  52286. +static ssize_t bussuspend_show(struct device *_dev,
  52287. + struct device_attribute *attr, char *buf)
  52288. +{
  52289. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52290. + return sprintf(buf, "Bus Suspend = 0x%x\n",
  52291. + dwc_otg_get_prtsuspend(otg_dev->core_if));
  52292. +}
  52293. +
  52294. +/**
  52295. + * Set the Bus Suspend status
  52296. + */
  52297. +static ssize_t bussuspend_store(struct device *_dev,
  52298. + struct device_attribute *attr,
  52299. + const char *buf, size_t count)
  52300. +{
  52301. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52302. + uint32_t in = simple_strtoul(buf, NULL, 16);
  52303. + dwc_otg_set_prtsuspend(otg_dev->core_if, in);
  52304. + return count;
  52305. +}
  52306. +
  52307. +DEVICE_ATTR(bussuspend, 0644, bussuspend_show, bussuspend_store);
  52308. +
  52309. +/**
  52310. + * Show the Mode Change Ready Timer status
  52311. + */
  52312. +static ssize_t mode_ch_tim_en_show(struct device *_dev,
  52313. + struct device_attribute *attr, char *buf)
  52314. +{
  52315. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52316. + return sprintf(buf, "Mode Change Ready Timer Enable = 0x%x\n",
  52317. + dwc_otg_get_mode_ch_tim(otg_dev->core_if));
  52318. +}
  52319. +
  52320. +/**
  52321. + * Set the Mode Change Ready Timer status
  52322. + */
  52323. +static ssize_t mode_ch_tim_en_store(struct device *_dev,
  52324. + struct device_attribute *attr,
  52325. + const char *buf, size_t count)
  52326. +{
  52327. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52328. + uint32_t in = simple_strtoul(buf, NULL, 16);
  52329. + dwc_otg_set_mode_ch_tim(otg_dev->core_if, in);
  52330. + return count;
  52331. +}
  52332. +
  52333. +DEVICE_ATTR(mode_ch_tim_en, 0644, mode_ch_tim_en_show, mode_ch_tim_en_store);
  52334. +
  52335. +/**
  52336. + * Show the value of HFIR Frame Interval bitfield
  52337. + */
  52338. +static ssize_t fr_interval_show(struct device *_dev,
  52339. + struct device_attribute *attr, char *buf)
  52340. +{
  52341. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52342. + return sprintf(buf, "Frame Interval = 0x%x\n",
  52343. + dwc_otg_get_fr_interval(otg_dev->core_if));
  52344. +}
  52345. +
  52346. +/**
  52347. + * Set the HFIR Frame Interval value
  52348. + */
  52349. +static ssize_t fr_interval_store(struct device *_dev,
  52350. + struct device_attribute *attr,
  52351. + const char *buf, size_t count)
  52352. +{
  52353. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52354. + uint32_t in = simple_strtoul(buf, NULL, 10);
  52355. + dwc_otg_set_fr_interval(otg_dev->core_if, in);
  52356. + return count;
  52357. +}
  52358. +
  52359. +DEVICE_ATTR(fr_interval, 0644, fr_interval_show, fr_interval_store);
  52360. +
  52361. +/**
  52362. + * Show the status of Remote Wakeup.
  52363. + */
  52364. +static ssize_t remote_wakeup_show(struct device *_dev,
  52365. + struct device_attribute *attr, char *buf)
  52366. +{
  52367. +#ifndef DWC_HOST_ONLY
  52368. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52369. +
  52370. + return sprintf(buf,
  52371. + "Remote Wakeup Sig = %d Enabled = %d LPM Remote Wakeup = %d\n",
  52372. + dwc_otg_get_remotewakesig(otg_dev->core_if),
  52373. + dwc_otg_pcd_get_rmwkup_enable(otg_dev->pcd),
  52374. + dwc_otg_get_lpm_remotewakeenabled(otg_dev->core_if));
  52375. +#else
  52376. + return sprintf(buf, "Host Only Mode!\n");
  52377. +#endif /* DWC_HOST_ONLY */
  52378. +}
  52379. +
  52380. +/**
  52381. + * Initiate a remote wakeup of the host. The Device control register
  52382. + * Remote Wakeup Signal bit is written if the PCD Remote wakeup enable
  52383. + * flag is set.
  52384. + *
  52385. + */
  52386. +static ssize_t remote_wakeup_store(struct device *_dev,
  52387. + struct device_attribute *attr,
  52388. + const char *buf, size_t count)
  52389. +{
  52390. +#ifndef DWC_HOST_ONLY
  52391. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52392. + uint32_t val = simple_strtoul(buf, NULL, 16);
  52393. +
  52394. + if (val & 1) {
  52395. + dwc_otg_pcd_remote_wakeup(otg_dev->pcd, 1);
  52396. + } else {
  52397. + dwc_otg_pcd_remote_wakeup(otg_dev->pcd, 0);
  52398. + }
  52399. +#endif /* DWC_HOST_ONLY */
  52400. + return count;
  52401. +}
  52402. +
  52403. +DEVICE_ATTR(remote_wakeup, S_IRUGO | S_IWUSR, remote_wakeup_show,
  52404. + remote_wakeup_store);
  52405. +
  52406. +/**
  52407. + * Show the whether core is hibernated or not.
  52408. + */
  52409. +static ssize_t rem_wakeup_pwrdn_show(struct device *_dev,
  52410. + struct device_attribute *attr, char *buf)
  52411. +{
  52412. +#ifndef DWC_HOST_ONLY
  52413. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52414. +
  52415. + if (dwc_otg_get_core_state(otg_dev->core_if)) {
  52416. + DWC_PRINTF("Core is in hibernation\n");
  52417. + } else {
  52418. + DWC_PRINTF("Core is not in hibernation\n");
  52419. + }
  52420. +#endif /* DWC_HOST_ONLY */
  52421. + return 0;
  52422. +}
  52423. +
  52424. +extern int dwc_otg_device_hibernation_restore(dwc_otg_core_if_t * core_if,
  52425. + int rem_wakeup, int reset);
  52426. +
  52427. +/**
  52428. + * Initiate a remote wakeup of the device to exit from hibernation.
  52429. + */
  52430. +static ssize_t rem_wakeup_pwrdn_store(struct device *_dev,
  52431. + struct device_attribute *attr,
  52432. + const char *buf, size_t count)
  52433. +{
  52434. +#ifndef DWC_HOST_ONLY
  52435. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52436. + dwc_otg_device_hibernation_restore(otg_dev->core_if, 1, 0);
  52437. +#endif
  52438. + return count;
  52439. +}
  52440. +
  52441. +DEVICE_ATTR(rem_wakeup_pwrdn, S_IRUGO | S_IWUSR, rem_wakeup_pwrdn_show,
  52442. + rem_wakeup_pwrdn_store);
  52443. +
  52444. +static ssize_t disconnect_us(struct device *_dev,
  52445. + struct device_attribute *attr,
  52446. + const char *buf, size_t count)
  52447. +{
  52448. +
  52449. +#ifndef DWC_HOST_ONLY
  52450. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52451. + uint32_t val = simple_strtoul(buf, NULL, 16);
  52452. + DWC_PRINTF("The Passed value is %04x\n", val);
  52453. +
  52454. + dwc_otg_pcd_disconnect_us(otg_dev->pcd, 50);
  52455. +
  52456. +#endif /* DWC_HOST_ONLY */
  52457. + return count;
  52458. +}
  52459. +
  52460. +DEVICE_ATTR(disconnect_us, S_IWUSR, 0, disconnect_us);
  52461. +
  52462. +/**
  52463. + * Dump global registers and either host or device registers (depending on the
  52464. + * current mode of the core).
  52465. + */
  52466. +static ssize_t regdump_show(struct device *_dev,
  52467. + struct device_attribute *attr, char *buf)
  52468. +{
  52469. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52470. +
  52471. + dwc_otg_dump_global_registers(otg_dev->core_if);
  52472. + if (dwc_otg_is_host_mode(otg_dev->core_if)) {
  52473. + dwc_otg_dump_host_registers(otg_dev->core_if);
  52474. + } else {
  52475. + dwc_otg_dump_dev_registers(otg_dev->core_if);
  52476. +
  52477. + }
  52478. + return sprintf(buf, "Register Dump\n");
  52479. +}
  52480. +
  52481. +DEVICE_ATTR(regdump, S_IRUGO, regdump_show, 0);
  52482. +
  52483. +/**
  52484. + * Dump global registers and either host or device registers (depending on the
  52485. + * current mode of the core).
  52486. + */
  52487. +static ssize_t spramdump_show(struct device *_dev,
  52488. + struct device_attribute *attr, char *buf)
  52489. +{
  52490. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52491. +
  52492. + //dwc_otg_dump_spram(otg_dev->core_if);
  52493. +
  52494. + return sprintf(buf, "SPRAM Dump\n");
  52495. +}
  52496. +
  52497. +DEVICE_ATTR(spramdump, S_IRUGO, spramdump_show, 0);
  52498. +
  52499. +/**
  52500. + * Dump the current hcd state.
  52501. + */
  52502. +static ssize_t hcddump_show(struct device *_dev,
  52503. + struct device_attribute *attr, char *buf)
  52504. +{
  52505. +#ifndef DWC_DEVICE_ONLY
  52506. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52507. + dwc_otg_hcd_dump_state(otg_dev->hcd);
  52508. +#endif /* DWC_DEVICE_ONLY */
  52509. + return sprintf(buf, "HCD Dump\n");
  52510. +}
  52511. +
  52512. +DEVICE_ATTR(hcddump, S_IRUGO, hcddump_show, 0);
  52513. +
  52514. +/**
  52515. + * Dump the average frame remaining at SOF. This can be used to
  52516. + * determine average interrupt latency. Frame remaining is also shown for
  52517. + * start transfer and two additional sample points.
  52518. + */
  52519. +static ssize_t hcd_frrem_show(struct device *_dev,
  52520. + struct device_attribute *attr, char *buf)
  52521. +{
  52522. +#ifndef DWC_DEVICE_ONLY
  52523. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52524. +
  52525. + dwc_otg_hcd_dump_frrem(otg_dev->hcd);
  52526. +#endif /* DWC_DEVICE_ONLY */
  52527. + return sprintf(buf, "HCD Dump Frame Remaining\n");
  52528. +}
  52529. +
  52530. +DEVICE_ATTR(hcd_frrem, S_IRUGO, hcd_frrem_show, 0);
  52531. +
  52532. +/**
  52533. + * Displays the time required to read the GNPTXFSIZ register many times (the
  52534. + * output shows the number of times the register is read).
  52535. + */
  52536. +#define RW_REG_COUNT 10000000
  52537. +#define MSEC_PER_JIFFIE 1000/HZ
  52538. +static ssize_t rd_reg_test_show(struct device *_dev,
  52539. + struct device_attribute *attr, char *buf)
  52540. +{
  52541. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52542. + int i;
  52543. + int time;
  52544. + int start_jiffies;
  52545. +
  52546. + printk("HZ %d, MSEC_PER_JIFFIE %d, loops_per_jiffy %lu\n",
  52547. + HZ, MSEC_PER_JIFFIE, loops_per_jiffy);
  52548. + start_jiffies = jiffies;
  52549. + for (i = 0; i < RW_REG_COUNT; i++) {
  52550. + dwc_otg_get_gnptxfsiz(otg_dev->core_if);
  52551. + }
  52552. + time = jiffies - start_jiffies;
  52553. + return sprintf(buf,
  52554. + "Time to read GNPTXFSIZ reg %d times: %d msecs (%d jiffies)\n",
  52555. + RW_REG_COUNT, time * MSEC_PER_JIFFIE, time);
  52556. +}
  52557. +
  52558. +DEVICE_ATTR(rd_reg_test, S_IRUGO, rd_reg_test_show, 0);
  52559. +
  52560. +/**
  52561. + * Displays the time required to write the GNPTXFSIZ register many times (the
  52562. + * output shows the number of times the register is written).
  52563. + */
  52564. +static ssize_t wr_reg_test_show(struct device *_dev,
  52565. + struct device_attribute *attr, char *buf)
  52566. +{
  52567. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52568. + uint32_t reg_val;
  52569. + int i;
  52570. + int time;
  52571. + int start_jiffies;
  52572. +
  52573. + printk("HZ %d, MSEC_PER_JIFFIE %d, loops_per_jiffy %lu\n",
  52574. + HZ, MSEC_PER_JIFFIE, loops_per_jiffy);
  52575. + reg_val = dwc_otg_get_gnptxfsiz(otg_dev->core_if);
  52576. + start_jiffies = jiffies;
  52577. + for (i = 0; i < RW_REG_COUNT; i++) {
  52578. + dwc_otg_set_gnptxfsiz(otg_dev->core_if, reg_val);
  52579. + }
  52580. + time = jiffies - start_jiffies;
  52581. + return sprintf(buf,
  52582. + "Time to write GNPTXFSIZ reg %d times: %d msecs (%d jiffies)\n",
  52583. + RW_REG_COUNT, time * MSEC_PER_JIFFIE, time);
  52584. +}
  52585. +
  52586. +DEVICE_ATTR(wr_reg_test, S_IRUGO, wr_reg_test_show, 0);
  52587. +
  52588. +#ifdef CONFIG_USB_DWC_OTG_LPM
  52589. +
  52590. +/**
  52591. +* Show the lpm_response attribute.
  52592. +*/
  52593. +static ssize_t lpmresp_show(struct device *_dev,
  52594. + struct device_attribute *attr, char *buf)
  52595. +{
  52596. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52597. +
  52598. + if (!dwc_otg_get_param_lpm_enable(otg_dev->core_if))
  52599. + return sprintf(buf, "** LPM is DISABLED **\n");
  52600. +
  52601. + if (!dwc_otg_is_device_mode(otg_dev->core_if)) {
  52602. + return sprintf(buf, "** Current mode is not device mode\n");
  52603. + }
  52604. + return sprintf(buf, "lpm_response = %d\n",
  52605. + dwc_otg_get_lpmresponse(otg_dev->core_if));
  52606. +}
  52607. +
  52608. +/**
  52609. +* Store the lpm_response attribute.
  52610. +*/
  52611. +static ssize_t lpmresp_store(struct device *_dev,
  52612. + struct device_attribute *attr,
  52613. + const char *buf, size_t count)
  52614. +{
  52615. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52616. + uint32_t val = simple_strtoul(buf, NULL, 16);
  52617. +
  52618. + if (!dwc_otg_get_param_lpm_enable(otg_dev->core_if)) {
  52619. + return 0;
  52620. + }
  52621. +
  52622. + if (!dwc_otg_is_device_mode(otg_dev->core_if)) {
  52623. + return 0;
  52624. + }
  52625. +
  52626. + dwc_otg_set_lpmresponse(otg_dev->core_if, val);
  52627. + return count;
  52628. +}
  52629. +
  52630. +DEVICE_ATTR(lpm_response, S_IRUGO | S_IWUSR, lpmresp_show, lpmresp_store);
  52631. +
  52632. +/**
  52633. +* Show the sleep_status attribute.
  52634. +*/
  52635. +static ssize_t sleepstatus_show(struct device *_dev,
  52636. + struct device_attribute *attr, char *buf)
  52637. +{
  52638. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52639. + return sprintf(buf, "Sleep Status = %d\n",
  52640. + dwc_otg_get_lpm_portsleepstatus(otg_dev->core_if));
  52641. +}
  52642. +
  52643. +/**
  52644. + * Store the sleep_status attribure.
  52645. + */
  52646. +static ssize_t sleepstatus_store(struct device *_dev,
  52647. + struct device_attribute *attr,
  52648. + const char *buf, size_t count)
  52649. +{
  52650. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52651. + dwc_otg_core_if_t *core_if = otg_dev->core_if;
  52652. +
  52653. + if (dwc_otg_get_lpm_portsleepstatus(otg_dev->core_if)) {
  52654. + if (dwc_otg_is_host_mode(core_if)) {
  52655. +
  52656. + DWC_PRINTF("Host initiated resume\n");
  52657. + dwc_otg_set_prtresume(otg_dev->core_if, 1);
  52658. + }
  52659. + }
  52660. +
  52661. + return count;
  52662. +}
  52663. +
  52664. +DEVICE_ATTR(sleep_status, S_IRUGO | S_IWUSR, sleepstatus_show,
  52665. + sleepstatus_store);
  52666. +
  52667. +#endif /* CONFIG_USB_DWC_OTG_LPM_ENABLE */
  52668. +
  52669. +/**@}*/
  52670. +
  52671. +/**
  52672. + * Create the device files
  52673. + */
  52674. +void dwc_otg_attr_create(
  52675. +#ifdef LM_INTERFACE
  52676. + struct lm_device *dev
  52677. +#elif defined(PCI_INTERFACE)
  52678. + struct pci_dev *dev
  52679. +#elif defined(PLATFORM_INTERFACE)
  52680. + struct platform_device *dev
  52681. +#endif
  52682. + )
  52683. +{
  52684. + int error;
  52685. +
  52686. + error = device_create_file(&dev->dev, &dev_attr_regoffset);
  52687. + error = device_create_file(&dev->dev, &dev_attr_regvalue);
  52688. + error = device_create_file(&dev->dev, &dev_attr_mode);
  52689. + error = device_create_file(&dev->dev, &dev_attr_hnpcapable);
  52690. + error = device_create_file(&dev->dev, &dev_attr_srpcapable);
  52691. + error = device_create_file(&dev->dev, &dev_attr_hsic_connect);
  52692. + error = device_create_file(&dev->dev, &dev_attr_inv_sel_hsic);
  52693. + error = device_create_file(&dev->dev, &dev_attr_hnp);
  52694. + error = device_create_file(&dev->dev, &dev_attr_srp);
  52695. + error = device_create_file(&dev->dev, &dev_attr_buspower);
  52696. + error = device_create_file(&dev->dev, &dev_attr_bussuspend);
  52697. + error = device_create_file(&dev->dev, &dev_attr_mode_ch_tim_en);
  52698. + error = device_create_file(&dev->dev, &dev_attr_fr_interval);
  52699. + error = device_create_file(&dev->dev, &dev_attr_busconnected);
  52700. + error = device_create_file(&dev->dev, &dev_attr_gotgctl);
  52701. + error = device_create_file(&dev->dev, &dev_attr_gusbcfg);
  52702. + error = device_create_file(&dev->dev, &dev_attr_grxfsiz);
  52703. + error = device_create_file(&dev->dev, &dev_attr_gnptxfsiz);
  52704. + error = device_create_file(&dev->dev, &dev_attr_gpvndctl);
  52705. + error = device_create_file(&dev->dev, &dev_attr_ggpio);
  52706. + error = device_create_file(&dev->dev, &dev_attr_guid);
  52707. + error = device_create_file(&dev->dev, &dev_attr_gsnpsid);
  52708. + error = device_create_file(&dev->dev, &dev_attr_devspeed);
  52709. + error = device_create_file(&dev->dev, &dev_attr_enumspeed);
  52710. + error = device_create_file(&dev->dev, &dev_attr_hptxfsiz);
  52711. + error = device_create_file(&dev->dev, &dev_attr_hprt0);
  52712. + error = device_create_file(&dev->dev, &dev_attr_remote_wakeup);
  52713. + error = device_create_file(&dev->dev, &dev_attr_rem_wakeup_pwrdn);
  52714. + error = device_create_file(&dev->dev, &dev_attr_disconnect_us);
  52715. + error = device_create_file(&dev->dev, &dev_attr_regdump);
  52716. + error = device_create_file(&dev->dev, &dev_attr_spramdump);
  52717. + error = device_create_file(&dev->dev, &dev_attr_hcddump);
  52718. + error = device_create_file(&dev->dev, &dev_attr_hcd_frrem);
  52719. + error = device_create_file(&dev->dev, &dev_attr_rd_reg_test);
  52720. + error = device_create_file(&dev->dev, &dev_attr_wr_reg_test);
  52721. +#ifdef CONFIG_USB_DWC_OTG_LPM
  52722. + error = device_create_file(&dev->dev, &dev_attr_lpm_response);
  52723. + error = device_create_file(&dev->dev, &dev_attr_sleep_status);
  52724. +#endif
  52725. +}
  52726. +
  52727. +/**
  52728. + * Remove the device files
  52729. + */
  52730. +void dwc_otg_attr_remove(
  52731. +#ifdef LM_INTERFACE
  52732. + struct lm_device *dev
  52733. +#elif defined(PCI_INTERFACE)
  52734. + struct pci_dev *dev
  52735. +#elif defined(PLATFORM_INTERFACE)
  52736. + struct platform_device *dev
  52737. +#endif
  52738. + )
  52739. +{
  52740. + device_remove_file(&dev->dev, &dev_attr_regoffset);
  52741. + device_remove_file(&dev->dev, &dev_attr_regvalue);
  52742. + device_remove_file(&dev->dev, &dev_attr_mode);
  52743. + device_remove_file(&dev->dev, &dev_attr_hnpcapable);
  52744. + device_remove_file(&dev->dev, &dev_attr_srpcapable);
  52745. + device_remove_file(&dev->dev, &dev_attr_hsic_connect);
  52746. + device_remove_file(&dev->dev, &dev_attr_inv_sel_hsic);
  52747. + device_remove_file(&dev->dev, &dev_attr_hnp);
  52748. + device_remove_file(&dev->dev, &dev_attr_srp);
  52749. + device_remove_file(&dev->dev, &dev_attr_buspower);
  52750. + device_remove_file(&dev->dev, &dev_attr_bussuspend);
  52751. + device_remove_file(&dev->dev, &dev_attr_mode_ch_tim_en);
  52752. + device_remove_file(&dev->dev, &dev_attr_fr_interval);
  52753. + device_remove_file(&dev->dev, &dev_attr_busconnected);
  52754. + device_remove_file(&dev->dev, &dev_attr_gotgctl);
  52755. + device_remove_file(&dev->dev, &dev_attr_gusbcfg);
  52756. + device_remove_file(&dev->dev, &dev_attr_grxfsiz);
  52757. + device_remove_file(&dev->dev, &dev_attr_gnptxfsiz);
  52758. + device_remove_file(&dev->dev, &dev_attr_gpvndctl);
  52759. + device_remove_file(&dev->dev, &dev_attr_ggpio);
  52760. + device_remove_file(&dev->dev, &dev_attr_guid);
  52761. + device_remove_file(&dev->dev, &dev_attr_gsnpsid);
  52762. + device_remove_file(&dev->dev, &dev_attr_devspeed);
  52763. + device_remove_file(&dev->dev, &dev_attr_enumspeed);
  52764. + device_remove_file(&dev->dev, &dev_attr_hptxfsiz);
  52765. + device_remove_file(&dev->dev, &dev_attr_hprt0);
  52766. + device_remove_file(&dev->dev, &dev_attr_remote_wakeup);
  52767. + device_remove_file(&dev->dev, &dev_attr_rem_wakeup_pwrdn);
  52768. + device_remove_file(&dev->dev, &dev_attr_disconnect_us);
  52769. + device_remove_file(&dev->dev, &dev_attr_regdump);
  52770. + device_remove_file(&dev->dev, &dev_attr_spramdump);
  52771. + device_remove_file(&dev->dev, &dev_attr_hcddump);
  52772. + device_remove_file(&dev->dev, &dev_attr_hcd_frrem);
  52773. + device_remove_file(&dev->dev, &dev_attr_rd_reg_test);
  52774. + device_remove_file(&dev->dev, &dev_attr_wr_reg_test);
  52775. +#ifdef CONFIG_USB_DWC_OTG_LPM
  52776. + device_remove_file(&dev->dev, &dev_attr_lpm_response);
  52777. + device_remove_file(&dev->dev, &dev_attr_sleep_status);
  52778. +#endif
  52779. +}
  52780. diff -Nur linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_attr.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_attr.h
  52781. --- linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_attr.h 1970-01-01 01:00:00.000000000 +0100
  52782. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_attr.h 2014-04-24 15:37:13.310990489 +0200
  52783. @@ -0,0 +1,89 @@
  52784. +/* ==========================================================================
  52785. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_attr.h $
  52786. + * $Revision: #13 $
  52787. + * $Date: 2010/06/21 $
  52788. + * $Change: 1532021 $
  52789. + *
  52790. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  52791. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  52792. + * otherwise expressly agreed to in writing between Synopsys and you.
  52793. + *
  52794. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  52795. + * any End User Software License Agreement or Agreement for Licensed Product
  52796. + * with Synopsys or any supplement thereto. You are permitted to use and
  52797. + * redistribute this Software in source and binary forms, with or without
  52798. + * modification, provided that redistributions of source code must retain this
  52799. + * notice. You may not view, use, disclose, copy or distribute this file or
  52800. + * any information contained herein except pursuant to this license grant from
  52801. + * Synopsys. If you do not agree with this notice, including the disclaimer
  52802. + * below, then you are not authorized to use the Software.
  52803. + *
  52804. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  52805. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  52806. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  52807. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  52808. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  52809. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  52810. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  52811. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  52812. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  52813. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  52814. + * DAMAGE.
  52815. + * ========================================================================== */
  52816. +
  52817. +#if !defined(__DWC_OTG_ATTR_H__)
  52818. +#define __DWC_OTG_ATTR_H__
  52819. +
  52820. +/** @file
  52821. + * This file contains the interface to the Linux device attributes.
  52822. + */
  52823. +extern struct device_attribute dev_attr_regoffset;
  52824. +extern struct device_attribute dev_attr_regvalue;
  52825. +
  52826. +extern struct device_attribute dev_attr_mode;
  52827. +extern struct device_attribute dev_attr_hnpcapable;
  52828. +extern struct device_attribute dev_attr_srpcapable;
  52829. +extern struct device_attribute dev_attr_hnp;
  52830. +extern struct device_attribute dev_attr_srp;
  52831. +extern struct device_attribute dev_attr_buspower;
  52832. +extern struct device_attribute dev_attr_bussuspend;
  52833. +extern struct device_attribute dev_attr_mode_ch_tim_en;
  52834. +extern struct device_attribute dev_attr_fr_interval;
  52835. +extern struct device_attribute dev_attr_busconnected;
  52836. +extern struct device_attribute dev_attr_gotgctl;
  52837. +extern struct device_attribute dev_attr_gusbcfg;
  52838. +extern struct device_attribute dev_attr_grxfsiz;
  52839. +extern struct device_attribute dev_attr_gnptxfsiz;
  52840. +extern struct device_attribute dev_attr_gpvndctl;
  52841. +extern struct device_attribute dev_attr_ggpio;
  52842. +extern struct device_attribute dev_attr_guid;
  52843. +extern struct device_attribute dev_attr_gsnpsid;
  52844. +extern struct device_attribute dev_attr_devspeed;
  52845. +extern struct device_attribute dev_attr_enumspeed;
  52846. +extern struct device_attribute dev_attr_hptxfsiz;
  52847. +extern struct device_attribute dev_attr_hprt0;
  52848. +#ifdef CONFIG_USB_DWC_OTG_LPM
  52849. +extern struct device_attribute dev_attr_lpm_response;
  52850. +extern struct device_attribute devi_attr_sleep_status;
  52851. +#endif
  52852. +
  52853. +void dwc_otg_attr_create(
  52854. +#ifdef LM_INTERFACE
  52855. + struct lm_device *dev
  52856. +#elif defined(PCI_INTERFACE)
  52857. + struct pci_dev *dev
  52858. +#elif defined(PLATFORM_INTERFACE)
  52859. + struct platform_device *dev
  52860. +#endif
  52861. + );
  52862. +
  52863. +void dwc_otg_attr_remove(
  52864. +#ifdef LM_INTERFACE
  52865. + struct lm_device *dev
  52866. +#elif defined(PCI_INTERFACE)
  52867. + struct pci_dev *dev
  52868. +#elif defined(PLATFORM_INTERFACE)
  52869. + struct platform_device *dev
  52870. +#endif
  52871. + );
  52872. +#endif
  52873. diff -Nur linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_cfi.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cfi.c
  52874. --- linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_cfi.c 1970-01-01 01:00:00.000000000 +0100
  52875. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cfi.c 2014-04-24 15:37:13.310990489 +0200
  52876. @@ -0,0 +1,1876 @@
  52877. +/* ==========================================================================
  52878. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  52879. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  52880. + * otherwise expressly agreed to in writing between Synopsys and you.
  52881. + *
  52882. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  52883. + * any End User Software License Agreement or Agreement for Licensed Product
  52884. + * with Synopsys or any supplement thereto. You are permitted to use and
  52885. + * redistribute this Software in source and binary forms, with or without
  52886. + * modification, provided that redistributions of source code must retain this
  52887. + * notice. You may not view, use, disclose, copy or distribute this file or
  52888. + * any information contained herein except pursuant to this license grant from
  52889. + * Synopsys. If you do not agree with this notice, including the disclaimer
  52890. + * below, then you are not authorized to use the Software.
  52891. + *
  52892. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  52893. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  52894. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  52895. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  52896. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  52897. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  52898. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  52899. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  52900. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  52901. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  52902. + * DAMAGE.
  52903. + * ========================================================================== */
  52904. +
  52905. +/** @file
  52906. + *
  52907. + * This file contains the most of the CFI(Core Feature Interface)
  52908. + * implementation for the OTG.
  52909. + */
  52910. +
  52911. +#ifdef DWC_UTE_CFI
  52912. +
  52913. +#include "dwc_otg_pcd.h"
  52914. +#include "dwc_otg_cfi.h"
  52915. +
  52916. +/** This definition should actually migrate to the Portability Library */
  52917. +#define DWC_CONSTANT_CPU_TO_LE16(x) (x)
  52918. +
  52919. +extern dwc_otg_pcd_ep_t *get_ep_by_addr(dwc_otg_pcd_t * pcd, u16 wIndex);
  52920. +
  52921. +static int cfi_core_features_buf(uint8_t * buf, uint16_t buflen);
  52922. +static int cfi_get_feature_value(uint8_t * buf, uint16_t buflen,
  52923. + struct dwc_otg_pcd *pcd,
  52924. + struct cfi_usb_ctrlrequest *ctrl_req);
  52925. +static int cfi_set_feature_value(struct dwc_otg_pcd *pcd);
  52926. +static int cfi_ep_get_sg_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  52927. + struct cfi_usb_ctrlrequest *req);
  52928. +static int cfi_ep_get_concat_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  52929. + struct cfi_usb_ctrlrequest *req);
  52930. +static int cfi_ep_get_align_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  52931. + struct cfi_usb_ctrlrequest *req);
  52932. +static int cfi_preproc_reset(struct dwc_otg_pcd *pcd,
  52933. + struct cfi_usb_ctrlrequest *req);
  52934. +static void cfi_free_ep_bs_dyn_data(cfi_ep_t * cfiep);
  52935. +
  52936. +static uint16_t get_dfifo_size(dwc_otg_core_if_t * core_if);
  52937. +static int32_t get_rxfifo_size(dwc_otg_core_if_t * core_if, uint16_t wValue);
  52938. +static int32_t get_txfifo_size(struct dwc_otg_pcd *pcd, uint16_t wValue);
  52939. +
  52940. +static uint8_t resize_fifos(dwc_otg_core_if_t * core_if);
  52941. +
  52942. +/** This is the header of the all features descriptor */
  52943. +static cfi_all_features_header_t all_props_desc_header = {
  52944. + .wVersion = DWC_CONSTANT_CPU_TO_LE16(0x100),
  52945. + .wCoreID = DWC_CONSTANT_CPU_TO_LE16(CFI_CORE_ID_OTG),
  52946. + .wNumFeatures = DWC_CONSTANT_CPU_TO_LE16(9),
  52947. +};
  52948. +
  52949. +/** This is an array of statically allocated feature descriptors */
  52950. +static cfi_feature_desc_header_t prop_descs[] = {
  52951. +
  52952. + /* FT_ID_DMA_MODE */
  52953. + {
  52954. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_MODE),
  52955. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  52956. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(1),
  52957. + },
  52958. +
  52959. + /* FT_ID_DMA_BUFFER_SETUP */
  52960. + {
  52961. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_BUFFER_SETUP),
  52962. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  52963. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(6),
  52964. + },
  52965. +
  52966. + /* FT_ID_DMA_BUFF_ALIGN */
  52967. + {
  52968. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_BUFF_ALIGN),
  52969. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  52970. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(2),
  52971. + },
  52972. +
  52973. + /* FT_ID_DMA_CONCAT_SETUP */
  52974. + {
  52975. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_CONCAT_SETUP),
  52976. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  52977. + //.wDataLength = DWC_CONSTANT_CPU_TO_LE16(6),
  52978. + },
  52979. +
  52980. + /* FT_ID_DMA_CIRCULAR */
  52981. + {
  52982. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_CIRCULAR),
  52983. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  52984. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(6),
  52985. + },
  52986. +
  52987. + /* FT_ID_THRESHOLD_SETUP */
  52988. + {
  52989. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_THRESHOLD_SETUP),
  52990. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  52991. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(6),
  52992. + },
  52993. +
  52994. + /* FT_ID_DFIFO_DEPTH */
  52995. + {
  52996. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DFIFO_DEPTH),
  52997. + .bmAttributes = CFI_FEATURE_ATTR_RO,
  52998. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(2),
  52999. + },
  53000. +
  53001. + /* FT_ID_TX_FIFO_DEPTH */
  53002. + {
  53003. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_TX_FIFO_DEPTH),
  53004. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  53005. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(2),
  53006. + },
  53007. +
  53008. + /* FT_ID_RX_FIFO_DEPTH */
  53009. + {
  53010. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_RX_FIFO_DEPTH),
  53011. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  53012. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(2),
  53013. + }
  53014. +};
  53015. +
  53016. +/** The table of feature names */
  53017. +cfi_string_t prop_name_table[] = {
  53018. + {FT_ID_DMA_MODE, "dma_mode"},
  53019. + {FT_ID_DMA_BUFFER_SETUP, "buffer_setup"},
  53020. + {FT_ID_DMA_BUFF_ALIGN, "buffer_align"},
  53021. + {FT_ID_DMA_CONCAT_SETUP, "concat_setup"},
  53022. + {FT_ID_DMA_CIRCULAR, "buffer_circular"},
  53023. + {FT_ID_THRESHOLD_SETUP, "threshold_setup"},
  53024. + {FT_ID_DFIFO_DEPTH, "dfifo_depth"},
  53025. + {FT_ID_TX_FIFO_DEPTH, "txfifo_depth"},
  53026. + {FT_ID_RX_FIFO_DEPTH, "rxfifo_depth"},
  53027. + {}
  53028. +};
  53029. +
  53030. +/************************************************************************/
  53031. +
  53032. +/**
  53033. + * Returns the name of the feature by its ID
  53034. + * or NULL if no featute ID matches.
  53035. + *
  53036. + */
  53037. +const uint8_t *get_prop_name(uint16_t prop_id, int *len)
  53038. +{
  53039. + cfi_string_t *pstr;
  53040. + *len = 0;
  53041. +
  53042. + for (pstr = prop_name_table; pstr && pstr->s; pstr++) {
  53043. + if (pstr->id == prop_id) {
  53044. + *len = DWC_STRLEN(pstr->s);
  53045. + return pstr->s;
  53046. + }
  53047. + }
  53048. + return NULL;
  53049. +}
  53050. +
  53051. +/**
  53052. + * This function handles all CFI specific control requests.
  53053. + *
  53054. + * Return a negative value to stall the DCE.
  53055. + */
  53056. +int cfi_setup(struct dwc_otg_pcd *pcd, struct cfi_usb_ctrlrequest *ctrl)
  53057. +{
  53058. + int retval = 0;
  53059. + dwc_otg_pcd_ep_t *ep = NULL;
  53060. + cfiobject_t *cfi = pcd->cfi;
  53061. + struct dwc_otg_core_if *coreif = GET_CORE_IF(pcd);
  53062. + uint16_t wLen = DWC_LE16_TO_CPU(&ctrl->wLength);
  53063. + uint16_t wValue = DWC_LE16_TO_CPU(&ctrl->wValue);
  53064. + uint16_t wIndex = DWC_LE16_TO_CPU(&ctrl->wIndex);
  53065. + uint32_t regaddr = 0;
  53066. + uint32_t regval = 0;
  53067. +
  53068. + /* Save this Control Request in the CFI object.
  53069. + * The data field will be assigned in the data stage completion CB function.
  53070. + */
  53071. + cfi->ctrl_req = *ctrl;
  53072. + cfi->ctrl_req.data = NULL;
  53073. +
  53074. + cfi->need_gadget_att = 0;
  53075. + cfi->need_status_in_complete = 0;
  53076. +
  53077. + switch (ctrl->bRequest) {
  53078. + case VEN_CORE_GET_FEATURES:
  53079. + retval = cfi_core_features_buf(cfi->buf_in.buf, CFI_IN_BUF_LEN);
  53080. + if (retval >= 0) {
  53081. + //dump_msg(cfi->buf_in.buf, retval);
  53082. + ep = &pcd->ep0;
  53083. +
  53084. + retval = min((uint16_t) retval, wLen);
  53085. + /* Transfer this buffer to the host through the EP0-IN EP */
  53086. + ep->dwc_ep.dma_addr = cfi->buf_in.addr;
  53087. + ep->dwc_ep.start_xfer_buff = cfi->buf_in.buf;
  53088. + ep->dwc_ep.xfer_buff = cfi->buf_in.buf;
  53089. + ep->dwc_ep.xfer_len = retval;
  53090. + ep->dwc_ep.xfer_count = 0;
  53091. + ep->dwc_ep.sent_zlp = 0;
  53092. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  53093. +
  53094. + pcd->ep0_pending = 1;
  53095. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  53096. + }
  53097. + retval = 0;
  53098. + break;
  53099. +
  53100. + case VEN_CORE_GET_FEATURE:
  53101. + CFI_INFO("VEN_CORE_GET_FEATURE\n");
  53102. + retval = cfi_get_feature_value(cfi->buf_in.buf, CFI_IN_BUF_LEN,
  53103. + pcd, ctrl);
  53104. + if (retval >= 0) {
  53105. + ep = &pcd->ep0;
  53106. +
  53107. + retval = min((uint16_t) retval, wLen);
  53108. + /* Transfer this buffer to the host through the EP0-IN EP */
  53109. + ep->dwc_ep.dma_addr = cfi->buf_in.addr;
  53110. + ep->dwc_ep.start_xfer_buff = cfi->buf_in.buf;
  53111. + ep->dwc_ep.xfer_buff = cfi->buf_in.buf;
  53112. + ep->dwc_ep.xfer_len = retval;
  53113. + ep->dwc_ep.xfer_count = 0;
  53114. + ep->dwc_ep.sent_zlp = 0;
  53115. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  53116. +
  53117. + pcd->ep0_pending = 1;
  53118. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  53119. + }
  53120. + CFI_INFO("VEN_CORE_GET_FEATURE=%d\n", retval);
  53121. + dump_msg(cfi->buf_in.buf, retval);
  53122. + break;
  53123. +
  53124. + case VEN_CORE_SET_FEATURE:
  53125. + CFI_INFO("VEN_CORE_SET_FEATURE\n");
  53126. + /* Set up an XFER to get the data stage of the control request,
  53127. + * which is the new value of the feature to be modified.
  53128. + */
  53129. + ep = &pcd->ep0;
  53130. + ep->dwc_ep.is_in = 0;
  53131. + ep->dwc_ep.dma_addr = cfi->buf_out.addr;
  53132. + ep->dwc_ep.start_xfer_buff = cfi->buf_out.buf;
  53133. + ep->dwc_ep.xfer_buff = cfi->buf_out.buf;
  53134. + ep->dwc_ep.xfer_len = wLen;
  53135. + ep->dwc_ep.xfer_count = 0;
  53136. + ep->dwc_ep.sent_zlp = 0;
  53137. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  53138. +
  53139. + pcd->ep0_pending = 1;
  53140. + /* Read the control write's data stage */
  53141. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  53142. + retval = 0;
  53143. + break;
  53144. +
  53145. + case VEN_CORE_RESET_FEATURES:
  53146. + CFI_INFO("VEN_CORE_RESET_FEATURES\n");
  53147. + cfi->need_gadget_att = 1;
  53148. + cfi->need_status_in_complete = 1;
  53149. + retval = cfi_preproc_reset(pcd, ctrl);
  53150. + CFI_INFO("VEN_CORE_RESET_FEATURES = (%d)\n", retval);
  53151. + break;
  53152. +
  53153. + case VEN_CORE_ACTIVATE_FEATURES:
  53154. + CFI_INFO("VEN_CORE_ACTIVATE_FEATURES\n");
  53155. + break;
  53156. +
  53157. + case VEN_CORE_READ_REGISTER:
  53158. + CFI_INFO("VEN_CORE_READ_REGISTER\n");
  53159. + /* wValue optionally contains the HI WORD of the register offset and
  53160. + * wIndex contains the LOW WORD of the register offset
  53161. + */
  53162. + if (wValue == 0) {
  53163. + /* @TODO - MAS - fix the access to the base field */
  53164. + regaddr = 0;
  53165. + //regaddr = (uint32_t) pcd->otg_dev->os_dep.base;
  53166. + //GET_CORE_IF(pcd)->co
  53167. + regaddr |= wIndex;
  53168. + } else {
  53169. + regaddr = (wValue << 16) | wIndex;
  53170. + }
  53171. +
  53172. + /* Read a 32-bit value of the memory at the regaddr */
  53173. + regval = DWC_READ_REG32((uint32_t *) regaddr);
  53174. +
  53175. + ep = &pcd->ep0;
  53176. + dwc_memcpy(cfi->buf_in.buf, &regval, sizeof(uint32_t));
  53177. + ep->dwc_ep.is_in = 1;
  53178. + ep->dwc_ep.dma_addr = cfi->buf_in.addr;
  53179. + ep->dwc_ep.start_xfer_buff = cfi->buf_in.buf;
  53180. + ep->dwc_ep.xfer_buff = cfi->buf_in.buf;
  53181. + ep->dwc_ep.xfer_len = wLen;
  53182. + ep->dwc_ep.xfer_count = 0;
  53183. + ep->dwc_ep.sent_zlp = 0;
  53184. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  53185. +
  53186. + pcd->ep0_pending = 1;
  53187. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  53188. + cfi->need_gadget_att = 0;
  53189. + retval = 0;
  53190. + break;
  53191. +
  53192. + case VEN_CORE_WRITE_REGISTER:
  53193. + CFI_INFO("VEN_CORE_WRITE_REGISTER\n");
  53194. + /* Set up an XFER to get the data stage of the control request,
  53195. + * which is the new value of the register to be modified.
  53196. + */
  53197. + ep = &pcd->ep0;
  53198. + ep->dwc_ep.is_in = 0;
  53199. + ep->dwc_ep.dma_addr = cfi->buf_out.addr;
  53200. + ep->dwc_ep.start_xfer_buff = cfi->buf_out.buf;
  53201. + ep->dwc_ep.xfer_buff = cfi->buf_out.buf;
  53202. + ep->dwc_ep.xfer_len = wLen;
  53203. + ep->dwc_ep.xfer_count = 0;
  53204. + ep->dwc_ep.sent_zlp = 0;
  53205. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  53206. +
  53207. + pcd->ep0_pending = 1;
  53208. + /* Read the control write's data stage */
  53209. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  53210. + retval = 0;
  53211. + break;
  53212. +
  53213. + default:
  53214. + retval = -DWC_E_NOT_SUPPORTED;
  53215. + break;
  53216. + }
  53217. +
  53218. + return retval;
  53219. +}
  53220. +
  53221. +/**
  53222. + * This function prepares the core features descriptors and copies its
  53223. + * raw representation into the buffer <buf>.
  53224. + *
  53225. + * The buffer structure is as follows:
  53226. + * all_features_header (8 bytes)
  53227. + * features_#1 (8 bytes + feature name string length)
  53228. + * features_#2 (8 bytes + feature name string length)
  53229. + * .....
  53230. + * features_#n - where n=the total count of feature descriptors
  53231. + */
  53232. +static int cfi_core_features_buf(uint8_t * buf, uint16_t buflen)
  53233. +{
  53234. + cfi_feature_desc_header_t *prop_hdr = prop_descs;
  53235. + cfi_feature_desc_header_t *prop;
  53236. + cfi_all_features_header_t *all_props_hdr = &all_props_desc_header;
  53237. + cfi_all_features_header_t *tmp;
  53238. + uint8_t *tmpbuf = buf;
  53239. + const uint8_t *pname = NULL;
  53240. + int i, j, namelen = 0, totlen;
  53241. +
  53242. + /* Prepare and copy the core features into the buffer */
  53243. + CFI_INFO("%s:\n", __func__);
  53244. +
  53245. + tmp = (cfi_all_features_header_t *) tmpbuf;
  53246. + *tmp = *all_props_hdr;
  53247. + tmpbuf += CFI_ALL_FEATURES_HDR_LEN;
  53248. +
  53249. + j = sizeof(prop_descs) / sizeof(cfi_all_features_header_t);
  53250. + for (i = 0; i < j; i++, prop_hdr++) {
  53251. + pname = get_prop_name(prop_hdr->wFeatureID, &namelen);
  53252. + prop = (cfi_feature_desc_header_t *) tmpbuf;
  53253. + *prop = *prop_hdr;
  53254. +
  53255. + prop->bNameLen = namelen;
  53256. + prop->wLength =
  53257. + DWC_CONSTANT_CPU_TO_LE16(CFI_FEATURE_DESC_HDR_LEN +
  53258. + namelen);
  53259. +
  53260. + tmpbuf += CFI_FEATURE_DESC_HDR_LEN;
  53261. + dwc_memcpy(tmpbuf, pname, namelen);
  53262. + tmpbuf += namelen;
  53263. + }
  53264. +
  53265. + totlen = tmpbuf - buf;
  53266. +
  53267. + if (totlen > 0) {
  53268. + tmp = (cfi_all_features_header_t *) buf;
  53269. + tmp->wTotalLen = DWC_CONSTANT_CPU_TO_LE16(totlen);
  53270. + }
  53271. +
  53272. + return totlen;
  53273. +}
  53274. +
  53275. +/**
  53276. + * This function releases all the dynamic memory in the CFI object.
  53277. + */
  53278. +static void cfi_release(cfiobject_t * cfiobj)
  53279. +{
  53280. + cfi_ep_t *cfiep;
  53281. + dwc_list_link_t *tmp;
  53282. +
  53283. + CFI_INFO("%s\n", __func__);
  53284. +
  53285. + if (cfiobj->buf_in.buf) {
  53286. + DWC_DMA_FREE(CFI_IN_BUF_LEN, cfiobj->buf_in.buf,
  53287. + cfiobj->buf_in.addr);
  53288. + cfiobj->buf_in.buf = NULL;
  53289. + }
  53290. +
  53291. + if (cfiobj->buf_out.buf) {
  53292. + DWC_DMA_FREE(CFI_OUT_BUF_LEN, cfiobj->buf_out.buf,
  53293. + cfiobj->buf_out.addr);
  53294. + cfiobj->buf_out.buf = NULL;
  53295. + }
  53296. +
  53297. + /* Free the Buffer Setup values for each EP */
  53298. + //list_for_each_entry(cfiep, &cfiobj->active_eps, lh) {
  53299. + DWC_LIST_FOREACH(tmp, &cfiobj->active_eps) {
  53300. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  53301. + cfi_free_ep_bs_dyn_data(cfiep);
  53302. + }
  53303. +}
  53304. +
  53305. +/**
  53306. + * This function frees the dynamically allocated EP buffer setup data.
  53307. + */
  53308. +static void cfi_free_ep_bs_dyn_data(cfi_ep_t * cfiep)
  53309. +{
  53310. + if (cfiep->bm_sg) {
  53311. + DWC_FREE(cfiep->bm_sg);
  53312. + cfiep->bm_sg = NULL;
  53313. + }
  53314. +
  53315. + if (cfiep->bm_align) {
  53316. + DWC_FREE(cfiep->bm_align);
  53317. + cfiep->bm_align = NULL;
  53318. + }
  53319. +
  53320. + if (cfiep->bm_concat) {
  53321. + if (NULL != cfiep->bm_concat->wTxBytes) {
  53322. + DWC_FREE(cfiep->bm_concat->wTxBytes);
  53323. + cfiep->bm_concat->wTxBytes = NULL;
  53324. + }
  53325. + DWC_FREE(cfiep->bm_concat);
  53326. + cfiep->bm_concat = NULL;
  53327. + }
  53328. +}
  53329. +
  53330. +/**
  53331. + * This function initializes the default values of the features
  53332. + * for a specific endpoint and should be called only once when
  53333. + * the EP is enabled first time.
  53334. + */
  53335. +static int cfi_ep_init_defaults(struct dwc_otg_pcd *pcd, cfi_ep_t * cfiep)
  53336. +{
  53337. + int retval = 0;
  53338. +
  53339. + cfiep->bm_sg = DWC_ALLOC(sizeof(ddma_sg_buffer_setup_t));
  53340. + if (NULL == cfiep->bm_sg) {
  53341. + CFI_INFO("Failed to allocate memory for SG feature value\n");
  53342. + return -DWC_E_NO_MEMORY;
  53343. + }
  53344. + dwc_memset(cfiep->bm_sg, 0, sizeof(ddma_sg_buffer_setup_t));
  53345. +
  53346. + /* For the Concatenation feature's default value we do not allocate
  53347. + * memory for the wTxBytes field - it will be done in the set_feature_value
  53348. + * request handler.
  53349. + */
  53350. + cfiep->bm_concat = DWC_ALLOC(sizeof(ddma_concat_buffer_setup_t));
  53351. + if (NULL == cfiep->bm_concat) {
  53352. + CFI_INFO
  53353. + ("Failed to allocate memory for CONCATENATION feature value\n");
  53354. + DWC_FREE(cfiep->bm_sg);
  53355. + return -DWC_E_NO_MEMORY;
  53356. + }
  53357. + dwc_memset(cfiep->bm_concat, 0, sizeof(ddma_concat_buffer_setup_t));
  53358. +
  53359. + cfiep->bm_align = DWC_ALLOC(sizeof(ddma_align_buffer_setup_t));
  53360. + if (NULL == cfiep->bm_align) {
  53361. + CFI_INFO
  53362. + ("Failed to allocate memory for Alignment feature value\n");
  53363. + DWC_FREE(cfiep->bm_sg);
  53364. + DWC_FREE(cfiep->bm_concat);
  53365. + return -DWC_E_NO_MEMORY;
  53366. + }
  53367. + dwc_memset(cfiep->bm_align, 0, sizeof(ddma_align_buffer_setup_t));
  53368. +
  53369. + return retval;
  53370. +}
  53371. +
  53372. +/**
  53373. + * The callback function that notifies the CFI on the activation of
  53374. + * an endpoint in the PCD. The following steps are done in this function:
  53375. + *
  53376. + * Create a dynamically allocated cfi_ep_t object (a CFI wrapper to the PCD's
  53377. + * active endpoint)
  53378. + * Create MAX_DMA_DESCS_PER_EP count DMA Descriptors for the EP
  53379. + * Set the Buffer Mode to standard
  53380. + * Initialize the default values for all EP modes (SG, Circular, Concat, Align)
  53381. + * Add the cfi_ep_t object to the list of active endpoints in the CFI object
  53382. + */
  53383. +static int cfi_ep_enable(struct cfiobject *cfi, struct dwc_otg_pcd *pcd,
  53384. + struct dwc_otg_pcd_ep *ep)
  53385. +{
  53386. + cfi_ep_t *cfiep;
  53387. + int retval = -DWC_E_NOT_SUPPORTED;
  53388. +
  53389. + CFI_INFO("%s: epname=%s; epnum=0x%02x\n", __func__,
  53390. + "EP_" /*ep->ep.name */ , ep->desc->bEndpointAddress);
  53391. + /* MAS - Check whether this endpoint already is in the list */
  53392. + cfiep = get_cfi_ep_by_pcd_ep(cfi, ep);
  53393. +
  53394. + if (NULL == cfiep) {
  53395. + /* Allocate a cfi_ep_t object */
  53396. + cfiep = DWC_ALLOC(sizeof(cfi_ep_t));
  53397. + if (NULL == cfiep) {
  53398. + CFI_INFO
  53399. + ("Unable to allocate memory for <cfiep> in function %s\n",
  53400. + __func__);
  53401. + return -DWC_E_NO_MEMORY;
  53402. + }
  53403. + dwc_memset(cfiep, 0, sizeof(cfi_ep_t));
  53404. +
  53405. + /* Save the dwc_otg_pcd_ep pointer in the cfiep object */
  53406. + cfiep->ep = ep;
  53407. +
  53408. + /* Allocate the DMA Descriptors chain of MAX_DMA_DESCS_PER_EP count */
  53409. + ep->dwc_ep.descs =
  53410. + DWC_DMA_ALLOC(MAX_DMA_DESCS_PER_EP *
  53411. + sizeof(dwc_otg_dma_desc_t),
  53412. + &ep->dwc_ep.descs_dma_addr);
  53413. +
  53414. + if (NULL == ep->dwc_ep.descs) {
  53415. + DWC_FREE(cfiep);
  53416. + return -DWC_E_NO_MEMORY;
  53417. + }
  53418. +
  53419. + DWC_LIST_INIT(&cfiep->lh);
  53420. +
  53421. + /* Set the buffer mode to BM_STANDARD. It will be modified
  53422. + * when building descriptors for a specific buffer mode */
  53423. + ep->dwc_ep.buff_mode = BM_STANDARD;
  53424. +
  53425. + /* Create and initialize the default values for this EP's Buffer modes */
  53426. + if ((retval = cfi_ep_init_defaults(pcd, cfiep)) < 0)
  53427. + return retval;
  53428. +
  53429. + /* Add the cfi_ep_t object to the CFI object's list of active endpoints */
  53430. + DWC_LIST_INSERT_TAIL(&cfi->active_eps, &cfiep->lh);
  53431. + retval = 0;
  53432. + } else { /* The sought EP already is in the list */
  53433. + CFI_INFO("%s: The sought EP already is in the list\n",
  53434. + __func__);
  53435. + }
  53436. +
  53437. + return retval;
  53438. +}
  53439. +
  53440. +/**
  53441. + * This function is called when the data stage of a 3-stage Control Write request
  53442. + * is complete.
  53443. + *
  53444. + */
  53445. +static int cfi_ctrl_write_complete(struct cfiobject *cfi,
  53446. + struct dwc_otg_pcd *pcd)
  53447. +{
  53448. + uint32_t addr, reg_value;
  53449. + uint16_t wIndex, wValue;
  53450. + uint8_t bRequest;
  53451. + uint8_t *buf = cfi->buf_out.buf;
  53452. + //struct usb_ctrlrequest *ctrl_req = &cfi->ctrl_req_saved;
  53453. + struct cfi_usb_ctrlrequest *ctrl_req = &cfi->ctrl_req;
  53454. + int retval = -DWC_E_NOT_SUPPORTED;
  53455. +
  53456. + CFI_INFO("%s\n", __func__);
  53457. +
  53458. + bRequest = ctrl_req->bRequest;
  53459. + wIndex = DWC_CONSTANT_CPU_TO_LE16(ctrl_req->wIndex);
  53460. + wValue = DWC_CONSTANT_CPU_TO_LE16(ctrl_req->wValue);
  53461. +
  53462. + /*
  53463. + * Save the pointer to the data stage in the ctrl_req's <data> field.
  53464. + * The request should be already saved in the command stage by now.
  53465. + */
  53466. + ctrl_req->data = cfi->buf_out.buf;
  53467. + cfi->need_status_in_complete = 0;
  53468. + cfi->need_gadget_att = 0;
  53469. +
  53470. + switch (bRequest) {
  53471. + case VEN_CORE_WRITE_REGISTER:
  53472. + /* The buffer contains raw data of the new value for the register */
  53473. + reg_value = *((uint32_t *) buf);
  53474. + if (wValue == 0) {
  53475. + addr = 0;
  53476. + //addr = (uint32_t) pcd->otg_dev->os_dep.base;
  53477. + addr += wIndex;
  53478. + } else {
  53479. + addr = (wValue << 16) | wIndex;
  53480. + }
  53481. +
  53482. + //writel(reg_value, addr);
  53483. +
  53484. + retval = 0;
  53485. + cfi->need_status_in_complete = 1;
  53486. + break;
  53487. +
  53488. + case VEN_CORE_SET_FEATURE:
  53489. + /* The buffer contains raw data of the new value of the feature */
  53490. + retval = cfi_set_feature_value(pcd);
  53491. + if (retval < 0)
  53492. + return retval;
  53493. +
  53494. + cfi->need_status_in_complete = 1;
  53495. + break;
  53496. +
  53497. + default:
  53498. + break;
  53499. + }
  53500. +
  53501. + return retval;
  53502. +}
  53503. +
  53504. +/**
  53505. + * This function builds the DMA descriptors for the SG buffer mode.
  53506. + */
  53507. +static void cfi_build_sg_descs(struct cfiobject *cfi, cfi_ep_t * cfiep,
  53508. + dwc_otg_pcd_request_t * req)
  53509. +{
  53510. + struct dwc_otg_pcd_ep *ep = cfiep->ep;
  53511. + ddma_sg_buffer_setup_t *sgval = cfiep->bm_sg;
  53512. + struct dwc_otg_dma_desc *desc = cfiep->ep->dwc_ep.descs;
  53513. + struct dwc_otg_dma_desc *desc_last = cfiep->ep->dwc_ep.descs;
  53514. + dma_addr_t buff_addr = req->dma;
  53515. + int i;
  53516. + uint32_t txsize, off;
  53517. +
  53518. + txsize = sgval->wSize;
  53519. + off = sgval->bOffset;
  53520. +
  53521. +// CFI_INFO("%s: %s TXSIZE=0x%08x; OFFSET=0x%08x\n",
  53522. +// __func__, cfiep->ep->ep.name, txsize, off);
  53523. +
  53524. + for (i = 0; i < sgval->bCount; i++) {
  53525. + desc->status.b.bs = BS_HOST_BUSY;
  53526. + desc->buf = buff_addr;
  53527. + desc->status.b.l = 0;
  53528. + desc->status.b.ioc = 0;
  53529. + desc->status.b.sp = 0;
  53530. + desc->status.b.bytes = txsize;
  53531. + desc->status.b.bs = BS_HOST_READY;
  53532. +
  53533. + /* Set the next address of the buffer */
  53534. + buff_addr += txsize + off;
  53535. + desc_last = desc;
  53536. + desc++;
  53537. + }
  53538. +
  53539. + /* Set the last, ioc and sp bits on the Last DMA Descriptor */
  53540. + desc_last->status.b.l = 1;
  53541. + desc_last->status.b.ioc = 1;
  53542. + desc_last->status.b.sp = ep->dwc_ep.sent_zlp;
  53543. + /* Save the last DMA descriptor pointer */
  53544. + cfiep->dma_desc_last = desc_last;
  53545. + cfiep->desc_count = sgval->bCount;
  53546. +}
  53547. +
  53548. +/**
  53549. + * This function builds the DMA descriptors for the Concatenation buffer mode.
  53550. + */
  53551. +static void cfi_build_concat_descs(struct cfiobject *cfi, cfi_ep_t * cfiep,
  53552. + dwc_otg_pcd_request_t * req)
  53553. +{
  53554. + struct dwc_otg_pcd_ep *ep = cfiep->ep;
  53555. + ddma_concat_buffer_setup_t *concatval = cfiep->bm_concat;
  53556. + struct dwc_otg_dma_desc *desc = cfiep->ep->dwc_ep.descs;
  53557. + struct dwc_otg_dma_desc *desc_last = cfiep->ep->dwc_ep.descs;
  53558. + dma_addr_t buff_addr = req->dma;
  53559. + int i;
  53560. + uint16_t *txsize;
  53561. +
  53562. + txsize = concatval->wTxBytes;
  53563. +
  53564. + for (i = 0; i < concatval->hdr.bDescCount; i++) {
  53565. + desc->buf = buff_addr;
  53566. + desc->status.b.bs = BS_HOST_BUSY;
  53567. + desc->status.b.l = 0;
  53568. + desc->status.b.ioc = 0;
  53569. + desc->status.b.sp = 0;
  53570. + desc->status.b.bytes = *txsize;
  53571. + desc->status.b.bs = BS_HOST_READY;
  53572. +
  53573. + txsize++;
  53574. + /* Set the next address of the buffer */
  53575. + buff_addr += UGETW(ep->desc->wMaxPacketSize);
  53576. + desc_last = desc;
  53577. + desc++;
  53578. + }
  53579. +
  53580. + /* Set the last, ioc and sp bits on the Last DMA Descriptor */
  53581. + desc_last->status.b.l = 1;
  53582. + desc_last->status.b.ioc = 1;
  53583. + desc_last->status.b.sp = ep->dwc_ep.sent_zlp;
  53584. + cfiep->dma_desc_last = desc_last;
  53585. + cfiep->desc_count = concatval->hdr.bDescCount;
  53586. +}
  53587. +
  53588. +/**
  53589. + * This function builds the DMA descriptors for the Circular buffer mode
  53590. + */
  53591. +static void cfi_build_circ_descs(struct cfiobject *cfi, cfi_ep_t * cfiep,
  53592. + dwc_otg_pcd_request_t * req)
  53593. +{
  53594. + /* @todo: MAS - add implementation when this feature needs to be tested */
  53595. +}
  53596. +
  53597. +/**
  53598. + * This function builds the DMA descriptors for the Alignment buffer mode
  53599. + */
  53600. +static void cfi_build_align_descs(struct cfiobject *cfi, cfi_ep_t * cfiep,
  53601. + dwc_otg_pcd_request_t * req)
  53602. +{
  53603. + struct dwc_otg_pcd_ep *ep = cfiep->ep;
  53604. + ddma_align_buffer_setup_t *alignval = cfiep->bm_align;
  53605. + struct dwc_otg_dma_desc *desc = cfiep->ep->dwc_ep.descs;
  53606. + dma_addr_t buff_addr = req->dma;
  53607. +
  53608. + desc->status.b.bs = BS_HOST_BUSY;
  53609. + desc->status.b.l = 1;
  53610. + desc->status.b.ioc = 1;
  53611. + desc->status.b.sp = ep->dwc_ep.sent_zlp;
  53612. + desc->status.b.bytes = req->length;
  53613. + /* Adjust the buffer alignment */
  53614. + desc->buf = (buff_addr + alignval->bAlign);
  53615. + desc->status.b.bs = BS_HOST_READY;
  53616. + cfiep->dma_desc_last = desc;
  53617. + cfiep->desc_count = 1;
  53618. +}
  53619. +
  53620. +/**
  53621. + * This function builds the DMA descriptors chain for different modes of the
  53622. + * buffer setup of an endpoint.
  53623. + */
  53624. +static void cfi_build_descriptors(struct cfiobject *cfi,
  53625. + struct dwc_otg_pcd *pcd,
  53626. + struct dwc_otg_pcd_ep *ep,
  53627. + dwc_otg_pcd_request_t * req)
  53628. +{
  53629. + cfi_ep_t *cfiep;
  53630. +
  53631. + /* Get the cfiep by the dwc_otg_pcd_ep */
  53632. + cfiep = get_cfi_ep_by_pcd_ep(cfi, ep);
  53633. + if (NULL == cfiep) {
  53634. + CFI_INFO("%s: Unable to find a matching active endpoint\n",
  53635. + __func__);
  53636. + return;
  53637. + }
  53638. +
  53639. + cfiep->xfer_len = req->length;
  53640. +
  53641. + /* Iterate through all the DMA descriptors */
  53642. + switch (cfiep->ep->dwc_ep.buff_mode) {
  53643. + case BM_SG:
  53644. + cfi_build_sg_descs(cfi, cfiep, req);
  53645. + break;
  53646. +
  53647. + case BM_CONCAT:
  53648. + cfi_build_concat_descs(cfi, cfiep, req);
  53649. + break;
  53650. +
  53651. + case BM_CIRCULAR:
  53652. + cfi_build_circ_descs(cfi, cfiep, req);
  53653. + break;
  53654. +
  53655. + case BM_ALIGN:
  53656. + cfi_build_align_descs(cfi, cfiep, req);
  53657. + break;
  53658. +
  53659. + default:
  53660. + break;
  53661. + }
  53662. +}
  53663. +
  53664. +/**
  53665. + * Allocate DMA buffer for different Buffer modes.
  53666. + */
  53667. +static void *cfi_ep_alloc_buf(struct cfiobject *cfi, struct dwc_otg_pcd *pcd,
  53668. + struct dwc_otg_pcd_ep *ep, dma_addr_t * dma,
  53669. + unsigned size, gfp_t flags)
  53670. +{
  53671. + return DWC_DMA_ALLOC(size, dma);
  53672. +}
  53673. +
  53674. +/**
  53675. + * This function initializes the CFI object.
  53676. + */
  53677. +int init_cfi(cfiobject_t * cfiobj)
  53678. +{
  53679. + CFI_INFO("%s\n", __func__);
  53680. +
  53681. + /* Allocate a buffer for IN XFERs */
  53682. + cfiobj->buf_in.buf =
  53683. + DWC_DMA_ALLOC(CFI_IN_BUF_LEN, &cfiobj->buf_in.addr);
  53684. + if (NULL == cfiobj->buf_in.buf) {
  53685. + CFI_INFO("Unable to allocate buffer for INs\n");
  53686. + return -DWC_E_NO_MEMORY;
  53687. + }
  53688. +
  53689. + /* Allocate a buffer for OUT XFERs */
  53690. + cfiobj->buf_out.buf =
  53691. + DWC_DMA_ALLOC(CFI_OUT_BUF_LEN, &cfiobj->buf_out.addr);
  53692. + if (NULL == cfiobj->buf_out.buf) {
  53693. + CFI_INFO("Unable to allocate buffer for OUT\n");
  53694. + return -DWC_E_NO_MEMORY;
  53695. + }
  53696. +
  53697. + /* Initialize the callback function pointers */
  53698. + cfiobj->ops.release = cfi_release;
  53699. + cfiobj->ops.ep_enable = cfi_ep_enable;
  53700. + cfiobj->ops.ctrl_write_complete = cfi_ctrl_write_complete;
  53701. + cfiobj->ops.build_descriptors = cfi_build_descriptors;
  53702. + cfiobj->ops.ep_alloc_buf = cfi_ep_alloc_buf;
  53703. +
  53704. + /* Initialize the list of active endpoints in the CFI object */
  53705. + DWC_LIST_INIT(&cfiobj->active_eps);
  53706. +
  53707. + return 0;
  53708. +}
  53709. +
  53710. +/**
  53711. + * This function reads the required feature's current value into the buffer
  53712. + *
  53713. + * @retval: Returns negative as error, or the data length of the feature
  53714. + */
  53715. +static int cfi_get_feature_value(uint8_t * buf, uint16_t buflen,
  53716. + struct dwc_otg_pcd *pcd,
  53717. + struct cfi_usb_ctrlrequest *ctrl_req)
  53718. +{
  53719. + int retval = -DWC_E_NOT_SUPPORTED;
  53720. + struct dwc_otg_core_if *coreif = GET_CORE_IF(pcd);
  53721. + uint16_t dfifo, rxfifo, txfifo;
  53722. +
  53723. + switch (ctrl_req->wIndex) {
  53724. + /* Whether the DDMA is enabled or not */
  53725. + case FT_ID_DMA_MODE:
  53726. + *buf = (coreif->dma_enable && coreif->dma_desc_enable) ? 1 : 0;
  53727. + retval = 1;
  53728. + break;
  53729. +
  53730. + case FT_ID_DMA_BUFFER_SETUP:
  53731. + retval = cfi_ep_get_sg_val(buf, pcd, ctrl_req);
  53732. + break;
  53733. +
  53734. + case FT_ID_DMA_BUFF_ALIGN:
  53735. + retval = cfi_ep_get_align_val(buf, pcd, ctrl_req);
  53736. + break;
  53737. +
  53738. + case FT_ID_DMA_CONCAT_SETUP:
  53739. + retval = cfi_ep_get_concat_val(buf, pcd, ctrl_req);
  53740. + break;
  53741. +
  53742. + case FT_ID_DMA_CIRCULAR:
  53743. + CFI_INFO("GetFeature value (FT_ID_DMA_CIRCULAR)\n");
  53744. + break;
  53745. +
  53746. + case FT_ID_THRESHOLD_SETUP:
  53747. + CFI_INFO("GetFeature value (FT_ID_THRESHOLD_SETUP)\n");
  53748. + break;
  53749. +
  53750. + case FT_ID_DFIFO_DEPTH:
  53751. + dfifo = get_dfifo_size(coreif);
  53752. + *((uint16_t *) buf) = dfifo;
  53753. + retval = sizeof(uint16_t);
  53754. + break;
  53755. +
  53756. + case FT_ID_TX_FIFO_DEPTH:
  53757. + retval = get_txfifo_size(pcd, ctrl_req->wValue);
  53758. + if (retval >= 0) {
  53759. + txfifo = retval;
  53760. + *((uint16_t *) buf) = txfifo;
  53761. + retval = sizeof(uint16_t);
  53762. + }
  53763. + break;
  53764. +
  53765. + case FT_ID_RX_FIFO_DEPTH:
  53766. + retval = get_rxfifo_size(coreif, ctrl_req->wValue);
  53767. + if (retval >= 0) {
  53768. + rxfifo = retval;
  53769. + *((uint16_t *) buf) = rxfifo;
  53770. + retval = sizeof(uint16_t);
  53771. + }
  53772. + break;
  53773. + }
  53774. +
  53775. + return retval;
  53776. +}
  53777. +
  53778. +/**
  53779. + * This function resets the SG for the specified EP to its default value
  53780. + */
  53781. +static int cfi_reset_sg_val(cfi_ep_t * cfiep)
  53782. +{
  53783. + dwc_memset(cfiep->bm_sg, 0, sizeof(ddma_sg_buffer_setup_t));
  53784. + return 0;
  53785. +}
  53786. +
  53787. +/**
  53788. + * This function resets the Alignment for the specified EP to its default value
  53789. + */
  53790. +static int cfi_reset_align_val(cfi_ep_t * cfiep)
  53791. +{
  53792. + dwc_memset(cfiep->bm_sg, 0, sizeof(ddma_sg_buffer_setup_t));
  53793. + return 0;
  53794. +}
  53795. +
  53796. +/**
  53797. + * This function resets the Concatenation for the specified EP to its default value
  53798. + * This function will also set the value of the wTxBytes field to NULL after
  53799. + * freeing the memory previously allocated for this field.
  53800. + */
  53801. +static int cfi_reset_concat_val(cfi_ep_t * cfiep)
  53802. +{
  53803. + /* First we need to free the wTxBytes field */
  53804. + if (cfiep->bm_concat->wTxBytes) {
  53805. + DWC_FREE(cfiep->bm_concat->wTxBytes);
  53806. + cfiep->bm_concat->wTxBytes = NULL;
  53807. + }
  53808. +
  53809. + dwc_memset(cfiep->bm_concat, 0, sizeof(ddma_concat_buffer_setup_t));
  53810. + return 0;
  53811. +}
  53812. +
  53813. +/**
  53814. + * This function resets all the buffer setups of the specified endpoint
  53815. + */
  53816. +static int cfi_ep_reset_all_setup_vals(cfi_ep_t * cfiep)
  53817. +{
  53818. + cfi_reset_sg_val(cfiep);
  53819. + cfi_reset_align_val(cfiep);
  53820. + cfi_reset_concat_val(cfiep);
  53821. + return 0;
  53822. +}
  53823. +
  53824. +static int cfi_handle_reset_fifo_val(struct dwc_otg_pcd *pcd, uint8_t ep_addr,
  53825. + uint8_t rx_rst, uint8_t tx_rst)
  53826. +{
  53827. + int retval = -DWC_E_INVALID;
  53828. + uint16_t tx_siz[15];
  53829. + uint16_t rx_siz = 0;
  53830. + dwc_otg_pcd_ep_t *ep = NULL;
  53831. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  53832. + dwc_otg_core_params_t *params = GET_CORE_IF(pcd)->core_params;
  53833. +
  53834. + if (rx_rst) {
  53835. + rx_siz = params->dev_rx_fifo_size;
  53836. + params->dev_rx_fifo_size = GET_CORE_IF(pcd)->init_rxfsiz;
  53837. + }
  53838. +
  53839. + if (tx_rst) {
  53840. + if (ep_addr == 0) {
  53841. + int i;
  53842. +
  53843. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  53844. + tx_siz[i] =
  53845. + core_if->core_params->dev_tx_fifo_size[i];
  53846. + core_if->core_params->dev_tx_fifo_size[i] =
  53847. + core_if->init_txfsiz[i];
  53848. + }
  53849. + } else {
  53850. +
  53851. + ep = get_ep_by_addr(pcd, ep_addr);
  53852. +
  53853. + if (NULL == ep) {
  53854. + CFI_INFO
  53855. + ("%s: Unable to get the endpoint addr=0x%02x\n",
  53856. + __func__, ep_addr);
  53857. + return -DWC_E_INVALID;
  53858. + }
  53859. +
  53860. + tx_siz[0] =
  53861. + params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num -
  53862. + 1];
  53863. + params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num - 1] =
  53864. + GET_CORE_IF(pcd)->init_txfsiz[ep->
  53865. + dwc_ep.tx_fifo_num -
  53866. + 1];
  53867. + }
  53868. + }
  53869. +
  53870. + if (resize_fifos(GET_CORE_IF(pcd))) {
  53871. + retval = 0;
  53872. + } else {
  53873. + CFI_INFO
  53874. + ("%s: Error resetting the feature Reset All(FIFO size)\n",
  53875. + __func__);
  53876. + if (rx_rst) {
  53877. + params->dev_rx_fifo_size = rx_siz;
  53878. + }
  53879. +
  53880. + if (tx_rst) {
  53881. + if (ep_addr == 0) {
  53882. + int i;
  53883. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps;
  53884. + i++) {
  53885. + core_if->
  53886. + core_params->dev_tx_fifo_size[i] =
  53887. + tx_siz[i];
  53888. + }
  53889. + } else {
  53890. + params->dev_tx_fifo_size[ep->
  53891. + dwc_ep.tx_fifo_num -
  53892. + 1] = tx_siz[0];
  53893. + }
  53894. + }
  53895. + retval = -DWC_E_INVALID;
  53896. + }
  53897. + return retval;
  53898. +}
  53899. +
  53900. +static int cfi_handle_reset_all(struct dwc_otg_pcd *pcd, uint8_t addr)
  53901. +{
  53902. + int retval = 0;
  53903. + cfi_ep_t *cfiep;
  53904. + cfiobject_t *cfi = pcd->cfi;
  53905. + dwc_list_link_t *tmp;
  53906. +
  53907. + retval = cfi_handle_reset_fifo_val(pcd, addr, 1, 1);
  53908. + if (retval < 0) {
  53909. + return retval;
  53910. + }
  53911. +
  53912. + /* If the EP address is known then reset the features for only that EP */
  53913. + if (addr) {
  53914. + cfiep = get_cfi_ep_by_addr(pcd->cfi, addr);
  53915. + if (NULL == cfiep) {
  53916. + CFI_INFO("%s: Error getting the EP address 0x%02x\n",
  53917. + __func__, addr);
  53918. + return -DWC_E_INVALID;
  53919. + }
  53920. + retval = cfi_ep_reset_all_setup_vals(cfiep);
  53921. + cfiep->ep->dwc_ep.buff_mode = BM_STANDARD;
  53922. + }
  53923. + /* Otherwise (wValue == 0), reset all features of all EP's */
  53924. + else {
  53925. + /* Traverse all the active EP's and reset the feature(s) value(s) */
  53926. + //list_for_each_entry(cfiep, &cfi->active_eps, lh) {
  53927. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  53928. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  53929. + retval = cfi_ep_reset_all_setup_vals(cfiep);
  53930. + cfiep->ep->dwc_ep.buff_mode = BM_STANDARD;
  53931. + if (retval < 0) {
  53932. + CFI_INFO
  53933. + ("%s: Error resetting the feature Reset All\n",
  53934. + __func__);
  53935. + return retval;
  53936. + }
  53937. + }
  53938. + }
  53939. + return retval;
  53940. +}
  53941. +
  53942. +static int cfi_handle_reset_dma_buff_setup(struct dwc_otg_pcd *pcd,
  53943. + uint8_t addr)
  53944. +{
  53945. + int retval = 0;
  53946. + cfi_ep_t *cfiep;
  53947. + cfiobject_t *cfi = pcd->cfi;
  53948. + dwc_list_link_t *tmp;
  53949. +
  53950. + /* If the EP address is known then reset the features for only that EP */
  53951. + if (addr) {
  53952. + cfiep = get_cfi_ep_by_addr(pcd->cfi, addr);
  53953. + if (NULL == cfiep) {
  53954. + CFI_INFO("%s: Error getting the EP address 0x%02x\n",
  53955. + __func__, addr);
  53956. + return -DWC_E_INVALID;
  53957. + }
  53958. + retval = cfi_reset_sg_val(cfiep);
  53959. + }
  53960. + /* Otherwise (wValue == 0), reset all features of all EP's */
  53961. + else {
  53962. + /* Traverse all the active EP's and reset the feature(s) value(s) */
  53963. + //list_for_each_entry(cfiep, &cfi->active_eps, lh) {
  53964. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  53965. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  53966. + retval = cfi_reset_sg_val(cfiep);
  53967. + if (retval < 0) {
  53968. + CFI_INFO
  53969. + ("%s: Error resetting the feature Buffer Setup\n",
  53970. + __func__);
  53971. + return retval;
  53972. + }
  53973. + }
  53974. + }
  53975. + return retval;
  53976. +}
  53977. +
  53978. +static int cfi_handle_reset_concat_val(struct dwc_otg_pcd *pcd, uint8_t addr)
  53979. +{
  53980. + int retval = 0;
  53981. + cfi_ep_t *cfiep;
  53982. + cfiobject_t *cfi = pcd->cfi;
  53983. + dwc_list_link_t *tmp;
  53984. +
  53985. + /* If the EP address is known then reset the features for only that EP */
  53986. + if (addr) {
  53987. + cfiep = get_cfi_ep_by_addr(pcd->cfi, addr);
  53988. + if (NULL == cfiep) {
  53989. + CFI_INFO("%s: Error getting the EP address 0x%02x\n",
  53990. + __func__, addr);
  53991. + return -DWC_E_INVALID;
  53992. + }
  53993. + retval = cfi_reset_concat_val(cfiep);
  53994. + }
  53995. + /* Otherwise (wValue == 0), reset all features of all EP's */
  53996. + else {
  53997. + /* Traverse all the active EP's and reset the feature(s) value(s) */
  53998. + //list_for_each_entry(cfiep, &cfi->active_eps, lh) {
  53999. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  54000. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  54001. + retval = cfi_reset_concat_val(cfiep);
  54002. + if (retval < 0) {
  54003. + CFI_INFO
  54004. + ("%s: Error resetting the feature Concatenation Value\n",
  54005. + __func__);
  54006. + return retval;
  54007. + }
  54008. + }
  54009. + }
  54010. + return retval;
  54011. +}
  54012. +
  54013. +static int cfi_handle_reset_align_val(struct dwc_otg_pcd *pcd, uint8_t addr)
  54014. +{
  54015. + int retval = 0;
  54016. + cfi_ep_t *cfiep;
  54017. + cfiobject_t *cfi = pcd->cfi;
  54018. + dwc_list_link_t *tmp;
  54019. +
  54020. + /* If the EP address is known then reset the features for only that EP */
  54021. + if (addr) {
  54022. + cfiep = get_cfi_ep_by_addr(pcd->cfi, addr);
  54023. + if (NULL == cfiep) {
  54024. + CFI_INFO("%s: Error getting the EP address 0x%02x\n",
  54025. + __func__, addr);
  54026. + return -DWC_E_INVALID;
  54027. + }
  54028. + retval = cfi_reset_align_val(cfiep);
  54029. + }
  54030. + /* Otherwise (wValue == 0), reset all features of all EP's */
  54031. + else {
  54032. + /* Traverse all the active EP's and reset the feature(s) value(s) */
  54033. + //list_for_each_entry(cfiep, &cfi->active_eps, lh) {
  54034. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  54035. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  54036. + retval = cfi_reset_align_val(cfiep);
  54037. + if (retval < 0) {
  54038. + CFI_INFO
  54039. + ("%s: Error resetting the feature Aliignment Value\n",
  54040. + __func__);
  54041. + return retval;
  54042. + }
  54043. + }
  54044. + }
  54045. + return retval;
  54046. +
  54047. +}
  54048. +
  54049. +static int cfi_preproc_reset(struct dwc_otg_pcd *pcd,
  54050. + struct cfi_usb_ctrlrequest *req)
  54051. +{
  54052. + int retval = 0;
  54053. +
  54054. + switch (req->wIndex) {
  54055. + case 0:
  54056. + /* Reset all features */
  54057. + retval = cfi_handle_reset_all(pcd, req->wValue & 0xff);
  54058. + break;
  54059. +
  54060. + case FT_ID_DMA_BUFFER_SETUP:
  54061. + /* Reset the SG buffer setup */
  54062. + retval =
  54063. + cfi_handle_reset_dma_buff_setup(pcd, req->wValue & 0xff);
  54064. + break;
  54065. +
  54066. + case FT_ID_DMA_CONCAT_SETUP:
  54067. + /* Reset the Concatenation buffer setup */
  54068. + retval = cfi_handle_reset_concat_val(pcd, req->wValue & 0xff);
  54069. + break;
  54070. +
  54071. + case FT_ID_DMA_BUFF_ALIGN:
  54072. + /* Reset the Alignment buffer setup */
  54073. + retval = cfi_handle_reset_align_val(pcd, req->wValue & 0xff);
  54074. + break;
  54075. +
  54076. + case FT_ID_TX_FIFO_DEPTH:
  54077. + retval =
  54078. + cfi_handle_reset_fifo_val(pcd, req->wValue & 0xff, 0, 1);
  54079. + pcd->cfi->need_gadget_att = 0;
  54080. + break;
  54081. +
  54082. + case FT_ID_RX_FIFO_DEPTH:
  54083. + retval = cfi_handle_reset_fifo_val(pcd, 0, 1, 0);
  54084. + pcd->cfi->need_gadget_att = 0;
  54085. + break;
  54086. + default:
  54087. + break;
  54088. + }
  54089. + return retval;
  54090. +}
  54091. +
  54092. +/**
  54093. + * This function sets a new value for the SG buffer setup.
  54094. + */
  54095. +static int cfi_ep_set_sg_val(uint8_t * buf, struct dwc_otg_pcd *pcd)
  54096. +{
  54097. + uint8_t inaddr, outaddr;
  54098. + cfi_ep_t *epin, *epout;
  54099. + ddma_sg_buffer_setup_t *psgval;
  54100. + uint32_t desccount, size;
  54101. +
  54102. + CFI_INFO("%s\n", __func__);
  54103. +
  54104. + psgval = (ddma_sg_buffer_setup_t *) buf;
  54105. + desccount = (uint32_t) psgval->bCount;
  54106. + size = (uint32_t) psgval->wSize;
  54107. +
  54108. + /* Check the DMA descriptor count */
  54109. + if ((desccount > MAX_DMA_DESCS_PER_EP) || (desccount == 0)) {
  54110. + CFI_INFO
  54111. + ("%s: The count of DMA Descriptors should be between 1 and %d\n",
  54112. + __func__, MAX_DMA_DESCS_PER_EP);
  54113. + return -DWC_E_INVALID;
  54114. + }
  54115. +
  54116. + /* Check the DMA descriptor count */
  54117. +
  54118. + if (size == 0) {
  54119. +
  54120. + CFI_INFO("%s: The transfer size should be at least 1 byte\n",
  54121. + __func__);
  54122. +
  54123. + return -DWC_E_INVALID;
  54124. +
  54125. + }
  54126. +
  54127. + inaddr = psgval->bInEndpointAddress;
  54128. + outaddr = psgval->bOutEndpointAddress;
  54129. +
  54130. + epin = get_cfi_ep_by_addr(pcd->cfi, inaddr);
  54131. + epout = get_cfi_ep_by_addr(pcd->cfi, outaddr);
  54132. +
  54133. + if (NULL == epin || NULL == epout) {
  54134. + CFI_INFO
  54135. + ("%s: Unable to get the endpoints inaddr=0x%02x outaddr=0x%02x\n",
  54136. + __func__, inaddr, outaddr);
  54137. + return -DWC_E_INVALID;
  54138. + }
  54139. +
  54140. + epin->ep->dwc_ep.buff_mode = BM_SG;
  54141. + dwc_memcpy(epin->bm_sg, psgval, sizeof(ddma_sg_buffer_setup_t));
  54142. +
  54143. + epout->ep->dwc_ep.buff_mode = BM_SG;
  54144. + dwc_memcpy(epout->bm_sg, psgval, sizeof(ddma_sg_buffer_setup_t));
  54145. +
  54146. + return 0;
  54147. +}
  54148. +
  54149. +/**
  54150. + * This function sets a new value for the buffer Alignment setup.
  54151. + */
  54152. +static int cfi_ep_set_alignment_val(uint8_t * buf, struct dwc_otg_pcd *pcd)
  54153. +{
  54154. + cfi_ep_t *ep;
  54155. + uint8_t addr;
  54156. + ddma_align_buffer_setup_t *palignval;
  54157. +
  54158. + palignval = (ddma_align_buffer_setup_t *) buf;
  54159. + addr = palignval->bEndpointAddress;
  54160. +
  54161. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  54162. +
  54163. + if (NULL == ep) {
  54164. + CFI_INFO("%s: Unable to get the endpoint addr=0x%02x\n",
  54165. + __func__, addr);
  54166. + return -DWC_E_INVALID;
  54167. + }
  54168. +
  54169. + ep->ep->dwc_ep.buff_mode = BM_ALIGN;
  54170. + dwc_memcpy(ep->bm_align, palignval, sizeof(ddma_align_buffer_setup_t));
  54171. +
  54172. + return 0;
  54173. +}
  54174. +
  54175. +/**
  54176. + * This function sets a new value for the Concatenation buffer setup.
  54177. + */
  54178. +static int cfi_ep_set_concat_val(uint8_t * buf, struct dwc_otg_pcd *pcd)
  54179. +{
  54180. + uint8_t addr;
  54181. + cfi_ep_t *ep;
  54182. + struct _ddma_concat_buffer_setup_hdr *pConcatValHdr;
  54183. + uint16_t *pVals;
  54184. + uint32_t desccount;
  54185. + int i;
  54186. + uint16_t mps;
  54187. +
  54188. + pConcatValHdr = (struct _ddma_concat_buffer_setup_hdr *)buf;
  54189. + desccount = (uint32_t) pConcatValHdr->bDescCount;
  54190. + pVals = (uint16_t *) (buf + BS_CONCAT_VAL_HDR_LEN);
  54191. +
  54192. + /* Check the DMA descriptor count */
  54193. + if (desccount > MAX_DMA_DESCS_PER_EP) {
  54194. + CFI_INFO("%s: Maximum DMA Descriptor count should be %d\n",
  54195. + __func__, MAX_DMA_DESCS_PER_EP);
  54196. + return -DWC_E_INVALID;
  54197. + }
  54198. +
  54199. + addr = pConcatValHdr->bEndpointAddress;
  54200. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  54201. + if (NULL == ep) {
  54202. + CFI_INFO("%s: Unable to get the endpoint addr=0x%02x\n",
  54203. + __func__, addr);
  54204. + return -DWC_E_INVALID;
  54205. + }
  54206. +
  54207. + mps = UGETW(ep->ep->desc->wMaxPacketSize);
  54208. +
  54209. +#if 0
  54210. + for (i = 0; i < desccount; i++) {
  54211. + CFI_INFO("%s: wTxSize[%d]=0x%04x\n", __func__, i, pVals[i]);
  54212. + }
  54213. + CFI_INFO("%s: epname=%s; mps=%d\n", __func__, ep->ep->ep.name, mps);
  54214. +#endif
  54215. +
  54216. + /* Check the wTxSizes to be less than or equal to the mps */
  54217. + for (i = 0; i < desccount; i++) {
  54218. + if (pVals[i] > mps) {
  54219. + CFI_INFO
  54220. + ("%s: ERROR - the wTxSize[%d] should be <= MPS (wTxSize=%d)\n",
  54221. + __func__, i, pVals[i]);
  54222. + return -DWC_E_INVALID;
  54223. + }
  54224. + }
  54225. +
  54226. + ep->ep->dwc_ep.buff_mode = BM_CONCAT;
  54227. + dwc_memcpy(ep->bm_concat, pConcatValHdr, BS_CONCAT_VAL_HDR_LEN);
  54228. +
  54229. + /* Free the previously allocated storage for the wTxBytes */
  54230. + if (ep->bm_concat->wTxBytes) {
  54231. + DWC_FREE(ep->bm_concat->wTxBytes);
  54232. + }
  54233. +
  54234. + /* Allocate a new storage for the wTxBytes field */
  54235. + ep->bm_concat->wTxBytes =
  54236. + DWC_ALLOC(sizeof(uint16_t) * pConcatValHdr->bDescCount);
  54237. + if (NULL == ep->bm_concat->wTxBytes) {
  54238. + CFI_INFO("%s: Unable to allocate memory\n", __func__);
  54239. + return -DWC_E_NO_MEMORY;
  54240. + }
  54241. +
  54242. + /* Copy the new values into the wTxBytes filed */
  54243. + dwc_memcpy(ep->bm_concat->wTxBytes, buf + BS_CONCAT_VAL_HDR_LEN,
  54244. + sizeof(uint16_t) * pConcatValHdr->bDescCount);
  54245. +
  54246. + return 0;
  54247. +}
  54248. +
  54249. +/**
  54250. + * This function calculates the total of all FIFO sizes
  54251. + *
  54252. + * @param core_if Programming view of DWC_otg controller
  54253. + *
  54254. + * @return The total of data FIFO sizes.
  54255. + *
  54256. + */
  54257. +static uint16_t get_dfifo_size(dwc_otg_core_if_t * core_if)
  54258. +{
  54259. + dwc_otg_core_params_t *params = core_if->core_params;
  54260. + uint16_t dfifo_total = 0;
  54261. + int i;
  54262. +
  54263. + /* The shared RxFIFO size */
  54264. + dfifo_total =
  54265. + params->dev_rx_fifo_size + params->dev_nperio_tx_fifo_size;
  54266. +
  54267. + /* Add up each TxFIFO size to the total */
  54268. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  54269. + dfifo_total += params->dev_tx_fifo_size[i];
  54270. + }
  54271. +
  54272. + return dfifo_total;
  54273. +}
  54274. +
  54275. +/**
  54276. + * This function returns Rx FIFO size
  54277. + *
  54278. + * @param core_if Programming view of DWC_otg controller
  54279. + *
  54280. + * @return The total of data FIFO sizes.
  54281. + *
  54282. + */
  54283. +static int32_t get_rxfifo_size(dwc_otg_core_if_t * core_if, uint16_t wValue)
  54284. +{
  54285. + switch (wValue >> 8) {
  54286. + case 0:
  54287. + return (core_if->pwron_rxfsiz <
  54288. + 32768) ? core_if->pwron_rxfsiz : 32768;
  54289. + break;
  54290. + case 1:
  54291. + return core_if->core_params->dev_rx_fifo_size;
  54292. + break;
  54293. + default:
  54294. + return -DWC_E_INVALID;
  54295. + break;
  54296. + }
  54297. +}
  54298. +
  54299. +/**
  54300. + * This function returns Tx FIFO size for IN EP
  54301. + *
  54302. + * @param core_if Programming view of DWC_otg controller
  54303. + *
  54304. + * @return The total of data FIFO sizes.
  54305. + *
  54306. + */
  54307. +static int32_t get_txfifo_size(struct dwc_otg_pcd *pcd, uint16_t wValue)
  54308. +{
  54309. + dwc_otg_pcd_ep_t *ep;
  54310. +
  54311. + ep = get_ep_by_addr(pcd, wValue & 0xff);
  54312. +
  54313. + if (NULL == ep) {
  54314. + CFI_INFO("%s: Unable to get the endpoint addr=0x%02x\n",
  54315. + __func__, wValue & 0xff);
  54316. + return -DWC_E_INVALID;
  54317. + }
  54318. +
  54319. + if (!ep->dwc_ep.is_in) {
  54320. + CFI_INFO
  54321. + ("%s: No Tx FIFO assingned to the Out endpoint addr=0x%02x\n",
  54322. + __func__, wValue & 0xff);
  54323. + return -DWC_E_INVALID;
  54324. + }
  54325. +
  54326. + switch (wValue >> 8) {
  54327. + case 0:
  54328. + return (GET_CORE_IF(pcd)->pwron_txfsiz
  54329. + [ep->dwc_ep.tx_fifo_num - 1] <
  54330. + 768) ? GET_CORE_IF(pcd)->pwron_txfsiz[ep->
  54331. + dwc_ep.tx_fifo_num
  54332. + - 1] : 32768;
  54333. + break;
  54334. + case 1:
  54335. + return GET_CORE_IF(pcd)->core_params->
  54336. + dev_tx_fifo_size[ep->dwc_ep.num - 1];
  54337. + break;
  54338. + default:
  54339. + return -DWC_E_INVALID;
  54340. + break;
  54341. + }
  54342. +}
  54343. +
  54344. +/**
  54345. + * This function checks if the submitted combination of
  54346. + * device mode FIFO sizes is possible or not.
  54347. + *
  54348. + * @param core_if Programming view of DWC_otg controller
  54349. + *
  54350. + * @return 1 if possible, 0 otherwise.
  54351. + *
  54352. + */
  54353. +static uint8_t check_fifo_sizes(dwc_otg_core_if_t * core_if)
  54354. +{
  54355. + uint16_t dfifo_actual = 0;
  54356. + dwc_otg_core_params_t *params = core_if->core_params;
  54357. + uint16_t start_addr = 0;
  54358. + int i;
  54359. +
  54360. + dfifo_actual =
  54361. + params->dev_rx_fifo_size + params->dev_nperio_tx_fifo_size;
  54362. +
  54363. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  54364. + dfifo_actual += params->dev_tx_fifo_size[i];
  54365. + }
  54366. +
  54367. + if (dfifo_actual > core_if->total_fifo_size) {
  54368. + return 0;
  54369. + }
  54370. +
  54371. + if (params->dev_rx_fifo_size > 32768 || params->dev_rx_fifo_size < 16)
  54372. + return 0;
  54373. +
  54374. + if (params->dev_nperio_tx_fifo_size > 32768
  54375. + || params->dev_nperio_tx_fifo_size < 16)
  54376. + return 0;
  54377. +
  54378. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  54379. +
  54380. + if (params->dev_tx_fifo_size[i] > 768
  54381. + || params->dev_tx_fifo_size[i] < 4)
  54382. + return 0;
  54383. + }
  54384. +
  54385. + if (params->dev_rx_fifo_size > core_if->pwron_rxfsiz)
  54386. + return 0;
  54387. + start_addr = params->dev_rx_fifo_size;
  54388. +
  54389. + if (params->dev_nperio_tx_fifo_size > core_if->pwron_gnptxfsiz)
  54390. + return 0;
  54391. + start_addr += params->dev_nperio_tx_fifo_size;
  54392. +
  54393. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  54394. +
  54395. + if (params->dev_tx_fifo_size[i] > core_if->pwron_txfsiz[i])
  54396. + return 0;
  54397. + start_addr += params->dev_tx_fifo_size[i];
  54398. + }
  54399. +
  54400. + return 1;
  54401. +}
  54402. +
  54403. +/**
  54404. + * This function resizes Device mode FIFOs
  54405. + *
  54406. + * @param core_if Programming view of DWC_otg controller
  54407. + *
  54408. + * @return 1 if successful, 0 otherwise
  54409. + *
  54410. + */
  54411. +static uint8_t resize_fifos(dwc_otg_core_if_t * core_if)
  54412. +{
  54413. + int i = 0;
  54414. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  54415. + dwc_otg_core_params_t *params = core_if->core_params;
  54416. + uint32_t rx_fifo_size;
  54417. + fifosize_data_t nptxfifosize;
  54418. + fifosize_data_t txfifosize[15];
  54419. +
  54420. + uint32_t rx_fsz_bak;
  54421. + uint32_t nptxfsz_bak;
  54422. + uint32_t txfsz_bak[15];
  54423. +
  54424. + uint16_t start_address;
  54425. + uint8_t retval = 1;
  54426. +
  54427. + if (!check_fifo_sizes(core_if)) {
  54428. + return 0;
  54429. + }
  54430. +
  54431. + /* Configure data FIFO sizes */
  54432. + if (core_if->hwcfg2.b.dynamic_fifo && params->enable_dynamic_fifo) {
  54433. + rx_fsz_bak = DWC_READ_REG32(&global_regs->grxfsiz);
  54434. + rx_fifo_size = params->dev_rx_fifo_size;
  54435. + DWC_WRITE_REG32(&global_regs->grxfsiz, rx_fifo_size);
  54436. +
  54437. + /*
  54438. + * Tx FIFOs These FIFOs are numbered from 1 to 15.
  54439. + * Indexes of the FIFO size module parameters in the
  54440. + * dev_tx_fifo_size array and the FIFO size registers in
  54441. + * the dtxfsiz array run from 0 to 14.
  54442. + */
  54443. +
  54444. + /* Non-periodic Tx FIFO */
  54445. + nptxfsz_bak = DWC_READ_REG32(&global_regs->gnptxfsiz);
  54446. + nptxfifosize.b.depth = params->dev_nperio_tx_fifo_size;
  54447. + start_address = params->dev_rx_fifo_size;
  54448. + nptxfifosize.b.startaddr = start_address;
  54449. +
  54450. + DWC_WRITE_REG32(&global_regs->gnptxfsiz, nptxfifosize.d32);
  54451. +
  54452. + start_address += nptxfifosize.b.depth;
  54453. +
  54454. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  54455. + txfsz_bak[i] = DWC_READ_REG32(&global_regs->dtxfsiz[i]);
  54456. +
  54457. + txfifosize[i].b.depth = params->dev_tx_fifo_size[i];
  54458. + txfifosize[i].b.startaddr = start_address;
  54459. + DWC_WRITE_REG32(&global_regs->dtxfsiz[i],
  54460. + txfifosize[i].d32);
  54461. +
  54462. + start_address += txfifosize[i].b.depth;
  54463. + }
  54464. +
  54465. + /** Check if register values are set correctly */
  54466. + if (rx_fifo_size != DWC_READ_REG32(&global_regs->grxfsiz)) {
  54467. + retval = 0;
  54468. + }
  54469. +
  54470. + if (nptxfifosize.d32 != DWC_READ_REG32(&global_regs->gnptxfsiz)) {
  54471. + retval = 0;
  54472. + }
  54473. +
  54474. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  54475. + if (txfifosize[i].d32 !=
  54476. + DWC_READ_REG32(&global_regs->dtxfsiz[i])) {
  54477. + retval = 0;
  54478. + }
  54479. + }
  54480. +
  54481. + /** If register values are not set correctly, reset old values */
  54482. + if (retval == 0) {
  54483. + DWC_WRITE_REG32(&global_regs->grxfsiz, rx_fsz_bak);
  54484. +
  54485. + /* Non-periodic Tx FIFO */
  54486. + DWC_WRITE_REG32(&global_regs->gnptxfsiz, nptxfsz_bak);
  54487. +
  54488. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  54489. + DWC_WRITE_REG32(&global_regs->dtxfsiz[i],
  54490. + txfsz_bak[i]);
  54491. + }
  54492. + }
  54493. + } else {
  54494. + return 0;
  54495. + }
  54496. +
  54497. + /* Flush the FIFOs */
  54498. + dwc_otg_flush_tx_fifo(core_if, 0x10); /* all Tx FIFOs */
  54499. + dwc_otg_flush_rx_fifo(core_if);
  54500. +
  54501. + return retval;
  54502. +}
  54503. +
  54504. +/**
  54505. + * This function sets a new value for the buffer Alignment setup.
  54506. + */
  54507. +static int cfi_ep_set_tx_fifo_val(uint8_t * buf, dwc_otg_pcd_t * pcd)
  54508. +{
  54509. + int retval;
  54510. + uint32_t fsiz;
  54511. + uint16_t size;
  54512. + uint16_t ep_addr;
  54513. + dwc_otg_pcd_ep_t *ep;
  54514. + dwc_otg_core_params_t *params = GET_CORE_IF(pcd)->core_params;
  54515. + tx_fifo_size_setup_t *ptxfifoval;
  54516. +
  54517. + ptxfifoval = (tx_fifo_size_setup_t *) buf;
  54518. + ep_addr = ptxfifoval->bEndpointAddress;
  54519. + size = ptxfifoval->wDepth;
  54520. +
  54521. + ep = get_ep_by_addr(pcd, ep_addr);
  54522. +
  54523. + CFI_INFO
  54524. + ("%s: Set Tx FIFO size: endpoint addr=0x%02x, depth=%d, FIFO Num=%d\n",
  54525. + __func__, ep_addr, size, ep->dwc_ep.tx_fifo_num);
  54526. +
  54527. + if (NULL == ep) {
  54528. + CFI_INFO("%s: Unable to get the endpoint addr=0x%02x\n",
  54529. + __func__, ep_addr);
  54530. + return -DWC_E_INVALID;
  54531. + }
  54532. +
  54533. + fsiz = params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num - 1];
  54534. + params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num - 1] = size;
  54535. +
  54536. + if (resize_fifos(GET_CORE_IF(pcd))) {
  54537. + retval = 0;
  54538. + } else {
  54539. + CFI_INFO
  54540. + ("%s: Error setting the feature Tx FIFO Size for EP%d\n",
  54541. + __func__, ep_addr);
  54542. + params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num - 1] = fsiz;
  54543. + retval = -DWC_E_INVALID;
  54544. + }
  54545. +
  54546. + return retval;
  54547. +}
  54548. +
  54549. +/**
  54550. + * This function sets a new value for the buffer Alignment setup.
  54551. + */
  54552. +static int cfi_set_rx_fifo_val(uint8_t * buf, dwc_otg_pcd_t * pcd)
  54553. +{
  54554. + int retval;
  54555. + uint32_t fsiz;
  54556. + uint16_t size;
  54557. + dwc_otg_core_params_t *params = GET_CORE_IF(pcd)->core_params;
  54558. + rx_fifo_size_setup_t *prxfifoval;
  54559. +
  54560. + prxfifoval = (rx_fifo_size_setup_t *) buf;
  54561. + size = prxfifoval->wDepth;
  54562. +
  54563. + fsiz = params->dev_rx_fifo_size;
  54564. + params->dev_rx_fifo_size = size;
  54565. +
  54566. + if (resize_fifos(GET_CORE_IF(pcd))) {
  54567. + retval = 0;
  54568. + } else {
  54569. + CFI_INFO("%s: Error setting the feature Rx FIFO Size\n",
  54570. + __func__);
  54571. + params->dev_rx_fifo_size = fsiz;
  54572. + retval = -DWC_E_INVALID;
  54573. + }
  54574. +
  54575. + return retval;
  54576. +}
  54577. +
  54578. +/**
  54579. + * This function reads the SG of an EP's buffer setup into the buffer buf
  54580. + */
  54581. +static int cfi_ep_get_sg_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  54582. + struct cfi_usb_ctrlrequest *req)
  54583. +{
  54584. + int retval = -DWC_E_INVALID;
  54585. + uint8_t addr;
  54586. + cfi_ep_t *ep;
  54587. +
  54588. + /* The Low Byte of the wValue contains a non-zero address of the endpoint */
  54589. + addr = req->wValue & 0xFF;
  54590. + if (addr == 0) /* The address should be non-zero */
  54591. + return retval;
  54592. +
  54593. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  54594. + if (NULL == ep) {
  54595. + CFI_INFO("%s: Unable to get the endpoint address(0x%02x)\n",
  54596. + __func__, addr);
  54597. + return retval;
  54598. + }
  54599. +
  54600. + dwc_memcpy(buf, ep->bm_sg, BS_SG_VAL_DESC_LEN);
  54601. + retval = BS_SG_VAL_DESC_LEN;
  54602. + return retval;
  54603. +}
  54604. +
  54605. +/**
  54606. + * This function reads the Concatenation value of an EP's buffer mode into
  54607. + * the buffer buf
  54608. + */
  54609. +static int cfi_ep_get_concat_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  54610. + struct cfi_usb_ctrlrequest *req)
  54611. +{
  54612. + int retval = -DWC_E_INVALID;
  54613. + uint8_t addr;
  54614. + cfi_ep_t *ep;
  54615. + uint8_t desc_count;
  54616. +
  54617. + /* The Low Byte of the wValue contains a non-zero address of the endpoint */
  54618. + addr = req->wValue & 0xFF;
  54619. + if (addr == 0) /* The address should be non-zero */
  54620. + return retval;
  54621. +
  54622. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  54623. + if (NULL == ep) {
  54624. + CFI_INFO("%s: Unable to get the endpoint address(0x%02x)\n",
  54625. + __func__, addr);
  54626. + return retval;
  54627. + }
  54628. +
  54629. + /* Copy the header to the buffer */
  54630. + dwc_memcpy(buf, ep->bm_concat, BS_CONCAT_VAL_HDR_LEN);
  54631. + /* Advance the buffer pointer by the header size */
  54632. + buf += BS_CONCAT_VAL_HDR_LEN;
  54633. +
  54634. + desc_count = ep->bm_concat->hdr.bDescCount;
  54635. + /* Copy alll the wTxBytes to the buffer */
  54636. + dwc_memcpy(buf, ep->bm_concat->wTxBytes, sizeof(uid16_t) * desc_count);
  54637. +
  54638. + retval = BS_CONCAT_VAL_HDR_LEN + sizeof(uid16_t) * desc_count;
  54639. + return retval;
  54640. +}
  54641. +
  54642. +/**
  54643. + * This function reads the buffer Alignment value of an EP's buffer mode into
  54644. + * the buffer buf
  54645. + *
  54646. + * @return The total number of bytes copied to the buffer or negative error code.
  54647. + */
  54648. +static int cfi_ep_get_align_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  54649. + struct cfi_usb_ctrlrequest *req)
  54650. +{
  54651. + int retval = -DWC_E_INVALID;
  54652. + uint8_t addr;
  54653. + cfi_ep_t *ep;
  54654. +
  54655. + /* The Low Byte of the wValue contains a non-zero address of the endpoint */
  54656. + addr = req->wValue & 0xFF;
  54657. + if (addr == 0) /* The address should be non-zero */
  54658. + return retval;
  54659. +
  54660. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  54661. + if (NULL == ep) {
  54662. + CFI_INFO("%s: Unable to get the endpoint address(0x%02x)\n",
  54663. + __func__, addr);
  54664. + return retval;
  54665. + }
  54666. +
  54667. + dwc_memcpy(buf, ep->bm_align, BS_ALIGN_VAL_HDR_LEN);
  54668. + retval = BS_ALIGN_VAL_HDR_LEN;
  54669. +
  54670. + return retval;
  54671. +}
  54672. +
  54673. +/**
  54674. + * This function sets a new value for the specified feature
  54675. + *
  54676. + * @param pcd A pointer to the PCD object
  54677. + *
  54678. + * @return 0 if successful, negative error code otherwise to stall the DCE.
  54679. + */
  54680. +static int cfi_set_feature_value(struct dwc_otg_pcd *pcd)
  54681. +{
  54682. + int retval = -DWC_E_NOT_SUPPORTED;
  54683. + uint16_t wIndex, wValue;
  54684. + uint8_t bRequest;
  54685. + struct dwc_otg_core_if *coreif;
  54686. + cfiobject_t *cfi = pcd->cfi;
  54687. + struct cfi_usb_ctrlrequest *ctrl_req;
  54688. + uint8_t *buf;
  54689. + ctrl_req = &cfi->ctrl_req;
  54690. +
  54691. + buf = pcd->cfi->ctrl_req.data;
  54692. +
  54693. + coreif = GET_CORE_IF(pcd);
  54694. + bRequest = ctrl_req->bRequest;
  54695. + wIndex = DWC_CONSTANT_CPU_TO_LE16(ctrl_req->wIndex);
  54696. + wValue = DWC_CONSTANT_CPU_TO_LE16(ctrl_req->wValue);
  54697. +
  54698. + /* See which feature is to be modified */
  54699. + switch (wIndex) {
  54700. + case FT_ID_DMA_BUFFER_SETUP:
  54701. + /* Modify the feature */
  54702. + if ((retval = cfi_ep_set_sg_val(buf, pcd)) < 0)
  54703. + return retval;
  54704. +
  54705. + /* And send this request to the gadget */
  54706. + cfi->need_gadget_att = 1;
  54707. + break;
  54708. +
  54709. + case FT_ID_DMA_BUFF_ALIGN:
  54710. + if ((retval = cfi_ep_set_alignment_val(buf, pcd)) < 0)
  54711. + return retval;
  54712. + cfi->need_gadget_att = 1;
  54713. + break;
  54714. +
  54715. + case FT_ID_DMA_CONCAT_SETUP:
  54716. + /* Modify the feature */
  54717. + if ((retval = cfi_ep_set_concat_val(buf, pcd)) < 0)
  54718. + return retval;
  54719. + cfi->need_gadget_att = 1;
  54720. + break;
  54721. +
  54722. + case FT_ID_DMA_CIRCULAR:
  54723. + CFI_INFO("FT_ID_DMA_CIRCULAR\n");
  54724. + break;
  54725. +
  54726. + case FT_ID_THRESHOLD_SETUP:
  54727. + CFI_INFO("FT_ID_THRESHOLD_SETUP\n");
  54728. + break;
  54729. +
  54730. + case FT_ID_DFIFO_DEPTH:
  54731. + CFI_INFO("FT_ID_DFIFO_DEPTH\n");
  54732. + break;
  54733. +
  54734. + case FT_ID_TX_FIFO_DEPTH:
  54735. + CFI_INFO("FT_ID_TX_FIFO_DEPTH\n");
  54736. + if ((retval = cfi_ep_set_tx_fifo_val(buf, pcd)) < 0)
  54737. + return retval;
  54738. + cfi->need_gadget_att = 0;
  54739. + break;
  54740. +
  54741. + case FT_ID_RX_FIFO_DEPTH:
  54742. + CFI_INFO("FT_ID_RX_FIFO_DEPTH\n");
  54743. + if ((retval = cfi_set_rx_fifo_val(buf, pcd)) < 0)
  54744. + return retval;
  54745. + cfi->need_gadget_att = 0;
  54746. + break;
  54747. + }
  54748. +
  54749. + return retval;
  54750. +}
  54751. +
  54752. +#endif //DWC_UTE_CFI
  54753. diff -Nur linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_cfi.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cfi.h
  54754. --- linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_cfi.h 1970-01-01 01:00:00.000000000 +0100
  54755. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cfi.h 2014-04-24 15:37:13.310990489 +0200
  54756. @@ -0,0 +1,320 @@
  54757. +/* ==========================================================================
  54758. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  54759. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  54760. + * otherwise expressly agreed to in writing between Synopsys and you.
  54761. + *
  54762. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  54763. + * any End User Software License Agreement or Agreement for Licensed Product
  54764. + * with Synopsys or any supplement thereto. You are permitted to use and
  54765. + * redistribute this Software in source and binary forms, with or without
  54766. + * modification, provided that redistributions of source code must retain this
  54767. + * notice. You may not view, use, disclose, copy or distribute this file or
  54768. + * any information contained herein except pursuant to this license grant from
  54769. + * Synopsys. If you do not agree with this notice, including the disclaimer
  54770. + * below, then you are not authorized to use the Software.
  54771. + *
  54772. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  54773. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  54774. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  54775. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  54776. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  54777. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  54778. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  54779. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  54780. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  54781. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  54782. + * DAMAGE.
  54783. + * ========================================================================== */
  54784. +
  54785. +#if !defined(__DWC_OTG_CFI_H__)
  54786. +#define __DWC_OTG_CFI_H__
  54787. +
  54788. +#include "dwc_otg_pcd.h"
  54789. +#include "dwc_cfi_common.h"
  54790. +
  54791. +/**
  54792. + * @file
  54793. + * This file contains the CFI related OTG PCD specific common constants,
  54794. + * interfaces(functions and macros) and data structures.The CFI Protocol is an
  54795. + * optional interface for internal testing purposes that a DUT may implement to
  54796. + * support testing of configurable features.
  54797. + *
  54798. + */
  54799. +
  54800. +struct dwc_otg_pcd;
  54801. +struct dwc_otg_pcd_ep;
  54802. +
  54803. +/** OTG CFI Features (properties) ID constants */
  54804. +/** This is a request for all Core Features */
  54805. +#define FT_ID_DMA_MODE 0x0001
  54806. +#define FT_ID_DMA_BUFFER_SETUP 0x0002
  54807. +#define FT_ID_DMA_BUFF_ALIGN 0x0003
  54808. +#define FT_ID_DMA_CONCAT_SETUP 0x0004
  54809. +#define FT_ID_DMA_CIRCULAR 0x0005
  54810. +#define FT_ID_THRESHOLD_SETUP 0x0006
  54811. +#define FT_ID_DFIFO_DEPTH 0x0007
  54812. +#define FT_ID_TX_FIFO_DEPTH 0x0008
  54813. +#define FT_ID_RX_FIFO_DEPTH 0x0009
  54814. +
  54815. +/**********************************************************/
  54816. +#define CFI_INFO_DEF
  54817. +
  54818. +#ifdef CFI_INFO_DEF
  54819. +#define CFI_INFO(fmt...) DWC_PRINTF("CFI: " fmt);
  54820. +#else
  54821. +#define CFI_INFO(fmt...)
  54822. +#endif
  54823. +
  54824. +#define min(x,y) ({ \
  54825. + x < y ? x : y; })
  54826. +
  54827. +#define max(x,y) ({ \
  54828. + x > y ? x : y; })
  54829. +
  54830. +/**
  54831. + * Descriptor DMA SG Buffer setup structure (SG buffer). This structure is
  54832. + * also used for setting up a buffer for Circular DDMA.
  54833. + */
  54834. +struct _ddma_sg_buffer_setup {
  54835. +#define BS_SG_VAL_DESC_LEN 6
  54836. + /* The OUT EP address */
  54837. + uint8_t bOutEndpointAddress;
  54838. + /* The IN EP address */
  54839. + uint8_t bInEndpointAddress;
  54840. + /* Number of bytes to put between transfer segments (must be DWORD boundaries) */
  54841. + uint8_t bOffset;
  54842. + /* The number of transfer segments (a DMA descriptors per each segment) */
  54843. + uint8_t bCount;
  54844. + /* Size (in byte) of each transfer segment */
  54845. + uint16_t wSize;
  54846. +} __attribute__ ((packed));
  54847. +typedef struct _ddma_sg_buffer_setup ddma_sg_buffer_setup_t;
  54848. +
  54849. +/** Descriptor DMA Concatenation Buffer setup structure */
  54850. +struct _ddma_concat_buffer_setup_hdr {
  54851. +#define BS_CONCAT_VAL_HDR_LEN 4
  54852. + /* The endpoint for which the buffer is to be set up */
  54853. + uint8_t bEndpointAddress;
  54854. + /* The count of descriptors to be used */
  54855. + uint8_t bDescCount;
  54856. + /* The total size of the transfer */
  54857. + uint16_t wSize;
  54858. +} __attribute__ ((packed));
  54859. +typedef struct _ddma_concat_buffer_setup_hdr ddma_concat_buffer_setup_hdr_t;
  54860. +
  54861. +/** Descriptor DMA Concatenation Buffer setup structure */
  54862. +struct _ddma_concat_buffer_setup {
  54863. + /* The SG header */
  54864. + ddma_concat_buffer_setup_hdr_t hdr;
  54865. +
  54866. + /* The XFER sizes pointer (allocated dynamically) */
  54867. + uint16_t *wTxBytes;
  54868. +} __attribute__ ((packed));
  54869. +typedef struct _ddma_concat_buffer_setup ddma_concat_buffer_setup_t;
  54870. +
  54871. +/** Descriptor DMA Alignment Buffer setup structure */
  54872. +struct _ddma_align_buffer_setup {
  54873. +#define BS_ALIGN_VAL_HDR_LEN 2
  54874. + uint8_t bEndpointAddress;
  54875. + uint8_t bAlign;
  54876. +} __attribute__ ((packed));
  54877. +typedef struct _ddma_align_buffer_setup ddma_align_buffer_setup_t;
  54878. +
  54879. +/** Transmit FIFO Size setup structure */
  54880. +struct _tx_fifo_size_setup {
  54881. + uint8_t bEndpointAddress;
  54882. + uint16_t wDepth;
  54883. +} __attribute__ ((packed));
  54884. +typedef struct _tx_fifo_size_setup tx_fifo_size_setup_t;
  54885. +
  54886. +/** Transmit FIFO Size setup structure */
  54887. +struct _rx_fifo_size_setup {
  54888. + uint16_t wDepth;
  54889. +} __attribute__ ((packed));
  54890. +typedef struct _rx_fifo_size_setup rx_fifo_size_setup_t;
  54891. +
  54892. +/**
  54893. + * struct cfi_usb_ctrlrequest - the CFI implementation of the struct usb_ctrlrequest
  54894. + * This structure encapsulates the standard usb_ctrlrequest and adds a pointer
  54895. + * to the data returned in the data stage of a 3-stage Control Write requests.
  54896. + */
  54897. +struct cfi_usb_ctrlrequest {
  54898. + uint8_t bRequestType;
  54899. + uint8_t bRequest;
  54900. + uint16_t wValue;
  54901. + uint16_t wIndex;
  54902. + uint16_t wLength;
  54903. + uint8_t *data;
  54904. +} UPACKED;
  54905. +
  54906. +/*---------------------------------------------------------------------------*/
  54907. +
  54908. +/**
  54909. + * The CFI wrapper of the enabled and activated dwc_otg_pcd_ep structures.
  54910. + * This structure is used to store the buffer setup data for any
  54911. + * enabled endpoint in the PCD.
  54912. + */
  54913. +struct cfi_ep {
  54914. + /* Entry for the list container */
  54915. + dwc_list_link_t lh;
  54916. + /* Pointer to the active PCD endpoint structure */
  54917. + struct dwc_otg_pcd_ep *ep;
  54918. + /* The last descriptor in the chain of DMA descriptors of the endpoint */
  54919. + struct dwc_otg_dma_desc *dma_desc_last;
  54920. + /* The SG feature value */
  54921. + ddma_sg_buffer_setup_t *bm_sg;
  54922. + /* The Circular feature value */
  54923. + ddma_sg_buffer_setup_t *bm_circ;
  54924. + /* The Concatenation feature value */
  54925. + ddma_concat_buffer_setup_t *bm_concat;
  54926. + /* The Alignment feature value */
  54927. + ddma_align_buffer_setup_t *bm_align;
  54928. + /* XFER length */
  54929. + uint32_t xfer_len;
  54930. + /*
  54931. + * Count of DMA descriptors currently used.
  54932. + * The total should not exceed the MAX_DMA_DESCS_PER_EP value
  54933. + * defined in the dwc_otg_cil.h
  54934. + */
  54935. + uint32_t desc_count;
  54936. +};
  54937. +typedef struct cfi_ep cfi_ep_t;
  54938. +
  54939. +typedef struct cfi_dma_buff {
  54940. +#define CFI_IN_BUF_LEN 1024
  54941. +#define CFI_OUT_BUF_LEN 1024
  54942. + dma_addr_t addr;
  54943. + uint8_t *buf;
  54944. +} cfi_dma_buff_t;
  54945. +
  54946. +struct cfiobject;
  54947. +
  54948. +/**
  54949. + * This is the interface for the CFI operations.
  54950. + *
  54951. + * @param ep_enable Called when any endpoint is enabled and activated.
  54952. + * @param release Called when the CFI object is released and it needs to correctly
  54953. + * deallocate the dynamic memory
  54954. + * @param ctrl_write_complete Called when the data stage of the request is complete
  54955. + */
  54956. +typedef struct cfi_ops {
  54957. + int (*ep_enable) (struct cfiobject * cfi, struct dwc_otg_pcd * pcd,
  54958. + struct dwc_otg_pcd_ep * ep);
  54959. + void *(*ep_alloc_buf) (struct cfiobject * cfi, struct dwc_otg_pcd * pcd,
  54960. + struct dwc_otg_pcd_ep * ep, dma_addr_t * dma,
  54961. + unsigned size, gfp_t flags);
  54962. + void (*release) (struct cfiobject * cfi);
  54963. + int (*ctrl_write_complete) (struct cfiobject * cfi,
  54964. + struct dwc_otg_pcd * pcd);
  54965. + void (*build_descriptors) (struct cfiobject * cfi,
  54966. + struct dwc_otg_pcd * pcd,
  54967. + struct dwc_otg_pcd_ep * ep,
  54968. + dwc_otg_pcd_request_t * req);
  54969. +} cfi_ops_t;
  54970. +
  54971. +struct cfiobject {
  54972. + cfi_ops_t ops;
  54973. + struct dwc_otg_pcd *pcd;
  54974. + struct usb_gadget *gadget;
  54975. +
  54976. + /* Buffers used to send/receive CFI-related request data */
  54977. + cfi_dma_buff_t buf_in;
  54978. + cfi_dma_buff_t buf_out;
  54979. +
  54980. + /* CFI specific Control request wrapper */
  54981. + struct cfi_usb_ctrlrequest ctrl_req;
  54982. +
  54983. + /* The list of active EP's in the PCD of type cfi_ep_t */
  54984. + dwc_list_link_t active_eps;
  54985. +
  54986. + /* This flag shall control the propagation of a specific request
  54987. + * to the gadget's processing routines.
  54988. + * 0 - no gadget handling
  54989. + * 1 - the gadget needs to know about this request (w/o completing a status
  54990. + * phase - just return a 0 to the _setup callback)
  54991. + */
  54992. + uint8_t need_gadget_att;
  54993. +
  54994. + /* Flag indicating whether the status IN phase needs to be
  54995. + * completed by the PCD
  54996. + */
  54997. + uint8_t need_status_in_complete;
  54998. +};
  54999. +typedef struct cfiobject cfiobject_t;
  55000. +
  55001. +#define DUMP_MSG
  55002. +
  55003. +#if defined(DUMP_MSG)
  55004. +static inline void dump_msg(const u8 * buf, unsigned int length)
  55005. +{
  55006. + unsigned int start, num, i;
  55007. + char line[52], *p;
  55008. +
  55009. + if (length >= 512)
  55010. + return;
  55011. +
  55012. + start = 0;
  55013. + while (length > 0) {
  55014. + num = min(length, 16u);
  55015. + p = line;
  55016. + for (i = 0; i < num; ++i) {
  55017. + if (i == 8)
  55018. + *p++ = ' ';
  55019. + DWC_SPRINTF(p, " %02x", buf[i]);
  55020. + p += 3;
  55021. + }
  55022. + *p = 0;
  55023. + DWC_DEBUG("%6x: %s\n", start, line);
  55024. + buf += num;
  55025. + start += num;
  55026. + length -= num;
  55027. + }
  55028. +}
  55029. +#else
  55030. +static inline void dump_msg(const u8 * buf, unsigned int length)
  55031. +{
  55032. +}
  55033. +#endif
  55034. +
  55035. +/**
  55036. + * This function returns a pointer to cfi_ep_t object with the addr address.
  55037. + */
  55038. +static inline struct cfi_ep *get_cfi_ep_by_addr(struct cfiobject *cfi,
  55039. + uint8_t addr)
  55040. +{
  55041. + struct cfi_ep *pcfiep;
  55042. + dwc_list_link_t *tmp;
  55043. +
  55044. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  55045. + pcfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  55046. +
  55047. + if (pcfiep->ep->desc->bEndpointAddress == addr) {
  55048. + return pcfiep;
  55049. + }
  55050. + }
  55051. +
  55052. + return NULL;
  55053. +}
  55054. +
  55055. +/**
  55056. + * This function returns a pointer to cfi_ep_t object that matches
  55057. + * the dwc_otg_pcd_ep object.
  55058. + */
  55059. +static inline struct cfi_ep *get_cfi_ep_by_pcd_ep(struct cfiobject *cfi,
  55060. + struct dwc_otg_pcd_ep *ep)
  55061. +{
  55062. + struct cfi_ep *pcfiep = NULL;
  55063. + dwc_list_link_t *tmp;
  55064. +
  55065. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  55066. + pcfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  55067. + if (pcfiep->ep == ep) {
  55068. + return pcfiep;
  55069. + }
  55070. + }
  55071. + return NULL;
  55072. +}
  55073. +
  55074. +int cfi_setup(struct dwc_otg_pcd *pcd, struct cfi_usb_ctrlrequest *ctrl);
  55075. +
  55076. +#endif /* (__DWC_OTG_CFI_H__) */
  55077. diff -Nur linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_cil.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cil.c
  55078. --- linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_cil.c 1970-01-01 01:00:00.000000000 +0100
  55079. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cil.c 2014-04-24 15:37:13.310990489 +0200
  55080. @@ -0,0 +1,7151 @@
  55081. +/* ==========================================================================
  55082. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_cil.c $
  55083. + * $Revision: #191 $
  55084. + * $Date: 2012/08/10 $
  55085. + * $Change: 2047372 $
  55086. + *
  55087. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  55088. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  55089. + * otherwise expressly agreed to in writing between Synopsys and you.
  55090. + *
  55091. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  55092. + * any End User Software License Agreement or Agreement for Licensed Product
  55093. + * with Synopsys or any supplement thereto. You are permitted to use and
  55094. + * redistribute this Software in source and binary forms, with or without
  55095. + * modification, provided that redistributions of source code must retain this
  55096. + * notice. You may not view, use, disclose, copy or distribute this file or
  55097. + * any information contained herein except pursuant to this license grant from
  55098. + * Synopsys. If you do not agree with this notice, including the disclaimer
  55099. + * below, then you are not authorized to use the Software.
  55100. + *
  55101. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  55102. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  55103. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  55104. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  55105. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  55106. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  55107. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  55108. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  55109. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  55110. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  55111. + * DAMAGE.
  55112. + * ========================================================================== */
  55113. +
  55114. +/** @file
  55115. + *
  55116. + * The Core Interface Layer provides basic services for accessing and
  55117. + * managing the DWC_otg hardware. These services are used by both the
  55118. + * Host Controller Driver and the Peripheral Controller Driver.
  55119. + *
  55120. + * The CIL manages the memory map for the core so that the HCD and PCD
  55121. + * don't have to do this separately. It also handles basic tasks like
  55122. + * reading/writing the registers and data FIFOs in the controller.
  55123. + * Some of the data access functions provide encapsulation of several
  55124. + * operations required to perform a task, such as writing multiple
  55125. + * registers to start a transfer. Finally, the CIL performs basic
  55126. + * services that are not specific to either the host or device modes
  55127. + * of operation. These services include management of the OTG Host
  55128. + * Negotiation Protocol (HNP) and Session Request Protocol (SRP). A
  55129. + * Diagnostic API is also provided to allow testing of the controller
  55130. + * hardware.
  55131. + *
  55132. + * The Core Interface Layer has the following requirements:
  55133. + * - Provides basic controller operations.
  55134. + * - Minimal use of OS services.
  55135. + * - The OS services used will be abstracted by using inline functions
  55136. + * or macros.
  55137. + *
  55138. + */
  55139. +
  55140. +#include "dwc_os.h"
  55141. +#include "dwc_otg_regs.h"
  55142. +#include "dwc_otg_cil.h"
  55143. +
  55144. +static int dwc_otg_setup_params(dwc_otg_core_if_t * core_if);
  55145. +
  55146. +/**
  55147. + * This function is called to initialize the DWC_otg CSR data
  55148. + * structures. The register addresses in the device and host
  55149. + * structures are initialized from the base address supplied by the
  55150. + * caller. The calling function must make the OS calls to get the
  55151. + * base address of the DWC_otg controller registers. The core_params
  55152. + * argument holds the parameters that specify how the core should be
  55153. + * configured.
  55154. + *
  55155. + * @param reg_base_addr Base address of DWC_otg core registers
  55156. + *
  55157. + */
  55158. +dwc_otg_core_if_t *dwc_otg_cil_init(const uint32_t * reg_base_addr)
  55159. +{
  55160. + dwc_otg_core_if_t *core_if = 0;
  55161. + dwc_otg_dev_if_t *dev_if = 0;
  55162. + dwc_otg_host_if_t *host_if = 0;
  55163. + uint8_t *reg_base = (uint8_t *) reg_base_addr;
  55164. + int i = 0;
  55165. +
  55166. + DWC_DEBUGPL(DBG_CILV, "%s(%p)\n", __func__, reg_base_addr);
  55167. +
  55168. + core_if = DWC_ALLOC(sizeof(dwc_otg_core_if_t));
  55169. +
  55170. + if (core_if == NULL) {
  55171. + DWC_DEBUGPL(DBG_CIL,
  55172. + "Allocation of dwc_otg_core_if_t failed\n");
  55173. + return 0;
  55174. + }
  55175. + core_if->core_global_regs = (dwc_otg_core_global_regs_t *) reg_base;
  55176. +
  55177. + /*
  55178. + * Allocate the Device Mode structures.
  55179. + */
  55180. + dev_if = DWC_ALLOC(sizeof(dwc_otg_dev_if_t));
  55181. +
  55182. + if (dev_if == NULL) {
  55183. + DWC_DEBUGPL(DBG_CIL, "Allocation of dwc_otg_dev_if_t failed\n");
  55184. + DWC_FREE(core_if);
  55185. + return 0;
  55186. + }
  55187. +
  55188. + dev_if->dev_global_regs =
  55189. + (dwc_otg_device_global_regs_t *) (reg_base +
  55190. + DWC_DEV_GLOBAL_REG_OFFSET);
  55191. +
  55192. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  55193. + dev_if->in_ep_regs[i] = (dwc_otg_dev_in_ep_regs_t *)
  55194. + (reg_base + DWC_DEV_IN_EP_REG_OFFSET +
  55195. + (i * DWC_EP_REG_OFFSET));
  55196. +
  55197. + dev_if->out_ep_regs[i] = (dwc_otg_dev_out_ep_regs_t *)
  55198. + (reg_base + DWC_DEV_OUT_EP_REG_OFFSET +
  55199. + (i * DWC_EP_REG_OFFSET));
  55200. + DWC_DEBUGPL(DBG_CILV, "in_ep_regs[%d]->diepctl=%p\n",
  55201. + i, &dev_if->in_ep_regs[i]->diepctl);
  55202. + DWC_DEBUGPL(DBG_CILV, "out_ep_regs[%d]->doepctl=%p\n",
  55203. + i, &dev_if->out_ep_regs[i]->doepctl);
  55204. + }
  55205. +
  55206. + dev_if->speed = 0; // unknown
  55207. +
  55208. + core_if->dev_if = dev_if;
  55209. +
  55210. + /*
  55211. + * Allocate the Host Mode structures.
  55212. + */
  55213. + host_if = DWC_ALLOC(sizeof(dwc_otg_host_if_t));
  55214. +
  55215. + if (host_if == NULL) {
  55216. + DWC_DEBUGPL(DBG_CIL,
  55217. + "Allocation of dwc_otg_host_if_t failed\n");
  55218. + DWC_FREE(dev_if);
  55219. + DWC_FREE(core_if);
  55220. + return 0;
  55221. + }
  55222. +
  55223. + host_if->host_global_regs = (dwc_otg_host_global_regs_t *)
  55224. + (reg_base + DWC_OTG_HOST_GLOBAL_REG_OFFSET);
  55225. +
  55226. + host_if->hprt0 =
  55227. + (uint32_t *) (reg_base + DWC_OTG_HOST_PORT_REGS_OFFSET);
  55228. +
  55229. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  55230. + host_if->hc_regs[i] = (dwc_otg_hc_regs_t *)
  55231. + (reg_base + DWC_OTG_HOST_CHAN_REGS_OFFSET +
  55232. + (i * DWC_OTG_CHAN_REGS_OFFSET));
  55233. + DWC_DEBUGPL(DBG_CILV, "hc_reg[%d]->hcchar=%p\n",
  55234. + i, &host_if->hc_regs[i]->hcchar);
  55235. + }
  55236. +
  55237. + host_if->num_host_channels = MAX_EPS_CHANNELS;
  55238. + core_if->host_if = host_if;
  55239. +
  55240. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  55241. + core_if->data_fifo[i] =
  55242. + (uint32_t *) (reg_base + DWC_OTG_DATA_FIFO_OFFSET +
  55243. + (i * DWC_OTG_DATA_FIFO_SIZE));
  55244. + DWC_DEBUGPL(DBG_CILV, "data_fifo[%d]=0x%08lx\n",
  55245. + i, (unsigned long)core_if->data_fifo[i]);
  55246. + }
  55247. +
  55248. + core_if->pcgcctl = (uint32_t *) (reg_base + DWC_OTG_PCGCCTL_OFFSET);
  55249. +
  55250. + /* Initiate lx_state to L3 disconnected state */
  55251. + core_if->lx_state = DWC_OTG_L3;
  55252. + /*
  55253. + * Store the contents of the hardware configuration registers here for
  55254. + * easy access later.
  55255. + */
  55256. + core_if->hwcfg1.d32 =
  55257. + DWC_READ_REG32(&core_if->core_global_regs->ghwcfg1);
  55258. + core_if->hwcfg2.d32 =
  55259. + DWC_READ_REG32(&core_if->core_global_regs->ghwcfg2);
  55260. + core_if->hwcfg3.d32 =
  55261. + DWC_READ_REG32(&core_if->core_global_regs->ghwcfg3);
  55262. + core_if->hwcfg4.d32 =
  55263. + DWC_READ_REG32(&core_if->core_global_regs->ghwcfg4);
  55264. +
  55265. + /* Force host mode to get HPTXFSIZ exact power on value */
  55266. + {
  55267. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  55268. + gusbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  55269. + gusbcfg.b.force_host_mode = 1;
  55270. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, gusbcfg.d32);
  55271. + dwc_mdelay(100);
  55272. + core_if->hptxfsiz.d32 =
  55273. + DWC_READ_REG32(&core_if->core_global_regs->hptxfsiz);
  55274. + gusbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  55275. + gusbcfg.b.force_host_mode = 0;
  55276. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, gusbcfg.d32);
  55277. + dwc_mdelay(100);
  55278. + }
  55279. +
  55280. + DWC_DEBUGPL(DBG_CILV, "hwcfg1=%08x\n", core_if->hwcfg1.d32);
  55281. + DWC_DEBUGPL(DBG_CILV, "hwcfg2=%08x\n", core_if->hwcfg2.d32);
  55282. + DWC_DEBUGPL(DBG_CILV, "hwcfg3=%08x\n", core_if->hwcfg3.d32);
  55283. + DWC_DEBUGPL(DBG_CILV, "hwcfg4=%08x\n", core_if->hwcfg4.d32);
  55284. +
  55285. + core_if->hcfg.d32 =
  55286. + DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  55287. + core_if->dcfg.d32 =
  55288. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  55289. +
  55290. + DWC_DEBUGPL(DBG_CILV, "hcfg=%08x\n", core_if->hcfg.d32);
  55291. + DWC_DEBUGPL(DBG_CILV, "dcfg=%08x\n", core_if->dcfg.d32);
  55292. +
  55293. + DWC_DEBUGPL(DBG_CILV, "op_mode=%0x\n", core_if->hwcfg2.b.op_mode);
  55294. + DWC_DEBUGPL(DBG_CILV, "arch=%0x\n", core_if->hwcfg2.b.architecture);
  55295. + DWC_DEBUGPL(DBG_CILV, "num_dev_ep=%d\n", core_if->hwcfg2.b.num_dev_ep);
  55296. + DWC_DEBUGPL(DBG_CILV, "num_host_chan=%d\n",
  55297. + core_if->hwcfg2.b.num_host_chan);
  55298. + DWC_DEBUGPL(DBG_CILV, "nonperio_tx_q_depth=0x%0x\n",
  55299. + core_if->hwcfg2.b.nonperio_tx_q_depth);
  55300. + DWC_DEBUGPL(DBG_CILV, "host_perio_tx_q_depth=0x%0x\n",
  55301. + core_if->hwcfg2.b.host_perio_tx_q_depth);
  55302. + DWC_DEBUGPL(DBG_CILV, "dev_token_q_depth=0x%0x\n",
  55303. + core_if->hwcfg2.b.dev_token_q_depth);
  55304. +
  55305. + DWC_DEBUGPL(DBG_CILV, "Total FIFO SZ=%d\n",
  55306. + core_if->hwcfg3.b.dfifo_depth);
  55307. + DWC_DEBUGPL(DBG_CILV, "xfer_size_cntr_width=%0x\n",
  55308. + core_if->hwcfg3.b.xfer_size_cntr_width);
  55309. +
  55310. + /*
  55311. + * Set the SRP sucess bit for FS-I2c
  55312. + */
  55313. + core_if->srp_success = 0;
  55314. + core_if->srp_timer_started = 0;
  55315. +
  55316. + /*
  55317. + * Create new workqueue and init works
  55318. + */
  55319. + core_if->wq_otg = DWC_WORKQ_ALLOC("dwc_otg");
  55320. + if (core_if->wq_otg == 0) {
  55321. + DWC_WARN("DWC_WORKQ_ALLOC failed\n");
  55322. + DWC_FREE(host_if);
  55323. + DWC_FREE(dev_if);
  55324. + DWC_FREE(core_if);
  55325. + return 0;
  55326. + }
  55327. +
  55328. + core_if->snpsid = DWC_READ_REG32(&core_if->core_global_regs->gsnpsid);
  55329. +
  55330. + DWC_PRINTF("Core Release: %x.%x%x%x\n",
  55331. + (core_if->snpsid >> 12 & 0xF),
  55332. + (core_if->snpsid >> 8 & 0xF),
  55333. + (core_if->snpsid >> 4 & 0xF), (core_if->snpsid & 0xF));
  55334. +
  55335. + core_if->wkp_timer = DWC_TIMER_ALLOC("Wake Up Timer",
  55336. + w_wakeup_detected, core_if);
  55337. + if (core_if->wkp_timer == 0) {
  55338. + DWC_WARN("DWC_TIMER_ALLOC failed\n");
  55339. + DWC_FREE(host_if);
  55340. + DWC_FREE(dev_if);
  55341. + DWC_WORKQ_FREE(core_if->wq_otg);
  55342. + DWC_FREE(core_if);
  55343. + return 0;
  55344. + }
  55345. +
  55346. + if (dwc_otg_setup_params(core_if)) {
  55347. + DWC_WARN("Error while setting core params\n");
  55348. + }
  55349. +
  55350. + core_if->hibernation_suspend = 0;
  55351. +
  55352. + /** ADP initialization */
  55353. + dwc_otg_adp_init(core_if);
  55354. +
  55355. + return core_if;
  55356. +}
  55357. +
  55358. +/**
  55359. + * This function frees the structures allocated by dwc_otg_cil_init().
  55360. + *
  55361. + * @param core_if The core interface pointer returned from
  55362. + * dwc_otg_cil_init().
  55363. + *
  55364. + */
  55365. +void dwc_otg_cil_remove(dwc_otg_core_if_t * core_if)
  55366. +{
  55367. + dctl_data_t dctl = {.d32 = 0 };
  55368. + DWC_DEBUGPL(DBG_CILV, "%s(%p)\n", __func__, core_if);
  55369. +
  55370. + /* Disable all interrupts */
  55371. + DWC_MODIFY_REG32(&core_if->core_global_regs->gahbcfg, 1, 0);
  55372. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, 0);
  55373. +
  55374. + dctl.b.sftdiscon = 1;
  55375. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  55376. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0,
  55377. + dctl.d32);
  55378. + }
  55379. +
  55380. + if (core_if->wq_otg) {
  55381. + DWC_WORKQ_WAIT_WORK_DONE(core_if->wq_otg, 500);
  55382. + DWC_WORKQ_FREE(core_if->wq_otg);
  55383. + }
  55384. + if (core_if->dev_if) {
  55385. + DWC_FREE(core_if->dev_if);
  55386. + }
  55387. + if (core_if->host_if) {
  55388. + DWC_FREE(core_if->host_if);
  55389. + }
  55390. +
  55391. + /** Remove ADP Stuff */
  55392. + dwc_otg_adp_remove(core_if);
  55393. + if (core_if->core_params) {
  55394. + DWC_FREE(core_if->core_params);
  55395. + }
  55396. + if (core_if->wkp_timer) {
  55397. + DWC_TIMER_FREE(core_if->wkp_timer);
  55398. + }
  55399. + if (core_if->srp_timer) {
  55400. + DWC_TIMER_FREE(core_if->srp_timer);
  55401. + }
  55402. + DWC_FREE(core_if);
  55403. +}
  55404. +
  55405. +/**
  55406. + * This function enables the controller's Global Interrupt in the AHB Config
  55407. + * register.
  55408. + *
  55409. + * @param core_if Programming view of DWC_otg controller.
  55410. + */
  55411. +void dwc_otg_enable_global_interrupts(dwc_otg_core_if_t * core_if)
  55412. +{
  55413. + gahbcfg_data_t ahbcfg = {.d32 = 0 };
  55414. + ahbcfg.b.glblintrmsk = 1; /* Enable interrupts */
  55415. + DWC_MODIFY_REG32(&core_if->core_global_regs->gahbcfg, 0, ahbcfg.d32);
  55416. +}
  55417. +
  55418. +/**
  55419. + * This function disables the controller's Global Interrupt in the AHB Config
  55420. + * register.
  55421. + *
  55422. + * @param core_if Programming view of DWC_otg controller.
  55423. + */
  55424. +void dwc_otg_disable_global_interrupts(dwc_otg_core_if_t * core_if)
  55425. +{
  55426. + gahbcfg_data_t ahbcfg = {.d32 = 0 };
  55427. + ahbcfg.b.glblintrmsk = 1; /* Disable interrupts */
  55428. + DWC_MODIFY_REG32(&core_if->core_global_regs->gahbcfg, ahbcfg.d32, 0);
  55429. +}
  55430. +
  55431. +/**
  55432. + * This function initializes the commmon interrupts, used in both
  55433. + * device and host modes.
  55434. + *
  55435. + * @param core_if Programming view of the DWC_otg controller
  55436. + *
  55437. + */
  55438. +static void dwc_otg_enable_common_interrupts(dwc_otg_core_if_t * core_if)
  55439. +{
  55440. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  55441. + gintmsk_data_t intr_mask = {.d32 = 0 };
  55442. +
  55443. + /* Clear any pending OTG Interrupts */
  55444. + DWC_WRITE_REG32(&global_regs->gotgint, 0xFFFFFFFF);
  55445. +
  55446. + /* Clear any pending interrupts */
  55447. + DWC_WRITE_REG32(&global_regs->gintsts, 0xFFFFFFFF);
  55448. +
  55449. + /*
  55450. + * Enable the interrupts in the GINTMSK.
  55451. + */
  55452. + intr_mask.b.modemismatch = 1;
  55453. + intr_mask.b.otgintr = 1;
  55454. +
  55455. + if (!core_if->dma_enable) {
  55456. + intr_mask.b.rxstsqlvl = 1;
  55457. + }
  55458. +
  55459. + intr_mask.b.conidstschng = 1;
  55460. + intr_mask.b.wkupintr = 1;
  55461. + intr_mask.b.disconnect = 0;
  55462. + intr_mask.b.usbsuspend = 1;
  55463. + intr_mask.b.sessreqintr = 1;
  55464. +#ifdef CONFIG_USB_DWC_OTG_LPM
  55465. + if (core_if->core_params->lpm_enable) {
  55466. + intr_mask.b.lpmtranrcvd = 1;
  55467. + }
  55468. +#endif
  55469. + DWC_WRITE_REG32(&global_regs->gintmsk, intr_mask.d32);
  55470. +}
  55471. +
  55472. +/*
  55473. + * The restore operation is modified to support Synopsys Emulated Powerdown and
  55474. + * Hibernation. This function is for exiting from Device mode hibernation by
  55475. + * Host Initiated Resume/Reset and Device Initiated Remote-Wakeup.
  55476. + * @param core_if Programming view of DWC_otg controller.
  55477. + * @param rem_wakeup - indicates whether resume is initiated by Device or Host.
  55478. + * @param reset - indicates whether resume is initiated by Reset.
  55479. + */
  55480. +int dwc_otg_device_hibernation_restore(dwc_otg_core_if_t * core_if,
  55481. + int rem_wakeup, int reset)
  55482. +{
  55483. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  55484. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  55485. + dctl_data_t dctl = {.d32 = 0 };
  55486. +
  55487. + int timeout = 2000;
  55488. +
  55489. + if (!core_if->hibernation_suspend) {
  55490. + DWC_PRINTF("Already exited from Hibernation\n");
  55491. + return 1;
  55492. + }
  55493. +
  55494. + DWC_DEBUGPL(DBG_PCD, "%s called\n", __FUNCTION__);
  55495. + /* Switch-on voltage to the core */
  55496. + gpwrdn.b.pwrdnswtch = 1;
  55497. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  55498. + dwc_udelay(10);
  55499. +
  55500. + /* Reset core */
  55501. + gpwrdn.d32 = 0;
  55502. + gpwrdn.b.pwrdnrstn = 1;
  55503. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  55504. + dwc_udelay(10);
  55505. +
  55506. + /* Assert Restore signal */
  55507. + gpwrdn.d32 = 0;
  55508. + gpwrdn.b.restore = 1;
  55509. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  55510. + dwc_udelay(10);
  55511. +
  55512. + /* Disable power clamps */
  55513. + gpwrdn.d32 = 0;
  55514. + gpwrdn.b.pwrdnclmp = 1;
  55515. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  55516. +
  55517. + if (rem_wakeup) {
  55518. + dwc_udelay(70);
  55519. + }
  55520. +
  55521. + /* Deassert Reset core */
  55522. + gpwrdn.d32 = 0;
  55523. + gpwrdn.b.pwrdnrstn = 1;
  55524. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  55525. + dwc_udelay(10);
  55526. +
  55527. + /* Disable PMU interrupt */
  55528. + gpwrdn.d32 = 0;
  55529. + gpwrdn.b.pmuintsel = 1;
  55530. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  55531. +
  55532. + /* Mask interrupts from gpwrdn */
  55533. + gpwrdn.d32 = 0;
  55534. + gpwrdn.b.connect_det_msk = 1;
  55535. + gpwrdn.b.srp_det_msk = 1;
  55536. + gpwrdn.b.disconn_det_msk = 1;
  55537. + gpwrdn.b.rst_det_msk = 1;
  55538. + gpwrdn.b.lnstchng_msk = 1;
  55539. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  55540. +
  55541. + /* Indicates that we are going out from hibernation */
  55542. + core_if->hibernation_suspend = 0;
  55543. +
  55544. + /*
  55545. + * Set Restore Essential Regs bit in PCGCCTL register, restore_mode = 1
  55546. + * indicates restore from remote_wakeup
  55547. + */
  55548. + restore_essential_regs(core_if, rem_wakeup, 0);
  55549. +
  55550. + /*
  55551. + * Wait a little for seeing new value of variable hibernation_suspend if
  55552. + * Restore done interrupt received before polling
  55553. + */
  55554. + dwc_udelay(10);
  55555. +
  55556. + if (core_if->hibernation_suspend == 0) {
  55557. + /*
  55558. + * Wait For Restore_done Interrupt. This mechanism of polling the
  55559. + * interrupt is introduced to avoid any possible race conditions
  55560. + */
  55561. + do {
  55562. + gintsts_data_t gintsts;
  55563. + gintsts.d32 =
  55564. + DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  55565. + if (gintsts.b.restoredone) {
  55566. + gintsts.d32 = 0;
  55567. + gintsts.b.restoredone = 1;
  55568. + DWC_WRITE_REG32(&core_if->core_global_regs->
  55569. + gintsts, gintsts.d32);
  55570. + DWC_PRINTF("Restore Done Interrupt seen\n");
  55571. + break;
  55572. + }
  55573. + dwc_udelay(10);
  55574. + } while (--timeout);
  55575. + if (!timeout) {
  55576. + DWC_PRINTF("Restore Done interrupt wasn't generated here\n");
  55577. + }
  55578. + }
  55579. + /* Clear all pending interupts */
  55580. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  55581. +
  55582. + /* De-assert Restore */
  55583. + gpwrdn.d32 = 0;
  55584. + gpwrdn.b.restore = 1;
  55585. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  55586. + dwc_udelay(10);
  55587. +
  55588. + if (!rem_wakeup) {
  55589. + pcgcctl.d32 = 0;
  55590. + pcgcctl.b.rstpdwnmodule = 1;
  55591. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  55592. + }
  55593. +
  55594. + /* Restore GUSBCFG and DCFG */
  55595. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg,
  55596. + core_if->gr_backup->gusbcfg_local);
  55597. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg,
  55598. + core_if->dr_backup->dcfg);
  55599. +
  55600. + /* De-assert Wakeup Logic */
  55601. + gpwrdn.d32 = 0;
  55602. + gpwrdn.b.pmuactv = 1;
  55603. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  55604. + dwc_udelay(10);
  55605. +
  55606. + if (!rem_wakeup) {
  55607. + /* Set Device programming done bit */
  55608. + dctl.b.pwronprgdone = 1;
  55609. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  55610. + } else {
  55611. + /* Start Remote Wakeup Signaling */
  55612. + dctl.d32 = core_if->dr_backup->dctl;
  55613. + dctl.b.rmtwkupsig = 1;
  55614. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32);
  55615. + }
  55616. +
  55617. + dwc_mdelay(2);
  55618. + /* Clear all pending interupts */
  55619. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  55620. +
  55621. + /* Restore global registers */
  55622. + dwc_otg_restore_global_regs(core_if);
  55623. + /* Restore device global registers */
  55624. + dwc_otg_restore_dev_regs(core_if, rem_wakeup);
  55625. +
  55626. + if (rem_wakeup) {
  55627. + dwc_mdelay(7);
  55628. + dctl.d32 = 0;
  55629. + dctl.b.rmtwkupsig = 1;
  55630. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32, 0);
  55631. + }
  55632. +
  55633. + core_if->hibernation_suspend = 0;
  55634. + /* The core will be in ON STATE */
  55635. + core_if->lx_state = DWC_OTG_L0;
  55636. + DWC_PRINTF("Hibernation recovery completes here\n");
  55637. +
  55638. + return 1;
  55639. +}
  55640. +
  55641. +/*
  55642. + * The restore operation is modified to support Synopsys Emulated Powerdown and
  55643. + * Hibernation. This function is for exiting from Host mode hibernation by
  55644. + * Host Initiated Resume/Reset and Device Initiated Remote-Wakeup.
  55645. + * @param core_if Programming view of DWC_otg controller.
  55646. + * @param rem_wakeup - indicates whether resume is initiated by Device or Host.
  55647. + * @param reset - indicates whether resume is initiated by Reset.
  55648. + */
  55649. +int dwc_otg_host_hibernation_restore(dwc_otg_core_if_t * core_if,
  55650. + int rem_wakeup, int reset)
  55651. +{
  55652. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  55653. + hprt0_data_t hprt0 = {.d32 = 0 };
  55654. +
  55655. + int timeout = 2000;
  55656. +
  55657. + DWC_DEBUGPL(DBG_HCD, "%s called\n", __FUNCTION__);
  55658. + /* Switch-on voltage to the core */
  55659. + gpwrdn.b.pwrdnswtch = 1;
  55660. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  55661. + dwc_udelay(10);
  55662. +
  55663. + /* Reset core */
  55664. + gpwrdn.d32 = 0;
  55665. + gpwrdn.b.pwrdnrstn = 1;
  55666. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  55667. + dwc_udelay(10);
  55668. +
  55669. + /* Assert Restore signal */
  55670. + gpwrdn.d32 = 0;
  55671. + gpwrdn.b.restore = 1;
  55672. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  55673. + dwc_udelay(10);
  55674. +
  55675. + /* Disable power clamps */
  55676. + gpwrdn.d32 = 0;
  55677. + gpwrdn.b.pwrdnclmp = 1;
  55678. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  55679. +
  55680. + if (!rem_wakeup) {
  55681. + dwc_udelay(50);
  55682. + }
  55683. +
  55684. + /* Deassert Reset core */
  55685. + gpwrdn.d32 = 0;
  55686. + gpwrdn.b.pwrdnrstn = 1;
  55687. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  55688. + dwc_udelay(10);
  55689. +
  55690. + /* Disable PMU interrupt */
  55691. + gpwrdn.d32 = 0;
  55692. + gpwrdn.b.pmuintsel = 1;
  55693. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  55694. +
  55695. + gpwrdn.d32 = 0;
  55696. + gpwrdn.b.connect_det_msk = 1;
  55697. + gpwrdn.b.srp_det_msk = 1;
  55698. + gpwrdn.b.disconn_det_msk = 1;
  55699. + gpwrdn.b.rst_det_msk = 1;
  55700. + gpwrdn.b.lnstchng_msk = 1;
  55701. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  55702. +
  55703. + /* Indicates that we are going out from hibernation */
  55704. + core_if->hibernation_suspend = 0;
  55705. +
  55706. + /* Set Restore Essential Regs bit in PCGCCTL register */
  55707. + restore_essential_regs(core_if, rem_wakeup, 1);
  55708. +
  55709. + /* Wait a little for seeing new value of variable hibernation_suspend if
  55710. + * Restore done interrupt received before polling */
  55711. + dwc_udelay(10);
  55712. +
  55713. + if (core_if->hibernation_suspend == 0) {
  55714. + /* Wait For Restore_done Interrupt. This mechanism of polling the
  55715. + * interrupt is introduced to avoid any possible race conditions
  55716. + */
  55717. + do {
  55718. + gintsts_data_t gintsts;
  55719. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  55720. + if (gintsts.b.restoredone) {
  55721. + gintsts.d32 = 0;
  55722. + gintsts.b.restoredone = 1;
  55723. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  55724. + DWC_DEBUGPL(DBG_HCD,"Restore Done Interrupt seen\n");
  55725. + break;
  55726. + }
  55727. + dwc_udelay(10);
  55728. + } while (--timeout);
  55729. + if (!timeout) {
  55730. + DWC_WARN("Restore Done interrupt wasn't generated\n");
  55731. + }
  55732. + }
  55733. +
  55734. + /* Set the flag's value to 0 again after receiving restore done interrupt */
  55735. + core_if->hibernation_suspend = 0;
  55736. +
  55737. + /* This step is not described in functional spec but if not wait for this
  55738. + * delay, mismatch interrupts occurred because just after restore core is
  55739. + * in Device mode(gintsts.curmode == 0) */
  55740. + dwc_mdelay(100);
  55741. +
  55742. + /* Clear all pending interrupts */
  55743. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  55744. +
  55745. + /* De-assert Restore */
  55746. + gpwrdn.d32 = 0;
  55747. + gpwrdn.b.restore = 1;
  55748. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  55749. + dwc_udelay(10);
  55750. +
  55751. + /* Restore GUSBCFG and HCFG */
  55752. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg,
  55753. + core_if->gr_backup->gusbcfg_local);
  55754. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg,
  55755. + core_if->hr_backup->hcfg_local);
  55756. +
  55757. + /* De-assert Wakeup Logic */
  55758. + gpwrdn.d32 = 0;
  55759. + gpwrdn.b.pmuactv = 1;
  55760. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  55761. + dwc_udelay(10);
  55762. +
  55763. + /* Start the Resume operation by programming HPRT0 */
  55764. + hprt0.d32 = core_if->hr_backup->hprt0_local;
  55765. + hprt0.b.prtpwr = 1;
  55766. + hprt0.b.prtena = 0;
  55767. + hprt0.b.prtsusp = 0;
  55768. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  55769. +
  55770. + DWC_PRINTF("Resume Starts Now\n");
  55771. + if (!reset) { // Indicates it is Resume Operation
  55772. + hprt0.d32 = core_if->hr_backup->hprt0_local;
  55773. + hprt0.b.prtres = 1;
  55774. + hprt0.b.prtpwr = 1;
  55775. + hprt0.b.prtena = 0;
  55776. + hprt0.b.prtsusp = 0;
  55777. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  55778. +
  55779. + if (!rem_wakeup)
  55780. + hprt0.b.prtres = 0;
  55781. + /* Wait for Resume time and then program HPRT again */
  55782. + dwc_mdelay(100);
  55783. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  55784. +
  55785. + } else { // Indicates it is Reset Operation
  55786. + hprt0.d32 = core_if->hr_backup->hprt0_local;
  55787. + hprt0.b.prtrst = 1;
  55788. + hprt0.b.prtpwr = 1;
  55789. + hprt0.b.prtena = 0;
  55790. + hprt0.b.prtsusp = 0;
  55791. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  55792. + /* Wait for Reset time and then program HPRT again */
  55793. + dwc_mdelay(60);
  55794. + hprt0.b.prtrst = 0;
  55795. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  55796. + }
  55797. + /* Clear all interrupt status */
  55798. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  55799. + hprt0.b.prtconndet = 1;
  55800. + hprt0.b.prtenchng = 1;
  55801. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  55802. +
  55803. + /* Clear all pending interupts */
  55804. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  55805. +
  55806. + /* Restore global registers */
  55807. + dwc_otg_restore_global_regs(core_if);
  55808. + /* Restore host global registers */
  55809. + dwc_otg_restore_host_regs(core_if, reset);
  55810. +
  55811. + /* The core will be in ON STATE */
  55812. + core_if->lx_state = DWC_OTG_L0;
  55813. + DWC_PRINTF("Hibernation recovery is complete here\n");
  55814. + return 0;
  55815. +}
  55816. +
  55817. +/** Saves some register values into system memory. */
  55818. +int dwc_otg_save_global_regs(dwc_otg_core_if_t * core_if)
  55819. +{
  55820. + struct dwc_otg_global_regs_backup *gr;
  55821. + int i;
  55822. +
  55823. + gr = core_if->gr_backup;
  55824. + if (!gr) {
  55825. + gr = DWC_ALLOC(sizeof(*gr));
  55826. + if (!gr) {
  55827. + return -DWC_E_NO_MEMORY;
  55828. + }
  55829. + core_if->gr_backup = gr;
  55830. + }
  55831. +
  55832. + gr->gotgctl_local = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  55833. + gr->gintmsk_local = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  55834. + gr->gahbcfg_local = DWC_READ_REG32(&core_if->core_global_regs->gahbcfg);
  55835. + gr->gusbcfg_local = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  55836. + gr->grxfsiz_local = DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  55837. + gr->gnptxfsiz_local = DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz);
  55838. + gr->hptxfsiz_local = DWC_READ_REG32(&core_if->core_global_regs->hptxfsiz);
  55839. +#ifdef CONFIG_USB_DWC_OTG_LPM
  55840. + gr->glpmcfg_local = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  55841. +#endif
  55842. + gr->gi2cctl_local = DWC_READ_REG32(&core_if->core_global_regs->gi2cctl);
  55843. + gr->pcgcctl_local = DWC_READ_REG32(core_if->pcgcctl);
  55844. + gr->gdfifocfg_local =
  55845. + DWC_READ_REG32(&core_if->core_global_regs->gdfifocfg);
  55846. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  55847. + gr->dtxfsiz_local[i] =
  55848. + DWC_READ_REG32(&(core_if->core_global_regs->dtxfsiz[i]));
  55849. + }
  55850. +
  55851. + DWC_DEBUGPL(DBG_ANY, "===========Backing Global registers==========\n");
  55852. + DWC_DEBUGPL(DBG_ANY, "Backed up gotgctl = %08x\n", gr->gotgctl_local);
  55853. + DWC_DEBUGPL(DBG_ANY, "Backed up gintmsk = %08x\n", gr->gintmsk_local);
  55854. + DWC_DEBUGPL(DBG_ANY, "Backed up gahbcfg = %08x\n", gr->gahbcfg_local);
  55855. + DWC_DEBUGPL(DBG_ANY, "Backed up gusbcfg = %08x\n", gr->gusbcfg_local);
  55856. + DWC_DEBUGPL(DBG_ANY, "Backed up grxfsiz = %08x\n", gr->grxfsiz_local);
  55857. + DWC_DEBUGPL(DBG_ANY, "Backed up gnptxfsiz = %08x\n",
  55858. + gr->gnptxfsiz_local);
  55859. + DWC_DEBUGPL(DBG_ANY, "Backed up hptxfsiz = %08x\n",
  55860. + gr->hptxfsiz_local);
  55861. +#ifdef CONFIG_USB_DWC_OTG_LPM
  55862. + DWC_DEBUGPL(DBG_ANY, "Backed up glpmcfg = %08x\n", gr->glpmcfg_local);
  55863. +#endif
  55864. + DWC_DEBUGPL(DBG_ANY, "Backed up gi2cctl = %08x\n", gr->gi2cctl_local);
  55865. + DWC_DEBUGPL(DBG_ANY, "Backed up pcgcctl = %08x\n", gr->pcgcctl_local);
  55866. + DWC_DEBUGPL(DBG_ANY,"Backed up gdfifocfg = %08x\n",gr->gdfifocfg_local);
  55867. +
  55868. + return 0;
  55869. +}
  55870. +
  55871. +/** Saves GINTMSK register before setting the msk bits. */
  55872. +int dwc_otg_save_gintmsk_reg(dwc_otg_core_if_t * core_if)
  55873. +{
  55874. + struct dwc_otg_global_regs_backup *gr;
  55875. +
  55876. + gr = core_if->gr_backup;
  55877. + if (!gr) {
  55878. + gr = DWC_ALLOC(sizeof(*gr));
  55879. + if (!gr) {
  55880. + return -DWC_E_NO_MEMORY;
  55881. + }
  55882. + core_if->gr_backup = gr;
  55883. + }
  55884. +
  55885. + gr->gintmsk_local = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  55886. +
  55887. + DWC_DEBUGPL(DBG_ANY,"=============Backing GINTMSK registers============\n");
  55888. + DWC_DEBUGPL(DBG_ANY, "Backed up gintmsk = %08x\n", gr->gintmsk_local);
  55889. +
  55890. + return 0;
  55891. +}
  55892. +
  55893. +int dwc_otg_save_dev_regs(dwc_otg_core_if_t * core_if)
  55894. +{
  55895. + struct dwc_otg_dev_regs_backup *dr;
  55896. + int i;
  55897. +
  55898. + dr = core_if->dr_backup;
  55899. + if (!dr) {
  55900. + dr = DWC_ALLOC(sizeof(*dr));
  55901. + if (!dr) {
  55902. + return -DWC_E_NO_MEMORY;
  55903. + }
  55904. + core_if->dr_backup = dr;
  55905. + }
  55906. +
  55907. + dr->dcfg = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  55908. + dr->dctl = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  55909. + dr->daintmsk =
  55910. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daintmsk);
  55911. + dr->diepmsk =
  55912. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->diepmsk);
  55913. + dr->doepmsk =
  55914. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->doepmsk);
  55915. +
  55916. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  55917. + dr->diepctl[i] =
  55918. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[i]->diepctl);
  55919. + dr->dieptsiz[i] =
  55920. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[i]->dieptsiz);
  55921. + dr->diepdma[i] =
  55922. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[i]->diepdma);
  55923. + }
  55924. +
  55925. + DWC_DEBUGPL(DBG_ANY,
  55926. + "=============Backing Host registers==============\n");
  55927. + DWC_DEBUGPL(DBG_ANY, "Backed up dcfg = %08x\n", dr->dcfg);
  55928. + DWC_DEBUGPL(DBG_ANY, "Backed up dctl = %08x\n", dr->dctl);
  55929. + DWC_DEBUGPL(DBG_ANY, "Backed up daintmsk = %08x\n",
  55930. + dr->daintmsk);
  55931. + DWC_DEBUGPL(DBG_ANY, "Backed up diepmsk = %08x\n", dr->diepmsk);
  55932. + DWC_DEBUGPL(DBG_ANY, "Backed up doepmsk = %08x\n", dr->doepmsk);
  55933. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  55934. + DWC_DEBUGPL(DBG_ANY, "Backed up diepctl[%d] = %08x\n", i,
  55935. + dr->diepctl[i]);
  55936. + DWC_DEBUGPL(DBG_ANY, "Backed up dieptsiz[%d] = %08x\n",
  55937. + i, dr->dieptsiz[i]);
  55938. + DWC_DEBUGPL(DBG_ANY, "Backed up diepdma[%d] = %08x\n", i,
  55939. + dr->diepdma[i]);
  55940. + }
  55941. +
  55942. + return 0;
  55943. +}
  55944. +
  55945. +int dwc_otg_save_host_regs(dwc_otg_core_if_t * core_if)
  55946. +{
  55947. + struct dwc_otg_host_regs_backup *hr;
  55948. + int i;
  55949. +
  55950. + hr = core_if->hr_backup;
  55951. + if (!hr) {
  55952. + hr = DWC_ALLOC(sizeof(*hr));
  55953. + if (!hr) {
  55954. + return -DWC_E_NO_MEMORY;
  55955. + }
  55956. + core_if->hr_backup = hr;
  55957. + }
  55958. +
  55959. + hr->hcfg_local =
  55960. + DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  55961. + hr->haintmsk_local =
  55962. + DWC_READ_REG32(&core_if->host_if->host_global_regs->haintmsk);
  55963. + for (i = 0; i < dwc_otg_get_param_host_channels(core_if); ++i) {
  55964. + hr->hcintmsk_local[i] =
  55965. + DWC_READ_REG32(&core_if->host_if->hc_regs[i]->hcintmsk);
  55966. + }
  55967. + hr->hprt0_local = DWC_READ_REG32(core_if->host_if->hprt0);
  55968. + hr->hfir_local =
  55969. + DWC_READ_REG32(&core_if->host_if->host_global_regs->hfir);
  55970. +
  55971. + DWC_DEBUGPL(DBG_ANY,
  55972. + "=============Backing Host registers===============\n");
  55973. + DWC_DEBUGPL(DBG_ANY, "Backed up hcfg = %08x\n",
  55974. + hr->hcfg_local);
  55975. + DWC_DEBUGPL(DBG_ANY, "Backed up haintmsk = %08x\n", hr->haintmsk_local);
  55976. + for (i = 0; i < dwc_otg_get_param_host_channels(core_if); ++i) {
  55977. + DWC_DEBUGPL(DBG_ANY, "Backed up hcintmsk[%02d]=%08x\n", i,
  55978. + hr->hcintmsk_local[i]);
  55979. + }
  55980. + DWC_DEBUGPL(DBG_ANY, "Backed up hprt0 = %08x\n",
  55981. + hr->hprt0_local);
  55982. + DWC_DEBUGPL(DBG_ANY, "Backed up hfir = %08x\n",
  55983. + hr->hfir_local);
  55984. +
  55985. + return 0;
  55986. +}
  55987. +
  55988. +int dwc_otg_restore_global_regs(dwc_otg_core_if_t *core_if)
  55989. +{
  55990. + struct dwc_otg_global_regs_backup *gr;
  55991. + int i;
  55992. +
  55993. + gr = core_if->gr_backup;
  55994. + if (!gr) {
  55995. + return -DWC_E_INVALID;
  55996. + }
  55997. +
  55998. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgctl, gr->gotgctl_local);
  55999. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gr->gintmsk_local);
  56000. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, gr->gusbcfg_local);
  56001. + DWC_WRITE_REG32(&core_if->core_global_regs->gahbcfg, gr->gahbcfg_local);
  56002. + DWC_WRITE_REG32(&core_if->core_global_regs->grxfsiz, gr->grxfsiz_local);
  56003. + DWC_WRITE_REG32(&core_if->core_global_regs->gnptxfsiz,
  56004. + gr->gnptxfsiz_local);
  56005. + DWC_WRITE_REG32(&core_if->core_global_regs->hptxfsiz,
  56006. + gr->hptxfsiz_local);
  56007. + DWC_WRITE_REG32(&core_if->core_global_regs->gdfifocfg,
  56008. + gr->gdfifocfg_local);
  56009. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  56010. + DWC_WRITE_REG32(&core_if->core_global_regs->dtxfsiz[i],
  56011. + gr->dtxfsiz_local[i]);
  56012. + }
  56013. +
  56014. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  56015. + DWC_WRITE_REG32(core_if->host_if->hprt0, 0x0000100A);
  56016. + DWC_WRITE_REG32(&core_if->core_global_regs->gahbcfg,
  56017. + (gr->gahbcfg_local));
  56018. + return 0;
  56019. +}
  56020. +
  56021. +int dwc_otg_restore_dev_regs(dwc_otg_core_if_t * core_if, int rem_wakeup)
  56022. +{
  56023. + struct dwc_otg_dev_regs_backup *dr;
  56024. + int i;
  56025. +
  56026. + dr = core_if->dr_backup;
  56027. +
  56028. + if (!dr) {
  56029. + return -DWC_E_INVALID;
  56030. + }
  56031. +
  56032. + if (!rem_wakeup) {
  56033. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl,
  56034. + dr->dctl);
  56035. + }
  56036. +
  56037. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->daintmsk, dr->daintmsk);
  56038. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->diepmsk, dr->diepmsk);
  56039. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->doepmsk, dr->doepmsk);
  56040. +
  56041. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  56042. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->dieptsiz, dr->dieptsiz[i]);
  56043. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->diepdma, dr->diepdma[i]);
  56044. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->diepctl, dr->diepctl[i]);
  56045. + }
  56046. +
  56047. + return 0;
  56048. +}
  56049. +
  56050. +int dwc_otg_restore_host_regs(dwc_otg_core_if_t * core_if, int reset)
  56051. +{
  56052. + struct dwc_otg_host_regs_backup *hr;
  56053. + int i;
  56054. + hr = core_if->hr_backup;
  56055. +
  56056. + if (!hr) {
  56057. + return -DWC_E_INVALID;
  56058. + }
  56059. +
  56060. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg, hr->hcfg_local);
  56061. + //if (!reset)
  56062. + //{
  56063. + // DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hfir, hr->hfir_local);
  56064. + //}
  56065. +
  56066. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->haintmsk,
  56067. + hr->haintmsk_local);
  56068. + for (i = 0; i < dwc_otg_get_param_host_channels(core_if); ++i) {
  56069. + DWC_WRITE_REG32(&core_if->host_if->hc_regs[i]->hcintmsk,
  56070. + hr->hcintmsk_local[i]);
  56071. + }
  56072. +
  56073. + return 0;
  56074. +}
  56075. +
  56076. +int restore_lpm_i2c_regs(dwc_otg_core_if_t * core_if)
  56077. +{
  56078. + struct dwc_otg_global_regs_backup *gr;
  56079. +
  56080. + gr = core_if->gr_backup;
  56081. +
  56082. + /* Restore values for LPM and I2C */
  56083. +#ifdef CONFIG_USB_DWC_OTG_LPM
  56084. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, gr->glpmcfg_local);
  56085. +#endif
  56086. + DWC_WRITE_REG32(&core_if->core_global_regs->gi2cctl, gr->gi2cctl_local);
  56087. +
  56088. + return 0;
  56089. +}
  56090. +
  56091. +int restore_essential_regs(dwc_otg_core_if_t * core_if, int rmode, int is_host)
  56092. +{
  56093. + struct dwc_otg_global_regs_backup *gr;
  56094. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  56095. + gahbcfg_data_t gahbcfg = {.d32 = 0 };
  56096. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  56097. + gintmsk_data_t gintmsk = {.d32 = 0 };
  56098. +
  56099. + /* Restore LPM and I2C registers */
  56100. + restore_lpm_i2c_regs(core_if);
  56101. +
  56102. + /* Set PCGCCTL to 0 */
  56103. + DWC_WRITE_REG32(core_if->pcgcctl, 0x00000000);
  56104. +
  56105. + gr = core_if->gr_backup;
  56106. + /* Load restore values for [31:14] bits */
  56107. + DWC_WRITE_REG32(core_if->pcgcctl,
  56108. + ((gr->pcgcctl_local & 0xffffc000) | 0x00020000));
  56109. +
  56110. + /* Umnask global Interrupt in GAHBCFG and restore it */
  56111. + gahbcfg.d32 = gr->gahbcfg_local;
  56112. + gahbcfg.b.glblintrmsk = 1;
  56113. + DWC_WRITE_REG32(&core_if->core_global_regs->gahbcfg, gahbcfg.d32);
  56114. +
  56115. + /* Clear all pending interupts */
  56116. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  56117. +
  56118. + /* Unmask restore done interrupt */
  56119. + gintmsk.b.restoredone = 1;
  56120. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gintmsk.d32);
  56121. +
  56122. + /* Restore GUSBCFG and HCFG/DCFG */
  56123. + gusbcfg.d32 = core_if->gr_backup->gusbcfg_local;
  56124. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, gusbcfg.d32);
  56125. +
  56126. + if (is_host) {
  56127. + hcfg_data_t hcfg = {.d32 = 0 };
  56128. + hcfg.d32 = core_if->hr_backup->hcfg_local;
  56129. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg,
  56130. + hcfg.d32);
  56131. +
  56132. + /* Load restore values for [31:14] bits */
  56133. + pcgcctl.d32 = gr->pcgcctl_local & 0xffffc000;
  56134. + pcgcctl.d32 = gr->pcgcctl_local | 0x00020000;
  56135. +
  56136. + if (rmode)
  56137. + pcgcctl.b.restoremode = 1;
  56138. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  56139. + dwc_udelay(10);
  56140. +
  56141. + /* Load restore values for [31:14] bits and set EssRegRestored bit */
  56142. + pcgcctl.d32 = gr->pcgcctl_local | 0xffffc000;
  56143. + pcgcctl.d32 = gr->pcgcctl_local & 0xffffc000;
  56144. + pcgcctl.b.ess_reg_restored = 1;
  56145. + if (rmode)
  56146. + pcgcctl.b.restoremode = 1;
  56147. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  56148. + } else {
  56149. + dcfg_data_t dcfg = {.d32 = 0 };
  56150. + dcfg.d32 = core_if->dr_backup->dcfg;
  56151. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg, dcfg.d32);
  56152. +
  56153. + /* Load restore values for [31:14] bits */
  56154. + pcgcctl.d32 = gr->pcgcctl_local & 0xffffc000;
  56155. + pcgcctl.d32 = gr->pcgcctl_local | 0x00020000;
  56156. + if (!rmode) {
  56157. + pcgcctl.d32 |= 0x208;
  56158. + }
  56159. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  56160. + dwc_udelay(10);
  56161. +
  56162. + /* Load restore values for [31:14] bits */
  56163. + pcgcctl.d32 = gr->pcgcctl_local & 0xffffc000;
  56164. + pcgcctl.d32 = gr->pcgcctl_local | 0x00020000;
  56165. + pcgcctl.b.ess_reg_restored = 1;
  56166. + if (!rmode)
  56167. + pcgcctl.d32 |= 0x208;
  56168. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  56169. + }
  56170. +
  56171. + return 0;
  56172. +}
  56173. +
  56174. +/**
  56175. + * Initializes the FSLSPClkSel field of the HCFG register depending on the PHY
  56176. + * type.
  56177. + */
  56178. +static void init_fslspclksel(dwc_otg_core_if_t * core_if)
  56179. +{
  56180. + uint32_t val;
  56181. + hcfg_data_t hcfg;
  56182. +
  56183. + if (((core_if->hwcfg2.b.hs_phy_type == 2) &&
  56184. + (core_if->hwcfg2.b.fs_phy_type == 1) &&
  56185. + (core_if->core_params->ulpi_fs_ls)) ||
  56186. + (core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS)) {
  56187. + /* Full speed PHY */
  56188. + val = DWC_HCFG_48_MHZ;
  56189. + } else {
  56190. + /* High speed PHY running at full speed or high speed */
  56191. + val = DWC_HCFG_30_60_MHZ;
  56192. + }
  56193. +
  56194. + DWC_DEBUGPL(DBG_CIL, "Initializing HCFG.FSLSPClkSel to 0x%1x\n", val);
  56195. + hcfg.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  56196. + hcfg.b.fslspclksel = val;
  56197. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg, hcfg.d32);
  56198. +}
  56199. +
  56200. +/**
  56201. + * Initializes the DevSpd field of the DCFG register depending on the PHY type
  56202. + * and the enumeration speed of the device.
  56203. + */
  56204. +static void init_devspd(dwc_otg_core_if_t * core_if)
  56205. +{
  56206. + uint32_t val;
  56207. + dcfg_data_t dcfg;
  56208. +
  56209. + if (((core_if->hwcfg2.b.hs_phy_type == 2) &&
  56210. + (core_if->hwcfg2.b.fs_phy_type == 1) &&
  56211. + (core_if->core_params->ulpi_fs_ls)) ||
  56212. + (core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS)) {
  56213. + /* Full speed PHY */
  56214. + val = 0x3;
  56215. + } else if (core_if->core_params->speed == DWC_SPEED_PARAM_FULL) {
  56216. + /* High speed PHY running at full speed */
  56217. + val = 0x1;
  56218. + } else {
  56219. + /* High speed PHY running at high speed */
  56220. + val = 0x0;
  56221. + }
  56222. +
  56223. + DWC_DEBUGPL(DBG_CIL, "Initializing DCFG.DevSpd to 0x%1x\n", val);
  56224. +
  56225. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  56226. + dcfg.b.devspd = val;
  56227. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg, dcfg.d32);
  56228. +}
  56229. +
  56230. +/**
  56231. + * This function calculates the number of IN EPS
  56232. + * using GHWCFG1 and GHWCFG2 registers values
  56233. + *
  56234. + * @param core_if Programming view of the DWC_otg controller
  56235. + */
  56236. +static uint32_t calc_num_in_eps(dwc_otg_core_if_t * core_if)
  56237. +{
  56238. + uint32_t num_in_eps = 0;
  56239. + uint32_t num_eps = core_if->hwcfg2.b.num_dev_ep;
  56240. + uint32_t hwcfg1 = core_if->hwcfg1.d32 >> 3;
  56241. + uint32_t num_tx_fifos = core_if->hwcfg4.b.num_in_eps;
  56242. + int i;
  56243. +
  56244. + for (i = 0; i < num_eps; ++i) {
  56245. + if (!(hwcfg1 & 0x1))
  56246. + num_in_eps++;
  56247. +
  56248. + hwcfg1 >>= 2;
  56249. + }
  56250. +
  56251. + if (core_if->hwcfg4.b.ded_fifo_en) {
  56252. + num_in_eps =
  56253. + (num_in_eps > num_tx_fifos) ? num_tx_fifos : num_in_eps;
  56254. + }
  56255. +
  56256. + return num_in_eps;
  56257. +}
  56258. +
  56259. +/**
  56260. + * This function calculates the number of OUT EPS
  56261. + * using GHWCFG1 and GHWCFG2 registers values
  56262. + *
  56263. + * @param core_if Programming view of the DWC_otg controller
  56264. + */
  56265. +static uint32_t calc_num_out_eps(dwc_otg_core_if_t * core_if)
  56266. +{
  56267. + uint32_t num_out_eps = 0;
  56268. + uint32_t num_eps = core_if->hwcfg2.b.num_dev_ep;
  56269. + uint32_t hwcfg1 = core_if->hwcfg1.d32 >> 2;
  56270. + int i;
  56271. +
  56272. + for (i = 0; i < num_eps; ++i) {
  56273. + if (!(hwcfg1 & 0x1))
  56274. + num_out_eps++;
  56275. +
  56276. + hwcfg1 >>= 2;
  56277. + }
  56278. + return num_out_eps;
  56279. +}
  56280. +
  56281. +/**
  56282. + * This function initializes the DWC_otg controller registers and
  56283. + * prepares the core for device mode or host mode operation.
  56284. + *
  56285. + * @param core_if Programming view of the DWC_otg controller
  56286. + *
  56287. + */
  56288. +void dwc_otg_core_init(dwc_otg_core_if_t * core_if)
  56289. +{
  56290. + int i = 0;
  56291. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  56292. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  56293. + gahbcfg_data_t ahbcfg = {.d32 = 0 };
  56294. + gusbcfg_data_t usbcfg = {.d32 = 0 };
  56295. + gi2cctl_data_t i2cctl = {.d32 = 0 };
  56296. +
  56297. + DWC_DEBUGPL(DBG_CILV, "dwc_otg_core_init(%p) regs at %p\n",
  56298. + core_if, global_regs);
  56299. +
  56300. + /* Common Initialization */
  56301. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  56302. +
  56303. + /* Program the ULPI External VBUS bit if needed */
  56304. + usbcfg.b.ulpi_ext_vbus_drv =
  56305. + (core_if->core_params->phy_ulpi_ext_vbus ==
  56306. + DWC_PHY_ULPI_EXTERNAL_VBUS) ? 1 : 0;
  56307. +
  56308. + /* Set external TS Dline pulsing */
  56309. + usbcfg.b.term_sel_dl_pulse =
  56310. + (core_if->core_params->ts_dline == 1) ? 1 : 0;
  56311. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  56312. +
  56313. + /* Reset the Controller */
  56314. + dwc_otg_core_reset(core_if);
  56315. +
  56316. + core_if->adp_enable = core_if->core_params->adp_supp_enable;
  56317. + core_if->power_down = core_if->core_params->power_down;
  56318. + core_if->otg_sts = 0;
  56319. +
  56320. + /* Initialize parameters from Hardware configuration registers. */
  56321. + dev_if->num_in_eps = calc_num_in_eps(core_if);
  56322. + dev_if->num_out_eps = calc_num_out_eps(core_if);
  56323. +
  56324. + DWC_DEBUGPL(DBG_CIL, "num_dev_perio_in_ep=%d\n",
  56325. + core_if->hwcfg4.b.num_dev_perio_in_ep);
  56326. +
  56327. + for (i = 0; i < core_if->hwcfg4.b.num_dev_perio_in_ep; i++) {
  56328. + dev_if->perio_tx_fifo_size[i] =
  56329. + DWC_READ_REG32(&global_regs->dtxfsiz[i]) >> 16;
  56330. + DWC_DEBUGPL(DBG_CIL, "Periodic Tx FIFO SZ #%d=0x%0x\n",
  56331. + i, dev_if->perio_tx_fifo_size[i]);
  56332. + }
  56333. +
  56334. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  56335. + dev_if->tx_fifo_size[i] =
  56336. + DWC_READ_REG32(&global_regs->dtxfsiz[i]) >> 16;
  56337. + DWC_DEBUGPL(DBG_CIL, "Tx FIFO SZ #%d=0x%0x\n",
  56338. + i, dev_if->tx_fifo_size[i]);
  56339. + }
  56340. +
  56341. + core_if->total_fifo_size = core_if->hwcfg3.b.dfifo_depth;
  56342. + core_if->rx_fifo_size = DWC_READ_REG32(&global_regs->grxfsiz);
  56343. + core_if->nperio_tx_fifo_size =
  56344. + DWC_READ_REG32(&global_regs->gnptxfsiz) >> 16;
  56345. +
  56346. + DWC_DEBUGPL(DBG_CIL, "Total FIFO SZ=%d\n", core_if->total_fifo_size);
  56347. + DWC_DEBUGPL(DBG_CIL, "Rx FIFO SZ=%d\n", core_if->rx_fifo_size);
  56348. + DWC_DEBUGPL(DBG_CIL, "NP Tx FIFO SZ=%d\n",
  56349. + core_if->nperio_tx_fifo_size);
  56350. +
  56351. + /* This programming sequence needs to happen in FS mode before any other
  56352. + * programming occurs */
  56353. + if ((core_if->core_params->speed == DWC_SPEED_PARAM_FULL) &&
  56354. + (core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS)) {
  56355. + /* If FS mode with FS PHY */
  56356. +
  56357. + /* core_init() is now called on every switch so only call the
  56358. + * following for the first time through. */
  56359. + if (!core_if->phy_init_done) {
  56360. + core_if->phy_init_done = 1;
  56361. + DWC_DEBUGPL(DBG_CIL, "FS_PHY detected\n");
  56362. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  56363. + usbcfg.b.physel = 1;
  56364. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  56365. +
  56366. + /* Reset after a PHY select */
  56367. + dwc_otg_core_reset(core_if);
  56368. + }
  56369. +
  56370. + /* Program DCFG.DevSpd or HCFG.FSLSPclkSel to 48Mhz in FS. Also
  56371. + * do this on HNP Dev/Host mode switches (done in dev_init and
  56372. + * host_init). */
  56373. + if (dwc_otg_is_host_mode(core_if)) {
  56374. + init_fslspclksel(core_if);
  56375. + } else {
  56376. + init_devspd(core_if);
  56377. + }
  56378. +
  56379. + if (core_if->core_params->i2c_enable) {
  56380. + DWC_DEBUGPL(DBG_CIL, "FS_PHY Enabling I2c\n");
  56381. + /* Program GUSBCFG.OtgUtmifsSel to I2C */
  56382. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  56383. + usbcfg.b.otgutmifssel = 1;
  56384. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  56385. +
  56386. + /* Program GI2CCTL.I2CEn */
  56387. + i2cctl.d32 = DWC_READ_REG32(&global_regs->gi2cctl);
  56388. + i2cctl.b.i2cdevaddr = 1;
  56389. + i2cctl.b.i2cen = 0;
  56390. + DWC_WRITE_REG32(&global_regs->gi2cctl, i2cctl.d32);
  56391. + i2cctl.b.i2cen = 1;
  56392. + DWC_WRITE_REG32(&global_regs->gi2cctl, i2cctl.d32);
  56393. + }
  56394. +
  56395. + } /* endif speed == DWC_SPEED_PARAM_FULL */
  56396. + else {
  56397. + /* High speed PHY. */
  56398. + if (!core_if->phy_init_done) {
  56399. + core_if->phy_init_done = 1;
  56400. + /* HS PHY parameters. These parameters are preserved
  56401. + * during soft reset so only program the first time. Do
  56402. + * a soft reset immediately after setting phyif. */
  56403. +
  56404. + if (core_if->core_params->phy_type == 2) {
  56405. + /* ULPI interface */
  56406. + usbcfg.b.ulpi_utmi_sel = 1;
  56407. + usbcfg.b.phyif = 0;
  56408. + usbcfg.b.ddrsel =
  56409. + core_if->core_params->phy_ulpi_ddr;
  56410. + } else if (core_if->core_params->phy_type == 1) {
  56411. + /* UTMI+ interface */
  56412. + usbcfg.b.ulpi_utmi_sel = 0;
  56413. + if (core_if->core_params->phy_utmi_width == 16) {
  56414. + usbcfg.b.phyif = 1;
  56415. +
  56416. + } else {
  56417. + usbcfg.b.phyif = 0;
  56418. + }
  56419. + } else {
  56420. + DWC_ERROR("FS PHY TYPE\n");
  56421. + }
  56422. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  56423. + /* Reset after setting the PHY parameters */
  56424. + dwc_otg_core_reset(core_if);
  56425. + }
  56426. + }
  56427. +
  56428. + if ((core_if->hwcfg2.b.hs_phy_type == 2) &&
  56429. + (core_if->hwcfg2.b.fs_phy_type == 1) &&
  56430. + (core_if->core_params->ulpi_fs_ls)) {
  56431. + DWC_DEBUGPL(DBG_CIL, "Setting ULPI FSLS\n");
  56432. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  56433. + usbcfg.b.ulpi_fsls = 1;
  56434. + usbcfg.b.ulpi_clk_sus_m = 1;
  56435. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  56436. + } else {
  56437. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  56438. + usbcfg.b.ulpi_fsls = 0;
  56439. + usbcfg.b.ulpi_clk_sus_m = 0;
  56440. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  56441. + }
  56442. +
  56443. + /* Program the GAHBCFG Register. */
  56444. + switch (core_if->hwcfg2.b.architecture) {
  56445. +
  56446. + case DWC_SLAVE_ONLY_ARCH:
  56447. + DWC_DEBUGPL(DBG_CIL, "Slave Only Mode\n");
  56448. + ahbcfg.b.nptxfemplvl_txfemplvl =
  56449. + DWC_GAHBCFG_TXFEMPTYLVL_HALFEMPTY;
  56450. + ahbcfg.b.ptxfemplvl = DWC_GAHBCFG_TXFEMPTYLVL_HALFEMPTY;
  56451. + core_if->dma_enable = 0;
  56452. + core_if->dma_desc_enable = 0;
  56453. + break;
  56454. +
  56455. + case DWC_EXT_DMA_ARCH:
  56456. + DWC_DEBUGPL(DBG_CIL, "External DMA Mode\n");
  56457. + {
  56458. + uint8_t brst_sz = core_if->core_params->dma_burst_size;
  56459. + ahbcfg.b.hburstlen = 0;
  56460. + while (brst_sz > 1) {
  56461. + ahbcfg.b.hburstlen++;
  56462. + brst_sz >>= 1;
  56463. + }
  56464. + }
  56465. + core_if->dma_enable = (core_if->core_params->dma_enable != 0);
  56466. + core_if->dma_desc_enable =
  56467. + (core_if->core_params->dma_desc_enable != 0);
  56468. + break;
  56469. +
  56470. + case DWC_INT_DMA_ARCH:
  56471. + DWC_DEBUGPL(DBG_CIL, "Internal DMA Mode\n");
  56472. + /* Old value was DWC_GAHBCFG_INT_DMA_BURST_INCR - done for
  56473. + Host mode ISOC in issue fix - vahrama */
  56474. + /* Broadcom had altered to (1<<3)|(0<<0) - WRESP=1, max 4 beats */
  56475. + ahbcfg.b.hburstlen = (1<<3)|(0<<0);//DWC_GAHBCFG_INT_DMA_BURST_INCR4;
  56476. + core_if->dma_enable = (core_if->core_params->dma_enable != 0);
  56477. + core_if->dma_desc_enable =
  56478. + (core_if->core_params->dma_desc_enable != 0);
  56479. + break;
  56480. +
  56481. + }
  56482. + if (core_if->dma_enable) {
  56483. + if (core_if->dma_desc_enable) {
  56484. + DWC_PRINTF("Using Descriptor DMA mode\n");
  56485. + } else {
  56486. + DWC_PRINTF("Using Buffer DMA mode\n");
  56487. +
  56488. + }
  56489. + } else {
  56490. + DWC_PRINTF("Using Slave mode\n");
  56491. + core_if->dma_desc_enable = 0;
  56492. + }
  56493. +
  56494. + if (core_if->core_params->ahb_single) {
  56495. + ahbcfg.b.ahbsingle = 1;
  56496. + }
  56497. +
  56498. + ahbcfg.b.dmaenable = core_if->dma_enable;
  56499. + DWC_WRITE_REG32(&global_regs->gahbcfg, ahbcfg.d32);
  56500. +
  56501. + core_if->en_multiple_tx_fifo = core_if->hwcfg4.b.ded_fifo_en;
  56502. +
  56503. + core_if->pti_enh_enable = core_if->core_params->pti_enable != 0;
  56504. + core_if->multiproc_int_enable = core_if->core_params->mpi_enable;
  56505. + DWC_PRINTF("Periodic Transfer Interrupt Enhancement - %s\n",
  56506. + ((core_if->pti_enh_enable) ? "enabled" : "disabled"));
  56507. + DWC_PRINTF("Multiprocessor Interrupt Enhancement - %s\n",
  56508. + ((core_if->multiproc_int_enable) ? "enabled" : "disabled"));
  56509. +
  56510. + /*
  56511. + * Program the GUSBCFG register.
  56512. + */
  56513. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  56514. +
  56515. + switch (core_if->hwcfg2.b.op_mode) {
  56516. + case DWC_MODE_HNP_SRP_CAPABLE:
  56517. + usbcfg.b.hnpcap = (core_if->core_params->otg_cap ==
  56518. + DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE);
  56519. + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
  56520. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  56521. + break;
  56522. +
  56523. + case DWC_MODE_SRP_ONLY_CAPABLE:
  56524. + usbcfg.b.hnpcap = 0;
  56525. + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
  56526. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  56527. + break;
  56528. +
  56529. + case DWC_MODE_NO_HNP_SRP_CAPABLE:
  56530. + usbcfg.b.hnpcap = 0;
  56531. + usbcfg.b.srpcap = 0;
  56532. + break;
  56533. +
  56534. + case DWC_MODE_SRP_CAPABLE_DEVICE:
  56535. + usbcfg.b.hnpcap = 0;
  56536. + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
  56537. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  56538. + break;
  56539. +
  56540. + case DWC_MODE_NO_SRP_CAPABLE_DEVICE:
  56541. + usbcfg.b.hnpcap = 0;
  56542. + usbcfg.b.srpcap = 0;
  56543. + break;
  56544. +
  56545. + case DWC_MODE_SRP_CAPABLE_HOST:
  56546. + usbcfg.b.hnpcap = 0;
  56547. + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
  56548. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  56549. + break;
  56550. +
  56551. + case DWC_MODE_NO_SRP_CAPABLE_HOST:
  56552. + usbcfg.b.hnpcap = 0;
  56553. + usbcfg.b.srpcap = 0;
  56554. + break;
  56555. + }
  56556. +
  56557. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  56558. +
  56559. +#ifdef CONFIG_USB_DWC_OTG_LPM
  56560. + if (core_if->core_params->lpm_enable) {
  56561. + glpmcfg_data_t lpmcfg = {.d32 = 0 };
  56562. +
  56563. + /* To enable LPM support set lpm_cap_en bit */
  56564. + lpmcfg.b.lpm_cap_en = 1;
  56565. +
  56566. + /* Make AppL1Res ACK */
  56567. + lpmcfg.b.appl_resp = 1;
  56568. +
  56569. + /* Retry 3 times */
  56570. + lpmcfg.b.retry_count = 3;
  56571. +
  56572. + DWC_MODIFY_REG32(&core_if->core_global_regs->glpmcfg,
  56573. + 0, lpmcfg.d32);
  56574. +
  56575. + }
  56576. +#endif
  56577. + if (core_if->core_params->ic_usb_cap) {
  56578. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  56579. + gusbcfg.b.ic_usb_cap = 1;
  56580. + DWC_MODIFY_REG32(&core_if->core_global_regs->gusbcfg,
  56581. + 0, gusbcfg.d32);
  56582. + }
  56583. + {
  56584. + gotgctl_data_t gotgctl = {.d32 = 0 };
  56585. + gotgctl.b.otgver = core_if->core_params->otg_ver;
  56586. + DWC_MODIFY_REG32(&core_if->core_global_regs->gotgctl, 0,
  56587. + gotgctl.d32);
  56588. + /* Set OTG version supported */
  56589. + core_if->otg_ver = core_if->core_params->otg_ver;
  56590. + DWC_PRINTF("OTG VER PARAM: %d, OTG VER FLAG: %d\n",
  56591. + core_if->core_params->otg_ver, core_if->otg_ver);
  56592. + }
  56593. +
  56594. +
  56595. + /* Enable common interrupts */
  56596. + dwc_otg_enable_common_interrupts(core_if);
  56597. +
  56598. + /* Do device or host intialization based on mode during PCD
  56599. + * and HCD initialization */
  56600. + if (dwc_otg_is_host_mode(core_if)) {
  56601. + DWC_DEBUGPL(DBG_ANY, "Host Mode\n");
  56602. + core_if->op_state = A_HOST;
  56603. + } else {
  56604. + DWC_DEBUGPL(DBG_ANY, "Device Mode\n");
  56605. + core_if->op_state = B_PERIPHERAL;
  56606. +#ifdef DWC_DEVICE_ONLY
  56607. + dwc_otg_core_dev_init(core_if);
  56608. +#endif
  56609. + }
  56610. +}
  56611. +
  56612. +/**
  56613. + * This function enables the Device mode interrupts.
  56614. + *
  56615. + * @param core_if Programming view of DWC_otg controller
  56616. + */
  56617. +void dwc_otg_enable_device_interrupts(dwc_otg_core_if_t * core_if)
  56618. +{
  56619. + gintmsk_data_t intr_mask = {.d32 = 0 };
  56620. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  56621. +
  56622. + DWC_DEBUGPL(DBG_CIL, "%s()\n", __func__);
  56623. +
  56624. + /* Disable all interrupts. */
  56625. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  56626. +
  56627. + /* Clear any pending interrupts */
  56628. + DWC_WRITE_REG32(&global_regs->gintsts, 0xFFFFFFFF);
  56629. +
  56630. + /* Enable the common interrupts */
  56631. + dwc_otg_enable_common_interrupts(core_if);
  56632. +
  56633. + /* Enable interrupts */
  56634. + intr_mask.b.usbreset = 1;
  56635. + intr_mask.b.enumdone = 1;
  56636. + /* Disable Disconnect interrupt in Device mode */
  56637. + intr_mask.b.disconnect = 0;
  56638. +
  56639. + if (!core_if->multiproc_int_enable) {
  56640. + intr_mask.b.inepintr = 1;
  56641. + intr_mask.b.outepintr = 1;
  56642. + }
  56643. +
  56644. + intr_mask.b.erlysuspend = 1;
  56645. +
  56646. + if (core_if->en_multiple_tx_fifo == 0) {
  56647. + intr_mask.b.epmismatch = 1;
  56648. + }
  56649. +
  56650. + //intr_mask.b.incomplisoout = 1;
  56651. + intr_mask.b.incomplisoin = 1;
  56652. +
  56653. +/* Enable the ignore frame number for ISOC xfers - MAS */
  56654. +/* Disable to support high bandwith ISOC transfers - manukz */
  56655. +#if 0
  56656. +#ifdef DWC_UTE_PER_IO
  56657. + if (core_if->dma_enable) {
  56658. + if (core_if->dma_desc_enable) {
  56659. + dctl_data_t dctl1 = {.d32 = 0 };
  56660. + dctl1.b.ifrmnum = 1;
  56661. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  56662. + dctl, 0, dctl1.d32);
  56663. + DWC_DEBUG("----Enabled Ignore frame number (0x%08x)",
  56664. + DWC_READ_REG32(&core_if->dev_if->
  56665. + dev_global_regs->dctl));
  56666. + }
  56667. + }
  56668. +#endif
  56669. +#endif
  56670. +#ifdef DWC_EN_ISOC
  56671. + if (core_if->dma_enable) {
  56672. + if (core_if->dma_desc_enable == 0) {
  56673. + if (core_if->pti_enh_enable) {
  56674. + dctl_data_t dctl = {.d32 = 0 };
  56675. + dctl.b.ifrmnum = 1;
  56676. + DWC_MODIFY_REG32(&core_if->
  56677. + dev_if->dev_global_regs->dctl,
  56678. + 0, dctl.d32);
  56679. + } else {
  56680. + intr_mask.b.incomplisoin = 1;
  56681. + intr_mask.b.incomplisoout = 1;
  56682. + }
  56683. + }
  56684. + } else {
  56685. + intr_mask.b.incomplisoin = 1;
  56686. + intr_mask.b.incomplisoout = 1;
  56687. + }
  56688. +#endif /* DWC_EN_ISOC */
  56689. +
  56690. + /** @todo NGS: Should this be a module parameter? */
  56691. +#ifdef USE_PERIODIC_EP
  56692. + intr_mask.b.isooutdrop = 1;
  56693. + intr_mask.b.eopframe = 1;
  56694. + intr_mask.b.incomplisoin = 1;
  56695. + intr_mask.b.incomplisoout = 1;
  56696. +#endif
  56697. +
  56698. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32, intr_mask.d32);
  56699. +
  56700. + DWC_DEBUGPL(DBG_CIL, "%s() gintmsk=%0x\n", __func__,
  56701. + DWC_READ_REG32(&global_regs->gintmsk));
  56702. +}
  56703. +
  56704. +/**
  56705. + * This function initializes the DWC_otg controller registers for
  56706. + * device mode.
  56707. + *
  56708. + * @param core_if Programming view of DWC_otg controller
  56709. + *
  56710. + */
  56711. +void dwc_otg_core_dev_init(dwc_otg_core_if_t * core_if)
  56712. +{
  56713. + int i;
  56714. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  56715. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  56716. + dwc_otg_core_params_t *params = core_if->core_params;
  56717. + dcfg_data_t dcfg = {.d32 = 0 };
  56718. + depctl_data_t diepctl = {.d32 = 0 };
  56719. + grstctl_t resetctl = {.d32 = 0 };
  56720. + uint32_t rx_fifo_size;
  56721. + fifosize_data_t nptxfifosize;
  56722. + fifosize_data_t txfifosize;
  56723. + dthrctl_data_t dthrctl;
  56724. + fifosize_data_t ptxfifosize;
  56725. + uint16_t rxfsiz, nptxfsiz;
  56726. + gdfifocfg_data_t gdfifocfg = {.d32 = 0 };
  56727. + hwcfg3_data_t hwcfg3 = {.d32 = 0 };
  56728. +
  56729. + /* Restart the Phy Clock */
  56730. + DWC_WRITE_REG32(core_if->pcgcctl, 0);
  56731. +
  56732. + /* Device configuration register */
  56733. + init_devspd(core_if);
  56734. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  56735. + dcfg.b.descdma = (core_if->dma_desc_enable) ? 1 : 0;
  56736. + dcfg.b.perfrint = DWC_DCFG_FRAME_INTERVAL_80;
  56737. + /* Enable Device OUT NAK in case of DDMA mode*/
  56738. + if (core_if->core_params->dev_out_nak) {
  56739. + dcfg.b.endevoutnak = 1;
  56740. + }
  56741. +
  56742. + if (core_if->core_params->cont_on_bna) {
  56743. + dctl_data_t dctl = {.d32 = 0 };
  56744. + dctl.b.encontonbna = 1;
  56745. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, 0, dctl.d32);
  56746. + }
  56747. +
  56748. +
  56749. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  56750. +
  56751. + /* Configure data FIFO sizes */
  56752. + if (core_if->hwcfg2.b.dynamic_fifo && params->enable_dynamic_fifo) {
  56753. + DWC_DEBUGPL(DBG_CIL, "Total FIFO Size=%d\n",
  56754. + core_if->total_fifo_size);
  56755. + DWC_DEBUGPL(DBG_CIL, "Rx FIFO Size=%d\n",
  56756. + params->dev_rx_fifo_size);
  56757. + DWC_DEBUGPL(DBG_CIL, "NP Tx FIFO Size=%d\n",
  56758. + params->dev_nperio_tx_fifo_size);
  56759. +
  56760. + /* Rx FIFO */
  56761. + DWC_DEBUGPL(DBG_CIL, "initial grxfsiz=%08x\n",
  56762. + DWC_READ_REG32(&global_regs->grxfsiz));
  56763. +
  56764. +#ifdef DWC_UTE_CFI
  56765. + core_if->pwron_rxfsiz = DWC_READ_REG32(&global_regs->grxfsiz);
  56766. + core_if->init_rxfsiz = params->dev_rx_fifo_size;
  56767. +#endif
  56768. + rx_fifo_size = params->dev_rx_fifo_size;
  56769. + DWC_WRITE_REG32(&global_regs->grxfsiz, rx_fifo_size);
  56770. +
  56771. + DWC_DEBUGPL(DBG_CIL, "new grxfsiz=%08x\n",
  56772. + DWC_READ_REG32(&global_regs->grxfsiz));
  56773. +
  56774. + /** Set Periodic Tx FIFO Mask all bits 0 */
  56775. + core_if->p_tx_msk = 0;
  56776. +
  56777. + /** Set Tx FIFO Mask all bits 0 */
  56778. + core_if->tx_msk = 0;
  56779. +
  56780. + if (core_if->en_multiple_tx_fifo == 0) {
  56781. + /* Non-periodic Tx FIFO */
  56782. + DWC_DEBUGPL(DBG_CIL, "initial gnptxfsiz=%08x\n",
  56783. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  56784. +
  56785. + nptxfifosize.b.depth = params->dev_nperio_tx_fifo_size;
  56786. + nptxfifosize.b.startaddr = params->dev_rx_fifo_size;
  56787. +
  56788. + DWC_WRITE_REG32(&global_regs->gnptxfsiz,
  56789. + nptxfifosize.d32);
  56790. +
  56791. + DWC_DEBUGPL(DBG_CIL, "new gnptxfsiz=%08x\n",
  56792. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  56793. +
  56794. + /**@todo NGS: Fix Periodic FIFO Sizing! */
  56795. + /*
  56796. + * Periodic Tx FIFOs These FIFOs are numbered from 1 to 15.
  56797. + * Indexes of the FIFO size module parameters in the
  56798. + * dev_perio_tx_fifo_size array and the FIFO size registers in
  56799. + * the dptxfsiz array run from 0 to 14.
  56800. + */
  56801. + /** @todo Finish debug of this */
  56802. + ptxfifosize.b.startaddr =
  56803. + nptxfifosize.b.startaddr + nptxfifosize.b.depth;
  56804. + for (i = 0; i < core_if->hwcfg4.b.num_dev_perio_in_ep; i++) {
  56805. + ptxfifosize.b.depth =
  56806. + params->dev_perio_tx_fifo_size[i];
  56807. + DWC_DEBUGPL(DBG_CIL,
  56808. + "initial dtxfsiz[%d]=%08x\n", i,
  56809. + DWC_READ_REG32(&global_regs->dtxfsiz
  56810. + [i]));
  56811. + DWC_WRITE_REG32(&global_regs->dtxfsiz[i],
  56812. + ptxfifosize.d32);
  56813. + DWC_DEBUGPL(DBG_CIL, "new dtxfsiz[%d]=%08x\n",
  56814. + i,
  56815. + DWC_READ_REG32(&global_regs->dtxfsiz
  56816. + [i]));
  56817. + ptxfifosize.b.startaddr += ptxfifosize.b.depth;
  56818. + }
  56819. + } else {
  56820. + /*
  56821. + * Tx FIFOs These FIFOs are numbered from 1 to 15.
  56822. + * Indexes of the FIFO size module parameters in the
  56823. + * dev_tx_fifo_size array and the FIFO size registers in
  56824. + * the dtxfsiz array run from 0 to 14.
  56825. + */
  56826. +
  56827. + /* Non-periodic Tx FIFO */
  56828. + DWC_DEBUGPL(DBG_CIL, "initial gnptxfsiz=%08x\n",
  56829. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  56830. +
  56831. +#ifdef DWC_UTE_CFI
  56832. + core_if->pwron_gnptxfsiz =
  56833. + (DWC_READ_REG32(&global_regs->gnptxfsiz) >> 16);
  56834. + core_if->init_gnptxfsiz =
  56835. + params->dev_nperio_tx_fifo_size;
  56836. +#endif
  56837. + nptxfifosize.b.depth = params->dev_nperio_tx_fifo_size;
  56838. + nptxfifosize.b.startaddr = params->dev_rx_fifo_size;
  56839. +
  56840. + DWC_WRITE_REG32(&global_regs->gnptxfsiz,
  56841. + nptxfifosize.d32);
  56842. +
  56843. + DWC_DEBUGPL(DBG_CIL, "new gnptxfsiz=%08x\n",
  56844. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  56845. +
  56846. + txfifosize.b.startaddr =
  56847. + nptxfifosize.b.startaddr + nptxfifosize.b.depth;
  56848. +
  56849. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  56850. +
  56851. + txfifosize.b.depth =
  56852. + params->dev_tx_fifo_size[i];
  56853. +
  56854. + DWC_DEBUGPL(DBG_CIL,
  56855. + "initial dtxfsiz[%d]=%08x\n",
  56856. + i,
  56857. + DWC_READ_REG32(&global_regs->dtxfsiz
  56858. + [i]));
  56859. +
  56860. +#ifdef DWC_UTE_CFI
  56861. + core_if->pwron_txfsiz[i] =
  56862. + (DWC_READ_REG32
  56863. + (&global_regs->dtxfsiz[i]) >> 16);
  56864. + core_if->init_txfsiz[i] =
  56865. + params->dev_tx_fifo_size[i];
  56866. +#endif
  56867. + DWC_WRITE_REG32(&global_regs->dtxfsiz[i],
  56868. + txfifosize.d32);
  56869. +
  56870. + DWC_DEBUGPL(DBG_CIL,
  56871. + "new dtxfsiz[%d]=%08x\n",
  56872. + i,
  56873. + DWC_READ_REG32(&global_regs->dtxfsiz
  56874. + [i]));
  56875. +
  56876. + txfifosize.b.startaddr += txfifosize.b.depth;
  56877. + }
  56878. + if (core_if->snpsid <= OTG_CORE_REV_2_94a) {
  56879. + /* Calculating DFIFOCFG for Device mode to include RxFIFO and NPTXFIFO */
  56880. + gdfifocfg.d32 = DWC_READ_REG32(&global_regs->gdfifocfg);
  56881. + hwcfg3.d32 = DWC_READ_REG32(&global_regs->ghwcfg3);
  56882. + gdfifocfg.b.gdfifocfg = (DWC_READ_REG32(&global_regs->ghwcfg3) >> 16);
  56883. + DWC_WRITE_REG32(&global_regs->gdfifocfg, gdfifocfg.d32);
  56884. + rxfsiz = (DWC_READ_REG32(&global_regs->grxfsiz) & 0x0000ffff);
  56885. + nptxfsiz = (DWC_READ_REG32(&global_regs->gnptxfsiz) >> 16);
  56886. + gdfifocfg.b.epinfobase = rxfsiz + nptxfsiz;
  56887. + DWC_WRITE_REG32(&global_regs->gdfifocfg, gdfifocfg.d32);
  56888. + }
  56889. + }
  56890. +
  56891. + /* Flush the FIFOs */
  56892. + dwc_otg_flush_tx_fifo(core_if, 0x10); /* all Tx FIFOs */
  56893. + dwc_otg_flush_rx_fifo(core_if);
  56894. +
  56895. + /* Flush the Learning Queue. */
  56896. + resetctl.b.intknqflsh = 1;
  56897. + DWC_WRITE_REG32(&core_if->core_global_regs->grstctl, resetctl.d32);
  56898. +
  56899. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable) {
  56900. + core_if->start_predict = 0;
  56901. + for (i = 0; i<= core_if->dev_if->num_in_eps; ++i) {
  56902. + core_if->nextep_seq[i] = 0xff; // 0xff - EP not active
  56903. + }
  56904. + core_if->nextep_seq[0] = 0;
  56905. + core_if->first_in_nextep_seq = 0;
  56906. + diepctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl);
  56907. + diepctl.b.nextep = 0;
  56908. + DWC_WRITE_REG32(&dev_if->in_ep_regs[0]->diepctl, diepctl.d32);
  56909. +
  56910. + /* Update IN Endpoint Mismatch Count by active IN NP EP count + 1 */
  56911. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  56912. + dcfg.b.epmscnt = 2;
  56913. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  56914. +
  56915. + DWC_DEBUGPL(DBG_CILV,"%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  56916. + __func__, core_if->first_in_nextep_seq);
  56917. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  56918. + DWC_DEBUGPL(DBG_CILV, "%2d ", core_if->nextep_seq[i]);
  56919. + }
  56920. + DWC_DEBUGPL(DBG_CILV,"\n");
  56921. + }
  56922. +
  56923. + /* Clear all pending Device Interrupts */
  56924. + /** @todo - if the condition needed to be checked
  56925. + * or in any case all pending interrutps should be cleared?
  56926. + */
  56927. + if (core_if->multiproc_int_enable) {
  56928. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  56929. + DWC_WRITE_REG32(&dev_if->
  56930. + dev_global_regs->diepeachintmsk[i], 0);
  56931. + }
  56932. + }
  56933. +
  56934. + for (i = 0; i < core_if->dev_if->num_out_eps; ++i) {
  56935. + DWC_WRITE_REG32(&dev_if->
  56936. + dev_global_regs->doepeachintmsk[i], 0);
  56937. + }
  56938. +
  56939. + DWC_WRITE_REG32(&dev_if->dev_global_regs->deachint, 0xFFFFFFFF);
  56940. + DWC_WRITE_REG32(&dev_if->dev_global_regs->deachintmsk, 0);
  56941. + } else {
  56942. + DWC_WRITE_REG32(&dev_if->dev_global_regs->diepmsk, 0);
  56943. + DWC_WRITE_REG32(&dev_if->dev_global_regs->doepmsk, 0);
  56944. + DWC_WRITE_REG32(&dev_if->dev_global_regs->daint, 0xFFFFFFFF);
  56945. + DWC_WRITE_REG32(&dev_if->dev_global_regs->daintmsk, 0);
  56946. + }
  56947. +
  56948. + for (i = 0; i <= dev_if->num_in_eps; i++) {
  56949. + depctl_data_t depctl;
  56950. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  56951. + if (depctl.b.epena) {
  56952. + depctl.d32 = 0;
  56953. + depctl.b.epdis = 1;
  56954. + depctl.b.snak = 1;
  56955. + } else {
  56956. + depctl.d32 = 0;
  56957. + }
  56958. +
  56959. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepctl, depctl.d32);
  56960. +
  56961. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->dieptsiz, 0);
  56962. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepdma, 0);
  56963. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepint, 0xFF);
  56964. + }
  56965. +
  56966. + for (i = 0; i <= dev_if->num_out_eps; i++) {
  56967. + depctl_data_t depctl;
  56968. + depctl.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[i]->doepctl);
  56969. + if (depctl.b.epena) {
  56970. + dctl_data_t dctl = {.d32 = 0 };
  56971. + gintmsk_data_t gintsts = {.d32 = 0 };
  56972. + doepint_data_t doepint = {.d32 = 0 };
  56973. + dctl.b.sgoutnak = 1;
  56974. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  56975. + do {
  56976. + dwc_udelay(10);
  56977. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  56978. + } while (!gintsts.b.goutnakeff);
  56979. + gintsts.d32 = 0;
  56980. + gintsts.b.goutnakeff = 1;
  56981. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  56982. +
  56983. + depctl.d32 = 0;
  56984. + depctl.b.epdis = 1;
  56985. + depctl.b.snak = 1;
  56986. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[i]->doepctl, depctl.d32);
  56987. + do {
  56988. + dwc_udelay(10);
  56989. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  56990. + out_ep_regs[i]->doepint);
  56991. + } while (!doepint.b.epdisabled);
  56992. +
  56993. + doepint.b.epdisabled = 1;
  56994. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[i]->doepint, doepint.d32);
  56995. +
  56996. + dctl.d32 = 0;
  56997. + dctl.b.cgoutnak = 1;
  56998. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  56999. + } else {
  57000. + depctl.d32 = 0;
  57001. + }
  57002. +
  57003. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepctl, depctl.d32);
  57004. +
  57005. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doeptsiz, 0);
  57006. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepdma, 0);
  57007. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepint, 0xFF);
  57008. + }
  57009. +
  57010. + if (core_if->en_multiple_tx_fifo && core_if->dma_enable) {
  57011. + dev_if->non_iso_tx_thr_en = params->thr_ctl & 0x1;
  57012. + dev_if->iso_tx_thr_en = (params->thr_ctl >> 1) & 0x1;
  57013. + dev_if->rx_thr_en = (params->thr_ctl >> 2) & 0x1;
  57014. +
  57015. + dev_if->rx_thr_length = params->rx_thr_length;
  57016. + dev_if->tx_thr_length = params->tx_thr_length;
  57017. +
  57018. + dev_if->setup_desc_index = 0;
  57019. +
  57020. + dthrctl.d32 = 0;
  57021. + dthrctl.b.non_iso_thr_en = dev_if->non_iso_tx_thr_en;
  57022. + dthrctl.b.iso_thr_en = dev_if->iso_tx_thr_en;
  57023. + dthrctl.b.tx_thr_len = dev_if->tx_thr_length;
  57024. + dthrctl.b.rx_thr_en = dev_if->rx_thr_en;
  57025. + dthrctl.b.rx_thr_len = dev_if->rx_thr_length;
  57026. + dthrctl.b.ahb_thr_ratio = params->ahb_thr_ratio;
  57027. +
  57028. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dtknqr3_dthrctl,
  57029. + dthrctl.d32);
  57030. +
  57031. + DWC_DEBUGPL(DBG_CIL,
  57032. + "Non ISO Tx Thr - %d\nISO Tx Thr - %d\nRx Thr - %d\nTx Thr Len - %d\nRx Thr Len - %d\n",
  57033. + dthrctl.b.non_iso_thr_en, dthrctl.b.iso_thr_en,
  57034. + dthrctl.b.rx_thr_en, dthrctl.b.tx_thr_len,
  57035. + dthrctl.b.rx_thr_len);
  57036. +
  57037. + }
  57038. +
  57039. + dwc_otg_enable_device_interrupts(core_if);
  57040. +
  57041. + {
  57042. + diepmsk_data_t msk = {.d32 = 0 };
  57043. + msk.b.txfifoundrn = 1;
  57044. + if (core_if->multiproc_int_enable) {
  57045. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->
  57046. + diepeachintmsk[0], msk.d32, msk.d32);
  57047. + } else {
  57048. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->diepmsk,
  57049. + msk.d32, msk.d32);
  57050. + }
  57051. + }
  57052. +
  57053. + if (core_if->multiproc_int_enable) {
  57054. + /* Set NAK on Babble */
  57055. + dctl_data_t dctl = {.d32 = 0 };
  57056. + dctl.b.nakonbble = 1;
  57057. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, 0, dctl.d32);
  57058. + }
  57059. +
  57060. + if (core_if->snpsid >= OTG_CORE_REV_2_94a) {
  57061. + dctl_data_t dctl = {.d32 = 0 };
  57062. + dctl.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dctl);
  57063. + dctl.b.sftdiscon = 0;
  57064. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dctl, dctl.d32);
  57065. + }
  57066. +}
  57067. +
  57068. +/**
  57069. + * This function enables the Host mode interrupts.
  57070. + *
  57071. + * @param core_if Programming view of DWC_otg controller
  57072. + */
  57073. +void dwc_otg_enable_host_interrupts(dwc_otg_core_if_t * core_if)
  57074. +{
  57075. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  57076. + gintmsk_data_t intr_mask = {.d32 = 0 };
  57077. +
  57078. + DWC_DEBUGPL(DBG_CIL, "%s(%p)\n", __func__, core_if);
  57079. +
  57080. + /* Disable all interrupts. */
  57081. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  57082. +
  57083. + /* Clear any pending interrupts. */
  57084. + DWC_WRITE_REG32(&global_regs->gintsts, 0xFFFFFFFF);
  57085. +
  57086. + /* Enable the common interrupts */
  57087. + dwc_otg_enable_common_interrupts(core_if);
  57088. +
  57089. + /*
  57090. + * Enable host mode interrupts without disturbing common
  57091. + * interrupts.
  57092. + */
  57093. +
  57094. + intr_mask.b.disconnect = 1;
  57095. + intr_mask.b.portintr = 1;
  57096. + intr_mask.b.hcintr = 1;
  57097. +
  57098. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32, intr_mask.d32);
  57099. +}
  57100. +
  57101. +/**
  57102. + * This function disables the Host Mode interrupts.
  57103. + *
  57104. + * @param core_if Programming view of DWC_otg controller
  57105. + */
  57106. +void dwc_otg_disable_host_interrupts(dwc_otg_core_if_t * core_if)
  57107. +{
  57108. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  57109. + gintmsk_data_t intr_mask = {.d32 = 0 };
  57110. +
  57111. + DWC_DEBUGPL(DBG_CILV, "%s()\n", __func__);
  57112. +
  57113. + /*
  57114. + * Disable host mode interrupts without disturbing common
  57115. + * interrupts.
  57116. + */
  57117. + intr_mask.b.sofintr = 1;
  57118. + intr_mask.b.portintr = 1;
  57119. + intr_mask.b.hcintr = 1;
  57120. + intr_mask.b.ptxfempty = 1;
  57121. + intr_mask.b.nptxfempty = 1;
  57122. +
  57123. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32, 0);
  57124. +}
  57125. +
  57126. +/**
  57127. + * This function initializes the DWC_otg controller registers for
  57128. + * host mode.
  57129. + *
  57130. + * This function flushes the Tx and Rx FIFOs and it flushes any entries in the
  57131. + * request queues. Host channels are reset to ensure that they are ready for
  57132. + * performing transfers.
  57133. + *
  57134. + * @param core_if Programming view of DWC_otg controller
  57135. + *
  57136. + */
  57137. +void dwc_otg_core_host_init(dwc_otg_core_if_t * core_if)
  57138. +{
  57139. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  57140. + dwc_otg_host_if_t *host_if = core_if->host_if;
  57141. + dwc_otg_core_params_t *params = core_if->core_params;
  57142. + hprt0_data_t hprt0 = {.d32 = 0 };
  57143. + fifosize_data_t nptxfifosize;
  57144. + fifosize_data_t ptxfifosize;
  57145. + uint16_t rxfsiz, nptxfsiz, hptxfsiz;
  57146. + gdfifocfg_data_t gdfifocfg = {.d32 = 0 };
  57147. + int i;
  57148. + hcchar_data_t hcchar;
  57149. + hcfg_data_t hcfg;
  57150. + hfir_data_t hfir;
  57151. + dwc_otg_hc_regs_t *hc_regs;
  57152. + int num_channels;
  57153. + gotgctl_data_t gotgctl = {.d32 = 0 };
  57154. +
  57155. + DWC_DEBUGPL(DBG_CILV, "%s(%p)\n", __func__, core_if);
  57156. +
  57157. + /* Restart the Phy Clock */
  57158. + DWC_WRITE_REG32(core_if->pcgcctl, 0);
  57159. +
  57160. + /* Initialize Host Configuration Register */
  57161. + init_fslspclksel(core_if);
  57162. + if (core_if->core_params->speed == DWC_SPEED_PARAM_FULL) {
  57163. + hcfg.d32 = DWC_READ_REG32(&host_if->host_global_regs->hcfg);
  57164. + hcfg.b.fslssupp = 1;
  57165. + DWC_WRITE_REG32(&host_if->host_global_regs->hcfg, hcfg.d32);
  57166. +
  57167. + }
  57168. +
  57169. + /* This bit allows dynamic reloading of the HFIR register
  57170. + * during runtime. This bit needs to be programmed during
  57171. + * initial configuration and its value must not be changed
  57172. + * during runtime.*/
  57173. + if (core_if->core_params->reload_ctl == 1) {
  57174. + hfir.d32 = DWC_READ_REG32(&host_if->host_global_regs->hfir);
  57175. + hfir.b.hfirrldctrl = 1;
  57176. + DWC_WRITE_REG32(&host_if->host_global_regs->hfir, hfir.d32);
  57177. + }
  57178. +
  57179. + if (core_if->core_params->dma_desc_enable) {
  57180. + uint8_t op_mode = core_if->hwcfg2.b.op_mode;
  57181. + if (!
  57182. + (core_if->hwcfg4.b.desc_dma
  57183. + && (core_if->snpsid >= OTG_CORE_REV_2_90a)
  57184. + && ((op_mode == DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG)
  57185. + || (op_mode == DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG)
  57186. + || (op_mode ==
  57187. + DWC_HWCFG2_OP_MODE_NO_HNP_SRP_CAPABLE_OTG)
  57188. + || (op_mode == DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST)
  57189. + || (op_mode ==
  57190. + DWC_HWCFG2_OP_MODE_NO_SRP_CAPABLE_HOST)))) {
  57191. +
  57192. + DWC_ERROR("Host can't operate in Descriptor DMA mode.\n"
  57193. + "Either core version is below 2.90a or "
  57194. + "GHWCFG2, GHWCFG4 registers' values do not allow Descriptor DMA in host mode.\n"
  57195. + "To run the driver in Buffer DMA host mode set dma_desc_enable "
  57196. + "module parameter to 0.\n");
  57197. + return;
  57198. + }
  57199. + hcfg.d32 = DWC_READ_REG32(&host_if->host_global_regs->hcfg);
  57200. + hcfg.b.descdma = 1;
  57201. + DWC_WRITE_REG32(&host_if->host_global_regs->hcfg, hcfg.d32);
  57202. + }
  57203. +
  57204. + /* Configure data FIFO sizes */
  57205. + if (core_if->hwcfg2.b.dynamic_fifo && params->enable_dynamic_fifo) {
  57206. + DWC_DEBUGPL(DBG_CIL, "Total FIFO Size=%d\n",
  57207. + core_if->total_fifo_size);
  57208. + DWC_DEBUGPL(DBG_CIL, "Rx FIFO Size=%d\n",
  57209. + params->host_rx_fifo_size);
  57210. + DWC_DEBUGPL(DBG_CIL, "NP Tx FIFO Size=%d\n",
  57211. + params->host_nperio_tx_fifo_size);
  57212. + DWC_DEBUGPL(DBG_CIL, "P Tx FIFO Size=%d\n",
  57213. + params->host_perio_tx_fifo_size);
  57214. +
  57215. + /* Rx FIFO */
  57216. + DWC_DEBUGPL(DBG_CIL, "initial grxfsiz=%08x\n",
  57217. + DWC_READ_REG32(&global_regs->grxfsiz));
  57218. + DWC_WRITE_REG32(&global_regs->grxfsiz,
  57219. + params->host_rx_fifo_size);
  57220. + DWC_DEBUGPL(DBG_CIL, "new grxfsiz=%08x\n",
  57221. + DWC_READ_REG32(&global_regs->grxfsiz));
  57222. +
  57223. + /* Non-periodic Tx FIFO */
  57224. + DWC_DEBUGPL(DBG_CIL, "initial gnptxfsiz=%08x\n",
  57225. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  57226. + nptxfifosize.b.depth = params->host_nperio_tx_fifo_size;
  57227. + nptxfifosize.b.startaddr = params->host_rx_fifo_size;
  57228. + DWC_WRITE_REG32(&global_regs->gnptxfsiz, nptxfifosize.d32);
  57229. + DWC_DEBUGPL(DBG_CIL, "new gnptxfsiz=%08x\n",
  57230. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  57231. +
  57232. + /* Periodic Tx FIFO */
  57233. + DWC_DEBUGPL(DBG_CIL, "initial hptxfsiz=%08x\n",
  57234. + DWC_READ_REG32(&global_regs->hptxfsiz));
  57235. + ptxfifosize.b.depth = params->host_perio_tx_fifo_size;
  57236. + ptxfifosize.b.startaddr =
  57237. + nptxfifosize.b.startaddr + nptxfifosize.b.depth;
  57238. + DWC_WRITE_REG32(&global_regs->hptxfsiz, ptxfifosize.d32);
  57239. + DWC_DEBUGPL(DBG_CIL, "new hptxfsiz=%08x\n",
  57240. + DWC_READ_REG32(&global_regs->hptxfsiz));
  57241. +
  57242. + if (core_if->en_multiple_tx_fifo
  57243. + && core_if->snpsid <= OTG_CORE_REV_2_94a) {
  57244. + /* Global DFIFOCFG calculation for Host mode - include RxFIFO, NPTXFIFO and HPTXFIFO */
  57245. + gdfifocfg.d32 = DWC_READ_REG32(&global_regs->gdfifocfg);
  57246. + rxfsiz = (DWC_READ_REG32(&global_regs->grxfsiz) & 0x0000ffff);
  57247. + nptxfsiz = (DWC_READ_REG32(&global_regs->gnptxfsiz) >> 16);
  57248. + hptxfsiz = (DWC_READ_REG32(&global_regs->hptxfsiz) >> 16);
  57249. + gdfifocfg.b.epinfobase = rxfsiz + nptxfsiz + hptxfsiz;
  57250. + DWC_WRITE_REG32(&global_regs->gdfifocfg, gdfifocfg.d32);
  57251. + }
  57252. + }
  57253. +
  57254. + /* TODO - check this */
  57255. + /* Clear Host Set HNP Enable in the OTG Control Register */
  57256. + gotgctl.b.hstsethnpen = 1;
  57257. + DWC_MODIFY_REG32(&global_regs->gotgctl, gotgctl.d32, 0);
  57258. + /* Make sure the FIFOs are flushed. */
  57259. + dwc_otg_flush_tx_fifo(core_if, 0x10 /* all TX FIFOs */ );
  57260. + dwc_otg_flush_rx_fifo(core_if);
  57261. +
  57262. + /* Clear Host Set HNP Enable in the OTG Control Register */
  57263. + gotgctl.b.hstsethnpen = 1;
  57264. + DWC_MODIFY_REG32(&global_regs->gotgctl, gotgctl.d32, 0);
  57265. +
  57266. + if (!core_if->core_params->dma_desc_enable) {
  57267. + /* Flush out any leftover queued requests. */
  57268. + num_channels = core_if->core_params->host_channels;
  57269. +
  57270. + for (i = 0; i < num_channels; i++) {
  57271. + hc_regs = core_if->host_if->hc_regs[i];
  57272. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  57273. + hcchar.b.chen = 0;
  57274. + hcchar.b.chdis = 1;
  57275. + hcchar.b.epdir = 0;
  57276. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  57277. + }
  57278. +
  57279. + /* Halt all channels to put them into a known state. */
  57280. + for (i = 0; i < num_channels; i++) {
  57281. + int count = 0;
  57282. + hc_regs = core_if->host_if->hc_regs[i];
  57283. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  57284. + hcchar.b.chen = 1;
  57285. + hcchar.b.chdis = 1;
  57286. + hcchar.b.epdir = 0;
  57287. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  57288. + DWC_DEBUGPL(DBG_HCDV, "%s: Halt channel %d regs %p\n", __func__, i, hc_regs);
  57289. + do {
  57290. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  57291. + if (++count > 1000) {
  57292. + DWC_ERROR
  57293. + ("%s: Unable to clear halt on channel %d (timeout HCCHAR 0x%X @%p)\n",
  57294. + __func__, i, hcchar.d32, &hc_regs->hcchar);
  57295. + break;
  57296. + }
  57297. + dwc_udelay(1);
  57298. + } while (hcchar.b.chen);
  57299. + }
  57300. + }
  57301. +
  57302. + /* Turn on the vbus power. */
  57303. + DWC_PRINTF("Init: Port Power? op_state=%d\n", core_if->op_state);
  57304. + if (core_if->op_state == A_HOST) {
  57305. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  57306. + DWC_PRINTF("Init: Power Port (%d)\n", hprt0.b.prtpwr);
  57307. + if (hprt0.b.prtpwr == 0) {
  57308. + hprt0.b.prtpwr = 1;
  57309. + DWC_WRITE_REG32(host_if->hprt0, hprt0.d32);
  57310. + }
  57311. + }
  57312. +
  57313. + dwc_otg_enable_host_interrupts(core_if);
  57314. +}
  57315. +
  57316. +/**
  57317. + * Prepares a host channel for transferring packets to/from a specific
  57318. + * endpoint. The HCCHARn register is set up with the characteristics specified
  57319. + * in _hc. Host channel interrupts that may need to be serviced while this
  57320. + * transfer is in progress are enabled.
  57321. + *
  57322. + * @param core_if Programming view of DWC_otg controller
  57323. + * @param hc Information needed to initialize the host channel
  57324. + */
  57325. +void dwc_otg_hc_init(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  57326. +{
  57327. + uint32_t intr_enable;
  57328. + hcintmsk_data_t hc_intr_mask;
  57329. + gintmsk_data_t gintmsk = {.d32 = 0 };
  57330. + hcchar_data_t hcchar;
  57331. + hcsplt_data_t hcsplt;
  57332. +
  57333. + uint8_t hc_num = hc->hc_num;
  57334. + dwc_otg_host_if_t *host_if = core_if->host_if;
  57335. + dwc_otg_hc_regs_t *hc_regs = host_if->hc_regs[hc_num];
  57336. +
  57337. + /* Clear old interrupt conditions for this host channel. */
  57338. + hc_intr_mask.d32 = 0xFFFFFFFF;
  57339. + hc_intr_mask.b.reserved14_31 = 0;
  57340. + DWC_WRITE_REG32(&hc_regs->hcint, hc_intr_mask.d32);
  57341. +
  57342. + /* Enable channel interrupts required for this transfer. */
  57343. + hc_intr_mask.d32 = 0;
  57344. + hc_intr_mask.b.chhltd = 1;
  57345. + if (core_if->dma_enable) {
  57346. + /* For Descriptor DMA mode core halts the channel on AHB error. Interrupt is not required */
  57347. + if (!core_if->dma_desc_enable)
  57348. + hc_intr_mask.b.ahberr = 1;
  57349. + else {
  57350. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)
  57351. + hc_intr_mask.b.xfercompl = 1;
  57352. + }
  57353. +
  57354. + if (hc->error_state && !hc->do_split &&
  57355. + hc->ep_type != DWC_OTG_EP_TYPE_ISOC) {
  57356. + hc_intr_mask.b.ack = 1;
  57357. + if (hc->ep_is_in) {
  57358. + hc_intr_mask.b.datatglerr = 1;
  57359. + if (hc->ep_type != DWC_OTG_EP_TYPE_INTR) {
  57360. + hc_intr_mask.b.nak = 1;
  57361. + }
  57362. + }
  57363. + }
  57364. + } else {
  57365. + switch (hc->ep_type) {
  57366. + case DWC_OTG_EP_TYPE_CONTROL:
  57367. + case DWC_OTG_EP_TYPE_BULK:
  57368. + hc_intr_mask.b.xfercompl = 1;
  57369. + hc_intr_mask.b.stall = 1;
  57370. + hc_intr_mask.b.xacterr = 1;
  57371. + hc_intr_mask.b.datatglerr = 1;
  57372. + if (hc->ep_is_in) {
  57373. + hc_intr_mask.b.bblerr = 1;
  57374. + } else {
  57375. + hc_intr_mask.b.nak = 1;
  57376. + hc_intr_mask.b.nyet = 1;
  57377. + if (hc->do_ping) {
  57378. + hc_intr_mask.b.ack = 1;
  57379. + }
  57380. + }
  57381. +
  57382. + if (hc->do_split) {
  57383. + hc_intr_mask.b.nak = 1;
  57384. + if (hc->complete_split) {
  57385. + hc_intr_mask.b.nyet = 1;
  57386. + } else {
  57387. + hc_intr_mask.b.ack = 1;
  57388. + }
  57389. + }
  57390. +
  57391. + if (hc->error_state) {
  57392. + hc_intr_mask.b.ack = 1;
  57393. + }
  57394. + break;
  57395. + case DWC_OTG_EP_TYPE_INTR:
  57396. + hc_intr_mask.b.xfercompl = 1;
  57397. + hc_intr_mask.b.nak = 1;
  57398. + hc_intr_mask.b.stall = 1;
  57399. + hc_intr_mask.b.xacterr = 1;
  57400. + hc_intr_mask.b.datatglerr = 1;
  57401. + hc_intr_mask.b.frmovrun = 1;
  57402. +
  57403. + if (hc->ep_is_in) {
  57404. + hc_intr_mask.b.bblerr = 1;
  57405. + }
  57406. + if (hc->error_state) {
  57407. + hc_intr_mask.b.ack = 1;
  57408. + }
  57409. + if (hc->do_split) {
  57410. + if (hc->complete_split) {
  57411. + hc_intr_mask.b.nyet = 1;
  57412. + } else {
  57413. + hc_intr_mask.b.ack = 1;
  57414. + }
  57415. + }
  57416. + break;
  57417. + case DWC_OTG_EP_TYPE_ISOC:
  57418. + hc_intr_mask.b.xfercompl = 1;
  57419. + hc_intr_mask.b.frmovrun = 1;
  57420. + hc_intr_mask.b.ack = 1;
  57421. +
  57422. + if (hc->ep_is_in) {
  57423. + hc_intr_mask.b.xacterr = 1;
  57424. + hc_intr_mask.b.bblerr = 1;
  57425. + }
  57426. + break;
  57427. + }
  57428. + }
  57429. + DWC_WRITE_REG32(&hc_regs->hcintmsk, hc_intr_mask.d32);
  57430. +
  57431. + /* Enable the top level host channel interrupt. */
  57432. + intr_enable = (1 << hc_num);
  57433. + DWC_MODIFY_REG32(&host_if->host_global_regs->haintmsk, 0, intr_enable);
  57434. +
  57435. + /* Make sure host channel interrupts are enabled. */
  57436. + gintmsk.b.hcintr = 1;
  57437. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, gintmsk.d32);
  57438. +
  57439. + /*
  57440. + * Program the HCCHARn register with the endpoint characteristics for
  57441. + * the current transfer.
  57442. + */
  57443. + hcchar.d32 = 0;
  57444. + hcchar.b.devaddr = hc->dev_addr;
  57445. + hcchar.b.epnum = hc->ep_num;
  57446. + hcchar.b.epdir = hc->ep_is_in;
  57447. + hcchar.b.lspddev = (hc->speed == DWC_OTG_EP_SPEED_LOW);
  57448. + hcchar.b.eptype = hc->ep_type;
  57449. + hcchar.b.mps = hc->max_packet;
  57450. +
  57451. + DWC_WRITE_REG32(&host_if->hc_regs[hc_num]->hcchar, hcchar.d32);
  57452. +
  57453. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d, Dev Addr %d, EP #%d\n",
  57454. + __func__, hc->hc_num, hcchar.b.devaddr, hcchar.b.epnum);
  57455. + DWC_DEBUGPL(DBG_HCDV, " Is In %d, Is Low Speed %d, EP Type %d, "
  57456. + "Max Pkt %d, Multi Cnt %d\n",
  57457. + hcchar.b.epdir, hcchar.b.lspddev, hcchar.b.eptype,
  57458. + hcchar.b.mps, hcchar.b.multicnt);
  57459. +
  57460. + /*
  57461. + * Program the HCSPLIT register for SPLITs
  57462. + */
  57463. + hcsplt.d32 = 0;
  57464. + if (hc->do_split) {
  57465. + DWC_DEBUGPL(DBG_HCDV, "Programming HC %d with split --> %s\n",
  57466. + hc->hc_num,
  57467. + hc->complete_split ? "CSPLIT" : "SSPLIT");
  57468. + hcsplt.b.compsplt = hc->complete_split;
  57469. + hcsplt.b.xactpos = hc->xact_pos;
  57470. + hcsplt.b.hubaddr = hc->hub_addr;
  57471. + hcsplt.b.prtaddr = hc->port_addr;
  57472. + DWC_DEBUGPL(DBG_HCDV, "\t comp split %d\n", hc->complete_split);
  57473. + DWC_DEBUGPL(DBG_HCDV, "\t xact pos %d\n", hc->xact_pos);
  57474. + DWC_DEBUGPL(DBG_HCDV, "\t hub addr %d\n", hc->hub_addr);
  57475. + DWC_DEBUGPL(DBG_HCDV, "\t port addr %d\n", hc->port_addr);
  57476. + DWC_DEBUGPL(DBG_HCDV, "\t is_in %d\n", hc->ep_is_in);
  57477. + DWC_DEBUGPL(DBG_HCDV, "\t Max Pkt: %d\n", hcchar.b.mps);
  57478. + DWC_DEBUGPL(DBG_HCDV, "\t xferlen: %d\n", hc->xfer_len);
  57479. + }
  57480. + DWC_WRITE_REG32(&host_if->hc_regs[hc_num]->hcsplt, hcsplt.d32);
  57481. +
  57482. +}
  57483. +
  57484. +/**
  57485. + * Attempts to halt a host channel. This function should only be called in
  57486. + * Slave mode or to abort a transfer in either Slave mode or DMA mode. Under
  57487. + * normal circumstances in DMA mode, the controller halts the channel when the
  57488. + * transfer is complete or a condition occurs that requires application
  57489. + * intervention.
  57490. + *
  57491. + * In slave mode, checks for a free request queue entry, then sets the Channel
  57492. + * Enable and Channel Disable bits of the Host Channel Characteristics
  57493. + * register of the specified channel to intiate the halt. If there is no free
  57494. + * request queue entry, sets only the Channel Disable bit of the HCCHARn
  57495. + * register to flush requests for this channel. In the latter case, sets a
  57496. + * flag to indicate that the host channel needs to be halted when a request
  57497. + * queue slot is open.
  57498. + *
  57499. + * In DMA mode, always sets the Channel Enable and Channel Disable bits of the
  57500. + * HCCHARn register. The controller ensures there is space in the request
  57501. + * queue before submitting the halt request.
  57502. + *
  57503. + * Some time may elapse before the core flushes any posted requests for this
  57504. + * host channel and halts. The Channel Halted interrupt handler completes the
  57505. + * deactivation of the host channel.
  57506. + *
  57507. + * @param core_if Controller register interface.
  57508. + * @param hc Host channel to halt.
  57509. + * @param halt_status Reason for halting the channel.
  57510. + */
  57511. +void dwc_otg_hc_halt(dwc_otg_core_if_t * core_if,
  57512. + dwc_hc_t * hc, dwc_otg_halt_status_e halt_status)
  57513. +{
  57514. + gnptxsts_data_t nptxsts;
  57515. + hptxsts_data_t hptxsts;
  57516. + hcchar_data_t hcchar;
  57517. + dwc_otg_hc_regs_t *hc_regs;
  57518. + dwc_otg_core_global_regs_t *global_regs;
  57519. + dwc_otg_host_global_regs_t *host_global_regs;
  57520. +
  57521. + hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  57522. + global_regs = core_if->core_global_regs;
  57523. + host_global_regs = core_if->host_if->host_global_regs;
  57524. +
  57525. + DWC_ASSERT(!(halt_status == DWC_OTG_HC_XFER_NO_HALT_STATUS),
  57526. + "halt_status = %d\n", halt_status);
  57527. +
  57528. + if (halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE ||
  57529. + halt_status == DWC_OTG_HC_XFER_AHB_ERR) {
  57530. + /*
  57531. + * Disable all channel interrupts except Ch Halted. The QTD
  57532. + * and QH state associated with this transfer has been cleared
  57533. + * (in the case of URB_DEQUEUE), so the channel needs to be
  57534. + * shut down carefully to prevent crashes.
  57535. + */
  57536. + hcintmsk_data_t hcintmsk;
  57537. + hcintmsk.d32 = 0;
  57538. + hcintmsk.b.chhltd = 1;
  57539. + DWC_WRITE_REG32(&hc_regs->hcintmsk, hcintmsk.d32);
  57540. +
  57541. + /*
  57542. + * Make sure no other interrupts besides halt are currently
  57543. + * pending. Handling another interrupt could cause a crash due
  57544. + * to the QTD and QH state.
  57545. + */
  57546. + DWC_WRITE_REG32(&hc_regs->hcint, ~hcintmsk.d32);
  57547. +
  57548. + /*
  57549. + * Make sure the halt status is set to URB_DEQUEUE or AHB_ERR
  57550. + * even if the channel was already halted for some other
  57551. + * reason.
  57552. + */
  57553. + hc->halt_status = halt_status;
  57554. +
  57555. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  57556. + if (hcchar.b.chen == 0) {
  57557. + /*
  57558. + * The channel is either already halted or it hasn't
  57559. + * started yet. In DMA mode, the transfer may halt if
  57560. + * it finishes normally or a condition occurs that
  57561. + * requires driver intervention. Don't want to halt
  57562. + * the channel again. In either Slave or DMA mode,
  57563. + * it's possible that the transfer has been assigned
  57564. + * to a channel, but not started yet when an URB is
  57565. + * dequeued. Don't want to halt a channel that hasn't
  57566. + * started yet.
  57567. + */
  57568. + return;
  57569. + }
  57570. + }
  57571. + if (hc->halt_pending) {
  57572. + /*
  57573. + * A halt has already been issued for this channel. This might
  57574. + * happen when a transfer is aborted by a higher level in
  57575. + * the stack.
  57576. + */
  57577. +#ifdef DEBUG
  57578. + DWC_PRINTF
  57579. + ("*** %s: Channel %d, _hc->halt_pending already set ***\n",
  57580. + __func__, hc->hc_num);
  57581. +
  57582. +#endif
  57583. + return;
  57584. + }
  57585. +
  57586. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  57587. +
  57588. + /* No need to set the bit in DDMA for disabling the channel */
  57589. + //TODO check it everywhere channel is disabled
  57590. + if (!core_if->core_params->dma_desc_enable)
  57591. + hcchar.b.chen = 1;
  57592. + hcchar.b.chdis = 1;
  57593. +
  57594. + if (!core_if->dma_enable) {
  57595. + /* Check for space in the request queue to issue the halt. */
  57596. + if (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL ||
  57597. + hc->ep_type == DWC_OTG_EP_TYPE_BULK) {
  57598. + nptxsts.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  57599. + if (nptxsts.b.nptxqspcavail == 0) {
  57600. + hcchar.b.chen = 0;
  57601. + }
  57602. + } else {
  57603. + hptxsts.d32 =
  57604. + DWC_READ_REG32(&host_global_regs->hptxsts);
  57605. + if ((hptxsts.b.ptxqspcavail == 0)
  57606. + || (core_if->queuing_high_bandwidth)) {
  57607. + hcchar.b.chen = 0;
  57608. + }
  57609. + }
  57610. + }
  57611. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  57612. +
  57613. + hc->halt_status = halt_status;
  57614. +
  57615. + if (hcchar.b.chen) {
  57616. + hc->halt_pending = 1;
  57617. + hc->halt_on_queue = 0;
  57618. + } else {
  57619. + hc->halt_on_queue = 1;
  57620. + }
  57621. +
  57622. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  57623. + DWC_DEBUGPL(DBG_HCDV, " hcchar: 0x%08x\n", hcchar.d32);
  57624. + DWC_DEBUGPL(DBG_HCDV, " halt_pending: %d\n", hc->halt_pending);
  57625. + DWC_DEBUGPL(DBG_HCDV, " halt_on_queue: %d\n", hc->halt_on_queue);
  57626. + DWC_DEBUGPL(DBG_HCDV, " halt_status: %d\n", hc->halt_status);
  57627. +
  57628. + return;
  57629. +}
  57630. +
  57631. +/**
  57632. + * Clears the transfer state for a host channel. This function is normally
  57633. + * called after a transfer is done and the host channel is being released.
  57634. + *
  57635. + * @param core_if Programming view of DWC_otg controller.
  57636. + * @param hc Identifies the host channel to clean up.
  57637. + */
  57638. +void dwc_otg_hc_cleanup(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  57639. +{
  57640. + dwc_otg_hc_regs_t *hc_regs;
  57641. +
  57642. + hc->xfer_started = 0;
  57643. +
  57644. + /*
  57645. + * Clear channel interrupt enables and any unhandled channel interrupt
  57646. + * conditions.
  57647. + */
  57648. + hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  57649. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0);
  57650. + DWC_WRITE_REG32(&hc_regs->hcint, 0xFFFFFFFF);
  57651. +#ifdef DEBUG
  57652. + DWC_TIMER_CANCEL(core_if->hc_xfer_timer[hc->hc_num]);
  57653. +#endif
  57654. +}
  57655. +
  57656. +/**
  57657. + * Sets the channel property that indicates in which frame a periodic transfer
  57658. + * should occur. This is always set to the _next_ frame. This function has no
  57659. + * effect on non-periodic transfers.
  57660. + *
  57661. + * @param core_if Programming view of DWC_otg controller.
  57662. + * @param hc Identifies the host channel to set up and its properties.
  57663. + * @param hcchar Current value of the HCCHAR register for the specified host
  57664. + * channel.
  57665. + */
  57666. +static inline void hc_set_even_odd_frame(dwc_otg_core_if_t * core_if,
  57667. + dwc_hc_t * hc, hcchar_data_t * hcchar)
  57668. +{
  57669. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  57670. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  57671. + hfnum_data_t hfnum;
  57672. + hfnum.d32 =
  57673. + DWC_READ_REG32(&core_if->host_if->host_global_regs->hfnum);
  57674. +
  57675. + /* 1 if _next_ frame is odd, 0 if it's even */
  57676. + hcchar->b.oddfrm = (hfnum.b.frnum & 0x1) ? 0 : 1;
  57677. +#ifdef DEBUG
  57678. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR && hc->do_split
  57679. + && !hc->complete_split) {
  57680. + switch (hfnum.b.frnum & 0x7) {
  57681. + case 7:
  57682. + core_if->hfnum_7_samples++;
  57683. + core_if->hfnum_7_frrem_accum += hfnum.b.frrem;
  57684. + break;
  57685. + case 0:
  57686. + core_if->hfnum_0_samples++;
  57687. + core_if->hfnum_0_frrem_accum += hfnum.b.frrem;
  57688. + break;
  57689. + default:
  57690. + core_if->hfnum_other_samples++;
  57691. + core_if->hfnum_other_frrem_accum +=
  57692. + hfnum.b.frrem;
  57693. + break;
  57694. + }
  57695. + }
  57696. +#endif
  57697. + }
  57698. +}
  57699. +
  57700. +#ifdef DEBUG
  57701. +void hc_xfer_timeout(void *ptr)
  57702. +{
  57703. + hc_xfer_info_t *xfer_info = NULL;
  57704. + int hc_num = 0;
  57705. +
  57706. + if (ptr)
  57707. + xfer_info = (hc_xfer_info_t *) ptr;
  57708. +
  57709. + if (!xfer_info->hc) {
  57710. + DWC_ERROR("xfer_info->hc = %p\n", xfer_info->hc);
  57711. + return;
  57712. + }
  57713. +
  57714. + hc_num = xfer_info->hc->hc_num;
  57715. + DWC_WARN("%s: timeout on channel %d\n", __func__, hc_num);
  57716. + DWC_WARN(" start_hcchar_val 0x%08x\n",
  57717. + xfer_info->core_if->start_hcchar_val[hc_num]);
  57718. +}
  57719. +#endif
  57720. +
  57721. +void ep_xfer_timeout(void *ptr)
  57722. +{
  57723. + ep_xfer_info_t *xfer_info = NULL;
  57724. + int ep_num = 0;
  57725. + dctl_data_t dctl = {.d32 = 0 };
  57726. + gintsts_data_t gintsts = {.d32 = 0 };
  57727. + gintmsk_data_t gintmsk = {.d32 = 0 };
  57728. +
  57729. + if (ptr)
  57730. + xfer_info = (ep_xfer_info_t *) ptr;
  57731. +
  57732. + if (!xfer_info->ep) {
  57733. + DWC_ERROR("xfer_info->ep = %p\n", xfer_info->ep);
  57734. + return;
  57735. + }
  57736. +
  57737. + ep_num = xfer_info->ep->num;
  57738. + DWC_WARN("%s: timeout on endpoit %d\n", __func__, ep_num);
  57739. + /* Put the sate to 2 as it was time outed */
  57740. + xfer_info->state = 2;
  57741. +
  57742. + dctl.d32 =
  57743. + DWC_READ_REG32(&xfer_info->core_if->dev_if->dev_global_regs->dctl);
  57744. + gintsts.d32 =
  57745. + DWC_READ_REG32(&xfer_info->core_if->core_global_regs->gintsts);
  57746. + gintmsk.d32 =
  57747. + DWC_READ_REG32(&xfer_info->core_if->core_global_regs->gintmsk);
  57748. +
  57749. + if (!gintmsk.b.goutnakeff) {
  57750. + /* Unmask it */
  57751. + gintmsk.b.goutnakeff = 1;
  57752. + DWC_WRITE_REG32(&xfer_info->core_if->core_global_regs->gintmsk,
  57753. + gintmsk.d32);
  57754. +
  57755. + }
  57756. +
  57757. + if (!gintsts.b.goutnakeff) {
  57758. + dctl.b.sgoutnak = 1;
  57759. + }
  57760. + DWC_WRITE_REG32(&xfer_info->core_if->dev_if->dev_global_regs->dctl,
  57761. + dctl.d32);
  57762. +
  57763. +}
  57764. +
  57765. +void set_pid_isoc(dwc_hc_t * hc)
  57766. +{
  57767. + /* Set up the initial PID for the transfer. */
  57768. + if (hc->speed == DWC_OTG_EP_SPEED_HIGH) {
  57769. + if (hc->ep_is_in) {
  57770. + if (hc->multi_count == 1) {
  57771. + hc->data_pid_start = DWC_OTG_HC_PID_DATA0;
  57772. + } else if (hc->multi_count == 2) {
  57773. + hc->data_pid_start = DWC_OTG_HC_PID_DATA1;
  57774. + } else {
  57775. + hc->data_pid_start = DWC_OTG_HC_PID_DATA2;
  57776. + }
  57777. + } else {
  57778. + if (hc->multi_count == 1) {
  57779. + hc->data_pid_start = DWC_OTG_HC_PID_DATA0;
  57780. + } else {
  57781. + hc->data_pid_start = DWC_OTG_HC_PID_MDATA;
  57782. + }
  57783. + }
  57784. + } else {
  57785. + hc->data_pid_start = DWC_OTG_HC_PID_DATA0;
  57786. + }
  57787. +}
  57788. +
  57789. +/**
  57790. + * This function does the setup for a data transfer for a host channel and
  57791. + * starts the transfer. May be called in either Slave mode or DMA mode. In
  57792. + * Slave mode, the caller must ensure that there is sufficient space in the
  57793. + * request queue and Tx Data FIFO.
  57794. + *
  57795. + * For an OUT transfer in Slave mode, it loads a data packet into the
  57796. + * appropriate FIFO. If necessary, additional data packets will be loaded in
  57797. + * the Host ISR.
  57798. + *
  57799. + * For an IN transfer in Slave mode, a data packet is requested. The data
  57800. + * packets are unloaded from the Rx FIFO in the Host ISR. If necessary,
  57801. + * additional data packets are requested in the Host ISR.
  57802. + *
  57803. + * For a PING transfer in Slave mode, the Do Ping bit is set in the HCTSIZ
  57804. + * register along with a packet count of 1 and the channel is enabled. This
  57805. + * causes a single PING transaction to occur. Other fields in HCTSIZ are
  57806. + * simply set to 0 since no data transfer occurs in this case.
  57807. + *
  57808. + * For a PING transfer in DMA mode, the HCTSIZ register is initialized with
  57809. + * all the information required to perform the subsequent data transfer. In
  57810. + * addition, the Do Ping bit is set in the HCTSIZ register. In this case, the
  57811. + * controller performs the entire PING protocol, then starts the data
  57812. + * transfer.
  57813. + *
  57814. + * @param core_if Programming view of DWC_otg controller.
  57815. + * @param hc Information needed to initialize the host channel. The xfer_len
  57816. + * value may be reduced to accommodate the max widths of the XferSize and
  57817. + * PktCnt fields in the HCTSIZn register. The multi_count value may be changed
  57818. + * to reflect the final xfer_len value.
  57819. + */
  57820. +void dwc_otg_hc_start_transfer(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  57821. +{
  57822. + hcchar_data_t hcchar;
  57823. + hctsiz_data_t hctsiz;
  57824. + uint16_t num_packets;
  57825. + uint32_t max_hc_xfer_size = core_if->core_params->max_transfer_size;
  57826. + uint16_t max_hc_pkt_count = core_if->core_params->max_packet_count;
  57827. + dwc_otg_hc_regs_t *hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  57828. +
  57829. + hctsiz.d32 = 0;
  57830. +
  57831. + if (hc->do_ping) {
  57832. + if (!core_if->dma_enable) {
  57833. + dwc_otg_hc_do_ping(core_if, hc);
  57834. + hc->xfer_started = 1;
  57835. + return;
  57836. + } else {
  57837. + hctsiz.b.dopng = 1;
  57838. + }
  57839. + }
  57840. +
  57841. + if (hc->do_split) {
  57842. + num_packets = 1;
  57843. +
  57844. + if (hc->complete_split && !hc->ep_is_in) {
  57845. + /* For CSPLIT OUT Transfer, set the size to 0 so the
  57846. + * core doesn't expect any data written to the FIFO */
  57847. + hc->xfer_len = 0;
  57848. + } else if (hc->ep_is_in || (hc->xfer_len > hc->max_packet)) {
  57849. + hc->xfer_len = hc->max_packet;
  57850. + } else if (!hc->ep_is_in && (hc->xfer_len > 188)) {
  57851. + hc->xfer_len = 188;
  57852. + }
  57853. +
  57854. + hctsiz.b.xfersize = hc->xfer_len;
  57855. + } else {
  57856. + /*
  57857. + * Ensure that the transfer length and packet count will fit
  57858. + * in the widths allocated for them in the HCTSIZn register.
  57859. + */
  57860. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  57861. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  57862. + /*
  57863. + * Make sure the transfer size is no larger than one
  57864. + * (micro)frame's worth of data. (A check was done
  57865. + * when the periodic transfer was accepted to ensure
  57866. + * that a (micro)frame's worth of data can be
  57867. + * programmed into a channel.)
  57868. + */
  57869. + uint32_t max_periodic_len =
  57870. + hc->multi_count * hc->max_packet;
  57871. + if (hc->xfer_len > max_periodic_len) {
  57872. + hc->xfer_len = max_periodic_len;
  57873. + } else {
  57874. + }
  57875. + } else if (hc->xfer_len > max_hc_xfer_size) {
  57876. + /* Make sure that xfer_len is a multiple of max packet size. */
  57877. + hc->xfer_len = max_hc_xfer_size - hc->max_packet + 1;
  57878. + }
  57879. +
  57880. + if (hc->xfer_len > 0) {
  57881. + num_packets =
  57882. + (hc->xfer_len + hc->max_packet -
  57883. + 1) / hc->max_packet;
  57884. + if (num_packets > max_hc_pkt_count) {
  57885. + num_packets = max_hc_pkt_count;
  57886. + hc->xfer_len = num_packets * hc->max_packet;
  57887. + }
  57888. + } else {
  57889. + /* Need 1 packet for transfer length of 0. */
  57890. + num_packets = 1;
  57891. + }
  57892. +
  57893. + if (hc->ep_is_in) {
  57894. + /* Always program an integral # of max packets for IN transfers. */
  57895. + hc->xfer_len = num_packets * hc->max_packet;
  57896. + }
  57897. +
  57898. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  57899. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  57900. + /*
  57901. + * Make sure that the multi_count field matches the
  57902. + * actual transfer length.
  57903. + */
  57904. + hc->multi_count = num_packets;
  57905. + }
  57906. +
  57907. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)
  57908. + set_pid_isoc(hc);
  57909. +
  57910. + hctsiz.b.xfersize = hc->xfer_len;
  57911. + }
  57912. +
  57913. + hc->start_pkt_count = num_packets;
  57914. + hctsiz.b.pktcnt = num_packets;
  57915. + hctsiz.b.pid = hc->data_pid_start;
  57916. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  57917. +
  57918. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  57919. + DWC_DEBUGPL(DBG_HCDV, " Xfer Size: %d\n", hctsiz.b.xfersize);
  57920. + DWC_DEBUGPL(DBG_HCDV, " Num Pkts: %d\n", hctsiz.b.pktcnt);
  57921. + DWC_DEBUGPL(DBG_HCDV, " Start PID: %d\n", hctsiz.b.pid);
  57922. +
  57923. + if (core_if->dma_enable) {
  57924. + dwc_dma_t dma_addr;
  57925. + if (hc->align_buff) {
  57926. + dma_addr = hc->align_buff;
  57927. + } else {
  57928. + dma_addr = ((unsigned long)hc->xfer_buff & 0xffffffff);
  57929. + }
  57930. + DWC_WRITE_REG32(&hc_regs->hcdma, dma_addr);
  57931. + }
  57932. +
  57933. + /* Start the split */
  57934. + if (hc->do_split) {
  57935. + hcsplt_data_t hcsplt;
  57936. + hcsplt.d32 = DWC_READ_REG32(&hc_regs->hcsplt);
  57937. + hcsplt.b.spltena = 1;
  57938. + DWC_WRITE_REG32(&hc_regs->hcsplt, hcsplt.d32);
  57939. + }
  57940. +
  57941. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  57942. + hcchar.b.multicnt = hc->multi_count;
  57943. + hc_set_even_odd_frame(core_if, hc, &hcchar);
  57944. +#ifdef DEBUG
  57945. + core_if->start_hcchar_val[hc->hc_num] = hcchar.d32;
  57946. + if (hcchar.b.chdis) {
  57947. + DWC_WARN("%s: chdis set, channel %d, hcchar 0x%08x\n",
  57948. + __func__, hc->hc_num, hcchar.d32);
  57949. + }
  57950. +#endif
  57951. +
  57952. + /* Set host channel enable after all other setup is complete. */
  57953. + hcchar.b.chen = 1;
  57954. + hcchar.b.chdis = 0;
  57955. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  57956. +
  57957. + hc->xfer_started = 1;
  57958. + hc->requests++;
  57959. +
  57960. + if (!core_if->dma_enable && !hc->ep_is_in && hc->xfer_len > 0) {
  57961. + /* Load OUT packet into the appropriate Tx FIFO. */
  57962. + dwc_otg_hc_write_packet(core_if, hc);
  57963. + }
  57964. +#ifdef DEBUG
  57965. + if (hc->ep_type != DWC_OTG_EP_TYPE_INTR) {
  57966. + DWC_DEBUGPL(DBG_HCDV, "transfer %d from core_if %p\n",
  57967. + hc->hc_num, core_if);//GRAYG
  57968. + core_if->hc_xfer_info[hc->hc_num].core_if = core_if;
  57969. + core_if->hc_xfer_info[hc->hc_num].hc = hc;
  57970. +
  57971. + /* Start a timer for this transfer. */
  57972. + DWC_TIMER_SCHEDULE(core_if->hc_xfer_timer[hc->hc_num], 10000);
  57973. + }
  57974. +#endif
  57975. +}
  57976. +
  57977. +/**
  57978. + * This function does the setup for a data transfer for a host channel
  57979. + * and starts the transfer in Descriptor DMA mode.
  57980. + *
  57981. + * Initializes HCTSIZ register. For a PING transfer the Do Ping bit is set.
  57982. + * Sets PID and NTD values. For periodic transfers
  57983. + * initializes SCHED_INFO field with micro-frame bitmap.
  57984. + *
  57985. + * Initializes HCDMA register with descriptor list address and CTD value
  57986. + * then starts the transfer via enabling the channel.
  57987. + *
  57988. + * @param core_if Programming view of DWC_otg controller.
  57989. + * @param hc Information needed to initialize the host channel.
  57990. + */
  57991. +void dwc_otg_hc_start_transfer_ddma(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  57992. +{
  57993. + dwc_otg_hc_regs_t *hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  57994. + hcchar_data_t hcchar;
  57995. + hctsiz_data_t hctsiz;
  57996. + hcdma_data_t hcdma;
  57997. +
  57998. + hctsiz.d32 = 0;
  57999. +
  58000. + if (hc->do_ping)
  58001. + hctsiz.b_ddma.dopng = 1;
  58002. +
  58003. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)
  58004. + set_pid_isoc(hc);
  58005. +
  58006. + /* Packet Count and Xfer Size are not used in Descriptor DMA mode */
  58007. + hctsiz.b_ddma.pid = hc->data_pid_start;
  58008. + hctsiz.b_ddma.ntd = hc->ntd - 1; /* 0 - 1 descriptor, 1 - 2 descriptors, etc. */
  58009. + hctsiz.b_ddma.schinfo = hc->schinfo; /* Non-zero only for high-speed interrupt endpoints */
  58010. +
  58011. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  58012. + DWC_DEBUGPL(DBG_HCDV, " Start PID: %d\n", hctsiz.b.pid);
  58013. + DWC_DEBUGPL(DBG_HCDV, " NTD: %d\n", hctsiz.b_ddma.ntd);
  58014. +
  58015. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  58016. +
  58017. + hcdma.d32 = 0;
  58018. + hcdma.b.dma_addr = ((uint32_t) hc->desc_list_addr) >> 11;
  58019. +
  58020. + /* Always start from first descriptor. */
  58021. + hcdma.b.ctd = 0;
  58022. + DWC_WRITE_REG32(&hc_regs->hcdma, hcdma.d32);
  58023. +
  58024. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  58025. + hcchar.b.multicnt = hc->multi_count;
  58026. +
  58027. +#ifdef DEBUG
  58028. + core_if->start_hcchar_val[hc->hc_num] = hcchar.d32;
  58029. + if (hcchar.b.chdis) {
  58030. + DWC_WARN("%s: chdis set, channel %d, hcchar 0x%08x\n",
  58031. + __func__, hc->hc_num, hcchar.d32);
  58032. + }
  58033. +#endif
  58034. +
  58035. + /* Set host channel enable after all other setup is complete. */
  58036. + hcchar.b.chen = 1;
  58037. + hcchar.b.chdis = 0;
  58038. +
  58039. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  58040. +
  58041. + hc->xfer_started = 1;
  58042. + hc->requests++;
  58043. +
  58044. +#ifdef DEBUG
  58045. + if ((hc->ep_type != DWC_OTG_EP_TYPE_INTR)
  58046. + && (hc->ep_type != DWC_OTG_EP_TYPE_ISOC)) {
  58047. + DWC_DEBUGPL(DBG_HCDV, "DMA transfer %d from core_if %p\n",
  58048. + hc->hc_num, core_if);//GRAYG
  58049. + core_if->hc_xfer_info[hc->hc_num].core_if = core_if;
  58050. + core_if->hc_xfer_info[hc->hc_num].hc = hc;
  58051. + /* Start a timer for this transfer. */
  58052. + DWC_TIMER_SCHEDULE(core_if->hc_xfer_timer[hc->hc_num], 10000);
  58053. + }
  58054. +#endif
  58055. +
  58056. +}
  58057. +
  58058. +/**
  58059. + * This function continues a data transfer that was started by previous call
  58060. + * to <code>dwc_otg_hc_start_transfer</code>. The caller must ensure there is
  58061. + * sufficient space in the request queue and Tx Data FIFO. This function
  58062. + * should only be called in Slave mode. In DMA mode, the controller acts
  58063. + * autonomously to complete transfers programmed to a host channel.
  58064. + *
  58065. + * For an OUT transfer, a new data packet is loaded into the appropriate FIFO
  58066. + * if there is any data remaining to be queued. For an IN transfer, another
  58067. + * data packet is always requested. For the SETUP phase of a control transfer,
  58068. + * this function does nothing.
  58069. + *
  58070. + * @return 1 if a new request is queued, 0 if no more requests are required
  58071. + * for this transfer.
  58072. + */
  58073. +int dwc_otg_hc_continue_transfer(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  58074. +{
  58075. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  58076. +
  58077. + if (hc->do_split) {
  58078. + /* SPLITs always queue just once per channel */
  58079. + return 0;
  58080. + } else if (hc->data_pid_start == DWC_OTG_HC_PID_SETUP) {
  58081. + /* SETUPs are queued only once since they can't be NAKed. */
  58082. + return 0;
  58083. + } else if (hc->ep_is_in) {
  58084. + /*
  58085. + * Always queue another request for other IN transfers. If
  58086. + * back-to-back INs are issued and NAKs are received for both,
  58087. + * the driver may still be processing the first NAK when the
  58088. + * second NAK is received. When the interrupt handler clears
  58089. + * the NAK interrupt for the first NAK, the second NAK will
  58090. + * not be seen. So we can't depend on the NAK interrupt
  58091. + * handler to requeue a NAKed request. Instead, IN requests
  58092. + * are issued each time this function is called. When the
  58093. + * transfer completes, the extra requests for the channel will
  58094. + * be flushed.
  58095. + */
  58096. + hcchar_data_t hcchar;
  58097. + dwc_otg_hc_regs_t *hc_regs =
  58098. + core_if->host_if->hc_regs[hc->hc_num];
  58099. +
  58100. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  58101. + hc_set_even_odd_frame(core_if, hc, &hcchar);
  58102. + hcchar.b.chen = 1;
  58103. + hcchar.b.chdis = 0;
  58104. + DWC_DEBUGPL(DBG_HCDV, " IN xfer: hcchar = 0x%08x\n",
  58105. + hcchar.d32);
  58106. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  58107. + hc->requests++;
  58108. + return 1;
  58109. + } else {
  58110. + /* OUT transfers. */
  58111. + if (hc->xfer_count < hc->xfer_len) {
  58112. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  58113. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  58114. + hcchar_data_t hcchar;
  58115. + dwc_otg_hc_regs_t *hc_regs;
  58116. + hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  58117. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  58118. + hc_set_even_odd_frame(core_if, hc, &hcchar);
  58119. + }
  58120. +
  58121. + /* Load OUT packet into the appropriate Tx FIFO. */
  58122. + dwc_otg_hc_write_packet(core_if, hc);
  58123. + hc->requests++;
  58124. + return 1;
  58125. + } else {
  58126. + return 0;
  58127. + }
  58128. + }
  58129. +}
  58130. +
  58131. +/**
  58132. + * Starts a PING transfer. This function should only be called in Slave mode.
  58133. + * The Do Ping bit is set in the HCTSIZ register, then the channel is enabled.
  58134. + */
  58135. +void dwc_otg_hc_do_ping(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  58136. +{
  58137. + hcchar_data_t hcchar;
  58138. + hctsiz_data_t hctsiz;
  58139. + dwc_otg_hc_regs_t *hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  58140. +
  58141. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  58142. +
  58143. + hctsiz.d32 = 0;
  58144. + hctsiz.b.dopng = 1;
  58145. + hctsiz.b.pktcnt = 1;
  58146. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  58147. +
  58148. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  58149. + hcchar.b.chen = 1;
  58150. + hcchar.b.chdis = 0;
  58151. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  58152. +}
  58153. +
  58154. +/*
  58155. + * This function writes a packet into the Tx FIFO associated with the Host
  58156. + * Channel. For a channel associated with a non-periodic EP, the non-periodic
  58157. + * Tx FIFO is written. For a channel associated with a periodic EP, the
  58158. + * periodic Tx FIFO is written. This function should only be called in Slave
  58159. + * mode.
  58160. + *
  58161. + * Upon return the xfer_buff and xfer_count fields in _hc are incremented by
  58162. + * then number of bytes written to the Tx FIFO.
  58163. + */
  58164. +void dwc_otg_hc_write_packet(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  58165. +{
  58166. + uint32_t i;
  58167. + uint32_t remaining_count;
  58168. + uint32_t byte_count;
  58169. + uint32_t dword_count;
  58170. +
  58171. + uint32_t *data_buff = (uint32_t *) (hc->xfer_buff);
  58172. + uint32_t *data_fifo = core_if->data_fifo[hc->hc_num];
  58173. +
  58174. + remaining_count = hc->xfer_len - hc->xfer_count;
  58175. + if (remaining_count > hc->max_packet) {
  58176. + byte_count = hc->max_packet;
  58177. + } else {
  58178. + byte_count = remaining_count;
  58179. + }
  58180. +
  58181. + dword_count = (byte_count + 3) / 4;
  58182. +
  58183. + if ((((unsigned long)data_buff) & 0x3) == 0) {
  58184. + /* xfer_buff is DWORD aligned. */
  58185. + for (i = 0; i < dword_count; i++, data_buff++) {
  58186. + DWC_WRITE_REG32(data_fifo, *data_buff);
  58187. + }
  58188. + } else {
  58189. + /* xfer_buff is not DWORD aligned. */
  58190. + for (i = 0; i < dword_count; i++, data_buff++) {
  58191. + uint32_t data;
  58192. + data =
  58193. + (data_buff[0] | data_buff[1] << 8 | data_buff[2] <<
  58194. + 16 | data_buff[3] << 24);
  58195. + DWC_WRITE_REG32(data_fifo, data);
  58196. + }
  58197. + }
  58198. +
  58199. + hc->xfer_count += byte_count;
  58200. + hc->xfer_buff += byte_count;
  58201. +}
  58202. +
  58203. +/**
  58204. + * Gets the current USB frame number. This is the frame number from the last
  58205. + * SOF packet.
  58206. + */
  58207. +uint32_t dwc_otg_get_frame_number(dwc_otg_core_if_t * core_if)
  58208. +{
  58209. + dsts_data_t dsts;
  58210. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  58211. +
  58212. + /* read current frame/microframe number from DSTS register */
  58213. + return dsts.b.soffn;
  58214. +}
  58215. +
  58216. +/**
  58217. + * Calculates and gets the frame Interval value of HFIR register according PHY
  58218. + * type and speed.The application can modify a value of HFIR register only after
  58219. + * the Port Enable bit of the Host Port Control and Status register
  58220. + * (HPRT.PrtEnaPort) has been set.
  58221. +*/
  58222. +
  58223. +uint32_t calc_frame_interval(dwc_otg_core_if_t * core_if)
  58224. +{
  58225. + gusbcfg_data_t usbcfg;
  58226. + hwcfg2_data_t hwcfg2;
  58227. + hprt0_data_t hprt0;
  58228. + int clock = 60; // default value
  58229. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  58230. + hwcfg2.d32 = DWC_READ_REG32(&core_if->core_global_regs->ghwcfg2);
  58231. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  58232. + if (!usbcfg.b.physel && usbcfg.b.ulpi_utmi_sel && !usbcfg.b.phyif)
  58233. + clock = 60;
  58234. + if (usbcfg.b.physel && hwcfg2.b.fs_phy_type == 3)
  58235. + clock = 48;
  58236. + if (!usbcfg.b.phylpwrclksel && !usbcfg.b.physel &&
  58237. + !usbcfg.b.ulpi_utmi_sel && usbcfg.b.phyif)
  58238. + clock = 30;
  58239. + if (!usbcfg.b.phylpwrclksel && !usbcfg.b.physel &&
  58240. + !usbcfg.b.ulpi_utmi_sel && !usbcfg.b.phyif)
  58241. + clock = 60;
  58242. + if (usbcfg.b.phylpwrclksel && !usbcfg.b.physel &&
  58243. + !usbcfg.b.ulpi_utmi_sel && usbcfg.b.phyif)
  58244. + clock = 48;
  58245. + if (usbcfg.b.physel && !usbcfg.b.phyif && hwcfg2.b.fs_phy_type == 2)
  58246. + clock = 48;
  58247. + if (usbcfg.b.physel && hwcfg2.b.fs_phy_type == 1)
  58248. + clock = 48;
  58249. + if (hprt0.b.prtspd == 0)
  58250. + /* High speed case */
  58251. + return 125 * clock;
  58252. + else
  58253. + /* FS/LS case */
  58254. + return 1000 * clock;
  58255. +}
  58256. +
  58257. +/**
  58258. + * This function reads a setup packet from the Rx FIFO into the destination
  58259. + * buffer. This function is called from the Rx Status Queue Level (RxStsQLvl)
  58260. + * Interrupt routine when a SETUP packet has been received in Slave mode.
  58261. + *
  58262. + * @param core_if Programming view of DWC_otg controller.
  58263. + * @param dest Destination buffer for packet data.
  58264. + */
  58265. +void dwc_otg_read_setup_packet(dwc_otg_core_if_t * core_if, uint32_t * dest)
  58266. +{
  58267. + device_grxsts_data_t status;
  58268. + /* Get the 8 bytes of a setup transaction data */
  58269. +
  58270. + /* Pop 2 DWORDS off the receive data FIFO into memory */
  58271. + dest[0] = DWC_READ_REG32(core_if->data_fifo[0]);
  58272. + dest[1] = DWC_READ_REG32(core_if->data_fifo[0]);
  58273. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  58274. + status.d32 =
  58275. + DWC_READ_REG32(&core_if->core_global_regs->grxstsp);
  58276. + DWC_DEBUGPL(DBG_ANY,
  58277. + "EP:%d BCnt:%d " "pktsts:%x Frame:%d(0x%0x)\n",
  58278. + status.b.epnum, status.b.bcnt, status.b.pktsts,
  58279. + status.b.fn, status.b.fn);
  58280. + }
  58281. +}
  58282. +
  58283. +/**
  58284. + * This function enables EP0 OUT to receive SETUP packets and configures EP0
  58285. + * IN for transmitting packets. It is normally called when the
  58286. + * "Enumeration Done" interrupt occurs.
  58287. + *
  58288. + * @param core_if Programming view of DWC_otg controller.
  58289. + * @param ep The EP0 data.
  58290. + */
  58291. +void dwc_otg_ep0_activate(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  58292. +{
  58293. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  58294. + dsts_data_t dsts;
  58295. + depctl_data_t diepctl;
  58296. + depctl_data_t doepctl;
  58297. + dctl_data_t dctl = {.d32 = 0 };
  58298. +
  58299. + ep->stp_rollover = 0;
  58300. + /* Read the Device Status and Endpoint 0 Control registers */
  58301. + dsts.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dsts);
  58302. + diepctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl);
  58303. + doepctl.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl);
  58304. +
  58305. + /* Set the MPS of the IN EP based on the enumeration speed */
  58306. + switch (dsts.b.enumspd) {
  58307. + case DWC_DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ:
  58308. + case DWC_DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ:
  58309. + case DWC_DSTS_ENUMSPD_FS_PHY_48MHZ:
  58310. + diepctl.b.mps = DWC_DEP0CTL_MPS_64;
  58311. + break;
  58312. + case DWC_DSTS_ENUMSPD_LS_PHY_6MHZ:
  58313. + diepctl.b.mps = DWC_DEP0CTL_MPS_8;
  58314. + break;
  58315. + }
  58316. +
  58317. + DWC_WRITE_REG32(&dev_if->in_ep_regs[0]->diepctl, diepctl.d32);
  58318. +
  58319. + /* Enable OUT EP for receive */
  58320. + if (core_if->snpsid <= OTG_CORE_REV_2_94a) {
  58321. + doepctl.b.epena = 1;
  58322. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doepctl, doepctl.d32);
  58323. + }
  58324. +#ifdef VERBOSE
  58325. + DWC_DEBUGPL(DBG_PCDV, "doepctl0=%0x\n",
  58326. + DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl));
  58327. + DWC_DEBUGPL(DBG_PCDV, "diepctl0=%0x\n",
  58328. + DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl));
  58329. +#endif
  58330. + dctl.b.cgnpinnak = 1;
  58331. +
  58332. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  58333. + DWC_DEBUGPL(DBG_PCDV, "dctl=%0x\n",
  58334. + DWC_READ_REG32(&dev_if->dev_global_regs->dctl));
  58335. +
  58336. +}
  58337. +
  58338. +/**
  58339. + * This function activates an EP. The Device EP control register for
  58340. + * the EP is configured as defined in the ep structure. Note: This
  58341. + * function is not used for EP0.
  58342. + *
  58343. + * @param core_if Programming view of DWC_otg controller.
  58344. + * @param ep The EP to activate.
  58345. + */
  58346. +void dwc_otg_ep_activate(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  58347. +{
  58348. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  58349. + depctl_data_t depctl;
  58350. + volatile uint32_t *addr;
  58351. + daint_data_t daintmsk = {.d32 = 0 };
  58352. + dcfg_data_t dcfg;
  58353. + uint8_t i;
  58354. +
  58355. + DWC_DEBUGPL(DBG_PCDV, "%s() EP%d-%s\n", __func__, ep->num,
  58356. + (ep->is_in ? "IN" : "OUT"));
  58357. +
  58358. +#ifdef DWC_UTE_PER_IO
  58359. + ep->xiso_frame_num = 0xFFFFFFFF;
  58360. + ep->xiso_active_xfers = 0;
  58361. + ep->xiso_queued_xfers = 0;
  58362. +#endif
  58363. + /* Read DEPCTLn register */
  58364. + if (ep->is_in == 1) {
  58365. + addr = &dev_if->in_ep_regs[ep->num]->diepctl;
  58366. + daintmsk.ep.in = 1 << ep->num;
  58367. + } else {
  58368. + addr = &dev_if->out_ep_regs[ep->num]->doepctl;
  58369. + daintmsk.ep.out = 1 << ep->num;
  58370. + }
  58371. +
  58372. + /* If the EP is already active don't change the EP Control
  58373. + * register. */
  58374. + depctl.d32 = DWC_READ_REG32(addr);
  58375. + if (!depctl.b.usbactep) {
  58376. + depctl.b.mps = ep->maxpacket;
  58377. + depctl.b.eptype = ep->type;
  58378. + depctl.b.txfnum = ep->tx_fifo_num;
  58379. +
  58380. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  58381. + depctl.b.setd0pid = 1; // ???
  58382. + } else {
  58383. + depctl.b.setd0pid = 1;
  58384. + }
  58385. + depctl.b.usbactep = 1;
  58386. +
  58387. + /* Update nextep_seq array and EPMSCNT in DCFG*/
  58388. + if (!(depctl.b.eptype & 1) && (ep->is_in == 1)) { // NP IN EP
  58389. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  58390. + if (core_if->nextep_seq[i] == core_if->first_in_nextep_seq)
  58391. + break;
  58392. + }
  58393. + core_if->nextep_seq[i] = ep->num;
  58394. + core_if->nextep_seq[ep->num] = core_if->first_in_nextep_seq;
  58395. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  58396. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  58397. + dcfg.b.epmscnt++;
  58398. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  58399. +
  58400. + DWC_DEBUGPL(DBG_PCDV,
  58401. + "%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  58402. + __func__, core_if->first_in_nextep_seq);
  58403. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  58404. + DWC_DEBUGPL(DBG_PCDV, "%2d\n",
  58405. + core_if->nextep_seq[i]);
  58406. + }
  58407. +
  58408. + }
  58409. +
  58410. +
  58411. + DWC_WRITE_REG32(addr, depctl.d32);
  58412. + DWC_DEBUGPL(DBG_PCDV, "DEPCTL=%08x\n", DWC_READ_REG32(addr));
  58413. + }
  58414. +
  58415. + /* Enable the Interrupt for this EP */
  58416. + if (core_if->multiproc_int_enable) {
  58417. + if (ep->is_in == 1) {
  58418. + diepmsk_data_t diepmsk = {.d32 = 0 };
  58419. + diepmsk.b.xfercompl = 1;
  58420. + diepmsk.b.timeout = 1;
  58421. + diepmsk.b.epdisabled = 1;
  58422. + diepmsk.b.ahberr = 1;
  58423. + diepmsk.b.intknepmis = 1;
  58424. + if (!core_if->en_multiple_tx_fifo && core_if->dma_enable)
  58425. + diepmsk.b.intknepmis = 0;
  58426. + diepmsk.b.txfifoundrn = 1; //?????
  58427. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  58428. + diepmsk.b.nak = 1;
  58429. + }
  58430. +
  58431. +
  58432. +
  58433. +/*
  58434. + if (core_if->dma_desc_enable) {
  58435. + diepmsk.b.bna = 1;
  58436. + }
  58437. +*/
  58438. +/*
  58439. + if (core_if->dma_enable) {
  58440. + doepmsk.b.nak = 1;
  58441. + }
  58442. +*/
  58443. + DWC_WRITE_REG32(&dev_if->dev_global_regs->
  58444. + diepeachintmsk[ep->num], diepmsk.d32);
  58445. +
  58446. + } else {
  58447. + doepmsk_data_t doepmsk = {.d32 = 0 };
  58448. + doepmsk.b.xfercompl = 1;
  58449. + doepmsk.b.ahberr = 1;
  58450. + doepmsk.b.epdisabled = 1;
  58451. + if (ep->type == DWC_OTG_EP_TYPE_ISOC)
  58452. + doepmsk.b.outtknepdis = 1;
  58453. +
  58454. +/*
  58455. +
  58456. + if (core_if->dma_desc_enable) {
  58457. + doepmsk.b.bna = 1;
  58458. + }
  58459. +*/
  58460. +/*
  58461. + doepmsk.b.babble = 1;
  58462. + doepmsk.b.nyet = 1;
  58463. + doepmsk.b.nak = 1;
  58464. +*/
  58465. + DWC_WRITE_REG32(&dev_if->dev_global_regs->
  58466. + doepeachintmsk[ep->num], doepmsk.d32);
  58467. + }
  58468. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->deachintmsk,
  58469. + 0, daintmsk.d32);
  58470. + } else {
  58471. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  58472. + if (ep->is_in) {
  58473. + diepmsk_data_t diepmsk = {.d32 = 0 };
  58474. + diepmsk.b.nak = 1;
  58475. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->diepmsk, 0, diepmsk.d32);
  58476. + } else {
  58477. + doepmsk_data_t doepmsk = {.d32 = 0 };
  58478. + doepmsk.b.outtknepdis = 1;
  58479. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->doepmsk, 0, doepmsk.d32);
  58480. + }
  58481. + }
  58482. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->daintmsk,
  58483. + 0, daintmsk.d32);
  58484. + }
  58485. +
  58486. + DWC_DEBUGPL(DBG_PCDV, "DAINTMSK=%0x\n",
  58487. + DWC_READ_REG32(&dev_if->dev_global_regs->daintmsk));
  58488. +
  58489. + ep->stall_clear_flag = 0;
  58490. +
  58491. + return;
  58492. +}
  58493. +
  58494. +/**
  58495. + * This function deactivates an EP. This is done by clearing the USB Active
  58496. + * EP bit in the Device EP control register. Note: This function is not used
  58497. + * for EP0. EP0 cannot be deactivated.
  58498. + *
  58499. + * @param core_if Programming view of DWC_otg controller.
  58500. + * @param ep The EP to deactivate.
  58501. + */
  58502. +void dwc_otg_ep_deactivate(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  58503. +{
  58504. + depctl_data_t depctl = {.d32 = 0 };
  58505. + volatile uint32_t *addr;
  58506. + daint_data_t daintmsk = {.d32 = 0 };
  58507. + dcfg_data_t dcfg;
  58508. + uint8_t i = 0;
  58509. +
  58510. +#ifdef DWC_UTE_PER_IO
  58511. + ep->xiso_frame_num = 0xFFFFFFFF;
  58512. + ep->xiso_active_xfers = 0;
  58513. + ep->xiso_queued_xfers = 0;
  58514. +#endif
  58515. +
  58516. + /* Read DEPCTLn register */
  58517. + if (ep->is_in == 1) {
  58518. + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
  58519. + daintmsk.ep.in = 1 << ep->num;
  58520. + } else {
  58521. + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
  58522. + daintmsk.ep.out = 1 << ep->num;
  58523. + }
  58524. +
  58525. + depctl.d32 = DWC_READ_REG32(addr);
  58526. +
  58527. + depctl.b.usbactep = 0;
  58528. +
  58529. + /* Update nextep_seq array and EPMSCNT in DCFG*/
  58530. + if (!(depctl.b.eptype & 1) && ep->is_in == 1) { // NP EP IN
  58531. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  58532. + if (core_if->nextep_seq[i] == ep->num)
  58533. + break;
  58534. + }
  58535. + core_if->nextep_seq[i] = core_if->nextep_seq[ep->num];
  58536. + if (core_if->first_in_nextep_seq == ep->num)
  58537. + core_if->first_in_nextep_seq = i;
  58538. + core_if->nextep_seq[ep->num] = 0xff;
  58539. + depctl.b.nextep = 0;
  58540. + dcfg.d32 =
  58541. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  58542. + dcfg.b.epmscnt--;
  58543. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg,
  58544. + dcfg.d32);
  58545. +
  58546. + DWC_DEBUGPL(DBG_PCDV,
  58547. + "%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  58548. + __func__, core_if->first_in_nextep_seq);
  58549. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  58550. + DWC_DEBUGPL(DBG_PCDV, "%2d\n", core_if->nextep_seq[i]);
  58551. + }
  58552. + }
  58553. +
  58554. + if (ep->is_in == 1)
  58555. + depctl.b.txfnum = 0;
  58556. +
  58557. + if (core_if->dma_desc_enable)
  58558. + depctl.b.epdis = 1;
  58559. +
  58560. + DWC_WRITE_REG32(addr, depctl.d32);
  58561. + depctl.d32 = DWC_READ_REG32(addr);
  58562. + if (core_if->dma_enable && ep->type == DWC_OTG_EP_TYPE_ISOC
  58563. + && depctl.b.epena) {
  58564. + depctl_data_t depctl = {.d32 = 0};
  58565. + if (ep->is_in) {
  58566. + diepint_data_t diepint = {.d32 = 0};
  58567. +
  58568. + depctl.b.snak = 1;
  58569. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  58570. + diepctl, depctl.d32);
  58571. + do {
  58572. + dwc_udelay(10);
  58573. + diepint.d32 =
  58574. + DWC_READ_REG32(&core_if->
  58575. + dev_if->in_ep_regs[ep->num]->
  58576. + diepint);
  58577. + } while (!diepint.b.inepnakeff);
  58578. + diepint.b.inepnakeff = 1;
  58579. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  58580. + diepint, diepint.d32);
  58581. + depctl.d32 = 0;
  58582. + depctl.b.epdis = 1;
  58583. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  58584. + diepctl, depctl.d32);
  58585. + do {
  58586. + dwc_udelay(10);
  58587. + diepint.d32 =
  58588. + DWC_READ_REG32(&core_if->
  58589. + dev_if->in_ep_regs[ep->num]->
  58590. + diepint);
  58591. + } while (!diepint.b.epdisabled);
  58592. + diepint.b.epdisabled = 1;
  58593. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  58594. + diepint, diepint.d32);
  58595. + } else {
  58596. + dctl_data_t dctl = {.d32 = 0};
  58597. + gintmsk_data_t gintsts = {.d32 = 0};
  58598. + doepint_data_t doepint = {.d32 = 0};
  58599. + dctl.b.sgoutnak = 1;
  58600. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  58601. + dctl, 0, dctl.d32);
  58602. + do {
  58603. + dwc_udelay(10);
  58604. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  58605. + } while (!gintsts.b.goutnakeff);
  58606. + gintsts.d32 = 0;
  58607. + gintsts.b.goutnakeff = 1;
  58608. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  58609. +
  58610. + depctl.d32 = 0;
  58611. + depctl.b.epdis = 1;
  58612. + depctl.b.snak = 1;
  58613. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[ep->num]->doepctl, depctl.d32);
  58614. + do
  58615. + {
  58616. + dwc_udelay(10);
  58617. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  58618. + out_ep_regs[ep->num]->doepint);
  58619. + } while (!doepint.b.epdisabled);
  58620. +
  58621. + doepint.b.epdisabled = 1;
  58622. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[ep->num]->doepint, doepint.d32);
  58623. +
  58624. + dctl.d32 = 0;
  58625. + dctl.b.cgoutnak = 1;
  58626. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  58627. + }
  58628. + }
  58629. +
  58630. + /* Disable the Interrupt for this EP */
  58631. + if (core_if->multiproc_int_enable) {
  58632. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->deachintmsk,
  58633. + daintmsk.d32, 0);
  58634. +
  58635. + if (ep->is_in == 1) {
  58636. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->
  58637. + diepeachintmsk[ep->num], 0);
  58638. + } else {
  58639. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->
  58640. + doepeachintmsk[ep->num], 0);
  58641. + }
  58642. + } else {
  58643. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->daintmsk,
  58644. + daintmsk.d32, 0);
  58645. + }
  58646. +
  58647. +}
  58648. +
  58649. +/**
  58650. + * This function initializes dma descriptor chain.
  58651. + *
  58652. + * @param core_if Programming view of DWC_otg controller.
  58653. + * @param ep The EP to start the transfer on.
  58654. + */
  58655. +static void init_dma_desc_chain(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  58656. +{
  58657. + dwc_otg_dev_dma_desc_t *dma_desc;
  58658. + uint32_t offset;
  58659. + uint32_t xfer_est;
  58660. + int i;
  58661. + unsigned maxxfer_local, total_len;
  58662. +
  58663. + if (!ep->is_in && ep->type == DWC_OTG_EP_TYPE_INTR &&
  58664. + (ep->maxpacket%4)) {
  58665. + maxxfer_local = ep->maxpacket;
  58666. + total_len = ep->xfer_len;
  58667. + } else {
  58668. + maxxfer_local = ep->maxxfer;
  58669. + total_len = ep->total_len;
  58670. + }
  58671. +
  58672. + ep->desc_cnt = (total_len / maxxfer_local) +
  58673. + ((total_len % maxxfer_local) ? 1 : 0);
  58674. +
  58675. + if (!ep->desc_cnt)
  58676. + ep->desc_cnt = 1;
  58677. +
  58678. + if (ep->desc_cnt > MAX_DMA_DESC_CNT)
  58679. + ep->desc_cnt = MAX_DMA_DESC_CNT;
  58680. +
  58681. + dma_desc = ep->desc_addr;
  58682. + if (maxxfer_local == ep->maxpacket) {
  58683. + if ((total_len % maxxfer_local) &&
  58684. + (total_len/maxxfer_local < MAX_DMA_DESC_CNT)) {
  58685. + xfer_est = (ep->desc_cnt - 1) * maxxfer_local +
  58686. + (total_len % maxxfer_local);
  58687. + } else
  58688. + xfer_est = ep->desc_cnt * maxxfer_local;
  58689. + } else
  58690. + xfer_est = total_len;
  58691. + offset = 0;
  58692. + for (i = 0; i < ep->desc_cnt; ++i) {
  58693. + /** DMA Descriptor Setup */
  58694. + if (xfer_est > maxxfer_local) {
  58695. + dma_desc->status.b.bs = BS_HOST_BUSY;
  58696. + dma_desc->status.b.l = 0;
  58697. + dma_desc->status.b.ioc = 0;
  58698. + dma_desc->status.b.sp = 0;
  58699. + dma_desc->status.b.bytes = maxxfer_local;
  58700. + dma_desc->buf = ep->dma_addr + offset;
  58701. + dma_desc->status.b.sts = 0;
  58702. + dma_desc->status.b.bs = BS_HOST_READY;
  58703. +
  58704. + xfer_est -= maxxfer_local;
  58705. + offset += maxxfer_local;
  58706. + } else {
  58707. + dma_desc->status.b.bs = BS_HOST_BUSY;
  58708. + dma_desc->status.b.l = 1;
  58709. + dma_desc->status.b.ioc = 1;
  58710. + if (ep->is_in) {
  58711. + dma_desc->status.b.sp =
  58712. + (xfer_est %
  58713. + ep->maxpacket) ? 1 : ((ep->
  58714. + sent_zlp) ? 1 : 0);
  58715. + dma_desc->status.b.bytes = xfer_est;
  58716. + } else {
  58717. + if (maxxfer_local == ep->maxpacket)
  58718. + dma_desc->status.b.bytes = xfer_est;
  58719. + else
  58720. + dma_desc->status.b.bytes =
  58721. + xfer_est + ((4 - (xfer_est & 0x3)) & 0x3);
  58722. + }
  58723. +
  58724. + dma_desc->buf = ep->dma_addr + offset;
  58725. + dma_desc->status.b.sts = 0;
  58726. + dma_desc->status.b.bs = BS_HOST_READY;
  58727. + }
  58728. + dma_desc++;
  58729. + }
  58730. +}
  58731. +/**
  58732. + * This function is called when to write ISOC data into appropriate dedicated
  58733. + * periodic FIFO.
  58734. + */
  58735. +static int32_t write_isoc_tx_fifo(dwc_otg_core_if_t * core_if, dwc_ep_t * dwc_ep)
  58736. +{
  58737. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  58738. + dwc_otg_dev_in_ep_regs_t *ep_regs;
  58739. + dtxfsts_data_t txstatus = {.d32 = 0 };
  58740. + uint32_t len = 0;
  58741. + int epnum = dwc_ep->num;
  58742. + int dwords;
  58743. +
  58744. + DWC_DEBUGPL(DBG_PCD, "Dedicated TxFifo Empty: %d \n", epnum);
  58745. +
  58746. + ep_regs = core_if->dev_if->in_ep_regs[epnum];
  58747. +
  58748. + len = dwc_ep->xfer_len - dwc_ep->xfer_count;
  58749. +
  58750. + if (len > dwc_ep->maxpacket) {
  58751. + len = dwc_ep->maxpacket;
  58752. + }
  58753. +
  58754. + dwords = (len + 3) / 4;
  58755. +
  58756. + /* While there is space in the queue and space in the FIFO and
  58757. + * More data to tranfer, Write packets to the Tx FIFO */
  58758. + txstatus.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts);
  58759. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", epnum, txstatus.d32);
  58760. +
  58761. + while (txstatus.b.txfspcavail > dwords &&
  58762. + dwc_ep->xfer_count < dwc_ep->xfer_len && dwc_ep->xfer_len != 0) {
  58763. + /* Write the FIFO */
  58764. + dwc_otg_ep_write_packet(core_if, dwc_ep, 0);
  58765. +
  58766. + len = dwc_ep->xfer_len - dwc_ep->xfer_count;
  58767. + if (len > dwc_ep->maxpacket) {
  58768. + len = dwc_ep->maxpacket;
  58769. + }
  58770. +
  58771. + dwords = (len + 3) / 4;
  58772. + txstatus.d32 =
  58773. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts);
  58774. + DWC_DEBUGPL(DBG_PCDV, "dtxfsts[%d]=0x%08x\n", epnum,
  58775. + txstatus.d32);
  58776. + }
  58777. +
  58778. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", epnum,
  58779. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts));
  58780. +
  58781. + return 1;
  58782. +}
  58783. +/**
  58784. + * This function does the setup for a data transfer for an EP and
  58785. + * starts the transfer. For an IN transfer, the packets will be
  58786. + * loaded into the appropriate Tx FIFO in the ISR. For OUT transfers,
  58787. + * the packets are unloaded from the Rx FIFO in the ISR. the ISR.
  58788. + *
  58789. + * @param core_if Programming view of DWC_otg controller.
  58790. + * @param ep The EP to start the transfer on.
  58791. + */
  58792. +
  58793. +void dwc_otg_ep_start_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  58794. +{
  58795. + depctl_data_t depctl;
  58796. + deptsiz_data_t deptsiz;
  58797. + gintmsk_data_t intr_mask = {.d32 = 0 };
  58798. +
  58799. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s()\n", __func__);
  58800. + DWC_DEBUGPL(DBG_PCD, "ep%d-%s xfer_len=%d xfer_cnt=%d "
  58801. + "xfer_buff=%p start_xfer_buff=%p, total_len = %d\n",
  58802. + ep->num, (ep->is_in ? "IN" : "OUT"), ep->xfer_len,
  58803. + ep->xfer_count, ep->xfer_buff, ep->start_xfer_buff,
  58804. + ep->total_len);
  58805. + /* IN endpoint */
  58806. + if (ep->is_in == 1) {
  58807. + dwc_otg_dev_in_ep_regs_t *in_regs =
  58808. + core_if->dev_if->in_ep_regs[ep->num];
  58809. +
  58810. + gnptxsts_data_t gtxstatus;
  58811. +
  58812. + gtxstatus.d32 =
  58813. + DWC_READ_REG32(&core_if->core_global_regs->gnptxsts);
  58814. +
  58815. + if (core_if->en_multiple_tx_fifo == 0
  58816. + && gtxstatus.b.nptxqspcavail == 0 && !core_if->dma_enable) {
  58817. +#ifdef DEBUG
  58818. + DWC_PRINTF("TX Queue Full (0x%0x)\n", gtxstatus.d32);
  58819. +#endif
  58820. + return;
  58821. + }
  58822. +
  58823. + depctl.d32 = DWC_READ_REG32(&(in_regs->diepctl));
  58824. + deptsiz.d32 = DWC_READ_REG32(&(in_regs->dieptsiz));
  58825. +
  58826. + if (ep->maxpacket > ep->maxxfer / MAX_PKT_CNT)
  58827. + ep->xfer_len += (ep->maxxfer < (ep->total_len - ep->xfer_len)) ?
  58828. + ep->maxxfer : (ep->total_len - ep->xfer_len);
  58829. + else
  58830. + ep->xfer_len += (MAX_PKT_CNT * ep->maxpacket < (ep->total_len - ep->xfer_len)) ?
  58831. + MAX_PKT_CNT * ep->maxpacket : (ep->total_len - ep->xfer_len);
  58832. +
  58833. +
  58834. + /* Zero Length Packet? */
  58835. + if ((ep->xfer_len - ep->xfer_count) == 0) {
  58836. + deptsiz.b.xfersize = 0;
  58837. + deptsiz.b.pktcnt = 1;
  58838. + } else {
  58839. + /* Program the transfer size and packet count
  58840. + * as follows: xfersize = N * maxpacket +
  58841. + * short_packet pktcnt = N + (short_packet
  58842. + * exist ? 1 : 0)
  58843. + */
  58844. + deptsiz.b.xfersize = ep->xfer_len - ep->xfer_count;
  58845. + deptsiz.b.pktcnt =
  58846. + (ep->xfer_len - ep->xfer_count - 1 +
  58847. + ep->maxpacket) / ep->maxpacket;
  58848. + if (deptsiz.b.pktcnt > MAX_PKT_CNT) {
  58849. + deptsiz.b.pktcnt = MAX_PKT_CNT;
  58850. + deptsiz.b.xfersize = deptsiz.b.pktcnt * ep->maxpacket;
  58851. + }
  58852. + if (ep->type == DWC_OTG_EP_TYPE_ISOC)
  58853. + deptsiz.b.mc = deptsiz.b.pktcnt;
  58854. + }
  58855. +
  58856. + /* Write the DMA register */
  58857. + if (core_if->dma_enable) {
  58858. + if (core_if->dma_desc_enable == 0) {
  58859. + if (ep->type != DWC_OTG_EP_TYPE_ISOC)
  58860. + deptsiz.b.mc = 1;
  58861. + DWC_WRITE_REG32(&in_regs->dieptsiz,
  58862. + deptsiz.d32);
  58863. + DWC_WRITE_REG32(&(in_regs->diepdma),
  58864. + (uint32_t) ep->dma_addr);
  58865. + } else {
  58866. +#ifdef DWC_UTE_CFI
  58867. + /* The descriptor chain should be already initialized by now */
  58868. + if (ep->buff_mode != BM_STANDARD) {
  58869. + DWC_WRITE_REG32(&in_regs->diepdma,
  58870. + ep->descs_dma_addr);
  58871. + } else {
  58872. +#endif
  58873. + init_dma_desc_chain(core_if, ep);
  58874. + /** DIEPDMAn Register write */
  58875. + DWC_WRITE_REG32(&in_regs->diepdma,
  58876. + ep->dma_desc_addr);
  58877. +#ifdef DWC_UTE_CFI
  58878. + }
  58879. +#endif
  58880. + }
  58881. + } else {
  58882. + DWC_WRITE_REG32(&in_regs->dieptsiz, deptsiz.d32);
  58883. + if (ep->type != DWC_OTG_EP_TYPE_ISOC) {
  58884. + /**
  58885. + * Enable the Non-Periodic Tx FIFO empty interrupt,
  58886. + * or the Tx FIFO epmty interrupt in dedicated Tx FIFO mode,
  58887. + * the data will be written into the fifo by the ISR.
  58888. + */
  58889. + if (core_if->en_multiple_tx_fifo == 0) {
  58890. + intr_mask.b.nptxfempty = 1;
  58891. + DWC_MODIFY_REG32
  58892. + (&core_if->core_global_regs->gintmsk,
  58893. + intr_mask.d32, intr_mask.d32);
  58894. + } else {
  58895. + /* Enable the Tx FIFO Empty Interrupt for this EP */
  58896. + if (ep->xfer_len > 0) {
  58897. + uint32_t fifoemptymsk = 0;
  58898. + fifoemptymsk = 1 << ep->num;
  58899. + DWC_MODIFY_REG32
  58900. + (&core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  58901. + 0, fifoemptymsk);
  58902. +
  58903. + }
  58904. + }
  58905. + } else {
  58906. + write_isoc_tx_fifo(core_if, ep);
  58907. + }
  58908. + }
  58909. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable)
  58910. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  58911. +
  58912. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  58913. + dsts_data_t dsts = {.d32 = 0};
  58914. + if (ep->bInterval == 1) {
  58915. + dsts.d32 =
  58916. + DWC_READ_REG32(&core_if->dev_if->
  58917. + dev_global_regs->dsts);
  58918. + ep->frame_num = dsts.b.soffn + ep->bInterval;
  58919. + if (ep->frame_num > 0x3FFF) {
  58920. + ep->frm_overrun = 1;
  58921. + ep->frame_num &= 0x3FFF;
  58922. + } else
  58923. + ep->frm_overrun = 0;
  58924. + if (ep->frame_num & 0x1) {
  58925. + depctl.b.setd1pid = 1;
  58926. + } else {
  58927. + depctl.b.setd0pid = 1;
  58928. + }
  58929. + }
  58930. + }
  58931. + /* EP enable, IN data in FIFO */
  58932. + depctl.b.cnak = 1;
  58933. + depctl.b.epena = 1;
  58934. + DWC_WRITE_REG32(&in_regs->diepctl, depctl.d32);
  58935. +
  58936. + } else {
  58937. + /* OUT endpoint */
  58938. + dwc_otg_dev_out_ep_regs_t *out_regs =
  58939. + core_if->dev_if->out_ep_regs[ep->num];
  58940. +
  58941. + depctl.d32 = DWC_READ_REG32(&(out_regs->doepctl));
  58942. + deptsiz.d32 = DWC_READ_REG32(&(out_regs->doeptsiz));
  58943. +
  58944. + if (!core_if->dma_desc_enable) {
  58945. + if (ep->maxpacket > ep->maxxfer / MAX_PKT_CNT)
  58946. + ep->xfer_len += (ep->maxxfer < (ep->total_len - ep->xfer_len)) ?
  58947. + ep->maxxfer : (ep->total_len - ep->xfer_len);
  58948. + else
  58949. + ep->xfer_len += (MAX_PKT_CNT * ep->maxpacket < (ep->total_len
  58950. + - ep->xfer_len)) ? MAX_PKT_CNT * ep->maxpacket : (ep->total_len - ep->xfer_len);
  58951. + }
  58952. +
  58953. + /* Program the transfer size and packet count as follows:
  58954. + *
  58955. + * pktcnt = N
  58956. + * xfersize = N * maxpacket
  58957. + */
  58958. + if ((ep->xfer_len - ep->xfer_count) == 0) {
  58959. + /* Zero Length Packet */
  58960. + deptsiz.b.xfersize = ep->maxpacket;
  58961. + deptsiz.b.pktcnt = 1;
  58962. + } else {
  58963. + deptsiz.b.pktcnt =
  58964. + (ep->xfer_len - ep->xfer_count +
  58965. + (ep->maxpacket - 1)) / ep->maxpacket;
  58966. + if (deptsiz.b.pktcnt > MAX_PKT_CNT) {
  58967. + deptsiz.b.pktcnt = MAX_PKT_CNT;
  58968. + }
  58969. + if (!core_if->dma_desc_enable) {
  58970. + ep->xfer_len =
  58971. + deptsiz.b.pktcnt * ep->maxpacket + ep->xfer_count;
  58972. + }
  58973. + deptsiz.b.xfersize = ep->xfer_len - ep->xfer_count;
  58974. + }
  58975. +
  58976. + DWC_DEBUGPL(DBG_PCDV, "ep%d xfersize=%d pktcnt=%d\n",
  58977. + ep->num, deptsiz.b.xfersize, deptsiz.b.pktcnt);
  58978. +
  58979. + if (core_if->dma_enable) {
  58980. + if (!core_if->dma_desc_enable) {
  58981. + DWC_WRITE_REG32(&out_regs->doeptsiz,
  58982. + deptsiz.d32);
  58983. +
  58984. + DWC_WRITE_REG32(&(out_regs->doepdma),
  58985. + (uint32_t) ep->dma_addr);
  58986. + } else {
  58987. +#ifdef DWC_UTE_CFI
  58988. + /* The descriptor chain should be already initialized by now */
  58989. + if (ep->buff_mode != BM_STANDARD) {
  58990. + DWC_WRITE_REG32(&out_regs->doepdma,
  58991. + ep->descs_dma_addr);
  58992. + } else {
  58993. +#endif
  58994. + /** This is used for interrupt out transfers*/
  58995. + if (!ep->xfer_len)
  58996. + ep->xfer_len = ep->total_len;
  58997. + init_dma_desc_chain(core_if, ep);
  58998. +
  58999. + if (core_if->core_params->dev_out_nak) {
  59000. + if (ep->type == DWC_OTG_EP_TYPE_BULK) {
  59001. + deptsiz.b.pktcnt = (ep->total_len +
  59002. + (ep->maxpacket - 1)) / ep->maxpacket;
  59003. + deptsiz.b.xfersize = ep->total_len;
  59004. + /* Remember initial value of doeptsiz */
  59005. + core_if->start_doeptsiz_val[ep->num] = deptsiz.d32;
  59006. + DWC_WRITE_REG32(&out_regs->doeptsiz,
  59007. + deptsiz.d32);
  59008. + }
  59009. + }
  59010. + /** DOEPDMAn Register write */
  59011. + DWC_WRITE_REG32(&out_regs->doepdma,
  59012. + ep->dma_desc_addr);
  59013. +#ifdef DWC_UTE_CFI
  59014. + }
  59015. +#endif
  59016. + }
  59017. + } else {
  59018. + DWC_WRITE_REG32(&out_regs->doeptsiz, deptsiz.d32);
  59019. + }
  59020. +
  59021. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  59022. + dsts_data_t dsts = {.d32 = 0};
  59023. + if (ep->bInterval == 1) {
  59024. + dsts.d32 =
  59025. + DWC_READ_REG32(&core_if->dev_if->
  59026. + dev_global_regs->dsts);
  59027. + ep->frame_num = dsts.b.soffn + ep->bInterval;
  59028. + if (ep->frame_num > 0x3FFF) {
  59029. + ep->frm_overrun = 1;
  59030. + ep->frame_num &= 0x3FFF;
  59031. + } else
  59032. + ep->frm_overrun = 0;
  59033. +
  59034. + if (ep->frame_num & 0x1) {
  59035. + depctl.b.setd1pid = 1;
  59036. + } else {
  59037. + depctl.b.setd0pid = 1;
  59038. + }
  59039. + }
  59040. + }
  59041. +
  59042. + /* EP enable */
  59043. + depctl.b.cnak = 1;
  59044. + depctl.b.epena = 1;
  59045. +
  59046. + DWC_WRITE_REG32(&out_regs->doepctl, depctl.d32);
  59047. +
  59048. + DWC_DEBUGPL(DBG_PCD, "DOEPCTL=%08x DOEPTSIZ=%08x\n",
  59049. + DWC_READ_REG32(&out_regs->doepctl),
  59050. + DWC_READ_REG32(&out_regs->doeptsiz));
  59051. + DWC_DEBUGPL(DBG_PCD, "DAINTMSK=%08x GINTMSK=%08x\n",
  59052. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->
  59053. + daintmsk),
  59054. + DWC_READ_REG32(&core_if->core_global_regs->
  59055. + gintmsk));
  59056. +
  59057. + /* Timer is scheduling only for out bulk transfers for
  59058. + * "Device DDMA OUT NAK Enhancement" feature to inform user
  59059. + * about received data payload in case of timeout
  59060. + */
  59061. + if (core_if->core_params->dev_out_nak) {
  59062. + if (ep->type == DWC_OTG_EP_TYPE_BULK) {
  59063. + core_if->ep_xfer_info[ep->num].core_if = core_if;
  59064. + core_if->ep_xfer_info[ep->num].ep = ep;
  59065. + core_if->ep_xfer_info[ep->num].state = 1;
  59066. +
  59067. + /* Start a timer for this transfer. */
  59068. + DWC_TIMER_SCHEDULE(core_if->ep_xfer_timer[ep->num], 10000);
  59069. + }
  59070. + }
  59071. + }
  59072. +}
  59073. +
  59074. +/**
  59075. + * This function setup a zero length transfer in Buffer DMA and
  59076. + * Slave modes for usb requests with zero field set
  59077. + *
  59078. + * @param core_if Programming view of DWC_otg controller.
  59079. + * @param ep The EP to start the transfer on.
  59080. + *
  59081. + */
  59082. +void dwc_otg_ep_start_zl_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  59083. +{
  59084. +
  59085. + depctl_data_t depctl;
  59086. + deptsiz_data_t deptsiz;
  59087. + gintmsk_data_t intr_mask = {.d32 = 0 };
  59088. +
  59089. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s()\n", __func__);
  59090. + DWC_PRINTF("zero length transfer is called\n");
  59091. +
  59092. + /* IN endpoint */
  59093. + if (ep->is_in == 1) {
  59094. + dwc_otg_dev_in_ep_regs_t *in_regs =
  59095. + core_if->dev_if->in_ep_regs[ep->num];
  59096. +
  59097. + depctl.d32 = DWC_READ_REG32(&(in_regs->diepctl));
  59098. + deptsiz.d32 = DWC_READ_REG32(&(in_regs->dieptsiz));
  59099. +
  59100. + deptsiz.b.xfersize = 0;
  59101. + deptsiz.b.pktcnt = 1;
  59102. +
  59103. + /* Write the DMA register */
  59104. + if (core_if->dma_enable) {
  59105. + if (core_if->dma_desc_enable == 0) {
  59106. + deptsiz.b.mc = 1;
  59107. + DWC_WRITE_REG32(&in_regs->dieptsiz,
  59108. + deptsiz.d32);
  59109. + DWC_WRITE_REG32(&(in_regs->diepdma),
  59110. + (uint32_t) ep->dma_addr);
  59111. + }
  59112. + } else {
  59113. + DWC_WRITE_REG32(&in_regs->dieptsiz, deptsiz.d32);
  59114. + /**
  59115. + * Enable the Non-Periodic Tx FIFO empty interrupt,
  59116. + * or the Tx FIFO epmty interrupt in dedicated Tx FIFO mode,
  59117. + * the data will be written into the fifo by the ISR.
  59118. + */
  59119. + if (core_if->en_multiple_tx_fifo == 0) {
  59120. + intr_mask.b.nptxfempty = 1;
  59121. + DWC_MODIFY_REG32(&core_if->
  59122. + core_global_regs->gintmsk,
  59123. + intr_mask.d32, intr_mask.d32);
  59124. + } else {
  59125. + /* Enable the Tx FIFO Empty Interrupt for this EP */
  59126. + if (ep->xfer_len > 0) {
  59127. + uint32_t fifoemptymsk = 0;
  59128. + fifoemptymsk = 1 << ep->num;
  59129. + DWC_MODIFY_REG32(&core_if->
  59130. + dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  59131. + 0, fifoemptymsk);
  59132. + }
  59133. + }
  59134. + }
  59135. +
  59136. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable)
  59137. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  59138. + /* EP enable, IN data in FIFO */
  59139. + depctl.b.cnak = 1;
  59140. + depctl.b.epena = 1;
  59141. + DWC_WRITE_REG32(&in_regs->diepctl, depctl.d32);
  59142. +
  59143. + } else {
  59144. + /* OUT endpoint */
  59145. + dwc_otg_dev_out_ep_regs_t *out_regs =
  59146. + core_if->dev_if->out_ep_regs[ep->num];
  59147. +
  59148. + depctl.d32 = DWC_READ_REG32(&(out_regs->doepctl));
  59149. + deptsiz.d32 = DWC_READ_REG32(&(out_regs->doeptsiz));
  59150. +
  59151. + /* Zero Length Packet */
  59152. + deptsiz.b.xfersize = ep->maxpacket;
  59153. + deptsiz.b.pktcnt = 1;
  59154. +
  59155. + if (core_if->dma_enable) {
  59156. + if (!core_if->dma_desc_enable) {
  59157. + DWC_WRITE_REG32(&out_regs->doeptsiz,
  59158. + deptsiz.d32);
  59159. +
  59160. + DWC_WRITE_REG32(&(out_regs->doepdma),
  59161. + (uint32_t) ep->dma_addr);
  59162. + }
  59163. + } else {
  59164. + DWC_WRITE_REG32(&out_regs->doeptsiz, deptsiz.d32);
  59165. + }
  59166. +
  59167. + /* EP enable */
  59168. + depctl.b.cnak = 1;
  59169. + depctl.b.epena = 1;
  59170. +
  59171. + DWC_WRITE_REG32(&out_regs->doepctl, depctl.d32);
  59172. +
  59173. + }
  59174. +}
  59175. +
  59176. +/**
  59177. + * This function does the setup for a data transfer for EP0 and starts
  59178. + * the transfer. For an IN transfer, the packets will be loaded into
  59179. + * the appropriate Tx FIFO in the ISR. For OUT transfers, the packets are
  59180. + * unloaded from the Rx FIFO in the ISR.
  59181. + *
  59182. + * @param core_if Programming view of DWC_otg controller.
  59183. + * @param ep The EP0 data.
  59184. + */
  59185. +void dwc_otg_ep0_start_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  59186. +{
  59187. + depctl_data_t depctl;
  59188. + deptsiz0_data_t deptsiz;
  59189. + gintmsk_data_t intr_mask = {.d32 = 0 };
  59190. + dwc_otg_dev_dma_desc_t *dma_desc;
  59191. +
  59192. + DWC_DEBUGPL(DBG_PCD, "ep%d-%s xfer_len=%d xfer_cnt=%d "
  59193. + "xfer_buff=%p start_xfer_buff=%p \n",
  59194. + ep->num, (ep->is_in ? "IN" : "OUT"), ep->xfer_len,
  59195. + ep->xfer_count, ep->xfer_buff, ep->start_xfer_buff);
  59196. +
  59197. + ep->total_len = ep->xfer_len;
  59198. +
  59199. + /* IN endpoint */
  59200. + if (ep->is_in == 1) {
  59201. + dwc_otg_dev_in_ep_regs_t *in_regs =
  59202. + core_if->dev_if->in_ep_regs[0];
  59203. +
  59204. + gnptxsts_data_t gtxstatus;
  59205. +
  59206. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  59207. + depctl.d32 = DWC_READ_REG32(&in_regs->diepctl);
  59208. + if (depctl.b.epena)
  59209. + return;
  59210. + }
  59211. +
  59212. + gtxstatus.d32 =
  59213. + DWC_READ_REG32(&core_if->core_global_regs->gnptxsts);
  59214. +
  59215. + /* If dedicated FIFO every time flush fifo before enable ep*/
  59216. + if (core_if->en_multiple_tx_fifo && core_if->snpsid >= OTG_CORE_REV_3_00a)
  59217. + dwc_otg_flush_tx_fifo(core_if, ep->tx_fifo_num);
  59218. +
  59219. + if (core_if->en_multiple_tx_fifo == 0
  59220. + && gtxstatus.b.nptxqspcavail == 0
  59221. + && !core_if->dma_enable) {
  59222. +#ifdef DEBUG
  59223. + deptsiz.d32 = DWC_READ_REG32(&in_regs->dieptsiz);
  59224. + DWC_DEBUGPL(DBG_PCD, "DIEPCTL0=%0x\n",
  59225. + DWC_READ_REG32(&in_regs->diepctl));
  59226. + DWC_DEBUGPL(DBG_PCD, "DIEPTSIZ0=%0x (sz=%d, pcnt=%d)\n",
  59227. + deptsiz.d32,
  59228. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  59229. + DWC_PRINTF("TX Queue or FIFO Full (0x%0x)\n",
  59230. + gtxstatus.d32);
  59231. +#endif
  59232. + return;
  59233. + }
  59234. +
  59235. + depctl.d32 = DWC_READ_REG32(&in_regs->diepctl);
  59236. + deptsiz.d32 = DWC_READ_REG32(&in_regs->dieptsiz);
  59237. +
  59238. + /* Zero Length Packet? */
  59239. + if (ep->xfer_len == 0) {
  59240. + deptsiz.b.xfersize = 0;
  59241. + deptsiz.b.pktcnt = 1;
  59242. + } else {
  59243. + /* Program the transfer size and packet count
  59244. + * as follows: xfersize = N * maxpacket +
  59245. + * short_packet pktcnt = N + (short_packet
  59246. + * exist ? 1 : 0)
  59247. + */
  59248. + if (ep->xfer_len > ep->maxpacket) {
  59249. + ep->xfer_len = ep->maxpacket;
  59250. + deptsiz.b.xfersize = ep->maxpacket;
  59251. + } else {
  59252. + deptsiz.b.xfersize = ep->xfer_len;
  59253. + }
  59254. + deptsiz.b.pktcnt = 1;
  59255. +
  59256. + }
  59257. + DWC_DEBUGPL(DBG_PCDV,
  59258. + "IN len=%d xfersize=%d pktcnt=%d [%08x]\n",
  59259. + ep->xfer_len, deptsiz.b.xfersize, deptsiz.b.pktcnt,
  59260. + deptsiz.d32);
  59261. +
  59262. + /* Write the DMA register */
  59263. + if (core_if->dma_enable) {
  59264. + if (core_if->dma_desc_enable == 0) {
  59265. + DWC_WRITE_REG32(&in_regs->dieptsiz,
  59266. + deptsiz.d32);
  59267. +
  59268. + DWC_WRITE_REG32(&(in_regs->diepdma),
  59269. + (uint32_t) ep->dma_addr);
  59270. + } else {
  59271. + dma_desc = core_if->dev_if->in_desc_addr;
  59272. +
  59273. + /** DMA Descriptor Setup */
  59274. + dma_desc->status.b.bs = BS_HOST_BUSY;
  59275. + dma_desc->status.b.l = 1;
  59276. + dma_desc->status.b.ioc = 1;
  59277. + dma_desc->status.b.sp =
  59278. + (ep->xfer_len == ep->maxpacket) ? 0 : 1;
  59279. + dma_desc->status.b.bytes = ep->xfer_len;
  59280. + dma_desc->buf = ep->dma_addr;
  59281. + dma_desc->status.b.sts = 0;
  59282. + dma_desc->status.b.bs = BS_HOST_READY;
  59283. +
  59284. + /** DIEPDMA0 Register write */
  59285. + DWC_WRITE_REG32(&in_regs->diepdma,
  59286. + core_if->
  59287. + dev_if->dma_in_desc_addr);
  59288. + }
  59289. + } else {
  59290. + DWC_WRITE_REG32(&in_regs->dieptsiz, deptsiz.d32);
  59291. + }
  59292. +
  59293. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable)
  59294. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  59295. + /* EP enable, IN data in FIFO */
  59296. + depctl.b.cnak = 1;
  59297. + depctl.b.epena = 1;
  59298. + DWC_WRITE_REG32(&in_regs->diepctl, depctl.d32);
  59299. +
  59300. + /**
  59301. + * Enable the Non-Periodic Tx FIFO empty interrupt, the
  59302. + * data will be written into the fifo by the ISR.
  59303. + */
  59304. + if (!core_if->dma_enable) {
  59305. + if (core_if->en_multiple_tx_fifo == 0) {
  59306. + intr_mask.b.nptxfempty = 1;
  59307. + DWC_MODIFY_REG32(&core_if->
  59308. + core_global_regs->gintmsk,
  59309. + intr_mask.d32, intr_mask.d32);
  59310. + } else {
  59311. + /* Enable the Tx FIFO Empty Interrupt for this EP */
  59312. + if (ep->xfer_len > 0) {
  59313. + uint32_t fifoemptymsk = 0;
  59314. + fifoemptymsk |= 1 << ep->num;
  59315. + DWC_MODIFY_REG32(&core_if->
  59316. + dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  59317. + 0, fifoemptymsk);
  59318. + }
  59319. + }
  59320. + }
  59321. + } else {
  59322. + /* OUT endpoint */
  59323. + dwc_otg_dev_out_ep_regs_t *out_regs =
  59324. + core_if->dev_if->out_ep_regs[0];
  59325. +
  59326. + depctl.d32 = DWC_READ_REG32(&out_regs->doepctl);
  59327. + deptsiz.d32 = DWC_READ_REG32(&out_regs->doeptsiz);
  59328. +
  59329. + /* Program the transfer size and packet count as follows:
  59330. + * xfersize = N * (maxpacket + 4 - (maxpacket % 4))
  59331. + * pktcnt = N */
  59332. + /* Zero Length Packet */
  59333. + deptsiz.b.xfersize = ep->maxpacket;
  59334. + deptsiz.b.pktcnt = 1;
  59335. + if (core_if->snpsid >= OTG_CORE_REV_3_00a)
  59336. + deptsiz.b.supcnt = 3;
  59337. +
  59338. + DWC_DEBUGPL(DBG_PCDV, "len=%d xfersize=%d pktcnt=%d\n",
  59339. + ep->xfer_len, deptsiz.b.xfersize, deptsiz.b.pktcnt);
  59340. +
  59341. + if (core_if->dma_enable) {
  59342. + if (!core_if->dma_desc_enable) {
  59343. + DWC_WRITE_REG32(&out_regs->doeptsiz,
  59344. + deptsiz.d32);
  59345. +
  59346. + DWC_WRITE_REG32(&(out_regs->doepdma),
  59347. + (uint32_t) ep->dma_addr);
  59348. + } else {
  59349. + dma_desc = core_if->dev_if->out_desc_addr;
  59350. +
  59351. + /** DMA Descriptor Setup */
  59352. + dma_desc->status.b.bs = BS_HOST_BUSY;
  59353. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  59354. + dma_desc->status.b.mtrf = 0;
  59355. + dma_desc->status.b.sr = 0;
  59356. + }
  59357. + dma_desc->status.b.l = 1;
  59358. + dma_desc->status.b.ioc = 1;
  59359. + dma_desc->status.b.bytes = ep->maxpacket;
  59360. + dma_desc->buf = ep->dma_addr;
  59361. + dma_desc->status.b.sts = 0;
  59362. + dma_desc->status.b.bs = BS_HOST_READY;
  59363. +
  59364. + /** DOEPDMA0 Register write */
  59365. + DWC_WRITE_REG32(&out_regs->doepdma,
  59366. + core_if->dev_if->
  59367. + dma_out_desc_addr);
  59368. + }
  59369. + } else {
  59370. + DWC_WRITE_REG32(&out_regs->doeptsiz, deptsiz.d32);
  59371. + }
  59372. +
  59373. + /* EP enable */
  59374. + depctl.b.cnak = 1;
  59375. + depctl.b.epena = 1;
  59376. + DWC_WRITE_REG32(&(out_regs->doepctl), depctl.d32);
  59377. + }
  59378. +}
  59379. +
  59380. +/**
  59381. + * This function continues control IN transfers started by
  59382. + * dwc_otg_ep0_start_transfer, when the transfer does not fit in a
  59383. + * single packet. NOTE: The DIEPCTL0/DOEPCTL0 registers only have one
  59384. + * bit for the packet count.
  59385. + *
  59386. + * @param core_if Programming view of DWC_otg controller.
  59387. + * @param ep The EP0 data.
  59388. + */
  59389. +void dwc_otg_ep0_continue_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  59390. +{
  59391. + depctl_data_t depctl;
  59392. + deptsiz0_data_t deptsiz;
  59393. + gintmsk_data_t intr_mask = {.d32 = 0 };
  59394. + dwc_otg_dev_dma_desc_t *dma_desc;
  59395. +
  59396. + if (ep->is_in == 1) {
  59397. + dwc_otg_dev_in_ep_regs_t *in_regs =
  59398. + core_if->dev_if->in_ep_regs[0];
  59399. + gnptxsts_data_t tx_status = {.d32 = 0 };
  59400. +
  59401. + tx_status.d32 =
  59402. + DWC_READ_REG32(&core_if->core_global_regs->gnptxsts);
  59403. + /** @todo Should there be check for room in the Tx
  59404. + * Status Queue. If not remove the code above this comment. */
  59405. +
  59406. + depctl.d32 = DWC_READ_REG32(&in_regs->diepctl);
  59407. + deptsiz.d32 = DWC_READ_REG32(&in_regs->dieptsiz);
  59408. +
  59409. + /* Program the transfer size and packet count
  59410. + * as follows: xfersize = N * maxpacket +
  59411. + * short_packet pktcnt = N + (short_packet
  59412. + * exist ? 1 : 0)
  59413. + */
  59414. +
  59415. + if (core_if->dma_desc_enable == 0) {
  59416. + deptsiz.b.xfersize =
  59417. + (ep->total_len - ep->xfer_count) >
  59418. + ep->maxpacket ? ep->maxpacket : (ep->total_len -
  59419. + ep->xfer_count);
  59420. + deptsiz.b.pktcnt = 1;
  59421. + if (core_if->dma_enable == 0) {
  59422. + ep->xfer_len += deptsiz.b.xfersize;
  59423. + } else {
  59424. + ep->xfer_len = deptsiz.b.xfersize;
  59425. + }
  59426. + DWC_WRITE_REG32(&in_regs->dieptsiz, deptsiz.d32);
  59427. + } else {
  59428. + ep->xfer_len =
  59429. + (ep->total_len - ep->xfer_count) >
  59430. + ep->maxpacket ? ep->maxpacket : (ep->total_len -
  59431. + ep->xfer_count);
  59432. +
  59433. + dma_desc = core_if->dev_if->in_desc_addr;
  59434. +
  59435. + /** DMA Descriptor Setup */
  59436. + dma_desc->status.b.bs = BS_HOST_BUSY;
  59437. + dma_desc->status.b.l = 1;
  59438. + dma_desc->status.b.ioc = 1;
  59439. + dma_desc->status.b.sp =
  59440. + (ep->xfer_len == ep->maxpacket) ? 0 : 1;
  59441. + dma_desc->status.b.bytes = ep->xfer_len;
  59442. + dma_desc->buf = ep->dma_addr;
  59443. + dma_desc->status.b.sts = 0;
  59444. + dma_desc->status.b.bs = BS_HOST_READY;
  59445. +
  59446. + /** DIEPDMA0 Register write */
  59447. + DWC_WRITE_REG32(&in_regs->diepdma,
  59448. + core_if->dev_if->dma_in_desc_addr);
  59449. + }
  59450. +
  59451. + DWC_DEBUGPL(DBG_PCDV,
  59452. + "IN len=%d xfersize=%d pktcnt=%d [%08x]\n",
  59453. + ep->xfer_len, deptsiz.b.xfersize, deptsiz.b.pktcnt,
  59454. + deptsiz.d32);
  59455. +
  59456. + /* Write the DMA register */
  59457. + if (core_if->hwcfg2.b.architecture == DWC_INT_DMA_ARCH) {
  59458. + if (core_if->dma_desc_enable == 0)
  59459. + DWC_WRITE_REG32(&(in_regs->diepdma),
  59460. + (uint32_t) ep->dma_addr);
  59461. + }
  59462. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable)
  59463. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  59464. + /* EP enable, IN data in FIFO */
  59465. + depctl.b.cnak = 1;
  59466. + depctl.b.epena = 1;
  59467. + DWC_WRITE_REG32(&in_regs->diepctl, depctl.d32);
  59468. +
  59469. + /**
  59470. + * Enable the Non-Periodic Tx FIFO empty interrupt, the
  59471. + * data will be written into the fifo by the ISR.
  59472. + */
  59473. + if (!core_if->dma_enable) {
  59474. + if (core_if->en_multiple_tx_fifo == 0) {
  59475. + /* First clear it from GINTSTS */
  59476. + intr_mask.b.nptxfempty = 1;
  59477. + DWC_MODIFY_REG32(&core_if->
  59478. + core_global_regs->gintmsk,
  59479. + intr_mask.d32, intr_mask.d32);
  59480. +
  59481. + } else {
  59482. + /* Enable the Tx FIFO Empty Interrupt for this EP */
  59483. + if (ep->xfer_len > 0) {
  59484. + uint32_t fifoemptymsk = 0;
  59485. + fifoemptymsk |= 1 << ep->num;
  59486. + DWC_MODIFY_REG32(&core_if->
  59487. + dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  59488. + 0, fifoemptymsk);
  59489. + }
  59490. + }
  59491. + }
  59492. + } else {
  59493. + dwc_otg_dev_out_ep_regs_t *out_regs =
  59494. + core_if->dev_if->out_ep_regs[0];
  59495. +
  59496. + depctl.d32 = DWC_READ_REG32(&out_regs->doepctl);
  59497. + deptsiz.d32 = DWC_READ_REG32(&out_regs->doeptsiz);
  59498. +
  59499. + /* Program the transfer size and packet count
  59500. + * as follows: xfersize = N * maxpacket +
  59501. + * short_packet pktcnt = N + (short_packet
  59502. + * exist ? 1 : 0)
  59503. + */
  59504. + deptsiz.b.xfersize = ep->maxpacket;
  59505. + deptsiz.b.pktcnt = 1;
  59506. +
  59507. + if (core_if->dma_desc_enable == 0) {
  59508. + DWC_WRITE_REG32(&out_regs->doeptsiz, deptsiz.d32);
  59509. + } else {
  59510. + dma_desc = core_if->dev_if->out_desc_addr;
  59511. +
  59512. + /** DMA Descriptor Setup */
  59513. + dma_desc->status.b.bs = BS_HOST_BUSY;
  59514. + dma_desc->status.b.l = 1;
  59515. + dma_desc->status.b.ioc = 1;
  59516. + dma_desc->status.b.bytes = ep->maxpacket;
  59517. + dma_desc->buf = ep->dma_addr;
  59518. + dma_desc->status.b.sts = 0;
  59519. + dma_desc->status.b.bs = BS_HOST_READY;
  59520. +
  59521. + /** DOEPDMA0 Register write */
  59522. + DWC_WRITE_REG32(&out_regs->doepdma,
  59523. + core_if->dev_if->dma_out_desc_addr);
  59524. + }
  59525. +
  59526. + DWC_DEBUGPL(DBG_PCDV,
  59527. + "IN len=%d xfersize=%d pktcnt=%d [%08x]\n",
  59528. + ep->xfer_len, deptsiz.b.xfersize, deptsiz.b.pktcnt,
  59529. + deptsiz.d32);
  59530. +
  59531. + /* Write the DMA register */
  59532. + if (core_if->hwcfg2.b.architecture == DWC_INT_DMA_ARCH) {
  59533. + if (core_if->dma_desc_enable == 0)
  59534. + DWC_WRITE_REG32(&(out_regs->doepdma),
  59535. + (uint32_t) ep->dma_addr);
  59536. +
  59537. + }
  59538. +
  59539. + /* EP enable, IN data in FIFO */
  59540. + depctl.b.cnak = 1;
  59541. + depctl.b.epena = 1;
  59542. + DWC_WRITE_REG32(&out_regs->doepctl, depctl.d32);
  59543. +
  59544. + }
  59545. +}
  59546. +
  59547. +#ifdef DEBUG
  59548. +void dump_msg(const u8 * buf, unsigned int length)
  59549. +{
  59550. + unsigned int start, num, i;
  59551. + char line[52], *p;
  59552. +
  59553. + if (length >= 512)
  59554. + return;
  59555. + start = 0;
  59556. + while (length > 0) {
  59557. + num = length < 16u ? length : 16u;
  59558. + p = line;
  59559. + for (i = 0; i < num; ++i) {
  59560. + if (i == 8)
  59561. + *p++ = ' ';
  59562. + DWC_SPRINTF(p, " %02x", buf[i]);
  59563. + p += 3;
  59564. + }
  59565. + *p = 0;
  59566. + DWC_PRINTF("%6x: %s\n", start, line);
  59567. + buf += num;
  59568. + start += num;
  59569. + length -= num;
  59570. + }
  59571. +}
  59572. +#else
  59573. +static inline void dump_msg(const u8 * buf, unsigned int length)
  59574. +{
  59575. +}
  59576. +#endif
  59577. +
  59578. +/**
  59579. + * This function writes a packet into the Tx FIFO associated with the
  59580. + * EP. For non-periodic EPs the non-periodic Tx FIFO is written. For
  59581. + * periodic EPs the periodic Tx FIFO associated with the EP is written
  59582. + * with all packets for the next micro-frame.
  59583. + *
  59584. + * @param core_if Programming view of DWC_otg controller.
  59585. + * @param ep The EP to write packet for.
  59586. + * @param dma Indicates if DMA is being used.
  59587. + */
  59588. +void dwc_otg_ep_write_packet(dwc_otg_core_if_t * core_if, dwc_ep_t * ep,
  59589. + int dma)
  59590. +{
  59591. + /**
  59592. + * The buffer is padded to DWORD on a per packet basis in
  59593. + * slave/dma mode if the MPS is not DWORD aligned. The last
  59594. + * packet, if short, is also padded to a multiple of DWORD.
  59595. + *
  59596. + * ep->xfer_buff always starts DWORD aligned in memory and is a
  59597. + * multiple of DWORD in length
  59598. + *
  59599. + * ep->xfer_len can be any number of bytes
  59600. + *
  59601. + * ep->xfer_count is a multiple of ep->maxpacket until the last
  59602. + * packet
  59603. + *
  59604. + * FIFO access is DWORD */
  59605. +
  59606. + uint32_t i;
  59607. + uint32_t byte_count;
  59608. + uint32_t dword_count;
  59609. + uint32_t *fifo;
  59610. + uint32_t *data_buff = (uint32_t *) ep->xfer_buff;
  59611. +
  59612. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s(%p,%p)\n", __func__, core_if,
  59613. + ep);
  59614. + if (ep->xfer_count >= ep->xfer_len) {
  59615. + DWC_WARN("%s() No data for EP%d!!!\n", __func__, ep->num);
  59616. + return;
  59617. + }
  59618. +
  59619. + /* Find the byte length of the packet either short packet or MPS */
  59620. + if ((ep->xfer_len - ep->xfer_count) < ep->maxpacket) {
  59621. + byte_count = ep->xfer_len - ep->xfer_count;
  59622. + } else {
  59623. + byte_count = ep->maxpacket;
  59624. + }
  59625. +
  59626. + /* Find the DWORD length, padded by extra bytes as neccessary if MPS
  59627. + * is not a multiple of DWORD */
  59628. + dword_count = (byte_count + 3) / 4;
  59629. +
  59630. +#ifdef VERBOSE
  59631. + dump_msg(ep->xfer_buff, byte_count);
  59632. +#endif
  59633. +
  59634. + /**@todo NGS Where are the Periodic Tx FIFO addresses
  59635. + * intialized? What should this be? */
  59636. +
  59637. + fifo = core_if->data_fifo[ep->num];
  59638. +
  59639. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "fifo=%p buff=%p *p=%08x bc=%d\n",
  59640. + fifo, data_buff, *data_buff, byte_count);
  59641. +
  59642. + if (!dma) {
  59643. + for (i = 0; i < dword_count; i++, data_buff++) {
  59644. + DWC_WRITE_REG32(fifo, *data_buff);
  59645. + }
  59646. + }
  59647. +
  59648. + ep->xfer_count += byte_count;
  59649. + ep->xfer_buff += byte_count;
  59650. + ep->dma_addr += byte_count;
  59651. +}
  59652. +
  59653. +/**
  59654. + * Set the EP STALL.
  59655. + *
  59656. + * @param core_if Programming view of DWC_otg controller.
  59657. + * @param ep The EP to set the stall on.
  59658. + */
  59659. +void dwc_otg_ep_set_stall(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  59660. +{
  59661. + depctl_data_t depctl;
  59662. + volatile uint32_t *depctl_addr;
  59663. +
  59664. + DWC_DEBUGPL(DBG_PCD, "%s ep%d-%s\n", __func__, ep->num,
  59665. + (ep->is_in ? "IN" : "OUT"));
  59666. +
  59667. + if (ep->is_in == 1) {
  59668. + depctl_addr = &(core_if->dev_if->in_ep_regs[ep->num]->diepctl);
  59669. + depctl.d32 = DWC_READ_REG32(depctl_addr);
  59670. +
  59671. + /* set the disable and stall bits */
  59672. + if (depctl.b.epena) {
  59673. + depctl.b.epdis = 1;
  59674. + }
  59675. + depctl.b.stall = 1;
  59676. + DWC_WRITE_REG32(depctl_addr, depctl.d32);
  59677. + } else {
  59678. + depctl_addr = &(core_if->dev_if->out_ep_regs[ep->num]->doepctl);
  59679. + depctl.d32 = DWC_READ_REG32(depctl_addr);
  59680. +
  59681. + /* set the stall bit */
  59682. + depctl.b.stall = 1;
  59683. + DWC_WRITE_REG32(depctl_addr, depctl.d32);
  59684. + }
  59685. +
  59686. + DWC_DEBUGPL(DBG_PCD, "DEPCTL=%0x\n", DWC_READ_REG32(depctl_addr));
  59687. +
  59688. + return;
  59689. +}
  59690. +
  59691. +/**
  59692. + * Clear the EP STALL.
  59693. + *
  59694. + * @param core_if Programming view of DWC_otg controller.
  59695. + * @param ep The EP to clear stall from.
  59696. + */
  59697. +void dwc_otg_ep_clear_stall(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  59698. +{
  59699. + depctl_data_t depctl;
  59700. + volatile uint32_t *depctl_addr;
  59701. +
  59702. + DWC_DEBUGPL(DBG_PCD, "%s ep%d-%s\n", __func__, ep->num,
  59703. + (ep->is_in ? "IN" : "OUT"));
  59704. +
  59705. + if (ep->is_in == 1) {
  59706. + depctl_addr = &(core_if->dev_if->in_ep_regs[ep->num]->diepctl);
  59707. + } else {
  59708. + depctl_addr = &(core_if->dev_if->out_ep_regs[ep->num]->doepctl);
  59709. + }
  59710. +
  59711. + depctl.d32 = DWC_READ_REG32(depctl_addr);
  59712. +
  59713. + /* clear the stall bits */
  59714. + depctl.b.stall = 0;
  59715. +
  59716. + /*
  59717. + * USB Spec 9.4.5: For endpoints using data toggle, regardless
  59718. + * of whether an endpoint has the Halt feature set, a
  59719. + * ClearFeature(ENDPOINT_HALT) request always results in the
  59720. + * data toggle being reinitialized to DATA0.
  59721. + */
  59722. + if (ep->type == DWC_OTG_EP_TYPE_INTR ||
  59723. + ep->type == DWC_OTG_EP_TYPE_BULK) {
  59724. + depctl.b.setd0pid = 1; /* DATA0 */
  59725. + }
  59726. +
  59727. + DWC_WRITE_REG32(depctl_addr, depctl.d32);
  59728. + DWC_DEBUGPL(DBG_PCD, "DEPCTL=%0x\n", DWC_READ_REG32(depctl_addr));
  59729. + return;
  59730. +}
  59731. +
  59732. +/**
  59733. + * This function reads a packet from the Rx FIFO into the destination
  59734. + * buffer. To read SETUP data use dwc_otg_read_setup_packet.
  59735. + *
  59736. + * @param core_if Programming view of DWC_otg controller.
  59737. + * @param dest Destination buffer for the packet.
  59738. + * @param bytes Number of bytes to copy to the destination.
  59739. + */
  59740. +void dwc_otg_read_packet(dwc_otg_core_if_t * core_if,
  59741. + uint8_t * dest, uint16_t bytes)
  59742. +{
  59743. + int i;
  59744. + int word_count = (bytes + 3) / 4;
  59745. +
  59746. + volatile uint32_t *fifo = core_if->data_fifo[0];
  59747. + uint32_t *data_buff = (uint32_t *) dest;
  59748. +
  59749. + /**
  59750. + * @todo Account for the case where _dest is not dword aligned. This
  59751. + * requires reading data from the FIFO into a uint32_t temp buffer,
  59752. + * then moving it into the data buffer.
  59753. + */
  59754. +
  59755. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s(%p,%p,%d)\n", __func__,
  59756. + core_if, dest, bytes);
  59757. +
  59758. + for (i = 0; i < word_count; i++, data_buff++) {
  59759. + *data_buff = DWC_READ_REG32(fifo);
  59760. + }
  59761. +
  59762. + return;
  59763. +}
  59764. +
  59765. +/**
  59766. + * This functions reads the device registers and prints them
  59767. + *
  59768. + * @param core_if Programming view of DWC_otg controller.
  59769. + */
  59770. +void dwc_otg_dump_dev_registers(dwc_otg_core_if_t * core_if)
  59771. +{
  59772. + int i;
  59773. + volatile uint32_t *addr;
  59774. +
  59775. + DWC_PRINTF("Device Global Registers\n");
  59776. + addr = &core_if->dev_if->dev_global_regs->dcfg;
  59777. + DWC_PRINTF("DCFG @0x%08lX : 0x%08X\n",
  59778. + (unsigned long)addr, DWC_READ_REG32(addr));
  59779. + addr = &core_if->dev_if->dev_global_regs->dctl;
  59780. + DWC_PRINTF("DCTL @0x%08lX : 0x%08X\n",
  59781. + (unsigned long)addr, DWC_READ_REG32(addr));
  59782. + addr = &core_if->dev_if->dev_global_regs->dsts;
  59783. + DWC_PRINTF("DSTS @0x%08lX : 0x%08X\n",
  59784. + (unsigned long)addr, DWC_READ_REG32(addr));
  59785. + addr = &core_if->dev_if->dev_global_regs->diepmsk;
  59786. + DWC_PRINTF("DIEPMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59787. + DWC_READ_REG32(addr));
  59788. + addr = &core_if->dev_if->dev_global_regs->doepmsk;
  59789. + DWC_PRINTF("DOEPMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59790. + DWC_READ_REG32(addr));
  59791. + addr = &core_if->dev_if->dev_global_regs->daint;
  59792. + DWC_PRINTF("DAINT @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59793. + DWC_READ_REG32(addr));
  59794. + addr = &core_if->dev_if->dev_global_regs->daintmsk;
  59795. + DWC_PRINTF("DAINTMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59796. + DWC_READ_REG32(addr));
  59797. + addr = &core_if->dev_if->dev_global_regs->dtknqr1;
  59798. + DWC_PRINTF("DTKNQR1 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59799. + DWC_READ_REG32(addr));
  59800. + if (core_if->hwcfg2.b.dev_token_q_depth > 6) {
  59801. + addr = &core_if->dev_if->dev_global_regs->dtknqr2;
  59802. + DWC_PRINTF("DTKNQR2 @0x%08lX : 0x%08X\n",
  59803. + (unsigned long)addr, DWC_READ_REG32(addr));
  59804. + }
  59805. +
  59806. + addr = &core_if->dev_if->dev_global_regs->dvbusdis;
  59807. + DWC_PRINTF("DVBUSID @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59808. + DWC_READ_REG32(addr));
  59809. +
  59810. + addr = &core_if->dev_if->dev_global_regs->dvbuspulse;
  59811. + DWC_PRINTF("DVBUSPULSE @0x%08lX : 0x%08X\n",
  59812. + (unsigned long)addr, DWC_READ_REG32(addr));
  59813. +
  59814. + addr = &core_if->dev_if->dev_global_regs->dtknqr3_dthrctl;
  59815. + DWC_PRINTF("DTKNQR3_DTHRCTL @0x%08lX : 0x%08X\n",
  59816. + (unsigned long)addr, DWC_READ_REG32(addr));
  59817. +
  59818. + if (core_if->hwcfg2.b.dev_token_q_depth > 22) {
  59819. + addr = &core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk;
  59820. + DWC_PRINTF("DTKNQR4 @0x%08lX : 0x%08X\n",
  59821. + (unsigned long)addr, DWC_READ_REG32(addr));
  59822. + }
  59823. +
  59824. + addr = &core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk;
  59825. + DWC_PRINTF("FIFOEMPMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59826. + DWC_READ_REG32(addr));
  59827. +
  59828. + if (core_if->hwcfg2.b.multi_proc_int) {
  59829. +
  59830. + addr = &core_if->dev_if->dev_global_regs->deachint;
  59831. + DWC_PRINTF("DEACHINT @0x%08lX : 0x%08X\n",
  59832. + (unsigned long)addr, DWC_READ_REG32(addr));
  59833. + addr = &core_if->dev_if->dev_global_regs->deachintmsk;
  59834. + DWC_PRINTF("DEACHINTMSK @0x%08lX : 0x%08X\n",
  59835. + (unsigned long)addr, DWC_READ_REG32(addr));
  59836. +
  59837. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  59838. + addr =
  59839. + &core_if->dev_if->
  59840. + dev_global_regs->diepeachintmsk[i];
  59841. + DWC_PRINTF("DIEPEACHINTMSK[%d] @0x%08lX : 0x%08X\n",
  59842. + i, (unsigned long)addr,
  59843. + DWC_READ_REG32(addr));
  59844. + }
  59845. +
  59846. + for (i = 0; i <= core_if->dev_if->num_out_eps; i++) {
  59847. + addr =
  59848. + &core_if->dev_if->
  59849. + dev_global_regs->doepeachintmsk[i];
  59850. + DWC_PRINTF("DOEPEACHINTMSK[%d] @0x%08lX : 0x%08X\n",
  59851. + i, (unsigned long)addr,
  59852. + DWC_READ_REG32(addr));
  59853. + }
  59854. + }
  59855. +
  59856. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  59857. + DWC_PRINTF("Device IN EP %d Registers\n", i);
  59858. + addr = &core_if->dev_if->in_ep_regs[i]->diepctl;
  59859. + DWC_PRINTF("DIEPCTL @0x%08lX : 0x%08X\n",
  59860. + (unsigned long)addr, DWC_READ_REG32(addr));
  59861. + addr = &core_if->dev_if->in_ep_regs[i]->diepint;
  59862. + DWC_PRINTF("DIEPINT @0x%08lX : 0x%08X\n",
  59863. + (unsigned long)addr, DWC_READ_REG32(addr));
  59864. + addr = &core_if->dev_if->in_ep_regs[i]->dieptsiz;
  59865. + DWC_PRINTF("DIETSIZ @0x%08lX : 0x%08X\n",
  59866. + (unsigned long)addr, DWC_READ_REG32(addr));
  59867. + addr = &core_if->dev_if->in_ep_regs[i]->diepdma;
  59868. + DWC_PRINTF("DIEPDMA @0x%08lX : 0x%08X\n",
  59869. + (unsigned long)addr, DWC_READ_REG32(addr));
  59870. + addr = &core_if->dev_if->in_ep_regs[i]->dtxfsts;
  59871. + DWC_PRINTF("DTXFSTS @0x%08lX : 0x%08X\n",
  59872. + (unsigned long)addr, DWC_READ_REG32(addr));
  59873. + addr = &core_if->dev_if->in_ep_regs[i]->diepdmab;
  59874. + DWC_PRINTF("DIEPDMAB @0x%08lX : 0x%08X\n",
  59875. + (unsigned long)addr, 0 /*DWC_READ_REG32(addr) */ );
  59876. + }
  59877. +
  59878. + for (i = 0; i <= core_if->dev_if->num_out_eps; i++) {
  59879. + DWC_PRINTF("Device OUT EP %d Registers\n", i);
  59880. + addr = &core_if->dev_if->out_ep_regs[i]->doepctl;
  59881. + DWC_PRINTF("DOEPCTL @0x%08lX : 0x%08X\n",
  59882. + (unsigned long)addr, DWC_READ_REG32(addr));
  59883. + addr = &core_if->dev_if->out_ep_regs[i]->doepint;
  59884. + DWC_PRINTF("DOEPINT @0x%08lX : 0x%08X\n",
  59885. + (unsigned long)addr, DWC_READ_REG32(addr));
  59886. + addr = &core_if->dev_if->out_ep_regs[i]->doeptsiz;
  59887. + DWC_PRINTF("DOETSIZ @0x%08lX : 0x%08X\n",
  59888. + (unsigned long)addr, DWC_READ_REG32(addr));
  59889. + addr = &core_if->dev_if->out_ep_regs[i]->doepdma;
  59890. + DWC_PRINTF("DOEPDMA @0x%08lX : 0x%08X\n",
  59891. + (unsigned long)addr, DWC_READ_REG32(addr));
  59892. + if (core_if->dma_enable) { /* Don't access this register in SLAVE mode */
  59893. + addr = &core_if->dev_if->out_ep_regs[i]->doepdmab;
  59894. + DWC_PRINTF("DOEPDMAB @0x%08lX : 0x%08X\n",
  59895. + (unsigned long)addr, DWC_READ_REG32(addr));
  59896. + }
  59897. +
  59898. + }
  59899. +}
  59900. +
  59901. +/**
  59902. + * This functions reads the SPRAM and prints its content
  59903. + *
  59904. + * @param core_if Programming view of DWC_otg controller.
  59905. + */
  59906. +void dwc_otg_dump_spram(dwc_otg_core_if_t * core_if)
  59907. +{
  59908. + volatile uint8_t *addr, *start_addr, *end_addr;
  59909. +
  59910. + DWC_PRINTF("SPRAM Data:\n");
  59911. + start_addr = (void *)core_if->core_global_regs;
  59912. + DWC_PRINTF("Base Address: 0x%8lX\n", (unsigned long)start_addr);
  59913. + start_addr += 0x00028000;
  59914. + end_addr = (void *)core_if->core_global_regs;
  59915. + end_addr += 0x000280e0;
  59916. +
  59917. + for (addr = start_addr; addr < end_addr; addr += 16) {
  59918. + DWC_PRINTF
  59919. + ("0x%8lX:\t%2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X\n",
  59920. + (unsigned long)addr, addr[0], addr[1], addr[2], addr[3],
  59921. + addr[4], addr[5], addr[6], addr[7], addr[8], addr[9],
  59922. + addr[10], addr[11], addr[12], addr[13], addr[14], addr[15]
  59923. + );
  59924. + }
  59925. +
  59926. + return;
  59927. +}
  59928. +
  59929. +/**
  59930. + * This function reads the host registers and prints them
  59931. + *
  59932. + * @param core_if Programming view of DWC_otg controller.
  59933. + */
  59934. +void dwc_otg_dump_host_registers(dwc_otg_core_if_t * core_if)
  59935. +{
  59936. + int i;
  59937. + volatile uint32_t *addr;
  59938. +
  59939. + DWC_PRINTF("Host Global Registers\n");
  59940. + addr = &core_if->host_if->host_global_regs->hcfg;
  59941. + DWC_PRINTF("HCFG @0x%08lX : 0x%08X\n",
  59942. + (unsigned long)addr, DWC_READ_REG32(addr));
  59943. + addr = &core_if->host_if->host_global_regs->hfir;
  59944. + DWC_PRINTF("HFIR @0x%08lX : 0x%08X\n",
  59945. + (unsigned long)addr, DWC_READ_REG32(addr));
  59946. + addr = &core_if->host_if->host_global_regs->hfnum;
  59947. + DWC_PRINTF("HFNUM @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59948. + DWC_READ_REG32(addr));
  59949. + addr = &core_if->host_if->host_global_regs->hptxsts;
  59950. + DWC_PRINTF("HPTXSTS @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59951. + DWC_READ_REG32(addr));
  59952. + addr = &core_if->host_if->host_global_regs->haint;
  59953. + DWC_PRINTF("HAINT @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59954. + DWC_READ_REG32(addr));
  59955. + addr = &core_if->host_if->host_global_regs->haintmsk;
  59956. + DWC_PRINTF("HAINTMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59957. + DWC_READ_REG32(addr));
  59958. + if (core_if->dma_desc_enable) {
  59959. + addr = &core_if->host_if->host_global_regs->hflbaddr;
  59960. + DWC_PRINTF("HFLBADDR @0x%08lX : 0x%08X\n",
  59961. + (unsigned long)addr, DWC_READ_REG32(addr));
  59962. + }
  59963. +
  59964. + addr = core_if->host_if->hprt0;
  59965. + DWC_PRINTF("HPRT0 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59966. + DWC_READ_REG32(addr));
  59967. +
  59968. + for (i = 0; i < core_if->core_params->host_channels; i++) {
  59969. + DWC_PRINTF("Host Channel %d Specific Registers\n", i);
  59970. + addr = &core_if->host_if->hc_regs[i]->hcchar;
  59971. + DWC_PRINTF("HCCHAR @0x%08lX : 0x%08X\n",
  59972. + (unsigned long)addr, DWC_READ_REG32(addr));
  59973. + addr = &core_if->host_if->hc_regs[i]->hcsplt;
  59974. + DWC_PRINTF("HCSPLT @0x%08lX : 0x%08X\n",
  59975. + (unsigned long)addr, DWC_READ_REG32(addr));
  59976. + addr = &core_if->host_if->hc_regs[i]->hcint;
  59977. + DWC_PRINTF("HCINT @0x%08lX : 0x%08X\n",
  59978. + (unsigned long)addr, DWC_READ_REG32(addr));
  59979. + addr = &core_if->host_if->hc_regs[i]->hcintmsk;
  59980. + DWC_PRINTF("HCINTMSK @0x%08lX : 0x%08X\n",
  59981. + (unsigned long)addr, DWC_READ_REG32(addr));
  59982. + addr = &core_if->host_if->hc_regs[i]->hctsiz;
  59983. + DWC_PRINTF("HCTSIZ @0x%08lX : 0x%08X\n",
  59984. + (unsigned long)addr, DWC_READ_REG32(addr));
  59985. + addr = &core_if->host_if->hc_regs[i]->hcdma;
  59986. + DWC_PRINTF("HCDMA @0x%08lX : 0x%08X\n",
  59987. + (unsigned long)addr, DWC_READ_REG32(addr));
  59988. + if (core_if->dma_desc_enable) {
  59989. + addr = &core_if->host_if->hc_regs[i]->hcdmab;
  59990. + DWC_PRINTF("HCDMAB @0x%08lX : 0x%08X\n",
  59991. + (unsigned long)addr, DWC_READ_REG32(addr));
  59992. + }
  59993. +
  59994. + }
  59995. + return;
  59996. +}
  59997. +
  59998. +/**
  59999. + * This function reads the core global registers and prints them
  60000. + *
  60001. + * @param core_if Programming view of DWC_otg controller.
  60002. + */
  60003. +void dwc_otg_dump_global_registers(dwc_otg_core_if_t * core_if)
  60004. +{
  60005. + int i, ep_num;
  60006. + volatile uint32_t *addr;
  60007. + char *txfsiz;
  60008. +
  60009. + DWC_PRINTF("Core Global Registers\n");
  60010. + addr = &core_if->core_global_regs->gotgctl;
  60011. + DWC_PRINTF("GOTGCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60012. + DWC_READ_REG32(addr));
  60013. + addr = &core_if->core_global_regs->gotgint;
  60014. + DWC_PRINTF("GOTGINT @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60015. + DWC_READ_REG32(addr));
  60016. + addr = &core_if->core_global_regs->gahbcfg;
  60017. + DWC_PRINTF("GAHBCFG @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60018. + DWC_READ_REG32(addr));
  60019. + addr = &core_if->core_global_regs->gusbcfg;
  60020. + DWC_PRINTF("GUSBCFG @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60021. + DWC_READ_REG32(addr));
  60022. + addr = &core_if->core_global_regs->grstctl;
  60023. + DWC_PRINTF("GRSTCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60024. + DWC_READ_REG32(addr));
  60025. + addr = &core_if->core_global_regs->gintsts;
  60026. + DWC_PRINTF("GINTSTS @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60027. + DWC_READ_REG32(addr));
  60028. + addr = &core_if->core_global_regs->gintmsk;
  60029. + DWC_PRINTF("GINTMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60030. + DWC_READ_REG32(addr));
  60031. + addr = &core_if->core_global_regs->grxstsr;
  60032. + DWC_PRINTF("GRXSTSR @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60033. + DWC_READ_REG32(addr));
  60034. + addr = &core_if->core_global_regs->grxfsiz;
  60035. + DWC_PRINTF("GRXFSIZ @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60036. + DWC_READ_REG32(addr));
  60037. + addr = &core_if->core_global_regs->gnptxfsiz;
  60038. + DWC_PRINTF("GNPTXFSIZ @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60039. + DWC_READ_REG32(addr));
  60040. + addr = &core_if->core_global_regs->gnptxsts;
  60041. + DWC_PRINTF("GNPTXSTS @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60042. + DWC_READ_REG32(addr));
  60043. + addr = &core_if->core_global_regs->gi2cctl;
  60044. + DWC_PRINTF("GI2CCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60045. + DWC_READ_REG32(addr));
  60046. + addr = &core_if->core_global_regs->gpvndctl;
  60047. + DWC_PRINTF("GPVNDCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60048. + DWC_READ_REG32(addr));
  60049. + addr = &core_if->core_global_regs->ggpio;
  60050. + DWC_PRINTF("GGPIO @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60051. + DWC_READ_REG32(addr));
  60052. + addr = &core_if->core_global_regs->guid;
  60053. + DWC_PRINTF("GUID @0x%08lX : 0x%08X\n",
  60054. + (unsigned long)addr, DWC_READ_REG32(addr));
  60055. + addr = &core_if->core_global_regs->gsnpsid;
  60056. + DWC_PRINTF("GSNPSID @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60057. + DWC_READ_REG32(addr));
  60058. + addr = &core_if->core_global_regs->ghwcfg1;
  60059. + DWC_PRINTF("GHWCFG1 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60060. + DWC_READ_REG32(addr));
  60061. + addr = &core_if->core_global_regs->ghwcfg2;
  60062. + DWC_PRINTF("GHWCFG2 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60063. + DWC_READ_REG32(addr));
  60064. + addr = &core_if->core_global_regs->ghwcfg3;
  60065. + DWC_PRINTF("GHWCFG3 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60066. + DWC_READ_REG32(addr));
  60067. + addr = &core_if->core_global_regs->ghwcfg4;
  60068. + DWC_PRINTF("GHWCFG4 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60069. + DWC_READ_REG32(addr));
  60070. + addr = &core_if->core_global_regs->glpmcfg;
  60071. + DWC_PRINTF("GLPMCFG @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60072. + DWC_READ_REG32(addr));
  60073. + addr = &core_if->core_global_regs->gpwrdn;
  60074. + DWC_PRINTF("GPWRDN @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60075. + DWC_READ_REG32(addr));
  60076. + addr = &core_if->core_global_regs->gdfifocfg;
  60077. + DWC_PRINTF("GDFIFOCFG @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60078. + DWC_READ_REG32(addr));
  60079. + addr = &core_if->core_global_regs->adpctl;
  60080. + DWC_PRINTF("ADPCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60081. + dwc_otg_adp_read_reg(core_if));
  60082. + addr = &core_if->core_global_regs->hptxfsiz;
  60083. + DWC_PRINTF("HPTXFSIZ @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60084. + DWC_READ_REG32(addr));
  60085. +
  60086. + if (core_if->en_multiple_tx_fifo == 0) {
  60087. + ep_num = core_if->hwcfg4.b.num_dev_perio_in_ep;
  60088. + txfsiz = "DPTXFSIZ";
  60089. + } else {
  60090. + ep_num = core_if->hwcfg4.b.num_in_eps;
  60091. + txfsiz = "DIENPTXF";
  60092. + }
  60093. + for (i = 0; i < ep_num; i++) {
  60094. + addr = &core_if->core_global_regs->dtxfsiz[i];
  60095. + DWC_PRINTF("%s[%d] @0x%08lX : 0x%08X\n", txfsiz, i + 1,
  60096. + (unsigned long)addr, DWC_READ_REG32(addr));
  60097. + }
  60098. + addr = core_if->pcgcctl;
  60099. + DWC_PRINTF("PCGCCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60100. + DWC_READ_REG32(addr));
  60101. +}
  60102. +
  60103. +/**
  60104. + * Flush a Tx FIFO.
  60105. + *
  60106. + * @param core_if Programming view of DWC_otg controller.
  60107. + * @param num Tx FIFO to flush.
  60108. + */
  60109. +void dwc_otg_flush_tx_fifo(dwc_otg_core_if_t * core_if, const int num)
  60110. +{
  60111. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  60112. + volatile grstctl_t greset = {.d32 = 0 };
  60113. + int count = 0;
  60114. +
  60115. + DWC_DEBUGPL((DBG_CIL | DBG_PCDV), "Flush Tx FIFO %d\n", num);
  60116. +
  60117. + greset.b.txfflsh = 1;
  60118. + greset.b.txfnum = num;
  60119. + DWC_WRITE_REG32(&global_regs->grstctl, greset.d32);
  60120. +
  60121. + do {
  60122. + greset.d32 = DWC_READ_REG32(&global_regs->grstctl);
  60123. + if (++count > 10000) {
  60124. + DWC_WARN("%s() HANG! GRSTCTL=%0x GNPTXSTS=0x%08x\n",
  60125. + __func__, greset.d32,
  60126. + DWC_READ_REG32(&global_regs->gnptxsts));
  60127. + break;
  60128. + }
  60129. + dwc_udelay(1);
  60130. + } while (greset.b.txfflsh == 1);
  60131. +
  60132. + /* Wait for 3 PHY Clocks */
  60133. + dwc_udelay(1);
  60134. +}
  60135. +
  60136. +/**
  60137. + * Flush Rx FIFO.
  60138. + *
  60139. + * @param core_if Programming view of DWC_otg controller.
  60140. + */
  60141. +void dwc_otg_flush_rx_fifo(dwc_otg_core_if_t * core_if)
  60142. +{
  60143. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  60144. + volatile grstctl_t greset = {.d32 = 0 };
  60145. + int count = 0;
  60146. +
  60147. + DWC_DEBUGPL((DBG_CIL | DBG_PCDV), "%s\n", __func__);
  60148. + /*
  60149. + *
  60150. + */
  60151. + greset.b.rxfflsh = 1;
  60152. + DWC_WRITE_REG32(&global_regs->grstctl, greset.d32);
  60153. +
  60154. + do {
  60155. + greset.d32 = DWC_READ_REG32(&global_regs->grstctl);
  60156. + if (++count > 10000) {
  60157. + DWC_WARN("%s() HANG! GRSTCTL=%0x\n", __func__,
  60158. + greset.d32);
  60159. + break;
  60160. + }
  60161. + dwc_udelay(1);
  60162. + } while (greset.b.rxfflsh == 1);
  60163. +
  60164. + /* Wait for 3 PHY Clocks */
  60165. + dwc_udelay(1);
  60166. +}
  60167. +
  60168. +/**
  60169. + * Do core a soft reset of the core. Be careful with this because it
  60170. + * resets all the internal state machines of the core.
  60171. + */
  60172. +void dwc_otg_core_reset(dwc_otg_core_if_t * core_if)
  60173. +{
  60174. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  60175. + volatile grstctl_t greset = {.d32 = 0 };
  60176. + int count = 0;
  60177. +
  60178. + DWC_DEBUGPL(DBG_CILV, "%s\n", __func__);
  60179. + /* Wait for AHB master IDLE state. */
  60180. + do {
  60181. + dwc_udelay(10);
  60182. + greset.d32 = DWC_READ_REG32(&global_regs->grstctl);
  60183. + if (++count > 100000) {
  60184. + DWC_WARN("%s() HANG! AHB Idle GRSTCTL=%0x\n", __func__,
  60185. + greset.d32);
  60186. + return;
  60187. + }
  60188. + }
  60189. + while (greset.b.ahbidle == 0);
  60190. +
  60191. + /* Core Soft Reset */
  60192. + count = 0;
  60193. + greset.b.csftrst = 1;
  60194. + DWC_WRITE_REG32(&global_regs->grstctl, greset.d32);
  60195. + do {
  60196. + greset.d32 = DWC_READ_REG32(&global_regs->grstctl);
  60197. + if (++count > 10000) {
  60198. + DWC_WARN("%s() HANG! Soft Reset GRSTCTL=%0x\n",
  60199. + __func__, greset.d32);
  60200. + break;
  60201. + }
  60202. + dwc_udelay(1);
  60203. + }
  60204. + while (greset.b.csftrst == 1);
  60205. +
  60206. + /* Wait for 3 PHY Clocks */
  60207. + dwc_mdelay(100);
  60208. +}
  60209. +
  60210. +uint8_t dwc_otg_is_device_mode(dwc_otg_core_if_t * _core_if)
  60211. +{
  60212. + return (dwc_otg_mode(_core_if) != DWC_HOST_MODE);
  60213. +}
  60214. +
  60215. +uint8_t dwc_otg_is_host_mode(dwc_otg_core_if_t * _core_if)
  60216. +{
  60217. + return (dwc_otg_mode(_core_if) == DWC_HOST_MODE);
  60218. +}
  60219. +
  60220. +/**
  60221. + * Register HCD callbacks. The callbacks are used to start and stop
  60222. + * the HCD for interrupt processing.
  60223. + *
  60224. + * @param core_if Programming view of DWC_otg controller.
  60225. + * @param cb the HCD callback structure.
  60226. + * @param p pointer to be passed to callback function (usb_hcd*).
  60227. + */
  60228. +void dwc_otg_cil_register_hcd_callbacks(dwc_otg_core_if_t * core_if,
  60229. + dwc_otg_cil_callbacks_t * cb, void *p)
  60230. +{
  60231. + core_if->hcd_cb = cb;
  60232. + cb->p = p;
  60233. +}
  60234. +
  60235. +/**
  60236. + * Register PCD callbacks. The callbacks are used to start and stop
  60237. + * the PCD for interrupt processing.
  60238. + *
  60239. + * @param core_if Programming view of DWC_otg controller.
  60240. + * @param cb the PCD callback structure.
  60241. + * @param p pointer to be passed to callback function (pcd*).
  60242. + */
  60243. +void dwc_otg_cil_register_pcd_callbacks(dwc_otg_core_if_t * core_if,
  60244. + dwc_otg_cil_callbacks_t * cb, void *p)
  60245. +{
  60246. + core_if->pcd_cb = cb;
  60247. + cb->p = p;
  60248. +}
  60249. +
  60250. +#ifdef DWC_EN_ISOC
  60251. +
  60252. +/**
  60253. + * This function writes isoc data per 1 (micro)frame into tx fifo
  60254. + *
  60255. + * @param core_if Programming view of DWC_otg controller.
  60256. + * @param ep The EP to start the transfer on.
  60257. + *
  60258. + */
  60259. +void write_isoc_frame_data(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  60260. +{
  60261. + dwc_otg_dev_in_ep_regs_t *ep_regs;
  60262. + dtxfsts_data_t txstatus = {.d32 = 0 };
  60263. + uint32_t len = 0;
  60264. + uint32_t dwords;
  60265. +
  60266. + ep->xfer_len = ep->data_per_frame;
  60267. + ep->xfer_count = 0;
  60268. +
  60269. + ep_regs = core_if->dev_if->in_ep_regs[ep->num];
  60270. +
  60271. + len = ep->xfer_len - ep->xfer_count;
  60272. +
  60273. + if (len > ep->maxpacket) {
  60274. + len = ep->maxpacket;
  60275. + }
  60276. +
  60277. + dwords = (len + 3) / 4;
  60278. +
  60279. + /* While there is space in the queue and space in the FIFO and
  60280. + * More data to tranfer, Write packets to the Tx FIFO */
  60281. + txstatus.d32 =
  60282. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[ep->num]->dtxfsts);
  60283. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", ep->num, txstatus.d32);
  60284. +
  60285. + while (txstatus.b.txfspcavail > dwords &&
  60286. + ep->xfer_count < ep->xfer_len && ep->xfer_len != 0) {
  60287. + /* Write the FIFO */
  60288. + dwc_otg_ep_write_packet(core_if, ep, 0);
  60289. +
  60290. + len = ep->xfer_len - ep->xfer_count;
  60291. + if (len > ep->maxpacket) {
  60292. + len = ep->maxpacket;
  60293. + }
  60294. +
  60295. + dwords = (len + 3) / 4;
  60296. + txstatus.d32 =
  60297. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  60298. + dtxfsts);
  60299. + DWC_DEBUGPL(DBG_PCDV, "dtxfsts[%d]=0x%08x\n", ep->num,
  60300. + txstatus.d32);
  60301. + }
  60302. +}
  60303. +
  60304. +/**
  60305. + * This function initializes a descriptor chain for Isochronous transfer
  60306. + *
  60307. + * @param core_if Programming view of DWC_otg controller.
  60308. + * @param ep The EP to start the transfer on.
  60309. + *
  60310. + */
  60311. +void dwc_otg_iso_ep_start_frm_transfer(dwc_otg_core_if_t * core_if,
  60312. + dwc_ep_t * ep)
  60313. +{
  60314. + deptsiz_data_t deptsiz = {.d32 = 0 };
  60315. + depctl_data_t depctl = {.d32 = 0 };
  60316. + dsts_data_t dsts = {.d32 = 0 };
  60317. + volatile uint32_t *addr;
  60318. +
  60319. + if (ep->is_in) {
  60320. + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
  60321. + } else {
  60322. + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
  60323. + }
  60324. +
  60325. + ep->xfer_len = ep->data_per_frame;
  60326. + ep->xfer_count = 0;
  60327. + ep->xfer_buff = ep->cur_pkt_addr;
  60328. + ep->dma_addr = ep->cur_pkt_dma_addr;
  60329. +
  60330. + if (ep->is_in) {
  60331. + /* Program the transfer size and packet count
  60332. + * as follows: xfersize = N * maxpacket +
  60333. + * short_packet pktcnt = N + (short_packet
  60334. + * exist ? 1 : 0)
  60335. + */
  60336. + deptsiz.b.xfersize = ep->xfer_len;
  60337. + deptsiz.b.pktcnt =
  60338. + (ep->xfer_len - 1 + ep->maxpacket) / ep->maxpacket;
  60339. + deptsiz.b.mc = deptsiz.b.pktcnt;
  60340. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->dieptsiz,
  60341. + deptsiz.d32);
  60342. +
  60343. + /* Write the DMA register */
  60344. + if (core_if->dma_enable) {
  60345. + DWC_WRITE_REG32(&
  60346. + (core_if->dev_if->in_ep_regs[ep->num]->
  60347. + diepdma), (uint32_t) ep->dma_addr);
  60348. + }
  60349. + } else {
  60350. + deptsiz.b.pktcnt =
  60351. + (ep->xfer_len + (ep->maxpacket - 1)) / ep->maxpacket;
  60352. + deptsiz.b.xfersize = deptsiz.b.pktcnt * ep->maxpacket;
  60353. +
  60354. + DWC_WRITE_REG32(&core_if->dev_if->
  60355. + out_ep_regs[ep->num]->doeptsiz, deptsiz.d32);
  60356. +
  60357. + if (core_if->dma_enable) {
  60358. + DWC_WRITE_REG32(&
  60359. + (core_if->dev_if->
  60360. + out_ep_regs[ep->num]->doepdma),
  60361. + (uint32_t) ep->dma_addr);
  60362. + }
  60363. + }
  60364. +
  60365. + /** Enable endpoint, clear nak */
  60366. +
  60367. + depctl.d32 = 0;
  60368. + if (ep->bInterval == 1) {
  60369. + dsts.d32 =
  60370. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  60371. + ep->next_frame = dsts.b.soffn + ep->bInterval;
  60372. +
  60373. + if (ep->next_frame & 0x1) {
  60374. + depctl.b.setd1pid = 1;
  60375. + } else {
  60376. + depctl.b.setd0pid = 1;
  60377. + }
  60378. + } else {
  60379. + ep->next_frame += ep->bInterval;
  60380. +
  60381. + if (ep->next_frame & 0x1) {
  60382. + depctl.b.setd1pid = 1;
  60383. + } else {
  60384. + depctl.b.setd0pid = 1;
  60385. + }
  60386. + }
  60387. + depctl.b.epena = 1;
  60388. + depctl.b.cnak = 1;
  60389. +
  60390. + DWC_MODIFY_REG32(addr, 0, depctl.d32);
  60391. + depctl.d32 = DWC_READ_REG32(addr);
  60392. +
  60393. + if (ep->is_in && core_if->dma_enable == 0) {
  60394. + write_isoc_frame_data(core_if, ep);
  60395. + }
  60396. +
  60397. +}
  60398. +#endif /* DWC_EN_ISOC */
  60399. +
  60400. +static void dwc_otg_set_uninitialized(int32_t * p, int size)
  60401. +{
  60402. + int i;
  60403. + for (i = 0; i < size; i++) {
  60404. + p[i] = -1;
  60405. + }
  60406. +}
  60407. +
  60408. +static int dwc_otg_param_initialized(int32_t val)
  60409. +{
  60410. + return val != -1;
  60411. +}
  60412. +
  60413. +static int dwc_otg_setup_params(dwc_otg_core_if_t * core_if)
  60414. +{
  60415. + int i;
  60416. + core_if->core_params = DWC_ALLOC(sizeof(*core_if->core_params));
  60417. + if (!core_if->core_params) {
  60418. + return -DWC_E_NO_MEMORY;
  60419. + }
  60420. + dwc_otg_set_uninitialized((int32_t *) core_if->core_params,
  60421. + sizeof(*core_if->core_params) /
  60422. + sizeof(int32_t));
  60423. + DWC_PRINTF("Setting default values for core params\n");
  60424. + dwc_otg_set_param_otg_cap(core_if, dwc_param_otg_cap_default);
  60425. + dwc_otg_set_param_dma_enable(core_if, dwc_param_dma_enable_default);
  60426. + dwc_otg_set_param_dma_desc_enable(core_if,
  60427. + dwc_param_dma_desc_enable_default);
  60428. + dwc_otg_set_param_opt(core_if, dwc_param_opt_default);
  60429. + dwc_otg_set_param_dma_burst_size(core_if,
  60430. + dwc_param_dma_burst_size_default);
  60431. + dwc_otg_set_param_host_support_fs_ls_low_power(core_if,
  60432. + dwc_param_host_support_fs_ls_low_power_default);
  60433. + dwc_otg_set_param_enable_dynamic_fifo(core_if,
  60434. + dwc_param_enable_dynamic_fifo_default);
  60435. + dwc_otg_set_param_data_fifo_size(core_if,
  60436. + dwc_param_data_fifo_size_default);
  60437. + dwc_otg_set_param_dev_rx_fifo_size(core_if,
  60438. + dwc_param_dev_rx_fifo_size_default);
  60439. + dwc_otg_set_param_dev_nperio_tx_fifo_size(core_if,
  60440. + dwc_param_dev_nperio_tx_fifo_size_default);
  60441. + dwc_otg_set_param_host_rx_fifo_size(core_if,
  60442. + dwc_param_host_rx_fifo_size_default);
  60443. + dwc_otg_set_param_host_nperio_tx_fifo_size(core_if,
  60444. + dwc_param_host_nperio_tx_fifo_size_default);
  60445. + dwc_otg_set_param_host_perio_tx_fifo_size(core_if,
  60446. + dwc_param_host_perio_tx_fifo_size_default);
  60447. + dwc_otg_set_param_max_transfer_size(core_if,
  60448. + dwc_param_max_transfer_size_default);
  60449. + dwc_otg_set_param_max_packet_count(core_if,
  60450. + dwc_param_max_packet_count_default);
  60451. + dwc_otg_set_param_host_channels(core_if,
  60452. + dwc_param_host_channels_default);
  60453. + dwc_otg_set_param_dev_endpoints(core_if,
  60454. + dwc_param_dev_endpoints_default);
  60455. + dwc_otg_set_param_phy_type(core_if, dwc_param_phy_type_default);
  60456. + dwc_otg_set_param_speed(core_if, dwc_param_speed_default);
  60457. + dwc_otg_set_param_host_ls_low_power_phy_clk(core_if,
  60458. + dwc_param_host_ls_low_power_phy_clk_default);
  60459. + dwc_otg_set_param_phy_ulpi_ddr(core_if, dwc_param_phy_ulpi_ddr_default);
  60460. + dwc_otg_set_param_phy_ulpi_ext_vbus(core_if,
  60461. + dwc_param_phy_ulpi_ext_vbus_default);
  60462. + dwc_otg_set_param_phy_utmi_width(core_if,
  60463. + dwc_param_phy_utmi_width_default);
  60464. + dwc_otg_set_param_ts_dline(core_if, dwc_param_ts_dline_default);
  60465. + dwc_otg_set_param_i2c_enable(core_if, dwc_param_i2c_enable_default);
  60466. + dwc_otg_set_param_ulpi_fs_ls(core_if, dwc_param_ulpi_fs_ls_default);
  60467. + dwc_otg_set_param_en_multiple_tx_fifo(core_if,
  60468. + dwc_param_en_multiple_tx_fifo_default);
  60469. + for (i = 0; i < 15; i++) {
  60470. + dwc_otg_set_param_dev_perio_tx_fifo_size(core_if,
  60471. + dwc_param_dev_perio_tx_fifo_size_default,
  60472. + i);
  60473. + }
  60474. +
  60475. + for (i = 0; i < 15; i++) {
  60476. + dwc_otg_set_param_dev_tx_fifo_size(core_if,
  60477. + dwc_param_dev_tx_fifo_size_default,
  60478. + i);
  60479. + }
  60480. + dwc_otg_set_param_thr_ctl(core_if, dwc_param_thr_ctl_default);
  60481. + dwc_otg_set_param_mpi_enable(core_if, dwc_param_mpi_enable_default);
  60482. + dwc_otg_set_param_pti_enable(core_if, dwc_param_pti_enable_default);
  60483. + dwc_otg_set_param_lpm_enable(core_if, dwc_param_lpm_enable_default);
  60484. + dwc_otg_set_param_ic_usb_cap(core_if, dwc_param_ic_usb_cap_default);
  60485. + dwc_otg_set_param_tx_thr_length(core_if,
  60486. + dwc_param_tx_thr_length_default);
  60487. + dwc_otg_set_param_rx_thr_length(core_if,
  60488. + dwc_param_rx_thr_length_default);
  60489. + dwc_otg_set_param_ahb_thr_ratio(core_if,
  60490. + dwc_param_ahb_thr_ratio_default);
  60491. + dwc_otg_set_param_power_down(core_if, dwc_param_power_down_default);
  60492. + dwc_otg_set_param_reload_ctl(core_if, dwc_param_reload_ctl_default);
  60493. + dwc_otg_set_param_dev_out_nak(core_if, dwc_param_dev_out_nak_default);
  60494. + dwc_otg_set_param_cont_on_bna(core_if, dwc_param_cont_on_bna_default);
  60495. + dwc_otg_set_param_ahb_single(core_if, dwc_param_ahb_single_default);
  60496. + dwc_otg_set_param_otg_ver(core_if, dwc_param_otg_ver_default);
  60497. + dwc_otg_set_param_adp_enable(core_if, dwc_param_adp_enable_default);
  60498. + DWC_PRINTF("Finished setting default values for core params\n");
  60499. +
  60500. + return 0;
  60501. +}
  60502. +
  60503. +uint8_t dwc_otg_is_dma_enable(dwc_otg_core_if_t * core_if)
  60504. +{
  60505. + return core_if->dma_enable;
  60506. +}
  60507. +
  60508. +/* Checks if the parameter is outside of its valid range of values */
  60509. +#define DWC_OTG_PARAM_TEST(_param_, _low_, _high_) \
  60510. + (((_param_) < (_low_)) || \
  60511. + ((_param_) > (_high_)))
  60512. +
  60513. +/* Parameter access functions */
  60514. +int dwc_otg_set_param_otg_cap(dwc_otg_core_if_t * core_if, int32_t val)
  60515. +{
  60516. + int valid;
  60517. + int retval = 0;
  60518. + if (DWC_OTG_PARAM_TEST(val, 0, 2)) {
  60519. + DWC_WARN("Wrong value for otg_cap parameter\n");
  60520. + DWC_WARN("otg_cap parameter must be 0,1 or 2\n");
  60521. + retval = -DWC_E_INVALID;
  60522. + goto out;
  60523. + }
  60524. +
  60525. + valid = 1;
  60526. + switch (val) {
  60527. + case DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE:
  60528. + if (core_if->hwcfg2.b.op_mode !=
  60529. + DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG)
  60530. + valid = 0;
  60531. + break;
  60532. + case DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE:
  60533. + if ((core_if->hwcfg2.b.op_mode !=
  60534. + DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG)
  60535. + && (core_if->hwcfg2.b.op_mode !=
  60536. + DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG)
  60537. + && (core_if->hwcfg2.b.op_mode !=
  60538. + DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE)
  60539. + && (core_if->hwcfg2.b.op_mode !=
  60540. + DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST)) {
  60541. + valid = 0;
  60542. + }
  60543. + break;
  60544. + case DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE:
  60545. + /* always valid */
  60546. + break;
  60547. + }
  60548. + if (!valid) {
  60549. + if (dwc_otg_param_initialized(core_if->core_params->otg_cap)) {
  60550. + DWC_ERROR
  60551. + ("%d invalid for otg_cap paremter. Check HW configuration.\n",
  60552. + val);
  60553. + }
  60554. + val =
  60555. + (((core_if->hwcfg2.b.op_mode ==
  60556. + DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG)
  60557. + || (core_if->hwcfg2.b.op_mode ==
  60558. + DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG)
  60559. + || (core_if->hwcfg2.b.op_mode ==
  60560. + DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE)
  60561. + || (core_if->hwcfg2.b.op_mode ==
  60562. + DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST)) ?
  60563. + DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE :
  60564. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  60565. + retval = -DWC_E_INVALID;
  60566. + }
  60567. +
  60568. + core_if->core_params->otg_cap = val;
  60569. +out:
  60570. + return retval;
  60571. +}
  60572. +
  60573. +int32_t dwc_otg_get_param_otg_cap(dwc_otg_core_if_t * core_if)
  60574. +{
  60575. + return core_if->core_params->otg_cap;
  60576. +}
  60577. +
  60578. +int dwc_otg_set_param_opt(dwc_otg_core_if_t * core_if, int32_t val)
  60579. +{
  60580. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  60581. + DWC_WARN("Wrong value for opt parameter\n");
  60582. + return -DWC_E_INVALID;
  60583. + }
  60584. + core_if->core_params->opt = val;
  60585. + return 0;
  60586. +}
  60587. +
  60588. +int32_t dwc_otg_get_param_opt(dwc_otg_core_if_t * core_if)
  60589. +{
  60590. + return core_if->core_params->opt;
  60591. +}
  60592. +
  60593. +int dwc_otg_set_param_dma_enable(dwc_otg_core_if_t * core_if, int32_t val)
  60594. +{
  60595. + int retval = 0;
  60596. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  60597. + DWC_WARN("Wrong value for dma enable\n");
  60598. + return -DWC_E_INVALID;
  60599. + }
  60600. +
  60601. + if ((val == 1) && (core_if->hwcfg2.b.architecture == 0)) {
  60602. + if (dwc_otg_param_initialized(core_if->core_params->dma_enable)) {
  60603. + DWC_ERROR
  60604. + ("%d invalid for dma_enable paremter. Check HW configuration.\n",
  60605. + val);
  60606. + }
  60607. + val = 0;
  60608. + retval = -DWC_E_INVALID;
  60609. + }
  60610. +
  60611. + core_if->core_params->dma_enable = val;
  60612. + if (val == 0) {
  60613. + dwc_otg_set_param_dma_desc_enable(core_if, 0);
  60614. + }
  60615. + return retval;
  60616. +}
  60617. +
  60618. +int32_t dwc_otg_get_param_dma_enable(dwc_otg_core_if_t * core_if)
  60619. +{
  60620. + return core_if->core_params->dma_enable;
  60621. +}
  60622. +
  60623. +int dwc_otg_set_param_dma_desc_enable(dwc_otg_core_if_t * core_if, int32_t val)
  60624. +{
  60625. + int retval = 0;
  60626. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  60627. + DWC_WARN("Wrong value for dma_enable\n");
  60628. + DWC_WARN("dma_desc_enable must be 0 or 1\n");
  60629. + return -DWC_E_INVALID;
  60630. + }
  60631. +
  60632. + if ((val == 1)
  60633. + && ((dwc_otg_get_param_dma_enable(core_if) == 0)
  60634. + || (core_if->hwcfg4.b.desc_dma == 0))) {
  60635. + if (dwc_otg_param_initialized
  60636. + (core_if->core_params->dma_desc_enable)) {
  60637. + DWC_ERROR
  60638. + ("%d invalid for dma_desc_enable paremter. Check HW configuration.\n",
  60639. + val);
  60640. + }
  60641. + val = 0;
  60642. + retval = -DWC_E_INVALID;
  60643. + }
  60644. + core_if->core_params->dma_desc_enable = val;
  60645. + return retval;
  60646. +}
  60647. +
  60648. +int32_t dwc_otg_get_param_dma_desc_enable(dwc_otg_core_if_t * core_if)
  60649. +{
  60650. + return core_if->core_params->dma_desc_enable;
  60651. +}
  60652. +
  60653. +int dwc_otg_set_param_host_support_fs_ls_low_power(dwc_otg_core_if_t * core_if,
  60654. + int32_t val)
  60655. +{
  60656. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  60657. + DWC_WARN("Wrong value for host_support_fs_low_power\n");
  60658. + DWC_WARN("host_support_fs_low_power must be 0 or 1\n");
  60659. + return -DWC_E_INVALID;
  60660. + }
  60661. + core_if->core_params->host_support_fs_ls_low_power = val;
  60662. + return 0;
  60663. +}
  60664. +
  60665. +int32_t dwc_otg_get_param_host_support_fs_ls_low_power(dwc_otg_core_if_t *
  60666. + core_if)
  60667. +{
  60668. + return core_if->core_params->host_support_fs_ls_low_power;
  60669. +}
  60670. +
  60671. +int dwc_otg_set_param_enable_dynamic_fifo(dwc_otg_core_if_t * core_if,
  60672. + int32_t val)
  60673. +{
  60674. + int retval = 0;
  60675. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  60676. + DWC_WARN("Wrong value for enable_dynamic_fifo\n");
  60677. + DWC_WARN("enable_dynamic_fifo must be 0 or 1\n");
  60678. + return -DWC_E_INVALID;
  60679. + }
  60680. +
  60681. + if ((val == 1) && (core_if->hwcfg2.b.dynamic_fifo == 0)) {
  60682. + if (dwc_otg_param_initialized
  60683. + (core_if->core_params->enable_dynamic_fifo)) {
  60684. + DWC_ERROR
  60685. + ("%d invalid for enable_dynamic_fifo paremter. Check HW configuration.\n",
  60686. + val);
  60687. + }
  60688. + val = 0;
  60689. + retval = -DWC_E_INVALID;
  60690. + }
  60691. + core_if->core_params->enable_dynamic_fifo = val;
  60692. + return retval;
  60693. +}
  60694. +
  60695. +int32_t dwc_otg_get_param_enable_dynamic_fifo(dwc_otg_core_if_t * core_if)
  60696. +{
  60697. + return core_if->core_params->enable_dynamic_fifo;
  60698. +}
  60699. +
  60700. +int dwc_otg_set_param_data_fifo_size(dwc_otg_core_if_t * core_if, int32_t val)
  60701. +{
  60702. + int retval = 0;
  60703. + if (DWC_OTG_PARAM_TEST(val, 32, 32768)) {
  60704. + DWC_WARN("Wrong value for data_fifo_size\n");
  60705. + DWC_WARN("data_fifo_size must be 32-32768\n");
  60706. + return -DWC_E_INVALID;
  60707. + }
  60708. +
  60709. + if (val > core_if->hwcfg3.b.dfifo_depth) {
  60710. + if (dwc_otg_param_initialized
  60711. + (core_if->core_params->data_fifo_size)) {
  60712. + DWC_ERROR
  60713. + ("%d invalid for data_fifo_size parameter. Check HW configuration.\n",
  60714. + val);
  60715. + }
  60716. + val = core_if->hwcfg3.b.dfifo_depth;
  60717. + retval = -DWC_E_INVALID;
  60718. + }
  60719. +
  60720. + core_if->core_params->data_fifo_size = val;
  60721. + return retval;
  60722. +}
  60723. +
  60724. +int32_t dwc_otg_get_param_data_fifo_size(dwc_otg_core_if_t * core_if)
  60725. +{
  60726. + return core_if->core_params->data_fifo_size;
  60727. +}
  60728. +
  60729. +int dwc_otg_set_param_dev_rx_fifo_size(dwc_otg_core_if_t * core_if, int32_t val)
  60730. +{
  60731. + int retval = 0;
  60732. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  60733. + DWC_WARN("Wrong value for dev_rx_fifo_size\n");
  60734. + DWC_WARN("dev_rx_fifo_size must be 16-32768\n");
  60735. + return -DWC_E_INVALID;
  60736. + }
  60737. +
  60738. + if (val > DWC_READ_REG32(&core_if->core_global_regs->grxfsiz)) {
  60739. + if (dwc_otg_param_initialized(core_if->core_params->dev_rx_fifo_size)) {
  60740. + DWC_WARN("%d invalid for dev_rx_fifo_size parameter\n", val);
  60741. + }
  60742. + val = DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  60743. + retval = -DWC_E_INVALID;
  60744. + }
  60745. +
  60746. + core_if->core_params->dev_rx_fifo_size = val;
  60747. + return retval;
  60748. +}
  60749. +
  60750. +int32_t dwc_otg_get_param_dev_rx_fifo_size(dwc_otg_core_if_t * core_if)
  60751. +{
  60752. + return core_if->core_params->dev_rx_fifo_size;
  60753. +}
  60754. +
  60755. +int dwc_otg_set_param_dev_nperio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  60756. + int32_t val)
  60757. +{
  60758. + int retval = 0;
  60759. +
  60760. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  60761. + DWC_WARN("Wrong value for dev_nperio_tx_fifo\n");
  60762. + DWC_WARN("dev_nperio_tx_fifo must be 16-32768\n");
  60763. + return -DWC_E_INVALID;
  60764. + }
  60765. +
  60766. + if (val > (DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz) >> 16)) {
  60767. + if (dwc_otg_param_initialized
  60768. + (core_if->core_params->dev_nperio_tx_fifo_size)) {
  60769. + DWC_ERROR
  60770. + ("%d invalid for dev_nperio_tx_fifo_size. Check HW configuration.\n",
  60771. + val);
  60772. + }
  60773. + val =
  60774. + (DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz) >>
  60775. + 16);
  60776. + retval = -DWC_E_INVALID;
  60777. + }
  60778. +
  60779. + core_if->core_params->dev_nperio_tx_fifo_size = val;
  60780. + return retval;
  60781. +}
  60782. +
  60783. +int32_t dwc_otg_get_param_dev_nperio_tx_fifo_size(dwc_otg_core_if_t * core_if)
  60784. +{
  60785. + return core_if->core_params->dev_nperio_tx_fifo_size;
  60786. +}
  60787. +
  60788. +int dwc_otg_set_param_host_rx_fifo_size(dwc_otg_core_if_t * core_if,
  60789. + int32_t val)
  60790. +{
  60791. + int retval = 0;
  60792. +
  60793. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  60794. + DWC_WARN("Wrong value for host_rx_fifo_size\n");
  60795. + DWC_WARN("host_rx_fifo_size must be 16-32768\n");
  60796. + return -DWC_E_INVALID;
  60797. + }
  60798. +
  60799. + if (val > DWC_READ_REG32(&core_if->core_global_regs->grxfsiz)) {
  60800. + if (dwc_otg_param_initialized
  60801. + (core_if->core_params->host_rx_fifo_size)) {
  60802. + DWC_ERROR
  60803. + ("%d invalid for host_rx_fifo_size. Check HW configuration.\n",
  60804. + val);
  60805. + }
  60806. + val = DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  60807. + retval = -DWC_E_INVALID;
  60808. + }
  60809. +
  60810. + core_if->core_params->host_rx_fifo_size = val;
  60811. + return retval;
  60812. +
  60813. +}
  60814. +
  60815. +int32_t dwc_otg_get_param_host_rx_fifo_size(dwc_otg_core_if_t * core_if)
  60816. +{
  60817. + return core_if->core_params->host_rx_fifo_size;
  60818. +}
  60819. +
  60820. +int dwc_otg_set_param_host_nperio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  60821. + int32_t val)
  60822. +{
  60823. + int retval = 0;
  60824. +
  60825. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  60826. + DWC_WARN("Wrong value for host_nperio_tx_fifo_size\n");
  60827. + DWC_WARN("host_nperio_tx_fifo_size must be 16-32768\n");
  60828. + return -DWC_E_INVALID;
  60829. + }
  60830. +
  60831. + if (val > (DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz) >> 16)) {
  60832. + if (dwc_otg_param_initialized
  60833. + (core_if->core_params->host_nperio_tx_fifo_size)) {
  60834. + DWC_ERROR
  60835. + ("%d invalid for host_nperio_tx_fifo_size. Check HW configuration.\n",
  60836. + val);
  60837. + }
  60838. + val =
  60839. + (DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz) >>
  60840. + 16);
  60841. + retval = -DWC_E_INVALID;
  60842. + }
  60843. +
  60844. + core_if->core_params->host_nperio_tx_fifo_size = val;
  60845. + return retval;
  60846. +}
  60847. +
  60848. +int32_t dwc_otg_get_param_host_nperio_tx_fifo_size(dwc_otg_core_if_t * core_if)
  60849. +{
  60850. + return core_if->core_params->host_nperio_tx_fifo_size;
  60851. +}
  60852. +
  60853. +int dwc_otg_set_param_host_perio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  60854. + int32_t val)
  60855. +{
  60856. + int retval = 0;
  60857. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  60858. + DWC_WARN("Wrong value for host_perio_tx_fifo_size\n");
  60859. + DWC_WARN("host_perio_tx_fifo_size must be 16-32768\n");
  60860. + return -DWC_E_INVALID;
  60861. + }
  60862. +
  60863. + if (val > ((core_if->hptxfsiz.d32) >> 16)) {
  60864. + if (dwc_otg_param_initialized
  60865. + (core_if->core_params->host_perio_tx_fifo_size)) {
  60866. + DWC_ERROR
  60867. + ("%d invalid for host_perio_tx_fifo_size. Check HW configuration.\n",
  60868. + val);
  60869. + }
  60870. + val = (core_if->hptxfsiz.d32) >> 16;
  60871. + retval = -DWC_E_INVALID;
  60872. + }
  60873. +
  60874. + core_if->core_params->host_perio_tx_fifo_size = val;
  60875. + return retval;
  60876. +}
  60877. +
  60878. +int32_t dwc_otg_get_param_host_perio_tx_fifo_size(dwc_otg_core_if_t * core_if)
  60879. +{
  60880. + return core_if->core_params->host_perio_tx_fifo_size;
  60881. +}
  60882. +
  60883. +int dwc_otg_set_param_max_transfer_size(dwc_otg_core_if_t * core_if,
  60884. + int32_t val)
  60885. +{
  60886. + int retval = 0;
  60887. +
  60888. + if (DWC_OTG_PARAM_TEST(val, 2047, 524288)) {
  60889. + DWC_WARN("Wrong value for max_transfer_size\n");
  60890. + DWC_WARN("max_transfer_size must be 2047-524288\n");
  60891. + return -DWC_E_INVALID;
  60892. + }
  60893. +
  60894. + if (val >= (1 << (core_if->hwcfg3.b.xfer_size_cntr_width + 11))) {
  60895. + if (dwc_otg_param_initialized
  60896. + (core_if->core_params->max_transfer_size)) {
  60897. + DWC_ERROR
  60898. + ("%d invalid for max_transfer_size. Check HW configuration.\n",
  60899. + val);
  60900. + }
  60901. + val =
  60902. + ((1 << (core_if->hwcfg3.b.packet_size_cntr_width + 11)) -
  60903. + 1);
  60904. + retval = -DWC_E_INVALID;
  60905. + }
  60906. +
  60907. + core_if->core_params->max_transfer_size = val;
  60908. + return retval;
  60909. +}
  60910. +
  60911. +int32_t dwc_otg_get_param_max_transfer_size(dwc_otg_core_if_t * core_if)
  60912. +{
  60913. + return core_if->core_params->max_transfer_size;
  60914. +}
  60915. +
  60916. +int dwc_otg_set_param_max_packet_count(dwc_otg_core_if_t * core_if, int32_t val)
  60917. +{
  60918. + int retval = 0;
  60919. +
  60920. + if (DWC_OTG_PARAM_TEST(val, 15, 511)) {
  60921. + DWC_WARN("Wrong value for max_packet_count\n");
  60922. + DWC_WARN("max_packet_count must be 15-511\n");
  60923. + return -DWC_E_INVALID;
  60924. + }
  60925. +
  60926. + if (val > (1 << (core_if->hwcfg3.b.packet_size_cntr_width + 4))) {
  60927. + if (dwc_otg_param_initialized
  60928. + (core_if->core_params->max_packet_count)) {
  60929. + DWC_ERROR
  60930. + ("%d invalid for max_packet_count. Check HW configuration.\n",
  60931. + val);
  60932. + }
  60933. + val =
  60934. + ((1 << (core_if->hwcfg3.b.packet_size_cntr_width + 4)) - 1);
  60935. + retval = -DWC_E_INVALID;
  60936. + }
  60937. +
  60938. + core_if->core_params->max_packet_count = val;
  60939. + return retval;
  60940. +}
  60941. +
  60942. +int32_t dwc_otg_get_param_max_packet_count(dwc_otg_core_if_t * core_if)
  60943. +{
  60944. + return core_if->core_params->max_packet_count;
  60945. +}
  60946. +
  60947. +int dwc_otg_set_param_host_channels(dwc_otg_core_if_t * core_if, int32_t val)
  60948. +{
  60949. + int retval = 0;
  60950. +
  60951. + if (DWC_OTG_PARAM_TEST(val, 1, 16)) {
  60952. + DWC_WARN("Wrong value for host_channels\n");
  60953. + DWC_WARN("host_channels must be 1-16\n");
  60954. + return -DWC_E_INVALID;
  60955. + }
  60956. +
  60957. + if (val > (core_if->hwcfg2.b.num_host_chan + 1)) {
  60958. + if (dwc_otg_param_initialized
  60959. + (core_if->core_params->host_channels)) {
  60960. + DWC_ERROR
  60961. + ("%d invalid for host_channels. Check HW configurations.\n",
  60962. + val);
  60963. + }
  60964. + val = (core_if->hwcfg2.b.num_host_chan + 1);
  60965. + retval = -DWC_E_INVALID;
  60966. + }
  60967. +
  60968. + core_if->core_params->host_channels = val;
  60969. + return retval;
  60970. +}
  60971. +
  60972. +int32_t dwc_otg_get_param_host_channels(dwc_otg_core_if_t * core_if)
  60973. +{
  60974. + return core_if->core_params->host_channels;
  60975. +}
  60976. +
  60977. +int dwc_otg_set_param_dev_endpoints(dwc_otg_core_if_t * core_if, int32_t val)
  60978. +{
  60979. + int retval = 0;
  60980. +
  60981. + if (DWC_OTG_PARAM_TEST(val, 1, 15)) {
  60982. + DWC_WARN("Wrong value for dev_endpoints\n");
  60983. + DWC_WARN("dev_endpoints must be 1-15\n");
  60984. + return -DWC_E_INVALID;
  60985. + }
  60986. +
  60987. + if (val > (core_if->hwcfg2.b.num_dev_ep)) {
  60988. + if (dwc_otg_param_initialized
  60989. + (core_if->core_params->dev_endpoints)) {
  60990. + DWC_ERROR
  60991. + ("%d invalid for dev_endpoints. Check HW configurations.\n",
  60992. + val);
  60993. + }
  60994. + val = core_if->hwcfg2.b.num_dev_ep;
  60995. + retval = -DWC_E_INVALID;
  60996. + }
  60997. +
  60998. + core_if->core_params->dev_endpoints = val;
  60999. + return retval;
  61000. +}
  61001. +
  61002. +int32_t dwc_otg_get_param_dev_endpoints(dwc_otg_core_if_t * core_if)
  61003. +{
  61004. + return core_if->core_params->dev_endpoints;
  61005. +}
  61006. +
  61007. +int dwc_otg_set_param_phy_type(dwc_otg_core_if_t * core_if, int32_t val)
  61008. +{
  61009. + int retval = 0;
  61010. + int valid = 0;
  61011. +
  61012. + if (DWC_OTG_PARAM_TEST(val, 0, 2)) {
  61013. + DWC_WARN("Wrong value for phy_type\n");
  61014. + DWC_WARN("phy_type must be 0,1 or 2\n");
  61015. + return -DWC_E_INVALID;
  61016. + }
  61017. +#ifndef NO_FS_PHY_HW_CHECKS
  61018. + if ((val == DWC_PHY_TYPE_PARAM_UTMI) &&
  61019. + ((core_if->hwcfg2.b.hs_phy_type == 1) ||
  61020. + (core_if->hwcfg2.b.hs_phy_type == 3))) {
  61021. + valid = 1;
  61022. + } else if ((val == DWC_PHY_TYPE_PARAM_ULPI) &&
  61023. + ((core_if->hwcfg2.b.hs_phy_type == 2) ||
  61024. + (core_if->hwcfg2.b.hs_phy_type == 3))) {
  61025. + valid = 1;
  61026. + } else if ((val == DWC_PHY_TYPE_PARAM_FS) &&
  61027. + (core_if->hwcfg2.b.fs_phy_type == 1)) {
  61028. + valid = 1;
  61029. + }
  61030. + if (!valid) {
  61031. + if (dwc_otg_param_initialized(core_if->core_params->phy_type)) {
  61032. + DWC_ERROR
  61033. + ("%d invalid for phy_type. Check HW configurations.\n",
  61034. + val);
  61035. + }
  61036. + if (core_if->hwcfg2.b.hs_phy_type) {
  61037. + if ((core_if->hwcfg2.b.hs_phy_type == 3) ||
  61038. + (core_if->hwcfg2.b.hs_phy_type == 1)) {
  61039. + val = DWC_PHY_TYPE_PARAM_UTMI;
  61040. + } else {
  61041. + val = DWC_PHY_TYPE_PARAM_ULPI;
  61042. + }
  61043. + }
  61044. + retval = -DWC_E_INVALID;
  61045. + }
  61046. +#endif
  61047. + core_if->core_params->phy_type = val;
  61048. + return retval;
  61049. +}
  61050. +
  61051. +int32_t dwc_otg_get_param_phy_type(dwc_otg_core_if_t * core_if)
  61052. +{
  61053. + return core_if->core_params->phy_type;
  61054. +}
  61055. +
  61056. +int dwc_otg_set_param_speed(dwc_otg_core_if_t * core_if, int32_t val)
  61057. +{
  61058. + int retval = 0;
  61059. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61060. + DWC_WARN("Wrong value for speed parameter\n");
  61061. + DWC_WARN("max_speed parameter must be 0 or 1\n");
  61062. + return -DWC_E_INVALID;
  61063. + }
  61064. + if ((val == 0)
  61065. + && dwc_otg_get_param_phy_type(core_if) == DWC_PHY_TYPE_PARAM_FS) {
  61066. + if (dwc_otg_param_initialized(core_if->core_params->speed)) {
  61067. + DWC_ERROR
  61068. + ("%d invalid for speed paremter. Check HW configuration.\n",
  61069. + val);
  61070. + }
  61071. + val =
  61072. + (dwc_otg_get_param_phy_type(core_if) ==
  61073. + DWC_PHY_TYPE_PARAM_FS ? 1 : 0);
  61074. + retval = -DWC_E_INVALID;
  61075. + }
  61076. + core_if->core_params->speed = val;
  61077. + return retval;
  61078. +}
  61079. +
  61080. +int32_t dwc_otg_get_param_speed(dwc_otg_core_if_t * core_if)
  61081. +{
  61082. + return core_if->core_params->speed;
  61083. +}
  61084. +
  61085. +int dwc_otg_set_param_host_ls_low_power_phy_clk(dwc_otg_core_if_t * core_if,
  61086. + int32_t val)
  61087. +{
  61088. + int retval = 0;
  61089. +
  61090. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61091. + DWC_WARN
  61092. + ("Wrong value for host_ls_low_power_phy_clk parameter\n");
  61093. + DWC_WARN("host_ls_low_power_phy_clk must be 0 or 1\n");
  61094. + return -DWC_E_INVALID;
  61095. + }
  61096. +
  61097. + if ((val == DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ)
  61098. + && (dwc_otg_get_param_phy_type(core_if) == DWC_PHY_TYPE_PARAM_FS)) {
  61099. + if (dwc_otg_param_initialized
  61100. + (core_if->core_params->host_ls_low_power_phy_clk)) {
  61101. + DWC_ERROR
  61102. + ("%d invalid for host_ls_low_power_phy_clk. Check HW configuration.\n",
  61103. + val);
  61104. + }
  61105. + val =
  61106. + (dwc_otg_get_param_phy_type(core_if) ==
  61107. + DWC_PHY_TYPE_PARAM_FS) ?
  61108. + DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ :
  61109. + DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ;
  61110. + retval = -DWC_E_INVALID;
  61111. + }
  61112. +
  61113. + core_if->core_params->host_ls_low_power_phy_clk = val;
  61114. + return retval;
  61115. +}
  61116. +
  61117. +int32_t dwc_otg_get_param_host_ls_low_power_phy_clk(dwc_otg_core_if_t * core_if)
  61118. +{
  61119. + return core_if->core_params->host_ls_low_power_phy_clk;
  61120. +}
  61121. +
  61122. +int dwc_otg_set_param_phy_ulpi_ddr(dwc_otg_core_if_t * core_if, int32_t val)
  61123. +{
  61124. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61125. + DWC_WARN("Wrong value for phy_ulpi_ddr\n");
  61126. + DWC_WARN("phy_upli_ddr must be 0 or 1\n");
  61127. + return -DWC_E_INVALID;
  61128. + }
  61129. +
  61130. + core_if->core_params->phy_ulpi_ddr = val;
  61131. + return 0;
  61132. +}
  61133. +
  61134. +int32_t dwc_otg_get_param_phy_ulpi_ddr(dwc_otg_core_if_t * core_if)
  61135. +{
  61136. + return core_if->core_params->phy_ulpi_ddr;
  61137. +}
  61138. +
  61139. +int dwc_otg_set_param_phy_ulpi_ext_vbus(dwc_otg_core_if_t * core_if,
  61140. + int32_t val)
  61141. +{
  61142. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61143. + DWC_WARN("Wrong valaue for phy_ulpi_ext_vbus\n");
  61144. + DWC_WARN("phy_ulpi_ext_vbus must be 0 or 1\n");
  61145. + return -DWC_E_INVALID;
  61146. + }
  61147. +
  61148. + core_if->core_params->phy_ulpi_ext_vbus = val;
  61149. + return 0;
  61150. +}
  61151. +
  61152. +int32_t dwc_otg_get_param_phy_ulpi_ext_vbus(dwc_otg_core_if_t * core_if)
  61153. +{
  61154. + return core_if->core_params->phy_ulpi_ext_vbus;
  61155. +}
  61156. +
  61157. +int dwc_otg_set_param_phy_utmi_width(dwc_otg_core_if_t * core_if, int32_t val)
  61158. +{
  61159. + if (DWC_OTG_PARAM_TEST(val, 8, 8) && DWC_OTG_PARAM_TEST(val, 16, 16)) {
  61160. + DWC_WARN("Wrong valaue for phy_utmi_width\n");
  61161. + DWC_WARN("phy_utmi_width must be 8 or 16\n");
  61162. + return -DWC_E_INVALID;
  61163. + }
  61164. +
  61165. + core_if->core_params->phy_utmi_width = val;
  61166. + return 0;
  61167. +}
  61168. +
  61169. +int32_t dwc_otg_get_param_phy_utmi_width(dwc_otg_core_if_t * core_if)
  61170. +{
  61171. + return core_if->core_params->phy_utmi_width;
  61172. +}
  61173. +
  61174. +int dwc_otg_set_param_ulpi_fs_ls(dwc_otg_core_if_t * core_if, int32_t val)
  61175. +{
  61176. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61177. + DWC_WARN("Wrong valaue for ulpi_fs_ls\n");
  61178. + DWC_WARN("ulpi_fs_ls must be 0 or 1\n");
  61179. + return -DWC_E_INVALID;
  61180. + }
  61181. +
  61182. + core_if->core_params->ulpi_fs_ls = val;
  61183. + return 0;
  61184. +}
  61185. +
  61186. +int32_t dwc_otg_get_param_ulpi_fs_ls(dwc_otg_core_if_t * core_if)
  61187. +{
  61188. + return core_if->core_params->ulpi_fs_ls;
  61189. +}
  61190. +
  61191. +int dwc_otg_set_param_ts_dline(dwc_otg_core_if_t * core_if, int32_t val)
  61192. +{
  61193. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61194. + DWC_WARN("Wrong valaue for ts_dline\n");
  61195. + DWC_WARN("ts_dline must be 0 or 1\n");
  61196. + return -DWC_E_INVALID;
  61197. + }
  61198. +
  61199. + core_if->core_params->ts_dline = val;
  61200. + return 0;
  61201. +}
  61202. +
  61203. +int32_t dwc_otg_get_param_ts_dline(dwc_otg_core_if_t * core_if)
  61204. +{
  61205. + return core_if->core_params->ts_dline;
  61206. +}
  61207. +
  61208. +int dwc_otg_set_param_i2c_enable(dwc_otg_core_if_t * core_if, int32_t val)
  61209. +{
  61210. + int retval = 0;
  61211. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61212. + DWC_WARN("Wrong valaue for i2c_enable\n");
  61213. + DWC_WARN("i2c_enable must be 0 or 1\n");
  61214. + return -DWC_E_INVALID;
  61215. + }
  61216. +#ifndef NO_FS_PHY_HW_CHECK
  61217. + if (val == 1 && core_if->hwcfg3.b.i2c == 0) {
  61218. + if (dwc_otg_param_initialized(core_if->core_params->i2c_enable)) {
  61219. + DWC_ERROR
  61220. + ("%d invalid for i2c_enable. Check HW configuration.\n",
  61221. + val);
  61222. + }
  61223. + val = 0;
  61224. + retval = -DWC_E_INVALID;
  61225. + }
  61226. +#endif
  61227. +
  61228. + core_if->core_params->i2c_enable = val;
  61229. + return retval;
  61230. +}
  61231. +
  61232. +int32_t dwc_otg_get_param_i2c_enable(dwc_otg_core_if_t * core_if)
  61233. +{
  61234. + return core_if->core_params->i2c_enable;
  61235. +}
  61236. +
  61237. +int dwc_otg_set_param_dev_perio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  61238. + int32_t val, int fifo_num)
  61239. +{
  61240. + int retval = 0;
  61241. +
  61242. + if (DWC_OTG_PARAM_TEST(val, 4, 768)) {
  61243. + DWC_WARN("Wrong value for dev_perio_tx_fifo_size\n");
  61244. + DWC_WARN("dev_perio_tx_fifo_size must be 4-768\n");
  61245. + return -DWC_E_INVALID;
  61246. + }
  61247. +
  61248. + if (val >
  61249. + (DWC_READ_REG32(&core_if->core_global_regs->dtxfsiz[fifo_num]))) {
  61250. + if (dwc_otg_param_initialized
  61251. + (core_if->core_params->dev_perio_tx_fifo_size[fifo_num])) {
  61252. + DWC_ERROR
  61253. + ("`%d' invalid for parameter `dev_perio_fifo_size_%d'. Check HW configuration.\n",
  61254. + val, fifo_num);
  61255. + }
  61256. + val = (DWC_READ_REG32(&core_if->core_global_regs->dtxfsiz[fifo_num]));
  61257. + retval = -DWC_E_INVALID;
  61258. + }
  61259. +
  61260. + core_if->core_params->dev_perio_tx_fifo_size[fifo_num] = val;
  61261. + return retval;
  61262. +}
  61263. +
  61264. +int32_t dwc_otg_get_param_dev_perio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  61265. + int fifo_num)
  61266. +{
  61267. + return core_if->core_params->dev_perio_tx_fifo_size[fifo_num];
  61268. +}
  61269. +
  61270. +int dwc_otg_set_param_en_multiple_tx_fifo(dwc_otg_core_if_t * core_if,
  61271. + int32_t val)
  61272. +{
  61273. + int retval = 0;
  61274. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61275. + DWC_WARN("Wrong valaue for en_multiple_tx_fifo,\n");
  61276. + DWC_WARN("en_multiple_tx_fifo must be 0 or 1\n");
  61277. + return -DWC_E_INVALID;
  61278. + }
  61279. +
  61280. + if (val == 1 && core_if->hwcfg4.b.ded_fifo_en == 0) {
  61281. + if (dwc_otg_param_initialized
  61282. + (core_if->core_params->en_multiple_tx_fifo)) {
  61283. + DWC_ERROR
  61284. + ("%d invalid for parameter en_multiple_tx_fifo. Check HW configuration.\n",
  61285. + val);
  61286. + }
  61287. + val = 0;
  61288. + retval = -DWC_E_INVALID;
  61289. + }
  61290. +
  61291. + core_if->core_params->en_multiple_tx_fifo = val;
  61292. + return retval;
  61293. +}
  61294. +
  61295. +int32_t dwc_otg_get_param_en_multiple_tx_fifo(dwc_otg_core_if_t * core_if)
  61296. +{
  61297. + return core_if->core_params->en_multiple_tx_fifo;
  61298. +}
  61299. +
  61300. +int dwc_otg_set_param_dev_tx_fifo_size(dwc_otg_core_if_t * core_if, int32_t val,
  61301. + int fifo_num)
  61302. +{
  61303. + int retval = 0;
  61304. +
  61305. + if (DWC_OTG_PARAM_TEST(val, 4, 768)) {
  61306. + DWC_WARN("Wrong value for dev_tx_fifo_size\n");
  61307. + DWC_WARN("dev_tx_fifo_size must be 4-768\n");
  61308. + return -DWC_E_INVALID;
  61309. + }
  61310. +
  61311. + if (val >
  61312. + (DWC_READ_REG32(&core_if->core_global_regs->dtxfsiz[fifo_num]))) {
  61313. + if (dwc_otg_param_initialized
  61314. + (core_if->core_params->dev_tx_fifo_size[fifo_num])) {
  61315. + DWC_ERROR
  61316. + ("`%d' invalid for parameter `dev_tx_fifo_size_%d'. Check HW configuration.\n",
  61317. + val, fifo_num);
  61318. + }
  61319. + val = (DWC_READ_REG32(&core_if->core_global_regs->dtxfsiz[fifo_num]));
  61320. + retval = -DWC_E_INVALID;
  61321. + }
  61322. +
  61323. + core_if->core_params->dev_tx_fifo_size[fifo_num] = val;
  61324. + return retval;
  61325. +}
  61326. +
  61327. +int32_t dwc_otg_get_param_dev_tx_fifo_size(dwc_otg_core_if_t * core_if,
  61328. + int fifo_num)
  61329. +{
  61330. + return core_if->core_params->dev_tx_fifo_size[fifo_num];
  61331. +}
  61332. +
  61333. +int dwc_otg_set_param_thr_ctl(dwc_otg_core_if_t * core_if, int32_t val)
  61334. +{
  61335. + int retval = 0;
  61336. +
  61337. + if (DWC_OTG_PARAM_TEST(val, 0, 7)) {
  61338. + DWC_WARN("Wrong value for thr_ctl\n");
  61339. + DWC_WARN("thr_ctl must be 0-7\n");
  61340. + return -DWC_E_INVALID;
  61341. + }
  61342. +
  61343. + if ((val != 0) &&
  61344. + (!dwc_otg_get_param_dma_enable(core_if) ||
  61345. + !core_if->hwcfg4.b.ded_fifo_en)) {
  61346. + if (dwc_otg_param_initialized(core_if->core_params->thr_ctl)) {
  61347. + DWC_ERROR
  61348. + ("%d invalid for parameter thr_ctl. Check HW configuration.\n",
  61349. + val);
  61350. + }
  61351. + val = 0;
  61352. + retval = -DWC_E_INVALID;
  61353. + }
  61354. +
  61355. + core_if->core_params->thr_ctl = val;
  61356. + return retval;
  61357. +}
  61358. +
  61359. +int32_t dwc_otg_get_param_thr_ctl(dwc_otg_core_if_t * core_if)
  61360. +{
  61361. + return core_if->core_params->thr_ctl;
  61362. +}
  61363. +
  61364. +int dwc_otg_set_param_lpm_enable(dwc_otg_core_if_t * core_if, int32_t val)
  61365. +{
  61366. + int retval = 0;
  61367. +
  61368. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61369. + DWC_WARN("Wrong value for lpm_enable\n");
  61370. + DWC_WARN("lpm_enable must be 0 or 1\n");
  61371. + return -DWC_E_INVALID;
  61372. + }
  61373. +
  61374. + if (val && !core_if->hwcfg3.b.otg_lpm_en) {
  61375. + if (dwc_otg_param_initialized(core_if->core_params->lpm_enable)) {
  61376. + DWC_ERROR
  61377. + ("%d invalid for parameter lpm_enable. Check HW configuration.\n",
  61378. + val);
  61379. + }
  61380. + val = 0;
  61381. + retval = -DWC_E_INVALID;
  61382. + }
  61383. +
  61384. + core_if->core_params->lpm_enable = val;
  61385. + return retval;
  61386. +}
  61387. +
  61388. +int32_t dwc_otg_get_param_lpm_enable(dwc_otg_core_if_t * core_if)
  61389. +{
  61390. + return core_if->core_params->lpm_enable;
  61391. +}
  61392. +
  61393. +int dwc_otg_set_param_tx_thr_length(dwc_otg_core_if_t * core_if, int32_t val)
  61394. +{
  61395. + if (DWC_OTG_PARAM_TEST(val, 8, 128)) {
  61396. + DWC_WARN("Wrong valaue for tx_thr_length\n");
  61397. + DWC_WARN("tx_thr_length must be 8 - 128\n");
  61398. + return -DWC_E_INVALID;
  61399. + }
  61400. +
  61401. + core_if->core_params->tx_thr_length = val;
  61402. + return 0;
  61403. +}
  61404. +
  61405. +int32_t dwc_otg_get_param_tx_thr_length(dwc_otg_core_if_t * core_if)
  61406. +{
  61407. + return core_if->core_params->tx_thr_length;
  61408. +}
  61409. +
  61410. +int dwc_otg_set_param_rx_thr_length(dwc_otg_core_if_t * core_if, int32_t val)
  61411. +{
  61412. + if (DWC_OTG_PARAM_TEST(val, 8, 128)) {
  61413. + DWC_WARN("Wrong valaue for rx_thr_length\n");
  61414. + DWC_WARN("rx_thr_length must be 8 - 128\n");
  61415. + return -DWC_E_INVALID;
  61416. + }
  61417. +
  61418. + core_if->core_params->rx_thr_length = val;
  61419. + return 0;
  61420. +}
  61421. +
  61422. +int32_t dwc_otg_get_param_rx_thr_length(dwc_otg_core_if_t * core_if)
  61423. +{
  61424. + return core_if->core_params->rx_thr_length;
  61425. +}
  61426. +
  61427. +int dwc_otg_set_param_dma_burst_size(dwc_otg_core_if_t * core_if, int32_t val)
  61428. +{
  61429. + if (DWC_OTG_PARAM_TEST(val, 1, 1) &&
  61430. + DWC_OTG_PARAM_TEST(val, 4, 4) &&
  61431. + DWC_OTG_PARAM_TEST(val, 8, 8) &&
  61432. + DWC_OTG_PARAM_TEST(val, 16, 16) &&
  61433. + DWC_OTG_PARAM_TEST(val, 32, 32) &&
  61434. + DWC_OTG_PARAM_TEST(val, 64, 64) &&
  61435. + DWC_OTG_PARAM_TEST(val, 128, 128) &&
  61436. + DWC_OTG_PARAM_TEST(val, 256, 256)) {
  61437. + DWC_WARN("`%d' invalid for parameter `dma_burst_size'\n", val);
  61438. + return -DWC_E_INVALID;
  61439. + }
  61440. + core_if->core_params->dma_burst_size = val;
  61441. + return 0;
  61442. +}
  61443. +
  61444. +int32_t dwc_otg_get_param_dma_burst_size(dwc_otg_core_if_t * core_if)
  61445. +{
  61446. + return core_if->core_params->dma_burst_size;
  61447. +}
  61448. +
  61449. +int dwc_otg_set_param_pti_enable(dwc_otg_core_if_t * core_if, int32_t val)
  61450. +{
  61451. + int retval = 0;
  61452. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61453. + DWC_WARN("`%d' invalid for parameter `pti_enable'\n", val);
  61454. + return -DWC_E_INVALID;
  61455. + }
  61456. + if (val && (core_if->snpsid < OTG_CORE_REV_2_72a)) {
  61457. + if (dwc_otg_param_initialized(core_if->core_params->pti_enable)) {
  61458. + DWC_ERROR
  61459. + ("%d invalid for parameter pti_enable. Check HW configuration.\n",
  61460. + val);
  61461. + }
  61462. + retval = -DWC_E_INVALID;
  61463. + val = 0;
  61464. + }
  61465. + core_if->core_params->pti_enable = val;
  61466. + return retval;
  61467. +}
  61468. +
  61469. +int32_t dwc_otg_get_param_pti_enable(dwc_otg_core_if_t * core_if)
  61470. +{
  61471. + return core_if->core_params->pti_enable;
  61472. +}
  61473. +
  61474. +int dwc_otg_set_param_mpi_enable(dwc_otg_core_if_t * core_if, int32_t val)
  61475. +{
  61476. + int retval = 0;
  61477. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61478. + DWC_WARN("`%d' invalid for parameter `mpi_enable'\n", val);
  61479. + return -DWC_E_INVALID;
  61480. + }
  61481. + if (val && (core_if->hwcfg2.b.multi_proc_int == 0)) {
  61482. + if (dwc_otg_param_initialized(core_if->core_params->mpi_enable)) {
  61483. + DWC_ERROR
  61484. + ("%d invalid for parameter mpi_enable. Check HW configuration.\n",
  61485. + val);
  61486. + }
  61487. + retval = -DWC_E_INVALID;
  61488. + val = 0;
  61489. + }
  61490. + core_if->core_params->mpi_enable = val;
  61491. + return retval;
  61492. +}
  61493. +
  61494. +int32_t dwc_otg_get_param_mpi_enable(dwc_otg_core_if_t * core_if)
  61495. +{
  61496. + return core_if->core_params->mpi_enable;
  61497. +}
  61498. +
  61499. +int dwc_otg_set_param_adp_enable(dwc_otg_core_if_t * core_if, int32_t val)
  61500. +{
  61501. + int retval = 0;
  61502. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61503. + DWC_WARN("`%d' invalid for parameter `adp_enable'\n", val);
  61504. + return -DWC_E_INVALID;
  61505. + }
  61506. + if (val && (core_if->hwcfg3.b.adp_supp == 0)) {
  61507. + if (dwc_otg_param_initialized
  61508. + (core_if->core_params->adp_supp_enable)) {
  61509. + DWC_ERROR
  61510. + ("%d invalid for parameter adp_enable. Check HW configuration.\n",
  61511. + val);
  61512. + }
  61513. + retval = -DWC_E_INVALID;
  61514. + val = 0;
  61515. + }
  61516. + core_if->core_params->adp_supp_enable = val;
  61517. + /*Set OTG version 2.0 in case of enabling ADP*/
  61518. + if (val)
  61519. + dwc_otg_set_param_otg_ver(core_if, 1);
  61520. +
  61521. + return retval;
  61522. +}
  61523. +
  61524. +int32_t dwc_otg_get_param_adp_enable(dwc_otg_core_if_t * core_if)
  61525. +{
  61526. + return core_if->core_params->adp_supp_enable;
  61527. +}
  61528. +
  61529. +int dwc_otg_set_param_ic_usb_cap(dwc_otg_core_if_t * core_if, int32_t val)
  61530. +{
  61531. + int retval = 0;
  61532. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61533. + DWC_WARN("`%d' invalid for parameter `ic_usb_cap'\n", val);
  61534. + DWC_WARN("ic_usb_cap must be 0 or 1\n");
  61535. + return -DWC_E_INVALID;
  61536. + }
  61537. +
  61538. + if (val && (core_if->hwcfg2.b.otg_enable_ic_usb == 0)) {
  61539. + if (dwc_otg_param_initialized(core_if->core_params->ic_usb_cap)) {
  61540. + DWC_ERROR
  61541. + ("%d invalid for parameter ic_usb_cap. Check HW configuration.\n",
  61542. + val);
  61543. + }
  61544. + retval = -DWC_E_INVALID;
  61545. + val = 0;
  61546. + }
  61547. + core_if->core_params->ic_usb_cap = val;
  61548. + return retval;
  61549. +}
  61550. +
  61551. +int32_t dwc_otg_get_param_ic_usb_cap(dwc_otg_core_if_t * core_if)
  61552. +{
  61553. + return core_if->core_params->ic_usb_cap;
  61554. +}
  61555. +
  61556. +int dwc_otg_set_param_ahb_thr_ratio(dwc_otg_core_if_t * core_if, int32_t val)
  61557. +{
  61558. + int retval = 0;
  61559. + int valid = 1;
  61560. +
  61561. + if (DWC_OTG_PARAM_TEST(val, 0, 3)) {
  61562. + DWC_WARN("`%d' invalid for parameter `ahb_thr_ratio'\n", val);
  61563. + DWC_WARN("ahb_thr_ratio must be 0 - 3\n");
  61564. + return -DWC_E_INVALID;
  61565. + }
  61566. +
  61567. + if (val
  61568. + && (core_if->snpsid < OTG_CORE_REV_2_81a
  61569. + || !dwc_otg_get_param_thr_ctl(core_if))) {
  61570. + valid = 0;
  61571. + } else if (val
  61572. + && ((dwc_otg_get_param_tx_thr_length(core_if) / (1 << val)) <
  61573. + 4)) {
  61574. + valid = 0;
  61575. + }
  61576. + if (valid == 0) {
  61577. + if (dwc_otg_param_initialized
  61578. + (core_if->core_params->ahb_thr_ratio)) {
  61579. + DWC_ERROR
  61580. + ("%d invalid for parameter ahb_thr_ratio. Check HW configuration.\n",
  61581. + val);
  61582. + }
  61583. + retval = -DWC_E_INVALID;
  61584. + val = 0;
  61585. + }
  61586. +
  61587. + core_if->core_params->ahb_thr_ratio = val;
  61588. + return retval;
  61589. +}
  61590. +
  61591. +int32_t dwc_otg_get_param_ahb_thr_ratio(dwc_otg_core_if_t * core_if)
  61592. +{
  61593. + return core_if->core_params->ahb_thr_ratio;
  61594. +}
  61595. +
  61596. +int dwc_otg_set_param_power_down(dwc_otg_core_if_t * core_if, int32_t val)
  61597. +{
  61598. + int retval = 0;
  61599. + int valid = 1;
  61600. + hwcfg4_data_t hwcfg4 = {.d32 = 0 };
  61601. + hwcfg4.d32 = DWC_READ_REG32(&core_if->core_global_regs->ghwcfg4);
  61602. +
  61603. + if (DWC_OTG_PARAM_TEST(val, 0, 3)) {
  61604. + DWC_WARN("`%d' invalid for parameter `power_down'\n", val);
  61605. + DWC_WARN("power_down must be 0 - 2\n");
  61606. + return -DWC_E_INVALID;
  61607. + }
  61608. +
  61609. + if ((val == 2) && (core_if->snpsid < OTG_CORE_REV_2_91a)) {
  61610. + valid = 0;
  61611. + }
  61612. + if ((val == 3)
  61613. + && ((core_if->snpsid < OTG_CORE_REV_3_00a)
  61614. + || (hwcfg4.b.xhiber == 0))) {
  61615. + valid = 0;
  61616. + }
  61617. + if (valid == 0) {
  61618. + if (dwc_otg_param_initialized(core_if->core_params->power_down)) {
  61619. + DWC_ERROR
  61620. + ("%d invalid for parameter power_down. Check HW configuration.\n",
  61621. + val);
  61622. + }
  61623. + retval = -DWC_E_INVALID;
  61624. + val = 0;
  61625. + }
  61626. + core_if->core_params->power_down = val;
  61627. + return retval;
  61628. +}
  61629. +
  61630. +int32_t dwc_otg_get_param_power_down(dwc_otg_core_if_t * core_if)
  61631. +{
  61632. + return core_if->core_params->power_down;
  61633. +}
  61634. +
  61635. +int dwc_otg_set_param_reload_ctl(dwc_otg_core_if_t * core_if, int32_t val)
  61636. +{
  61637. + int retval = 0;
  61638. + int valid = 1;
  61639. +
  61640. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61641. + DWC_WARN("`%d' invalid for parameter `reload_ctl'\n", val);
  61642. + DWC_WARN("reload_ctl must be 0 or 1\n");
  61643. + return -DWC_E_INVALID;
  61644. + }
  61645. +
  61646. + if ((val == 1) && (core_if->snpsid < OTG_CORE_REV_2_92a)) {
  61647. + valid = 0;
  61648. + }
  61649. + if (valid == 0) {
  61650. + if (dwc_otg_param_initialized(core_if->core_params->reload_ctl)) {
  61651. + DWC_ERROR("%d invalid for parameter reload_ctl."
  61652. + "Check HW configuration.\n", val);
  61653. + }
  61654. + retval = -DWC_E_INVALID;
  61655. + val = 0;
  61656. + }
  61657. + core_if->core_params->reload_ctl = val;
  61658. + return retval;
  61659. +}
  61660. +
  61661. +int32_t dwc_otg_get_param_reload_ctl(dwc_otg_core_if_t * core_if)
  61662. +{
  61663. + return core_if->core_params->reload_ctl;
  61664. +}
  61665. +
  61666. +int dwc_otg_set_param_dev_out_nak(dwc_otg_core_if_t * core_if, int32_t val)
  61667. +{
  61668. + int retval = 0;
  61669. + int valid = 1;
  61670. +
  61671. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61672. + DWC_WARN("`%d' invalid for parameter `dev_out_nak'\n", val);
  61673. + DWC_WARN("dev_out_nak must be 0 or 1\n");
  61674. + return -DWC_E_INVALID;
  61675. + }
  61676. +
  61677. + if ((val == 1) && ((core_if->snpsid < OTG_CORE_REV_2_93a) ||
  61678. + !(core_if->core_params->dma_desc_enable))) {
  61679. + valid = 0;
  61680. + }
  61681. + if (valid == 0) {
  61682. + if (dwc_otg_param_initialized(core_if->core_params->dev_out_nak)) {
  61683. + DWC_ERROR("%d invalid for parameter dev_out_nak."
  61684. + "Check HW configuration.\n", val);
  61685. + }
  61686. + retval = -DWC_E_INVALID;
  61687. + val = 0;
  61688. + }
  61689. + core_if->core_params->dev_out_nak = val;
  61690. + return retval;
  61691. +}
  61692. +
  61693. +int32_t dwc_otg_get_param_dev_out_nak(dwc_otg_core_if_t * core_if)
  61694. +{
  61695. + return core_if->core_params->dev_out_nak;
  61696. +}
  61697. +
  61698. +int dwc_otg_set_param_cont_on_bna(dwc_otg_core_if_t * core_if, int32_t val)
  61699. +{
  61700. + int retval = 0;
  61701. + int valid = 1;
  61702. +
  61703. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61704. + DWC_WARN("`%d' invalid for parameter `cont_on_bna'\n", val);
  61705. + DWC_WARN("cont_on_bna must be 0 or 1\n");
  61706. + return -DWC_E_INVALID;
  61707. + }
  61708. +
  61709. + if ((val == 1) && ((core_if->snpsid < OTG_CORE_REV_2_94a) ||
  61710. + !(core_if->core_params->dma_desc_enable))) {
  61711. + valid = 0;
  61712. + }
  61713. + if (valid == 0) {
  61714. + if (dwc_otg_param_initialized(core_if->core_params->cont_on_bna)) {
  61715. + DWC_ERROR("%d invalid for parameter cont_on_bna."
  61716. + "Check HW configuration.\n", val);
  61717. + }
  61718. + retval = -DWC_E_INVALID;
  61719. + val = 0;
  61720. + }
  61721. + core_if->core_params->cont_on_bna = val;
  61722. + return retval;
  61723. +}
  61724. +
  61725. +int32_t dwc_otg_get_param_cont_on_bna(dwc_otg_core_if_t * core_if)
  61726. +{
  61727. + return core_if->core_params->cont_on_bna;
  61728. +}
  61729. +
  61730. +int dwc_otg_set_param_ahb_single(dwc_otg_core_if_t * core_if, int32_t val)
  61731. +{
  61732. + int retval = 0;
  61733. + int valid = 1;
  61734. +
  61735. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61736. + DWC_WARN("`%d' invalid for parameter `ahb_single'\n", val);
  61737. + DWC_WARN("ahb_single must be 0 or 1\n");
  61738. + return -DWC_E_INVALID;
  61739. + }
  61740. +
  61741. + if ((val == 1) && (core_if->snpsid < OTG_CORE_REV_2_94a)) {
  61742. + valid = 0;
  61743. + }
  61744. + if (valid == 0) {
  61745. + if (dwc_otg_param_initialized(core_if->core_params->ahb_single)) {
  61746. + DWC_ERROR("%d invalid for parameter ahb_single."
  61747. + "Check HW configuration.\n", val);
  61748. + }
  61749. + retval = -DWC_E_INVALID;
  61750. + val = 0;
  61751. + }
  61752. + core_if->core_params->ahb_single = val;
  61753. + return retval;
  61754. +}
  61755. +
  61756. +int32_t dwc_otg_get_param_ahb_single(dwc_otg_core_if_t * core_if)
  61757. +{
  61758. + return core_if->core_params->ahb_single;
  61759. +}
  61760. +
  61761. +int dwc_otg_set_param_otg_ver(dwc_otg_core_if_t * core_if, int32_t val)
  61762. +{
  61763. + int retval = 0;
  61764. +
  61765. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61766. + DWC_WARN("`%d' invalid for parameter `otg_ver'\n", val);
  61767. + DWC_WARN
  61768. + ("otg_ver must be 0(for OTG 1.3 support) or 1(for OTG 2.0 support)\n");
  61769. + return -DWC_E_INVALID;
  61770. + }
  61771. +
  61772. + core_if->core_params->otg_ver = val;
  61773. + return retval;
  61774. +}
  61775. +
  61776. +int32_t dwc_otg_get_param_otg_ver(dwc_otg_core_if_t * core_if)
  61777. +{
  61778. + return core_if->core_params->otg_ver;
  61779. +}
  61780. +
  61781. +uint32_t dwc_otg_get_hnpstatus(dwc_otg_core_if_t * core_if)
  61782. +{
  61783. + gotgctl_data_t otgctl;
  61784. + otgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  61785. + return otgctl.b.hstnegscs;
  61786. +}
  61787. +
  61788. +uint32_t dwc_otg_get_srpstatus(dwc_otg_core_if_t * core_if)
  61789. +{
  61790. + gotgctl_data_t otgctl;
  61791. + otgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  61792. + return otgctl.b.sesreqscs;
  61793. +}
  61794. +
  61795. +void dwc_otg_set_hnpreq(dwc_otg_core_if_t * core_if, uint32_t val)
  61796. +{
  61797. + if(core_if->otg_ver == 0) {
  61798. + gotgctl_data_t otgctl;
  61799. + otgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  61800. + otgctl.b.hnpreq = val;
  61801. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgctl, otgctl.d32);
  61802. + } else {
  61803. + core_if->otg_sts = val;
  61804. + }
  61805. +}
  61806. +
  61807. +uint32_t dwc_otg_get_gsnpsid(dwc_otg_core_if_t * core_if)
  61808. +{
  61809. + return core_if->snpsid;
  61810. +}
  61811. +
  61812. +uint32_t dwc_otg_get_mode(dwc_otg_core_if_t * core_if)
  61813. +{
  61814. + gintsts_data_t gintsts;
  61815. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  61816. + return gintsts.b.curmode;
  61817. +}
  61818. +
  61819. +uint32_t dwc_otg_get_hnpcapable(dwc_otg_core_if_t * core_if)
  61820. +{
  61821. + gusbcfg_data_t usbcfg;
  61822. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  61823. + return usbcfg.b.hnpcap;
  61824. +}
  61825. +
  61826. +void dwc_otg_set_hnpcapable(dwc_otg_core_if_t * core_if, uint32_t val)
  61827. +{
  61828. + gusbcfg_data_t usbcfg;
  61829. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  61830. + usbcfg.b.hnpcap = val;
  61831. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, usbcfg.d32);
  61832. +}
  61833. +
  61834. +uint32_t dwc_otg_get_srpcapable(dwc_otg_core_if_t * core_if)
  61835. +{
  61836. + gusbcfg_data_t usbcfg;
  61837. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  61838. + return usbcfg.b.srpcap;
  61839. +}
  61840. +
  61841. +void dwc_otg_set_srpcapable(dwc_otg_core_if_t * core_if, uint32_t val)
  61842. +{
  61843. + gusbcfg_data_t usbcfg;
  61844. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  61845. + usbcfg.b.srpcap = val;
  61846. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, usbcfg.d32);
  61847. +}
  61848. +
  61849. +uint32_t dwc_otg_get_devspeed(dwc_otg_core_if_t * core_if)
  61850. +{
  61851. + dcfg_data_t dcfg;
  61852. + /* originally: dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg); */
  61853. +
  61854. + dcfg.d32 = -1; //GRAYG
  61855. + DWC_DEBUGPL(DBG_CILV, "%s - core_if(%p)\n", __func__, core_if);
  61856. + if (NULL == core_if)
  61857. + DWC_ERROR("reg request with NULL core_if\n");
  61858. + DWC_DEBUGPL(DBG_CILV, "%s - core_if(%p)->dev_if(%p)\n", __func__,
  61859. + core_if, core_if->dev_if);
  61860. + if (NULL == core_if->dev_if)
  61861. + DWC_ERROR("reg request with NULL dev_if\n");
  61862. + DWC_DEBUGPL(DBG_CILV, "%s - core_if(%p)->dev_if(%p)->"
  61863. + "dev_global_regs(%p)\n", __func__,
  61864. + core_if, core_if->dev_if,
  61865. + core_if->dev_if->dev_global_regs);
  61866. + if (NULL == core_if->dev_if->dev_global_regs)
  61867. + DWC_ERROR("reg request with NULL dev_global_regs\n");
  61868. + else {
  61869. + DWC_DEBUGPL(DBG_CILV, "%s - &core_if(%p)->dev_if(%p)->"
  61870. + "dev_global_regs(%p)->dcfg = %p\n", __func__,
  61871. + core_if, core_if->dev_if,
  61872. + core_if->dev_if->dev_global_regs,
  61873. + &core_if->dev_if->dev_global_regs->dcfg);
  61874. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  61875. + }
  61876. + return dcfg.b.devspd;
  61877. +}
  61878. +
  61879. +void dwc_otg_set_devspeed(dwc_otg_core_if_t * core_if, uint32_t val)
  61880. +{
  61881. + dcfg_data_t dcfg;
  61882. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  61883. + dcfg.b.devspd = val;
  61884. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg, dcfg.d32);
  61885. +}
  61886. +
  61887. +uint32_t dwc_otg_get_busconnected(dwc_otg_core_if_t * core_if)
  61888. +{
  61889. + hprt0_data_t hprt0;
  61890. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  61891. + return hprt0.b.prtconnsts;
  61892. +}
  61893. +
  61894. +uint32_t dwc_otg_get_enumspeed(dwc_otg_core_if_t * core_if)
  61895. +{
  61896. + dsts_data_t dsts;
  61897. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  61898. + return dsts.b.enumspd;
  61899. +}
  61900. +
  61901. +uint32_t dwc_otg_get_prtpower(dwc_otg_core_if_t * core_if)
  61902. +{
  61903. + hprt0_data_t hprt0;
  61904. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  61905. + return hprt0.b.prtpwr;
  61906. +
  61907. +}
  61908. +
  61909. +uint32_t dwc_otg_get_core_state(dwc_otg_core_if_t * core_if)
  61910. +{
  61911. + return core_if->hibernation_suspend;
  61912. +}
  61913. +
  61914. +void dwc_otg_set_prtpower(dwc_otg_core_if_t * core_if, uint32_t val)
  61915. +{
  61916. + hprt0_data_t hprt0;
  61917. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  61918. + hprt0.b.prtpwr = val;
  61919. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  61920. +}
  61921. +
  61922. +uint32_t dwc_otg_get_prtsuspend(dwc_otg_core_if_t * core_if)
  61923. +{
  61924. + hprt0_data_t hprt0;
  61925. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  61926. + return hprt0.b.prtsusp;
  61927. +
  61928. +}
  61929. +
  61930. +void dwc_otg_set_prtsuspend(dwc_otg_core_if_t * core_if, uint32_t val)
  61931. +{
  61932. + hprt0_data_t hprt0;
  61933. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  61934. + hprt0.b.prtsusp = val;
  61935. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  61936. +}
  61937. +
  61938. +uint32_t dwc_otg_get_fr_interval(dwc_otg_core_if_t * core_if)
  61939. +{
  61940. + hfir_data_t hfir;
  61941. + hfir.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hfir);
  61942. + return hfir.b.frint;
  61943. +
  61944. +}
  61945. +
  61946. +void dwc_otg_set_fr_interval(dwc_otg_core_if_t * core_if, uint32_t val)
  61947. +{
  61948. + hfir_data_t hfir;
  61949. + uint32_t fram_int;
  61950. + fram_int = calc_frame_interval(core_if);
  61951. + hfir.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hfir);
  61952. + if (!core_if->core_params->reload_ctl) {
  61953. + DWC_WARN("\nCannot reload HFIR register.HFIR.HFIRRldCtrl bit is"
  61954. + "not set to 1.\nShould load driver with reload_ctl=1"
  61955. + " module parameter\n");
  61956. + return;
  61957. + }
  61958. + switch (fram_int) {
  61959. + case 3750:
  61960. + if ((val < 3350) || (val > 4150)) {
  61961. + DWC_WARN("HFIR interval for HS core and 30 MHz"
  61962. + "clock freq should be from 3350 to 4150\n");
  61963. + return;
  61964. + }
  61965. + break;
  61966. + case 30000:
  61967. + if ((val < 26820) || (val > 33180)) {
  61968. + DWC_WARN("HFIR interval for FS/LS core and 30 MHz"
  61969. + "clock freq should be from 26820 to 33180\n");
  61970. + return;
  61971. + }
  61972. + break;
  61973. + case 6000:
  61974. + if ((val < 5360) || (val > 6640)) {
  61975. + DWC_WARN("HFIR interval for HS core and 48 MHz"
  61976. + "clock freq should be from 5360 to 6640\n");
  61977. + return;
  61978. + }
  61979. + break;
  61980. + case 48000:
  61981. + if ((val < 42912) || (val > 53088)) {
  61982. + DWC_WARN("HFIR interval for FS/LS core and 48 MHz"
  61983. + "clock freq should be from 42912 to 53088\n");
  61984. + return;
  61985. + }
  61986. + break;
  61987. + case 7500:
  61988. + if ((val < 6700) || (val > 8300)) {
  61989. + DWC_WARN("HFIR interval for HS core and 60 MHz"
  61990. + "clock freq should be from 6700 to 8300\n");
  61991. + return;
  61992. + }
  61993. + break;
  61994. + case 60000:
  61995. + if ((val < 53640) || (val > 65536)) {
  61996. + DWC_WARN("HFIR interval for FS/LS core and 60 MHz"
  61997. + "clock freq should be from 53640 to 65536\n");
  61998. + return;
  61999. + }
  62000. + break;
  62001. + default:
  62002. + DWC_WARN("Unknown frame interval\n");
  62003. + return;
  62004. + break;
  62005. +
  62006. + }
  62007. + hfir.b.frint = val;
  62008. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hfir, hfir.d32);
  62009. +}
  62010. +
  62011. +uint32_t dwc_otg_get_mode_ch_tim(dwc_otg_core_if_t * core_if)
  62012. +{
  62013. + hcfg_data_t hcfg;
  62014. + hcfg.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  62015. + return hcfg.b.modechtimen;
  62016. +
  62017. +}
  62018. +
  62019. +void dwc_otg_set_mode_ch_tim(dwc_otg_core_if_t * core_if, uint32_t val)
  62020. +{
  62021. + hcfg_data_t hcfg;
  62022. + hcfg.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  62023. + hcfg.b.modechtimen = val;
  62024. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg, hcfg.d32);
  62025. +}
  62026. +
  62027. +void dwc_otg_set_prtresume(dwc_otg_core_if_t * core_if, uint32_t val)
  62028. +{
  62029. + hprt0_data_t hprt0;
  62030. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  62031. + hprt0.b.prtres = val;
  62032. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  62033. +}
  62034. +
  62035. +uint32_t dwc_otg_get_remotewakesig(dwc_otg_core_if_t * core_if)
  62036. +{
  62037. + dctl_data_t dctl;
  62038. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  62039. + return dctl.b.rmtwkupsig;
  62040. +}
  62041. +
  62042. +uint32_t dwc_otg_get_lpm_portsleepstatus(dwc_otg_core_if_t * core_if)
  62043. +{
  62044. + glpmcfg_data_t lpmcfg;
  62045. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  62046. +
  62047. + DWC_ASSERT(!
  62048. + ((core_if->lx_state == DWC_OTG_L1) ^ lpmcfg.b.prt_sleep_sts),
  62049. + "lx_state = %d, lmpcfg.prt_sleep_sts = %d\n",
  62050. + core_if->lx_state, lpmcfg.b.prt_sleep_sts);
  62051. +
  62052. + return lpmcfg.b.prt_sleep_sts;
  62053. +}
  62054. +
  62055. +uint32_t dwc_otg_get_lpm_remotewakeenabled(dwc_otg_core_if_t * core_if)
  62056. +{
  62057. + glpmcfg_data_t lpmcfg;
  62058. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  62059. + return lpmcfg.b.rem_wkup_en;
  62060. +}
  62061. +
  62062. +uint32_t dwc_otg_get_lpmresponse(dwc_otg_core_if_t * core_if)
  62063. +{
  62064. + glpmcfg_data_t lpmcfg;
  62065. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  62066. + return lpmcfg.b.appl_resp;
  62067. +}
  62068. +
  62069. +void dwc_otg_set_lpmresponse(dwc_otg_core_if_t * core_if, uint32_t val)
  62070. +{
  62071. + glpmcfg_data_t lpmcfg;
  62072. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  62073. + lpmcfg.b.appl_resp = val;
  62074. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  62075. +}
  62076. +
  62077. +uint32_t dwc_otg_get_hsic_connect(dwc_otg_core_if_t * core_if)
  62078. +{
  62079. + glpmcfg_data_t lpmcfg;
  62080. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  62081. + return lpmcfg.b.hsic_connect;
  62082. +}
  62083. +
  62084. +void dwc_otg_set_hsic_connect(dwc_otg_core_if_t * core_if, uint32_t val)
  62085. +{
  62086. + glpmcfg_data_t lpmcfg;
  62087. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  62088. + lpmcfg.b.hsic_connect = val;
  62089. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  62090. +}
  62091. +
  62092. +uint32_t dwc_otg_get_inv_sel_hsic(dwc_otg_core_if_t * core_if)
  62093. +{
  62094. + glpmcfg_data_t lpmcfg;
  62095. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  62096. + return lpmcfg.b.inv_sel_hsic;
  62097. +
  62098. +}
  62099. +
  62100. +void dwc_otg_set_inv_sel_hsic(dwc_otg_core_if_t * core_if, uint32_t val)
  62101. +{
  62102. + glpmcfg_data_t lpmcfg;
  62103. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  62104. + lpmcfg.b.inv_sel_hsic = val;
  62105. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  62106. +}
  62107. +
  62108. +uint32_t dwc_otg_get_gotgctl(dwc_otg_core_if_t * core_if)
  62109. +{
  62110. + return DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  62111. +}
  62112. +
  62113. +void dwc_otg_set_gotgctl(dwc_otg_core_if_t * core_if, uint32_t val)
  62114. +{
  62115. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgctl, val);
  62116. +}
  62117. +
  62118. +uint32_t dwc_otg_get_gusbcfg(dwc_otg_core_if_t * core_if)
  62119. +{
  62120. + return DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  62121. +}
  62122. +
  62123. +void dwc_otg_set_gusbcfg(dwc_otg_core_if_t * core_if, uint32_t val)
  62124. +{
  62125. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, val);
  62126. +}
  62127. +
  62128. +uint32_t dwc_otg_get_grxfsiz(dwc_otg_core_if_t * core_if)
  62129. +{
  62130. + return DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  62131. +}
  62132. +
  62133. +void dwc_otg_set_grxfsiz(dwc_otg_core_if_t * core_if, uint32_t val)
  62134. +{
  62135. + DWC_WRITE_REG32(&core_if->core_global_regs->grxfsiz, val);
  62136. +}
  62137. +
  62138. +uint32_t dwc_otg_get_gnptxfsiz(dwc_otg_core_if_t * core_if)
  62139. +{
  62140. + return DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz);
  62141. +}
  62142. +
  62143. +void dwc_otg_set_gnptxfsiz(dwc_otg_core_if_t * core_if, uint32_t val)
  62144. +{
  62145. + DWC_WRITE_REG32(&core_if->core_global_regs->gnptxfsiz, val);
  62146. +}
  62147. +
  62148. +uint32_t dwc_otg_get_gpvndctl(dwc_otg_core_if_t * core_if)
  62149. +{
  62150. + return DWC_READ_REG32(&core_if->core_global_regs->gpvndctl);
  62151. +}
  62152. +
  62153. +void dwc_otg_set_gpvndctl(dwc_otg_core_if_t * core_if, uint32_t val)
  62154. +{
  62155. + DWC_WRITE_REG32(&core_if->core_global_regs->gpvndctl, val);
  62156. +}
  62157. +
  62158. +uint32_t dwc_otg_get_ggpio(dwc_otg_core_if_t * core_if)
  62159. +{
  62160. + return DWC_READ_REG32(&core_if->core_global_regs->ggpio);
  62161. +}
  62162. +
  62163. +void dwc_otg_set_ggpio(dwc_otg_core_if_t * core_if, uint32_t val)
  62164. +{
  62165. + DWC_WRITE_REG32(&core_if->core_global_regs->ggpio, val);
  62166. +}
  62167. +
  62168. +uint32_t dwc_otg_get_hprt0(dwc_otg_core_if_t * core_if)
  62169. +{
  62170. + return DWC_READ_REG32(core_if->host_if->hprt0);
  62171. +
  62172. +}
  62173. +
  62174. +void dwc_otg_set_hprt0(dwc_otg_core_if_t * core_if, uint32_t val)
  62175. +{
  62176. + DWC_WRITE_REG32(core_if->host_if->hprt0, val);
  62177. +}
  62178. +
  62179. +uint32_t dwc_otg_get_guid(dwc_otg_core_if_t * core_if)
  62180. +{
  62181. + return DWC_READ_REG32(&core_if->core_global_regs->guid);
  62182. +}
  62183. +
  62184. +void dwc_otg_set_guid(dwc_otg_core_if_t * core_if, uint32_t val)
  62185. +{
  62186. + DWC_WRITE_REG32(&core_if->core_global_regs->guid, val);
  62187. +}
  62188. +
  62189. +uint32_t dwc_otg_get_hptxfsiz(dwc_otg_core_if_t * core_if)
  62190. +{
  62191. + return DWC_READ_REG32(&core_if->core_global_regs->hptxfsiz);
  62192. +}
  62193. +
  62194. +uint16_t dwc_otg_get_otg_version(dwc_otg_core_if_t * core_if)
  62195. +{
  62196. + return ((core_if->otg_ver == 1) ? (uint16_t)0x0200 : (uint16_t)0x0103);
  62197. +}
  62198. +
  62199. +/**
  62200. + * Start the SRP timer to detect when the SRP does not complete within
  62201. + * 6 seconds.
  62202. + *
  62203. + * @param core_if the pointer to core_if strucure.
  62204. + */
  62205. +void dwc_otg_pcd_start_srp_timer(dwc_otg_core_if_t * core_if)
  62206. +{
  62207. + core_if->srp_timer_started = 1;
  62208. + DWC_TIMER_SCHEDULE(core_if->srp_timer, 6000 /* 6 secs */ );
  62209. +}
  62210. +
  62211. +void dwc_otg_initiate_srp(dwc_otg_core_if_t * core_if)
  62212. +{
  62213. + uint32_t *addr = (uint32_t *) & (core_if->core_global_regs->gotgctl);
  62214. + gotgctl_data_t mem;
  62215. + gotgctl_data_t val;
  62216. +
  62217. + val.d32 = DWC_READ_REG32(addr);
  62218. + if (val.b.sesreq) {
  62219. + DWC_ERROR("Session Request Already active!\n");
  62220. + return;
  62221. + }
  62222. +
  62223. + DWC_INFO("Session Request Initated\n"); //NOTICE
  62224. + mem.d32 = DWC_READ_REG32(addr);
  62225. + mem.b.sesreq = 1;
  62226. + DWC_WRITE_REG32(addr, mem.d32);
  62227. +
  62228. + /* Start the SRP timer */
  62229. + dwc_otg_pcd_start_srp_timer(core_if);
  62230. + return;
  62231. +}
  62232. diff -Nur linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_cil.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cil.h
  62233. --- linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_cil.h 1970-01-01 01:00:00.000000000 +0100
  62234. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cil.h 2014-04-24 15:37:13.310990489 +0200
  62235. @@ -0,0 +1,1464 @@
  62236. +/* ==========================================================================
  62237. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_cil.h $
  62238. + * $Revision: #123 $
  62239. + * $Date: 2012/08/10 $
  62240. + * $Change: 2047372 $
  62241. + *
  62242. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  62243. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  62244. + * otherwise expressly agreed to in writing between Synopsys and you.
  62245. + *
  62246. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  62247. + * any End User Software License Agreement or Agreement for Licensed Product
  62248. + * with Synopsys or any supplement thereto. You are permitted to use and
  62249. + * redistribute this Software in source and binary forms, with or without
  62250. + * modification, provided that redistributions of source code must retain this
  62251. + * notice. You may not view, use, disclose, copy or distribute this file or
  62252. + * any information contained herein except pursuant to this license grant from
  62253. + * Synopsys. If you do not agree with this notice, including the disclaimer
  62254. + * below, then you are not authorized to use the Software.
  62255. + *
  62256. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  62257. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  62258. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  62259. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  62260. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  62261. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  62262. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  62263. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  62264. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  62265. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  62266. + * DAMAGE.
  62267. + * ========================================================================== */
  62268. +
  62269. +#if !defined(__DWC_CIL_H__)
  62270. +#define __DWC_CIL_H__
  62271. +
  62272. +#include "dwc_list.h"
  62273. +#include "dwc_otg_dbg.h"
  62274. +#include "dwc_otg_regs.h"
  62275. +
  62276. +#include "dwc_otg_core_if.h"
  62277. +#include "dwc_otg_adp.h"
  62278. +
  62279. +/**
  62280. + * @file
  62281. + * This file contains the interface to the Core Interface Layer.
  62282. + */
  62283. +
  62284. +#ifdef DWC_UTE_CFI
  62285. +
  62286. +#define MAX_DMA_DESCS_PER_EP 256
  62287. +
  62288. +/**
  62289. + * Enumeration for the data buffer mode
  62290. + */
  62291. +typedef enum _data_buffer_mode {
  62292. + BM_STANDARD = 0, /* data buffer is in normal mode */
  62293. + BM_SG = 1, /* data buffer uses the scatter/gather mode */
  62294. + BM_CONCAT = 2, /* data buffer uses the concatenation mode */
  62295. + BM_CIRCULAR = 3, /* data buffer uses the circular DMA mode */
  62296. + BM_ALIGN = 4 /* data buffer is in buffer alignment mode */
  62297. +} data_buffer_mode_e;
  62298. +#endif //DWC_UTE_CFI
  62299. +
  62300. +/** Macros defined for DWC OTG HW Release version */
  62301. +
  62302. +#define OTG_CORE_REV_2_60a 0x4F54260A
  62303. +#define OTG_CORE_REV_2_71a 0x4F54271A
  62304. +#define OTG_CORE_REV_2_72a 0x4F54272A
  62305. +#define OTG_CORE_REV_2_80a 0x4F54280A
  62306. +#define OTG_CORE_REV_2_81a 0x4F54281A
  62307. +#define OTG_CORE_REV_2_90a 0x4F54290A
  62308. +#define OTG_CORE_REV_2_91a 0x4F54291A
  62309. +#define OTG_CORE_REV_2_92a 0x4F54292A
  62310. +#define OTG_CORE_REV_2_93a 0x4F54293A
  62311. +#define OTG_CORE_REV_2_94a 0x4F54294A
  62312. +#define OTG_CORE_REV_3_00a 0x4F54300A
  62313. +
  62314. +/**
  62315. + * Information for each ISOC packet.
  62316. + */
  62317. +typedef struct iso_pkt_info {
  62318. + uint32_t offset;
  62319. + uint32_t length;
  62320. + int32_t status;
  62321. +} iso_pkt_info_t;
  62322. +
  62323. +/**
  62324. + * The <code>dwc_ep</code> structure represents the state of a single
  62325. + * endpoint when acting in device mode. It contains the data items
  62326. + * needed for an endpoint to be activated and transfer packets.
  62327. + */
  62328. +typedef struct dwc_ep {
  62329. + /** EP number used for register address lookup */
  62330. + uint8_t num;
  62331. + /** EP direction 0 = OUT */
  62332. + unsigned is_in:1;
  62333. + /** EP active. */
  62334. + unsigned active:1;
  62335. +
  62336. + /**
  62337. + * Periodic Tx FIFO # for IN EPs For INTR EP set to 0 to use non-periodic
  62338. + * Tx FIFO. If dedicated Tx FIFOs are enabled Tx FIFO # FOR IN EPs*/
  62339. + unsigned tx_fifo_num:4;
  62340. + /** EP type: 0 - Control, 1 - ISOC, 2 - BULK, 3 - INTR */
  62341. + unsigned type:2;
  62342. +#define DWC_OTG_EP_TYPE_CONTROL 0
  62343. +#define DWC_OTG_EP_TYPE_ISOC 1
  62344. +#define DWC_OTG_EP_TYPE_BULK 2
  62345. +#define DWC_OTG_EP_TYPE_INTR 3
  62346. +
  62347. + /** DATA start PID for INTR and BULK EP */
  62348. + unsigned data_pid_start:1;
  62349. + /** Frame (even/odd) for ISOC EP */
  62350. + unsigned even_odd_frame:1;
  62351. + /** Max Packet bytes */
  62352. + unsigned maxpacket:11;
  62353. +
  62354. + /** Max Transfer size */
  62355. + uint32_t maxxfer;
  62356. +
  62357. + /** @name Transfer state */
  62358. + /** @{ */
  62359. +
  62360. + /**
  62361. + * Pointer to the beginning of the transfer buffer -- do not modify
  62362. + * during transfer.
  62363. + */
  62364. +
  62365. + dwc_dma_t dma_addr;
  62366. +
  62367. + dwc_dma_t dma_desc_addr;
  62368. + dwc_otg_dev_dma_desc_t *desc_addr;
  62369. +
  62370. + uint8_t *start_xfer_buff;
  62371. + /** pointer to the transfer buffer */
  62372. + uint8_t *xfer_buff;
  62373. + /** Number of bytes to transfer */
  62374. + unsigned xfer_len:19;
  62375. + /** Number of bytes transferred. */
  62376. + unsigned xfer_count:19;
  62377. + /** Sent ZLP */
  62378. + unsigned sent_zlp:1;
  62379. + /** Total len for control transfer */
  62380. + unsigned total_len:19;
  62381. +
  62382. + /** stall clear flag */
  62383. + unsigned stall_clear_flag:1;
  62384. +
  62385. + /** SETUP pkt cnt rollover flag for EP0 out*/
  62386. + unsigned stp_rollover;
  62387. +
  62388. +#ifdef DWC_UTE_CFI
  62389. + /* The buffer mode */
  62390. + data_buffer_mode_e buff_mode;
  62391. +
  62392. + /* The chain of DMA descriptors.
  62393. + * MAX_DMA_DESCS_PER_EP will be allocated for each active EP.
  62394. + */
  62395. + dwc_otg_dma_desc_t *descs;
  62396. +
  62397. + /* The DMA address of the descriptors chain start */
  62398. + dma_addr_t descs_dma_addr;
  62399. + /** This variable stores the length of the last enqueued request */
  62400. + uint32_t cfi_req_len;
  62401. +#endif //DWC_UTE_CFI
  62402. +
  62403. +/** Max DMA Descriptor count for any EP */
  62404. +#define MAX_DMA_DESC_CNT 256
  62405. + /** Allocated DMA Desc count */
  62406. + uint32_t desc_cnt;
  62407. +
  62408. + /** bInterval */
  62409. + uint32_t bInterval;
  62410. + /** Next frame num to setup next ISOC transfer */
  62411. + uint32_t frame_num;
  62412. + /** Indicates SOF number overrun in DSTS */
  62413. + uint8_t frm_overrun;
  62414. +
  62415. +#ifdef DWC_UTE_PER_IO
  62416. + /** Next frame num for which will be setup DMA Desc */
  62417. + uint32_t xiso_frame_num;
  62418. + /** bInterval */
  62419. + uint32_t xiso_bInterval;
  62420. + /** Count of currently active transfers - shall be either 0 or 1 */
  62421. + int xiso_active_xfers;
  62422. + int xiso_queued_xfers;
  62423. +#endif
  62424. +#ifdef DWC_EN_ISOC
  62425. + /**
  62426. + * Variables specific for ISOC EPs
  62427. + *
  62428. + */
  62429. + /** DMA addresses of ISOC buffers */
  62430. + dwc_dma_t dma_addr0;
  62431. + dwc_dma_t dma_addr1;
  62432. +
  62433. + dwc_dma_t iso_dma_desc_addr;
  62434. + dwc_otg_dev_dma_desc_t *iso_desc_addr;
  62435. +
  62436. + /** pointer to the transfer buffers */
  62437. + uint8_t *xfer_buff0;
  62438. + uint8_t *xfer_buff1;
  62439. +
  62440. + /** number of ISOC Buffer is processing */
  62441. + uint32_t proc_buf_num;
  62442. + /** Interval of ISOC Buffer processing */
  62443. + uint32_t buf_proc_intrvl;
  62444. + /** Data size for regular frame */
  62445. + uint32_t data_per_frame;
  62446. +
  62447. + /* todo - pattern data support is to be implemented in the future */
  62448. + /** Data size for pattern frame */
  62449. + uint32_t data_pattern_frame;
  62450. + /** Frame number of pattern data */
  62451. + uint32_t sync_frame;
  62452. +
  62453. + /** bInterval */
  62454. + uint32_t bInterval;
  62455. + /** ISO Packet number per frame */
  62456. + uint32_t pkt_per_frm;
  62457. + /** Next frame num for which will be setup DMA Desc */
  62458. + uint32_t next_frame;
  62459. + /** Number of packets per buffer processing */
  62460. + uint32_t pkt_cnt;
  62461. + /** Info for all isoc packets */
  62462. + iso_pkt_info_t *pkt_info;
  62463. + /** current pkt number */
  62464. + uint32_t cur_pkt;
  62465. + /** current pkt number */
  62466. + uint8_t *cur_pkt_addr;
  62467. + /** current pkt number */
  62468. + uint32_t cur_pkt_dma_addr;
  62469. +#endif /* DWC_EN_ISOC */
  62470. +
  62471. +/** @} */
  62472. +} dwc_ep_t;
  62473. +
  62474. +/*
  62475. + * Reasons for halting a host channel.
  62476. + */
  62477. +typedef enum dwc_otg_halt_status {
  62478. + DWC_OTG_HC_XFER_NO_HALT_STATUS,
  62479. + DWC_OTG_HC_XFER_COMPLETE,
  62480. + DWC_OTG_HC_XFER_URB_COMPLETE,
  62481. + DWC_OTG_HC_XFER_ACK,
  62482. + DWC_OTG_HC_XFER_NAK,
  62483. + DWC_OTG_HC_XFER_NYET,
  62484. + DWC_OTG_HC_XFER_STALL,
  62485. + DWC_OTG_HC_XFER_XACT_ERR,
  62486. + DWC_OTG_HC_XFER_FRAME_OVERRUN,
  62487. + DWC_OTG_HC_XFER_BABBLE_ERR,
  62488. + DWC_OTG_HC_XFER_DATA_TOGGLE_ERR,
  62489. + DWC_OTG_HC_XFER_AHB_ERR,
  62490. + DWC_OTG_HC_XFER_PERIODIC_INCOMPLETE,
  62491. + DWC_OTG_HC_XFER_URB_DEQUEUE
  62492. +} dwc_otg_halt_status_e;
  62493. +
  62494. +/**
  62495. + * Host channel descriptor. This structure represents the state of a single
  62496. + * host channel when acting in host mode. It contains the data items needed to
  62497. + * transfer packets to an endpoint via a host channel.
  62498. + */
  62499. +typedef struct dwc_hc {
  62500. + /** Host channel number used for register address lookup */
  62501. + uint8_t hc_num;
  62502. +
  62503. + /** Device to access */
  62504. + unsigned dev_addr:7;
  62505. +
  62506. + /** EP to access */
  62507. + unsigned ep_num:4;
  62508. +
  62509. + /** EP direction. 0: OUT, 1: IN */
  62510. + unsigned ep_is_in:1;
  62511. +
  62512. + /**
  62513. + * EP speed.
  62514. + * One of the following values:
  62515. + * - DWC_OTG_EP_SPEED_LOW
  62516. + * - DWC_OTG_EP_SPEED_FULL
  62517. + * - DWC_OTG_EP_SPEED_HIGH
  62518. + */
  62519. + unsigned speed:2;
  62520. +#define DWC_OTG_EP_SPEED_LOW 0
  62521. +#define DWC_OTG_EP_SPEED_FULL 1
  62522. +#define DWC_OTG_EP_SPEED_HIGH 2
  62523. +
  62524. + /**
  62525. + * Endpoint type.
  62526. + * One of the following values:
  62527. + * - DWC_OTG_EP_TYPE_CONTROL: 0
  62528. + * - DWC_OTG_EP_TYPE_ISOC: 1
  62529. + * - DWC_OTG_EP_TYPE_BULK: 2
  62530. + * - DWC_OTG_EP_TYPE_INTR: 3
  62531. + */
  62532. + unsigned ep_type:2;
  62533. +
  62534. + /** Max packet size in bytes */
  62535. + unsigned max_packet:11;
  62536. +
  62537. + /**
  62538. + * PID for initial transaction.
  62539. + * 0: DATA0,<br>
  62540. + * 1: DATA2,<br>
  62541. + * 2: DATA1,<br>
  62542. + * 3: MDATA (non-Control EP),
  62543. + * SETUP (Control EP)
  62544. + */
  62545. + unsigned data_pid_start:2;
  62546. +#define DWC_OTG_HC_PID_DATA0 0
  62547. +#define DWC_OTG_HC_PID_DATA2 1
  62548. +#define DWC_OTG_HC_PID_DATA1 2
  62549. +#define DWC_OTG_HC_PID_MDATA 3
  62550. +#define DWC_OTG_HC_PID_SETUP 3
  62551. +
  62552. + /** Number of periodic transactions per (micro)frame */
  62553. + unsigned multi_count:2;
  62554. +
  62555. + /** @name Transfer State */
  62556. + /** @{ */
  62557. +
  62558. + /** Pointer to the current transfer buffer position. */
  62559. + uint8_t *xfer_buff;
  62560. + /**
  62561. + * In Buffer DMA mode this buffer will be used
  62562. + * if xfer_buff is not DWORD aligned.
  62563. + */
  62564. + dwc_dma_t align_buff;
  62565. + /** Total number of bytes to transfer. */
  62566. + uint32_t xfer_len;
  62567. + /** Number of bytes transferred so far. */
  62568. + uint32_t xfer_count;
  62569. + /** Packet count at start of transfer.*/
  62570. + uint16_t start_pkt_count;
  62571. +
  62572. + /**
  62573. + * Flag to indicate whether the transfer has been started. Set to 1 if
  62574. + * it has been started, 0 otherwise.
  62575. + */
  62576. + uint8_t xfer_started;
  62577. +
  62578. + /**
  62579. + * Set to 1 to indicate that a PING request should be issued on this
  62580. + * channel. If 0, process normally.
  62581. + */
  62582. + uint8_t do_ping;
  62583. +
  62584. + /**
  62585. + * Set to 1 to indicate that the error count for this transaction is
  62586. + * non-zero. Set to 0 if the error count is 0.
  62587. + */
  62588. + uint8_t error_state;
  62589. +
  62590. + /**
  62591. + * Set to 1 to indicate that this channel should be halted the next
  62592. + * time a request is queued for the channel. This is necessary in
  62593. + * slave mode if no request queue space is available when an attempt
  62594. + * is made to halt the channel.
  62595. + */
  62596. + uint8_t halt_on_queue;
  62597. +
  62598. + /**
  62599. + * Set to 1 if the host channel has been halted, but the core is not
  62600. + * finished flushing queued requests. Otherwise 0.
  62601. + */
  62602. + uint8_t halt_pending;
  62603. +
  62604. + /**
  62605. + * Reason for halting the host channel.
  62606. + */
  62607. + dwc_otg_halt_status_e halt_status;
  62608. +
  62609. + /*
  62610. + * Split settings for the host channel
  62611. + */
  62612. + uint8_t do_split; /**< Enable split for the channel */
  62613. + uint8_t complete_split; /**< Enable complete split */
  62614. + uint8_t hub_addr; /**< Address of high speed hub */
  62615. +
  62616. + uint8_t port_addr; /**< Port of the low/full speed device */
  62617. + /** Split transaction position
  62618. + * One of the following values:
  62619. + * - DWC_HCSPLIT_XACTPOS_MID
  62620. + * - DWC_HCSPLIT_XACTPOS_BEGIN
  62621. + * - DWC_HCSPLIT_XACTPOS_END
  62622. + * - DWC_HCSPLIT_XACTPOS_ALL */
  62623. + uint8_t xact_pos;
  62624. +
  62625. + /** Set when the host channel does a short read. */
  62626. + uint8_t short_read;
  62627. +
  62628. + /**
  62629. + * Number of requests issued for this channel since it was assigned to
  62630. + * the current transfer (not counting PINGs).
  62631. + */
  62632. + uint8_t requests;
  62633. +
  62634. + /**
  62635. + * Queue Head for the transfer being processed by this channel.
  62636. + */
  62637. + struct dwc_otg_qh *qh;
  62638. +
  62639. + /** @} */
  62640. +
  62641. + /** Entry in list of host channels. */
  62642. + DWC_CIRCLEQ_ENTRY(dwc_hc) hc_list_entry;
  62643. +
  62644. + /** @name Descriptor DMA support */
  62645. + /** @{ */
  62646. +
  62647. + /** Number of Transfer Descriptors */
  62648. + uint16_t ntd;
  62649. +
  62650. + /** Descriptor List DMA address */
  62651. + dwc_dma_t desc_list_addr;
  62652. +
  62653. + /** Scheduling micro-frame bitmap. */
  62654. + uint8_t schinfo;
  62655. +
  62656. + /** @} */
  62657. +} dwc_hc_t;
  62658. +
  62659. +/**
  62660. + * The following parameters may be specified when starting the module. These
  62661. + * parameters define how the DWC_otg controller should be configured.
  62662. + */
  62663. +typedef struct dwc_otg_core_params {
  62664. + int32_t opt;
  62665. +
  62666. + /**
  62667. + * Specifies the OTG capabilities. The driver will automatically
  62668. + * detect the value for this parameter if none is specified.
  62669. + * 0 - HNP and SRP capable (default)
  62670. + * 1 - SRP Only capable
  62671. + * 2 - No HNP/SRP capable
  62672. + */
  62673. + int32_t otg_cap;
  62674. +
  62675. + /**
  62676. + * Specifies whether to use slave or DMA mode for accessing the data
  62677. + * FIFOs. The driver will automatically detect the value for this
  62678. + * parameter if none is specified.
  62679. + * 0 - Slave
  62680. + * 1 - DMA (default, if available)
  62681. + */
  62682. + int32_t dma_enable;
  62683. +
  62684. + /**
  62685. + * When DMA mode is enabled specifies whether to use address DMA or DMA
  62686. + * Descriptor mode for accessing the data FIFOs in device mode. The driver
  62687. + * will automatically detect the value for this if none is specified.
  62688. + * 0 - address DMA
  62689. + * 1 - DMA Descriptor(default, if available)
  62690. + */
  62691. + int32_t dma_desc_enable;
  62692. + /** The DMA Burst size (applicable only for External DMA
  62693. + * Mode). 1, 4, 8 16, 32, 64, 128, 256 (default 32)
  62694. + */
  62695. + int32_t dma_burst_size; /* Translate this to GAHBCFG values */
  62696. +
  62697. + /**
  62698. + * Specifies the maximum speed of operation in host and device mode.
  62699. + * The actual speed depends on the speed of the attached device and
  62700. + * the value of phy_type. The actual speed depends on the speed of the
  62701. + * attached device.
  62702. + * 0 - High Speed (default)
  62703. + * 1 - Full Speed
  62704. + */
  62705. + int32_t speed;
  62706. + /** Specifies whether low power mode is supported when attached
  62707. + * to a Full Speed or Low Speed device in host mode.
  62708. + * 0 - Don't support low power mode (default)
  62709. + * 1 - Support low power mode
  62710. + */
  62711. + int32_t host_support_fs_ls_low_power;
  62712. +
  62713. + /** Specifies the PHY clock rate in low power mode when connected to a
  62714. + * Low Speed device in host mode. This parameter is applicable only if
  62715. + * HOST_SUPPORT_FS_LS_LOW_POWER is enabled. If PHY_TYPE is set to FS
  62716. + * then defaults to 6 MHZ otherwise 48 MHZ.
  62717. + *
  62718. + * 0 - 48 MHz
  62719. + * 1 - 6 MHz
  62720. + */
  62721. + int32_t host_ls_low_power_phy_clk;
  62722. +
  62723. + /**
  62724. + * 0 - Use cC FIFO size parameters
  62725. + * 1 - Allow dynamic FIFO sizing (default)
  62726. + */
  62727. + int32_t enable_dynamic_fifo;
  62728. +
  62729. + /** Total number of 4-byte words in the data FIFO memory. This
  62730. + * memory includes the Rx FIFO, non-periodic Tx FIFO, and periodic
  62731. + * Tx FIFOs.
  62732. + * 32 to 32768 (default 8192)
  62733. + * Note: The total FIFO memory depth in the FPGA configuration is 8192.
  62734. + */
  62735. + int32_t data_fifo_size;
  62736. +
  62737. + /** Number of 4-byte words in the Rx FIFO in device mode when dynamic
  62738. + * FIFO sizing is enabled.
  62739. + * 16 to 32768 (default 1064)
  62740. + */
  62741. + int32_t dev_rx_fifo_size;
  62742. +
  62743. + /** Number of 4-byte words in the non-periodic Tx FIFO in device mode
  62744. + * when dynamic FIFO sizing is enabled.
  62745. + * 16 to 32768 (default 1024)
  62746. + */
  62747. + int32_t dev_nperio_tx_fifo_size;
  62748. +
  62749. + /** Number of 4-byte words in each of the periodic Tx FIFOs in device
  62750. + * mode when dynamic FIFO sizing is enabled.
  62751. + * 4 to 768 (default 256)
  62752. + */
  62753. + uint32_t dev_perio_tx_fifo_size[MAX_PERIO_FIFOS];
  62754. +
  62755. + /** Number of 4-byte words in the Rx FIFO in host mode when dynamic
  62756. + * FIFO sizing is enabled.
  62757. + * 16 to 32768 (default 1024)
  62758. + */
  62759. + int32_t host_rx_fifo_size;
  62760. +
  62761. + /** Number of 4-byte words in the non-periodic Tx FIFO in host mode
  62762. + * when Dynamic FIFO sizing is enabled in the core.
  62763. + * 16 to 32768 (default 1024)
  62764. + */
  62765. + int32_t host_nperio_tx_fifo_size;
  62766. +
  62767. + /** Number of 4-byte words in the host periodic Tx FIFO when dynamic
  62768. + * FIFO sizing is enabled.
  62769. + * 16 to 32768 (default 1024)
  62770. + */
  62771. + int32_t host_perio_tx_fifo_size;
  62772. +
  62773. + /** The maximum transfer size supported in bytes.
  62774. + * 2047 to 65,535 (default 65,535)
  62775. + */
  62776. + int32_t max_transfer_size;
  62777. +
  62778. + /** The maximum number of packets in a transfer.
  62779. + * 15 to 511 (default 511)
  62780. + */
  62781. + int32_t max_packet_count;
  62782. +
  62783. + /** The number of host channel registers to use.
  62784. + * 1 to 16 (default 12)
  62785. + * Note: The FPGA configuration supports a maximum of 12 host channels.
  62786. + */
  62787. + int32_t host_channels;
  62788. +
  62789. + /** The number of endpoints in addition to EP0 available for device
  62790. + * mode operations.
  62791. + * 1 to 15 (default 6 IN and OUT)
  62792. + * Note: The FPGA configuration supports a maximum of 6 IN and OUT
  62793. + * endpoints in addition to EP0.
  62794. + */
  62795. + int32_t dev_endpoints;
  62796. +
  62797. + /**
  62798. + * Specifies the type of PHY interface to use. By default, the driver
  62799. + * will automatically detect the phy_type.
  62800. + *
  62801. + * 0 - Full Speed PHY
  62802. + * 1 - UTMI+ (default)
  62803. + * 2 - ULPI
  62804. + */
  62805. + int32_t phy_type;
  62806. +
  62807. + /**
  62808. + * Specifies the UTMI+ Data Width. This parameter is
  62809. + * applicable for a PHY_TYPE of UTMI+ or ULPI. (For a ULPI
  62810. + * PHY_TYPE, this parameter indicates the data width between
  62811. + * the MAC and the ULPI Wrapper.) Also, this parameter is
  62812. + * applicable only if the OTG_HSPHY_WIDTH cC parameter was set
  62813. + * to "8 and 16 bits", meaning that the core has been
  62814. + * configured to work at either data path width.
  62815. + *
  62816. + * 8 or 16 bits (default 16)
  62817. + */
  62818. + int32_t phy_utmi_width;
  62819. +
  62820. + /**
  62821. + * Specifies whether the ULPI operates at double or single
  62822. + * data rate. This parameter is only applicable if PHY_TYPE is
  62823. + * ULPI.
  62824. + *
  62825. + * 0 - single data rate ULPI interface with 8 bit wide data
  62826. + * bus (default)
  62827. + * 1 - double data rate ULPI interface with 4 bit wide data
  62828. + * bus
  62829. + */
  62830. + int32_t phy_ulpi_ddr;
  62831. +
  62832. + /**
  62833. + * Specifies whether to use the internal or external supply to
  62834. + * drive the vbus with a ULPI phy.
  62835. + */
  62836. + int32_t phy_ulpi_ext_vbus;
  62837. +
  62838. + /**
  62839. + * Specifies whether to use the I2Cinterface for full speed PHY. This
  62840. + * parameter is only applicable if PHY_TYPE is FS.
  62841. + * 0 - No (default)
  62842. + * 1 - Yes
  62843. + */
  62844. + int32_t i2c_enable;
  62845. +
  62846. + int32_t ulpi_fs_ls;
  62847. +
  62848. + int32_t ts_dline;
  62849. +
  62850. + /**
  62851. + * Specifies whether dedicated transmit FIFOs are
  62852. + * enabled for non periodic IN endpoints in device mode
  62853. + * 0 - No
  62854. + * 1 - Yes
  62855. + */
  62856. + int32_t en_multiple_tx_fifo;
  62857. +
  62858. + /** Number of 4-byte words in each of the Tx FIFOs in device
  62859. + * mode when dynamic FIFO sizing is enabled.
  62860. + * 4 to 768 (default 256)
  62861. + */
  62862. + uint32_t dev_tx_fifo_size[MAX_TX_FIFOS];
  62863. +
  62864. + /** Thresholding enable flag-
  62865. + * bit 0 - enable non-ISO Tx thresholding
  62866. + * bit 1 - enable ISO Tx thresholding
  62867. + * bit 2 - enable Rx thresholding
  62868. + */
  62869. + uint32_t thr_ctl;
  62870. +
  62871. + /** Thresholding length for Tx
  62872. + * FIFOs in 32 bit DWORDs
  62873. + */
  62874. + uint32_t tx_thr_length;
  62875. +
  62876. + /** Thresholding length for Rx
  62877. + * FIFOs in 32 bit DWORDs
  62878. + */
  62879. + uint32_t rx_thr_length;
  62880. +
  62881. + /**
  62882. + * Specifies whether LPM (Link Power Management) support is enabled
  62883. + */
  62884. + int32_t lpm_enable;
  62885. +
  62886. + /** Per Transfer Interrupt
  62887. + * mode enable flag
  62888. + * 1 - Enabled
  62889. + * 0 - Disabled
  62890. + */
  62891. + int32_t pti_enable;
  62892. +
  62893. + /** Multi Processor Interrupt
  62894. + * mode enable flag
  62895. + * 1 - Enabled
  62896. + * 0 - Disabled
  62897. + */
  62898. + int32_t mpi_enable;
  62899. +
  62900. + /** IS_USB Capability
  62901. + * 1 - Enabled
  62902. + * 0 - Disabled
  62903. + */
  62904. + int32_t ic_usb_cap;
  62905. +
  62906. + /** AHB Threshold Ratio
  62907. + * 2'b00 AHB Threshold = MAC Threshold
  62908. + * 2'b01 AHB Threshold = 1/2 MAC Threshold
  62909. + * 2'b10 AHB Threshold = 1/4 MAC Threshold
  62910. + * 2'b11 AHB Threshold = 1/8 MAC Threshold
  62911. + */
  62912. + int32_t ahb_thr_ratio;
  62913. +
  62914. + /** ADP Support
  62915. + * 1 - Enabled
  62916. + * 0 - Disabled
  62917. + */
  62918. + int32_t adp_supp_enable;
  62919. +
  62920. + /** HFIR Reload Control
  62921. + * 0 - The HFIR cannot be reloaded dynamically.
  62922. + * 1 - Allow dynamic reloading of the HFIR register during runtime.
  62923. + */
  62924. + int32_t reload_ctl;
  62925. +
  62926. + /** DCFG: Enable device Out NAK
  62927. + * 0 - The core does not set NAK after Bulk Out transfer complete.
  62928. + * 1 - The core sets NAK after Bulk OUT transfer complete.
  62929. + */
  62930. + int32_t dev_out_nak;
  62931. +
  62932. + /** DCFG: Enable Continue on BNA
  62933. + * After receiving BNA interrupt the core disables the endpoint,when the
  62934. + * endpoint is re-enabled by the application the core starts processing
  62935. + * 0 - from the DOEPDMA descriptor
  62936. + * 1 - from the descriptor which received the BNA.
  62937. + */
  62938. + int32_t cont_on_bna;
  62939. +
  62940. + /** GAHBCFG: AHB Single Support
  62941. + * This bit when programmed supports SINGLE transfers for remainder
  62942. + * data in a transfer for DMA mode of operation.
  62943. + * 0 - in this case the remainder data will be sent using INCR burst size.
  62944. + * 1 - in this case the remainder data will be sent using SINGLE burst size.
  62945. + */
  62946. + int32_t ahb_single;
  62947. +
  62948. + /** Core Power down mode
  62949. + * 0 - No Power Down is enabled
  62950. + * 1 - Reserved
  62951. + * 2 - Complete Power Down (Hibernation)
  62952. + */
  62953. + int32_t power_down;
  62954. +
  62955. + /** OTG revision supported
  62956. + * 0 - OTG 1.3 revision
  62957. + * 1 - OTG 2.0 revision
  62958. + */
  62959. + int32_t otg_ver;
  62960. +
  62961. +} dwc_otg_core_params_t;
  62962. +
  62963. +#ifdef DEBUG
  62964. +struct dwc_otg_core_if;
  62965. +typedef struct hc_xfer_info {
  62966. + struct dwc_otg_core_if *core_if;
  62967. + dwc_hc_t *hc;
  62968. +} hc_xfer_info_t;
  62969. +#endif
  62970. +
  62971. +typedef struct ep_xfer_info {
  62972. + struct dwc_otg_core_if *core_if;
  62973. + dwc_ep_t *ep;
  62974. + uint8_t state;
  62975. +} ep_xfer_info_t;
  62976. +/*
  62977. + * Device States
  62978. + */
  62979. +typedef enum dwc_otg_lx_state {
  62980. + /** On state */
  62981. + DWC_OTG_L0,
  62982. + /** LPM sleep state*/
  62983. + DWC_OTG_L1,
  62984. + /** USB suspend state*/
  62985. + DWC_OTG_L2,
  62986. + /** Off state*/
  62987. + DWC_OTG_L3
  62988. +} dwc_otg_lx_state_e;
  62989. +
  62990. +struct dwc_otg_global_regs_backup {
  62991. + uint32_t gotgctl_local;
  62992. + uint32_t gintmsk_local;
  62993. + uint32_t gahbcfg_local;
  62994. + uint32_t gusbcfg_local;
  62995. + uint32_t grxfsiz_local;
  62996. + uint32_t gnptxfsiz_local;
  62997. +#ifdef CONFIG_USB_DWC_OTG_LPM
  62998. + uint32_t glpmcfg_local;
  62999. +#endif
  63000. + uint32_t gi2cctl_local;
  63001. + uint32_t hptxfsiz_local;
  63002. + uint32_t pcgcctl_local;
  63003. + uint32_t gdfifocfg_local;
  63004. + uint32_t dtxfsiz_local[MAX_EPS_CHANNELS];
  63005. + uint32_t gpwrdn_local;
  63006. + uint32_t xhib_pcgcctl;
  63007. + uint32_t xhib_gpwrdn;
  63008. +};
  63009. +
  63010. +struct dwc_otg_host_regs_backup {
  63011. + uint32_t hcfg_local;
  63012. + uint32_t haintmsk_local;
  63013. + uint32_t hcintmsk_local[MAX_EPS_CHANNELS];
  63014. + uint32_t hprt0_local;
  63015. + uint32_t hfir_local;
  63016. +};
  63017. +
  63018. +struct dwc_otg_dev_regs_backup {
  63019. + uint32_t dcfg;
  63020. + uint32_t dctl;
  63021. + uint32_t daintmsk;
  63022. + uint32_t diepmsk;
  63023. + uint32_t doepmsk;
  63024. + uint32_t diepctl[MAX_EPS_CHANNELS];
  63025. + uint32_t dieptsiz[MAX_EPS_CHANNELS];
  63026. + uint32_t diepdma[MAX_EPS_CHANNELS];
  63027. +};
  63028. +/**
  63029. + * The <code>dwc_otg_core_if</code> structure contains information needed to manage
  63030. + * the DWC_otg controller acting in either host or device mode. It
  63031. + * represents the programming view of the controller as a whole.
  63032. + */
  63033. +struct dwc_otg_core_if {
  63034. + /** Parameters that define how the core should be configured.*/
  63035. + dwc_otg_core_params_t *core_params;
  63036. +
  63037. + /** Core Global registers starting at offset 000h. */
  63038. + dwc_otg_core_global_regs_t *core_global_regs;
  63039. +
  63040. + /** Device-specific information */
  63041. + dwc_otg_dev_if_t *dev_if;
  63042. + /** Host-specific information */
  63043. + dwc_otg_host_if_t *host_if;
  63044. +
  63045. + /** Value from SNPSID register */
  63046. + uint32_t snpsid;
  63047. +
  63048. + /*
  63049. + * Set to 1 if the core PHY interface bits in USBCFG have been
  63050. + * initialized.
  63051. + */
  63052. + uint8_t phy_init_done;
  63053. +
  63054. + /*
  63055. + * SRP Success flag, set by srp success interrupt in FS I2C mode
  63056. + */
  63057. + uint8_t srp_success;
  63058. + uint8_t srp_timer_started;
  63059. + /** Timer for SRP. If it expires before SRP is successful
  63060. + * clear the SRP. */
  63061. + dwc_timer_t *srp_timer;
  63062. +
  63063. +#ifdef DWC_DEV_SRPCAP
  63064. + /* This timer is needed to power on the hibernated host core if SRP is not
  63065. + * initiated on connected SRP capable device for limited period of time
  63066. + */
  63067. + uint8_t pwron_timer_started;
  63068. + dwc_timer_t *pwron_timer;
  63069. +#endif
  63070. + /* Common configuration information */
  63071. + /** Power and Clock Gating Control Register */
  63072. + volatile uint32_t *pcgcctl;
  63073. +#define DWC_OTG_PCGCCTL_OFFSET 0xE00
  63074. +
  63075. + /** Push/pop addresses for endpoints or host channels.*/
  63076. + uint32_t *data_fifo[MAX_EPS_CHANNELS];
  63077. +#define DWC_OTG_DATA_FIFO_OFFSET 0x1000
  63078. +#define DWC_OTG_DATA_FIFO_SIZE 0x1000
  63079. +
  63080. + /** Total RAM for FIFOs (Bytes) */
  63081. + uint16_t total_fifo_size;
  63082. + /** Size of Rx FIFO (Bytes) */
  63083. + uint16_t rx_fifo_size;
  63084. + /** Size of Non-periodic Tx FIFO (Bytes) */
  63085. + uint16_t nperio_tx_fifo_size;
  63086. +
  63087. + /** 1 if DMA is enabled, 0 otherwise. */
  63088. + uint8_t dma_enable;
  63089. +
  63090. + /** 1 if DMA descriptor is enabled, 0 otherwise. */
  63091. + uint8_t dma_desc_enable;
  63092. +
  63093. + /** 1 if PTI Enhancement mode is enabled, 0 otherwise. */
  63094. + uint8_t pti_enh_enable;
  63095. +
  63096. + /** 1 if MPI Enhancement mode is enabled, 0 otherwise. */
  63097. + uint8_t multiproc_int_enable;
  63098. +
  63099. + /** 1 if dedicated Tx FIFOs are enabled, 0 otherwise. */
  63100. + uint8_t en_multiple_tx_fifo;
  63101. +
  63102. + /** Set to 1 if multiple packets of a high-bandwidth transfer is in
  63103. + * process of being queued */
  63104. + uint8_t queuing_high_bandwidth;
  63105. +
  63106. + /** Hardware Configuration -- stored here for convenience.*/
  63107. + hwcfg1_data_t hwcfg1;
  63108. + hwcfg2_data_t hwcfg2;
  63109. + hwcfg3_data_t hwcfg3;
  63110. + hwcfg4_data_t hwcfg4;
  63111. + fifosize_data_t hptxfsiz;
  63112. +
  63113. + /** Host and Device Configuration -- stored here for convenience.*/
  63114. + hcfg_data_t hcfg;
  63115. + dcfg_data_t dcfg;
  63116. +
  63117. + /** The operational State, during transations
  63118. + * (a_host>>a_peripherial and b_device=>b_host) this may not
  63119. + * match the core but allows the software to determine
  63120. + * transitions.
  63121. + */
  63122. + uint8_t op_state;
  63123. +
  63124. + /**
  63125. + * Set to 1 if the HCD needs to be restarted on a session request
  63126. + * interrupt. This is required if no connector ID status change has
  63127. + * occurred since the HCD was last disconnected.
  63128. + */
  63129. + uint8_t restart_hcd_on_session_req;
  63130. +
  63131. + /** HCD callbacks */
  63132. + /** A-Device is a_host */
  63133. +#define A_HOST (1)
  63134. + /** A-Device is a_suspend */
  63135. +#define A_SUSPEND (2)
  63136. + /** A-Device is a_peripherial */
  63137. +#define A_PERIPHERAL (3)
  63138. + /** B-Device is operating as a Peripheral. */
  63139. +#define B_PERIPHERAL (4)
  63140. + /** B-Device is operating as a Host. */
  63141. +#define B_HOST (5)
  63142. +
  63143. + /** HCD callbacks */
  63144. + struct dwc_otg_cil_callbacks *hcd_cb;
  63145. + /** PCD callbacks */
  63146. + struct dwc_otg_cil_callbacks *pcd_cb;
  63147. +
  63148. + /** Device mode Periodic Tx FIFO Mask */
  63149. + uint32_t p_tx_msk;
  63150. + /** Device mode Periodic Tx FIFO Mask */
  63151. + uint32_t tx_msk;
  63152. +
  63153. + /** Workqueue object used for handling several interrupts */
  63154. + dwc_workq_t *wq_otg;
  63155. +
  63156. + /** Timer object used for handling "Wakeup Detected" Interrupt */
  63157. + dwc_timer_t *wkp_timer;
  63158. + /** This arrays used for debug purposes for DEV OUT NAK enhancement */
  63159. + uint32_t start_doeptsiz_val[MAX_EPS_CHANNELS];
  63160. + ep_xfer_info_t ep_xfer_info[MAX_EPS_CHANNELS];
  63161. + dwc_timer_t *ep_xfer_timer[MAX_EPS_CHANNELS];
  63162. +#ifdef DEBUG
  63163. + uint32_t start_hcchar_val[MAX_EPS_CHANNELS];
  63164. +
  63165. + hc_xfer_info_t hc_xfer_info[MAX_EPS_CHANNELS];
  63166. + dwc_timer_t *hc_xfer_timer[MAX_EPS_CHANNELS];
  63167. +
  63168. + uint32_t hfnum_7_samples;
  63169. + uint64_t hfnum_7_frrem_accum;
  63170. + uint32_t hfnum_0_samples;
  63171. + uint64_t hfnum_0_frrem_accum;
  63172. + uint32_t hfnum_other_samples;
  63173. + uint64_t hfnum_other_frrem_accum;
  63174. +#endif
  63175. +
  63176. +#ifdef DWC_UTE_CFI
  63177. + uint16_t pwron_rxfsiz;
  63178. + uint16_t pwron_gnptxfsiz;
  63179. + uint16_t pwron_txfsiz[15];
  63180. +
  63181. + uint16_t init_rxfsiz;
  63182. + uint16_t init_gnptxfsiz;
  63183. + uint16_t init_txfsiz[15];
  63184. +#endif
  63185. +
  63186. + /** Lx state of device */
  63187. + dwc_otg_lx_state_e lx_state;
  63188. +
  63189. + /** Saved Core Global registers */
  63190. + struct dwc_otg_global_regs_backup *gr_backup;
  63191. + /** Saved Host registers */
  63192. + struct dwc_otg_host_regs_backup *hr_backup;
  63193. + /** Saved Device registers */
  63194. + struct dwc_otg_dev_regs_backup *dr_backup;
  63195. +
  63196. + /** Power Down Enable */
  63197. + uint32_t power_down;
  63198. +
  63199. + /** ADP support Enable */
  63200. + uint32_t adp_enable;
  63201. +
  63202. + /** ADP structure object */
  63203. + dwc_otg_adp_t adp;
  63204. +
  63205. + /** hibernation/suspend flag */
  63206. + int hibernation_suspend;
  63207. +
  63208. + /** Device mode extended hibernation flag */
  63209. + int xhib;
  63210. +
  63211. + /** OTG revision supported */
  63212. + uint32_t otg_ver;
  63213. +
  63214. + /** OTG status flag used for HNP polling */
  63215. + uint8_t otg_sts;
  63216. +
  63217. + /** Pointer to either hcd->lock or pcd->lock */
  63218. + dwc_spinlock_t *lock;
  63219. +
  63220. + /** Start predict NextEP based on Learning Queue if equal 1,
  63221. + * also used as counter of disabled NP IN EP's */
  63222. + uint8_t start_predict;
  63223. +
  63224. + /** NextEp sequence, including EP0: nextep_seq[] = EP if non-periodic and
  63225. + * active, 0xff otherwise */
  63226. + uint8_t nextep_seq[MAX_EPS_CHANNELS];
  63227. +
  63228. + /** Index of fisrt EP in nextep_seq array which should be re-enabled **/
  63229. + uint8_t first_in_nextep_seq;
  63230. +
  63231. + /** Frame number while entering to ISR - needed for ISOCs **/
  63232. + uint32_t frame_num;
  63233. +
  63234. +};
  63235. +
  63236. +#ifdef DEBUG
  63237. +/*
  63238. + * This function is called when transfer is timed out.
  63239. + */
  63240. +extern void hc_xfer_timeout(void *ptr);
  63241. +#endif
  63242. +
  63243. +/*
  63244. + * This function is called when transfer is timed out on endpoint.
  63245. + */
  63246. +extern void ep_xfer_timeout(void *ptr);
  63247. +
  63248. +/*
  63249. + * The following functions are functions for works
  63250. + * using during handling some interrupts
  63251. + */
  63252. +extern void w_conn_id_status_change(void *p);
  63253. +
  63254. +extern void w_wakeup_detected(void *p);
  63255. +
  63256. +/** Saves global register values into system memory. */
  63257. +extern int dwc_otg_save_global_regs(dwc_otg_core_if_t * core_if);
  63258. +/** Saves device register values into system memory. */
  63259. +extern int dwc_otg_save_dev_regs(dwc_otg_core_if_t * core_if);
  63260. +/** Saves host register values into system memory. */
  63261. +extern int dwc_otg_save_host_regs(dwc_otg_core_if_t * core_if);
  63262. +/** Restore global register values. */
  63263. +extern int dwc_otg_restore_global_regs(dwc_otg_core_if_t * core_if);
  63264. +/** Restore host register values. */
  63265. +extern int dwc_otg_restore_host_regs(dwc_otg_core_if_t * core_if, int reset);
  63266. +/** Restore device register values. */
  63267. +extern int dwc_otg_restore_dev_regs(dwc_otg_core_if_t * core_if,
  63268. + int rem_wakeup);
  63269. +extern int restore_lpm_i2c_regs(dwc_otg_core_if_t * core_if);
  63270. +extern int restore_essential_regs(dwc_otg_core_if_t * core_if, int rmode,
  63271. + int is_host);
  63272. +
  63273. +extern int dwc_otg_host_hibernation_restore(dwc_otg_core_if_t * core_if,
  63274. + int restore_mode, int reset);
  63275. +extern int dwc_otg_device_hibernation_restore(dwc_otg_core_if_t * core_if,
  63276. + int rem_wakeup, int reset);
  63277. +
  63278. +/*
  63279. + * The following functions support initialization of the CIL driver component
  63280. + * and the DWC_otg controller.
  63281. + */
  63282. +extern void dwc_otg_core_host_init(dwc_otg_core_if_t * _core_if);
  63283. +extern void dwc_otg_core_dev_init(dwc_otg_core_if_t * _core_if);
  63284. +
  63285. +/** @name Device CIL Functions
  63286. + * The following functions support managing the DWC_otg controller in device
  63287. + * mode.
  63288. + */
  63289. +/**@{*/
  63290. +extern void dwc_otg_wakeup(dwc_otg_core_if_t * _core_if);
  63291. +extern void dwc_otg_read_setup_packet(dwc_otg_core_if_t * _core_if,
  63292. + uint32_t * _dest);
  63293. +extern uint32_t dwc_otg_get_frame_number(dwc_otg_core_if_t * _core_if);
  63294. +extern void dwc_otg_ep0_activate(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
  63295. +extern void dwc_otg_ep_activate(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
  63296. +extern void dwc_otg_ep_deactivate(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
  63297. +extern void dwc_otg_ep_start_transfer(dwc_otg_core_if_t * _core_if,
  63298. + dwc_ep_t * _ep);
  63299. +extern void dwc_otg_ep_start_zl_transfer(dwc_otg_core_if_t * _core_if,
  63300. + dwc_ep_t * _ep);
  63301. +extern void dwc_otg_ep0_start_transfer(dwc_otg_core_if_t * _core_if,
  63302. + dwc_ep_t * _ep);
  63303. +extern void dwc_otg_ep0_continue_transfer(dwc_otg_core_if_t * _core_if,
  63304. + dwc_ep_t * _ep);
  63305. +extern void dwc_otg_ep_write_packet(dwc_otg_core_if_t * _core_if,
  63306. + dwc_ep_t * _ep, int _dma);
  63307. +extern void dwc_otg_ep_set_stall(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
  63308. +extern void dwc_otg_ep_clear_stall(dwc_otg_core_if_t * _core_if,
  63309. + dwc_ep_t * _ep);
  63310. +extern void dwc_otg_enable_device_interrupts(dwc_otg_core_if_t * _core_if);
  63311. +
  63312. +#ifdef DWC_EN_ISOC
  63313. +extern void dwc_otg_iso_ep_start_frm_transfer(dwc_otg_core_if_t * core_if,
  63314. + dwc_ep_t * ep);
  63315. +extern void dwc_otg_iso_ep_start_buf_transfer(dwc_otg_core_if_t * core_if,
  63316. + dwc_ep_t * ep);
  63317. +#endif /* DWC_EN_ISOC */
  63318. +/**@}*/
  63319. +
  63320. +/** @name Host CIL Functions
  63321. + * The following functions support managing the DWC_otg controller in host
  63322. + * mode.
  63323. + */
  63324. +/**@{*/
  63325. +extern void dwc_otg_hc_init(dwc_otg_core_if_t * _core_if, dwc_hc_t * _hc);
  63326. +extern void dwc_otg_hc_halt(dwc_otg_core_if_t * _core_if,
  63327. + dwc_hc_t * _hc, dwc_otg_halt_status_e _halt_status);
  63328. +extern void dwc_otg_hc_cleanup(dwc_otg_core_if_t * _core_if, dwc_hc_t * _hc);
  63329. +extern void dwc_otg_hc_start_transfer(dwc_otg_core_if_t * _core_if,
  63330. + dwc_hc_t * _hc);
  63331. +extern int dwc_otg_hc_continue_transfer(dwc_otg_core_if_t * _core_if,
  63332. + dwc_hc_t * _hc);
  63333. +extern void dwc_otg_hc_do_ping(dwc_otg_core_if_t * _core_if, dwc_hc_t * _hc);
  63334. +extern void dwc_otg_hc_write_packet(dwc_otg_core_if_t * _core_if,
  63335. + dwc_hc_t * _hc);
  63336. +extern void dwc_otg_enable_host_interrupts(dwc_otg_core_if_t * _core_if);
  63337. +extern void dwc_otg_disable_host_interrupts(dwc_otg_core_if_t * _core_if);
  63338. +
  63339. +extern void dwc_otg_hc_start_transfer_ddma(dwc_otg_core_if_t * core_if,
  63340. + dwc_hc_t * hc);
  63341. +
  63342. +extern uint32_t calc_frame_interval(dwc_otg_core_if_t * core_if);
  63343. +
  63344. +/* Macro used to clear one channel interrupt */
  63345. +#define clear_hc_int(_hc_regs_, _intr_) \
  63346. +do { \
  63347. + hcint_data_t hcint_clear = {.d32 = 0}; \
  63348. + hcint_clear.b._intr_ = 1; \
  63349. + DWC_WRITE_REG32(&(_hc_regs_)->hcint, hcint_clear.d32); \
  63350. +} while (0)
  63351. +
  63352. +/*
  63353. + * Macro used to disable one channel interrupt. Channel interrupts are
  63354. + * disabled when the channel is halted or released by the interrupt handler.
  63355. + * There is no need to handle further interrupts of that type until the
  63356. + * channel is re-assigned. In fact, subsequent handling may cause crashes
  63357. + * because the channel structures are cleaned up when the channel is released.
  63358. + */
  63359. +#define disable_hc_int(_hc_regs_, _intr_) \
  63360. +do { \
  63361. + hcintmsk_data_t hcintmsk = {.d32 = 0}; \
  63362. + hcintmsk.b._intr_ = 1; \
  63363. + DWC_MODIFY_REG32(&(_hc_regs_)->hcintmsk, hcintmsk.d32, 0); \
  63364. +} while (0)
  63365. +
  63366. +/**
  63367. + * This function Reads HPRT0 in preparation to modify. It keeps the
  63368. + * WC bits 0 so that if they are read as 1, they won't clear when you
  63369. + * write it back
  63370. + */
  63371. +static inline uint32_t dwc_otg_read_hprt0(dwc_otg_core_if_t * _core_if)
  63372. +{
  63373. + hprt0_data_t hprt0;
  63374. + hprt0.d32 = DWC_READ_REG32(_core_if->host_if->hprt0);
  63375. + hprt0.b.prtena = 0;
  63376. + hprt0.b.prtconndet = 0;
  63377. + hprt0.b.prtenchng = 0;
  63378. + hprt0.b.prtovrcurrchng = 0;
  63379. + return hprt0.d32;
  63380. +}
  63381. +
  63382. +/**@}*/
  63383. +
  63384. +/** @name Common CIL Functions
  63385. + * The following functions support managing the DWC_otg controller in either
  63386. + * device or host mode.
  63387. + */
  63388. +/**@{*/
  63389. +
  63390. +extern void dwc_otg_read_packet(dwc_otg_core_if_t * core_if,
  63391. + uint8_t * dest, uint16_t bytes);
  63392. +
  63393. +extern void dwc_otg_flush_tx_fifo(dwc_otg_core_if_t * _core_if, const int _num);
  63394. +extern void dwc_otg_flush_rx_fifo(dwc_otg_core_if_t * _core_if);
  63395. +extern void dwc_otg_core_reset(dwc_otg_core_if_t * _core_if);
  63396. +
  63397. +/**
  63398. + * This function returns the Core Interrupt register.
  63399. + */
  63400. +static inline uint32_t dwc_otg_read_core_intr(dwc_otg_core_if_t * core_if)
  63401. +{
  63402. + return (DWC_READ_REG32(&core_if->core_global_regs->gintsts) &
  63403. + DWC_READ_REG32(&core_if->core_global_regs->gintmsk));
  63404. +}
  63405. +
  63406. +/**
  63407. + * This function returns the OTG Interrupt register.
  63408. + */
  63409. +static inline uint32_t dwc_otg_read_otg_intr(dwc_otg_core_if_t * core_if)
  63410. +{
  63411. + return (DWC_READ_REG32(&core_if->core_global_regs->gotgint));
  63412. +}
  63413. +
  63414. +/**
  63415. + * This function reads the Device All Endpoints Interrupt register and
  63416. + * returns the IN endpoint interrupt bits.
  63417. + */
  63418. +static inline uint32_t dwc_otg_read_dev_all_in_ep_intr(dwc_otg_core_if_t *
  63419. + core_if)
  63420. +{
  63421. +
  63422. + uint32_t v;
  63423. +
  63424. + if (core_if->multiproc_int_enable) {
  63425. + v = DWC_READ_REG32(&core_if->dev_if->
  63426. + dev_global_regs->deachint) &
  63427. + DWC_READ_REG32(&core_if->
  63428. + dev_if->dev_global_regs->deachintmsk);
  63429. + } else {
  63430. + v = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daint) &
  63431. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daintmsk);
  63432. + }
  63433. + return (v & 0xffff);
  63434. +}
  63435. +
  63436. +/**
  63437. + * This function reads the Device All Endpoints Interrupt register and
  63438. + * returns the OUT endpoint interrupt bits.
  63439. + */
  63440. +static inline uint32_t dwc_otg_read_dev_all_out_ep_intr(dwc_otg_core_if_t *
  63441. + core_if)
  63442. +{
  63443. + uint32_t v;
  63444. +
  63445. + if (core_if->multiproc_int_enable) {
  63446. + v = DWC_READ_REG32(&core_if->dev_if->
  63447. + dev_global_regs->deachint) &
  63448. + DWC_READ_REG32(&core_if->
  63449. + dev_if->dev_global_regs->deachintmsk);
  63450. + } else {
  63451. + v = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daint) &
  63452. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daintmsk);
  63453. + }
  63454. +
  63455. + return ((v & 0xffff0000) >> 16);
  63456. +}
  63457. +
  63458. +/**
  63459. + * This function returns the Device IN EP Interrupt register
  63460. + */
  63461. +static inline uint32_t dwc_otg_read_dev_in_ep_intr(dwc_otg_core_if_t * core_if,
  63462. + dwc_ep_t * ep)
  63463. +{
  63464. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  63465. + uint32_t v, msk, emp;
  63466. +
  63467. + if (core_if->multiproc_int_enable) {
  63468. + msk =
  63469. + DWC_READ_REG32(&dev_if->
  63470. + dev_global_regs->diepeachintmsk[ep->num]);
  63471. + emp =
  63472. + DWC_READ_REG32(&dev_if->
  63473. + dev_global_regs->dtknqr4_fifoemptymsk);
  63474. + msk |= ((emp >> ep->num) & 0x1) << 7;
  63475. + v = DWC_READ_REG32(&dev_if->in_ep_regs[ep->num]->diepint) & msk;
  63476. + } else {
  63477. + msk = DWC_READ_REG32(&dev_if->dev_global_regs->diepmsk);
  63478. + emp =
  63479. + DWC_READ_REG32(&dev_if->
  63480. + dev_global_regs->dtknqr4_fifoemptymsk);
  63481. + msk |= ((emp >> ep->num) & 0x1) << 7;
  63482. + v = DWC_READ_REG32(&dev_if->in_ep_regs[ep->num]->diepint) & msk;
  63483. + }
  63484. +
  63485. + return v;
  63486. +}
  63487. +
  63488. +/**
  63489. + * This function returns the Device OUT EP Interrupt register
  63490. + */
  63491. +static inline uint32_t dwc_otg_read_dev_out_ep_intr(dwc_otg_core_if_t *
  63492. + _core_if, dwc_ep_t * _ep)
  63493. +{
  63494. + dwc_otg_dev_if_t *dev_if = _core_if->dev_if;
  63495. + uint32_t v;
  63496. + doepmsk_data_t msk = {.d32 = 0 };
  63497. +
  63498. + if (_core_if->multiproc_int_enable) {
  63499. + msk.d32 =
  63500. + DWC_READ_REG32(&dev_if->
  63501. + dev_global_regs->doepeachintmsk[_ep->num]);
  63502. + if (_core_if->pti_enh_enable) {
  63503. + msk.b.pktdrpsts = 1;
  63504. + }
  63505. + v = DWC_READ_REG32(&dev_if->
  63506. + out_ep_regs[_ep->num]->doepint) & msk.d32;
  63507. + } else {
  63508. + msk.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->doepmsk);
  63509. + if (_core_if->pti_enh_enable) {
  63510. + msk.b.pktdrpsts = 1;
  63511. + }
  63512. + v = DWC_READ_REG32(&dev_if->
  63513. + out_ep_regs[_ep->num]->doepint) & msk.d32;
  63514. + }
  63515. + return v;
  63516. +}
  63517. +
  63518. +/**
  63519. + * This function returns the Host All Channel Interrupt register
  63520. + */
  63521. +static inline uint32_t dwc_otg_read_host_all_channels_intr(dwc_otg_core_if_t *
  63522. + _core_if)
  63523. +{
  63524. + return (DWC_READ_REG32(&_core_if->host_if->host_global_regs->haint));
  63525. +}
  63526. +
  63527. +static inline uint32_t dwc_otg_read_host_channel_intr(dwc_otg_core_if_t *
  63528. + _core_if, dwc_hc_t * _hc)
  63529. +{
  63530. + return (DWC_READ_REG32
  63531. + (&_core_if->host_if->hc_regs[_hc->hc_num]->hcint));
  63532. +}
  63533. +
  63534. +/**
  63535. + * This function returns the mode of the operation, host or device.
  63536. + *
  63537. + * @return 0 - Device Mode, 1 - Host Mode
  63538. + */
  63539. +static inline uint32_t dwc_otg_mode(dwc_otg_core_if_t * _core_if)
  63540. +{
  63541. + return (DWC_READ_REG32(&_core_if->core_global_regs->gintsts) & 0x1);
  63542. +}
  63543. +
  63544. +/**@}*/
  63545. +
  63546. +/**
  63547. + * DWC_otg CIL callback structure. This structure allows the HCD and
  63548. + * PCD to register functions used for starting and stopping the PCD
  63549. + * and HCD for role change on for a DRD.
  63550. + */
  63551. +typedef struct dwc_otg_cil_callbacks {
  63552. + /** Start function for role change */
  63553. + int (*start) (void *_p);
  63554. + /** Stop Function for role change */
  63555. + int (*stop) (void *_p);
  63556. + /** Disconnect Function for role change */
  63557. + int (*disconnect) (void *_p);
  63558. + /** Resume/Remote wakeup Function */
  63559. + int (*resume_wakeup) (void *_p);
  63560. + /** Suspend function */
  63561. + int (*suspend) (void *_p);
  63562. + /** Session Start (SRP) */
  63563. + int (*session_start) (void *_p);
  63564. +#ifdef CONFIG_USB_DWC_OTG_LPM
  63565. + /** Sleep (switch to L0 state) */
  63566. + int (*sleep) (void *_p);
  63567. +#endif
  63568. + /** Pointer passed to start() and stop() */
  63569. + void *p;
  63570. +} dwc_otg_cil_callbacks_t;
  63571. +
  63572. +extern void dwc_otg_cil_register_pcd_callbacks(dwc_otg_core_if_t * _core_if,
  63573. + dwc_otg_cil_callbacks_t * _cb,
  63574. + void *_p);
  63575. +extern void dwc_otg_cil_register_hcd_callbacks(dwc_otg_core_if_t * _core_if,
  63576. + dwc_otg_cil_callbacks_t * _cb,
  63577. + void *_p);
  63578. +
  63579. +void dwc_otg_initiate_srp(dwc_otg_core_if_t * core_if);
  63580. +
  63581. +//////////////////////////////////////////////////////////////////////
  63582. +/** Start the HCD. Helper function for using the HCD callbacks.
  63583. + *
  63584. + * @param core_if Programming view of DWC_otg controller.
  63585. + */
  63586. +static inline void cil_hcd_start(dwc_otg_core_if_t * core_if)
  63587. +{
  63588. + if (core_if->hcd_cb && core_if->hcd_cb->start) {
  63589. + core_if->hcd_cb->start(core_if->hcd_cb->p);
  63590. + }
  63591. +}
  63592. +
  63593. +/** Stop the HCD. Helper function for using the HCD callbacks.
  63594. + *
  63595. + * @param core_if Programming view of DWC_otg controller.
  63596. + */
  63597. +static inline void cil_hcd_stop(dwc_otg_core_if_t * core_if)
  63598. +{
  63599. + if (core_if->hcd_cb && core_if->hcd_cb->stop) {
  63600. + core_if->hcd_cb->stop(core_if->hcd_cb->p);
  63601. + }
  63602. +}
  63603. +
  63604. +/** Disconnect the HCD. Helper function for using the HCD callbacks.
  63605. + *
  63606. + * @param core_if Programming view of DWC_otg controller.
  63607. + */
  63608. +static inline void cil_hcd_disconnect(dwc_otg_core_if_t * core_if)
  63609. +{
  63610. + if (core_if->hcd_cb && core_if->hcd_cb->disconnect) {
  63611. + core_if->hcd_cb->disconnect(core_if->hcd_cb->p);
  63612. + }
  63613. +}
  63614. +
  63615. +/** Inform the HCD the a New Session has begun. Helper function for
  63616. + * using the HCD callbacks.
  63617. + *
  63618. + * @param core_if Programming view of DWC_otg controller.
  63619. + */
  63620. +static inline void cil_hcd_session_start(dwc_otg_core_if_t * core_if)
  63621. +{
  63622. + if (core_if->hcd_cb && core_if->hcd_cb->session_start) {
  63623. + core_if->hcd_cb->session_start(core_if->hcd_cb->p);
  63624. + }
  63625. +}
  63626. +
  63627. +#ifdef CONFIG_USB_DWC_OTG_LPM
  63628. +/**
  63629. + * Inform the HCD about LPM sleep.
  63630. + * Helper function for using the HCD callbacks.
  63631. + *
  63632. + * @param core_if Programming view of DWC_otg controller.
  63633. + */
  63634. +static inline void cil_hcd_sleep(dwc_otg_core_if_t * core_if)
  63635. +{
  63636. + if (core_if->hcd_cb && core_if->hcd_cb->sleep) {
  63637. + core_if->hcd_cb->sleep(core_if->hcd_cb->p);
  63638. + }
  63639. +}
  63640. +#endif
  63641. +
  63642. +/** Resume the HCD. Helper function for using the HCD callbacks.
  63643. + *
  63644. + * @param core_if Programming view of DWC_otg controller.
  63645. + */
  63646. +static inline void cil_hcd_resume(dwc_otg_core_if_t * core_if)
  63647. +{
  63648. + if (core_if->hcd_cb && core_if->hcd_cb->resume_wakeup) {
  63649. + core_if->hcd_cb->resume_wakeup(core_if->hcd_cb->p);
  63650. + }
  63651. +}
  63652. +
  63653. +/** Start the PCD. Helper function for using the PCD callbacks.
  63654. + *
  63655. + * @param core_if Programming view of DWC_otg controller.
  63656. + */
  63657. +static inline void cil_pcd_start(dwc_otg_core_if_t * core_if)
  63658. +{
  63659. + if (core_if->pcd_cb && core_if->pcd_cb->start) {
  63660. + core_if->pcd_cb->start(core_if->pcd_cb->p);
  63661. + }
  63662. +}
  63663. +
  63664. +/** Stop the PCD. Helper function for using the PCD callbacks.
  63665. + *
  63666. + * @param core_if Programming view of DWC_otg controller.
  63667. + */
  63668. +static inline void cil_pcd_stop(dwc_otg_core_if_t * core_if)
  63669. +{
  63670. + if (core_if->pcd_cb && core_if->pcd_cb->stop) {
  63671. + core_if->pcd_cb->stop(core_if->pcd_cb->p);
  63672. + }
  63673. +}
  63674. +
  63675. +/** Suspend the PCD. Helper function for using the PCD callbacks.
  63676. + *
  63677. + * @param core_if Programming view of DWC_otg controller.
  63678. + */
  63679. +static inline void cil_pcd_suspend(dwc_otg_core_if_t * core_if)
  63680. +{
  63681. + if (core_if->pcd_cb && core_if->pcd_cb->suspend) {
  63682. + core_if->pcd_cb->suspend(core_if->pcd_cb->p);
  63683. + }
  63684. +}
  63685. +
  63686. +/** Resume the PCD. Helper function for using the PCD callbacks.
  63687. + *
  63688. + * @param core_if Programming view of DWC_otg controller.
  63689. + */
  63690. +static inline void cil_pcd_resume(dwc_otg_core_if_t * core_if)
  63691. +{
  63692. + if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
  63693. + core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
  63694. + }
  63695. +}
  63696. +
  63697. +//////////////////////////////////////////////////////////////////////
  63698. +
  63699. +#endif
  63700. diff -Nur linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c
  63701. --- linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c 1970-01-01 01:00:00.000000000 +0100
  63702. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c 2014-04-24 15:37:13.310990489 +0200
  63703. @@ -0,0 +1,1595 @@
  63704. +/* ==========================================================================
  63705. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_cil_intr.c $
  63706. + * $Revision: #32 $
  63707. + * $Date: 2012/08/10 $
  63708. + * $Change: 2047372 $
  63709. + *
  63710. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  63711. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  63712. + * otherwise expressly agreed to in writing between Synopsys and you.
  63713. + *
  63714. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  63715. + * any End User Software License Agreement or Agreement for Licensed Product
  63716. + * with Synopsys or any supplement thereto. You are permitted to use and
  63717. + * redistribute this Software in source and binary forms, with or without
  63718. + * modification, provided that redistributions of source code must retain this
  63719. + * notice. You may not view, use, disclose, copy or distribute this file or
  63720. + * any information contained herein except pursuant to this license grant from
  63721. + * Synopsys. If you do not agree with this notice, including the disclaimer
  63722. + * below, then you are not authorized to use the Software.
  63723. + *
  63724. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  63725. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  63726. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  63727. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  63728. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  63729. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  63730. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  63731. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  63732. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  63733. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  63734. + * DAMAGE.
  63735. + * ========================================================================== */
  63736. +
  63737. +/** @file
  63738. + *
  63739. + * The Core Interface Layer provides basic services for accessing and
  63740. + * managing the DWC_otg hardware. These services are used by both the
  63741. + * Host Controller Driver and the Peripheral Controller Driver.
  63742. + *
  63743. + * This file contains the Common Interrupt handlers.
  63744. + */
  63745. +#include "dwc_os.h"
  63746. +#include "dwc_otg_regs.h"
  63747. +#include "dwc_otg_cil.h"
  63748. +#include "dwc_otg_driver.h"
  63749. +#include "dwc_otg_pcd.h"
  63750. +#include "dwc_otg_hcd.h"
  63751. +
  63752. +#ifdef DEBUG
  63753. +inline const char *op_state_str(dwc_otg_core_if_t * core_if)
  63754. +{
  63755. + return (core_if->op_state == A_HOST ? "a_host" :
  63756. + (core_if->op_state == A_SUSPEND ? "a_suspend" :
  63757. + (core_if->op_state == A_PERIPHERAL ? "a_peripheral" :
  63758. + (core_if->op_state == B_PERIPHERAL ? "b_peripheral" :
  63759. + (core_if->op_state == B_HOST ? "b_host" : "unknown")))));
  63760. +}
  63761. +#endif
  63762. +
  63763. +/** This function will log a debug message
  63764. + *
  63765. + * @param core_if Programming view of DWC_otg controller.
  63766. + */
  63767. +int32_t dwc_otg_handle_mode_mismatch_intr(dwc_otg_core_if_t * core_if)
  63768. +{
  63769. + gintsts_data_t gintsts;
  63770. + DWC_WARN("Mode Mismatch Interrupt: currently in %s mode\n",
  63771. + dwc_otg_mode(core_if) ? "Host" : "Device");
  63772. +
  63773. + /* Clear interrupt */
  63774. + gintsts.d32 = 0;
  63775. + gintsts.b.modemismatch = 1;
  63776. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  63777. + return 1;
  63778. +}
  63779. +
  63780. +/**
  63781. + * This function handles the OTG Interrupts. It reads the OTG
  63782. + * Interrupt Register (GOTGINT) to determine what interrupt has
  63783. + * occurred.
  63784. + *
  63785. + * @param core_if Programming view of DWC_otg controller.
  63786. + */
  63787. +int32_t dwc_otg_handle_otg_intr(dwc_otg_core_if_t * core_if)
  63788. +{
  63789. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  63790. + gotgint_data_t gotgint;
  63791. + gotgctl_data_t gotgctl;
  63792. + gintmsk_data_t gintmsk;
  63793. + gpwrdn_data_t gpwrdn;
  63794. +
  63795. + gotgint.d32 = DWC_READ_REG32(&global_regs->gotgint);
  63796. + gotgctl.d32 = DWC_READ_REG32(&global_regs->gotgctl);
  63797. + DWC_DEBUGPL(DBG_CIL, "++OTG Interrupt gotgint=%0x [%s]\n", gotgint.d32,
  63798. + op_state_str(core_if));
  63799. +
  63800. + if (gotgint.b.sesenddet) {
  63801. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
  63802. + "Session End Detected++ (%s)\n",
  63803. + op_state_str(core_if));
  63804. + gotgctl.d32 = DWC_READ_REG32(&global_regs->gotgctl);
  63805. +
  63806. + if (core_if->op_state == B_HOST) {
  63807. + cil_pcd_start(core_if);
  63808. + core_if->op_state = B_PERIPHERAL;
  63809. + } else {
  63810. + /* If not B_HOST and Device HNP still set. HNP
  63811. + * Did not succeed!*/
  63812. + if (gotgctl.b.devhnpen) {
  63813. + DWC_DEBUGPL(DBG_ANY, "Session End Detected\n");
  63814. + __DWC_ERROR("Device Not Connected/Responding!\n");
  63815. + }
  63816. +
  63817. + /* If Session End Detected the B-Cable has
  63818. + * been disconnected. */
  63819. + /* Reset PCD and Gadget driver to a
  63820. + * clean state. */
  63821. + core_if->lx_state = DWC_OTG_L0;
  63822. + DWC_SPINUNLOCK(core_if->lock);
  63823. + cil_pcd_stop(core_if);
  63824. + DWC_SPINLOCK(core_if->lock);
  63825. +
  63826. + if (core_if->adp_enable) {
  63827. + if (core_if->power_down == 2) {
  63828. + gpwrdn.d32 = 0;
  63829. + gpwrdn.b.pwrdnswtch = 1;
  63830. + DWC_MODIFY_REG32(&core_if->
  63831. + core_global_regs->
  63832. + gpwrdn, gpwrdn.d32, 0);
  63833. + }
  63834. +
  63835. + gpwrdn.d32 = 0;
  63836. + gpwrdn.b.pmuintsel = 1;
  63837. + gpwrdn.b.pmuactv = 1;
  63838. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  63839. + gpwrdn, 0, gpwrdn.d32);
  63840. +
  63841. + dwc_otg_adp_sense_start(core_if);
  63842. + }
  63843. + }
  63844. +
  63845. + gotgctl.d32 = 0;
  63846. + gotgctl.b.devhnpen = 1;
  63847. + DWC_MODIFY_REG32(&global_regs->gotgctl, gotgctl.d32, 0);
  63848. + }
  63849. + if (gotgint.b.sesreqsucstschng) {
  63850. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
  63851. + "Session Reqeust Success Status Change++\n");
  63852. + gotgctl.d32 = DWC_READ_REG32(&global_regs->gotgctl);
  63853. + if (gotgctl.b.sesreqscs) {
  63854. +
  63855. + if ((core_if->core_params->phy_type ==
  63856. + DWC_PHY_TYPE_PARAM_FS) && (core_if->core_params->i2c_enable)) {
  63857. + core_if->srp_success = 1;
  63858. + } else {
  63859. + DWC_SPINUNLOCK(core_if->lock);
  63860. + cil_pcd_resume(core_if);
  63861. + DWC_SPINLOCK(core_if->lock);
  63862. + /* Clear Session Request */
  63863. + gotgctl.d32 = 0;
  63864. + gotgctl.b.sesreq = 1;
  63865. + DWC_MODIFY_REG32(&global_regs->gotgctl,
  63866. + gotgctl.d32, 0);
  63867. + }
  63868. + }
  63869. + }
  63870. + if (gotgint.b.hstnegsucstschng) {
  63871. + /* Print statements during the HNP interrupt handling
  63872. + * can cause it to fail.*/
  63873. + gotgctl.d32 = DWC_READ_REG32(&global_regs->gotgctl);
  63874. + /* WA for 3.00a- HW is not setting cur_mode, even sometimes
  63875. + * this does not help*/
  63876. + if (core_if->snpsid >= OTG_CORE_REV_3_00a)
  63877. + dwc_udelay(100);
  63878. + if (gotgctl.b.hstnegscs) {
  63879. + if (dwc_otg_is_host_mode(core_if)) {
  63880. + core_if->op_state = B_HOST;
  63881. + /*
  63882. + * Need to disable SOF interrupt immediately.
  63883. + * When switching from device to host, the PCD
  63884. + * interrupt handler won't handle the
  63885. + * interrupt if host mode is already set. The
  63886. + * HCD interrupt handler won't get called if
  63887. + * the HCD state is HALT. This means that the
  63888. + * interrupt does not get handled and Linux
  63889. + * complains loudly.
  63890. + */
  63891. + gintmsk.d32 = 0;
  63892. + gintmsk.b.sofintr = 1;
  63893. + DWC_MODIFY_REG32(&global_regs->gintmsk,
  63894. + gintmsk.d32, 0);
  63895. + /* Call callback function with spin lock released */
  63896. + DWC_SPINUNLOCK(core_if->lock);
  63897. + cil_pcd_stop(core_if);
  63898. + /*
  63899. + * Initialize the Core for Host mode.
  63900. + */
  63901. + cil_hcd_start(core_if);
  63902. + DWC_SPINLOCK(core_if->lock);
  63903. + core_if->op_state = B_HOST;
  63904. + }
  63905. + } else {
  63906. + gotgctl.d32 = 0;
  63907. + gotgctl.b.hnpreq = 1;
  63908. + gotgctl.b.devhnpen = 1;
  63909. + DWC_MODIFY_REG32(&global_regs->gotgctl, gotgctl.d32, 0);
  63910. + DWC_DEBUGPL(DBG_ANY, "HNP Failed\n");
  63911. + __DWC_ERROR("Device Not Connected/Responding\n");
  63912. + }
  63913. + }
  63914. + if (gotgint.b.hstnegdet) {
  63915. + /* The disconnect interrupt is set at the same time as
  63916. + * Host Negotiation Detected. During the mode
  63917. + * switch all interrupts are cleared so the disconnect
  63918. + * interrupt handler will not get executed.
  63919. + */
  63920. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
  63921. + "Host Negotiation Detected++ (%s)\n",
  63922. + (dwc_otg_is_host_mode(core_if) ? "Host" :
  63923. + "Device"));
  63924. + if (dwc_otg_is_device_mode(core_if)) {
  63925. + DWC_DEBUGPL(DBG_ANY, "a_suspend->a_peripheral (%d)\n",
  63926. + core_if->op_state);
  63927. + DWC_SPINUNLOCK(core_if->lock);
  63928. + cil_hcd_disconnect(core_if);
  63929. + cil_pcd_start(core_if);
  63930. + DWC_SPINLOCK(core_if->lock);
  63931. + core_if->op_state = A_PERIPHERAL;
  63932. + } else {
  63933. + /*
  63934. + * Need to disable SOF interrupt immediately. When
  63935. + * switching from device to host, the PCD interrupt
  63936. + * handler won't handle the interrupt if host mode is
  63937. + * already set. The HCD interrupt handler won't get
  63938. + * called if the HCD state is HALT. This means that
  63939. + * the interrupt does not get handled and Linux
  63940. + * complains loudly.
  63941. + */
  63942. + gintmsk.d32 = 0;
  63943. + gintmsk.b.sofintr = 1;
  63944. + DWC_MODIFY_REG32(&global_regs->gintmsk, gintmsk.d32, 0);
  63945. + DWC_SPINUNLOCK(core_if->lock);
  63946. + cil_pcd_stop(core_if);
  63947. + cil_hcd_start(core_if);
  63948. + DWC_SPINLOCK(core_if->lock);
  63949. + core_if->op_state = A_HOST;
  63950. + }
  63951. + }
  63952. + if (gotgint.b.adevtoutchng) {
  63953. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
  63954. + "A-Device Timeout Change++\n");
  63955. + }
  63956. + if (gotgint.b.debdone) {
  63957. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: " "Debounce Done++\n");
  63958. + }
  63959. +
  63960. + /* Clear GOTGINT */
  63961. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgint, gotgint.d32);
  63962. +
  63963. + return 1;
  63964. +}
  63965. +
  63966. +void w_conn_id_status_change(void *p)
  63967. +{
  63968. + dwc_otg_core_if_t *core_if = p;
  63969. + uint32_t count = 0;
  63970. + gotgctl_data_t gotgctl = {.d32 = 0 };
  63971. +
  63972. + gotgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  63973. + DWC_DEBUGPL(DBG_CIL, "gotgctl=%0x\n", gotgctl.d32);
  63974. + DWC_DEBUGPL(DBG_CIL, "gotgctl.b.conidsts=%d\n", gotgctl.b.conidsts);
  63975. +
  63976. + /* B-Device connector (Device Mode) */
  63977. + if (gotgctl.b.conidsts) {
  63978. + /* Wait for switch to device mode. */
  63979. + while (!dwc_otg_is_device_mode(core_if)) {
  63980. + DWC_PRINTF("Waiting for Peripheral Mode, Mode=%s\n",
  63981. + (dwc_otg_is_host_mode(core_if) ? "Host" :
  63982. + "Peripheral"));
  63983. + dwc_mdelay(100);
  63984. + if (++count > 10000)
  63985. + break;
  63986. + }
  63987. + DWC_ASSERT(++count < 10000,
  63988. + "Connection id status change timed out");
  63989. + core_if->op_state = B_PERIPHERAL;
  63990. + dwc_otg_core_init(core_if);
  63991. + dwc_otg_enable_global_interrupts(core_if);
  63992. + cil_pcd_start(core_if);
  63993. + } else {
  63994. + /* A-Device connector (Host Mode) */
  63995. + while (!dwc_otg_is_host_mode(core_if)) {
  63996. + DWC_PRINTF("Waiting for Host Mode, Mode=%s\n",
  63997. + (dwc_otg_is_host_mode(core_if) ? "Host" :
  63998. + "Peripheral"));
  63999. + dwc_mdelay(100);
  64000. + if (++count > 10000)
  64001. + break;
  64002. + }
  64003. + DWC_ASSERT(++count < 10000,
  64004. + "Connection id status change timed out");
  64005. + core_if->op_state = A_HOST;
  64006. + /*
  64007. + * Initialize the Core for Host mode.
  64008. + */
  64009. + dwc_otg_core_init(core_if);
  64010. + dwc_otg_enable_global_interrupts(core_if);
  64011. + cil_hcd_start(core_if);
  64012. + }
  64013. +}
  64014. +
  64015. +/**
  64016. + * This function handles the Connector ID Status Change Interrupt. It
  64017. + * reads the OTG Interrupt Register (GOTCTL) to determine whether this
  64018. + * is a Device to Host Mode transition or a Host Mode to Device
  64019. + * Transition.
  64020. + *
  64021. + * This only occurs when the cable is connected/removed from the PHY
  64022. + * connector.
  64023. + *
  64024. + * @param core_if Programming view of DWC_otg controller.
  64025. + */
  64026. +int32_t dwc_otg_handle_conn_id_status_change_intr(dwc_otg_core_if_t * core_if)
  64027. +{
  64028. +
  64029. + /*
  64030. + * Need to disable SOF interrupt immediately. If switching from device
  64031. + * to host, the PCD interrupt handler won't handle the interrupt if
  64032. + * host mode is already set. The HCD interrupt handler won't get
  64033. + * called if the HCD state is HALT. This means that the interrupt does
  64034. + * not get handled and Linux complains loudly.
  64035. + */
  64036. + gintmsk_data_t gintmsk = {.d32 = 0 };
  64037. + gintsts_data_t gintsts = {.d32 = 0 };
  64038. +
  64039. + gintmsk.b.sofintr = 1;
  64040. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, gintmsk.d32, 0);
  64041. +
  64042. + DWC_DEBUGPL(DBG_CIL,
  64043. + " ++Connector ID Status Change Interrupt++ (%s)\n",
  64044. + (dwc_otg_is_host_mode(core_if) ? "Host" : "Device"));
  64045. +
  64046. + DWC_SPINUNLOCK(core_if->lock);
  64047. +
  64048. + /*
  64049. + * Need to schedule a work, as there are possible DELAY function calls
  64050. + * Release lock before scheduling workq as it holds spinlock during scheduling
  64051. + */
  64052. +
  64053. + DWC_WORKQ_SCHEDULE(core_if->wq_otg, w_conn_id_status_change,
  64054. + core_if, "connection id status change");
  64055. + DWC_SPINLOCK(core_if->lock);
  64056. +
  64057. + /* Set flag and clear interrupt */
  64058. + gintsts.b.conidstschng = 1;
  64059. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  64060. +
  64061. + return 1;
  64062. +}
  64063. +
  64064. +/**
  64065. + * This interrupt indicates that a device is initiating the Session
  64066. + * Request Protocol to request the host to turn on bus power so a new
  64067. + * session can begin. The handler responds by turning on bus power. If
  64068. + * the DWC_otg controller is in low power mode, the handler brings the
  64069. + * controller out of low power mode before turning on bus power.
  64070. + *
  64071. + * @param core_if Programming view of DWC_otg controller.
  64072. + */
  64073. +int32_t dwc_otg_handle_session_req_intr(dwc_otg_core_if_t * core_if)
  64074. +{
  64075. + gintsts_data_t gintsts;
  64076. +
  64077. +#ifndef DWC_HOST_ONLY
  64078. + DWC_DEBUGPL(DBG_ANY, "++Session Request Interrupt++\n");
  64079. +
  64080. + if (dwc_otg_is_device_mode(core_if)) {
  64081. + DWC_PRINTF("SRP: Device mode\n");
  64082. + } else {
  64083. + hprt0_data_t hprt0;
  64084. + DWC_PRINTF("SRP: Host mode\n");
  64085. +
  64086. + /* Turn on the port power bit. */
  64087. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  64088. + hprt0.b.prtpwr = 1;
  64089. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  64090. +
  64091. + /* Start the Connection timer. So a message can be displayed
  64092. + * if connect does not occur within 10 seconds. */
  64093. + cil_hcd_session_start(core_if);
  64094. + }
  64095. +#endif
  64096. +
  64097. + /* Clear interrupt */
  64098. + gintsts.d32 = 0;
  64099. + gintsts.b.sessreqintr = 1;
  64100. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  64101. +
  64102. + return 1;
  64103. +}
  64104. +
  64105. +void w_wakeup_detected(void *p)
  64106. +{
  64107. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) p;
  64108. + /*
  64109. + * Clear the Resume after 70ms. (Need 20 ms minimum. Use 70 ms
  64110. + * so that OPT tests pass with all PHYs).
  64111. + */
  64112. + hprt0_data_t hprt0 = {.d32 = 0 };
  64113. +#if 0
  64114. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  64115. + /* Restart the Phy Clock */
  64116. + pcgcctl.b.stoppclk = 1;
  64117. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  64118. + dwc_udelay(10);
  64119. +#endif //0
  64120. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  64121. + DWC_DEBUGPL(DBG_ANY, "Resume: HPRT0=%0x\n", hprt0.d32);
  64122. +// dwc_mdelay(70);
  64123. + hprt0.b.prtres = 0; /* Resume */
  64124. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  64125. + DWC_DEBUGPL(DBG_ANY, "Clear Resume: HPRT0=%0x\n",
  64126. + DWC_READ_REG32(core_if->host_if->hprt0));
  64127. +
  64128. + cil_hcd_resume(core_if);
  64129. +
  64130. + /** Change to L0 state*/
  64131. + core_if->lx_state = DWC_OTG_L0;
  64132. +}
  64133. +
  64134. +/**
  64135. + * This interrupt indicates that the DWC_otg controller has detected a
  64136. + * resume or remote wakeup sequence. If the DWC_otg controller is in
  64137. + * low power mode, the handler must brings the controller out of low
  64138. + * power mode. The controller automatically begins resume
  64139. + * signaling. The handler schedules a time to stop resume signaling.
  64140. + */
  64141. +int32_t dwc_otg_handle_wakeup_detected_intr(dwc_otg_core_if_t * core_if)
  64142. +{
  64143. + gintsts_data_t gintsts;
  64144. +
  64145. + DWC_DEBUGPL(DBG_ANY,
  64146. + "++Resume and Remote Wakeup Detected Interrupt++\n");
  64147. +
  64148. + DWC_PRINTF("%s lxstate = %d\n", __func__, core_if->lx_state);
  64149. +
  64150. + if (dwc_otg_is_device_mode(core_if)) {
  64151. + dctl_data_t dctl = {.d32 = 0 };
  64152. + DWC_DEBUGPL(DBG_PCD, "DSTS=0x%0x\n",
  64153. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->
  64154. + dsts));
  64155. + if (core_if->lx_state == DWC_OTG_L2) {
  64156. +#ifdef PARTIAL_POWER_DOWN
  64157. + if (core_if->hwcfg4.b.power_optimiz) {
  64158. + pcgcctl_data_t power = {.d32 = 0 };
  64159. +
  64160. + power.d32 = DWC_READ_REG32(core_if->pcgcctl);
  64161. + DWC_DEBUGPL(DBG_CIL, "PCGCCTL=%0x\n",
  64162. + power.d32);
  64163. +
  64164. + power.b.stoppclk = 0;
  64165. + DWC_WRITE_REG32(core_if->pcgcctl, power.d32);
  64166. +
  64167. + power.b.pwrclmp = 0;
  64168. + DWC_WRITE_REG32(core_if->pcgcctl, power.d32);
  64169. +
  64170. + power.b.rstpdwnmodule = 0;
  64171. + DWC_WRITE_REG32(core_if->pcgcctl, power.d32);
  64172. + }
  64173. +#endif
  64174. + /* Clear the Remote Wakeup Signaling */
  64175. + dctl.b.rmtwkupsig = 1;
  64176. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  64177. + dctl, dctl.d32, 0);
  64178. +
  64179. + DWC_SPINUNLOCK(core_if->lock);
  64180. + if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
  64181. + core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
  64182. + }
  64183. + DWC_SPINLOCK(core_if->lock);
  64184. + } else {
  64185. + glpmcfg_data_t lpmcfg;
  64186. + lpmcfg.d32 =
  64187. + DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  64188. + lpmcfg.b.hird_thres &= (~(1 << 4));
  64189. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg,
  64190. + lpmcfg.d32);
  64191. + }
  64192. + /** Change to L0 state*/
  64193. + core_if->lx_state = DWC_OTG_L0;
  64194. + } else {
  64195. + if (core_if->lx_state != DWC_OTG_L1) {
  64196. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  64197. +
  64198. + /* Restart the Phy Clock */
  64199. + pcgcctl.b.stoppclk = 1;
  64200. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  64201. + DWC_TIMER_SCHEDULE(core_if->wkp_timer, 71);
  64202. + } else {
  64203. + /** Change to L0 state*/
  64204. + core_if->lx_state = DWC_OTG_L0;
  64205. + }
  64206. + }
  64207. +
  64208. + /* Clear interrupt */
  64209. + gintsts.d32 = 0;
  64210. + gintsts.b.wkupintr = 1;
  64211. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  64212. +
  64213. + return 1;
  64214. +}
  64215. +
  64216. +/**
  64217. + * This interrupt indicates that the Wakeup Logic has detected a
  64218. + * Device disconnect.
  64219. + */
  64220. +static int32_t dwc_otg_handle_pwrdn_disconnect_intr(dwc_otg_core_if_t *core_if)
  64221. +{
  64222. + gpwrdn_data_t gpwrdn = { .d32 = 0 };
  64223. + gpwrdn_data_t gpwrdn_temp = { .d32 = 0 };
  64224. + gpwrdn_temp.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  64225. +
  64226. + DWC_PRINTF("%s called\n", __FUNCTION__);
  64227. +
  64228. + if (!core_if->hibernation_suspend) {
  64229. + DWC_PRINTF("Already exited from Hibernation\n");
  64230. + return 1;
  64231. + }
  64232. +
  64233. + /* Switch on the voltage to the core */
  64234. + gpwrdn.b.pwrdnswtch = 1;
  64235. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64236. + dwc_udelay(10);
  64237. +
  64238. + /* Reset the core */
  64239. + gpwrdn.d32 = 0;
  64240. + gpwrdn.b.pwrdnrstn = 1;
  64241. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64242. + dwc_udelay(10);
  64243. +
  64244. + /* Disable power clamps*/
  64245. + gpwrdn.d32 = 0;
  64246. + gpwrdn.b.pwrdnclmp = 1;
  64247. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64248. +
  64249. + /* Remove reset the core signal */
  64250. + gpwrdn.d32 = 0;
  64251. + gpwrdn.b.pwrdnrstn = 1;
  64252. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  64253. + dwc_udelay(10);
  64254. +
  64255. + /* Disable PMU interrupt */
  64256. + gpwrdn.d32 = 0;
  64257. + gpwrdn.b.pmuintsel = 1;
  64258. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64259. +
  64260. + core_if->hibernation_suspend = 0;
  64261. +
  64262. + /* Disable PMU */
  64263. + gpwrdn.d32 = 0;
  64264. + gpwrdn.b.pmuactv = 1;
  64265. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64266. + dwc_udelay(10);
  64267. +
  64268. + if (gpwrdn_temp.b.idsts) {
  64269. + core_if->op_state = B_PERIPHERAL;
  64270. + dwc_otg_core_init(core_if);
  64271. + dwc_otg_enable_global_interrupts(core_if);
  64272. + cil_pcd_start(core_if);
  64273. + } else {
  64274. + core_if->op_state = A_HOST;
  64275. + dwc_otg_core_init(core_if);
  64276. + dwc_otg_enable_global_interrupts(core_if);
  64277. + cil_hcd_start(core_if);
  64278. + }
  64279. +
  64280. + return 1;
  64281. +}
  64282. +
  64283. +/**
  64284. + * This interrupt indicates that the Wakeup Logic has detected a
  64285. + * remote wakeup sequence.
  64286. + */
  64287. +static int32_t dwc_otg_handle_pwrdn_wakeup_detected_intr(dwc_otg_core_if_t * core_if)
  64288. +{
  64289. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  64290. + DWC_DEBUGPL(DBG_ANY,
  64291. + "++Powerdown Remote Wakeup Detected Interrupt++\n");
  64292. +
  64293. + if (!core_if->hibernation_suspend) {
  64294. + DWC_PRINTF("Already exited from Hibernation\n");
  64295. + return 1;
  64296. + }
  64297. +
  64298. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  64299. + if (gpwrdn.b.idsts) { // Device Mode
  64300. + if ((core_if->power_down == 2)
  64301. + && (core_if->hibernation_suspend == 1)) {
  64302. + dwc_otg_device_hibernation_restore(core_if, 0, 0);
  64303. + }
  64304. + } else {
  64305. + if ((core_if->power_down == 2)
  64306. + && (core_if->hibernation_suspend == 1)) {
  64307. + dwc_otg_host_hibernation_restore(core_if, 1, 0);
  64308. + }
  64309. + }
  64310. + return 1;
  64311. +}
  64312. +
  64313. +static int32_t dwc_otg_handle_pwrdn_idsts_change(dwc_otg_device_t *otg_dev)
  64314. +{
  64315. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  64316. + gpwrdn_data_t gpwrdn_temp = {.d32 = 0 };
  64317. + dwc_otg_core_if_t *core_if = otg_dev->core_if;
  64318. +
  64319. + DWC_DEBUGPL(DBG_ANY, "%s called\n", __FUNCTION__);
  64320. + gpwrdn_temp.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  64321. + if (core_if->power_down == 2) {
  64322. + if (!core_if->hibernation_suspend) {
  64323. + DWC_PRINTF("Already exited from Hibernation\n");
  64324. + return 1;
  64325. + }
  64326. + DWC_DEBUGPL(DBG_ANY, "Exit from hibernation on ID sts change\n");
  64327. + /* Switch on the voltage to the core */
  64328. + gpwrdn.b.pwrdnswtch = 1;
  64329. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64330. + dwc_udelay(10);
  64331. +
  64332. + /* Reset the core */
  64333. + gpwrdn.d32 = 0;
  64334. + gpwrdn.b.pwrdnrstn = 1;
  64335. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64336. + dwc_udelay(10);
  64337. +
  64338. + /* Disable power clamps */
  64339. + gpwrdn.d32 = 0;
  64340. + gpwrdn.b.pwrdnclmp = 1;
  64341. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64342. +
  64343. + /* Remove reset the core signal */
  64344. + gpwrdn.d32 = 0;
  64345. + gpwrdn.b.pwrdnrstn = 1;
  64346. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  64347. + dwc_udelay(10);
  64348. +
  64349. + /* Disable PMU interrupt */
  64350. + gpwrdn.d32 = 0;
  64351. + gpwrdn.b.pmuintsel = 1;
  64352. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64353. +
  64354. + /*Indicates that we are exiting from hibernation */
  64355. + core_if->hibernation_suspend = 0;
  64356. +
  64357. + /* Disable PMU */
  64358. + gpwrdn.d32 = 0;
  64359. + gpwrdn.b.pmuactv = 1;
  64360. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64361. + dwc_udelay(10);
  64362. +
  64363. + gpwrdn.d32 = core_if->gr_backup->gpwrdn_local;
  64364. + if (gpwrdn.b.dis_vbus == 1) {
  64365. + gpwrdn.d32 = 0;
  64366. + gpwrdn.b.dis_vbus = 1;
  64367. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64368. + }
  64369. +
  64370. + if (gpwrdn_temp.b.idsts) {
  64371. + core_if->op_state = B_PERIPHERAL;
  64372. + dwc_otg_core_init(core_if);
  64373. + dwc_otg_enable_global_interrupts(core_if);
  64374. + cil_pcd_start(core_if);
  64375. + } else {
  64376. + core_if->op_state = A_HOST;
  64377. + dwc_otg_core_init(core_if);
  64378. + dwc_otg_enable_global_interrupts(core_if);
  64379. + cil_hcd_start(core_if);
  64380. + }
  64381. + }
  64382. +
  64383. + if (core_if->adp_enable) {
  64384. + uint8_t is_host = 0;
  64385. + DWC_SPINUNLOCK(core_if->lock);
  64386. + /* Change the core_if's lock to hcd/pcd lock depend on mode? */
  64387. +#ifndef DWC_HOST_ONLY
  64388. + if (gpwrdn_temp.b.idsts)
  64389. + core_if->lock = otg_dev->pcd->lock;
  64390. +#endif
  64391. +#ifndef DWC_DEVICE_ONLY
  64392. + if (!gpwrdn_temp.b.idsts) {
  64393. + core_if->lock = otg_dev->hcd->lock;
  64394. + is_host = 1;
  64395. + }
  64396. +#endif
  64397. + DWC_PRINTF("RESTART ADP\n");
  64398. + if (core_if->adp.probe_enabled)
  64399. + dwc_otg_adp_probe_stop(core_if);
  64400. + if (core_if->adp.sense_enabled)
  64401. + dwc_otg_adp_sense_stop(core_if);
  64402. + if (core_if->adp.sense_timer_started)
  64403. + DWC_TIMER_CANCEL(core_if->adp.sense_timer);
  64404. + if (core_if->adp.vbuson_timer_started)
  64405. + DWC_TIMER_CANCEL(core_if->adp.vbuson_timer);
  64406. + core_if->adp.probe_timer_values[0] = -1;
  64407. + core_if->adp.probe_timer_values[1] = -1;
  64408. + core_if->adp.sense_timer_started = 0;
  64409. + core_if->adp.vbuson_timer_started = 0;
  64410. + core_if->adp.probe_counter = 0;
  64411. + core_if->adp.gpwrdn = 0;
  64412. +
  64413. + /* Disable PMU and restart ADP */
  64414. + gpwrdn_temp.d32 = 0;
  64415. + gpwrdn_temp.b.pmuactv = 1;
  64416. + gpwrdn_temp.b.pmuintsel = 1;
  64417. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64418. + DWC_PRINTF("Check point 1\n");
  64419. + dwc_mdelay(110);
  64420. + dwc_otg_adp_start(core_if, is_host);
  64421. + DWC_SPINLOCK(core_if->lock);
  64422. + }
  64423. +
  64424. +
  64425. + return 1;
  64426. +}
  64427. +
  64428. +static int32_t dwc_otg_handle_pwrdn_session_change(dwc_otg_core_if_t * core_if)
  64429. +{
  64430. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  64431. + int32_t otg_cap_param = core_if->core_params->otg_cap;
  64432. + DWC_DEBUGPL(DBG_ANY, "%s called\n", __FUNCTION__);
  64433. +
  64434. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  64435. + if (core_if->power_down == 2) {
  64436. + if (!core_if->hibernation_suspend) {
  64437. + DWC_PRINTF("Already exited from Hibernation\n");
  64438. + return 1;
  64439. + }
  64440. +
  64441. + if ((otg_cap_param != DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE ||
  64442. + otg_cap_param != DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE) &&
  64443. + gpwrdn.b.bsessvld == 0) {
  64444. + /* Save gpwrdn register for further usage if stschng interrupt */
  64445. + core_if->gr_backup->gpwrdn_local =
  64446. + DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  64447. + /*Exit from ISR and wait for stschng interrupt with bsessvld = 1 */
  64448. + return 1;
  64449. + }
  64450. +
  64451. + /* Switch on the voltage to the core */
  64452. + gpwrdn.d32 = 0;
  64453. + gpwrdn.b.pwrdnswtch = 1;
  64454. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64455. + dwc_udelay(10);
  64456. +
  64457. + /* Reset the core */
  64458. + gpwrdn.d32 = 0;
  64459. + gpwrdn.b.pwrdnrstn = 1;
  64460. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64461. + dwc_udelay(10);
  64462. +
  64463. + /* Disable power clamps */
  64464. + gpwrdn.d32 = 0;
  64465. + gpwrdn.b.pwrdnclmp = 1;
  64466. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64467. +
  64468. + /* Remove reset the core signal */
  64469. + gpwrdn.d32 = 0;
  64470. + gpwrdn.b.pwrdnrstn = 1;
  64471. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  64472. + dwc_udelay(10);
  64473. +
  64474. + /* Disable PMU interrupt */
  64475. + gpwrdn.d32 = 0;
  64476. + gpwrdn.b.pmuintsel = 1;
  64477. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64478. + dwc_udelay(10);
  64479. +
  64480. + /*Indicates that we are exiting from hibernation */
  64481. + core_if->hibernation_suspend = 0;
  64482. +
  64483. + /* Disable PMU */
  64484. + gpwrdn.d32 = 0;
  64485. + gpwrdn.b.pmuactv = 1;
  64486. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64487. + dwc_udelay(10);
  64488. +
  64489. + core_if->op_state = B_PERIPHERAL;
  64490. + dwc_otg_core_init(core_if);
  64491. + dwc_otg_enable_global_interrupts(core_if);
  64492. + cil_pcd_start(core_if);
  64493. +
  64494. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE ||
  64495. + otg_cap_param == DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE) {
  64496. + /*
  64497. + * Initiate SRP after initial ADP probe.
  64498. + */
  64499. + dwc_otg_initiate_srp(core_if);
  64500. + }
  64501. + }
  64502. +
  64503. + return 1;
  64504. +}
  64505. +/**
  64506. + * This interrupt indicates that the Wakeup Logic has detected a
  64507. + * status change either on IDDIG or BSessVld.
  64508. + */
  64509. +static uint32_t dwc_otg_handle_pwrdn_stschng_intr(dwc_otg_device_t *otg_dev)
  64510. +{
  64511. + int retval;
  64512. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  64513. + gpwrdn_data_t gpwrdn_temp = {.d32 = 0 };
  64514. + dwc_otg_core_if_t *core_if = otg_dev->core_if;
  64515. +
  64516. + DWC_PRINTF("%s called\n", __FUNCTION__);
  64517. +
  64518. + if (core_if->power_down == 2) {
  64519. + if (core_if->hibernation_suspend <= 0) {
  64520. + DWC_PRINTF("Already exited from Hibernation\n");
  64521. + return 1;
  64522. + } else
  64523. + gpwrdn_temp.d32 = core_if->gr_backup->gpwrdn_local;
  64524. +
  64525. + } else {
  64526. + gpwrdn_temp.d32 = core_if->adp.gpwrdn;
  64527. + }
  64528. +
  64529. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  64530. +
  64531. + if (gpwrdn.b.idsts ^ gpwrdn_temp.b.idsts) {
  64532. + retval = dwc_otg_handle_pwrdn_idsts_change(otg_dev);
  64533. + } else if (gpwrdn.b.bsessvld ^ gpwrdn_temp.b.bsessvld) {
  64534. + retval = dwc_otg_handle_pwrdn_session_change(core_if);
  64535. + }
  64536. +
  64537. + return retval;
  64538. +}
  64539. +
  64540. +/**
  64541. + * This interrupt indicates that the Wakeup Logic has detected a
  64542. + * SRP.
  64543. + */
  64544. +static int32_t dwc_otg_handle_pwrdn_srp_intr(dwc_otg_core_if_t * core_if)
  64545. +{
  64546. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  64547. +
  64548. + DWC_PRINTF("%s called\n", __FUNCTION__);
  64549. +
  64550. + if (!core_if->hibernation_suspend) {
  64551. + DWC_PRINTF("Already exited from Hibernation\n");
  64552. + return 1;
  64553. + }
  64554. +#ifdef DWC_DEV_SRPCAP
  64555. + if (core_if->pwron_timer_started) {
  64556. + core_if->pwron_timer_started = 0;
  64557. + DWC_TIMER_CANCEL(core_if->pwron_timer);
  64558. + }
  64559. +#endif
  64560. +
  64561. + /* Switch on the voltage to the core */
  64562. + gpwrdn.b.pwrdnswtch = 1;
  64563. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64564. + dwc_udelay(10);
  64565. +
  64566. + /* Reset the core */
  64567. + gpwrdn.d32 = 0;
  64568. + gpwrdn.b.pwrdnrstn = 1;
  64569. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64570. + dwc_udelay(10);
  64571. +
  64572. + /* Disable power clamps */
  64573. + gpwrdn.d32 = 0;
  64574. + gpwrdn.b.pwrdnclmp = 1;
  64575. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64576. +
  64577. + /* Remove reset the core signal */
  64578. + gpwrdn.d32 = 0;
  64579. + gpwrdn.b.pwrdnrstn = 1;
  64580. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  64581. + dwc_udelay(10);
  64582. +
  64583. + /* Disable PMU interrupt */
  64584. + gpwrdn.d32 = 0;
  64585. + gpwrdn.b.pmuintsel = 1;
  64586. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64587. +
  64588. + /* Indicates that we are exiting from hibernation */
  64589. + core_if->hibernation_suspend = 0;
  64590. +
  64591. + /* Disable PMU */
  64592. + gpwrdn.d32 = 0;
  64593. + gpwrdn.b.pmuactv = 1;
  64594. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64595. + dwc_udelay(10);
  64596. +
  64597. + /* Programm Disable VBUS to 0 */
  64598. + gpwrdn.d32 = 0;
  64599. + gpwrdn.b.dis_vbus = 1;
  64600. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64601. +
  64602. + /*Initialize the core as Host */
  64603. + core_if->op_state = A_HOST;
  64604. + dwc_otg_core_init(core_if);
  64605. + dwc_otg_enable_global_interrupts(core_if);
  64606. + cil_hcd_start(core_if);
  64607. +
  64608. + return 1;
  64609. +}
  64610. +
  64611. +/** This interrupt indicates that restore command after Hibernation
  64612. + * was completed by the core. */
  64613. +int32_t dwc_otg_handle_restore_done_intr(dwc_otg_core_if_t * core_if)
  64614. +{
  64615. + pcgcctl_data_t pcgcctl;
  64616. + DWC_DEBUGPL(DBG_ANY, "++Restore Done Interrupt++\n");
  64617. +
  64618. + //TODO De-assert restore signal. 8.a
  64619. + pcgcctl.d32 = DWC_READ_REG32(core_if->pcgcctl);
  64620. + if (pcgcctl.b.restoremode == 1) {
  64621. + gintmsk_data_t gintmsk = {.d32 = 0 };
  64622. + /*
  64623. + * If restore mode is Remote Wakeup,
  64624. + * unmask Remote Wakeup interrupt.
  64625. + */
  64626. + gintmsk.b.wkupintr = 1;
  64627. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk,
  64628. + 0, gintmsk.d32);
  64629. + }
  64630. +
  64631. + return 1;
  64632. +}
  64633. +
  64634. +/**
  64635. + * This interrupt indicates that a device has been disconnected from
  64636. + * the root port.
  64637. + */
  64638. +int32_t dwc_otg_handle_disconnect_intr(dwc_otg_core_if_t * core_if)
  64639. +{
  64640. + gintsts_data_t gintsts;
  64641. +
  64642. + DWC_DEBUGPL(DBG_ANY, "++Disconnect Detected Interrupt++ (%s) %s\n",
  64643. + (dwc_otg_is_host_mode(core_if) ? "Host" : "Device"),
  64644. + op_state_str(core_if));
  64645. +
  64646. +/** @todo Consolidate this if statement. */
  64647. +#ifndef DWC_HOST_ONLY
  64648. + if (core_if->op_state == B_HOST) {
  64649. + /* If in device mode Disconnect and stop the HCD, then
  64650. + * start the PCD. */
  64651. + DWC_SPINUNLOCK(core_if->lock);
  64652. + cil_hcd_disconnect(core_if);
  64653. + cil_pcd_start(core_if);
  64654. + DWC_SPINLOCK(core_if->lock);
  64655. + core_if->op_state = B_PERIPHERAL;
  64656. + } else if (dwc_otg_is_device_mode(core_if)) {
  64657. + gotgctl_data_t gotgctl = {.d32 = 0 };
  64658. + gotgctl.d32 =
  64659. + DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  64660. + if (gotgctl.b.hstsethnpen == 1) {
  64661. + /* Do nothing, if HNP in process the OTG
  64662. + * interrupt "Host Negotiation Detected"
  64663. + * interrupt will do the mode switch.
  64664. + */
  64665. + } else if (gotgctl.b.devhnpen == 0) {
  64666. + /* If in device mode Disconnect and stop the HCD, then
  64667. + * start the PCD. */
  64668. + DWC_SPINUNLOCK(core_if->lock);
  64669. + cil_hcd_disconnect(core_if);
  64670. + cil_pcd_start(core_if);
  64671. + DWC_SPINLOCK(core_if->lock);
  64672. + core_if->op_state = B_PERIPHERAL;
  64673. + } else {
  64674. + DWC_DEBUGPL(DBG_ANY, "!a_peripheral && !devhnpen\n");
  64675. + }
  64676. + } else {
  64677. + if (core_if->op_state == A_HOST) {
  64678. + /* A-Cable still connected but device disconnected. */
  64679. + cil_hcd_disconnect(core_if);
  64680. + if (core_if->adp_enable) {
  64681. + gpwrdn_data_t gpwrdn = { .d32 = 0 };
  64682. + cil_hcd_stop(core_if);
  64683. + /* Enable Power Down Logic */
  64684. + gpwrdn.b.pmuintsel = 1;
  64685. + gpwrdn.b.pmuactv = 1;
  64686. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  64687. + gpwrdn, 0, gpwrdn.d32);
  64688. + dwc_otg_adp_probe_start(core_if);
  64689. +
  64690. + /* Power off the core */
  64691. + if (core_if->power_down == 2) {
  64692. + gpwrdn.d32 = 0;
  64693. + gpwrdn.b.pwrdnswtch = 1;
  64694. + DWC_MODIFY_REG32
  64695. + (&core_if->core_global_regs->gpwrdn,
  64696. + gpwrdn.d32, 0);
  64697. + }
  64698. + }
  64699. + }
  64700. + }
  64701. +#endif
  64702. + /* Change to L3(OFF) state */
  64703. + core_if->lx_state = DWC_OTG_L3;
  64704. +
  64705. + gintsts.d32 = 0;
  64706. + gintsts.b.disconnect = 1;
  64707. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  64708. + return 1;
  64709. +}
  64710. +
  64711. +/**
  64712. + * This interrupt indicates that SUSPEND state has been detected on
  64713. + * the USB.
  64714. + *
  64715. + * For HNP the USB Suspend interrupt signals the change from
  64716. + * "a_peripheral" to "a_host".
  64717. + *
  64718. + * When power management is enabled the core will be put in low power
  64719. + * mode.
  64720. + */
  64721. +int32_t dwc_otg_handle_usb_suspend_intr(dwc_otg_core_if_t * core_if)
  64722. +{
  64723. + dsts_data_t dsts;
  64724. + gintsts_data_t gintsts;
  64725. + dcfg_data_t dcfg;
  64726. +
  64727. + DWC_DEBUGPL(DBG_ANY, "USB SUSPEND\n");
  64728. +
  64729. + if (dwc_otg_is_device_mode(core_if)) {
  64730. + /* Check the Device status register to determine if the Suspend
  64731. + * state is active. */
  64732. + dsts.d32 =
  64733. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  64734. + DWC_DEBUGPL(DBG_PCD, "DSTS=0x%0x\n", dsts.d32);
  64735. + DWC_DEBUGPL(DBG_PCD, "DSTS.Suspend Status=%d "
  64736. + "HWCFG4.power Optimize=%d\n",
  64737. + dsts.b.suspsts, core_if->hwcfg4.b.power_optimiz);
  64738. +
  64739. +#ifdef PARTIAL_POWER_DOWN
  64740. +/** @todo Add a module parameter for power management. */
  64741. +
  64742. + if (dsts.b.suspsts && core_if->hwcfg4.b.power_optimiz) {
  64743. + pcgcctl_data_t power = {.d32 = 0 };
  64744. + DWC_DEBUGPL(DBG_CIL, "suspend\n");
  64745. +
  64746. + power.b.pwrclmp = 1;
  64747. + DWC_WRITE_REG32(core_if->pcgcctl, power.d32);
  64748. +
  64749. + power.b.rstpdwnmodule = 1;
  64750. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, power.d32);
  64751. +
  64752. + power.b.stoppclk = 1;
  64753. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, power.d32);
  64754. +
  64755. + } else {
  64756. + DWC_DEBUGPL(DBG_ANY, "disconnect?\n");
  64757. + }
  64758. +#endif
  64759. + /* PCD callback for suspend. Release the lock inside of callback function */
  64760. + cil_pcd_suspend(core_if);
  64761. + if (core_if->power_down == 2)
  64762. + {
  64763. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  64764. + DWC_DEBUGPL(DBG_ANY,"lx_state = %08x\n",core_if->lx_state);
  64765. + DWC_DEBUGPL(DBG_ANY," device address = %08d\n",dcfg.b.devaddr);
  64766. +
  64767. + if (core_if->lx_state != DWC_OTG_L3 && dcfg.b.devaddr) {
  64768. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  64769. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  64770. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  64771. +
  64772. + /* Change to L2(suspend) state */
  64773. + core_if->lx_state = DWC_OTG_L2;
  64774. +
  64775. + /* Clear interrupt in gintsts */
  64776. + gintsts.d32 = 0;
  64777. + gintsts.b.usbsuspend = 1;
  64778. + DWC_WRITE_REG32(&core_if->core_global_regs->
  64779. + gintsts, gintsts.d32);
  64780. + DWC_PRINTF("Start of hibernation completed\n");
  64781. + dwc_otg_save_global_regs(core_if);
  64782. + dwc_otg_save_dev_regs(core_if);
  64783. +
  64784. + gusbcfg.d32 =
  64785. + DWC_READ_REG32(&core_if->core_global_regs->
  64786. + gusbcfg);
  64787. + if (gusbcfg.b.ulpi_utmi_sel == 1) {
  64788. + /* ULPI interface */
  64789. + /* Suspend the Phy Clock */
  64790. + pcgcctl.d32 = 0;
  64791. + pcgcctl.b.stoppclk = 1;
  64792. + DWC_MODIFY_REG32(core_if->pcgcctl, 0,
  64793. + pcgcctl.d32);
  64794. + dwc_udelay(10);
  64795. + gpwrdn.b.pmuactv = 1;
  64796. + DWC_MODIFY_REG32(&core_if->
  64797. + core_global_regs->
  64798. + gpwrdn, 0, gpwrdn.d32);
  64799. + } else {
  64800. + /* UTMI+ Interface */
  64801. + gpwrdn.b.pmuactv = 1;
  64802. + DWC_MODIFY_REG32(&core_if->
  64803. + core_global_regs->
  64804. + gpwrdn, 0, gpwrdn.d32);
  64805. + dwc_udelay(10);
  64806. + pcgcctl.b.stoppclk = 1;
  64807. + DWC_MODIFY_REG32(core_if->pcgcctl, 0,
  64808. + pcgcctl.d32);
  64809. + dwc_udelay(10);
  64810. + }
  64811. +
  64812. + /* Set flag to indicate that we are in hibernation */
  64813. + core_if->hibernation_suspend = 1;
  64814. + /* Enable interrupts from wake up logic */
  64815. + gpwrdn.d32 = 0;
  64816. + gpwrdn.b.pmuintsel = 1;
  64817. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  64818. + gpwrdn, 0, gpwrdn.d32);
  64819. + dwc_udelay(10);
  64820. +
  64821. + /* Unmask device mode interrupts in GPWRDN */
  64822. + gpwrdn.d32 = 0;
  64823. + gpwrdn.b.rst_det_msk = 1;
  64824. + gpwrdn.b.lnstchng_msk = 1;
  64825. + gpwrdn.b.sts_chngint_msk = 1;
  64826. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  64827. + gpwrdn, 0, gpwrdn.d32);
  64828. + dwc_udelay(10);
  64829. +
  64830. + /* Enable Power Down Clamp */
  64831. + gpwrdn.d32 = 0;
  64832. + gpwrdn.b.pwrdnclmp = 1;
  64833. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  64834. + gpwrdn, 0, gpwrdn.d32);
  64835. + dwc_udelay(10);
  64836. +
  64837. + /* Switch off VDD */
  64838. + gpwrdn.d32 = 0;
  64839. + gpwrdn.b.pwrdnswtch = 1;
  64840. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  64841. + gpwrdn, 0, gpwrdn.d32);
  64842. +
  64843. + /* Save gpwrdn register for further usage if stschng interrupt */
  64844. + core_if->gr_backup->gpwrdn_local =
  64845. + DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  64846. + DWC_PRINTF("Hibernation completed\n");
  64847. +
  64848. + return 1;
  64849. + }
  64850. + } else if (core_if->power_down == 3) {
  64851. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  64852. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  64853. + DWC_DEBUGPL(DBG_ANY, "lx_state = %08x\n",core_if->lx_state);
  64854. + DWC_DEBUGPL(DBG_ANY, " device address = %08d\n",dcfg.b.devaddr);
  64855. +
  64856. + if (core_if->lx_state != DWC_OTG_L3 && dcfg.b.devaddr) {
  64857. + DWC_DEBUGPL(DBG_ANY, "Start entering to extended hibernation\n");
  64858. + core_if->xhib = 1;
  64859. +
  64860. + /* Clear interrupt in gintsts */
  64861. + gintsts.d32 = 0;
  64862. + gintsts.b.usbsuspend = 1;
  64863. + DWC_WRITE_REG32(&core_if->core_global_regs->
  64864. + gintsts, gintsts.d32);
  64865. +
  64866. + dwc_otg_save_global_regs(core_if);
  64867. + dwc_otg_save_dev_regs(core_if);
  64868. +
  64869. + /* Wait for 10 PHY clocks */
  64870. + dwc_udelay(10);
  64871. +
  64872. + /* Program GPIO register while entering to xHib */
  64873. + DWC_WRITE_REG32(&core_if->core_global_regs->ggpio, 0x1);
  64874. +
  64875. + pcgcctl.b.enbl_extnd_hiber = 1;
  64876. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  64877. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  64878. +
  64879. + pcgcctl.d32 = 0;
  64880. + pcgcctl.b.extnd_hiber_pwrclmp = 1;
  64881. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  64882. +
  64883. + pcgcctl.d32 = 0;
  64884. + pcgcctl.b.extnd_hiber_switch = 1;
  64885. + core_if->gr_backup->xhib_gpwrdn = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  64886. + core_if->gr_backup->xhib_pcgcctl = DWC_READ_REG32(core_if->pcgcctl) | pcgcctl.d32;
  64887. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  64888. +
  64889. + DWC_DEBUGPL(DBG_ANY, "Finished entering to extended hibernation\n");
  64890. +
  64891. + return 1;
  64892. + }
  64893. + }
  64894. + } else {
  64895. + if (core_if->op_state == A_PERIPHERAL) {
  64896. + DWC_DEBUGPL(DBG_ANY, "a_peripheral->a_host\n");
  64897. + /* Clear the a_peripheral flag, back to a_host. */
  64898. + DWC_SPINUNLOCK(core_if->lock);
  64899. + cil_pcd_stop(core_if);
  64900. + cil_hcd_start(core_if);
  64901. + DWC_SPINLOCK(core_if->lock);
  64902. + core_if->op_state = A_HOST;
  64903. + }
  64904. + }
  64905. +
  64906. + /* Change to L2(suspend) state */
  64907. + core_if->lx_state = DWC_OTG_L2;
  64908. +
  64909. + /* Clear interrupt */
  64910. + gintsts.d32 = 0;
  64911. + gintsts.b.usbsuspend = 1;
  64912. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  64913. +
  64914. + return 1;
  64915. +}
  64916. +
  64917. +static int32_t dwc_otg_handle_xhib_exit_intr(dwc_otg_core_if_t * core_if)
  64918. +{
  64919. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  64920. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  64921. + gahbcfg_data_t gahbcfg = {.d32 = 0 };
  64922. +
  64923. + dwc_udelay(10);
  64924. +
  64925. + /* Program GPIO register while entering to xHib */
  64926. + DWC_WRITE_REG32(&core_if->core_global_regs->ggpio, 0x0);
  64927. +
  64928. + pcgcctl.d32 = core_if->gr_backup->xhib_pcgcctl;
  64929. + pcgcctl.b.extnd_hiber_pwrclmp = 0;
  64930. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  64931. + dwc_udelay(10);
  64932. +
  64933. + gpwrdn.d32 = core_if->gr_backup->xhib_gpwrdn;
  64934. + gpwrdn.b.restore = 1;
  64935. + DWC_WRITE_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32);
  64936. + dwc_udelay(10);
  64937. +
  64938. + restore_lpm_i2c_regs(core_if);
  64939. +
  64940. + pcgcctl.d32 = core_if->gr_backup->pcgcctl_local & (0x3FFFF << 14);
  64941. + pcgcctl.b.max_xcvrselect = 1;
  64942. + pcgcctl.b.ess_reg_restored = 0;
  64943. + pcgcctl.b.extnd_hiber_switch = 0;
  64944. + pcgcctl.b.extnd_hiber_pwrclmp = 0;
  64945. + pcgcctl.b.enbl_extnd_hiber = 1;
  64946. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  64947. +
  64948. + gahbcfg.d32 = core_if->gr_backup->gahbcfg_local;
  64949. + gahbcfg.b.glblintrmsk = 1;
  64950. + DWC_WRITE_REG32(&core_if->core_global_regs->gahbcfg, gahbcfg.d32);
  64951. +
  64952. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  64953. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, 0x1 << 16);
  64954. +
  64955. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg,
  64956. + core_if->gr_backup->gusbcfg_local);
  64957. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg,
  64958. + core_if->dr_backup->dcfg);
  64959. +
  64960. + pcgcctl.d32 = 0;
  64961. + pcgcctl.d32 = core_if->gr_backup->pcgcctl_local & (0x3FFFF << 14);
  64962. + pcgcctl.b.max_xcvrselect = 1;
  64963. + pcgcctl.d32 |= 0x608;
  64964. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  64965. + dwc_udelay(10);
  64966. +
  64967. + pcgcctl.d32 = 0;
  64968. + pcgcctl.d32 = core_if->gr_backup->pcgcctl_local & (0x3FFFF << 14);
  64969. + pcgcctl.b.max_xcvrselect = 1;
  64970. + pcgcctl.b.ess_reg_restored = 1;
  64971. + pcgcctl.b.enbl_extnd_hiber = 1;
  64972. + pcgcctl.b.rstpdwnmodule = 1;
  64973. + pcgcctl.b.restoremode = 1;
  64974. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  64975. +
  64976. + DWC_DEBUGPL(DBG_ANY, "%s called\n", __FUNCTION__);
  64977. +
  64978. + return 1;
  64979. +}
  64980. +
  64981. +#ifdef CONFIG_USB_DWC_OTG_LPM
  64982. +/**
  64983. + * This function hadles LPM transaction received interrupt.
  64984. + */
  64985. +static int32_t dwc_otg_handle_lpm_intr(dwc_otg_core_if_t * core_if)
  64986. +{
  64987. + glpmcfg_data_t lpmcfg;
  64988. + gintsts_data_t gintsts;
  64989. +
  64990. + if (!core_if->core_params->lpm_enable) {
  64991. + DWC_PRINTF("Unexpected LPM interrupt\n");
  64992. + }
  64993. +
  64994. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  64995. + DWC_PRINTF("LPM config register = 0x%08x\n", lpmcfg.d32);
  64996. +
  64997. + if (dwc_otg_is_host_mode(core_if)) {
  64998. + cil_hcd_sleep(core_if);
  64999. + } else {
  65000. + lpmcfg.b.hird_thres |= (1 << 4);
  65001. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg,
  65002. + lpmcfg.d32);
  65003. + }
  65004. +
  65005. + /* Examine prt_sleep_sts after TL1TokenTetry period max (10 us) */
  65006. + dwc_udelay(10);
  65007. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  65008. + if (lpmcfg.b.prt_sleep_sts) {
  65009. + /* Save the current state */
  65010. + core_if->lx_state = DWC_OTG_L1;
  65011. + }
  65012. +
  65013. + /* Clear interrupt */
  65014. + gintsts.d32 = 0;
  65015. + gintsts.b.lpmtranrcvd = 1;
  65016. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  65017. + return 1;
  65018. +}
  65019. +#endif /* CONFIG_USB_DWC_OTG_LPM */
  65020. +
  65021. +/**
  65022. + * This function returns the Core Interrupt register.
  65023. + */
  65024. +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)
  65025. +{
  65026. + gahbcfg_data_t gahbcfg = {.d32 = 0 };
  65027. + gintsts_data_t gintsts;
  65028. + gintmsk_data_t gintmsk;
  65029. + gintmsk_data_t gintmsk_common = {.d32 = 0 };
  65030. + gintmsk_common.b.wkupintr = 1;
  65031. + gintmsk_common.b.sessreqintr = 1;
  65032. + gintmsk_common.b.conidstschng = 1;
  65033. + gintmsk_common.b.otgintr = 1;
  65034. + gintmsk_common.b.modemismatch = 1;
  65035. + gintmsk_common.b.disconnect = 1;
  65036. + gintmsk_common.b.usbsuspend = 1;
  65037. +#ifdef CONFIG_USB_DWC_OTG_LPM
  65038. + gintmsk_common.b.lpmtranrcvd = 1;
  65039. +#endif
  65040. + gintmsk_common.b.restoredone = 1;
  65041. + if(dwc_otg_is_device_mode(core_if))
  65042. + {
  65043. + /** @todo: The port interrupt occurs while in device
  65044. + * mode. Added code to CIL to clear the interrupt for now!
  65045. + */
  65046. + gintmsk_common.b.portintr = 1;
  65047. + }
  65048. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  65049. + gintmsk.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  65050. + if(fiq_enable) {
  65051. + local_fiq_disable();
  65052. + /* Pull in the interrupts that the FIQ has masked */
  65053. + gintmsk.d32 |= ~(hcd->fiq_state->gintmsk_saved.d32);
  65054. + /* for the upstairs function to reenable - have to read it here in case FIQ triggers again */
  65055. + reenable_gintmsk->d32 |= gintmsk.d32;
  65056. + reenable_gintmsk->d32 |= ~(hcd->fiq_state->gintmsk_saved.d32);
  65057. + reenable_gintmsk->d32 &= gintmsk_common.d32;
  65058. + local_fiq_enable();
  65059. + }
  65060. +
  65061. + gahbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gahbcfg);
  65062. +
  65063. +#ifdef DEBUG
  65064. + /* if any common interrupts set */
  65065. + if (gintsts.d32 & gintmsk_common.d32) {
  65066. + DWC_DEBUGPL(DBG_ANY, "common_intr: gintsts=%08x gintmsk=%08x\n",
  65067. + gintsts.d32, gintmsk.d32);
  65068. + }
  65069. +#endif
  65070. + if (!fiq_enable){
  65071. + if (gahbcfg.b.glblintrmsk)
  65072. + return ((gintsts.d32 & gintmsk.d32) & gintmsk_common.d32);
  65073. + else
  65074. + return 0;
  65075. + } else {
  65076. + /* Our IRQ kicker is no longer the USB hardware, it's the MPHI interface.
  65077. + * Can't trust the global interrupt mask bit in this case.
  65078. + */
  65079. + return ((gintsts.d32 & gintmsk.d32) & gintmsk_common.d32);
  65080. + }
  65081. +
  65082. +}
  65083. +
  65084. +/* MACRO for clearing interupt bits in GPWRDN register */
  65085. +#define CLEAR_GPWRDN_INTR(__core_if,__intr) \
  65086. +do { \
  65087. + gpwrdn_data_t gpwrdn = {.d32=0}; \
  65088. + gpwrdn.b.__intr = 1; \
  65089. + DWC_MODIFY_REG32(&__core_if->core_global_regs->gpwrdn, \
  65090. + 0, gpwrdn.d32); \
  65091. +} while (0)
  65092. +
  65093. +/**
  65094. + * Common interrupt handler.
  65095. + *
  65096. + * The common interrupts are those that occur in both Host and Device mode.
  65097. + * This handler handles the following interrupts:
  65098. + * - Mode Mismatch Interrupt
  65099. + * - Disconnect Interrupt
  65100. + * - OTG Interrupt
  65101. + * - Connector ID Status Change Interrupt
  65102. + * - Session Request Interrupt.
  65103. + * - Resume / Remote Wakeup Detected Interrupt.
  65104. + * - LPM Transaction Received Interrupt
  65105. + * - ADP Transaction Received Interrupt
  65106. + *
  65107. + */
  65108. +int32_t dwc_otg_handle_common_intr(void *dev)
  65109. +{
  65110. + int retval = 0;
  65111. + gintsts_data_t gintsts;
  65112. + gintmsk_data_t gintmsk_reenable = { .d32 = 0 };
  65113. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  65114. + dwc_otg_device_t *otg_dev = dev;
  65115. + dwc_otg_core_if_t *core_if = otg_dev->core_if;
  65116. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  65117. + if (dwc_otg_is_device_mode(core_if))
  65118. + core_if->frame_num = dwc_otg_get_frame_number(core_if);
  65119. +
  65120. + if (core_if->lock)
  65121. + DWC_SPINLOCK(core_if->lock);
  65122. +
  65123. + if (core_if->power_down == 3 && core_if->xhib == 1) {
  65124. + DWC_DEBUGPL(DBG_ANY, "Exiting from xHIB state\n");
  65125. + retval |= dwc_otg_handle_xhib_exit_intr(core_if);
  65126. + core_if->xhib = 2;
  65127. + if (core_if->lock)
  65128. + DWC_SPINUNLOCK(core_if->lock);
  65129. +
  65130. + return retval;
  65131. + }
  65132. +
  65133. + if (core_if->hibernation_suspend <= 0) {
  65134. + /* read_common will have to poke the FIQ's saved mask. We must then clear this mask at the end
  65135. + * of this handler - god only knows why it's done like this
  65136. + */
  65137. + gintsts.d32 = dwc_otg_read_common_intr(core_if, &gintmsk_reenable, otg_dev->hcd);
  65138. +
  65139. + if (gintsts.b.modemismatch) {
  65140. + retval |= dwc_otg_handle_mode_mismatch_intr(core_if);
  65141. + }
  65142. + if (gintsts.b.otgintr) {
  65143. + retval |= dwc_otg_handle_otg_intr(core_if);
  65144. + }
  65145. + if (gintsts.b.conidstschng) {
  65146. + retval |=
  65147. + dwc_otg_handle_conn_id_status_change_intr(core_if);
  65148. + }
  65149. + if (gintsts.b.disconnect) {
  65150. + retval |= dwc_otg_handle_disconnect_intr(core_if);
  65151. + }
  65152. + if (gintsts.b.sessreqintr) {
  65153. + retval |= dwc_otg_handle_session_req_intr(core_if);
  65154. + }
  65155. + if (gintsts.b.wkupintr) {
  65156. + retval |= dwc_otg_handle_wakeup_detected_intr(core_if);
  65157. + }
  65158. + if (gintsts.b.usbsuspend) {
  65159. + retval |= dwc_otg_handle_usb_suspend_intr(core_if);
  65160. + }
  65161. +#ifdef CONFIG_USB_DWC_OTG_LPM
  65162. + if (gintsts.b.lpmtranrcvd) {
  65163. + retval |= dwc_otg_handle_lpm_intr(core_if);
  65164. + }
  65165. +#endif
  65166. + if (gintsts.b.restoredone) {
  65167. + gintsts.d32 = 0;
  65168. + if (core_if->power_down == 2)
  65169. + core_if->hibernation_suspend = -1;
  65170. + else if (core_if->power_down == 3 && core_if->xhib == 2) {
  65171. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  65172. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  65173. + dctl_data_t dctl = {.d32 = 0 };
  65174. +
  65175. + DWC_WRITE_REG32(&core_if->core_global_regs->
  65176. + gintsts, 0xFFFFFFFF);
  65177. +
  65178. + DWC_DEBUGPL(DBG_ANY,
  65179. + "RESTORE DONE generated\n");
  65180. +
  65181. + gpwrdn.b.restore = 1;
  65182. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65183. + dwc_udelay(10);
  65184. +
  65185. + pcgcctl.b.rstpdwnmodule = 1;
  65186. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  65187. +
  65188. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, core_if->gr_backup->gusbcfg_local);
  65189. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg, core_if->dr_backup->dcfg);
  65190. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, core_if->dr_backup->dctl);
  65191. + dwc_udelay(50);
  65192. +
  65193. + dctl.b.pwronprgdone = 1;
  65194. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  65195. + dwc_udelay(10);
  65196. +
  65197. + dwc_otg_restore_global_regs(core_if);
  65198. + dwc_otg_restore_dev_regs(core_if, 0);
  65199. +
  65200. + dctl.d32 = 0;
  65201. + dctl.b.pwronprgdone = 1;
  65202. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32, 0);
  65203. + dwc_udelay(10);
  65204. +
  65205. + pcgcctl.d32 = 0;
  65206. + pcgcctl.b.enbl_extnd_hiber = 1;
  65207. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  65208. +
  65209. + /* The core will be in ON STATE */
  65210. + core_if->lx_state = DWC_OTG_L0;
  65211. + core_if->xhib = 0;
  65212. +
  65213. + DWC_SPINUNLOCK(core_if->lock);
  65214. + if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
  65215. + core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
  65216. + }
  65217. + DWC_SPINLOCK(core_if->lock);
  65218. +
  65219. + }
  65220. +
  65221. + gintsts.b.restoredone = 1;
  65222. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts,gintsts.d32);
  65223. + DWC_PRINTF(" --Restore done interrupt received-- \n");
  65224. + retval |= 1;
  65225. + }
  65226. + if (gintsts.b.portintr && dwc_otg_is_device_mode(core_if)) {
  65227. + /* The port interrupt occurs while in device mode with HPRT0
  65228. + * Port Enable/Disable.
  65229. + */
  65230. + gintsts.d32 = 0;
  65231. + gintsts.b.portintr = 1;
  65232. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts,gintsts.d32);
  65233. + retval |= 1;
  65234. + gintmsk_reenable.b.portintr = 1;
  65235. +
  65236. + }
  65237. + /* Did we actually handle anything? if so, unmask the interrupt */
  65238. +// fiq_print(FIQDBG_INT, otg_dev->hcd->fiq_state, "CILOUT %1d", retval);
  65239. +// fiq_print(FIQDBG_INT, otg_dev->hcd->fiq_state, "%08x", gintsts.d32);
  65240. +// fiq_print(FIQDBG_INT, otg_dev->hcd->fiq_state, "%08x", gintmsk_reenable.d32);
  65241. + if (retval) {
  65242. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gintmsk_reenable.d32);
  65243. + }
  65244. +
  65245. + } else {
  65246. + DWC_DEBUGPL(DBG_ANY, "gpwrdn=%08x\n", gpwrdn.d32);
  65247. +
  65248. + if (gpwrdn.b.disconn_det && gpwrdn.b.disconn_det_msk) {
  65249. + CLEAR_GPWRDN_INTR(core_if, disconn_det);
  65250. + if (gpwrdn.b.linestate == 0) {
  65251. + dwc_otg_handle_pwrdn_disconnect_intr(core_if);
  65252. + } else {
  65253. + DWC_PRINTF("Disconnect detected while linestate is not 0\n");
  65254. + }
  65255. +
  65256. + retval |= 1;
  65257. + }
  65258. + if (gpwrdn.b.lnstschng && gpwrdn.b.lnstchng_msk) {
  65259. + CLEAR_GPWRDN_INTR(core_if, lnstschng);
  65260. + /* remote wakeup from hibernation */
  65261. + if (gpwrdn.b.linestate == 2 || gpwrdn.b.linestate == 1) {
  65262. + dwc_otg_handle_pwrdn_wakeup_detected_intr(core_if);
  65263. + } else {
  65264. + DWC_PRINTF("gpwrdn.linestate = %d\n", gpwrdn.b.linestate);
  65265. + }
  65266. + retval |= 1;
  65267. + }
  65268. + if (gpwrdn.b.rst_det && gpwrdn.b.rst_det_msk) {
  65269. + CLEAR_GPWRDN_INTR(core_if, rst_det);
  65270. + if (gpwrdn.b.linestate == 0) {
  65271. + DWC_PRINTF("Reset detected\n");
  65272. + retval |= dwc_otg_device_hibernation_restore(core_if, 0, 1);
  65273. + }
  65274. + }
  65275. + if (gpwrdn.b.srp_det && gpwrdn.b.srp_det_msk) {
  65276. + CLEAR_GPWRDN_INTR(core_if, srp_det);
  65277. + dwc_otg_handle_pwrdn_srp_intr(core_if);
  65278. + retval |= 1;
  65279. + }
  65280. + }
  65281. + /* Handle ADP interrupt here */
  65282. + if (gpwrdn.b.adp_int) {
  65283. + DWC_PRINTF("ADP interrupt\n");
  65284. + CLEAR_GPWRDN_INTR(core_if, adp_int);
  65285. + dwc_otg_adp_handle_intr(core_if);
  65286. + retval |= 1;
  65287. + }
  65288. + if (gpwrdn.b.sts_chngint && gpwrdn.b.sts_chngint_msk) {
  65289. + DWC_PRINTF("STS CHNG interrupt asserted\n");
  65290. + CLEAR_GPWRDN_INTR(core_if, sts_chngint);
  65291. + dwc_otg_handle_pwrdn_stschng_intr(otg_dev);
  65292. +
  65293. + retval |= 1;
  65294. + }
  65295. + if (core_if->lock)
  65296. + DWC_SPINUNLOCK(core_if->lock);
  65297. + return retval;
  65298. +}
  65299. diff -Nur linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_core_if.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_core_if.h
  65300. --- linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_core_if.h 1970-01-01 01:00:00.000000000 +0100
  65301. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_core_if.h 2014-04-24 15:37:13.310990489 +0200
  65302. @@ -0,0 +1,705 @@
  65303. +/* ==========================================================================
  65304. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_core_if.h $
  65305. + * $Revision: #13 $
  65306. + * $Date: 2012/08/10 $
  65307. + * $Change: 2047372 $
  65308. + *
  65309. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  65310. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  65311. + * otherwise expressly agreed to in writing between Synopsys and you.
  65312. + *
  65313. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  65314. + * any End User Software License Agreement or Agreement for Licensed Product
  65315. + * with Synopsys or any supplement thereto. You are permitted to use and
  65316. + * redistribute this Software in source and binary forms, with or without
  65317. + * modification, provided that redistributions of source code must retain this
  65318. + * notice. You may not view, use, disclose, copy or distribute this file or
  65319. + * any information contained herein except pursuant to this license grant from
  65320. + * Synopsys. If you do not agree with this notice, including the disclaimer
  65321. + * below, then you are not authorized to use the Software.
  65322. + *
  65323. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  65324. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  65325. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  65326. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  65327. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  65328. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  65329. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  65330. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  65331. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  65332. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  65333. + * DAMAGE.
  65334. + * ========================================================================== */
  65335. +#if !defined(__DWC_CORE_IF_H__)
  65336. +#define __DWC_CORE_IF_H__
  65337. +
  65338. +#include "dwc_os.h"
  65339. +
  65340. +/** @file
  65341. + * This file defines DWC_OTG Core API
  65342. + */
  65343. +
  65344. +struct dwc_otg_core_if;
  65345. +typedef struct dwc_otg_core_if dwc_otg_core_if_t;
  65346. +
  65347. +/** Maximum number of Periodic FIFOs */
  65348. +#define MAX_PERIO_FIFOS 15
  65349. +/** Maximum number of Periodic FIFOs */
  65350. +#define MAX_TX_FIFOS 15
  65351. +
  65352. +/** Maximum number of Endpoints/HostChannels */
  65353. +#define MAX_EPS_CHANNELS 16
  65354. +
  65355. +extern dwc_otg_core_if_t *dwc_otg_cil_init(const uint32_t * _reg_base_addr);
  65356. +extern void dwc_otg_core_init(dwc_otg_core_if_t * _core_if);
  65357. +extern void dwc_otg_cil_remove(dwc_otg_core_if_t * _core_if);
  65358. +
  65359. +extern void dwc_otg_enable_global_interrupts(dwc_otg_core_if_t * _core_if);
  65360. +extern void dwc_otg_disable_global_interrupts(dwc_otg_core_if_t * _core_if);
  65361. +
  65362. +extern uint8_t dwc_otg_is_device_mode(dwc_otg_core_if_t * _core_if);
  65363. +extern uint8_t dwc_otg_is_host_mode(dwc_otg_core_if_t * _core_if);
  65364. +
  65365. +extern uint8_t dwc_otg_is_dma_enable(dwc_otg_core_if_t * core_if);
  65366. +
  65367. +/** This function should be called on every hardware interrupt. */
  65368. +extern int32_t dwc_otg_handle_common_intr(void *otg_dev);
  65369. +
  65370. +/** @name OTG Core Parameters */
  65371. +/** @{ */
  65372. +
  65373. +/**
  65374. + * Specifies the OTG capabilities. The driver will automatically
  65375. + * detect the value for this parameter if none is specified.
  65376. + * 0 - HNP and SRP capable (default)
  65377. + * 1 - SRP Only capable
  65378. + * 2 - No HNP/SRP capable
  65379. + */
  65380. +extern int dwc_otg_set_param_otg_cap(dwc_otg_core_if_t * core_if, int32_t val);
  65381. +extern int32_t dwc_otg_get_param_otg_cap(dwc_otg_core_if_t * core_if);
  65382. +#define DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE 0
  65383. +#define DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE 1
  65384. +#define DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE 2
  65385. +#define dwc_param_otg_cap_default DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE
  65386. +
  65387. +extern int dwc_otg_set_param_opt(dwc_otg_core_if_t * core_if, int32_t val);
  65388. +extern int32_t dwc_otg_get_param_opt(dwc_otg_core_if_t * core_if);
  65389. +#define dwc_param_opt_default 1
  65390. +
  65391. +/**
  65392. + * Specifies whether to use slave or DMA mode for accessing the data
  65393. + * FIFOs. The driver will automatically detect the value for this
  65394. + * parameter if none is specified.
  65395. + * 0 - Slave
  65396. + * 1 - DMA (default, if available)
  65397. + */
  65398. +extern int dwc_otg_set_param_dma_enable(dwc_otg_core_if_t * core_if,
  65399. + int32_t val);
  65400. +extern int32_t dwc_otg_get_param_dma_enable(dwc_otg_core_if_t * core_if);
  65401. +#define dwc_param_dma_enable_default 1
  65402. +
  65403. +/**
  65404. + * When DMA mode is enabled specifies whether to use
  65405. + * address DMA or DMA Descritor mode for accessing the data
  65406. + * FIFOs in device mode. The driver will automatically detect
  65407. + * the value for this parameter if none is specified.
  65408. + * 0 - address DMA
  65409. + * 1 - DMA Descriptor(default, if available)
  65410. + */
  65411. +extern int dwc_otg_set_param_dma_desc_enable(dwc_otg_core_if_t * core_if,
  65412. + int32_t val);
  65413. +extern int32_t dwc_otg_get_param_dma_desc_enable(dwc_otg_core_if_t * core_if);
  65414. +//#define dwc_param_dma_desc_enable_default 1
  65415. +#define dwc_param_dma_desc_enable_default 0 // Broadcom BCM2708
  65416. +
  65417. +/** The DMA Burst size (applicable only for External DMA
  65418. + * Mode). 1, 4, 8 16, 32, 64, 128, 256 (default 32)
  65419. + */
  65420. +extern int dwc_otg_set_param_dma_burst_size(dwc_otg_core_if_t * core_if,
  65421. + int32_t val);
  65422. +extern int32_t dwc_otg_get_param_dma_burst_size(dwc_otg_core_if_t * core_if);
  65423. +#define dwc_param_dma_burst_size_default 32
  65424. +
  65425. +/**
  65426. + * Specifies the maximum speed of operation in host and device mode.
  65427. + * The actual speed depends on the speed of the attached device and
  65428. + * the value of phy_type. The actual speed depends on the speed of the
  65429. + * attached device.
  65430. + * 0 - High Speed (default)
  65431. + * 1 - Full Speed
  65432. + */
  65433. +extern int dwc_otg_set_param_speed(dwc_otg_core_if_t * core_if, int32_t val);
  65434. +extern int32_t dwc_otg_get_param_speed(dwc_otg_core_if_t * core_if);
  65435. +#define dwc_param_speed_default 0
  65436. +#define DWC_SPEED_PARAM_HIGH 0
  65437. +#define DWC_SPEED_PARAM_FULL 1
  65438. +
  65439. +/** Specifies whether low power mode is supported when attached
  65440. + * to a Full Speed or Low Speed device in host mode.
  65441. + * 0 - Don't support low power mode (default)
  65442. + * 1 - Support low power mode
  65443. + */
  65444. +extern int dwc_otg_set_param_host_support_fs_ls_low_power(dwc_otg_core_if_t *
  65445. + core_if, int32_t val);
  65446. +extern int32_t dwc_otg_get_param_host_support_fs_ls_low_power(dwc_otg_core_if_t
  65447. + * core_if);
  65448. +#define dwc_param_host_support_fs_ls_low_power_default 0
  65449. +
  65450. +/** Specifies the PHY clock rate in low power mode when connected to a
  65451. + * Low Speed device in host mode. This parameter is applicable only if
  65452. + * HOST_SUPPORT_FS_LS_LOW_POWER is enabled. If PHY_TYPE is set to FS
  65453. + * then defaults to 6 MHZ otherwise 48 MHZ.
  65454. + *
  65455. + * 0 - 48 MHz
  65456. + * 1 - 6 MHz
  65457. + */
  65458. +extern int dwc_otg_set_param_host_ls_low_power_phy_clk(dwc_otg_core_if_t *
  65459. + core_if, int32_t val);
  65460. +extern int32_t dwc_otg_get_param_host_ls_low_power_phy_clk(dwc_otg_core_if_t *
  65461. + core_if);
  65462. +#define dwc_param_host_ls_low_power_phy_clk_default 0
  65463. +#define DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ 0
  65464. +#define DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ 1
  65465. +
  65466. +/**
  65467. + * 0 - Use cC FIFO size parameters
  65468. + * 1 - Allow dynamic FIFO sizing (default)
  65469. + */
  65470. +extern int dwc_otg_set_param_enable_dynamic_fifo(dwc_otg_core_if_t * core_if,
  65471. + int32_t val);
  65472. +extern int32_t dwc_otg_get_param_enable_dynamic_fifo(dwc_otg_core_if_t *
  65473. + core_if);
  65474. +#define dwc_param_enable_dynamic_fifo_default 1
  65475. +
  65476. +/** Total number of 4-byte words in the data FIFO memory. This
  65477. + * memory includes the Rx FIFO, non-periodic Tx FIFO, and periodic
  65478. + * Tx FIFOs.
  65479. + * 32 to 32768 (default 8192)
  65480. + * Note: The total FIFO memory depth in the FPGA configuration is 8192.
  65481. + */
  65482. +extern int dwc_otg_set_param_data_fifo_size(dwc_otg_core_if_t * core_if,
  65483. + int32_t val);
  65484. +extern int32_t dwc_otg_get_param_data_fifo_size(dwc_otg_core_if_t * core_if);
  65485. +//#define dwc_param_data_fifo_size_default 8192
  65486. +#define dwc_param_data_fifo_size_default 0xFF0 // Broadcom BCM2708
  65487. +
  65488. +/** Number of 4-byte words in the Rx FIFO in device mode when dynamic
  65489. + * FIFO sizing is enabled.
  65490. + * 16 to 32768 (default 1064)
  65491. + */
  65492. +extern int dwc_otg_set_param_dev_rx_fifo_size(dwc_otg_core_if_t * core_if,
  65493. + int32_t val);
  65494. +extern int32_t dwc_otg_get_param_dev_rx_fifo_size(dwc_otg_core_if_t * core_if);
  65495. +#define dwc_param_dev_rx_fifo_size_default 1064
  65496. +
  65497. +/** Number of 4-byte words in the non-periodic Tx FIFO in device mode
  65498. + * when dynamic FIFO sizing is enabled.
  65499. + * 16 to 32768 (default 1024)
  65500. + */
  65501. +extern int dwc_otg_set_param_dev_nperio_tx_fifo_size(dwc_otg_core_if_t *
  65502. + core_if, int32_t val);
  65503. +extern int32_t dwc_otg_get_param_dev_nperio_tx_fifo_size(dwc_otg_core_if_t *
  65504. + core_if);
  65505. +#define dwc_param_dev_nperio_tx_fifo_size_default 1024
  65506. +
  65507. +/** Number of 4-byte words in each of the periodic Tx FIFOs in device
  65508. + * mode when dynamic FIFO sizing is enabled.
  65509. + * 4 to 768 (default 256)
  65510. + */
  65511. +extern int dwc_otg_set_param_dev_perio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  65512. + int32_t val, int fifo_num);
  65513. +extern int32_t dwc_otg_get_param_dev_perio_tx_fifo_size(dwc_otg_core_if_t *
  65514. + core_if, int fifo_num);
  65515. +#define dwc_param_dev_perio_tx_fifo_size_default 256
  65516. +
  65517. +/** Number of 4-byte words in the Rx FIFO in host mode when dynamic
  65518. + * FIFO sizing is enabled.
  65519. + * 16 to 32768 (default 1024)
  65520. + */
  65521. +extern int dwc_otg_set_param_host_rx_fifo_size(dwc_otg_core_if_t * core_if,
  65522. + int32_t val);
  65523. +extern int32_t dwc_otg_get_param_host_rx_fifo_size(dwc_otg_core_if_t * core_if);
  65524. +//#define dwc_param_host_rx_fifo_size_default 1024
  65525. +#define dwc_param_host_rx_fifo_size_default 774 // Broadcom BCM2708
  65526. +
  65527. +/** Number of 4-byte words in the non-periodic Tx FIFO in host mode
  65528. + * when Dynamic FIFO sizing is enabled in the core.
  65529. + * 16 to 32768 (default 1024)
  65530. + */
  65531. +extern int dwc_otg_set_param_host_nperio_tx_fifo_size(dwc_otg_core_if_t *
  65532. + core_if, int32_t val);
  65533. +extern int32_t dwc_otg_get_param_host_nperio_tx_fifo_size(dwc_otg_core_if_t *
  65534. + core_if);
  65535. +//#define dwc_param_host_nperio_tx_fifo_size_default 1024
  65536. +#define dwc_param_host_nperio_tx_fifo_size_default 0x100 // Broadcom BCM2708
  65537. +
  65538. +/** Number of 4-byte words in the host periodic Tx FIFO when dynamic
  65539. + * FIFO sizing is enabled.
  65540. + * 16 to 32768 (default 1024)
  65541. + */
  65542. +extern int dwc_otg_set_param_host_perio_tx_fifo_size(dwc_otg_core_if_t *
  65543. + core_if, int32_t val);
  65544. +extern int32_t dwc_otg_get_param_host_perio_tx_fifo_size(dwc_otg_core_if_t *
  65545. + core_if);
  65546. +//#define dwc_param_host_perio_tx_fifo_size_default 1024
  65547. +#define dwc_param_host_perio_tx_fifo_size_default 0x200 // Broadcom BCM2708
  65548. +
  65549. +/** The maximum transfer size supported in bytes.
  65550. + * 2047 to 65,535 (default 65,535)
  65551. + */
  65552. +extern int dwc_otg_set_param_max_transfer_size(dwc_otg_core_if_t * core_if,
  65553. + int32_t val);
  65554. +extern int32_t dwc_otg_get_param_max_transfer_size(dwc_otg_core_if_t * core_if);
  65555. +#define dwc_param_max_transfer_size_default 65535
  65556. +
  65557. +/** The maximum number of packets in a transfer.
  65558. + * 15 to 511 (default 511)
  65559. + */
  65560. +extern int dwc_otg_set_param_max_packet_count(dwc_otg_core_if_t * core_if,
  65561. + int32_t val);
  65562. +extern int32_t dwc_otg_get_param_max_packet_count(dwc_otg_core_if_t * core_if);
  65563. +#define dwc_param_max_packet_count_default 511
  65564. +
  65565. +/** The number of host channel registers to use.
  65566. + * 1 to 16 (default 12)
  65567. + * Note: The FPGA configuration supports a maximum of 12 host channels.
  65568. + */
  65569. +extern int dwc_otg_set_param_host_channels(dwc_otg_core_if_t * core_if,
  65570. + int32_t val);
  65571. +extern int32_t dwc_otg_get_param_host_channels(dwc_otg_core_if_t * core_if);
  65572. +//#define dwc_param_host_channels_default 12
  65573. +#define dwc_param_host_channels_default 8 // Broadcom BCM2708
  65574. +
  65575. +/** The number of endpoints in addition to EP0 available for device
  65576. + * mode operations.
  65577. + * 1 to 15 (default 6 IN and OUT)
  65578. + * Note: The FPGA configuration supports a maximum of 6 IN and OUT
  65579. + * endpoints in addition to EP0.
  65580. + */
  65581. +extern int dwc_otg_set_param_dev_endpoints(dwc_otg_core_if_t * core_if,
  65582. + int32_t val);
  65583. +extern int32_t dwc_otg_get_param_dev_endpoints(dwc_otg_core_if_t * core_if);
  65584. +#define dwc_param_dev_endpoints_default 6
  65585. +
  65586. +/**
  65587. + * Specifies the type of PHY interface to use. By default, the driver
  65588. + * will automatically detect the phy_type.
  65589. + *
  65590. + * 0 - Full Speed PHY
  65591. + * 1 - UTMI+ (default)
  65592. + * 2 - ULPI
  65593. + */
  65594. +extern int dwc_otg_set_param_phy_type(dwc_otg_core_if_t * core_if, int32_t val);
  65595. +extern int32_t dwc_otg_get_param_phy_type(dwc_otg_core_if_t * core_if);
  65596. +#define DWC_PHY_TYPE_PARAM_FS 0
  65597. +#define DWC_PHY_TYPE_PARAM_UTMI 1
  65598. +#define DWC_PHY_TYPE_PARAM_ULPI 2
  65599. +#define dwc_param_phy_type_default DWC_PHY_TYPE_PARAM_UTMI
  65600. +
  65601. +/**
  65602. + * Specifies the UTMI+ Data Width. This parameter is
  65603. + * applicable for a PHY_TYPE of UTMI+ or ULPI. (For a ULPI
  65604. + * PHY_TYPE, this parameter indicates the data width between
  65605. + * the MAC and the ULPI Wrapper.) Also, this parameter is
  65606. + * applicable only if the OTG_HSPHY_WIDTH cC parameter was set
  65607. + * to "8 and 16 bits", meaning that the core has been
  65608. + * configured to work at either data path width.
  65609. + *
  65610. + * 8 or 16 bits (default 16)
  65611. + */
  65612. +extern int dwc_otg_set_param_phy_utmi_width(dwc_otg_core_if_t * core_if,
  65613. + int32_t val);
  65614. +extern int32_t dwc_otg_get_param_phy_utmi_width(dwc_otg_core_if_t * core_if);
  65615. +//#define dwc_param_phy_utmi_width_default 16
  65616. +#define dwc_param_phy_utmi_width_default 8 // Broadcom BCM2708
  65617. +
  65618. +/**
  65619. + * Specifies whether the ULPI operates at double or single
  65620. + * data rate. This parameter is only applicable if PHY_TYPE is
  65621. + * ULPI.
  65622. + *
  65623. + * 0 - single data rate ULPI interface with 8 bit wide data
  65624. + * bus (default)
  65625. + * 1 - double data rate ULPI interface with 4 bit wide data
  65626. + * bus
  65627. + */
  65628. +extern int dwc_otg_set_param_phy_ulpi_ddr(dwc_otg_core_if_t * core_if,
  65629. + int32_t val);
  65630. +extern int32_t dwc_otg_get_param_phy_ulpi_ddr(dwc_otg_core_if_t * core_if);
  65631. +#define dwc_param_phy_ulpi_ddr_default 0
  65632. +
  65633. +/**
  65634. + * Specifies whether to use the internal or external supply to
  65635. + * drive the vbus with a ULPI phy.
  65636. + */
  65637. +extern int dwc_otg_set_param_phy_ulpi_ext_vbus(dwc_otg_core_if_t * core_if,
  65638. + int32_t val);
  65639. +extern int32_t dwc_otg_get_param_phy_ulpi_ext_vbus(dwc_otg_core_if_t * core_if);
  65640. +#define DWC_PHY_ULPI_INTERNAL_VBUS 0
  65641. +#define DWC_PHY_ULPI_EXTERNAL_VBUS 1
  65642. +#define dwc_param_phy_ulpi_ext_vbus_default DWC_PHY_ULPI_INTERNAL_VBUS
  65643. +
  65644. +/**
  65645. + * Specifies whether to use the I2Cinterface for full speed PHY. This
  65646. + * parameter is only applicable if PHY_TYPE is FS.
  65647. + * 0 - No (default)
  65648. + * 1 - Yes
  65649. + */
  65650. +extern int dwc_otg_set_param_i2c_enable(dwc_otg_core_if_t * core_if,
  65651. + int32_t val);
  65652. +extern int32_t dwc_otg_get_param_i2c_enable(dwc_otg_core_if_t * core_if);
  65653. +#define dwc_param_i2c_enable_default 0
  65654. +
  65655. +extern int dwc_otg_set_param_ulpi_fs_ls(dwc_otg_core_if_t * core_if,
  65656. + int32_t val);
  65657. +extern int32_t dwc_otg_get_param_ulpi_fs_ls(dwc_otg_core_if_t * core_if);
  65658. +#define dwc_param_ulpi_fs_ls_default 0
  65659. +
  65660. +extern int dwc_otg_set_param_ts_dline(dwc_otg_core_if_t * core_if, int32_t val);
  65661. +extern int32_t dwc_otg_get_param_ts_dline(dwc_otg_core_if_t * core_if);
  65662. +#define dwc_param_ts_dline_default 0
  65663. +
  65664. +/**
  65665. + * Specifies whether dedicated transmit FIFOs are
  65666. + * enabled for non periodic IN endpoints in device mode
  65667. + * 0 - No
  65668. + * 1 - Yes
  65669. + */
  65670. +extern int dwc_otg_set_param_en_multiple_tx_fifo(dwc_otg_core_if_t * core_if,
  65671. + int32_t val);
  65672. +extern int32_t dwc_otg_get_param_en_multiple_tx_fifo(dwc_otg_core_if_t *
  65673. + core_if);
  65674. +#define dwc_param_en_multiple_tx_fifo_default 1
  65675. +
  65676. +/** Number of 4-byte words in each of the Tx FIFOs in device
  65677. + * mode when dynamic FIFO sizing is enabled.
  65678. + * 4 to 768 (default 256)
  65679. + */
  65680. +extern int dwc_otg_set_param_dev_tx_fifo_size(dwc_otg_core_if_t * core_if,
  65681. + int fifo_num, int32_t val);
  65682. +extern int32_t dwc_otg_get_param_dev_tx_fifo_size(dwc_otg_core_if_t * core_if,
  65683. + int fifo_num);
  65684. +#define dwc_param_dev_tx_fifo_size_default 768
  65685. +
  65686. +/** Thresholding enable flag-
  65687. + * bit 0 - enable non-ISO Tx thresholding
  65688. + * bit 1 - enable ISO Tx thresholding
  65689. + * bit 2 - enable Rx thresholding
  65690. + */
  65691. +extern int dwc_otg_set_param_thr_ctl(dwc_otg_core_if_t * core_if, int32_t val);
  65692. +extern int32_t dwc_otg_get_thr_ctl(dwc_otg_core_if_t * core_if, int fifo_num);
  65693. +#define dwc_param_thr_ctl_default 0
  65694. +
  65695. +/** Thresholding length for Tx
  65696. + * FIFOs in 32 bit DWORDs
  65697. + */
  65698. +extern int dwc_otg_set_param_tx_thr_length(dwc_otg_core_if_t * core_if,
  65699. + int32_t val);
  65700. +extern int32_t dwc_otg_get_tx_thr_length(dwc_otg_core_if_t * core_if);
  65701. +#define dwc_param_tx_thr_length_default 64
  65702. +
  65703. +/** Thresholding length for Rx
  65704. + * FIFOs in 32 bit DWORDs
  65705. + */
  65706. +extern int dwc_otg_set_param_rx_thr_length(dwc_otg_core_if_t * core_if,
  65707. + int32_t val);
  65708. +extern int32_t dwc_otg_get_rx_thr_length(dwc_otg_core_if_t * core_if);
  65709. +#define dwc_param_rx_thr_length_default 64
  65710. +
  65711. +/**
  65712. + * Specifies whether LPM (Link Power Management) support is enabled
  65713. + */
  65714. +extern int dwc_otg_set_param_lpm_enable(dwc_otg_core_if_t * core_if,
  65715. + int32_t val);
  65716. +extern int32_t dwc_otg_get_param_lpm_enable(dwc_otg_core_if_t * core_if);
  65717. +#define dwc_param_lpm_enable_default 1
  65718. +
  65719. +/**
  65720. + * Specifies whether PTI enhancement is enabled
  65721. + */
  65722. +extern int dwc_otg_set_param_pti_enable(dwc_otg_core_if_t * core_if,
  65723. + int32_t val);
  65724. +extern int32_t dwc_otg_get_param_pti_enable(dwc_otg_core_if_t * core_if);
  65725. +#define dwc_param_pti_enable_default 0
  65726. +
  65727. +/**
  65728. + * Specifies whether MPI enhancement is enabled
  65729. + */
  65730. +extern int dwc_otg_set_param_mpi_enable(dwc_otg_core_if_t * core_if,
  65731. + int32_t val);
  65732. +extern int32_t dwc_otg_get_param_mpi_enable(dwc_otg_core_if_t * core_if);
  65733. +#define dwc_param_mpi_enable_default 0
  65734. +
  65735. +/**
  65736. + * Specifies whether ADP capability is enabled
  65737. + */
  65738. +extern int dwc_otg_set_param_adp_enable(dwc_otg_core_if_t * core_if,
  65739. + int32_t val);
  65740. +extern int32_t dwc_otg_get_param_adp_enable(dwc_otg_core_if_t * core_if);
  65741. +#define dwc_param_adp_enable_default 0
  65742. +
  65743. +/**
  65744. + * Specifies whether IC_USB capability is enabled
  65745. + */
  65746. +
  65747. +extern int dwc_otg_set_param_ic_usb_cap(dwc_otg_core_if_t * core_if,
  65748. + int32_t val);
  65749. +extern int32_t dwc_otg_get_param_ic_usb_cap(dwc_otg_core_if_t * core_if);
  65750. +#define dwc_param_ic_usb_cap_default 0
  65751. +
  65752. +extern int dwc_otg_set_param_ahb_thr_ratio(dwc_otg_core_if_t * core_if,
  65753. + int32_t val);
  65754. +extern int32_t dwc_otg_get_param_ahb_thr_ratio(dwc_otg_core_if_t * core_if);
  65755. +#define dwc_param_ahb_thr_ratio_default 0
  65756. +
  65757. +extern int dwc_otg_set_param_power_down(dwc_otg_core_if_t * core_if,
  65758. + int32_t val);
  65759. +extern int32_t dwc_otg_get_param_power_down(dwc_otg_core_if_t * core_if);
  65760. +#define dwc_param_power_down_default 0
  65761. +
  65762. +extern int dwc_otg_set_param_reload_ctl(dwc_otg_core_if_t * core_if,
  65763. + int32_t val);
  65764. +extern int32_t dwc_otg_get_param_reload_ctl(dwc_otg_core_if_t * core_if);
  65765. +#define dwc_param_reload_ctl_default 0
  65766. +
  65767. +extern int dwc_otg_set_param_dev_out_nak(dwc_otg_core_if_t * core_if,
  65768. + int32_t val);
  65769. +extern int32_t dwc_otg_get_param_dev_out_nak(dwc_otg_core_if_t * core_if);
  65770. +#define dwc_param_dev_out_nak_default 0
  65771. +
  65772. +extern int dwc_otg_set_param_cont_on_bna(dwc_otg_core_if_t * core_if,
  65773. + int32_t val);
  65774. +extern int32_t dwc_otg_get_param_cont_on_bna(dwc_otg_core_if_t * core_if);
  65775. +#define dwc_param_cont_on_bna_default 0
  65776. +
  65777. +extern int dwc_otg_set_param_ahb_single(dwc_otg_core_if_t * core_if,
  65778. + int32_t val);
  65779. +extern int32_t dwc_otg_get_param_ahb_single(dwc_otg_core_if_t * core_if);
  65780. +#define dwc_param_ahb_single_default 0
  65781. +
  65782. +extern int dwc_otg_set_param_otg_ver(dwc_otg_core_if_t * core_if, int32_t val);
  65783. +extern int32_t dwc_otg_get_param_otg_ver(dwc_otg_core_if_t * core_if);
  65784. +#define dwc_param_otg_ver_default 0
  65785. +
  65786. +/** @} */
  65787. +
  65788. +/** @name Access to registers and bit-fields */
  65789. +
  65790. +/**
  65791. + * Dump core registers and SPRAM
  65792. + */
  65793. +extern void dwc_otg_dump_dev_registers(dwc_otg_core_if_t * _core_if);
  65794. +extern void dwc_otg_dump_spram(dwc_otg_core_if_t * _core_if);
  65795. +extern void dwc_otg_dump_host_registers(dwc_otg_core_if_t * _core_if);
  65796. +extern void dwc_otg_dump_global_registers(dwc_otg_core_if_t * _core_if);
  65797. +
  65798. +/**
  65799. + * Get host negotiation status.
  65800. + */
  65801. +extern uint32_t dwc_otg_get_hnpstatus(dwc_otg_core_if_t * core_if);
  65802. +
  65803. +/**
  65804. + * Get srp status
  65805. + */
  65806. +extern uint32_t dwc_otg_get_srpstatus(dwc_otg_core_if_t * core_if);
  65807. +
  65808. +/**
  65809. + * Set hnpreq bit in the GOTGCTL register.
  65810. + */
  65811. +extern void dwc_otg_set_hnpreq(dwc_otg_core_if_t * core_if, uint32_t val);
  65812. +
  65813. +/**
  65814. + * Get Content of SNPSID register.
  65815. + */
  65816. +extern uint32_t dwc_otg_get_gsnpsid(dwc_otg_core_if_t * core_if);
  65817. +
  65818. +/**
  65819. + * Get current mode.
  65820. + * Returns 0 if in device mode, and 1 if in host mode.
  65821. + */
  65822. +extern uint32_t dwc_otg_get_mode(dwc_otg_core_if_t * core_if);
  65823. +
  65824. +/**
  65825. + * Get value of hnpcapable field in the GUSBCFG register
  65826. + */
  65827. +extern uint32_t dwc_otg_get_hnpcapable(dwc_otg_core_if_t * core_if);
  65828. +/**
  65829. + * Set value of hnpcapable field in the GUSBCFG register
  65830. + */
  65831. +extern void dwc_otg_set_hnpcapable(dwc_otg_core_if_t * core_if, uint32_t val);
  65832. +
  65833. +/**
  65834. + * Get value of srpcapable field in the GUSBCFG register
  65835. + */
  65836. +extern uint32_t dwc_otg_get_srpcapable(dwc_otg_core_if_t * core_if);
  65837. +/**
  65838. + * Set value of srpcapable field in the GUSBCFG register
  65839. + */
  65840. +extern void dwc_otg_set_srpcapable(dwc_otg_core_if_t * core_if, uint32_t val);
  65841. +
  65842. +/**
  65843. + * Get value of devspeed field in the DCFG register
  65844. + */
  65845. +extern uint32_t dwc_otg_get_devspeed(dwc_otg_core_if_t * core_if);
  65846. +/**
  65847. + * Set value of devspeed field in the DCFG register
  65848. + */
  65849. +extern void dwc_otg_set_devspeed(dwc_otg_core_if_t * core_if, uint32_t val);
  65850. +
  65851. +/**
  65852. + * Get the value of busconnected field from the HPRT0 register
  65853. + */
  65854. +extern uint32_t dwc_otg_get_busconnected(dwc_otg_core_if_t * core_if);
  65855. +
  65856. +/**
  65857. + * Gets the device enumeration Speed.
  65858. + */
  65859. +extern uint32_t dwc_otg_get_enumspeed(dwc_otg_core_if_t * core_if);
  65860. +
  65861. +/**
  65862. + * Get value of prtpwr field from the HPRT0 register
  65863. + */
  65864. +extern uint32_t dwc_otg_get_prtpower(dwc_otg_core_if_t * core_if);
  65865. +
  65866. +/**
  65867. + * Get value of flag indicating core state - hibernated or not
  65868. + */
  65869. +extern uint32_t dwc_otg_get_core_state(dwc_otg_core_if_t * core_if);
  65870. +
  65871. +/**
  65872. + * Set value of prtpwr field from the HPRT0 register
  65873. + */
  65874. +extern void dwc_otg_set_prtpower(dwc_otg_core_if_t * core_if, uint32_t val);
  65875. +
  65876. +/**
  65877. + * Get value of prtsusp field from the HPRT0 regsiter
  65878. + */
  65879. +extern uint32_t dwc_otg_get_prtsuspend(dwc_otg_core_if_t * core_if);
  65880. +/**
  65881. + * Set value of prtpwr field from the HPRT0 register
  65882. + */
  65883. +extern void dwc_otg_set_prtsuspend(dwc_otg_core_if_t * core_if, uint32_t val);
  65884. +
  65885. +/**
  65886. + * Get value of ModeChTimEn field from the HCFG regsiter
  65887. + */
  65888. +extern uint32_t dwc_otg_get_mode_ch_tim(dwc_otg_core_if_t * core_if);
  65889. +/**
  65890. + * Set value of ModeChTimEn field from the HCFG regsiter
  65891. + */
  65892. +extern void dwc_otg_set_mode_ch_tim(dwc_otg_core_if_t * core_if, uint32_t val);
  65893. +
  65894. +/**
  65895. + * Get value of Fram Interval field from the HFIR regsiter
  65896. + */
  65897. +extern uint32_t dwc_otg_get_fr_interval(dwc_otg_core_if_t * core_if);
  65898. +/**
  65899. + * Set value of Frame Interval field from the HFIR regsiter
  65900. + */
  65901. +extern void dwc_otg_set_fr_interval(dwc_otg_core_if_t * core_if, uint32_t val);
  65902. +
  65903. +/**
  65904. + * Set value of prtres field from the HPRT0 register
  65905. + *FIXME Remove?
  65906. + */
  65907. +extern void dwc_otg_set_prtresume(dwc_otg_core_if_t * core_if, uint32_t val);
  65908. +
  65909. +/**
  65910. + * Get value of rmtwkupsig bit in DCTL register
  65911. + */
  65912. +extern uint32_t dwc_otg_get_remotewakesig(dwc_otg_core_if_t * core_if);
  65913. +
  65914. +/**
  65915. + * Get value of prt_sleep_sts field from the GLPMCFG register
  65916. + */
  65917. +extern uint32_t dwc_otg_get_lpm_portsleepstatus(dwc_otg_core_if_t * core_if);
  65918. +
  65919. +/**
  65920. + * Get value of rem_wkup_en field from the GLPMCFG register
  65921. + */
  65922. +extern uint32_t dwc_otg_get_lpm_remotewakeenabled(dwc_otg_core_if_t * core_if);
  65923. +
  65924. +/**
  65925. + * Get value of appl_resp field from the GLPMCFG register
  65926. + */
  65927. +extern uint32_t dwc_otg_get_lpmresponse(dwc_otg_core_if_t * core_if);
  65928. +/**
  65929. + * Set value of appl_resp field from the GLPMCFG register
  65930. + */
  65931. +extern void dwc_otg_set_lpmresponse(dwc_otg_core_if_t * core_if, uint32_t val);
  65932. +
  65933. +/**
  65934. + * Get value of hsic_connect field from the GLPMCFG register
  65935. + */
  65936. +extern uint32_t dwc_otg_get_hsic_connect(dwc_otg_core_if_t * core_if);
  65937. +/**
  65938. + * Set value of hsic_connect field from the GLPMCFG register
  65939. + */
  65940. +extern void dwc_otg_set_hsic_connect(dwc_otg_core_if_t * core_if, uint32_t val);
  65941. +
  65942. +/**
  65943. + * Get value of inv_sel_hsic field from the GLPMCFG register.
  65944. + */
  65945. +extern uint32_t dwc_otg_get_inv_sel_hsic(dwc_otg_core_if_t * core_if);
  65946. +/**
  65947. + * Set value of inv_sel_hsic field from the GLPMFG register.
  65948. + */
  65949. +extern void dwc_otg_set_inv_sel_hsic(dwc_otg_core_if_t * core_if, uint32_t val);
  65950. +
  65951. +/*
  65952. + * Some functions for accessing registers
  65953. + */
  65954. +
  65955. +/**
  65956. + * GOTGCTL register
  65957. + */
  65958. +extern uint32_t dwc_otg_get_gotgctl(dwc_otg_core_if_t * core_if);
  65959. +extern void dwc_otg_set_gotgctl(dwc_otg_core_if_t * core_if, uint32_t val);
  65960. +
  65961. +/**
  65962. + * GUSBCFG register
  65963. + */
  65964. +extern uint32_t dwc_otg_get_gusbcfg(dwc_otg_core_if_t * core_if);
  65965. +extern void dwc_otg_set_gusbcfg(dwc_otg_core_if_t * core_if, uint32_t val);
  65966. +
  65967. +/**
  65968. + * GRXFSIZ register
  65969. + */
  65970. +extern uint32_t dwc_otg_get_grxfsiz(dwc_otg_core_if_t * core_if);
  65971. +extern void dwc_otg_set_grxfsiz(dwc_otg_core_if_t * core_if, uint32_t val);
  65972. +
  65973. +/**
  65974. + * GNPTXFSIZ register
  65975. + */
  65976. +extern uint32_t dwc_otg_get_gnptxfsiz(dwc_otg_core_if_t * core_if);
  65977. +extern void dwc_otg_set_gnptxfsiz(dwc_otg_core_if_t * core_if, uint32_t val);
  65978. +
  65979. +extern uint32_t dwc_otg_get_gpvndctl(dwc_otg_core_if_t * core_if);
  65980. +extern void dwc_otg_set_gpvndctl(dwc_otg_core_if_t * core_if, uint32_t val);
  65981. +
  65982. +/**
  65983. + * GGPIO register
  65984. + */
  65985. +extern uint32_t dwc_otg_get_ggpio(dwc_otg_core_if_t * core_if);
  65986. +extern void dwc_otg_set_ggpio(dwc_otg_core_if_t * core_if, uint32_t val);
  65987. +
  65988. +/**
  65989. + * GUID register
  65990. + */
  65991. +extern uint32_t dwc_otg_get_guid(dwc_otg_core_if_t * core_if);
  65992. +extern void dwc_otg_set_guid(dwc_otg_core_if_t * core_if, uint32_t val);
  65993. +
  65994. +/**
  65995. + * HPRT0 register
  65996. + */
  65997. +extern uint32_t dwc_otg_get_hprt0(dwc_otg_core_if_t * core_if);
  65998. +extern void dwc_otg_set_hprt0(dwc_otg_core_if_t * core_if, uint32_t val);
  65999. +
  66000. +/**
  66001. + * GHPTXFSIZE
  66002. + */
  66003. +extern uint32_t dwc_otg_get_hptxfsiz(dwc_otg_core_if_t * core_if);
  66004. +
  66005. +/** @} */
  66006. +
  66007. +#endif /* __DWC_CORE_IF_H__ */
  66008. diff -Nur linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_dbg.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_dbg.h
  66009. --- linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_dbg.h 1970-01-01 01:00:00.000000000 +0100
  66010. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_dbg.h 2014-04-24 15:37:13.310990489 +0200
  66011. @@ -0,0 +1,117 @@
  66012. +/* ==========================================================================
  66013. + *
  66014. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  66015. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  66016. + * otherwise expressly agreed to in writing between Synopsys and you.
  66017. + *
  66018. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  66019. + * any End User Software License Agreement or Agreement for Licensed Product
  66020. + * with Synopsys or any supplement thereto. You are permitted to use and
  66021. + * redistribute this Software in source and binary forms, with or without
  66022. + * modification, provided that redistributions of source code must retain this
  66023. + * notice. You may not view, use, disclose, copy or distribute this file or
  66024. + * any information contained herein except pursuant to this license grant from
  66025. + * Synopsys. If you do not agree with this notice, including the disclaimer
  66026. + * below, then you are not authorized to use the Software.
  66027. + *
  66028. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  66029. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  66030. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  66031. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  66032. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  66033. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  66034. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  66035. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  66036. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  66037. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  66038. + * DAMAGE.
  66039. + * ========================================================================== */
  66040. +
  66041. +#ifndef __DWC_OTG_DBG_H__
  66042. +#define __DWC_OTG_DBG_H__
  66043. +
  66044. +/** @file
  66045. + * This file defines debug levels.
  66046. + * Debugging support vanishes in non-debug builds.
  66047. + */
  66048. +
  66049. +/**
  66050. + * The Debug Level bit-mask variable.
  66051. + */
  66052. +extern uint32_t g_dbg_lvl;
  66053. +/**
  66054. + * Set the Debug Level variable.
  66055. + */
  66056. +static inline uint32_t SET_DEBUG_LEVEL(const uint32_t new)
  66057. +{
  66058. + uint32_t old = g_dbg_lvl;
  66059. + g_dbg_lvl = new;
  66060. + return old;
  66061. +}
  66062. +
  66063. +#define DBG_USER (0x1)
  66064. +/** When debug level has the DBG_CIL bit set, display CIL Debug messages. */
  66065. +#define DBG_CIL (0x2)
  66066. +/** When debug level has the DBG_CILV bit set, display CIL Verbose debug
  66067. + * messages */
  66068. +#define DBG_CILV (0x20)
  66069. +/** When debug level has the DBG_PCD bit set, display PCD (Device) debug
  66070. + * messages */
  66071. +#define DBG_PCD (0x4)
  66072. +/** When debug level has the DBG_PCDV set, display PCD (Device) Verbose debug
  66073. + * messages */
  66074. +#define DBG_PCDV (0x40)
  66075. +/** When debug level has the DBG_HCD bit set, display Host debug messages */
  66076. +#define DBG_HCD (0x8)
  66077. +/** When debug level has the DBG_HCDV bit set, display Verbose Host debug
  66078. + * messages */
  66079. +#define DBG_HCDV (0x80)
  66080. +/** When debug level has the DBG_HCD_URB bit set, display enqueued URBs in host
  66081. + * mode. */
  66082. +#define DBG_HCD_URB (0x800)
  66083. +/** When debug level has the DBG_HCDI bit set, display host interrupt
  66084. + * messages. */
  66085. +#define DBG_HCDI (0x1000)
  66086. +
  66087. +/** When debug level has any bit set, display debug messages */
  66088. +#define DBG_ANY (0xFF)
  66089. +
  66090. +/** All debug messages off */
  66091. +#define DBG_OFF 0
  66092. +
  66093. +/** Prefix string for DWC_DEBUG print macros. */
  66094. +#define USB_DWC "DWC_otg: "
  66095. +
  66096. +/**
  66097. + * Print a debug message when the Global debug level variable contains
  66098. + * the bit defined in <code>lvl</code>.
  66099. + *
  66100. + * @param[in] lvl - Debug level, use one of the DBG_ constants above.
  66101. + * @param[in] x - like printf
  66102. + *
  66103. + * Example:<p>
  66104. + * <code>
  66105. + * DWC_DEBUGPL( DBG_ANY, "%s(%p)\n", __func__, _reg_base_addr);
  66106. + * </code>
  66107. + * <br>
  66108. + * results in:<br>
  66109. + * <code>
  66110. + * usb-DWC_otg: dwc_otg_cil_init(ca867000)
  66111. + * </code>
  66112. + */
  66113. +#ifdef DEBUG
  66114. +
  66115. +# define DWC_DEBUGPL(lvl, x...) do{ if ((lvl)&g_dbg_lvl)__DWC_DEBUG(USB_DWC x ); }while(0)
  66116. +# define DWC_DEBUGP(x...) DWC_DEBUGPL(DBG_ANY, x )
  66117. +
  66118. +# define CHK_DEBUG_LEVEL(level) ((level) & g_dbg_lvl)
  66119. +
  66120. +#else
  66121. +
  66122. +# define DWC_DEBUGPL(lvl, x...) do{}while(0)
  66123. +# define DWC_DEBUGP(x...)
  66124. +
  66125. +# define CHK_DEBUG_LEVEL(level) (0)
  66126. +
  66127. +#endif /*DEBUG*/
  66128. +#endif
  66129. diff -Nur linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_driver.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_driver.c
  66130. --- linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_driver.c 1970-01-01 01:00:00.000000000 +0100
  66131. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_driver.c 2014-04-24 15:37:13.310990489 +0200
  66132. @@ -0,0 +1,1749 @@
  66133. +/* ==========================================================================
  66134. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_driver.c $
  66135. + * $Revision: #92 $
  66136. + * $Date: 2012/08/10 $
  66137. + * $Change: 2047372 $
  66138. + *
  66139. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  66140. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  66141. + * otherwise expressly agreed to in writing between Synopsys and you.
  66142. + *
  66143. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  66144. + * any End User Software License Agreement or Agreement for Licensed Product
  66145. + * with Synopsys or any supplement thereto. You are permitted to use and
  66146. + * redistribute this Software in source and binary forms, with or without
  66147. + * modification, provided that redistributions of source code must retain this
  66148. + * notice. You may not view, use, disclose, copy or distribute this file or
  66149. + * any information contained herein except pursuant to this license grant from
  66150. + * Synopsys. If you do not agree with this notice, including the disclaimer
  66151. + * below, then you are not authorized to use the Software.
  66152. + *
  66153. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  66154. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  66155. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  66156. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  66157. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  66158. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  66159. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  66160. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  66161. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  66162. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  66163. + * DAMAGE.
  66164. + * ========================================================================== */
  66165. +
  66166. +/** @file
  66167. + * The dwc_otg_driver module provides the initialization and cleanup entry
  66168. + * points for the DWC_otg driver. This module will be dynamically installed
  66169. + * after Linux is booted using the insmod command. When the module is
  66170. + * installed, the dwc_otg_driver_init function is called. When the module is
  66171. + * removed (using rmmod), the dwc_otg_driver_cleanup function is called.
  66172. + *
  66173. + * This module also defines a data structure for the dwc_otg_driver, which is
  66174. + * used in conjunction with the standard ARM lm_device structure. These
  66175. + * structures allow the OTG driver to comply with the standard Linux driver
  66176. + * model in which devices and drivers are registered with a bus driver. This
  66177. + * has the benefit that Linux can expose attributes of the driver and device
  66178. + * in its special sysfs file system. Users can then read or write files in
  66179. + * this file system to perform diagnostics on the driver components or the
  66180. + * device.
  66181. + */
  66182. +
  66183. +#include "dwc_otg_os_dep.h"
  66184. +#include "dwc_os.h"
  66185. +#include "dwc_otg_dbg.h"
  66186. +#include "dwc_otg_driver.h"
  66187. +#include "dwc_otg_attr.h"
  66188. +#include "dwc_otg_core_if.h"
  66189. +#include "dwc_otg_pcd_if.h"
  66190. +#include "dwc_otg_hcd_if.h"
  66191. +#include "dwc_otg_fiq_fsm.h"
  66192. +
  66193. +#define DWC_DRIVER_VERSION "3.00a 10-AUG-2012"
  66194. +#define DWC_DRIVER_DESC "HS OTG USB Controller driver"
  66195. +
  66196. +bool microframe_schedule=true;
  66197. +
  66198. +static const char dwc_driver_name[] = "dwc_otg";
  66199. +
  66200. +
  66201. +extern int pcd_init(
  66202. +#ifdef LM_INTERFACE
  66203. + struct lm_device *_dev
  66204. +#elif defined(PCI_INTERFACE)
  66205. + struct pci_dev *_dev
  66206. +#elif defined(PLATFORM_INTERFACE)
  66207. + struct platform_device *dev
  66208. +#endif
  66209. + );
  66210. +extern int hcd_init(
  66211. +#ifdef LM_INTERFACE
  66212. + struct lm_device *_dev
  66213. +#elif defined(PCI_INTERFACE)
  66214. + struct pci_dev *_dev
  66215. +#elif defined(PLATFORM_INTERFACE)
  66216. + struct platform_device *dev
  66217. +#endif
  66218. + );
  66219. +
  66220. +extern int pcd_remove(
  66221. +#ifdef LM_INTERFACE
  66222. + struct lm_device *_dev
  66223. +#elif defined(PCI_INTERFACE)
  66224. + struct pci_dev *_dev
  66225. +#elif defined(PLATFORM_INTERFACE)
  66226. + struct platform_device *_dev
  66227. +#endif
  66228. + );
  66229. +
  66230. +extern void hcd_remove(
  66231. +#ifdef LM_INTERFACE
  66232. + struct lm_device *_dev
  66233. +#elif defined(PCI_INTERFACE)
  66234. + struct pci_dev *_dev
  66235. +#elif defined(PLATFORM_INTERFACE)
  66236. + struct platform_device *_dev
  66237. +#endif
  66238. + );
  66239. +
  66240. +extern void dwc_otg_adp_start(dwc_otg_core_if_t * core_if, uint8_t is_host);
  66241. +
  66242. +/*-------------------------------------------------------------------------*/
  66243. +/* Encapsulate the module parameter settings */
  66244. +
  66245. +struct dwc_otg_driver_module_params {
  66246. + int32_t opt;
  66247. + int32_t otg_cap;
  66248. + int32_t dma_enable;
  66249. + int32_t dma_desc_enable;
  66250. + int32_t dma_burst_size;
  66251. + int32_t speed;
  66252. + int32_t host_support_fs_ls_low_power;
  66253. + int32_t host_ls_low_power_phy_clk;
  66254. + int32_t enable_dynamic_fifo;
  66255. + int32_t data_fifo_size;
  66256. + int32_t dev_rx_fifo_size;
  66257. + int32_t dev_nperio_tx_fifo_size;
  66258. + uint32_t dev_perio_tx_fifo_size[MAX_PERIO_FIFOS];
  66259. + int32_t host_rx_fifo_size;
  66260. + int32_t host_nperio_tx_fifo_size;
  66261. + int32_t host_perio_tx_fifo_size;
  66262. + int32_t max_transfer_size;
  66263. + int32_t max_packet_count;
  66264. + int32_t host_channels;
  66265. + int32_t dev_endpoints;
  66266. + int32_t phy_type;
  66267. + int32_t phy_utmi_width;
  66268. + int32_t phy_ulpi_ddr;
  66269. + int32_t phy_ulpi_ext_vbus;
  66270. + int32_t i2c_enable;
  66271. + int32_t ulpi_fs_ls;
  66272. + int32_t ts_dline;
  66273. + int32_t en_multiple_tx_fifo;
  66274. + uint32_t dev_tx_fifo_size[MAX_TX_FIFOS];
  66275. + uint32_t thr_ctl;
  66276. + uint32_t tx_thr_length;
  66277. + uint32_t rx_thr_length;
  66278. + int32_t pti_enable;
  66279. + int32_t mpi_enable;
  66280. + int32_t lpm_enable;
  66281. + int32_t ic_usb_cap;
  66282. + int32_t ahb_thr_ratio;
  66283. + int32_t power_down;
  66284. + int32_t reload_ctl;
  66285. + int32_t dev_out_nak;
  66286. + int32_t cont_on_bna;
  66287. + int32_t ahb_single;
  66288. + int32_t otg_ver;
  66289. + int32_t adp_enable;
  66290. +};
  66291. +
  66292. +static struct dwc_otg_driver_module_params dwc_otg_module_params = {
  66293. + .opt = -1,
  66294. + .otg_cap = -1,
  66295. + .dma_enable = -1,
  66296. + .dma_desc_enable = -1,
  66297. + .dma_burst_size = -1,
  66298. + .speed = -1,
  66299. + .host_support_fs_ls_low_power = -1,
  66300. + .host_ls_low_power_phy_clk = -1,
  66301. + .enable_dynamic_fifo = -1,
  66302. + .data_fifo_size = -1,
  66303. + .dev_rx_fifo_size = -1,
  66304. + .dev_nperio_tx_fifo_size = -1,
  66305. + .dev_perio_tx_fifo_size = {
  66306. + /* dev_perio_tx_fifo_size_1 */
  66307. + -1,
  66308. + -1,
  66309. + -1,
  66310. + -1,
  66311. + -1,
  66312. + -1,
  66313. + -1,
  66314. + -1,
  66315. + -1,
  66316. + -1,
  66317. + -1,
  66318. + -1,
  66319. + -1,
  66320. + -1,
  66321. + -1
  66322. + /* 15 */
  66323. + },
  66324. + .host_rx_fifo_size = -1,
  66325. + .host_nperio_tx_fifo_size = -1,
  66326. + .host_perio_tx_fifo_size = -1,
  66327. + .max_transfer_size = -1,
  66328. + .max_packet_count = -1,
  66329. + .host_channels = -1,
  66330. + .dev_endpoints = -1,
  66331. + .phy_type = -1,
  66332. + .phy_utmi_width = -1,
  66333. + .phy_ulpi_ddr = -1,
  66334. + .phy_ulpi_ext_vbus = -1,
  66335. + .i2c_enable = -1,
  66336. + .ulpi_fs_ls = -1,
  66337. + .ts_dline = -1,
  66338. + .en_multiple_tx_fifo = -1,
  66339. + .dev_tx_fifo_size = {
  66340. + /* dev_tx_fifo_size */
  66341. + -1,
  66342. + -1,
  66343. + -1,
  66344. + -1,
  66345. + -1,
  66346. + -1,
  66347. + -1,
  66348. + -1,
  66349. + -1,
  66350. + -1,
  66351. + -1,
  66352. + -1,
  66353. + -1,
  66354. + -1,
  66355. + -1
  66356. + /* 15 */
  66357. + },
  66358. + .thr_ctl = -1,
  66359. + .tx_thr_length = -1,
  66360. + .rx_thr_length = -1,
  66361. + .pti_enable = -1,
  66362. + .mpi_enable = -1,
  66363. + .lpm_enable = 0,
  66364. + .ic_usb_cap = -1,
  66365. + .ahb_thr_ratio = -1,
  66366. + .power_down = -1,
  66367. + .reload_ctl = -1,
  66368. + .dev_out_nak = -1,
  66369. + .cont_on_bna = -1,
  66370. + .ahb_single = -1,
  66371. + .otg_ver = -1,
  66372. + .adp_enable = -1,
  66373. +};
  66374. +
  66375. +//Global variable to switch the fiq fix on or off
  66376. +bool fiq_enable = 1;
  66377. +// Global variable to enable the split transaction fix
  66378. +bool fiq_fsm_enable = false;
  66379. +//Bulk split-transaction NAK holdoff in microframes
  66380. +uint16_t nak_holdoff = 8;
  66381. +
  66382. +unsigned short fiq_fsm_mask = 0x01;
  66383. +
  66384. +/**
  66385. + * This function shows the Driver Version.
  66386. + */
  66387. +static ssize_t version_show(struct device_driver *dev, char *buf)
  66388. +{
  66389. + return snprintf(buf, sizeof(DWC_DRIVER_VERSION) + 2, "%s\n",
  66390. + DWC_DRIVER_VERSION);
  66391. +}
  66392. +
  66393. +static DRIVER_ATTR(version, S_IRUGO, version_show, NULL);
  66394. +
  66395. +/**
  66396. + * Global Debug Level Mask.
  66397. + */
  66398. +uint32_t g_dbg_lvl = 0; /* OFF */
  66399. +
  66400. +/**
  66401. + * This function shows the driver Debug Level.
  66402. + */
  66403. +static ssize_t dbg_level_show(struct device_driver *drv, char *buf)
  66404. +{
  66405. + return sprintf(buf, "0x%0x\n", g_dbg_lvl);
  66406. +}
  66407. +
  66408. +/**
  66409. + * This function stores the driver Debug Level.
  66410. + */
  66411. +static ssize_t dbg_level_store(struct device_driver *drv, const char *buf,
  66412. + size_t count)
  66413. +{
  66414. + g_dbg_lvl = simple_strtoul(buf, NULL, 16);
  66415. + return count;
  66416. +}
  66417. +
  66418. +static DRIVER_ATTR(debuglevel, S_IRUGO | S_IWUSR, dbg_level_show,
  66419. + dbg_level_store);
  66420. +
  66421. +/**
  66422. + * This function is called during module intialization
  66423. + * to pass module parameters to the DWC_OTG CORE.
  66424. + */
  66425. +static int set_parameters(dwc_otg_core_if_t * core_if)
  66426. +{
  66427. + int retval = 0;
  66428. + int i;
  66429. +
  66430. + if (dwc_otg_module_params.otg_cap != -1) {
  66431. + retval +=
  66432. + dwc_otg_set_param_otg_cap(core_if,
  66433. + dwc_otg_module_params.otg_cap);
  66434. + }
  66435. + if (dwc_otg_module_params.dma_enable != -1) {
  66436. + retval +=
  66437. + dwc_otg_set_param_dma_enable(core_if,
  66438. + dwc_otg_module_params.
  66439. + dma_enable);
  66440. + }
  66441. + if (dwc_otg_module_params.dma_desc_enable != -1) {
  66442. + retval +=
  66443. + dwc_otg_set_param_dma_desc_enable(core_if,
  66444. + dwc_otg_module_params.
  66445. + dma_desc_enable);
  66446. + }
  66447. + if (dwc_otg_module_params.opt != -1) {
  66448. + retval +=
  66449. + dwc_otg_set_param_opt(core_if, dwc_otg_module_params.opt);
  66450. + }
  66451. + if (dwc_otg_module_params.dma_burst_size != -1) {
  66452. + retval +=
  66453. + dwc_otg_set_param_dma_burst_size(core_if,
  66454. + dwc_otg_module_params.
  66455. + dma_burst_size);
  66456. + }
  66457. + if (dwc_otg_module_params.host_support_fs_ls_low_power != -1) {
  66458. + retval +=
  66459. + dwc_otg_set_param_host_support_fs_ls_low_power(core_if,
  66460. + dwc_otg_module_params.
  66461. + host_support_fs_ls_low_power);
  66462. + }
  66463. + if (dwc_otg_module_params.enable_dynamic_fifo != -1) {
  66464. + retval +=
  66465. + dwc_otg_set_param_enable_dynamic_fifo(core_if,
  66466. + dwc_otg_module_params.
  66467. + enable_dynamic_fifo);
  66468. + }
  66469. + if (dwc_otg_module_params.data_fifo_size != -1) {
  66470. + retval +=
  66471. + dwc_otg_set_param_data_fifo_size(core_if,
  66472. + dwc_otg_module_params.
  66473. + data_fifo_size);
  66474. + }
  66475. + if (dwc_otg_module_params.dev_rx_fifo_size != -1) {
  66476. + retval +=
  66477. + dwc_otg_set_param_dev_rx_fifo_size(core_if,
  66478. + dwc_otg_module_params.
  66479. + dev_rx_fifo_size);
  66480. + }
  66481. + if (dwc_otg_module_params.dev_nperio_tx_fifo_size != -1) {
  66482. + retval +=
  66483. + dwc_otg_set_param_dev_nperio_tx_fifo_size(core_if,
  66484. + dwc_otg_module_params.
  66485. + dev_nperio_tx_fifo_size);
  66486. + }
  66487. + if (dwc_otg_module_params.host_rx_fifo_size != -1) {
  66488. + retval +=
  66489. + dwc_otg_set_param_host_rx_fifo_size(core_if,
  66490. + dwc_otg_module_params.host_rx_fifo_size);
  66491. + }
  66492. + if (dwc_otg_module_params.host_nperio_tx_fifo_size != -1) {
  66493. + retval +=
  66494. + dwc_otg_set_param_host_nperio_tx_fifo_size(core_if,
  66495. + dwc_otg_module_params.
  66496. + host_nperio_tx_fifo_size);
  66497. + }
  66498. + if (dwc_otg_module_params.host_perio_tx_fifo_size != -1) {
  66499. + retval +=
  66500. + dwc_otg_set_param_host_perio_tx_fifo_size(core_if,
  66501. + dwc_otg_module_params.
  66502. + host_perio_tx_fifo_size);
  66503. + }
  66504. + if (dwc_otg_module_params.max_transfer_size != -1) {
  66505. + retval +=
  66506. + dwc_otg_set_param_max_transfer_size(core_if,
  66507. + dwc_otg_module_params.
  66508. + max_transfer_size);
  66509. + }
  66510. + if (dwc_otg_module_params.max_packet_count != -1) {
  66511. + retval +=
  66512. + dwc_otg_set_param_max_packet_count(core_if,
  66513. + dwc_otg_module_params.
  66514. + max_packet_count);
  66515. + }
  66516. + if (dwc_otg_module_params.host_channels != -1) {
  66517. + retval +=
  66518. + dwc_otg_set_param_host_channels(core_if,
  66519. + dwc_otg_module_params.
  66520. + host_channels);
  66521. + }
  66522. + if (dwc_otg_module_params.dev_endpoints != -1) {
  66523. + retval +=
  66524. + dwc_otg_set_param_dev_endpoints(core_if,
  66525. + dwc_otg_module_params.
  66526. + dev_endpoints);
  66527. + }
  66528. + if (dwc_otg_module_params.phy_type != -1) {
  66529. + retval +=
  66530. + dwc_otg_set_param_phy_type(core_if,
  66531. + dwc_otg_module_params.phy_type);
  66532. + }
  66533. + if (dwc_otg_module_params.speed != -1) {
  66534. + retval +=
  66535. + dwc_otg_set_param_speed(core_if,
  66536. + dwc_otg_module_params.speed);
  66537. + }
  66538. + if (dwc_otg_module_params.host_ls_low_power_phy_clk != -1) {
  66539. + retval +=
  66540. + dwc_otg_set_param_host_ls_low_power_phy_clk(core_if,
  66541. + dwc_otg_module_params.
  66542. + host_ls_low_power_phy_clk);
  66543. + }
  66544. + if (dwc_otg_module_params.phy_ulpi_ddr != -1) {
  66545. + retval +=
  66546. + dwc_otg_set_param_phy_ulpi_ddr(core_if,
  66547. + dwc_otg_module_params.
  66548. + phy_ulpi_ddr);
  66549. + }
  66550. + if (dwc_otg_module_params.phy_ulpi_ext_vbus != -1) {
  66551. + retval +=
  66552. + dwc_otg_set_param_phy_ulpi_ext_vbus(core_if,
  66553. + dwc_otg_module_params.
  66554. + phy_ulpi_ext_vbus);
  66555. + }
  66556. + if (dwc_otg_module_params.phy_utmi_width != -1) {
  66557. + retval +=
  66558. + dwc_otg_set_param_phy_utmi_width(core_if,
  66559. + dwc_otg_module_params.
  66560. + phy_utmi_width);
  66561. + }
  66562. + if (dwc_otg_module_params.ulpi_fs_ls != -1) {
  66563. + retval +=
  66564. + dwc_otg_set_param_ulpi_fs_ls(core_if,
  66565. + dwc_otg_module_params.ulpi_fs_ls);
  66566. + }
  66567. + if (dwc_otg_module_params.ts_dline != -1) {
  66568. + retval +=
  66569. + dwc_otg_set_param_ts_dline(core_if,
  66570. + dwc_otg_module_params.ts_dline);
  66571. + }
  66572. + if (dwc_otg_module_params.i2c_enable != -1) {
  66573. + retval +=
  66574. + dwc_otg_set_param_i2c_enable(core_if,
  66575. + dwc_otg_module_params.
  66576. + i2c_enable);
  66577. + }
  66578. + if (dwc_otg_module_params.en_multiple_tx_fifo != -1) {
  66579. + retval +=
  66580. + dwc_otg_set_param_en_multiple_tx_fifo(core_if,
  66581. + dwc_otg_module_params.
  66582. + en_multiple_tx_fifo);
  66583. + }
  66584. + for (i = 0; i < 15; i++) {
  66585. + if (dwc_otg_module_params.dev_perio_tx_fifo_size[i] != -1) {
  66586. + retval +=
  66587. + dwc_otg_set_param_dev_perio_tx_fifo_size(core_if,
  66588. + dwc_otg_module_params.
  66589. + dev_perio_tx_fifo_size
  66590. + [i], i);
  66591. + }
  66592. + }
  66593. +
  66594. + for (i = 0; i < 15; i++) {
  66595. + if (dwc_otg_module_params.dev_tx_fifo_size[i] != -1) {
  66596. + retval += dwc_otg_set_param_dev_tx_fifo_size(core_if,
  66597. + dwc_otg_module_params.
  66598. + dev_tx_fifo_size
  66599. + [i], i);
  66600. + }
  66601. + }
  66602. + if (dwc_otg_module_params.thr_ctl != -1) {
  66603. + retval +=
  66604. + dwc_otg_set_param_thr_ctl(core_if,
  66605. + dwc_otg_module_params.thr_ctl);
  66606. + }
  66607. + if (dwc_otg_module_params.mpi_enable != -1) {
  66608. + retval +=
  66609. + dwc_otg_set_param_mpi_enable(core_if,
  66610. + dwc_otg_module_params.
  66611. + mpi_enable);
  66612. + }
  66613. + if (dwc_otg_module_params.pti_enable != -1) {
  66614. + retval +=
  66615. + dwc_otg_set_param_pti_enable(core_if,
  66616. + dwc_otg_module_params.
  66617. + pti_enable);
  66618. + }
  66619. + if (dwc_otg_module_params.lpm_enable != -1) {
  66620. + retval +=
  66621. + dwc_otg_set_param_lpm_enable(core_if,
  66622. + dwc_otg_module_params.
  66623. + lpm_enable);
  66624. + }
  66625. + if (dwc_otg_module_params.ic_usb_cap != -1) {
  66626. + retval +=
  66627. + dwc_otg_set_param_ic_usb_cap(core_if,
  66628. + dwc_otg_module_params.
  66629. + ic_usb_cap);
  66630. + }
  66631. + if (dwc_otg_module_params.tx_thr_length != -1) {
  66632. + retval +=
  66633. + dwc_otg_set_param_tx_thr_length(core_if,
  66634. + dwc_otg_module_params.tx_thr_length);
  66635. + }
  66636. + if (dwc_otg_module_params.rx_thr_length != -1) {
  66637. + retval +=
  66638. + dwc_otg_set_param_rx_thr_length(core_if,
  66639. + dwc_otg_module_params.
  66640. + rx_thr_length);
  66641. + }
  66642. + if (dwc_otg_module_params.ahb_thr_ratio != -1) {
  66643. + retval +=
  66644. + dwc_otg_set_param_ahb_thr_ratio(core_if,
  66645. + dwc_otg_module_params.ahb_thr_ratio);
  66646. + }
  66647. + if (dwc_otg_module_params.power_down != -1) {
  66648. + retval +=
  66649. + dwc_otg_set_param_power_down(core_if,
  66650. + dwc_otg_module_params.power_down);
  66651. + }
  66652. + if (dwc_otg_module_params.reload_ctl != -1) {
  66653. + retval +=
  66654. + dwc_otg_set_param_reload_ctl(core_if,
  66655. + dwc_otg_module_params.reload_ctl);
  66656. + }
  66657. +
  66658. + if (dwc_otg_module_params.dev_out_nak != -1) {
  66659. + retval +=
  66660. + dwc_otg_set_param_dev_out_nak(core_if,
  66661. + dwc_otg_module_params.dev_out_nak);
  66662. + }
  66663. +
  66664. + if (dwc_otg_module_params.cont_on_bna != -1) {
  66665. + retval +=
  66666. + dwc_otg_set_param_cont_on_bna(core_if,
  66667. + dwc_otg_module_params.cont_on_bna);
  66668. + }
  66669. +
  66670. + if (dwc_otg_module_params.ahb_single != -1) {
  66671. + retval +=
  66672. + dwc_otg_set_param_ahb_single(core_if,
  66673. + dwc_otg_module_params.ahb_single);
  66674. + }
  66675. +
  66676. + if (dwc_otg_module_params.otg_ver != -1) {
  66677. + retval +=
  66678. + dwc_otg_set_param_otg_ver(core_if,
  66679. + dwc_otg_module_params.otg_ver);
  66680. + }
  66681. + if (dwc_otg_module_params.adp_enable != -1) {
  66682. + retval +=
  66683. + dwc_otg_set_param_adp_enable(core_if,
  66684. + dwc_otg_module_params.
  66685. + adp_enable);
  66686. + }
  66687. + return retval;
  66688. +}
  66689. +
  66690. +/**
  66691. + * This function is the top level interrupt handler for the Common
  66692. + * (Device and host modes) interrupts.
  66693. + */
  66694. +static irqreturn_t dwc_otg_common_irq(int irq, void *dev)
  66695. +{
  66696. + int32_t retval = IRQ_NONE;
  66697. +
  66698. + retval = dwc_otg_handle_common_intr(dev);
  66699. + if (retval != 0) {
  66700. + S3C2410X_CLEAR_EINTPEND();
  66701. + }
  66702. + return IRQ_RETVAL(retval);
  66703. +}
  66704. +
  66705. +/**
  66706. + * This function is called when a lm_device is unregistered with the
  66707. + * dwc_otg_driver. This happens, for example, when the rmmod command is
  66708. + * executed. The device may or may not be electrically present. If it is
  66709. + * present, the driver stops device processing. Any resources used on behalf
  66710. + * of this device are freed.
  66711. + *
  66712. + * @param _dev
  66713. + */
  66714. +#ifdef LM_INTERFACE
  66715. +#define REM_RETVAL(n)
  66716. +static void dwc_otg_driver_remove( struct lm_device *_dev )
  66717. +{ dwc_otg_device_t *otg_dev = lm_get_drvdata(_dev);
  66718. +#elif defined(PCI_INTERFACE)
  66719. +#define REM_RETVAL(n)
  66720. +static void dwc_otg_driver_remove( struct pci_dev *_dev )
  66721. +{ dwc_otg_device_t *otg_dev = pci_get_drvdata(_dev);
  66722. +#elif defined(PLATFORM_INTERFACE)
  66723. +#define REM_RETVAL(n) n
  66724. +static int dwc_otg_driver_remove( struct platform_device *_dev )
  66725. +{ dwc_otg_device_t *otg_dev = platform_get_drvdata(_dev);
  66726. +#endif
  66727. +
  66728. + DWC_DEBUGPL(DBG_ANY, "%s(%p) otg_dev %p\n", __func__, _dev, otg_dev);
  66729. +
  66730. + if (!otg_dev) {
  66731. + /* Memory allocation for the dwc_otg_device failed. */
  66732. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev NULL!\n", __func__);
  66733. + return REM_RETVAL(-ENOMEM);
  66734. + }
  66735. +#ifndef DWC_DEVICE_ONLY
  66736. + if (otg_dev->hcd) {
  66737. + hcd_remove(_dev);
  66738. + } else {
  66739. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->hcd NULL!\n", __func__);
  66740. + return REM_RETVAL(-EINVAL);
  66741. + }
  66742. +#endif
  66743. +
  66744. +#ifndef DWC_HOST_ONLY
  66745. + if (otg_dev->pcd) {
  66746. + pcd_remove(_dev);
  66747. + } else {
  66748. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->pcd NULL!\n", __func__);
  66749. + return REM_RETVAL(-EINVAL);
  66750. + }
  66751. +#endif
  66752. + /*
  66753. + * Free the IRQ
  66754. + */
  66755. + if (otg_dev->common_irq_installed) {
  66756. +#ifdef PLATFORM_INTERFACE
  66757. + free_irq(platform_get_irq(_dev, 0), otg_dev);
  66758. +#else
  66759. + free_irq(_dev->irq, otg_dev);
  66760. +#endif
  66761. + } else {
  66762. + DWC_DEBUGPL(DBG_ANY, "%s: There is no installed irq!\n", __func__);
  66763. + return REM_RETVAL(-ENXIO);
  66764. + }
  66765. +
  66766. + if (otg_dev->core_if) {
  66767. + dwc_otg_cil_remove(otg_dev->core_if);
  66768. + } else {
  66769. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->core_if NULL!\n", __func__);
  66770. + return REM_RETVAL(-ENXIO);
  66771. + }
  66772. +
  66773. + /*
  66774. + * Remove the device attributes
  66775. + */
  66776. + dwc_otg_attr_remove(_dev);
  66777. +
  66778. + /*
  66779. + * Return the memory.
  66780. + */
  66781. + if (otg_dev->os_dep.base) {
  66782. + iounmap(otg_dev->os_dep.base);
  66783. + }
  66784. + DWC_FREE(otg_dev);
  66785. +
  66786. + /*
  66787. + * Clear the drvdata pointer.
  66788. + */
  66789. +#ifdef LM_INTERFACE
  66790. + lm_set_drvdata(_dev, 0);
  66791. +#elif defined(PCI_INTERFACE)
  66792. + release_mem_region(otg_dev->os_dep.rsrc_start,
  66793. + otg_dev->os_dep.rsrc_len);
  66794. + pci_set_drvdata(_dev, 0);
  66795. +#elif defined(PLATFORM_INTERFACE)
  66796. + platform_set_drvdata(_dev, 0);
  66797. +#endif
  66798. + return REM_RETVAL(0);
  66799. +}
  66800. +
  66801. +/**
  66802. + * This function is called when an lm_device is bound to a
  66803. + * dwc_otg_driver. It creates the driver components required to
  66804. + * control the device (CIL, HCD, and PCD) and it initializes the
  66805. + * device. The driver components are stored in a dwc_otg_device
  66806. + * structure. A reference to the dwc_otg_device is saved in the
  66807. + * lm_device. This allows the driver to access the dwc_otg_device
  66808. + * structure on subsequent calls to driver methods for this device.
  66809. + *
  66810. + * @param _dev Bus device
  66811. + */
  66812. +static int dwc_otg_driver_probe(
  66813. +#ifdef LM_INTERFACE
  66814. + struct lm_device *_dev
  66815. +#elif defined(PCI_INTERFACE)
  66816. + struct pci_dev *_dev,
  66817. + const struct pci_device_id *id
  66818. +#elif defined(PLATFORM_INTERFACE)
  66819. + struct platform_device *_dev
  66820. +#endif
  66821. + )
  66822. +{
  66823. + int retval = 0;
  66824. + dwc_otg_device_t *dwc_otg_device;
  66825. + int devirq;
  66826. +
  66827. + dev_dbg(&_dev->dev, "dwc_otg_driver_probe(%p)\n", _dev);
  66828. +#ifdef LM_INTERFACE
  66829. + dev_dbg(&_dev->dev, "start=0x%08x\n", (unsigned)_dev->resource.start);
  66830. +#elif defined(PCI_INTERFACE)
  66831. + if (!id) {
  66832. + DWC_ERROR("Invalid pci_device_id %p", id);
  66833. + return -EINVAL;
  66834. + }
  66835. +
  66836. + if (!_dev || (pci_enable_device(_dev) < 0)) {
  66837. + DWC_ERROR("Invalid pci_device %p", _dev);
  66838. + return -ENODEV;
  66839. + }
  66840. + dev_dbg(&_dev->dev, "start=0x%08x\n", (unsigned)pci_resource_start(_dev,0));
  66841. + /* other stuff needed as well? */
  66842. +
  66843. +#elif defined(PLATFORM_INTERFACE)
  66844. + dev_dbg(&_dev->dev, "start=0x%08x (len 0x%x)\n",
  66845. + (unsigned)_dev->resource->start,
  66846. + (unsigned)(_dev->resource->end - _dev->resource->start));
  66847. +#endif
  66848. +
  66849. + dwc_otg_device = DWC_ALLOC(sizeof(dwc_otg_device_t));
  66850. +
  66851. + if (!dwc_otg_device) {
  66852. + dev_err(&_dev->dev, "kmalloc of dwc_otg_device failed\n");
  66853. + return -ENOMEM;
  66854. + }
  66855. +
  66856. + memset(dwc_otg_device, 0, sizeof(*dwc_otg_device));
  66857. + dwc_otg_device->os_dep.reg_offset = 0xFFFFFFFF;
  66858. +
  66859. + /*
  66860. + * Map the DWC_otg Core memory into virtual address space.
  66861. + */
  66862. +#ifdef LM_INTERFACE
  66863. + dwc_otg_device->os_dep.base = ioremap(_dev->resource.start, SZ_256K);
  66864. +
  66865. + if (!dwc_otg_device->os_dep.base) {
  66866. + dev_err(&_dev->dev, "ioremap() failed\n");
  66867. + DWC_FREE(dwc_otg_device);
  66868. + return -ENOMEM;
  66869. + }
  66870. + dev_dbg(&_dev->dev, "base=0x%08x\n",
  66871. + (unsigned)dwc_otg_device->os_dep.base);
  66872. +#elif defined(PCI_INTERFACE)
  66873. + _dev->current_state = PCI_D0;
  66874. + _dev->dev.power.power_state = PMSG_ON;
  66875. +
  66876. + if (!_dev->irq) {
  66877. + DWC_ERROR("Found HC with no IRQ. Check BIOS/PCI %s setup!",
  66878. + pci_name(_dev));
  66879. + iounmap(dwc_otg_device->os_dep.base);
  66880. + DWC_FREE(dwc_otg_device);
  66881. + return -ENODEV;
  66882. + }
  66883. +
  66884. + dwc_otg_device->os_dep.rsrc_start = pci_resource_start(_dev, 0);
  66885. + dwc_otg_device->os_dep.rsrc_len = pci_resource_len(_dev, 0);
  66886. + DWC_DEBUGPL(DBG_ANY, "PCI resource: start=%08x, len=%08x\n",
  66887. + (unsigned)dwc_otg_device->os_dep.rsrc_start,
  66888. + (unsigned)dwc_otg_device->os_dep.rsrc_len);
  66889. + if (!request_mem_region
  66890. + (dwc_otg_device->os_dep.rsrc_start, dwc_otg_device->os_dep.rsrc_len,
  66891. + "dwc_otg")) {
  66892. + dev_dbg(&_dev->dev, "error requesting memory\n");
  66893. + iounmap(dwc_otg_device->os_dep.base);
  66894. + DWC_FREE(dwc_otg_device);
  66895. + return -EFAULT;
  66896. + }
  66897. +
  66898. + dwc_otg_device->os_dep.base =
  66899. + ioremap_nocache(dwc_otg_device->os_dep.rsrc_start,
  66900. + dwc_otg_device->os_dep.rsrc_len);
  66901. + if (dwc_otg_device->os_dep.base == NULL) {
  66902. + dev_dbg(&_dev->dev, "error mapping memory\n");
  66903. + release_mem_region(dwc_otg_device->os_dep.rsrc_start,
  66904. + dwc_otg_device->os_dep.rsrc_len);
  66905. + iounmap(dwc_otg_device->os_dep.base);
  66906. + DWC_FREE(dwc_otg_device);
  66907. + return -EFAULT;
  66908. + }
  66909. + dev_dbg(&_dev->dev, "base=0x%p (before adjust) \n",
  66910. + dwc_otg_device->os_dep.base);
  66911. + dwc_otg_device->os_dep.base = (char *)dwc_otg_device->os_dep.base;
  66912. + dev_dbg(&_dev->dev, "base=0x%p (after adjust) \n",
  66913. + dwc_otg_device->os_dep.base);
  66914. + dev_dbg(&_dev->dev, "%s: mapped PA 0x%x to VA 0x%p\n", __func__,
  66915. + (unsigned)dwc_otg_device->os_dep.rsrc_start,
  66916. + dwc_otg_device->os_dep.base);
  66917. +
  66918. + pci_set_master(_dev);
  66919. + pci_set_drvdata(_dev, dwc_otg_device);
  66920. +#elif defined(PLATFORM_INTERFACE)
  66921. + DWC_DEBUGPL(DBG_ANY,"Platform resource: start=%08x, len=%08x\n",
  66922. + _dev->resource->start,
  66923. + _dev->resource->end - _dev->resource->start + 1);
  66924. +#if 1
  66925. + if (!request_mem_region(_dev->resource[0].start,
  66926. + _dev->resource[0].end - _dev->resource[0].start + 1,
  66927. + "dwc_otg")) {
  66928. + dev_dbg(&_dev->dev, "error reserving mapped memory\n");
  66929. + retval = -EFAULT;
  66930. + goto fail;
  66931. + }
  66932. +
  66933. + dwc_otg_device->os_dep.base = ioremap_nocache(_dev->resource[0].start,
  66934. + _dev->resource[0].end -
  66935. + _dev->resource[0].start+1);
  66936. + if (fiq_enable)
  66937. + {
  66938. + if (!request_mem_region(_dev->resource[1].start,
  66939. + _dev->resource[1].end - _dev->resource[1].start + 1,
  66940. + "dwc_otg")) {
  66941. + dev_dbg(&_dev->dev, "error reserving mapped memory\n");
  66942. + retval = -EFAULT;
  66943. + goto fail;
  66944. + }
  66945. +
  66946. + dwc_otg_device->os_dep.mphi_base = ioremap_nocache(_dev->resource[1].start,
  66947. + _dev->resource[1].end -
  66948. + _dev->resource[1].start + 1);
  66949. + }
  66950. +
  66951. +#else
  66952. + {
  66953. + struct map_desc desc = {
  66954. + .virtual = IO_ADDRESS((unsigned)_dev->resource->start),
  66955. + .pfn = __phys_to_pfn((unsigned)_dev->resource->start),
  66956. + .length = SZ_128K,
  66957. + .type = MT_DEVICE
  66958. + };
  66959. + iotable_init(&desc, 1);
  66960. + dwc_otg_device->os_dep.base = (void *)desc.virtual;
  66961. + }
  66962. +#endif
  66963. + if (!dwc_otg_device->os_dep.base) {
  66964. + dev_err(&_dev->dev, "ioremap() failed\n");
  66965. + retval = -ENOMEM;
  66966. + goto fail;
  66967. + }
  66968. + dev_dbg(&_dev->dev, "base=0x%08x\n",
  66969. + (unsigned)dwc_otg_device->os_dep.base);
  66970. +#endif
  66971. +
  66972. + /*
  66973. + * Initialize driver data to point to the global DWC_otg
  66974. + * Device structure.
  66975. + */
  66976. +#ifdef LM_INTERFACE
  66977. + lm_set_drvdata(_dev, dwc_otg_device);
  66978. +#elif defined(PLATFORM_INTERFACE)
  66979. + platform_set_drvdata(_dev, dwc_otg_device);
  66980. +#endif
  66981. + dev_dbg(&_dev->dev, "dwc_otg_device=0x%p\n", dwc_otg_device);
  66982. +
  66983. + dwc_otg_device->core_if = dwc_otg_cil_init(dwc_otg_device->os_dep.base);
  66984. + DWC_DEBUGPL(DBG_HCDV, "probe of device %p given core_if %p\n",
  66985. + dwc_otg_device, dwc_otg_device->core_if);//GRAYG
  66986. +
  66987. + if (!dwc_otg_device->core_if) {
  66988. + dev_err(&_dev->dev, "CIL initialization failed!\n");
  66989. + retval = -ENOMEM;
  66990. + goto fail;
  66991. + }
  66992. +
  66993. + dev_dbg(&_dev->dev, "Calling get_gsnpsid\n");
  66994. + /*
  66995. + * Attempt to ensure this device is really a DWC_otg Controller.
  66996. + * Read and verify the SNPSID register contents. The value should be
  66997. + * 0x45F42XXX or 0x45F42XXX, which corresponds to either "OT2" or "OTG3",
  66998. + * as in "OTG version 2.XX" or "OTG version 3.XX".
  66999. + */
  67000. +
  67001. + if (((dwc_otg_get_gsnpsid(dwc_otg_device->core_if) & 0xFFFFF000) != 0x4F542000) &&
  67002. + ((dwc_otg_get_gsnpsid(dwc_otg_device->core_if) & 0xFFFFF000) != 0x4F543000)) {
  67003. + dev_err(&_dev->dev, "Bad value for SNPSID: 0x%08x\n",
  67004. + dwc_otg_get_gsnpsid(dwc_otg_device->core_if));
  67005. + retval = -EINVAL;
  67006. + goto fail;
  67007. + }
  67008. +
  67009. + /*
  67010. + * Validate parameter values.
  67011. + */
  67012. + dev_dbg(&_dev->dev, "Calling set_parameters\n");
  67013. + if (set_parameters(dwc_otg_device->core_if)) {
  67014. + retval = -EINVAL;
  67015. + goto fail;
  67016. + }
  67017. +
  67018. + /*
  67019. + * Create Device Attributes in sysfs
  67020. + */
  67021. + dev_dbg(&_dev->dev, "Calling attr_create\n");
  67022. + dwc_otg_attr_create(_dev);
  67023. +
  67024. + /*
  67025. + * Disable the global interrupt until all the interrupt
  67026. + * handlers are installed.
  67027. + */
  67028. + dev_dbg(&_dev->dev, "Calling disable_global_interrupts\n");
  67029. + dwc_otg_disable_global_interrupts(dwc_otg_device->core_if);
  67030. +
  67031. + /*
  67032. + * Install the interrupt handler for the common interrupts before
  67033. + * enabling common interrupts in core_init below.
  67034. + */
  67035. +
  67036. +#if defined(PLATFORM_INTERFACE)
  67037. + devirq = platform_get_irq(_dev, 0);
  67038. +#else
  67039. + devirq = _dev->irq;
  67040. +#endif
  67041. + DWC_DEBUGPL(DBG_CIL, "registering (common) handler for irq%d\n",
  67042. + devirq);
  67043. + dev_dbg(&_dev->dev, "Calling request_irq(%d)\n", devirq);
  67044. + retval = request_irq(devirq, dwc_otg_common_irq,
  67045. + IRQF_SHARED,
  67046. + "dwc_otg", dwc_otg_device);
  67047. + if (retval) {
  67048. + DWC_ERROR("request of irq%d failed\n", devirq);
  67049. + retval = -EBUSY;
  67050. + goto fail;
  67051. + } else {
  67052. + dwc_otg_device->common_irq_installed = 1;
  67053. + }
  67054. +
  67055. +#ifndef IRQF_TRIGGER_LOW
  67056. +#if defined(LM_INTERFACE) || defined(PLATFORM_INTERFACE)
  67057. + dev_dbg(&_dev->dev, "Calling set_irq_type\n");
  67058. + set_irq_type(devirq,
  67059. +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30))
  67060. + IRQT_LOW
  67061. +#else
  67062. + IRQ_TYPE_LEVEL_LOW
  67063. +#endif
  67064. + );
  67065. +#endif
  67066. +#endif /*IRQF_TRIGGER_LOW*/
  67067. +
  67068. + /*
  67069. + * Initialize the DWC_otg core.
  67070. + */
  67071. + dev_dbg(&_dev->dev, "Calling dwc_otg_core_init\n");
  67072. + dwc_otg_core_init(dwc_otg_device->core_if);
  67073. +
  67074. +#ifndef DWC_HOST_ONLY
  67075. + /*
  67076. + * Initialize the PCD
  67077. + */
  67078. + dev_dbg(&_dev->dev, "Calling pcd_init\n");
  67079. + retval = pcd_init(_dev);
  67080. + if (retval != 0) {
  67081. + DWC_ERROR("pcd_init failed\n");
  67082. + dwc_otg_device->pcd = NULL;
  67083. + goto fail;
  67084. + }
  67085. +#endif
  67086. +#ifndef DWC_DEVICE_ONLY
  67087. + /*
  67088. + * Initialize the HCD
  67089. + */
  67090. + dev_dbg(&_dev->dev, "Calling hcd_init\n");
  67091. + retval = hcd_init(_dev);
  67092. + if (retval != 0) {
  67093. + DWC_ERROR("hcd_init failed\n");
  67094. + dwc_otg_device->hcd = NULL;
  67095. + goto fail;
  67096. + }
  67097. +#endif
  67098. + /* Recover from drvdata having been overwritten by hcd_init() */
  67099. +#ifdef LM_INTERFACE
  67100. + lm_set_drvdata(_dev, dwc_otg_device);
  67101. +#elif defined(PLATFORM_INTERFACE)
  67102. + platform_set_drvdata(_dev, dwc_otg_device);
  67103. +#elif defined(PCI_INTERFACE)
  67104. + pci_set_drvdata(_dev, dwc_otg_device);
  67105. + dwc_otg_device->os_dep.pcidev = _dev;
  67106. +#endif
  67107. +
  67108. + /*
  67109. + * Enable the global interrupt after all the interrupt
  67110. + * handlers are installed if there is no ADP support else
  67111. + * perform initial actions required for Internal ADP logic.
  67112. + */
  67113. + if (!dwc_otg_get_param_adp_enable(dwc_otg_device->core_if)) {
  67114. + dev_dbg(&_dev->dev, "Calling enable_global_interrupts\n");
  67115. + dwc_otg_enable_global_interrupts(dwc_otg_device->core_if);
  67116. + dev_dbg(&_dev->dev, "Done\n");
  67117. + } else
  67118. + dwc_otg_adp_start(dwc_otg_device->core_if,
  67119. + dwc_otg_is_host_mode(dwc_otg_device->core_if));
  67120. +
  67121. + return 0;
  67122. +
  67123. +fail:
  67124. + dwc_otg_driver_remove(_dev);
  67125. + return retval;
  67126. +}
  67127. +
  67128. +/**
  67129. + * This structure defines the methods to be called by a bus driver
  67130. + * during the lifecycle of a device on that bus. Both drivers and
  67131. + * devices are registered with a bus driver. The bus driver matches
  67132. + * devices to drivers based on information in the device and driver
  67133. + * structures.
  67134. + *
  67135. + * The probe function is called when the bus driver matches a device
  67136. + * to this driver. The remove function is called when a device is
  67137. + * unregistered with the bus driver.
  67138. + */
  67139. +#ifdef LM_INTERFACE
  67140. +static struct lm_driver dwc_otg_driver = {
  67141. + .drv = {.name = (char *)dwc_driver_name,},
  67142. + .probe = dwc_otg_driver_probe,
  67143. + .remove = dwc_otg_driver_remove,
  67144. + // 'suspend' and 'resume' absent
  67145. +};
  67146. +#elif defined(PCI_INTERFACE)
  67147. +static const struct pci_device_id pci_ids[] = { {
  67148. + PCI_DEVICE(0x16c3, 0xabcd),
  67149. + .driver_data =
  67150. + (unsigned long)0xdeadbeef,
  67151. + }, { /* end: all zeroes */ }
  67152. +};
  67153. +
  67154. +MODULE_DEVICE_TABLE(pci, pci_ids);
  67155. +
  67156. +/* pci driver glue; this is a "new style" PCI driver module */
  67157. +static struct pci_driver dwc_otg_driver = {
  67158. + .name = "dwc_otg",
  67159. + .id_table = pci_ids,
  67160. +
  67161. + .probe = dwc_otg_driver_probe,
  67162. + .remove = dwc_otg_driver_remove,
  67163. +
  67164. + .driver = {
  67165. + .name = (char *)dwc_driver_name,
  67166. + },
  67167. +};
  67168. +#elif defined(PLATFORM_INTERFACE)
  67169. +static struct platform_device_id platform_ids[] = {
  67170. + {
  67171. + .name = "bcm2708_usb",
  67172. + .driver_data = (kernel_ulong_t) 0xdeadbeef,
  67173. + },
  67174. + { /* end: all zeroes */ }
  67175. +};
  67176. +MODULE_DEVICE_TABLE(platform, platform_ids);
  67177. +
  67178. +static struct platform_driver dwc_otg_driver = {
  67179. + .driver = {
  67180. + .name = (char *)dwc_driver_name,
  67181. + },
  67182. + .id_table = platform_ids,
  67183. +
  67184. + .probe = dwc_otg_driver_probe,
  67185. + .remove = dwc_otg_driver_remove,
  67186. + // no 'shutdown', 'suspend', 'resume', 'suspend_late' or 'resume_early'
  67187. +};
  67188. +#endif
  67189. +
  67190. +/**
  67191. + * This function is called when the dwc_otg_driver is installed with the
  67192. + * insmod command. It registers the dwc_otg_driver structure with the
  67193. + * appropriate bus driver. This will cause the dwc_otg_driver_probe function
  67194. + * to be called. In addition, the bus driver will automatically expose
  67195. + * attributes defined for the device and driver in the special sysfs file
  67196. + * system.
  67197. + *
  67198. + * @return
  67199. + */
  67200. +static int __init dwc_otg_driver_init(void)
  67201. +{
  67202. + int retval = 0;
  67203. + int error;
  67204. + struct device_driver *drv;
  67205. +
  67206. + if(fiq_fsm_enable && !fiq_enable) {
  67207. + printk(KERN_WARNING "dwc_otg: fiq_fsm_enable was set without fiq_enable! Correcting.\n");
  67208. + fiq_enable = 1;
  67209. + }
  67210. +
  67211. + printk(KERN_INFO "%s: version %s (%s bus)\n", dwc_driver_name,
  67212. + DWC_DRIVER_VERSION,
  67213. +#ifdef LM_INTERFACE
  67214. + "logicmodule");
  67215. + retval = lm_driver_register(&dwc_otg_driver);
  67216. + drv = &dwc_otg_driver.drv;
  67217. +#elif defined(PCI_INTERFACE)
  67218. + "pci");
  67219. + retval = pci_register_driver(&dwc_otg_driver);
  67220. + drv = &dwc_otg_driver.driver;
  67221. +#elif defined(PLATFORM_INTERFACE)
  67222. + "platform");
  67223. + retval = platform_driver_register(&dwc_otg_driver);
  67224. + drv = &dwc_otg_driver.driver;
  67225. +#endif
  67226. + if (retval < 0) {
  67227. + printk(KERN_ERR "%s retval=%d\n", __func__, retval);
  67228. + return retval;
  67229. + }
  67230. + printk(KERN_DEBUG "dwc_otg: FIQ %s\n", fiq_enable ? "enabled":"disabled");
  67231. + printk(KERN_DEBUG "dwc_otg: NAK holdoff %s\n", nak_holdoff ? "enabled":"disabled");
  67232. + printk(KERN_DEBUG "dwc_otg: FIQ split-transaction FSM %s\n", fiq_fsm_enable ? "enabled":"disabled");
  67233. +
  67234. + error = driver_create_file(drv, &driver_attr_version);
  67235. +#ifdef DEBUG
  67236. + error = driver_create_file(drv, &driver_attr_debuglevel);
  67237. +#endif
  67238. + return retval;
  67239. +}
  67240. +
  67241. +module_init(dwc_otg_driver_init);
  67242. +
  67243. +/**
  67244. + * This function is called when the driver is removed from the kernel
  67245. + * with the rmmod command. The driver unregisters itself with its bus
  67246. + * driver.
  67247. + *
  67248. + */
  67249. +static void __exit dwc_otg_driver_cleanup(void)
  67250. +{
  67251. + printk(KERN_DEBUG "dwc_otg_driver_cleanup()\n");
  67252. +
  67253. +#ifdef LM_INTERFACE
  67254. + driver_remove_file(&dwc_otg_driver.drv, &driver_attr_debuglevel);
  67255. + driver_remove_file(&dwc_otg_driver.drv, &driver_attr_version);
  67256. + lm_driver_unregister(&dwc_otg_driver);
  67257. +#elif defined(PCI_INTERFACE)
  67258. + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_debuglevel);
  67259. + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_version);
  67260. + pci_unregister_driver(&dwc_otg_driver);
  67261. +#elif defined(PLATFORM_INTERFACE)
  67262. + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_debuglevel);
  67263. + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_version);
  67264. + platform_driver_unregister(&dwc_otg_driver);
  67265. +#endif
  67266. +
  67267. + printk(KERN_INFO "%s module removed\n", dwc_driver_name);
  67268. +}
  67269. +
  67270. +module_exit(dwc_otg_driver_cleanup);
  67271. +
  67272. +MODULE_DESCRIPTION(DWC_DRIVER_DESC);
  67273. +MODULE_AUTHOR("Synopsys Inc.");
  67274. +MODULE_LICENSE("GPL");
  67275. +
  67276. +module_param_named(otg_cap, dwc_otg_module_params.otg_cap, int, 0444);
  67277. +MODULE_PARM_DESC(otg_cap, "OTG Capabilities 0=HNP&SRP 1=SRP Only 2=None");
  67278. +module_param_named(opt, dwc_otg_module_params.opt, int, 0444);
  67279. +MODULE_PARM_DESC(opt, "OPT Mode");
  67280. +module_param_named(dma_enable, dwc_otg_module_params.dma_enable, int, 0444);
  67281. +MODULE_PARM_DESC(dma_enable, "DMA Mode 0=Slave 1=DMA enabled");
  67282. +
  67283. +module_param_named(dma_desc_enable, dwc_otg_module_params.dma_desc_enable, int,
  67284. + 0444);
  67285. +MODULE_PARM_DESC(dma_desc_enable,
  67286. + "DMA Desc Mode 0=Address DMA 1=DMA Descriptor enabled");
  67287. +
  67288. +module_param_named(dma_burst_size, dwc_otg_module_params.dma_burst_size, int,
  67289. + 0444);
  67290. +MODULE_PARM_DESC(dma_burst_size,
  67291. + "DMA Burst Size 1, 4, 8, 16, 32, 64, 128, 256");
  67292. +module_param_named(speed, dwc_otg_module_params.speed, int, 0444);
  67293. +MODULE_PARM_DESC(speed, "Speed 0=High Speed 1=Full Speed");
  67294. +module_param_named(host_support_fs_ls_low_power,
  67295. + dwc_otg_module_params.host_support_fs_ls_low_power, int,
  67296. + 0444);
  67297. +MODULE_PARM_DESC(host_support_fs_ls_low_power,
  67298. + "Support Low Power w/FS or LS 0=Support 1=Don't Support");
  67299. +module_param_named(host_ls_low_power_phy_clk,
  67300. + dwc_otg_module_params.host_ls_low_power_phy_clk, int, 0444);
  67301. +MODULE_PARM_DESC(host_ls_low_power_phy_clk,
  67302. + "Low Speed Low Power Clock 0=48Mhz 1=6Mhz");
  67303. +module_param_named(enable_dynamic_fifo,
  67304. + dwc_otg_module_params.enable_dynamic_fifo, int, 0444);
  67305. +MODULE_PARM_DESC(enable_dynamic_fifo, "0=cC Setting 1=Allow Dynamic Sizing");
  67306. +module_param_named(data_fifo_size, dwc_otg_module_params.data_fifo_size, int,
  67307. + 0444);
  67308. +MODULE_PARM_DESC(data_fifo_size,
  67309. + "Total number of words in the data FIFO memory 32-32768");
  67310. +module_param_named(dev_rx_fifo_size, dwc_otg_module_params.dev_rx_fifo_size,
  67311. + int, 0444);
  67312. +MODULE_PARM_DESC(dev_rx_fifo_size, "Number of words in the Rx FIFO 16-32768");
  67313. +module_param_named(dev_nperio_tx_fifo_size,
  67314. + dwc_otg_module_params.dev_nperio_tx_fifo_size, int, 0444);
  67315. +MODULE_PARM_DESC(dev_nperio_tx_fifo_size,
  67316. + "Number of words in the non-periodic Tx FIFO 16-32768");
  67317. +module_param_named(dev_perio_tx_fifo_size_1,
  67318. + dwc_otg_module_params.dev_perio_tx_fifo_size[0], int, 0444);
  67319. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_1,
  67320. + "Number of words in the periodic Tx FIFO 4-768");
  67321. +module_param_named(dev_perio_tx_fifo_size_2,
  67322. + dwc_otg_module_params.dev_perio_tx_fifo_size[1], int, 0444);
  67323. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_2,
  67324. + "Number of words in the periodic Tx FIFO 4-768");
  67325. +module_param_named(dev_perio_tx_fifo_size_3,
  67326. + dwc_otg_module_params.dev_perio_tx_fifo_size[2], int, 0444);
  67327. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_3,
  67328. + "Number of words in the periodic Tx FIFO 4-768");
  67329. +module_param_named(dev_perio_tx_fifo_size_4,
  67330. + dwc_otg_module_params.dev_perio_tx_fifo_size[3], int, 0444);
  67331. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_4,
  67332. + "Number of words in the periodic Tx FIFO 4-768");
  67333. +module_param_named(dev_perio_tx_fifo_size_5,
  67334. + dwc_otg_module_params.dev_perio_tx_fifo_size[4], int, 0444);
  67335. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_5,
  67336. + "Number of words in the periodic Tx FIFO 4-768");
  67337. +module_param_named(dev_perio_tx_fifo_size_6,
  67338. + dwc_otg_module_params.dev_perio_tx_fifo_size[5], int, 0444);
  67339. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_6,
  67340. + "Number of words in the periodic Tx FIFO 4-768");
  67341. +module_param_named(dev_perio_tx_fifo_size_7,
  67342. + dwc_otg_module_params.dev_perio_tx_fifo_size[6], int, 0444);
  67343. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_7,
  67344. + "Number of words in the periodic Tx FIFO 4-768");
  67345. +module_param_named(dev_perio_tx_fifo_size_8,
  67346. + dwc_otg_module_params.dev_perio_tx_fifo_size[7], int, 0444);
  67347. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_8,
  67348. + "Number of words in the periodic Tx FIFO 4-768");
  67349. +module_param_named(dev_perio_tx_fifo_size_9,
  67350. + dwc_otg_module_params.dev_perio_tx_fifo_size[8], int, 0444);
  67351. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_9,
  67352. + "Number of words in the periodic Tx FIFO 4-768");
  67353. +module_param_named(dev_perio_tx_fifo_size_10,
  67354. + dwc_otg_module_params.dev_perio_tx_fifo_size[9], int, 0444);
  67355. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_10,
  67356. + "Number of words in the periodic Tx FIFO 4-768");
  67357. +module_param_named(dev_perio_tx_fifo_size_11,
  67358. + dwc_otg_module_params.dev_perio_tx_fifo_size[10], int, 0444);
  67359. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_11,
  67360. + "Number of words in the periodic Tx FIFO 4-768");
  67361. +module_param_named(dev_perio_tx_fifo_size_12,
  67362. + dwc_otg_module_params.dev_perio_tx_fifo_size[11], int, 0444);
  67363. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_12,
  67364. + "Number of words in the periodic Tx FIFO 4-768");
  67365. +module_param_named(dev_perio_tx_fifo_size_13,
  67366. + dwc_otg_module_params.dev_perio_tx_fifo_size[12], int, 0444);
  67367. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_13,
  67368. + "Number of words in the periodic Tx FIFO 4-768");
  67369. +module_param_named(dev_perio_tx_fifo_size_14,
  67370. + dwc_otg_module_params.dev_perio_tx_fifo_size[13], int, 0444);
  67371. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_14,
  67372. + "Number of words in the periodic Tx FIFO 4-768");
  67373. +module_param_named(dev_perio_tx_fifo_size_15,
  67374. + dwc_otg_module_params.dev_perio_tx_fifo_size[14], int, 0444);
  67375. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_15,
  67376. + "Number of words in the periodic Tx FIFO 4-768");
  67377. +module_param_named(host_rx_fifo_size, dwc_otg_module_params.host_rx_fifo_size,
  67378. + int, 0444);
  67379. +MODULE_PARM_DESC(host_rx_fifo_size, "Number of words in the Rx FIFO 16-32768");
  67380. +module_param_named(host_nperio_tx_fifo_size,
  67381. + dwc_otg_module_params.host_nperio_tx_fifo_size, int, 0444);
  67382. +MODULE_PARM_DESC(host_nperio_tx_fifo_size,
  67383. + "Number of words in the non-periodic Tx FIFO 16-32768");
  67384. +module_param_named(host_perio_tx_fifo_size,
  67385. + dwc_otg_module_params.host_perio_tx_fifo_size, int, 0444);
  67386. +MODULE_PARM_DESC(host_perio_tx_fifo_size,
  67387. + "Number of words in the host periodic Tx FIFO 16-32768");
  67388. +module_param_named(max_transfer_size, dwc_otg_module_params.max_transfer_size,
  67389. + int, 0444);
  67390. +/** @todo Set the max to 512K, modify checks */
  67391. +MODULE_PARM_DESC(max_transfer_size,
  67392. + "The maximum transfer size supported in bytes 2047-65535");
  67393. +module_param_named(max_packet_count, dwc_otg_module_params.max_packet_count,
  67394. + int, 0444);
  67395. +MODULE_PARM_DESC(max_packet_count,
  67396. + "The maximum number of packets in a transfer 15-511");
  67397. +module_param_named(host_channels, dwc_otg_module_params.host_channels, int,
  67398. + 0444);
  67399. +MODULE_PARM_DESC(host_channels,
  67400. + "The number of host channel registers to use 1-16");
  67401. +module_param_named(dev_endpoints, dwc_otg_module_params.dev_endpoints, int,
  67402. + 0444);
  67403. +MODULE_PARM_DESC(dev_endpoints,
  67404. + "The number of endpoints in addition to EP0 available for device mode 1-15");
  67405. +module_param_named(phy_type, dwc_otg_module_params.phy_type, int, 0444);
  67406. +MODULE_PARM_DESC(phy_type, "0=Reserved 1=UTMI+ 2=ULPI");
  67407. +module_param_named(phy_utmi_width, dwc_otg_module_params.phy_utmi_width, int,
  67408. + 0444);
  67409. +MODULE_PARM_DESC(phy_utmi_width, "Specifies the UTMI+ Data Width 8 or 16 bits");
  67410. +module_param_named(phy_ulpi_ddr, dwc_otg_module_params.phy_ulpi_ddr, int, 0444);
  67411. +MODULE_PARM_DESC(phy_ulpi_ddr,
  67412. + "ULPI at double or single data rate 0=Single 1=Double");
  67413. +module_param_named(phy_ulpi_ext_vbus, dwc_otg_module_params.phy_ulpi_ext_vbus,
  67414. + int, 0444);
  67415. +MODULE_PARM_DESC(phy_ulpi_ext_vbus,
  67416. + "ULPI PHY using internal or external vbus 0=Internal");
  67417. +module_param_named(i2c_enable, dwc_otg_module_params.i2c_enable, int, 0444);
  67418. +MODULE_PARM_DESC(i2c_enable, "FS PHY Interface");
  67419. +module_param_named(ulpi_fs_ls, dwc_otg_module_params.ulpi_fs_ls, int, 0444);
  67420. +MODULE_PARM_DESC(ulpi_fs_ls, "ULPI PHY FS/LS mode only");
  67421. +module_param_named(ts_dline, dwc_otg_module_params.ts_dline, int, 0444);
  67422. +MODULE_PARM_DESC(ts_dline, "Term select Dline pulsing for all PHYs");
  67423. +module_param_named(debug, g_dbg_lvl, int, 0444);
  67424. +MODULE_PARM_DESC(debug, "");
  67425. +
  67426. +module_param_named(en_multiple_tx_fifo,
  67427. + dwc_otg_module_params.en_multiple_tx_fifo, int, 0444);
  67428. +MODULE_PARM_DESC(en_multiple_tx_fifo,
  67429. + "Dedicated Non Periodic Tx FIFOs 0=disabled 1=enabled");
  67430. +module_param_named(dev_tx_fifo_size_1,
  67431. + dwc_otg_module_params.dev_tx_fifo_size[0], int, 0444);
  67432. +MODULE_PARM_DESC(dev_tx_fifo_size_1, "Number of words in the Tx FIFO 4-768");
  67433. +module_param_named(dev_tx_fifo_size_2,
  67434. + dwc_otg_module_params.dev_tx_fifo_size[1], int, 0444);
  67435. +MODULE_PARM_DESC(dev_tx_fifo_size_2, "Number of words in the Tx FIFO 4-768");
  67436. +module_param_named(dev_tx_fifo_size_3,
  67437. + dwc_otg_module_params.dev_tx_fifo_size[2], int, 0444);
  67438. +MODULE_PARM_DESC(dev_tx_fifo_size_3, "Number of words in the Tx FIFO 4-768");
  67439. +module_param_named(dev_tx_fifo_size_4,
  67440. + dwc_otg_module_params.dev_tx_fifo_size[3], int, 0444);
  67441. +MODULE_PARM_DESC(dev_tx_fifo_size_4, "Number of words in the Tx FIFO 4-768");
  67442. +module_param_named(dev_tx_fifo_size_5,
  67443. + dwc_otg_module_params.dev_tx_fifo_size[4], int, 0444);
  67444. +MODULE_PARM_DESC(dev_tx_fifo_size_5, "Number of words in the Tx FIFO 4-768");
  67445. +module_param_named(dev_tx_fifo_size_6,
  67446. + dwc_otg_module_params.dev_tx_fifo_size[5], int, 0444);
  67447. +MODULE_PARM_DESC(dev_tx_fifo_size_6, "Number of words in the Tx FIFO 4-768");
  67448. +module_param_named(dev_tx_fifo_size_7,
  67449. + dwc_otg_module_params.dev_tx_fifo_size[6], int, 0444);
  67450. +MODULE_PARM_DESC(dev_tx_fifo_size_7, "Number of words in the Tx FIFO 4-768");
  67451. +module_param_named(dev_tx_fifo_size_8,
  67452. + dwc_otg_module_params.dev_tx_fifo_size[7], int, 0444);
  67453. +MODULE_PARM_DESC(dev_tx_fifo_size_8, "Number of words in the Tx FIFO 4-768");
  67454. +module_param_named(dev_tx_fifo_size_9,
  67455. + dwc_otg_module_params.dev_tx_fifo_size[8], int, 0444);
  67456. +MODULE_PARM_DESC(dev_tx_fifo_size_9, "Number of words in the Tx FIFO 4-768");
  67457. +module_param_named(dev_tx_fifo_size_10,
  67458. + dwc_otg_module_params.dev_tx_fifo_size[9], int, 0444);
  67459. +MODULE_PARM_DESC(dev_tx_fifo_size_10, "Number of words in the Tx FIFO 4-768");
  67460. +module_param_named(dev_tx_fifo_size_11,
  67461. + dwc_otg_module_params.dev_tx_fifo_size[10], int, 0444);
  67462. +MODULE_PARM_DESC(dev_tx_fifo_size_11, "Number of words in the Tx FIFO 4-768");
  67463. +module_param_named(dev_tx_fifo_size_12,
  67464. + dwc_otg_module_params.dev_tx_fifo_size[11], int, 0444);
  67465. +MODULE_PARM_DESC(dev_tx_fifo_size_12, "Number of words in the Tx FIFO 4-768");
  67466. +module_param_named(dev_tx_fifo_size_13,
  67467. + dwc_otg_module_params.dev_tx_fifo_size[12], int, 0444);
  67468. +MODULE_PARM_DESC(dev_tx_fifo_size_13, "Number of words in the Tx FIFO 4-768");
  67469. +module_param_named(dev_tx_fifo_size_14,
  67470. + dwc_otg_module_params.dev_tx_fifo_size[13], int, 0444);
  67471. +MODULE_PARM_DESC(dev_tx_fifo_size_14, "Number of words in the Tx FIFO 4-768");
  67472. +module_param_named(dev_tx_fifo_size_15,
  67473. + dwc_otg_module_params.dev_tx_fifo_size[14], int, 0444);
  67474. +MODULE_PARM_DESC(dev_tx_fifo_size_15, "Number of words in the Tx FIFO 4-768");
  67475. +
  67476. +module_param_named(thr_ctl, dwc_otg_module_params.thr_ctl, int, 0444);
  67477. +MODULE_PARM_DESC(thr_ctl,
  67478. + "Thresholding enable flag bit 0 - non ISO Tx thr., 1 - ISO Tx thr., 2 - Rx thr.- bit 0=disabled 1=enabled");
  67479. +module_param_named(tx_thr_length, dwc_otg_module_params.tx_thr_length, int,
  67480. + 0444);
  67481. +MODULE_PARM_DESC(tx_thr_length, "Tx Threshold length in 32 bit DWORDs");
  67482. +module_param_named(rx_thr_length, dwc_otg_module_params.rx_thr_length, int,
  67483. + 0444);
  67484. +MODULE_PARM_DESC(rx_thr_length, "Rx Threshold length in 32 bit DWORDs");
  67485. +
  67486. +module_param_named(pti_enable, dwc_otg_module_params.pti_enable, int, 0444);
  67487. +module_param_named(mpi_enable, dwc_otg_module_params.mpi_enable, int, 0444);
  67488. +module_param_named(lpm_enable, dwc_otg_module_params.lpm_enable, int, 0444);
  67489. +MODULE_PARM_DESC(lpm_enable, "LPM Enable 0=LPM Disabled 1=LPM Enabled");
  67490. +module_param_named(ic_usb_cap, dwc_otg_module_params.ic_usb_cap, int, 0444);
  67491. +MODULE_PARM_DESC(ic_usb_cap,
  67492. + "IC_USB Capability 0=IC_USB Disabled 1=IC_USB Enabled");
  67493. +module_param_named(ahb_thr_ratio, dwc_otg_module_params.ahb_thr_ratio, int,
  67494. + 0444);
  67495. +MODULE_PARM_DESC(ahb_thr_ratio, "AHB Threshold Ratio");
  67496. +module_param_named(power_down, dwc_otg_module_params.power_down, int, 0444);
  67497. +MODULE_PARM_DESC(power_down, "Power Down Mode");
  67498. +module_param_named(reload_ctl, dwc_otg_module_params.reload_ctl, int, 0444);
  67499. +MODULE_PARM_DESC(reload_ctl, "HFIR Reload Control");
  67500. +module_param_named(dev_out_nak, dwc_otg_module_params.dev_out_nak, int, 0444);
  67501. +MODULE_PARM_DESC(dev_out_nak, "Enable Device OUT NAK");
  67502. +module_param_named(cont_on_bna, dwc_otg_module_params.cont_on_bna, int, 0444);
  67503. +MODULE_PARM_DESC(cont_on_bna, "Enable Enable Continue on BNA");
  67504. +module_param_named(ahb_single, dwc_otg_module_params.ahb_single, int, 0444);
  67505. +MODULE_PARM_DESC(ahb_single, "Enable AHB Single Support");
  67506. +module_param_named(adp_enable, dwc_otg_module_params.adp_enable, int, 0444);
  67507. +MODULE_PARM_DESC(adp_enable, "ADP Enable 0=ADP Disabled 1=ADP Enabled");
  67508. +module_param_named(otg_ver, dwc_otg_module_params.otg_ver, int, 0444);
  67509. +MODULE_PARM_DESC(otg_ver, "OTG revision supported 0=OTG 1.3 1=OTG 2.0");
  67510. +module_param(microframe_schedule, bool, 0444);
  67511. +MODULE_PARM_DESC(microframe_schedule, "Enable the microframe scheduler");
  67512. +
  67513. +module_param(fiq_enable, bool, 0444);
  67514. +MODULE_PARM_DESC(fiq_enable, "Enable the FIQ");
  67515. +module_param(nak_holdoff, ushort, 0644);
  67516. +MODULE_PARM_DESC(nak_holdoff, "Throttle duration for bulk split-transaction endpoints on a NAK. Default 8");
  67517. +module_param(fiq_fsm_enable, bool, 0444);
  67518. +MODULE_PARM_DESC(fiq_fsm_enable, "Enable the FIQ to perform split transactions as defined by fiq_fsm_mask");
  67519. +module_param(fiq_fsm_mask, ushort, 0444);
  67520. +MODULE_PARM_DESC(fiq_fsm_mask, "Bitmask of transactions to perform in the FIQ.\n"
  67521. + "Bit 0 : Non-periodic split transactions\n"
  67522. + "Bit 1 : Periodic split transactions\n"
  67523. + "Bit 2 : High-speed multi-transfer isochronous\n"
  67524. + "All other bits should be set 0.");
  67525. +
  67526. +
  67527. +/** @page "Module Parameters"
  67528. + *
  67529. + * The following parameters may be specified when starting the module.
  67530. + * These parameters define how the DWC_otg controller should be
  67531. + * configured. Parameter values are passed to the CIL initialization
  67532. + * function dwc_otg_cil_init
  67533. + *
  67534. + * Example: <code>modprobe dwc_otg speed=1 otg_cap=1</code>
  67535. + *
  67536. +
  67537. + <table>
  67538. + <tr><td>Parameter Name</td><td>Meaning</td></tr>
  67539. +
  67540. + <tr>
  67541. + <td>otg_cap</td>
  67542. + <td>Specifies the OTG capabilities. The driver will automatically detect the
  67543. + value for this parameter if none is specified.
  67544. + - 0: HNP and SRP capable (default, if available)
  67545. + - 1: SRP Only capable
  67546. + - 2: No HNP/SRP capable
  67547. + </td></tr>
  67548. +
  67549. + <tr>
  67550. + <td>dma_enable</td>
  67551. + <td>Specifies whether to use slave or DMA mode for accessing the data FIFOs.
  67552. + The driver will automatically detect the value for this parameter if none is
  67553. + specified.
  67554. + - 0: Slave
  67555. + - 1: DMA (default, if available)
  67556. + </td></tr>
  67557. +
  67558. + <tr>
  67559. + <td>dma_burst_size</td>
  67560. + <td>The DMA Burst size (applicable only for External DMA Mode).
  67561. + - Values: 1, 4, 8 16, 32, 64, 128, 256 (default 32)
  67562. + </td></tr>
  67563. +
  67564. + <tr>
  67565. + <td>speed</td>
  67566. + <td>Specifies the maximum speed of operation in host and device mode. The
  67567. + actual speed depends on the speed of the attached device and the value of
  67568. + phy_type.
  67569. + - 0: High Speed (default)
  67570. + - 1: Full Speed
  67571. + </td></tr>
  67572. +
  67573. + <tr>
  67574. + <td>host_support_fs_ls_low_power</td>
  67575. + <td>Specifies whether low power mode is supported when attached to a Full
  67576. + Speed or Low Speed device in host mode.
  67577. + - 0: Don't support low power mode (default)
  67578. + - 1: Support low power mode
  67579. + </td></tr>
  67580. +
  67581. + <tr>
  67582. + <td>host_ls_low_power_phy_clk</td>
  67583. + <td>Specifies the PHY clock rate in low power mode when connected to a Low
  67584. + Speed device in host mode. This parameter is applicable only if
  67585. + HOST_SUPPORT_FS_LS_LOW_POWER is enabled.
  67586. + - 0: 48 MHz (default)
  67587. + - 1: 6 MHz
  67588. + </td></tr>
  67589. +
  67590. + <tr>
  67591. + <td>enable_dynamic_fifo</td>
  67592. + <td> Specifies whether FIFOs may be resized by the driver software.
  67593. + - 0: Use cC FIFO size parameters
  67594. + - 1: Allow dynamic FIFO sizing (default)
  67595. + </td></tr>
  67596. +
  67597. + <tr>
  67598. + <td>data_fifo_size</td>
  67599. + <td>Total number of 4-byte words in the data FIFO memory. This memory
  67600. + includes the Rx FIFO, non-periodic Tx FIFO, and periodic Tx FIFOs.
  67601. + - Values: 32 to 32768 (default 8192)
  67602. +
  67603. + Note: The total FIFO memory depth in the FPGA configuration is 8192.
  67604. + </td></tr>
  67605. +
  67606. + <tr>
  67607. + <td>dev_rx_fifo_size</td>
  67608. + <td>Number of 4-byte words in the Rx FIFO in device mode when dynamic
  67609. + FIFO sizing is enabled.
  67610. + - Values: 16 to 32768 (default 1064)
  67611. + </td></tr>
  67612. +
  67613. + <tr>
  67614. + <td>dev_nperio_tx_fifo_size</td>
  67615. + <td>Number of 4-byte words in the non-periodic Tx FIFO in device mode when
  67616. + dynamic FIFO sizing is enabled.
  67617. + - Values: 16 to 32768 (default 1024)
  67618. + </td></tr>
  67619. +
  67620. + <tr>
  67621. + <td>dev_perio_tx_fifo_size_n (n = 1 to 15)</td>
  67622. + <td>Number of 4-byte words in each of the periodic Tx FIFOs in device mode
  67623. + when dynamic FIFO sizing is enabled.
  67624. + - Values: 4 to 768 (default 256)
  67625. + </td></tr>
  67626. +
  67627. + <tr>
  67628. + <td>host_rx_fifo_size</td>
  67629. + <td>Number of 4-byte words in the Rx FIFO in host mode when dynamic FIFO
  67630. + sizing is enabled.
  67631. + - Values: 16 to 32768 (default 1024)
  67632. + </td></tr>
  67633. +
  67634. + <tr>
  67635. + <td>host_nperio_tx_fifo_size</td>
  67636. + <td>Number of 4-byte words in the non-periodic Tx FIFO in host mode when
  67637. + dynamic FIFO sizing is enabled in the core.
  67638. + - Values: 16 to 32768 (default 1024)
  67639. + </td></tr>
  67640. +
  67641. + <tr>
  67642. + <td>host_perio_tx_fifo_size</td>
  67643. + <td>Number of 4-byte words in the host periodic Tx FIFO when dynamic FIFO
  67644. + sizing is enabled.
  67645. + - Values: 16 to 32768 (default 1024)
  67646. + </td></tr>
  67647. +
  67648. + <tr>
  67649. + <td>max_transfer_size</td>
  67650. + <td>The maximum transfer size supported in bytes.
  67651. + - Values: 2047 to 65,535 (default 65,535)
  67652. + </td></tr>
  67653. +
  67654. + <tr>
  67655. + <td>max_packet_count</td>
  67656. + <td>The maximum number of packets in a transfer.
  67657. + - Values: 15 to 511 (default 511)
  67658. + </td></tr>
  67659. +
  67660. + <tr>
  67661. + <td>host_channels</td>
  67662. + <td>The number of host channel registers to use.
  67663. + - Values: 1 to 16 (default 12)
  67664. +
  67665. + Note: The FPGA configuration supports a maximum of 12 host channels.
  67666. + </td></tr>
  67667. +
  67668. + <tr>
  67669. + <td>dev_endpoints</td>
  67670. + <td>The number of endpoints in addition to EP0 available for device mode
  67671. + operations.
  67672. + - Values: 1 to 15 (default 6 IN and OUT)
  67673. +
  67674. + Note: The FPGA configuration supports a maximum of 6 IN and OUT endpoints in
  67675. + addition to EP0.
  67676. + </td></tr>
  67677. +
  67678. + <tr>
  67679. + <td>phy_type</td>
  67680. + <td>Specifies the type of PHY interface to use. By default, the driver will
  67681. + automatically detect the phy_type.
  67682. + - 0: Full Speed
  67683. + - 1: UTMI+ (default, if available)
  67684. + - 2: ULPI
  67685. + </td></tr>
  67686. +
  67687. + <tr>
  67688. + <td>phy_utmi_width</td>
  67689. + <td>Specifies the UTMI+ Data Width. This parameter is applicable for a
  67690. + phy_type of UTMI+. Also, this parameter is applicable only if the
  67691. + OTG_HSPHY_WIDTH cC parameter was set to "8 and 16 bits", meaning that the
  67692. + core has been configured to work at either data path width.
  67693. + - Values: 8 or 16 bits (default 16)
  67694. + </td></tr>
  67695. +
  67696. + <tr>
  67697. + <td>phy_ulpi_ddr</td>
  67698. + <td>Specifies whether the ULPI operates at double or single data rate. This
  67699. + parameter is only applicable if phy_type is ULPI.
  67700. + - 0: single data rate ULPI interface with 8 bit wide data bus (default)
  67701. + - 1: double data rate ULPI interface with 4 bit wide data bus
  67702. + </td></tr>
  67703. +
  67704. + <tr>
  67705. + <td>i2c_enable</td>
  67706. + <td>Specifies whether to use the I2C interface for full speed PHY. This
  67707. + parameter is only applicable if PHY_TYPE is FS.
  67708. + - 0: Disabled (default)
  67709. + - 1: Enabled
  67710. + </td></tr>
  67711. +
  67712. + <tr>
  67713. + <td>ulpi_fs_ls</td>
  67714. + <td>Specifies whether to use ULPI FS/LS mode only.
  67715. + - 0: Disabled (default)
  67716. + - 1: Enabled
  67717. + </td></tr>
  67718. +
  67719. + <tr>
  67720. + <td>ts_dline</td>
  67721. + <td>Specifies whether term select D-Line pulsing for all PHYs is enabled.
  67722. + - 0: Disabled (default)
  67723. + - 1: Enabled
  67724. + </td></tr>
  67725. +
  67726. + <tr>
  67727. + <td>en_multiple_tx_fifo</td>
  67728. + <td>Specifies whether dedicatedto tx fifos are enabled for non periodic IN EPs.
  67729. + The driver will automatically detect the value for this parameter if none is
  67730. + specified.
  67731. + - 0: Disabled
  67732. + - 1: Enabled (default, if available)
  67733. + </td></tr>
  67734. +
  67735. + <tr>
  67736. + <td>dev_tx_fifo_size_n (n = 1 to 15)</td>
  67737. + <td>Number of 4-byte words in each of the Tx FIFOs in device mode
  67738. + when dynamic FIFO sizing is enabled.
  67739. + - Values: 4 to 768 (default 256)
  67740. + </td></tr>
  67741. +
  67742. + <tr>
  67743. + <td>tx_thr_length</td>
  67744. + <td>Transmit Threshold length in 32 bit double words
  67745. + - Values: 8 to 128 (default 64)
  67746. + </td></tr>
  67747. +
  67748. + <tr>
  67749. + <td>rx_thr_length</td>
  67750. + <td>Receive Threshold length in 32 bit double words
  67751. + - Values: 8 to 128 (default 64)
  67752. + </td></tr>
  67753. +
  67754. +<tr>
  67755. + <td>thr_ctl</td>
  67756. + <td>Specifies whether to enable Thresholding for Device mode. Bits 0, 1, 2 of
  67757. + this parmater specifies if thresholding is enabled for non-Iso Tx, Iso Tx and
  67758. + Rx transfers accordingly.
  67759. + The driver will automatically detect the value for this parameter if none is
  67760. + specified.
  67761. + - Values: 0 to 7 (default 0)
  67762. + Bit values indicate:
  67763. + - 0: Thresholding disabled
  67764. + - 1: Thresholding enabled
  67765. + </td></tr>
  67766. +
  67767. +<tr>
  67768. + <td>dma_desc_enable</td>
  67769. + <td>Specifies whether to enable Descriptor DMA mode.
  67770. + The driver will automatically detect the value for this parameter if none is
  67771. + specified.
  67772. + - 0: Descriptor DMA disabled
  67773. + - 1: Descriptor DMA (default, if available)
  67774. + </td></tr>
  67775. +
  67776. +<tr>
  67777. + <td>mpi_enable</td>
  67778. + <td>Specifies whether to enable MPI enhancement mode.
  67779. + The driver will automatically detect the value for this parameter if none is
  67780. + specified.
  67781. + - 0: MPI disabled (default)
  67782. + - 1: MPI enable
  67783. + </td></tr>
  67784. +
  67785. +<tr>
  67786. + <td>pti_enable</td>
  67787. + <td>Specifies whether to enable PTI enhancement support.
  67788. + The driver will automatically detect the value for this parameter if none is
  67789. + specified.
  67790. + - 0: PTI disabled (default)
  67791. + - 1: PTI enable
  67792. + </td></tr>
  67793. +
  67794. +<tr>
  67795. + <td>lpm_enable</td>
  67796. + <td>Specifies whether to enable LPM support.
  67797. + The driver will automatically detect the value for this parameter if none is
  67798. + specified.
  67799. + - 0: LPM disabled
  67800. + - 1: LPM enable (default, if available)
  67801. + </td></tr>
  67802. +
  67803. +<tr>
  67804. + <td>ic_usb_cap</td>
  67805. + <td>Specifies whether to enable IC_USB capability.
  67806. + The driver will automatically detect the value for this parameter if none is
  67807. + specified.
  67808. + - 0: IC_USB disabled (default, if available)
  67809. + - 1: IC_USB enable
  67810. + </td></tr>
  67811. +
  67812. +<tr>
  67813. + <td>ahb_thr_ratio</td>
  67814. + <td>Specifies AHB Threshold ratio.
  67815. + - Values: 0 to 3 (default 0)
  67816. + </td></tr>
  67817. +
  67818. +<tr>
  67819. + <td>power_down</td>
  67820. + <td>Specifies Power Down(Hibernation) Mode.
  67821. + The driver will automatically detect the value for this parameter if none is
  67822. + specified.
  67823. + - 0: Power Down disabled (default)
  67824. + - 2: Power Down enabled
  67825. + </td></tr>
  67826. +
  67827. + <tr>
  67828. + <td>reload_ctl</td>
  67829. + <td>Specifies whether dynamic reloading of the HFIR register is allowed during
  67830. + run time. The driver will automatically detect the value for this parameter if
  67831. + none is specified. In case the HFIR value is reloaded when HFIR.RldCtrl == 1'b0
  67832. + the core might misbehave.
  67833. + - 0: Reload Control disabled (default)
  67834. + - 1: Reload Control enabled
  67835. + </td></tr>
  67836. +
  67837. + <tr>
  67838. + <td>dev_out_nak</td>
  67839. + <td>Specifies whether Device OUT NAK enhancement enabled or no.
  67840. + The driver will automatically detect the value for this parameter if
  67841. + none is specified. This parameter is valid only when OTG_EN_DESC_DMA == 1b1.
  67842. + - 0: The core does not set NAK after Bulk OUT transfer complete (default)
  67843. + - 1: The core sets NAK after Bulk OUT transfer complete
  67844. + </td></tr>
  67845. +
  67846. + <tr>
  67847. + <td>cont_on_bna</td>
  67848. + <td>Specifies whether Enable Continue on BNA enabled or no.
  67849. + After receiving BNA interrupt the core disables the endpoint,when the
  67850. + endpoint is re-enabled by the application the
  67851. + - 0: Core starts processing from the DOEPDMA descriptor (default)
  67852. + - 1: Core starts processing from the descriptor which received the BNA.
  67853. + This parameter is valid only when OTG_EN_DESC_DMA == 1b1.
  67854. + </td></tr>
  67855. +
  67856. + <tr>
  67857. + <td>ahb_single</td>
  67858. + <td>This bit when programmed supports SINGLE transfers for remainder data
  67859. + in a transfer for DMA mode of operation.
  67860. + - 0: The remainder data will be sent using INCR burst size (default)
  67861. + - 1: The remainder data will be sent using SINGLE burst size.
  67862. + </td></tr>
  67863. +
  67864. +<tr>
  67865. + <td>adp_enable</td>
  67866. + <td>Specifies whether ADP feature is enabled.
  67867. + The driver will automatically detect the value for this parameter if none is
  67868. + specified.
  67869. + - 0: ADP feature disabled (default)
  67870. + - 1: ADP feature enabled
  67871. + </td></tr>
  67872. +
  67873. + <tr>
  67874. + <td>otg_ver</td>
  67875. + <td>Specifies whether OTG is performing as USB OTG Revision 2.0 or Revision 1.3
  67876. + USB OTG device.
  67877. + - 0: OTG 2.0 support disabled (default)
  67878. + - 1: OTG 2.0 support enabled
  67879. + </td></tr>
  67880. +
  67881. +*/
  67882. diff -Nur linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_driver.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_driver.h
  67883. --- linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_driver.h 1970-01-01 01:00:00.000000000 +0100
  67884. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_driver.h 2014-04-24 15:37:13.310990489 +0200
  67885. @@ -0,0 +1,86 @@
  67886. +/* ==========================================================================
  67887. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_driver.h $
  67888. + * $Revision: #19 $
  67889. + * $Date: 2010/11/15 $
  67890. + * $Change: 1627671 $
  67891. + *
  67892. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  67893. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  67894. + * otherwise expressly agreed to in writing between Synopsys and you.
  67895. + *
  67896. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  67897. + * any End User Software License Agreement or Agreement for Licensed Product
  67898. + * with Synopsys or any supplement thereto. You are permitted to use and
  67899. + * redistribute this Software in source and binary forms, with or without
  67900. + * modification, provided that redistributions of source code must retain this
  67901. + * notice. You may not view, use, disclose, copy or distribute this file or
  67902. + * any information contained herein except pursuant to this license grant from
  67903. + * Synopsys. If you do not agree with this notice, including the disclaimer
  67904. + * below, then you are not authorized to use the Software.
  67905. + *
  67906. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  67907. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  67908. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  67909. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  67910. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  67911. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  67912. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  67913. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  67914. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  67915. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  67916. + * DAMAGE.
  67917. + * ========================================================================== */
  67918. +
  67919. +#ifndef __DWC_OTG_DRIVER_H__
  67920. +#define __DWC_OTG_DRIVER_H__
  67921. +
  67922. +/** @file
  67923. + * This file contains the interface to the Linux driver.
  67924. + */
  67925. +#include "dwc_otg_os_dep.h"
  67926. +#include "dwc_otg_core_if.h"
  67927. +
  67928. +/* Type declarations */
  67929. +struct dwc_otg_pcd;
  67930. +struct dwc_otg_hcd;
  67931. +
  67932. +/**
  67933. + * This structure is a wrapper that encapsulates the driver components used to
  67934. + * manage a single DWC_otg controller.
  67935. + */
  67936. +typedef struct dwc_otg_device {
  67937. + /** Structure containing OS-dependent stuff. KEEP THIS STRUCT AT THE
  67938. + * VERY BEGINNING OF THE DEVICE STRUCT. OSes such as FreeBSD and NetBSD
  67939. + * require this. */
  67940. + struct os_dependent os_dep;
  67941. +
  67942. + /** Pointer to the core interface structure. */
  67943. + dwc_otg_core_if_t *core_if;
  67944. +
  67945. + /** Pointer to the PCD structure. */
  67946. + struct dwc_otg_pcd *pcd;
  67947. +
  67948. + /** Pointer to the HCD structure. */
  67949. + struct dwc_otg_hcd *hcd;
  67950. +
  67951. + /** Flag to indicate whether the common IRQ handler is installed. */
  67952. + uint8_t common_irq_installed;
  67953. +
  67954. +} dwc_otg_device_t;
  67955. +
  67956. +/*We must clear S3C24XX_EINTPEND external interrupt register
  67957. + * because after clearing in this register trigerred IRQ from
  67958. + * H/W core in kernel interrupt can be occured again before OTG
  67959. + * handlers clear all IRQ sources of Core registers because of
  67960. + * timing latencies and Low Level IRQ Type.
  67961. + */
  67962. +#ifdef CONFIG_MACH_IPMATE
  67963. +#define S3C2410X_CLEAR_EINTPEND() \
  67964. +do { \
  67965. + __raw_writel(1UL << 11,S3C24XX_EINTPEND); \
  67966. +} while (0)
  67967. +#else
  67968. +#define S3C2410X_CLEAR_EINTPEND() do { } while (0)
  67969. +#endif
  67970. +
  67971. +#endif
  67972. diff -Nur linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.c
  67973. --- linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.c 1970-01-01 01:00:00.000000000 +0100
  67974. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.c 2014-04-24 15:37:13.310990489 +0200
  67975. @@ -0,0 +1,1217 @@
  67976. +/*
  67977. + * dwc_otg_fiq_fsm.c - The finite state machine FIQ
  67978. + *
  67979. + * Copyright (c) 2013 Raspberry Pi Foundation
  67980. + *
  67981. + * Author: Jonathan Bell <jonathan@raspberrypi.org>
  67982. + * All rights reserved.
  67983. + *
  67984. + * Redistribution and use in source and binary forms, with or without
  67985. + * modification, are permitted provided that the following conditions are met:
  67986. + * * Redistributions of source code must retain the above copyright
  67987. + * notice, this list of conditions and the following disclaimer.
  67988. + * * Redistributions in binary form must reproduce the above copyright
  67989. + * notice, this list of conditions and the following disclaimer in the
  67990. + * documentation and/or other materials provided with the distribution.
  67991. + * * Neither the name of Raspberry Pi nor the
  67992. + * names of its contributors may be used to endorse or promote products
  67993. + * derived from this software without specific prior written permission.
  67994. + *
  67995. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  67996. + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  67997. + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  67998. + * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  67999. + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  68000. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  68001. + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  68002. + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  68003. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  68004. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  68005. + *
  68006. + * This FIQ implements functionality that performs split transactions on
  68007. + * the dwc_otg hardware without any outside intervention. A split transaction
  68008. + * is "queued" by nominating a specific host channel to perform the entirety
  68009. + * of a split transaction. This FIQ will then perform the microframe-precise
  68010. + * scheduling required in each phase of the transaction until completion.
  68011. + *
  68012. + * The FIQ functionality is glued into the Synopsys driver via the entry point
  68013. + * in the FSM enqueue function, and at the exit point in handling a HC interrupt
  68014. + * for a FSM-enabled channel.
  68015. + *
  68016. + * NB: Large parts of this implementation have architecture-specific code.
  68017. + * For porting this functionality to other ARM machines, the minimum is required:
  68018. + * - An interrupt controller allowing the top-level dwc USB interrupt to be routed
  68019. + * to the FIQ
  68020. + * - A method of forcing a software generated interrupt from FIQ mode that then
  68021. + * triggers an IRQ entry (with the dwc USB handler called by this IRQ number)
  68022. + * - Guaranteed interrupt routing such that both the FIQ and SGI occur on the same
  68023. + * processor core - there is no locking between the FIQ and IRQ (aside from
  68024. + * local_fiq_disable)
  68025. + *
  68026. + */
  68027. +
  68028. +#include "dwc_otg_fiq_fsm.h"
  68029. +
  68030. +
  68031. +char buffer[1000*16];
  68032. +int wptr;
  68033. +void notrace _fiq_print(enum fiq_debug_level dbg_lvl, volatile struct fiq_state *state, char *fmt, ...)
  68034. +{
  68035. + enum fiq_debug_level dbg_lvl_req = FIQDBG_ERR;
  68036. + va_list args;
  68037. + char text[17];
  68038. + hfnum_data_t hfnum = { .d32 = FIQ_READ(state->dwc_regs_base + 0x408) };
  68039. +
  68040. + if((dbg_lvl & dbg_lvl_req) || dbg_lvl == FIQDBG_ERR)
  68041. + {
  68042. + snprintf(text, 9, " %4d:%1u ", hfnum.b.frnum/8, hfnum.b.frnum & 7);
  68043. + va_start(args, fmt);
  68044. + vsnprintf(text+8, 9, fmt, args);
  68045. + va_end(args);
  68046. +
  68047. + memcpy(buffer + wptr, text, 16);
  68048. + wptr = (wptr + 16) % sizeof(buffer);
  68049. + }
  68050. +}
  68051. +
  68052. +/**
  68053. + * fiq_fsm_restart_channel() - Poke channel enable bit for a split transaction
  68054. + * @channel: channel to re-enable
  68055. + */
  68056. +static void fiq_fsm_restart_channel(struct fiq_state *st, int n, int force)
  68057. +{
  68058. + hcchar_data_t hcchar = { .d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR) };
  68059. +
  68060. + hcchar.b.chen = 0;
  68061. + if (st->channel[n].hcchar_copy.b.eptype & 0x1) {
  68062. + hfnum_data_t hfnum = { .d32 = FIQ_READ(st->dwc_regs_base + HFNUM) };
  68063. + /* Hardware bug workaround: update the ssplit index */
  68064. + if (st->channel[n].hcsplt_copy.b.spltena)
  68065. + st->channel[n].expected_uframe = (hfnum.b.frnum + 1) & 0x3FFF;
  68066. +
  68067. + hcchar.b.oddfrm = (hfnum.b.frnum & 0x1) ? 0 : 1;
  68068. + }
  68069. +
  68070. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR, hcchar.d32);
  68071. + hcchar.d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR);
  68072. + hcchar.b.chen = 1;
  68073. +
  68074. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR, hcchar.d32);
  68075. + fiq_print(FIQDBG_INT, st, "HCGO %01d %01d", n, force);
  68076. +}
  68077. +
  68078. +/**
  68079. + * fiq_fsm_setup_csplit() - Prepare a host channel for a CSplit transaction stage
  68080. + * @st: Pointer to the channel's state
  68081. + * @n : channel number
  68082. + *
  68083. + * Change host channel registers to perform a complete-split transaction. Being mindful of the
  68084. + * endpoint direction, set control regs up correctly.
  68085. + */
  68086. +static void notrace fiq_fsm_setup_csplit(struct fiq_state *st, int n)
  68087. +{
  68088. + hcsplt_data_t hcsplt = { .d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCSPLT) };
  68089. + hctsiz_data_t hctsiz = { .d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ) };
  68090. +
  68091. + hcsplt.b.compsplt = 1;
  68092. + if (st->channel[n].hcchar_copy.b.epdir == 1) {
  68093. + // If IN, the CSPLIT result contains the data or a hub handshake. hctsiz = maxpacket.
  68094. + hctsiz.b.xfersize = st->channel[n].hctsiz_copy.b.xfersize;
  68095. + } else {
  68096. + // If OUT, the CSPLIT result contains handshake only.
  68097. + hctsiz.b.xfersize = 0;
  68098. + }
  68099. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCSPLT, hcsplt.d32);
  68100. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ, hctsiz.d32);
  68101. + mb();
  68102. +}
  68103. +
  68104. +static inline int notrace fiq_get_xfer_len(struct fiq_state *st, int n)
  68105. +{
  68106. + /* The xfersize register is a bit wonky. For IN transfers, it decrements by the packet size. */
  68107. + hctsiz_data_t hctsiz = { .d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ) };
  68108. +
  68109. + if (st->channel[n].hcchar_copy.b.epdir == 0) {
  68110. + return st->channel[n].hctsiz_copy.b.xfersize;
  68111. + } else {
  68112. + return st->channel[n].hctsiz_copy.b.xfersize - hctsiz.b.xfersize;
  68113. + }
  68114. +
  68115. +}
  68116. +
  68117. +
  68118. +/**
  68119. + * fiq_increment_dma_buf() - update DMA address for bounce buffers after a CSPLIT
  68120. + *
  68121. + * Of use only for IN periodic transfers.
  68122. + */
  68123. +static int notrace fiq_increment_dma_buf(struct fiq_state *st, int num_channels, int n)
  68124. +{
  68125. + hcdma_data_t hcdma;
  68126. + int i = st->channel[n].nrpackets;
  68127. + int len = 254;
  68128. + struct fiq_dma_blob *blob = (struct fiq_dma_blob *) st->dma_base;
  68129. +
  68130. + len = fiq_get_xfer_len(st, n);
  68131. + fiq_print(FIQDBG_INT, st, "LEN: %03d", len);
  68132. + st->channel[n].dma_info.slot_len[i] = len;
  68133. + i++;
  68134. + if (i > 5)
  68135. + BUG();
  68136. +
  68137. + st->channel[n].nrpackets++;
  68138. +
  68139. + hcdma.d32 = (dma_addr_t) &blob->channel[n].index[i].buf[0];
  68140. + FIQ_WRITE(st->dwc_regs_base + HC_DMA + (HC_OFFSET * n), hcdma.d32);
  68141. + return 0;
  68142. +}
  68143. +
  68144. +/**
  68145. + * fiq_reload_hctsiz() - for IN transactions, reset HCTSIZ
  68146. + */
  68147. +static void notrace fiq_fsm_reload_hctsiz(struct fiq_state *st, int n)
  68148. +{
  68149. + hctsiz_data_t hctsiz = { .d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ) };
  68150. + hctsiz.b.xfersize = st->channel[n].hctsiz_copy.b.xfersize;
  68151. + hctsiz.b.pktcnt = 1;
  68152. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ, hctsiz.d32);
  68153. +}
  68154. +
  68155. +/**
  68156. + * fiq_iso_out_advance() - update DMA address and split position bits
  68157. + * for isochronous OUT transactions.
  68158. + *
  68159. + * Returns 1 if this is the last packet queued, 0 otherwise. Split-ALL and
  68160. + * Split-BEGIN states are not handled - this is done when the transaction was queued.
  68161. + *
  68162. + * This function must only be called from the FIQ_ISO_OUT_ACTIVE state.
  68163. + */
  68164. +static int notrace fiq_iso_out_advance(struct fiq_state *st, int num_channels, int n)
  68165. +{
  68166. + hcsplt_data_t hcsplt;
  68167. + hctsiz_data_t hctsiz;
  68168. + hcdma_data_t hcdma;
  68169. + struct fiq_dma_blob *blob = (struct fiq_dma_blob *) st->dma_base;
  68170. + int last = 0;
  68171. + int i = st->channel[n].dma_info.index;
  68172. +
  68173. + fiq_print(FIQDBG_INT, st, "ADV %01d %01d ", n, i);
  68174. + i++;
  68175. + if (i == 4)
  68176. + last = 1;
  68177. + if (st->channel[n].dma_info.slot_len[i+1] == 255)
  68178. + last = 1;
  68179. +
  68180. + /* New DMA address - address of bounce buffer referred to in index */
  68181. + hcdma.d32 = (uint32_t) &blob->channel[n].index[i].buf[0];
  68182. + //hcdma.d32 = FIQ_READ(st->dwc_regs_base + HC_DMA + (HC_OFFSET * n));
  68183. + //hcdma.d32 += st->channel[n].dma_info.slot_len[i];
  68184. + fiq_print(FIQDBG_INT, st, "LAST: %01d ", last);
  68185. + fiq_print(FIQDBG_INT, st, "LEN: %03d", st->channel[n].dma_info.slot_len[i]);
  68186. + hcsplt.d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCSPLT);
  68187. + hctsiz.d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ);
  68188. + hcsplt.b.xactpos = (last) ? ISOC_XACTPOS_END : ISOC_XACTPOS_MID;
  68189. + /* Set up new packet length */
  68190. + hctsiz.b.pktcnt = 1;
  68191. + hctsiz.b.xfersize = st->channel[n].dma_info.slot_len[i];
  68192. + fiq_print(FIQDBG_INT, st, "%08x", hctsiz.d32);
  68193. +
  68194. + st->channel[n].dma_info.index++;
  68195. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCSPLT, hcsplt.d32);
  68196. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ, hctsiz.d32);
  68197. + FIQ_WRITE(st->dwc_regs_base + HC_DMA + (HC_OFFSET * n), hcdma.d32);
  68198. + return last;
  68199. +}
  68200. +
  68201. +/**
  68202. + * fiq_fsm_tt_next_isoc() - queue next pending isochronous out start-split on a TT
  68203. + *
  68204. + * Despite the limitations of the DWC core, we can force a microframe pipeline of
  68205. + * isochronous OUT start-split transactions while waiting for a corresponding other-type
  68206. + * of endpoint to finish its CSPLITs. TTs have big periodic buffers therefore it
  68207. + * is very unlikely that filling the start-split FIFO will cause data loss.
  68208. + * This allows much better interleaving of transactions in an order-independent way-
  68209. + * there is no requirement to prioritise isochronous, just a state-space search has
  68210. + * to be performed on each periodic start-split complete interrupt.
  68211. + */
  68212. +static int notrace fiq_fsm_tt_next_isoc(struct fiq_state *st, int num_channels, int n)
  68213. +{
  68214. + int hub_addr = st->channel[n].hub_addr;
  68215. + int port_addr = st->channel[n].port_addr;
  68216. + int i, poked = 0;
  68217. + for (i = 0; i < num_channels; i++) {
  68218. + if (i == n || st->channel[i].fsm == FIQ_PASSTHROUGH)
  68219. + continue;
  68220. + if (st->channel[i].hub_addr == hub_addr &&
  68221. + st->channel[i].port_addr == port_addr) {
  68222. + switch (st->channel[i].fsm) {
  68223. + case FIQ_PER_ISO_OUT_PENDING:
  68224. + if (st->channel[i].nrpackets == 1) {
  68225. + st->channel[i].fsm = FIQ_PER_ISO_OUT_LAST;
  68226. + } else {
  68227. + st->channel[i].fsm = FIQ_PER_ISO_OUT_ACTIVE;
  68228. + }
  68229. + fiq_fsm_restart_channel(st, i, 0);
  68230. + poked = 1;
  68231. + break;
  68232. +
  68233. + default:
  68234. + break;
  68235. + }
  68236. + }
  68237. + if (poked)
  68238. + break;
  68239. + }
  68240. + return poked;
  68241. +}
  68242. +
  68243. +/**
  68244. + * fiq_fsm_tt_in_use() - search for host channels using this TT
  68245. + * @n: Channel to use as reference
  68246. + *
  68247. + */
  68248. +int notrace noinline fiq_fsm_tt_in_use(struct fiq_state *st, int num_channels, int n)
  68249. +{
  68250. + int hub_addr = st->channel[n].hub_addr;
  68251. + int port_addr = st->channel[n].port_addr;
  68252. + int i, in_use = 0;
  68253. + for (i = 0; i < num_channels; i++) {
  68254. + if (i == n || st->channel[i].fsm == FIQ_PASSTHROUGH)
  68255. + continue;
  68256. + switch (st->channel[i].fsm) {
  68257. + /* TT is reserved for channels that are in the middle of a periodic
  68258. + * split transaction.
  68259. + */
  68260. + case FIQ_PER_SSPLIT_STARTED:
  68261. + case FIQ_PER_CSPLIT_WAIT:
  68262. + case FIQ_PER_CSPLIT_NYET1:
  68263. + //case FIQ_PER_CSPLIT_POLL:
  68264. + case FIQ_PER_ISO_OUT_ACTIVE:
  68265. + if (st->channel[i].hub_addr == hub_addr &&
  68266. + st->channel[i].port_addr == port_addr) {
  68267. + in_use = 1;
  68268. + }
  68269. + break;
  68270. + default:
  68271. + break;
  68272. + }
  68273. + if (in_use)
  68274. + break;
  68275. + }
  68276. + return in_use;
  68277. +}
  68278. +
  68279. +/**
  68280. + * fiq_fsm_more_csplits() - determine whether additional CSPLITs need
  68281. + * to be issued for this IN transaction.
  68282. + *
  68283. + * We cannot tell the inbound PID of a data packet due to hardware limitations.
  68284. + * we need to make an educated guess as to whether we need to queue another CSPLIT
  68285. + * or not. A no-brainer is when we have received enough data to fill the endpoint
  68286. + * size, but for endpoints that give variable-length data then we have to resort
  68287. + * to heuristics.
  68288. + *
  68289. + * We also return whether this is the last CSPLIT to be queued, again based on
  68290. + * heuristics. This is to allow a 1-uframe overlap of periodic split transactions.
  68291. + */
  68292. +
  68293. +/*
  68294. + * We need some way of guaranteeing if a returned periodic packet of size X
  68295. + * has a DATA0 PID.
  68296. + * The heuristic value of 144 bytes assumes that the received data has maximal
  68297. + * bit-stuffing and the clock frequency of the transmitting device is at the lowest
  68298. + * permissible limit. If the transfer length results in a final packet size
  68299. + * 144 < p <= 188, then an erroneous CSPLIT will be issued.
  68300. + * Also used to ensure that an endpoint will nominally only return a single
  68301. + * complete-split worth of data.
  68302. + */
  68303. +#define DATA0_PID_HEURISTIC 144
  68304. +
  68305. +static int notrace noinline fiq_fsm_more_csplits(struct fiq_state *state, int n, int *probably_last)
  68306. +{
  68307. +
  68308. + int i;
  68309. + int total_len = 0;
  68310. + int more_needed = 1;
  68311. + struct fiq_channel_state *st = &state->channel[n];
  68312. +
  68313. + for (i = 0; i < st->nrpackets; i++) {
  68314. + total_len += st->dma_info.slot_len[i];
  68315. + }
  68316. +
  68317. + *probably_last = 0;
  68318. +
  68319. + if (st->hcchar_copy.b.eptype == 0x3) {
  68320. + /*
  68321. + * An interrupt endpoint will take max 2 CSPLITs. if we are receiving data
  68322. + * then this is definitely the last CSPLIT.
  68323. + */
  68324. + *probably_last = 1;
  68325. + } else {
  68326. + /* Isoc IN. This is a bit risky if we are the first transaction:
  68327. + * we may have been held off slightly. */
  68328. + if (i > 1 && st->dma_info.slot_len[st->nrpackets-1] <= DATA0_PID_HEURISTIC) {
  68329. + more_needed = 0;
  68330. + }
  68331. + /* If in the next uframe we will receive enough data to fill the endpoint,
  68332. + * then only issue 1 more csplit.
  68333. + */
  68334. + if (st->hctsiz_copy.b.xfersize - total_len <= DATA0_PID_HEURISTIC)
  68335. + *probably_last = 1;
  68336. + }
  68337. +
  68338. + if (total_len >= st->hctsiz_copy.b.xfersize ||
  68339. + i == 6 || total_len == 0)
  68340. + more_needed = 0;
  68341. +
  68342. + return more_needed;
  68343. +}
  68344. +
  68345. +/**
  68346. + * fiq_fsm_start_next_periodic() - A half-arsed attempt at a microframe pipeline
  68347. + *
  68348. + * Search pending transactions in the start-split pending state and queue them.
  68349. + * Don't queue packets in uframe .5 (comes out in .6) (USB2.0 11.18.4).
  68350. + * Note: we specifically don't do isochronous OUT transactions first because better
  68351. + * use of the TT's start-split fifo can be achieved by pipelining an IN before an OUT.
  68352. + */
  68353. +static void notrace noinline fiq_fsm_start_next_periodic(struct fiq_state *st, int num_channels)
  68354. +{
  68355. + int n;
  68356. + hfnum_data_t hfnum = { .d32 = FIQ_READ(st->dwc_regs_base + HFNUM) };
  68357. + if ((hfnum.b.frnum & 0x7) == 5)
  68358. + return;
  68359. + for (n = 0; n < num_channels; n++) {
  68360. + if (st->channel[n].fsm == FIQ_PER_SSPLIT_QUEUED) {
  68361. + /* Check to see if any other transactions are using this TT */
  68362. + if(!fiq_fsm_tt_in_use(st, num_channels, n)) {
  68363. + st->channel[n].fsm = FIQ_PER_SSPLIT_STARTED;
  68364. + fiq_print(FIQDBG_INT, st, "NEXTPER ");
  68365. + fiq_fsm_restart_channel(st, n, 0);
  68366. + break;
  68367. + }
  68368. + }
  68369. + }
  68370. + for (n = 0; n < num_channels; n++) {
  68371. + if (st->channel[n].fsm == FIQ_PER_ISO_OUT_PENDING) {
  68372. + if (!fiq_fsm_tt_in_use(st, num_channels, n)) {
  68373. + fiq_print(FIQDBG_INT, st, "NEXTISO ");
  68374. + st->channel[n].fsm = FIQ_PER_ISO_OUT_ACTIVE;
  68375. + fiq_fsm_restart_channel(st, n, 0);
  68376. + break;
  68377. + }
  68378. + }
  68379. + }
  68380. +}
  68381. +
  68382. +/**
  68383. + * fiq_fsm_update_hs_isoc() - update isochronous frame and transfer data
  68384. + * @state: Pointer to fiq_state
  68385. + * @n: Channel transaction is active on
  68386. + * @hcint: Copy of host channel interrupt register
  68387. + *
  68388. + * Returns 0 if there are no more transactions for this HC to do, 1
  68389. + * otherwise.
  68390. + */
  68391. +static int notrace noinline fiq_fsm_update_hs_isoc(struct fiq_state *state, int n, hcint_data_t hcint)
  68392. +{
  68393. + struct fiq_channel_state *st = &state->channel[n];
  68394. + int xfer_len = 0, nrpackets = 0;
  68395. + hcdma_data_t hcdma;
  68396. + fiq_print(FIQDBG_INT, state, "HSISO %02d", n);
  68397. +
  68398. + xfer_len = fiq_get_xfer_len(state, n);
  68399. + st->hs_isoc_info.iso_desc[st->hs_isoc_info.index].actual_length = xfer_len;
  68400. +
  68401. + st->hs_isoc_info.iso_desc[st->hs_isoc_info.index].status = hcint.d32;
  68402. +
  68403. + st->hs_isoc_info.index++;
  68404. + if (st->hs_isoc_info.index == st->hs_isoc_info.nrframes) {
  68405. + return 0;
  68406. + }
  68407. +
  68408. + /* grab the next DMA address offset from the array */
  68409. + hcdma.d32 = st->hcdma_copy.d32 + st->hs_isoc_info.iso_desc[st->hs_isoc_info.index].offset;
  68410. + FIQ_WRITE(state->dwc_regs_base + HC_DMA + (HC_OFFSET * n), hcdma.d32);
  68411. +
  68412. + /* We need to set multi_count. This is a bit tricky - has to be set per-transaction as
  68413. + * the core needs to be told to send the correct number. Caution: for IN transfers,
  68414. + * this is always set to the maximum size of the endpoint. */
  68415. + xfer_len = st->hs_isoc_info.iso_desc[st->hs_isoc_info.index].length;
  68416. + /* Integer divide in a FIQ: fun. FIXME: make this not suck */
  68417. + nrpackets = (xfer_len + st->hcchar_copy.b.mps - 1) / st->hcchar_copy.b.mps;
  68418. + if (nrpackets == 0)
  68419. + nrpackets = 1;
  68420. + st->hcchar_copy.b.multicnt = nrpackets;
  68421. + st->hctsiz_copy.b.pktcnt = nrpackets;
  68422. +
  68423. + /* Initial PID also needs to be set */
  68424. + if (st->hcchar_copy.b.epdir == 0) {
  68425. + st->hctsiz_copy.b.xfersize = xfer_len;
  68426. + switch (st->hcchar_copy.b.multicnt) {
  68427. + case 1:
  68428. + st->hctsiz_copy.b.pid = DWC_PID_DATA0;
  68429. + break;
  68430. + case 2:
  68431. + case 3:
  68432. + st->hctsiz_copy.b.pid = DWC_PID_MDATA;
  68433. + break;
  68434. + }
  68435. +
  68436. + } else {
  68437. + switch (st->hcchar_copy.b.multicnt) {
  68438. + st->hctsiz_copy.b.xfersize = nrpackets * st->hcchar_copy.b.mps;
  68439. + case 1:
  68440. + st->hctsiz_copy.b.pid = DWC_PID_DATA0;
  68441. + break;
  68442. + case 2:
  68443. + st->hctsiz_copy.b.pid = DWC_PID_DATA1;
  68444. + break;
  68445. + case 3:
  68446. + st->hctsiz_copy.b.pid = DWC_PID_DATA2;
  68447. + break;
  68448. + }
  68449. + }
  68450. + FIQ_WRITE(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ, st->hctsiz_copy.d32);
  68451. + FIQ_WRITE(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR, st->hcchar_copy.d32);
  68452. + /* Channel is enabled on hcint handler exit */
  68453. + fiq_print(FIQDBG_INT, state, "HSISOOUT");
  68454. + return 1;
  68455. +}
  68456. +
  68457. +
  68458. +/**
  68459. + * fiq_fsm_do_sof() - FSM start-of-frame interrupt handler
  68460. + * @state: Pointer to the state struct passed from banked FIQ mode registers.
  68461. + * @num_channels: set according to the DWC hardware configuration
  68462. + *
  68463. + * The SOF handler in FSM mode has two functions
  68464. + * 1. Hold off SOF from causing schedule advancement in IRQ context if there's
  68465. + * nothing to do
  68466. + * 2. Advance certain FSM states that require either a microframe delay, or a microframe
  68467. + * of holdoff.
  68468. + *
  68469. + * The second part is architecture-specific to mach-bcm2835 -
  68470. + * a sane interrupt controller would have a mask register for ARM interrupt sources
  68471. + * to be promoted to the nFIQ line, but it doesn't. Instead a single interrupt
  68472. + * number (USB) can be enabled. This means that certain parts of the USB specification
  68473. + * that require "wait a little while, then issue another packet" cannot be fulfilled with
  68474. + * the timing granularity required to achieve optimal throughout. The workaround is to use
  68475. + * the SOF "timer" (125uS) to perform this task.
  68476. + */
  68477. +static int notrace noinline fiq_fsm_do_sof(struct fiq_state *state, int num_channels)
  68478. +{
  68479. + hfnum_data_t hfnum = { .d32 = FIQ_READ(state->dwc_regs_base + HFNUM) };
  68480. + int n;
  68481. +
  68482. + for (n = 0; n < num_channels; n++) {
  68483. + switch (state->channel[n].fsm) {
  68484. +
  68485. + case FIQ_NP_SSPLIT_RETRY:
  68486. + case FIQ_NP_IN_CSPLIT_RETRY:
  68487. + case FIQ_NP_OUT_CSPLIT_RETRY:
  68488. + fiq_fsm_restart_channel(state, n, 0);
  68489. + break;
  68490. +
  68491. + case FIQ_HS_ISOC_SLEEPING:
  68492. + state->channel[n].fsm = FIQ_HS_ISOC_TURBO;
  68493. + fiq_fsm_restart_channel(state, n, 0);
  68494. + break;
  68495. +
  68496. + case FIQ_PER_SSPLIT_QUEUED:
  68497. + if ((hfnum.b.frnum & 0x7) == 5)
  68498. + break;
  68499. + if (!fiq_fsm_tt_in_use(state, num_channels, n)) {
  68500. + fiq_print(FIQDBG_INT, state, "SOF GO %01d", n);
  68501. + fiq_fsm_restart_channel(state, n, 0);
  68502. + state->channel[n].fsm = FIQ_PER_SSPLIT_STARTED;
  68503. + }
  68504. + break;
  68505. +
  68506. + case FIQ_PER_ISO_OUT_PENDING:
  68507. + /* Ordinarily, this should be poked after the SSPLIT
  68508. + * complete interrupt for a competing transfer on the same
  68509. + * TT. Doesn't happen for aborted transactions though.
  68510. + */
  68511. + if ((hfnum.b.frnum & 0x7) >= 5)
  68512. + break;
  68513. + if (!fiq_fsm_tt_in_use(state, num_channels, n)) {
  68514. + /* Hardware bug. SOF can sometimes occur after the channel halt interrupt
  68515. + * that caused this.
  68516. + */
  68517. + fiq_fsm_restart_channel(state, n, 0);
  68518. + fiq_print(FIQDBG_INT, state, "SOF ISOC");
  68519. + if (state->channel[n].nrpackets == 1) {
  68520. + state->channel[n].fsm = FIQ_PER_ISO_OUT_LAST;
  68521. + } else {
  68522. + state->channel[n].fsm = FIQ_PER_ISO_OUT_ACTIVE;
  68523. + }
  68524. + }
  68525. + break;
  68526. +
  68527. + case FIQ_PER_CSPLIT_WAIT:
  68528. + /* we are guaranteed to be in this state if and only if the SSPLIT interrupt
  68529. + * occurred when the bus transaction occurred. The SOF interrupt reversal bug
  68530. + * will utterly bugger this up though.
  68531. + */
  68532. + if (hfnum.b.frnum != state->channel[n].expected_uframe) {
  68533. + fiq_print(FIQDBG_INT, state, "SOFCS %d ", n);
  68534. + state->channel[n].fsm = FIQ_PER_CSPLIT_POLL;
  68535. + fiq_fsm_restart_channel(state, n, 0);
  68536. + fiq_fsm_start_next_periodic(state, num_channels);
  68537. +
  68538. + }
  68539. + break;
  68540. +
  68541. + default:
  68542. + break;
  68543. + }
  68544. + }
  68545. +
  68546. + if ((hfnum.b.frnum & 0x7) == 1) {
  68547. + /* We cannot issue csplits for transactions in the last frame past (n+1).1
  68548. + * Check to see if there are any transactions that are stale.
  68549. + * Boot them out.
  68550. + */
  68551. + for (n = 0; n < num_channels; n++) {
  68552. + switch (state->channel[n].fsm) {
  68553. + case FIQ_PER_CSPLIT_WAIT:
  68554. + case FIQ_PER_CSPLIT_NYET1:
  68555. + case FIQ_PER_CSPLIT_POLL:
  68556. + case FIQ_PER_CSPLIT_LAST:
  68557. + /* Check if we are no longer in the same full-speed frame. */
  68558. + if (((state->channel[n].expected_uframe & 0x3FFF) & ~0x7) <
  68559. + (hfnum.b.frnum & ~0x7))
  68560. + state->channel[n].fsm = FIQ_PER_SPLIT_TIMEOUT;
  68561. + break;
  68562. + default:
  68563. + break;
  68564. + }
  68565. + }
  68566. +
  68567. + }
  68568. +
  68569. + if (!state->kick_np_queues &&
  68570. + dwc_frame_num_gt(state->next_sched_frame, hfnum.b.frnum)) {
  68571. + return 1;
  68572. + } else {
  68573. + return 0;
  68574. + }
  68575. +}
  68576. +
  68577. +
  68578. +/**
  68579. + * fiq_fsm_do_hcintr() - FSM host channel interrupt handler
  68580. + * @state: Pointer to the FIQ state struct
  68581. + * @num_channels: Number of channels as per hardware config
  68582. + * @n: channel for which HAINT(i) was raised
  68583. + *
  68584. + * An important property is that only the CHHLT interrupt is unmasked. Unfortunately, AHBerr is as well.
  68585. + */
  68586. +static int notrace noinline fiq_fsm_do_hcintr(struct fiq_state *state, int num_channels, int n)
  68587. +{
  68588. + hcint_data_t hcint;
  68589. + hcintmsk_data_t hcintmsk;
  68590. + hcchar_data_t hcchar;
  68591. + int handled = 0;
  68592. + int restart = 0;
  68593. + int last_csplit = 0;
  68594. + int start_next_periodic = 0;
  68595. + struct fiq_channel_state *st = &state->channel[n];
  68596. + hfnum_data_t hfnum;
  68597. +
  68598. + hcint.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCINT);
  68599. + hcintmsk.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCINTMSK);
  68600. +
  68601. + if (st->fsm != FIQ_PASSTHROUGH) {
  68602. + fiq_print(FIQDBG_INT, state, "HC%01d ST%02d", n, st->fsm);
  68603. + fiq_print(FIQDBG_INT, state, "%08x", hcint.d32);
  68604. + }
  68605. +
  68606. + switch (st->fsm) {
  68607. +
  68608. + case FIQ_PASSTHROUGH:
  68609. + case FIQ_DEQUEUE_ISSUED:
  68610. + /* doesn't belong to us, kick it upstairs */
  68611. + break;
  68612. +
  68613. + /* Non-periodic state groups */
  68614. + case FIQ_NP_SSPLIT_STARTED:
  68615. + case FIQ_NP_SSPLIT_RETRY:
  68616. + /* Got a HCINT for a NP SSPLIT. Expected ACK / NAK / fail */
  68617. + if (hcint.b.ack) {
  68618. + /* SSPLIT complete. For OUT, the data has been sent. For IN, the LS transaction
  68619. + * will start shortly. SOF needs to kick the transaction to prevent a NYET flood.
  68620. + */
  68621. + if(st->hcchar_copy.b.epdir == 1)
  68622. + st->fsm = FIQ_NP_IN_CSPLIT_RETRY;
  68623. + else
  68624. + st->fsm = FIQ_NP_OUT_CSPLIT_RETRY;
  68625. + st->nr_errors = 0;
  68626. + handled = 1;
  68627. + fiq_fsm_setup_csplit(state, n);
  68628. + } else if (hcint.b.nak) {
  68629. + // No buffer space in TT. Retry on a uframe boundary.
  68630. + st->fsm = FIQ_NP_SSPLIT_RETRY;
  68631. + handled = 1;
  68632. + } else if (hcint.b.xacterr) {
  68633. + // The only other one we care about is xacterr. This implies HS bus error - retry.
  68634. + st->nr_errors++;
  68635. + st->fsm = FIQ_NP_SSPLIT_RETRY;
  68636. + if (st->nr_errors >= 3) {
  68637. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  68638. + } else {
  68639. + handled = 1;
  68640. + restart = 1;
  68641. + }
  68642. + } else {
  68643. + st->fsm = FIQ_NP_SPLIT_LS_ABORTED;
  68644. + handled = 0;
  68645. + restart = 0;
  68646. + }
  68647. + break;
  68648. +
  68649. + case FIQ_NP_IN_CSPLIT_RETRY:
  68650. + /* Received a CSPLIT done interrupt.
  68651. + * Expected Data/NAK/STALL/NYET for IN.
  68652. + */
  68653. + if (hcint.b.xfercomp) {
  68654. + /* For IN, data is present. */
  68655. + st->fsm = FIQ_NP_SPLIT_DONE;
  68656. + } else if (hcint.b.nak) {
  68657. + /* no endpoint data. Punt it upstairs */
  68658. + st->fsm = FIQ_NP_SPLIT_DONE;
  68659. + } else if (hcint.b.nyet) {
  68660. + /* CSPLIT NYET - retry on a uframe boundary. */
  68661. + handled = 1;
  68662. + st->nr_errors = 0;
  68663. + } else if (hcint.b.datatglerr) {
  68664. + /* data toggle errors do not set the xfercomp bit. */
  68665. + st->fsm = FIQ_NP_SPLIT_LS_ABORTED;
  68666. + } else if (hcint.b.xacterr) {
  68667. + /* HS error. Retry immediate */
  68668. + st->fsm = FIQ_NP_IN_CSPLIT_RETRY;
  68669. + st->nr_errors++;
  68670. + if (st->nr_errors >= 3) {
  68671. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  68672. + } else {
  68673. + handled = 1;
  68674. + restart = 1;
  68675. + }
  68676. + } else if (hcint.b.stall) {
  68677. + /* A STALL implies either a LS bus error or a genuine STALL. */
  68678. + st->fsm = FIQ_NP_SPLIT_LS_ABORTED;
  68679. + } else {
  68680. + /* Hardware bug. It's possible in some cases to
  68681. + * get a channel halt with nothing else set when
  68682. + * the response was a NYET. Treat as local 3-strikes retry.
  68683. + */
  68684. + hcint_data_t hcint_test = hcint;
  68685. + hcint_test.b.chhltd = 0;
  68686. + if (!hcint_test.d32) {
  68687. + st->nr_errors++;
  68688. + if (st->nr_errors >= 3) {
  68689. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  68690. + } else {
  68691. + handled = 1;
  68692. + }
  68693. + } else {
  68694. + /* Bail out if something unexpected happened */
  68695. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  68696. + }
  68697. + }
  68698. + break;
  68699. +
  68700. + case FIQ_NP_OUT_CSPLIT_RETRY:
  68701. + /* Received a CSPLIT done interrupt.
  68702. + * Expected ACK/NAK/STALL/NYET/XFERCOMP for OUT.*/
  68703. + if (hcint.b.xfercomp) {
  68704. + st->fsm = FIQ_NP_SPLIT_DONE;
  68705. + } else if (hcint.b.nak) {
  68706. + // The HCD will implement the holdoff on frame boundaries.
  68707. + st->fsm = FIQ_NP_SPLIT_DONE;
  68708. + } else if (hcint.b.nyet) {
  68709. + // Hub still processing.
  68710. + st->fsm = FIQ_NP_OUT_CSPLIT_RETRY;
  68711. + handled = 1;
  68712. + st->nr_errors = 0;
  68713. + //restart = 1;
  68714. + } else if (hcint.b.xacterr) {
  68715. + /* HS error. retry immediate */
  68716. + st->fsm = FIQ_NP_OUT_CSPLIT_RETRY;
  68717. + st->nr_errors++;
  68718. + if (st->nr_errors >= 3) {
  68719. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  68720. + } else {
  68721. + handled = 1;
  68722. + restart = 1;
  68723. + }
  68724. + } else if (hcint.b.stall) {
  68725. + /* LS bus error or genuine stall */
  68726. + st->fsm = FIQ_NP_SPLIT_LS_ABORTED;
  68727. + } else {
  68728. + /*
  68729. + * Hardware bug. It's possible in some cases to get a
  68730. + * channel halt with nothing else set when the response was a NYET.
  68731. + * Treat as local 3-strikes retry.
  68732. + */
  68733. + hcint_data_t hcint_test = hcint;
  68734. + hcint_test.b.chhltd = 0;
  68735. + if (!hcint_test.d32) {
  68736. + st->nr_errors++;
  68737. + if (st->nr_errors >= 3) {
  68738. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  68739. + } else {
  68740. + handled = 1;
  68741. + }
  68742. + } else {
  68743. + // Something unexpected happened. AHBerror or babble perhaps. Let the IRQ deal with it.
  68744. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  68745. + }
  68746. + }
  68747. + break;
  68748. +
  68749. + /* Periodic split states (except isoc out) */
  68750. + case FIQ_PER_SSPLIT_STARTED:
  68751. + /* Expect an ACK or failure for SSPLIT */
  68752. + if (hcint.b.ack) {
  68753. + /*
  68754. + * SSPLIT transfer complete interrupt - the generation of this interrupt is fraught with bugs.
  68755. + * For a packet queued in microframe n-3 to appear in n-2, if the channel is enabled near the EOF1
  68756. + * point for microframe n-3, the packet will not appear on the bus until microframe n.
  68757. + * Additionally, the generation of the actual interrupt is dodgy. For a packet appearing on the bus
  68758. + * in microframe n, sometimes the interrupt is generated immediately. Sometimes, it appears in n+1
  68759. + * coincident with SOF for n+1.
  68760. + * SOF is also buggy. It can sometimes be raised AFTER the first bus transaction has taken place.
  68761. + * These appear to be caused by timing/clock crossing bugs within the core itself.
  68762. + * State machine workaround.
  68763. + */
  68764. + hfnum.d32 = FIQ_READ(state->dwc_regs_base + HFNUM);
  68765. + hcchar.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR);
  68766. + fiq_fsm_setup_csplit(state, n);
  68767. + /* Poke the oddfrm bit. If we are equivalent, we received the interrupt at the correct
  68768. + * time. If not, then we're in the next SOF.
  68769. + */
  68770. + if ((hfnum.b.frnum & 0x1) == hcchar.b.oddfrm) {
  68771. + fiq_print(FIQDBG_INT, state, "CSWAIT %01d", n);
  68772. + st->expected_uframe = hfnum.b.frnum;
  68773. + st->fsm = FIQ_PER_CSPLIT_WAIT;
  68774. + } else {
  68775. + fiq_print(FIQDBG_INT, state, "CSPOL %01d", n);
  68776. + /* For isochronous IN endpoints,
  68777. + * we need to hold off if we are expecting a lot of data */
  68778. + if (st->hcchar_copy.b.mps < DATA0_PID_HEURISTIC) {
  68779. + start_next_periodic = 1;
  68780. + }
  68781. + /* Danger will robinson: we are in a broken state. If our first interrupt after
  68782. + * this is a NYET, it will be delayed by 1 uframe and result in an unrecoverable
  68783. + * lag. Unmask the NYET interrupt.
  68784. + */
  68785. + st->expected_uframe = (hfnum.b.frnum + 1) & 0x3FFF;
  68786. + st->fsm = FIQ_PER_CSPLIT_BROKEN_NYET1;
  68787. + restart = 1;
  68788. + }
  68789. + handled = 1;
  68790. + } else if (hcint.b.xacterr) {
  68791. + /* 3-strikes retry is enabled, we have hit our max nr_errors */
  68792. + st->fsm = FIQ_PER_SPLIT_HS_ABORTED;
  68793. + start_next_periodic = 1;
  68794. + } else {
  68795. + st->fsm = FIQ_PER_SPLIT_HS_ABORTED;
  68796. + start_next_periodic = 1;
  68797. + }
  68798. + /* We can now queue the next isochronous OUT transaction, if one is pending. */
  68799. + if(fiq_fsm_tt_next_isoc(state, num_channels, n)) {
  68800. + fiq_print(FIQDBG_INT, state, "NEXTISO ");
  68801. + }
  68802. + break;
  68803. +
  68804. + case FIQ_PER_CSPLIT_NYET1:
  68805. + /* First CSPLIT attempt was a NYET. If we get a subsequent NYET,
  68806. + * we are too late and the TT has dropped its CSPLIT fifo.
  68807. + */
  68808. + hfnum.d32 = FIQ_READ(state->dwc_regs_base + HFNUM);
  68809. + hcchar.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR);
  68810. + start_next_periodic = 1;
  68811. + if (hcint.b.nak) {
  68812. + st->fsm = FIQ_PER_SPLIT_DONE;
  68813. + } else if (hcint.b.xfercomp) {
  68814. + fiq_increment_dma_buf(state, num_channels, n);
  68815. + st->fsm = FIQ_PER_CSPLIT_POLL;
  68816. + st->nr_errors = 0;
  68817. + if (fiq_fsm_more_csplits(state, n, &last_csplit)) {
  68818. + handled = 1;
  68819. + restart = 1;
  68820. + if (!last_csplit)
  68821. + start_next_periodic = 0;
  68822. + } else {
  68823. + st->fsm = FIQ_PER_SPLIT_DONE;
  68824. + }
  68825. + } else if (hcint.b.nyet) {
  68826. + /* Doh. Data lost. */
  68827. + st->fsm = FIQ_PER_SPLIT_NYET_ABORTED;
  68828. + } else {
  68829. + st->fsm = FIQ_PER_SPLIT_HS_ABORTED;
  68830. + }
  68831. + break;
  68832. +
  68833. + case FIQ_PER_CSPLIT_BROKEN_NYET1:
  68834. + /*
  68835. + * we got here because our host channel is in the delayed-interrupt
  68836. + * state and we cannot take a NYET interrupt any later than when it
  68837. + * occurred. Disable then re-enable the channel if this happens to force
  68838. + * CSPLITs to occur at the right time.
  68839. + */
  68840. + hfnum.d32 = FIQ_READ(state->dwc_regs_base + HFNUM);
  68841. + hcchar.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR);
  68842. + fiq_print(FIQDBG_INT, state, "BROK: %01d ", n);
  68843. + if (hcint.b.nak) {
  68844. + st->fsm = FIQ_PER_SPLIT_DONE;
  68845. + start_next_periodic = 1;
  68846. + } else if (hcint.b.xfercomp) {
  68847. + fiq_increment_dma_buf(state, num_channels, n);
  68848. + if (fiq_fsm_more_csplits(state, n, &last_csplit)) {
  68849. + st->fsm = FIQ_PER_CSPLIT_POLL;
  68850. + handled = 1;
  68851. + restart = 1;
  68852. + start_next_periodic = 1;
  68853. + /* Reload HCTSIZ for the next transfer */
  68854. + fiq_fsm_reload_hctsiz(state, n);
  68855. + if (!last_csplit)
  68856. + start_next_periodic = 0;
  68857. + } else {
  68858. + st->fsm = FIQ_PER_SPLIT_DONE;
  68859. + }
  68860. + } else if (hcint.b.nyet) {
  68861. + st->fsm = FIQ_PER_SPLIT_NYET_ABORTED;
  68862. + start_next_periodic = 1;
  68863. + } else if (hcint.b.xacterr) {
  68864. + /* Local 3-strikes retry is handled by the core. This is a ERR response.*/
  68865. + st->fsm = FIQ_PER_SPLIT_LS_ABORTED;
  68866. + } else {
  68867. + fiq_print(FIQDBG_INT, state, "TOGGLES");
  68868. + BUG();
  68869. + }
  68870. + break;
  68871. +
  68872. + case FIQ_PER_CSPLIT_POLL:
  68873. + hfnum.d32 = FIQ_READ(state->dwc_regs_base + HFNUM);
  68874. + hcchar.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR);
  68875. + start_next_periodic = 1;
  68876. + if (hcint.b.nak) {
  68877. + st->fsm = FIQ_PER_SPLIT_DONE;
  68878. + } else if (hcint.b.xfercomp) {
  68879. + fiq_increment_dma_buf(state, num_channels, n);
  68880. + if (fiq_fsm_more_csplits(state, n, &last_csplit)) {
  68881. + handled = 1;
  68882. + restart = 1;
  68883. + /* Reload HCTSIZ for the next transfer */
  68884. + fiq_fsm_reload_hctsiz(state, n);
  68885. + if (!last_csplit)
  68886. + start_next_periodic = 0;
  68887. + } else {
  68888. + st->fsm = FIQ_PER_SPLIT_DONE;
  68889. + }
  68890. + } else if (hcint.b.nyet) {
  68891. + /* Are we a NYET after the first data packet? */
  68892. + if (st->nrpackets == 0) {
  68893. + st->fsm = FIQ_PER_CSPLIT_NYET1;
  68894. + handled = 1;
  68895. + restart = 1;
  68896. + } else {
  68897. + /* We got a NYET when polling CSPLITs. Can happen
  68898. + * if our heuristic fails, or if someone disables us
  68899. + * for any significant length of time.
  68900. + */
  68901. + if (st->nr_errors >= 3) {
  68902. + st->fsm = FIQ_PER_SPLIT_NYET_ABORTED;
  68903. + } else {
  68904. + st->fsm = FIQ_PER_SPLIT_DONE;
  68905. + }
  68906. + }
  68907. + } else if (hcint.b.xacterr) {
  68908. + /* Local 3-strikes retry is handled by the core. This is a ERR response.*/
  68909. + st->fsm = FIQ_PER_SPLIT_LS_ABORTED;
  68910. + } else if (hcint.b.datatglerr) {
  68911. + fiq_print(FIQDBG_INT, state, "TOGGLES");
  68912. + BUG();
  68913. + } else {
  68914. + st->fsm = FIQ_PER_SPLIT_HS_ABORTED;
  68915. + }
  68916. + break;
  68917. +
  68918. + case FIQ_HS_ISOC_TURBO:
  68919. + if (fiq_fsm_update_hs_isoc(state, n, hcint)) {
  68920. + /* more transactions to come */
  68921. + handled = 1;
  68922. + restart = 1;
  68923. + fiq_print(FIQDBG_INT, state, "HSISO M ");
  68924. + } else {
  68925. + st->fsm = FIQ_HS_ISOC_DONE;
  68926. + fiq_print(FIQDBG_INT, state, "HSISO F ");
  68927. + }
  68928. + break;
  68929. +
  68930. + case FIQ_HS_ISOC_ABORTED:
  68931. + /* This abort is called by the driver rewriting the state mid-transaction
  68932. + * which allows the dequeue mechanism to work more effectively.
  68933. + */
  68934. + break;
  68935. +
  68936. + case FIQ_PER_ISO_OUT_ACTIVE:
  68937. + if (hcint.b.ack) {
  68938. + if(fiq_iso_out_advance(state, num_channels, n)) {
  68939. + /* last OUT transfer */
  68940. + st->fsm = FIQ_PER_ISO_OUT_LAST;
  68941. + /*
  68942. + * Assuming the periodic FIFO in the dwc core
  68943. + * actually does its job properly, we can queue
  68944. + * the next ssplit now and in theory, the wire
  68945. + * transactions will be in-order.
  68946. + */
  68947. + // No it doesn't. It appears to process requests in host channel order.
  68948. + //start_next_periodic = 1;
  68949. + }
  68950. + handled = 1;
  68951. + restart = 1;
  68952. + } else {
  68953. + /*
  68954. + * Isochronous transactions carry on regardless. Log the error
  68955. + * and continue.
  68956. + */
  68957. + //explode += 1;
  68958. + st->nr_errors++;
  68959. + if(fiq_iso_out_advance(state, num_channels, n)) {
  68960. + st->fsm = FIQ_PER_ISO_OUT_LAST;
  68961. + //start_next_periodic = 1;
  68962. + }
  68963. + handled = 1;
  68964. + restart = 1;
  68965. + }
  68966. + break;
  68967. +
  68968. + case FIQ_PER_ISO_OUT_LAST:
  68969. + if (hcint.b.ack) {
  68970. + /* All done here */
  68971. + st->fsm = FIQ_PER_ISO_OUT_DONE;
  68972. + } else {
  68973. + st->fsm = FIQ_PER_ISO_OUT_DONE;
  68974. + st->nr_errors++;
  68975. + }
  68976. + start_next_periodic = 1;
  68977. + break;
  68978. +
  68979. + case FIQ_PER_SPLIT_TIMEOUT:
  68980. + /* SOF kicked us because we overran. */
  68981. + start_next_periodic = 1;
  68982. + break;
  68983. +
  68984. + default:
  68985. + break;
  68986. + }
  68987. +
  68988. + if (handled) {
  68989. + FIQ_WRITE(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCINT, hcint.d32);
  68990. + } else {
  68991. + /* Copy the regs into the state so the IRQ knows what to do */
  68992. + st->hcint_copy.d32 = hcint.d32;
  68993. + }
  68994. +
  68995. + if (restart) {
  68996. + /* Restart always implies handled. */
  68997. + if (restart == 2) {
  68998. + /* For complete-split INs, the show must go on.
  68999. + * Force a channel restart */
  69000. + fiq_fsm_restart_channel(state, n, 1);
  69001. + } else {
  69002. + fiq_fsm_restart_channel(state, n, 0);
  69003. + }
  69004. + }
  69005. + if (start_next_periodic) {
  69006. + fiq_fsm_start_next_periodic(state, num_channels);
  69007. + }
  69008. + if (st->fsm != FIQ_PASSTHROUGH)
  69009. + fiq_print(FIQDBG_INT, state, "FSMOUT%02d", st->fsm);
  69010. +
  69011. + return handled;
  69012. +}
  69013. +
  69014. +
  69015. +/**
  69016. + * dwc_otg_fiq_fsm() - Flying State Machine (monster) FIQ
  69017. + * @state: pointer to state struct passed from the banked FIQ mode registers.
  69018. + * @num_channels: set according to the DWC hardware configuration
  69019. + * @dma: pointer to DMA bounce buffers for split transaction slots
  69020. + *
  69021. + * The FSM FIQ performs the low-level tasks that normally would be performed by the microcode
  69022. + * inside an EHCI or similar host controller regarding split transactions. The DWC core
  69023. + * interrupts each and every time a split transaction packet is received or sent successfully.
  69024. + * This results in either an interrupt storm when everything is working "properly", or
  69025. + * the interrupt latency of the system in general breaks time-sensitive periodic split
  69026. + * transactions. Pushing the low-level, but relatively easy state machine work into the FIQ
  69027. + * solves these problems.
  69028. + *
  69029. + * Return: void
  69030. + */
  69031. +void notrace dwc_otg_fiq_fsm(struct fiq_state *state, int num_channels)
  69032. +{
  69033. + gintsts_data_t gintsts, gintsts_handled;
  69034. + gintmsk_data_t gintmsk;
  69035. + //hfnum_data_t hfnum;
  69036. + haint_data_t haint, haint_handled;
  69037. + haintmsk_data_t haintmsk;
  69038. + int kick_irq = 0;
  69039. +
  69040. + gintsts_handled.d32 = 0;
  69041. + haint_handled.d32 = 0;
  69042. +
  69043. + gintsts.d32 = FIQ_READ(state->dwc_regs_base + GINTSTS);
  69044. + gintmsk.d32 = FIQ_READ(state->dwc_regs_base + GINTMSK);
  69045. + gintsts.d32 &= gintmsk.d32;
  69046. +
  69047. + if (gintsts.b.sofintr) {
  69048. + /* For FSM mode, SOF is required to keep the state machine advance for
  69049. + * certain stages of the periodic pipeline. It's death to mask this
  69050. + * interrupt in that case.
  69051. + */
  69052. +
  69053. + if (!fiq_fsm_do_sof(state, num_channels)) {
  69054. + /* Kick IRQ once. Queue advancement means that all pending transactions
  69055. + * will get serviced when the IRQ finally executes.
  69056. + */
  69057. + if (state->gintmsk_saved.b.sofintr == 1)
  69058. + kick_irq |= 1;
  69059. + state->gintmsk_saved.b.sofintr = 0;
  69060. + }
  69061. + gintsts_handled.b.sofintr = 1;
  69062. + }
  69063. +
  69064. + if (gintsts.b.hcintr) {
  69065. + int i;
  69066. + haint.d32 = FIQ_READ(state->dwc_regs_base + HAINT);
  69067. + haintmsk.d32 = FIQ_READ(state->dwc_regs_base + HAINTMSK);
  69068. + haint.d32 &= haintmsk.d32;
  69069. + haint_handled.d32 = 0;
  69070. + for (i=0; i<num_channels; i++) {
  69071. + if (haint.b2.chint & (1 << i)) {
  69072. + if(!fiq_fsm_do_hcintr(state, num_channels, i)) {
  69073. + /* HCINT was not handled in FIQ
  69074. + * HAINT is level-sensitive, leading to level-sensitive ginststs.b.hcint bit.
  69075. + * Mask HAINT(i) but keep top-level hcint unmasked.
  69076. + */
  69077. + state->haintmsk_saved.b2.chint &= ~(1 << i);
  69078. + } else {
  69079. + /* do_hcintr cleaned up after itself, but clear haint */
  69080. + haint_handled.b2.chint |= (1 << i);
  69081. + }
  69082. + }
  69083. + }
  69084. +
  69085. + if (haint_handled.b2.chint) {
  69086. + FIQ_WRITE(state->dwc_regs_base + HAINT, haint_handled.d32);
  69087. + }
  69088. +
  69089. + if (haintmsk.d32 != (haintmsk.d32 & state->haintmsk_saved.d32)) {
  69090. + /*
  69091. + * This is necessary to avoid multiple retriggers of the MPHI in the case
  69092. + * where interrupts are held off and HCINTs start to pile up.
  69093. + * Only wake up the IRQ if a new interrupt came in, was not handled and was
  69094. + * masked.
  69095. + */
  69096. + haintmsk.d32 &= state->haintmsk_saved.d32;
  69097. + FIQ_WRITE(state->dwc_regs_base + HAINTMSK, haintmsk.d32);
  69098. + kick_irq |= 1;
  69099. + }
  69100. + /* Top-Level interrupt - always handled because it's level-sensitive */
  69101. + gintsts_handled.b.hcintr = 1;
  69102. + }
  69103. +
  69104. +
  69105. + /* Clear the bits in the saved register that were not handled but were triggered. */
  69106. + state->gintmsk_saved.d32 &= ~(gintsts.d32 & ~gintsts_handled.d32);
  69107. +
  69108. + /* FIQ didn't handle something - mask has changed - write new mask */
  69109. + if (gintmsk.d32 != (gintmsk.d32 & state->gintmsk_saved.d32)) {
  69110. + gintmsk.d32 &= state->gintmsk_saved.d32;
  69111. + gintmsk.b.sofintr = 1;
  69112. + FIQ_WRITE(state->dwc_regs_base + GINTMSK, gintmsk.d32);
  69113. +// fiq_print(FIQDBG_INT, state, "KICKGINT");
  69114. +// fiq_print(FIQDBG_INT, state, "%08x", gintmsk.d32);
  69115. +// fiq_print(FIQDBG_INT, state, "%08x", state->gintmsk_saved.d32);
  69116. + kick_irq |= 1;
  69117. + }
  69118. +
  69119. + if (gintsts_handled.d32) {
  69120. + /* Only applies to edge-sensitive bits in GINTSTS */
  69121. + FIQ_WRITE(state->dwc_regs_base + GINTSTS, gintsts_handled.d32);
  69122. + }
  69123. +
  69124. + /* We got an interrupt, didn't handle it. */
  69125. + if (kick_irq) {
  69126. + state->mphi_int_count++;
  69127. + FIQ_WRITE(state->mphi_regs.outdda, (int) state->dummy_send);
  69128. + FIQ_WRITE(state->mphi_regs.outddb, (1<<29));
  69129. +
  69130. + }
  69131. + state->fiq_done++;
  69132. + mb();
  69133. +}
  69134. +
  69135. +
  69136. +/**
  69137. + * dwc_otg_fiq_nop() - FIQ "lite"
  69138. + * @state: pointer to state struct passed from the banked FIQ mode registers.
  69139. + *
  69140. + * The "nop" handler does not intervene on any interrupts other than SOF.
  69141. + * It is limited in scope to deciding at each SOF if the IRQ SOF handler (which deals
  69142. + * with non-periodic/periodic queues) needs to be kicked.
  69143. + *
  69144. + * This is done to hold off the SOF interrupt, which occurs at a rate of 8000 per second.
  69145. + *
  69146. + * Return: void
  69147. + */
  69148. +void notrace dwc_otg_fiq_nop(struct fiq_state *state)
  69149. +{
  69150. + gintsts_data_t gintsts, gintsts_handled;
  69151. + gintmsk_data_t gintmsk;
  69152. + hfnum_data_t hfnum;
  69153. +
  69154. + hfnum.d32 = FIQ_READ(state->dwc_regs_base + HFNUM);
  69155. + gintsts.d32 = FIQ_READ(state->dwc_regs_base + GINTSTS);
  69156. + gintmsk.d32 = FIQ_READ(state->dwc_regs_base + GINTMSK);
  69157. + gintsts.d32 &= gintmsk.d32;
  69158. + gintsts_handled.d32 = 0;
  69159. +
  69160. + if (gintsts.b.sofintr) {
  69161. + if (!state->kick_np_queues &&
  69162. + dwc_frame_num_gt(state->next_sched_frame, hfnum.b.frnum)) {
  69163. + /* SOF handled, no work to do, just ACK interrupt */
  69164. + gintsts_handled.b.sofintr = 1;
  69165. + } else {
  69166. + /* Kick IRQ */
  69167. + state->gintmsk_saved.b.sofintr = 0;
  69168. + }
  69169. + }
  69170. +
  69171. + /* Reset handled interrupts */
  69172. + if(gintsts_handled.d32) {
  69173. + FIQ_WRITE(state->dwc_regs_base + GINTSTS, gintsts_handled.d32);
  69174. + }
  69175. +
  69176. + /* Clear the bits in the saved register that were not handled but were triggered. */
  69177. + state->gintmsk_saved.d32 &= ~(gintsts.d32 & ~gintsts_handled.d32);
  69178. +
  69179. + /* We got an interrupt, didn't handle it and want to mask it */
  69180. + if (~(state->gintmsk_saved.d32)) {
  69181. + state->mphi_int_count++;
  69182. + gintmsk.d32 &= state->gintmsk_saved.d32;
  69183. + FIQ_WRITE(state->dwc_regs_base + GINTMSK, gintmsk.d32);
  69184. + /* Force a clear before another dummy send */
  69185. + FIQ_WRITE(state->mphi_regs.intstat, (1<<29));
  69186. + FIQ_WRITE(state->mphi_regs.outdda, (int) state->dummy_send);
  69187. + FIQ_WRITE(state->mphi_regs.outddb, (1<<29));
  69188. +
  69189. + }
  69190. + state->fiq_done++;
  69191. + mb();
  69192. +}
  69193. diff -Nur linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.h
  69194. --- linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.h 1970-01-01 01:00:00.000000000 +0100
  69195. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.h 2014-04-24 15:37:13.310990489 +0200
  69196. @@ -0,0 +1,349 @@
  69197. +/*
  69198. + * dwc_otg_fiq_fsm.h - Finite state machine FIQ header definitions
  69199. + *
  69200. + * Copyright (c) 2013 Raspberry Pi Foundation
  69201. + *
  69202. + * Author: Jonathan Bell <jonathan@raspberrypi.org>
  69203. + * All rights reserved.
  69204. + *
  69205. + * Redistribution and use in source and binary forms, with or without
  69206. + * modification, are permitted provided that the following conditions are met:
  69207. + * * Redistributions of source code must retain the above copyright
  69208. + * notice, this list of conditions and the following disclaimer.
  69209. + * * Redistributions in binary form must reproduce the above copyright
  69210. + * notice, this list of conditions and the following disclaimer in the
  69211. + * documentation and/or other materials provided with the distribution.
  69212. + * * Neither the name of Raspberry Pi nor the
  69213. + * names of its contributors may be used to endorse or promote products
  69214. + * derived from this software without specific prior written permission.
  69215. + *
  69216. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  69217. + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  69218. + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  69219. + * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  69220. + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  69221. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  69222. + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  69223. + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  69224. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  69225. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  69226. + *
  69227. + * This FIQ implements functionality that performs split transactions on
  69228. + * the dwc_otg hardware without any outside intervention. A split transaction
  69229. + * is "queued" by nominating a specific host channel to perform the entirety
  69230. + * of a split transaction. This FIQ will then perform the microframe-precise
  69231. + * scheduling required in each phase of the transaction until completion.
  69232. + *
  69233. + * The FIQ functionality has been surgically implanted into the Synopsys
  69234. + * vendor-provided driver.
  69235. + *
  69236. + */
  69237. +
  69238. +#ifndef DWC_OTG_FIQ_FSM_H_
  69239. +#define DWC_OTG_FIQ_FSM_H_
  69240. +
  69241. +#include "dwc_otg_regs.h"
  69242. +#include "dwc_otg_cil.h"
  69243. +#include "dwc_otg_hcd.h"
  69244. +#include <linux/kernel.h>
  69245. +#include <linux/irqflags.h>
  69246. +#include <linux/string.h>
  69247. +#include <asm/barrier.h>
  69248. +
  69249. +#if 0
  69250. +#define FLAME_ON(x) \
  69251. +do { \
  69252. + int gpioreg; \
  69253. + \
  69254. + gpioreg = readl(__io_address(0x20200000+0x8)); \
  69255. + gpioreg &= ~(7 << (x-20)*3); \
  69256. + gpioreg |= 0x1 << (x-20)*3; \
  69257. + writel(gpioreg, __io_address(0x20200000+0x8)); \
  69258. + \
  69259. + writel(1<<x, __io_address(0x20200000+(0x1C))); \
  69260. +} while (0)
  69261. +
  69262. +#define FLAME_OFF(x) \
  69263. +do { \
  69264. + writel(1<<x, __io_address(0x20200000+(0x28))); \
  69265. +} while (0)
  69266. +#else
  69267. +#define FLAME_ON(x) do { } while (0)
  69268. +#define FLAME_OFF(X) do { } while (0)
  69269. +#endif
  69270. +
  69271. +/* This is a quick-and-dirty arch-specific register read/write. We know that
  69272. + * writes to a peripheral on BCM2835 will always arrive in-order, also that
  69273. + * reads and writes are executed in-order therefore the need for memory barriers
  69274. + * is obviated if we're only talking to USB.
  69275. + */
  69276. +#define FIQ_WRITE(_addr_,_data_) (*(volatile unsigned int *) (_addr_) = (_data_))
  69277. +#define FIQ_READ(_addr_) (*(volatile unsigned int *) (_addr_))
  69278. +
  69279. +/* FIQ-ified register definitions. Offsets are from dwc_regs_base. */
  69280. +#define GINTSTS 0x014
  69281. +#define GINTMSK 0x018
  69282. +/* Debug register. Poll the top of the received packets FIFO. */
  69283. +#define GRXSTSR 0x01C
  69284. +#define HFNUM 0x408
  69285. +#define HAINT 0x414
  69286. +#define HAINTMSK 0x418
  69287. +#define HPRT0 0x440
  69288. +
  69289. +/* HC_regs start from an offset of 0x500 */
  69290. +#define HC_START 0x500
  69291. +#define HC_OFFSET 0x020
  69292. +
  69293. +#define HC_DMA 0x514
  69294. +
  69295. +#define HCCHAR 0x00
  69296. +#define HCSPLT 0x04
  69297. +#define HCINT 0x08
  69298. +#define HCINTMSK 0x0C
  69299. +#define HCTSIZ 0x10
  69300. +
  69301. +#define ISOC_XACTPOS_ALL 0b11
  69302. +#define ISOC_XACTPOS_BEGIN 0b10
  69303. +#define ISOC_XACTPOS_MID 0b00
  69304. +#define ISOC_XACTPOS_END 0b01
  69305. +
  69306. +#define DWC_PID_DATA2 0b01
  69307. +#define DWC_PID_MDATA 0b11
  69308. +#define DWC_PID_DATA1 0b10
  69309. +#define DWC_PID_DATA0 0b00
  69310. +
  69311. +typedef struct {
  69312. + volatile void* base;
  69313. + volatile void* ctrl;
  69314. + volatile void* outdda;
  69315. + volatile void* outddb;
  69316. + volatile void* intstat;
  69317. +} mphi_regs_t;
  69318. +
  69319. +
  69320. +enum fiq_debug_level {
  69321. + FIQDBG_SCHED = (1 << 0),
  69322. + FIQDBG_INT = (1 << 1),
  69323. + FIQDBG_ERR = (1 << 2),
  69324. + FIQDBG_PORTHUB = (1 << 3),
  69325. +};
  69326. +
  69327. +struct fiq_state;
  69328. +
  69329. +extern void _fiq_print (enum fiq_debug_level dbg_lvl, volatile struct fiq_state *state, char *fmt, ...);
  69330. +#if 0
  69331. +#define fiq_print _fiq_print
  69332. +#else
  69333. +#define fiq_print(x, y, ...)
  69334. +#endif
  69335. +
  69336. +extern bool fiq_enable, fiq_fsm_enable;
  69337. +extern ushort nak_holdoff;
  69338. +
  69339. +/**
  69340. + * enum fiq_fsm_state - The FIQ FSM states.
  69341. + *
  69342. + * This is the "core" of the FIQ FSM. Broadly, the FSM states follow the
  69343. + * USB2.0 specification for host responses to various transaction states.
  69344. + * There are modifications to this host state machine because of a variety of
  69345. + * quirks and limitations in the dwc_otg hardware.
  69346. + *
  69347. + * The fsm state is also used to communicate back to the driver on completion of
  69348. + * a split transaction. The end states are used in conjunction with the interrupts
  69349. + * raised by the final transaction.
  69350. + */
  69351. +enum fiq_fsm_state {
  69352. + /* FIQ isn't enabled for this host channel */
  69353. + FIQ_PASSTHROUGH = 0,
  69354. +
  69355. + /* Nonperiodic state groups */
  69356. + FIQ_NP_SSPLIT_STARTED = 1,
  69357. + FIQ_NP_SSPLIT_RETRY = 2,
  69358. + FIQ_NP_OUT_CSPLIT_RETRY = 3,
  69359. + FIQ_NP_IN_CSPLIT_RETRY = 4,
  69360. + FIQ_NP_SPLIT_DONE = 5,
  69361. + FIQ_NP_SPLIT_LS_ABORTED = 6,
  69362. + /* This differentiates a HS transaction error from a LS one
  69363. + * (handling the hub state is different) */
  69364. + FIQ_NP_SPLIT_HS_ABORTED = 7,
  69365. +
  69366. + /* Periodic state groups */
  69367. + /* Periodic transactions are either started directly by the IRQ handler
  69368. + * or deferred if the TT is already in use.
  69369. + */
  69370. + FIQ_PER_SSPLIT_QUEUED = 8,
  69371. + FIQ_PER_SSPLIT_STARTED = 9,
  69372. + FIQ_PER_SSPLIT_LAST = 10,
  69373. +
  69374. +
  69375. + FIQ_PER_ISO_OUT_PENDING = 11,
  69376. + FIQ_PER_ISO_OUT_ACTIVE = 12,
  69377. + FIQ_PER_ISO_OUT_LAST = 13,
  69378. + FIQ_PER_ISO_OUT_DONE = 27,
  69379. +
  69380. + FIQ_PER_CSPLIT_WAIT = 14,
  69381. + FIQ_PER_CSPLIT_NYET1 = 15,
  69382. + FIQ_PER_CSPLIT_BROKEN_NYET1 = 28,
  69383. + FIQ_PER_CSPLIT_NYET_FAFF = 29,
  69384. + /* For multiple CSPLITs (large isoc IN, or delayed interrupt) */
  69385. + FIQ_PER_CSPLIT_POLL = 16,
  69386. + /* The last CSPLIT for a transaction has been issued, differentiates
  69387. + * for the state machine to queue the next packet.
  69388. + */
  69389. + FIQ_PER_CSPLIT_LAST = 17,
  69390. +
  69391. + FIQ_PER_SPLIT_DONE = 18,
  69392. + FIQ_PER_SPLIT_LS_ABORTED = 19,
  69393. + FIQ_PER_SPLIT_HS_ABORTED = 20,
  69394. + FIQ_PER_SPLIT_NYET_ABORTED = 21,
  69395. + /* Frame rollover has occurred without the transaction finishing. */
  69396. + FIQ_PER_SPLIT_TIMEOUT = 22,
  69397. +
  69398. + /* FIQ-accelerated HS Isochronous state groups */
  69399. + FIQ_HS_ISOC_TURBO = 23,
  69400. + /* For interval > 1, SOF wakes up the isochronous FSM */
  69401. + FIQ_HS_ISOC_SLEEPING = 24,
  69402. + FIQ_HS_ISOC_DONE = 25,
  69403. + FIQ_HS_ISOC_ABORTED = 26,
  69404. + FIQ_DEQUEUE_ISSUED = 30,
  69405. + FIQ_TEST = 32,
  69406. +};
  69407. +
  69408. +struct fiq_stack {
  69409. + int magic1;
  69410. + uint8_t stack[2048];
  69411. + int magic2;
  69412. +};
  69413. +
  69414. +
  69415. +/**
  69416. + * struct fiq_dma_info - DMA bounce buffer utilisation information (per-channel)
  69417. + * @index: Number of slots reported used for IN transactions / number of slots
  69418. + * transmitted for an OUT transaction
  69419. + * @slot_len[6]: Number of actual transfer bytes in each slot (255 if unused)
  69420. + *
  69421. + * Split transaction transfers can have variable length depending on other bus
  69422. + * traffic. The OTG core DMA engine requires 4-byte aligned addresses therefore
  69423. + * each transaction needs a guaranteed aligned address. A maximum of 6 split transfers
  69424. + * can happen per-frame.
  69425. + */
  69426. +struct fiq_dma_info {
  69427. + u8 index;
  69428. + u8 slot_len[6];
  69429. +};
  69430. +
  69431. +struct __attribute__((packed)) fiq_split_dma_slot {
  69432. + u8 buf[188];
  69433. +};
  69434. +
  69435. +struct fiq_dma_channel {
  69436. + struct __attribute__((packed)) fiq_split_dma_slot index[6];
  69437. +};
  69438. +
  69439. +struct fiq_dma_blob {
  69440. + struct __attribute__((packed)) fiq_dma_channel channel[0];
  69441. +};
  69442. +
  69443. +/**
  69444. + * struct fiq_hs_isoc_info - USB2.0 isochronous data
  69445. + * @iso_frame: Pointer to the array of OTG URB iso_frame_descs.
  69446. + * @nrframes: Total length of iso_frame_desc array
  69447. + * @index: Current index (FIQ-maintained)
  69448. + *
  69449. + */
  69450. +struct fiq_hs_isoc_info {
  69451. + struct dwc_otg_hcd_iso_packet_desc *iso_desc;
  69452. + unsigned int nrframes;
  69453. + unsigned int index;
  69454. +};
  69455. +
  69456. +/**
  69457. + * struct fiq_channel_state - FIQ state machine storage
  69458. + * @fsm: Current state of the channel as understood by the FIQ
  69459. + * @nr_errors: Number of transaction errors on this split-transaction
  69460. + * @hub_addr: SSPLIT/CSPLIT destination hub
  69461. + * @port_addr: SSPLIT/CSPLIT destination port - always 1 if single TT hub
  69462. + * @nrpackets: For isoc OUT, the number of split-OUT packets to transmit. For
  69463. + * split-IN, number of CSPLIT data packets that were received.
  69464. + * @hcchar_copy:
  69465. + * @hcsplt_copy:
  69466. + * @hcintmsk_copy:
  69467. + * @hctsiz_copy: Copies of the host channel registers.
  69468. + * For use as scratch, or for returning state.
  69469. + *
  69470. + * The fiq_channel_state is state storage between interrupts for a host channel. The
  69471. + * FSM state is stored here. Members of this structure must only be set up by the
  69472. + * driver prior to enabling the FIQ for this host channel, and not touched until the FIQ
  69473. + * has updated the state to either a COMPLETE state group or ABORT state group.
  69474. + */
  69475. +
  69476. +struct fiq_channel_state {
  69477. + enum fiq_fsm_state fsm;
  69478. + unsigned int nr_errors;
  69479. + unsigned int hub_addr;
  69480. + unsigned int port_addr;
  69481. + /* Hardware bug workaround: sometimes channel halt interrupts are
  69482. + * delayed until the next SOF. Keep track of when we expected to get interrupted. */
  69483. + unsigned int expected_uframe;
  69484. + /* in/out for communicating number of dma buffers used, or number of ISOC to do */
  69485. + unsigned int nrpackets;
  69486. + struct fiq_dma_info dma_info;
  69487. + struct fiq_hs_isoc_info hs_isoc_info;
  69488. + /* Copies of HC registers - in/out communication from/to IRQ handler
  69489. + * and for ease of channel setup. A bit of mungeing is performed - for
  69490. + * example the hctsiz.b.maxp is _always_ the max packet size of the endpoint.
  69491. + */
  69492. + hcchar_data_t hcchar_copy;
  69493. + hcsplt_data_t hcsplt_copy;
  69494. + hcint_data_t hcint_copy;
  69495. + hcintmsk_data_t hcintmsk_copy;
  69496. + hctsiz_data_t hctsiz_copy;
  69497. + hcdma_data_t hcdma_copy;
  69498. +};
  69499. +
  69500. +/**
  69501. + * struct fiq_state - top-level FIQ state machine storage
  69502. + * @mphi_regs: virtual address of the MPHI peripheral register file
  69503. + * @dwc_regs_base: virtual address of the base of the DWC core register file
  69504. + * @dma_base: physical address for the base of the DMA bounce buffers
  69505. + * @dummy_send: Scratch area for sending a fake message to the MPHI peripheral
  69506. + * @gintmsk_saved: Top-level mask of interrupts that the FIQ has not handled.
  69507. + * Used for determining which interrupts fired to set off the IRQ handler.
  69508. + * @haintmsk_saved: Mask of interrupts from host channels that the FIQ did not handle internally.
  69509. + * @np_count: Non-periodic transactions in the active queue
  69510. + * @np_sent: Count of non-periodic transactions that have completed
  69511. + * @next_sched_frame: For periodic transactions handled by the driver's SOF-driven queuing mechanism,
  69512. + * this is the next frame on which a SOF interrupt is required. Used to hold off
  69513. + * passing SOF through to the driver until necessary.
  69514. + * @channel[n]: Per-channel FIQ state. Allocated during init depending on the number of host
  69515. + * channels configured into the core logic.
  69516. + *
  69517. + * This is passed as the first argument to the dwc_otg_fiq_fsm top-level FIQ handler from the asm stub.
  69518. + * It contains top-level state information.
  69519. + */
  69520. +struct fiq_state {
  69521. + mphi_regs_t mphi_regs;
  69522. + void *dwc_regs_base;
  69523. + dma_addr_t dma_base;
  69524. + struct fiq_dma_blob *fiq_dmab;
  69525. + void *dummy_send;
  69526. + gintmsk_data_t gintmsk_saved;
  69527. + haintmsk_data_t haintmsk_saved;
  69528. + int mphi_int_count;
  69529. + unsigned int fiq_done;
  69530. + unsigned int kick_np_queues;
  69531. + unsigned int next_sched_frame;
  69532. +#ifdef FIQ_DEBUG
  69533. + char * buffer;
  69534. + unsigned int bufsiz;
  69535. +#endif
  69536. + struct fiq_channel_state channel[0];
  69537. +};
  69538. +
  69539. +extern int fiq_fsm_tt_in_use(struct fiq_state *st, int num_channels, int n);
  69540. +
  69541. +extern void dwc_otg_fiq_fsm(struct fiq_state *state, int num_channels);
  69542. +
  69543. +extern void dwc_otg_fiq_nop(struct fiq_state *state);
  69544. +
  69545. +#endif /* DWC_OTG_FIQ_FSM_H_ */
  69546. diff -Nur linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_fiq_stub.S linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_fiq_stub.S
  69547. --- linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_fiq_stub.S 1970-01-01 01:00:00.000000000 +0100
  69548. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_fiq_stub.S 2014-04-24 15:37:13.310990489 +0200
  69549. @@ -0,0 +1,81 @@
  69550. +/*
  69551. + * dwc_otg_fiq_fsm.S - assembly stub for the FSM FIQ
  69552. + *
  69553. + * Copyright (c) 2013 Raspberry Pi Foundation
  69554. + *
  69555. + * Author: Jonathan Bell <jonathan@raspberrypi.org>
  69556. + * All rights reserved.
  69557. + *
  69558. + * Redistribution and use in source and binary forms, with or without
  69559. + * modification, are permitted provided that the following conditions are met:
  69560. + * * Redistributions of source code must retain the above copyright
  69561. + * notice, this list of conditions and the following disclaimer.
  69562. + * * Redistributions in binary form must reproduce the above copyright
  69563. + * notice, this list of conditions and the following disclaimer in the
  69564. + * documentation and/or other materials provided with the distribution.
  69565. + * * Neither the name of Raspberry Pi nor the
  69566. + * names of its contributors may be used to endorse or promote products
  69567. + * derived from this software without specific prior written permission.
  69568. + *
  69569. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  69570. + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  69571. + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  69572. + * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  69573. + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  69574. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  69575. + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  69576. + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  69577. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  69578. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  69579. + */
  69580. +
  69581. +
  69582. +#include <asm/assembler.h>
  69583. +#include <linux/linkage.h>
  69584. +
  69585. +
  69586. +.text
  69587. +
  69588. +.global _dwc_otg_fiq_stub_end;
  69589. +
  69590. +/**
  69591. + * _dwc_otg_fiq_stub() - entry copied to the FIQ vector page to allow
  69592. + * a C-style function call with arguments from the FIQ banked registers.
  69593. + * r0 = &hcd->fiq_state
  69594. + * r1 = &hcd->num_channels
  69595. + * r2 = &hcd->dma_buffers
  69596. + * Tramples: r0, r1, r2, r4, fp, ip
  69597. + */
  69598. +
  69599. +ENTRY(_dwc_otg_fiq_stub)
  69600. + /* Stash unbanked regs - SP will have been set up for us */
  69601. + mov ip, sp;
  69602. + stmdb sp!, {r0-r12, lr};
  69603. +#ifdef FIQ_DEBUG
  69604. + // Cycle profiling - read cycle counter at start
  69605. + mrc p15, 0, r5, c15, c12, 1;
  69606. +#endif
  69607. + /* r11 = fp, don't trample it */
  69608. + mov r4, fp;
  69609. + /* set EABI frame size */
  69610. + sub fp, ip, #512;
  69611. +
  69612. + /* for fiq NOP mode - just need state */
  69613. + mov r0, r8;
  69614. + /* r9 = num_channels */
  69615. + mov r1, r9;
  69616. + /* r10 = struct *dma_bufs */
  69617. +// mov r2, r10;
  69618. +
  69619. + /* r4 = &fiq_c_function */
  69620. + blx r4;
  69621. +#ifdef FIQ_DEBUG
  69622. + mrc p15, 0, r4, c15, c12, 1;
  69623. + subs r5, r5, r4;
  69624. + // r5 is now the cycle count time for executing the FIQ. Store it somewhere?
  69625. +#endif
  69626. + ldmia sp!, {r0-r12, lr};
  69627. + subs pc, lr, #4;
  69628. +_dwc_otg_fiq_stub_end:
  69629. +END(_dwc_otg_fiq_stub)
  69630. +
  69631. diff -Nur linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_hcd.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd.c
  69632. --- linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_hcd.c 1970-01-01 01:00:00.000000000 +0100
  69633. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd.c 2014-04-24 15:37:13.314990533 +0200
  69634. @@ -0,0 +1,4185 @@
  69635. +
  69636. +/* ==========================================================================
  69637. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd.c $
  69638. + * $Revision: #104 $
  69639. + * $Date: 2011/10/24 $
  69640. + * $Change: 1871159 $
  69641. + *
  69642. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  69643. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  69644. + * otherwise expressly agreed to in writing between Synopsys and you.
  69645. + *
  69646. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  69647. + * any End User Software License Agreement or Agreement for Licensed Product
  69648. + * with Synopsys or any supplement thereto. You are permitted to use and
  69649. + * redistribute this Software in source and binary forms, with or without
  69650. + * modification, provided that redistributions of source code must retain this
  69651. + * notice. You may not view, use, disclose, copy or distribute this file or
  69652. + * any information contained herein except pursuant to this license grant from
  69653. + * Synopsys. If you do not agree with this notice, including the disclaimer
  69654. + * below, then you are not authorized to use the Software.
  69655. + *
  69656. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  69657. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  69658. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  69659. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  69660. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  69661. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  69662. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  69663. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  69664. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  69665. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  69666. + * DAMAGE.
  69667. + * ========================================================================== */
  69668. +#ifndef DWC_DEVICE_ONLY
  69669. +
  69670. +/** @file
  69671. + * This file implements HCD Core. All code in this file is portable and doesn't
  69672. + * use any OS specific functions.
  69673. + * Interface provided by HCD Core is defined in <code><hcd_if.h></code>
  69674. + * header file.
  69675. + */
  69676. +
  69677. +#include <linux/usb.h>
  69678. +#include <linux/usb/hcd.h>
  69679. +
  69680. +#include "dwc_otg_hcd.h"
  69681. +#include "dwc_otg_regs.h"
  69682. +#include "dwc_otg_fiq_fsm.h"
  69683. +
  69684. +extern bool microframe_schedule;
  69685. +extern uint16_t fiq_fsm_mask, nak_holdoff;
  69686. +
  69687. +//#define DEBUG_HOST_CHANNELS
  69688. +#ifdef DEBUG_HOST_CHANNELS
  69689. +static int last_sel_trans_num_per_scheduled = 0;
  69690. +static int last_sel_trans_num_nonper_scheduled = 0;
  69691. +static int last_sel_trans_num_avail_hc_at_start = 0;
  69692. +static int last_sel_trans_num_avail_hc_at_end = 0;
  69693. +#endif /* DEBUG_HOST_CHANNELS */
  69694. +
  69695. +
  69696. +dwc_otg_hcd_t *dwc_otg_hcd_alloc_hcd(void)
  69697. +{
  69698. + return DWC_ALLOC(sizeof(dwc_otg_hcd_t));
  69699. +}
  69700. +
  69701. +/**
  69702. + * Connection timeout function. An OTG host is required to display a
  69703. + * message if the device does not connect within 10 seconds.
  69704. + */
  69705. +void dwc_otg_hcd_connect_timeout(void *ptr)
  69706. +{
  69707. + DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, ptr);
  69708. + DWC_PRINTF("Connect Timeout\n");
  69709. + __DWC_ERROR("Device Not Connected/Responding\n");
  69710. +}
  69711. +
  69712. +#if defined(DEBUG)
  69713. +static void dump_channel_info(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  69714. +{
  69715. + if (qh->channel != NULL) {
  69716. + dwc_hc_t *hc = qh->channel;
  69717. + dwc_list_link_t *item;
  69718. + dwc_otg_qh_t *qh_item;
  69719. + int num_channels = hcd->core_if->core_params->host_channels;
  69720. + int i;
  69721. +
  69722. + dwc_otg_hc_regs_t *hc_regs;
  69723. + hcchar_data_t hcchar;
  69724. + hcsplt_data_t hcsplt;
  69725. + hctsiz_data_t hctsiz;
  69726. + uint32_t hcdma;
  69727. +
  69728. + hc_regs = hcd->core_if->host_if->hc_regs[hc->hc_num];
  69729. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  69730. + hcsplt.d32 = DWC_READ_REG32(&hc_regs->hcsplt);
  69731. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  69732. + hcdma = DWC_READ_REG32(&hc_regs->hcdma);
  69733. +
  69734. + DWC_PRINTF(" Assigned to channel %p:\n", hc);
  69735. + DWC_PRINTF(" hcchar 0x%08x, hcsplt 0x%08x\n", hcchar.d32,
  69736. + hcsplt.d32);
  69737. + DWC_PRINTF(" hctsiz 0x%08x, hcdma 0x%08x\n", hctsiz.d32,
  69738. + hcdma);
  69739. + DWC_PRINTF(" dev_addr: %d, ep_num: %d, ep_is_in: %d\n",
  69740. + hc->dev_addr, hc->ep_num, hc->ep_is_in);
  69741. + DWC_PRINTF(" ep_type: %d\n", hc->ep_type);
  69742. + DWC_PRINTF(" max_packet: %d\n", hc->max_packet);
  69743. + DWC_PRINTF(" data_pid_start: %d\n", hc->data_pid_start);
  69744. + DWC_PRINTF(" xfer_started: %d\n", hc->xfer_started);
  69745. + DWC_PRINTF(" halt_status: %d\n", hc->halt_status);
  69746. + DWC_PRINTF(" xfer_buff: %p\n", hc->xfer_buff);
  69747. + DWC_PRINTF(" xfer_len: %d\n", hc->xfer_len);
  69748. + DWC_PRINTF(" qh: %p\n", hc->qh);
  69749. + DWC_PRINTF(" NP inactive sched:\n");
  69750. + DWC_LIST_FOREACH(item, &hcd->non_periodic_sched_inactive) {
  69751. + qh_item =
  69752. + DWC_LIST_ENTRY(item, dwc_otg_qh_t, qh_list_entry);
  69753. + DWC_PRINTF(" %p\n", qh_item);
  69754. + }
  69755. + DWC_PRINTF(" NP active sched:\n");
  69756. + DWC_LIST_FOREACH(item, &hcd->non_periodic_sched_active) {
  69757. + qh_item =
  69758. + DWC_LIST_ENTRY(item, dwc_otg_qh_t, qh_list_entry);
  69759. + DWC_PRINTF(" %p\n", qh_item);
  69760. + }
  69761. + DWC_PRINTF(" Channels: \n");
  69762. + for (i = 0; i < num_channels; i++) {
  69763. + dwc_hc_t *hc = hcd->hc_ptr_array[i];
  69764. + DWC_PRINTF(" %2d: %p\n", i, hc);
  69765. + }
  69766. + }
  69767. +}
  69768. +#else
  69769. +#define dump_channel_info(hcd, qh)
  69770. +#endif /* DEBUG */
  69771. +
  69772. +/**
  69773. + * Work queue function for starting the HCD when A-Cable is connected.
  69774. + * The hcd_start() must be called in a process context.
  69775. + */
  69776. +static void hcd_start_func(void *_vp)
  69777. +{
  69778. + dwc_otg_hcd_t *hcd = (dwc_otg_hcd_t *) _vp;
  69779. +
  69780. + DWC_DEBUGPL(DBG_HCDV, "%s() %p\n", __func__, hcd);
  69781. + if (hcd) {
  69782. + hcd->fops->start(hcd);
  69783. + }
  69784. +}
  69785. +
  69786. +static void del_xfer_timers(dwc_otg_hcd_t * hcd)
  69787. +{
  69788. +#ifdef DEBUG
  69789. + int i;
  69790. + int num_channels = hcd->core_if->core_params->host_channels;
  69791. + for (i = 0; i < num_channels; i++) {
  69792. + DWC_TIMER_CANCEL(hcd->core_if->hc_xfer_timer[i]);
  69793. + }
  69794. +#endif
  69795. +}
  69796. +
  69797. +static void del_timers(dwc_otg_hcd_t * hcd)
  69798. +{
  69799. + del_xfer_timers(hcd);
  69800. + DWC_TIMER_CANCEL(hcd->conn_timer);
  69801. +}
  69802. +
  69803. +/**
  69804. + * Processes all the URBs in a single list of QHs. Completes them with
  69805. + * -ESHUTDOWN and frees the QTD.
  69806. + */
  69807. +static void kill_urbs_in_qh_list(dwc_otg_hcd_t * hcd, dwc_list_link_t * qh_list)
  69808. +{
  69809. + dwc_list_link_t *qh_item, *qh_tmp;
  69810. + dwc_otg_qh_t *qh;
  69811. + dwc_otg_qtd_t *qtd, *qtd_tmp;
  69812. +
  69813. + DWC_LIST_FOREACH_SAFE(qh_item, qh_tmp, qh_list) {
  69814. + qh = DWC_LIST_ENTRY(qh_item, dwc_otg_qh_t, qh_list_entry);
  69815. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp,
  69816. + &qh->qtd_list, qtd_list_entry) {
  69817. + qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  69818. + if (qtd->urb != NULL) {
  69819. + hcd->fops->complete(hcd, qtd->urb->priv,
  69820. + qtd->urb, -DWC_E_SHUTDOWN);
  69821. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  69822. + }
  69823. +
  69824. + }
  69825. + if(qh->channel) {
  69826. + /* Using hcchar.chen == 1 is not a reliable test.
  69827. + * It is possible that the channel has already halted
  69828. + * but not yet been through the IRQ handler.
  69829. + */
  69830. + dwc_otg_hc_halt(hcd->core_if, qh->channel,
  69831. + DWC_OTG_HC_XFER_URB_DEQUEUE);
  69832. + if(microframe_schedule)
  69833. + hcd->available_host_channels++;
  69834. + qh->channel = NULL;
  69835. + }
  69836. + dwc_otg_hcd_qh_remove(hcd, qh);
  69837. + }
  69838. +}
  69839. +
  69840. +/**
  69841. + * Responds with an error status of ESHUTDOWN to all URBs in the non-periodic
  69842. + * and periodic schedules. The QTD associated with each URB is removed from
  69843. + * the schedule and freed. This function may be called when a disconnect is
  69844. + * detected or when the HCD is being stopped.
  69845. + */
  69846. +static void kill_all_urbs(dwc_otg_hcd_t * hcd)
  69847. +{
  69848. + kill_urbs_in_qh_list(hcd, &hcd->non_periodic_sched_inactive);
  69849. + kill_urbs_in_qh_list(hcd, &hcd->non_periodic_sched_active);
  69850. + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_inactive);
  69851. + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_ready);
  69852. + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_assigned);
  69853. + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_queued);
  69854. +}
  69855. +
  69856. +/**
  69857. + * Start the connection timer. An OTG host is required to display a
  69858. + * message if the device does not connect within 10 seconds. The
  69859. + * timer is deleted if a port connect interrupt occurs before the
  69860. + * timer expires.
  69861. + */
  69862. +static void dwc_otg_hcd_start_connect_timer(dwc_otg_hcd_t * hcd)
  69863. +{
  69864. + DWC_TIMER_SCHEDULE(hcd->conn_timer, 10000 /* 10 secs */ );
  69865. +}
  69866. +
  69867. +/**
  69868. + * HCD Callback function for disconnect of the HCD.
  69869. + *
  69870. + * @param p void pointer to the <code>struct usb_hcd</code>
  69871. + */
  69872. +static int32_t dwc_otg_hcd_session_start_cb(void *p)
  69873. +{
  69874. + dwc_otg_hcd_t *dwc_otg_hcd;
  69875. + DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, p);
  69876. + dwc_otg_hcd = p;
  69877. + dwc_otg_hcd_start_connect_timer(dwc_otg_hcd);
  69878. + return 1;
  69879. +}
  69880. +
  69881. +/**
  69882. + * HCD Callback function for starting the HCD when A-Cable is
  69883. + * connected.
  69884. + *
  69885. + * @param p void pointer to the <code>struct usb_hcd</code>
  69886. + */
  69887. +static int32_t dwc_otg_hcd_start_cb(void *p)
  69888. +{
  69889. + dwc_otg_hcd_t *dwc_otg_hcd = p;
  69890. + dwc_otg_core_if_t *core_if;
  69891. + hprt0_data_t hprt0;
  69892. +
  69893. + core_if = dwc_otg_hcd->core_if;
  69894. +
  69895. + if (core_if->op_state == B_HOST) {
  69896. + /*
  69897. + * Reset the port. During a HNP mode switch the reset
  69898. + * needs to occur within 1ms and have a duration of at
  69899. + * least 50ms.
  69900. + */
  69901. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  69902. + hprt0.b.prtrst = 1;
  69903. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  69904. + }
  69905. + DWC_WORKQ_SCHEDULE_DELAYED(core_if->wq_otg,
  69906. + hcd_start_func, dwc_otg_hcd, 50,
  69907. + "start hcd");
  69908. +
  69909. + return 1;
  69910. +}
  69911. +
  69912. +/**
  69913. + * HCD Callback function for disconnect of the HCD.
  69914. + *
  69915. + * @param p void pointer to the <code>struct usb_hcd</code>
  69916. + */
  69917. +static int32_t dwc_otg_hcd_disconnect_cb(void *p)
  69918. +{
  69919. + gintsts_data_t intr;
  69920. + dwc_otg_hcd_t *dwc_otg_hcd = p;
  69921. +
  69922. + /*
  69923. + * Set status flags for the hub driver.
  69924. + */
  69925. + dwc_otg_hcd->flags.b.port_connect_status_change = 1;
  69926. + dwc_otg_hcd->flags.b.port_connect_status = 0;
  69927. + if(fiq_enable)
  69928. + local_fiq_disable();
  69929. + /*
  69930. + * Shutdown any transfers in process by clearing the Tx FIFO Empty
  69931. + * interrupt mask and status bits and disabling subsequent host
  69932. + * channel interrupts.
  69933. + */
  69934. + intr.d32 = 0;
  69935. + intr.b.nptxfempty = 1;
  69936. + intr.b.ptxfempty = 1;
  69937. + intr.b.hcintr = 1;
  69938. + DWC_MODIFY_REG32(&dwc_otg_hcd->core_if->core_global_regs->gintmsk,
  69939. + intr.d32, 0);
  69940. + DWC_MODIFY_REG32(&dwc_otg_hcd->core_if->core_global_regs->gintsts,
  69941. + intr.d32, 0);
  69942. +
  69943. + del_timers(dwc_otg_hcd);
  69944. +
  69945. + /*
  69946. + * Turn off the vbus power only if the core has transitioned to device
  69947. + * mode. If still in host mode, need to keep power on to detect a
  69948. + * reconnection.
  69949. + */
  69950. + if (dwc_otg_is_device_mode(dwc_otg_hcd->core_if)) {
  69951. + if (dwc_otg_hcd->core_if->op_state != A_SUSPEND) {
  69952. + hprt0_data_t hprt0 = {.d32 = 0 };
  69953. + DWC_PRINTF("Disconnect: PortPower off\n");
  69954. + hprt0.b.prtpwr = 0;
  69955. + DWC_WRITE_REG32(dwc_otg_hcd->core_if->host_if->hprt0,
  69956. + hprt0.d32);
  69957. + }
  69958. +
  69959. + dwc_otg_disable_host_interrupts(dwc_otg_hcd->core_if);
  69960. + }
  69961. +
  69962. + /* Respond with an error status to all URBs in the schedule. */
  69963. + kill_all_urbs(dwc_otg_hcd);
  69964. +
  69965. + if (dwc_otg_is_host_mode(dwc_otg_hcd->core_if)) {
  69966. + /* Clean up any host channels that were in use. */
  69967. + int num_channels;
  69968. + int i;
  69969. + dwc_hc_t *channel;
  69970. + dwc_otg_hc_regs_t *hc_regs;
  69971. + hcchar_data_t hcchar;
  69972. +
  69973. + num_channels = dwc_otg_hcd->core_if->core_params->host_channels;
  69974. +
  69975. + if (!dwc_otg_hcd->core_if->dma_enable) {
  69976. + /* Flush out any channel requests in slave mode. */
  69977. + for (i = 0; i < num_channels; i++) {
  69978. + channel = dwc_otg_hcd->hc_ptr_array[i];
  69979. + if (DWC_CIRCLEQ_EMPTY_ENTRY
  69980. + (channel, hc_list_entry)) {
  69981. + hc_regs =
  69982. + dwc_otg_hcd->core_if->
  69983. + host_if->hc_regs[i];
  69984. + hcchar.d32 =
  69985. + DWC_READ_REG32(&hc_regs->hcchar);
  69986. + if (hcchar.b.chen) {
  69987. + hcchar.b.chen = 0;
  69988. + hcchar.b.chdis = 1;
  69989. + hcchar.b.epdir = 0;
  69990. + DWC_WRITE_REG32
  69991. + (&hc_regs->hcchar,
  69992. + hcchar.d32);
  69993. + }
  69994. + }
  69995. + }
  69996. + }
  69997. +
  69998. + for (i = 0; i < num_channels; i++) {
  69999. + channel = dwc_otg_hcd->hc_ptr_array[i];
  70000. + if (DWC_CIRCLEQ_EMPTY_ENTRY(channel, hc_list_entry)) {
  70001. + hc_regs =
  70002. + dwc_otg_hcd->core_if->host_if->hc_regs[i];
  70003. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  70004. + if (hcchar.b.chen) {
  70005. + /* Halt the channel. */
  70006. + hcchar.b.chdis = 1;
  70007. + DWC_WRITE_REG32(&hc_regs->hcchar,
  70008. + hcchar.d32);
  70009. + }
  70010. +
  70011. + dwc_otg_hc_cleanup(dwc_otg_hcd->core_if,
  70012. + channel);
  70013. + DWC_CIRCLEQ_INSERT_TAIL
  70014. + (&dwc_otg_hcd->free_hc_list, channel,
  70015. + hc_list_entry);
  70016. + /*
  70017. + * Added for Descriptor DMA to prevent channel double cleanup
  70018. + * in release_channel_ddma(). Which called from ep_disable
  70019. + * when device disconnect.
  70020. + */
  70021. + channel->qh = NULL;
  70022. + }
  70023. + }
  70024. + if(fiq_fsm_enable) {
  70025. + for(i=0; i < 128; i++) {
  70026. + dwc_otg_hcd->hub_port[i] = 0;
  70027. + }
  70028. + }
  70029. +
  70030. + }
  70031. +
  70032. + if(fiq_enable)
  70033. + local_fiq_enable();
  70034. +
  70035. + if (dwc_otg_hcd->fops->disconnect) {
  70036. + dwc_otg_hcd->fops->disconnect(dwc_otg_hcd);
  70037. + }
  70038. +
  70039. + return 1;
  70040. +}
  70041. +
  70042. +/**
  70043. + * HCD Callback function for stopping the HCD.
  70044. + *
  70045. + * @param p void pointer to the <code>struct usb_hcd</code>
  70046. + */
  70047. +static int32_t dwc_otg_hcd_stop_cb(void *p)
  70048. +{
  70049. + dwc_otg_hcd_t *dwc_otg_hcd = p;
  70050. +
  70051. + DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, p);
  70052. + dwc_otg_hcd_stop(dwc_otg_hcd);
  70053. + return 1;
  70054. +}
  70055. +
  70056. +#ifdef CONFIG_USB_DWC_OTG_LPM
  70057. +/**
  70058. + * HCD Callback function for sleep of HCD.
  70059. + *
  70060. + * @param p void pointer to the <code>struct usb_hcd</code>
  70061. + */
  70062. +static int dwc_otg_hcd_sleep_cb(void *p)
  70063. +{
  70064. + dwc_otg_hcd_t *hcd = p;
  70065. +
  70066. + dwc_otg_hcd_free_hc_from_lpm(hcd);
  70067. +
  70068. + return 0;
  70069. +}
  70070. +#endif
  70071. +
  70072. +
  70073. +/**
  70074. + * HCD Callback function for Remote Wakeup.
  70075. + *
  70076. + * @param p void pointer to the <code>struct usb_hcd</code>
  70077. + */
  70078. +static int dwc_otg_hcd_rem_wakeup_cb(void *p)
  70079. +{
  70080. + dwc_otg_hcd_t *hcd = p;
  70081. +
  70082. + if (hcd->core_if->lx_state == DWC_OTG_L2) {
  70083. + hcd->flags.b.port_suspend_change = 1;
  70084. + }
  70085. +#ifdef CONFIG_USB_DWC_OTG_LPM
  70086. + else {
  70087. + hcd->flags.b.port_l1_change = 1;
  70088. + }
  70089. +#endif
  70090. + return 0;
  70091. +}
  70092. +
  70093. +/**
  70094. + * Halts the DWC_otg host mode operations in a clean manner. USB transfers are
  70095. + * stopped.
  70096. + */
  70097. +void dwc_otg_hcd_stop(dwc_otg_hcd_t * hcd)
  70098. +{
  70099. + hprt0_data_t hprt0 = {.d32 = 0 };
  70100. +
  70101. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD STOP\n");
  70102. +
  70103. + /*
  70104. + * The root hub should be disconnected before this function is called.
  70105. + * The disconnect will clear the QTD lists (via ..._hcd_urb_dequeue)
  70106. + * and the QH lists (via ..._hcd_endpoint_disable).
  70107. + */
  70108. +
  70109. + /* Turn off all host-specific interrupts. */
  70110. + dwc_otg_disable_host_interrupts(hcd->core_if);
  70111. +
  70112. + /* Turn off the vbus power */
  70113. + DWC_PRINTF("PortPower off\n");
  70114. + hprt0.b.prtpwr = 0;
  70115. + DWC_WRITE_REG32(hcd->core_if->host_if->hprt0, hprt0.d32);
  70116. + dwc_mdelay(1);
  70117. +}
  70118. +
  70119. +int dwc_otg_hcd_urb_enqueue(dwc_otg_hcd_t * hcd,
  70120. + dwc_otg_hcd_urb_t * dwc_otg_urb, void **ep_handle,
  70121. + int atomic_alloc)
  70122. +{
  70123. + int retval = 0;
  70124. + uint8_t needs_scheduling = 0;
  70125. + dwc_otg_transaction_type_e tr_type;
  70126. + dwc_otg_qtd_t *qtd;
  70127. + gintmsk_data_t intr_mask = {.d32 = 0 };
  70128. + hprt0_data_t hprt0 = { .d32 = 0 };
  70129. +
  70130. +#ifdef DEBUG /* integrity checks (Broadcom) */
  70131. + if (NULL == hcd->core_if) {
  70132. + DWC_ERROR("**** DWC OTG HCD URB Enqueue - HCD has NULL core_if\n");
  70133. + /* No longer connected. */
  70134. + return -DWC_E_INVALID;
  70135. + }
  70136. +#endif
  70137. + if (!hcd->flags.b.port_connect_status) {
  70138. + /* No longer connected. */
  70139. + DWC_ERROR("Not connected\n");
  70140. + return -DWC_E_NO_DEVICE;
  70141. + }
  70142. +
  70143. + /* Some core configurations cannot support LS traffic on a FS root port */
  70144. + if ((hcd->fops->speed(hcd, dwc_otg_urb->priv) == USB_SPEED_LOW) &&
  70145. + (hcd->core_if->hwcfg2.b.fs_phy_type == 1) &&
  70146. + (hcd->core_if->hwcfg2.b.hs_phy_type == 1)) {
  70147. + hprt0.d32 = DWC_READ_REG32(hcd->core_if->host_if->hprt0);
  70148. + if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_FULL_SPEED) {
  70149. + return -DWC_E_NO_DEVICE;
  70150. + }
  70151. + }
  70152. +
  70153. + qtd = dwc_otg_hcd_qtd_create(dwc_otg_urb, atomic_alloc);
  70154. + if (qtd == NULL) {
  70155. + DWC_ERROR("DWC OTG HCD URB Enqueue failed creating QTD\n");
  70156. + return -DWC_E_NO_MEMORY;
  70157. + }
  70158. +#ifdef DEBUG /* integrity checks (Broadcom) */
  70159. + if (qtd->urb == NULL) {
  70160. + DWC_ERROR("**** DWC OTG HCD URB Enqueue created QTD with no URBs\n");
  70161. + return -DWC_E_NO_MEMORY;
  70162. + }
  70163. + if (qtd->urb->priv == NULL) {
  70164. + DWC_ERROR("**** DWC OTG HCD URB Enqueue created QTD URB with no URB handle\n");
  70165. + return -DWC_E_NO_MEMORY;
  70166. + }
  70167. +#endif
  70168. + intr_mask.d32 = DWC_READ_REG32(&hcd->core_if->core_global_regs->gintmsk);
  70169. + if(!intr_mask.b.sofintr || fiq_enable) needs_scheduling = 1;
  70170. + if((((dwc_otg_qh_t *)ep_handle)->ep_type == UE_BULK) && !(qtd->urb->flags & URB_GIVEBACK_ASAP))
  70171. + /* Do not schedule SG transactions until qtd has URB_GIVEBACK_ASAP set */
  70172. + needs_scheduling = 0;
  70173. +
  70174. + retval = dwc_otg_hcd_qtd_add(qtd, hcd, (dwc_otg_qh_t **) ep_handle, atomic_alloc);
  70175. + // creates a new queue in ep_handle if it doesn't exist already
  70176. + if (retval < 0) {
  70177. + DWC_ERROR("DWC OTG HCD URB Enqueue failed adding QTD. "
  70178. + "Error status %d\n", retval);
  70179. + dwc_otg_hcd_qtd_free(qtd);
  70180. + return retval;
  70181. + }
  70182. +
  70183. + if(needs_scheduling) {
  70184. + tr_type = dwc_otg_hcd_select_transactions(hcd);
  70185. + if (tr_type != DWC_OTG_TRANSACTION_NONE) {
  70186. + dwc_otg_hcd_queue_transactions(hcd, tr_type);
  70187. + }
  70188. + }
  70189. + return retval;
  70190. +}
  70191. +
  70192. +int dwc_otg_hcd_urb_dequeue(dwc_otg_hcd_t * hcd,
  70193. + dwc_otg_hcd_urb_t * dwc_otg_urb)
  70194. +{
  70195. + dwc_otg_qh_t *qh;
  70196. + dwc_otg_qtd_t *urb_qtd;
  70197. + BUG_ON(!hcd);
  70198. + BUG_ON(!dwc_otg_urb);
  70199. +
  70200. +#ifdef DEBUG /* integrity checks (Broadcom) */
  70201. +
  70202. + if (hcd == NULL) {
  70203. + DWC_ERROR("**** DWC OTG HCD URB Dequeue has NULL HCD\n");
  70204. + return -DWC_E_INVALID;
  70205. + }
  70206. + if (dwc_otg_urb == NULL) {
  70207. + DWC_ERROR("**** DWC OTG HCD URB Dequeue has NULL URB\n");
  70208. + return -DWC_E_INVALID;
  70209. + }
  70210. + if (dwc_otg_urb->qtd == NULL) {
  70211. + DWC_ERROR("**** DWC OTG HCD URB Dequeue with NULL QTD\n");
  70212. + return -DWC_E_INVALID;
  70213. + }
  70214. + urb_qtd = dwc_otg_urb->qtd;
  70215. + BUG_ON(!urb_qtd);
  70216. + if (urb_qtd->qh == NULL) {
  70217. + DWC_ERROR("**** DWC OTG HCD URB Dequeue with QTD with NULL Q handler\n");
  70218. + return -DWC_E_INVALID;
  70219. + }
  70220. +#else
  70221. + urb_qtd = dwc_otg_urb->qtd;
  70222. + BUG_ON(!urb_qtd);
  70223. +#endif
  70224. + qh = urb_qtd->qh;
  70225. + BUG_ON(!qh);
  70226. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  70227. + if (urb_qtd->in_process) {
  70228. + dump_channel_info(hcd, qh);
  70229. + }
  70230. + }
  70231. +#ifdef DEBUG /* integrity checks (Broadcom) */
  70232. + if (hcd->core_if == NULL) {
  70233. + DWC_ERROR("**** DWC OTG HCD URB Dequeue HCD has NULL core_if\n");
  70234. + return -DWC_E_INVALID;
  70235. + }
  70236. +#endif
  70237. + if (urb_qtd->in_process && qh->channel) {
  70238. + /* The QTD is in process (it has been assigned to a channel). */
  70239. + if (hcd->flags.b.port_connect_status) {
  70240. + int n = qh->channel->hc_num;
  70241. + /*
  70242. + * If still connected (i.e. in host mode), halt the
  70243. + * channel so it can be used for other transfers. If
  70244. + * no longer connected, the host registers can't be
  70245. + * written to halt the channel since the core is in
  70246. + * device mode.
  70247. + */
  70248. + /* In FIQ FSM mode, we need to shut down carefully.
  70249. + * The FIQ may attempt to restart a disabled channel */
  70250. + if (fiq_fsm_enable && (hcd->fiq_state->channel[n].fsm != FIQ_PASSTHROUGH)) {
  70251. + hcd->fiq_state->channel[n].fsm = FIQ_DEQUEUE_ISSUED;
  70252. + }
  70253. + dwc_otg_hc_halt(hcd->core_if, qh->channel,
  70254. + DWC_OTG_HC_XFER_URB_DEQUEUE);
  70255. +
  70256. + }
  70257. + }
  70258. +
  70259. + /*
  70260. + * Free the QTD and clean up the associated QH. Leave the QH in the
  70261. + * schedule if it has any remaining QTDs.
  70262. + */
  70263. +
  70264. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Dequeue - "
  70265. + "delete %sQueue handler\n",
  70266. + hcd->core_if->dma_desc_enable?"DMA ":"");
  70267. + if (!hcd->core_if->dma_desc_enable) {
  70268. + uint8_t b = urb_qtd->in_process;
  70269. + dwc_otg_hcd_qtd_remove_and_free(hcd, urb_qtd, qh);
  70270. + if (b) {
  70271. + dwc_otg_hcd_qh_deactivate(hcd, qh, 0);
  70272. + qh->channel = NULL;
  70273. + } else if (DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  70274. + dwc_otg_hcd_qh_remove(hcd, qh);
  70275. + }
  70276. + } else {
  70277. + dwc_otg_hcd_qtd_remove_and_free(hcd, urb_qtd, qh);
  70278. + }
  70279. + return 0;
  70280. +}
  70281. +
  70282. +int dwc_otg_hcd_endpoint_disable(dwc_otg_hcd_t * hcd, void *ep_handle,
  70283. + int retry)
  70284. +{
  70285. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  70286. + int retval = 0;
  70287. + dwc_irqflags_t flags;
  70288. +
  70289. + if (retry < 0) {
  70290. + retval = -DWC_E_INVALID;
  70291. + goto done;
  70292. + }
  70293. +
  70294. + if (!qh) {
  70295. + retval = -DWC_E_INVALID;
  70296. + goto done;
  70297. + }
  70298. +
  70299. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  70300. +
  70301. + while (!DWC_CIRCLEQ_EMPTY(&qh->qtd_list) && retry) {
  70302. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  70303. + retry--;
  70304. + dwc_msleep(5);
  70305. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  70306. + }
  70307. +
  70308. + dwc_otg_hcd_qh_remove(hcd, qh);
  70309. +
  70310. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  70311. + /*
  70312. + * Split dwc_otg_hcd_qh_remove_and_free() into qh_remove
  70313. + * and qh_free to prevent stack dump on DWC_DMA_FREE() with
  70314. + * irq_disabled (spinlock_irqsave) in dwc_otg_hcd_desc_list_free()
  70315. + * and dwc_otg_hcd_frame_list_alloc().
  70316. + */
  70317. + dwc_otg_hcd_qh_free(hcd, qh);
  70318. +
  70319. +done:
  70320. + return retval;
  70321. +}
  70322. +
  70323. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
  70324. +int dwc_otg_hcd_endpoint_reset(dwc_otg_hcd_t * hcd, void *ep_handle)
  70325. +{
  70326. + int retval = 0;
  70327. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  70328. + if (!qh)
  70329. + return -DWC_E_INVALID;
  70330. +
  70331. + qh->data_toggle = DWC_OTG_HC_PID_DATA0;
  70332. + return retval;
  70333. +}
  70334. +#endif
  70335. +
  70336. +/**
  70337. + * HCD Callback structure for handling mode switching.
  70338. + */
  70339. +static dwc_otg_cil_callbacks_t hcd_cil_callbacks = {
  70340. + .start = dwc_otg_hcd_start_cb,
  70341. + .stop = dwc_otg_hcd_stop_cb,
  70342. + .disconnect = dwc_otg_hcd_disconnect_cb,
  70343. + .session_start = dwc_otg_hcd_session_start_cb,
  70344. + .resume_wakeup = dwc_otg_hcd_rem_wakeup_cb,
  70345. +#ifdef CONFIG_USB_DWC_OTG_LPM
  70346. + .sleep = dwc_otg_hcd_sleep_cb,
  70347. +#endif
  70348. + .p = 0,
  70349. +};
  70350. +
  70351. +/**
  70352. + * Reset tasklet function
  70353. + */
  70354. +static void reset_tasklet_func(void *data)
  70355. +{
  70356. + dwc_otg_hcd_t *dwc_otg_hcd = (dwc_otg_hcd_t *) data;
  70357. + dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
  70358. + hprt0_data_t hprt0;
  70359. +
  70360. + DWC_DEBUGPL(DBG_HCDV, "USB RESET tasklet called\n");
  70361. +
  70362. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  70363. + hprt0.b.prtrst = 1;
  70364. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  70365. + dwc_mdelay(60);
  70366. +
  70367. + hprt0.b.prtrst = 0;
  70368. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  70369. + dwc_otg_hcd->flags.b.port_reset_change = 1;
  70370. +}
  70371. +
  70372. +static void completion_tasklet_func(void *ptr)
  70373. +{
  70374. + dwc_otg_hcd_t *hcd = (dwc_otg_hcd_t *) ptr;
  70375. + struct urb *urb;
  70376. + urb_tq_entry_t *item;
  70377. + dwc_irqflags_t flags;
  70378. +
  70379. + /* This could just be spin_lock_irq */
  70380. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  70381. + while (!DWC_TAILQ_EMPTY(&hcd->completed_urb_list)) {
  70382. + item = DWC_TAILQ_FIRST(&hcd->completed_urb_list);
  70383. + urb = item->urb;
  70384. + DWC_TAILQ_REMOVE(&hcd->completed_urb_list, item,
  70385. + urb_tq_entries);
  70386. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  70387. + DWC_FREE(item);
  70388. +
  70389. + usb_hcd_giveback_urb(hcd->priv, urb, urb->status);
  70390. +
  70391. +
  70392. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  70393. + }
  70394. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  70395. + return;
  70396. +}
  70397. +
  70398. +static void qh_list_free(dwc_otg_hcd_t * hcd, dwc_list_link_t * qh_list)
  70399. +{
  70400. + dwc_list_link_t *item;
  70401. + dwc_otg_qh_t *qh;
  70402. + dwc_irqflags_t flags;
  70403. +
  70404. + if (!qh_list->next) {
  70405. + /* The list hasn't been initialized yet. */
  70406. + return;
  70407. + }
  70408. + /*
  70409. + * Hold spinlock here. Not needed in that case if bellow
  70410. + * function is being called from ISR
  70411. + */
  70412. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  70413. + /* Ensure there are no QTDs or URBs left. */
  70414. + kill_urbs_in_qh_list(hcd, qh_list);
  70415. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  70416. +
  70417. + DWC_LIST_FOREACH(item, qh_list) {
  70418. + qh = DWC_LIST_ENTRY(item, dwc_otg_qh_t, qh_list_entry);
  70419. + dwc_otg_hcd_qh_remove_and_free(hcd, qh);
  70420. + }
  70421. +}
  70422. +
  70423. +/**
  70424. + * Exit from Hibernation if Host did not detect SRP from connected SRP capable
  70425. + * Device during SRP time by host power up.
  70426. + */
  70427. +void dwc_otg_hcd_power_up(void *ptr)
  70428. +{
  70429. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  70430. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) ptr;
  70431. +
  70432. + DWC_PRINTF("%s called\n", __FUNCTION__);
  70433. +
  70434. + if (!core_if->hibernation_suspend) {
  70435. + DWC_PRINTF("Already exited from Hibernation\n");
  70436. + return;
  70437. + }
  70438. +
  70439. + /* Switch on the voltage to the core */
  70440. + gpwrdn.b.pwrdnswtch = 1;
  70441. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  70442. + dwc_udelay(10);
  70443. +
  70444. + /* Reset the core */
  70445. + gpwrdn.d32 = 0;
  70446. + gpwrdn.b.pwrdnrstn = 1;
  70447. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  70448. + dwc_udelay(10);
  70449. +
  70450. + /* Disable power clamps */
  70451. + gpwrdn.d32 = 0;
  70452. + gpwrdn.b.pwrdnclmp = 1;
  70453. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  70454. +
  70455. + /* Remove reset the core signal */
  70456. + gpwrdn.d32 = 0;
  70457. + gpwrdn.b.pwrdnrstn = 1;
  70458. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  70459. + dwc_udelay(10);
  70460. +
  70461. + /* Disable PMU interrupt */
  70462. + gpwrdn.d32 = 0;
  70463. + gpwrdn.b.pmuintsel = 1;
  70464. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  70465. +
  70466. + core_if->hibernation_suspend = 0;
  70467. +
  70468. + /* Disable PMU */
  70469. + gpwrdn.d32 = 0;
  70470. + gpwrdn.b.pmuactv = 1;
  70471. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  70472. + dwc_udelay(10);
  70473. +
  70474. + /* Enable VBUS */
  70475. + gpwrdn.d32 = 0;
  70476. + gpwrdn.b.dis_vbus = 1;
  70477. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  70478. +
  70479. + core_if->op_state = A_HOST;
  70480. + dwc_otg_core_init(core_if);
  70481. + dwc_otg_enable_global_interrupts(core_if);
  70482. + cil_hcd_start(core_if);
  70483. +}
  70484. +
  70485. +void dwc_otg_cleanup_fiq_channel(dwc_otg_hcd_t *hcd, uint32_t num)
  70486. +{
  70487. + struct fiq_channel_state *st = &hcd->fiq_state->channel[num];
  70488. + struct fiq_dma_blob *blob = hcd->fiq_dmab;
  70489. + int i;
  70490. +
  70491. + st->fsm = FIQ_PASSTHROUGH;
  70492. + st->hcchar_copy.d32 = 0;
  70493. + st->hcsplt_copy.d32 = 0;
  70494. + st->hcint_copy.d32 = 0;
  70495. + st->hcintmsk_copy.d32 = 0;
  70496. + st->hctsiz_copy.d32 = 0;
  70497. + st->hcdma_copy.d32 = 0;
  70498. + st->nr_errors = 0;
  70499. + st->hub_addr = 0;
  70500. + st->port_addr = 0;
  70501. + st->expected_uframe = 0;
  70502. + st->nrpackets = 0;
  70503. + st->dma_info.index = 0;
  70504. + for (i = 0; i < 6; i++)
  70505. + st->dma_info.slot_len[i] = 255;
  70506. + st->hs_isoc_info.index = 0;
  70507. + st->hs_isoc_info.iso_desc = NULL;
  70508. + st->hs_isoc_info.nrframes = 0;
  70509. +
  70510. + DWC_MEMSET(&blob->channel[num].index[0], 0x6b, 1128);
  70511. +}
  70512. +
  70513. +/**
  70514. + * Frees secondary storage associated with the dwc_otg_hcd structure contained
  70515. + * in the struct usb_hcd field.
  70516. + */
  70517. +static void dwc_otg_hcd_free(dwc_otg_hcd_t * dwc_otg_hcd)
  70518. +{
  70519. + int i;
  70520. +
  70521. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD FREE\n");
  70522. +
  70523. + del_timers(dwc_otg_hcd);
  70524. +
  70525. + /* Free memory for QH/QTD lists */
  70526. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->non_periodic_sched_inactive);
  70527. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->non_periodic_sched_active);
  70528. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_inactive);
  70529. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_ready);
  70530. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_assigned);
  70531. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_queued);
  70532. +
  70533. + /* Free memory for the host channels. */
  70534. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  70535. + dwc_hc_t *hc = dwc_otg_hcd->hc_ptr_array[i];
  70536. +
  70537. +#ifdef DEBUG
  70538. + if (dwc_otg_hcd->core_if->hc_xfer_timer[i]) {
  70539. + DWC_TIMER_FREE(dwc_otg_hcd->core_if->hc_xfer_timer[i]);
  70540. + }
  70541. +#endif
  70542. + if (hc != NULL) {
  70543. + DWC_DEBUGPL(DBG_HCDV, "HCD Free channel #%i, hc=%p\n",
  70544. + i, hc);
  70545. + DWC_FREE(hc);
  70546. + }
  70547. + }
  70548. +
  70549. + if (dwc_otg_hcd->core_if->dma_enable) {
  70550. + if (dwc_otg_hcd->status_buf_dma) {
  70551. + DWC_DMA_FREE(DWC_OTG_HCD_STATUS_BUF_SIZE,
  70552. + dwc_otg_hcd->status_buf,
  70553. + dwc_otg_hcd->status_buf_dma);
  70554. + }
  70555. + } else if (dwc_otg_hcd->status_buf != NULL) {
  70556. + DWC_FREE(dwc_otg_hcd->status_buf);
  70557. + }
  70558. + DWC_SPINLOCK_FREE(dwc_otg_hcd->channel_lock);
  70559. + DWC_SPINLOCK_FREE(dwc_otg_hcd->lock);
  70560. + /* Set core_if's lock pointer to NULL */
  70561. + dwc_otg_hcd->core_if->lock = NULL;
  70562. +
  70563. + DWC_TIMER_FREE(dwc_otg_hcd->conn_timer);
  70564. + DWC_TASK_FREE(dwc_otg_hcd->reset_tasklet);
  70565. + DWC_TASK_FREE(dwc_otg_hcd->completion_tasklet);
  70566. + DWC_FREE(dwc_otg_hcd->fiq_state);
  70567. +
  70568. +#ifdef DWC_DEV_SRPCAP
  70569. + if (dwc_otg_hcd->core_if->power_down == 2 &&
  70570. + dwc_otg_hcd->core_if->pwron_timer) {
  70571. + DWC_TIMER_FREE(dwc_otg_hcd->core_if->pwron_timer);
  70572. + }
  70573. +#endif
  70574. + DWC_FREE(dwc_otg_hcd);
  70575. +}
  70576. +
  70577. +int init_hcd_usecs(dwc_otg_hcd_t *_hcd);
  70578. +
  70579. +int dwc_otg_hcd_init(dwc_otg_hcd_t * hcd, dwc_otg_core_if_t * core_if)
  70580. +{
  70581. + int retval = 0;
  70582. + int num_channels;
  70583. + int i;
  70584. + dwc_hc_t *channel;
  70585. +
  70586. + hcd->lock = DWC_SPINLOCK_ALLOC();
  70587. + hcd->channel_lock = DWC_SPINLOCK_ALLOC();
  70588. + DWC_DEBUGPL(DBG_HCDV, "init of HCD %p given core_if %p\n",
  70589. + hcd, core_if);
  70590. + if (!hcd->lock) {
  70591. + DWC_ERROR("Could not allocate lock for pcd");
  70592. + DWC_FREE(hcd);
  70593. + retval = -DWC_E_NO_MEMORY;
  70594. + goto out;
  70595. + }
  70596. + hcd->core_if = core_if;
  70597. +
  70598. + /* Register the HCD CIL Callbacks */
  70599. + dwc_otg_cil_register_hcd_callbacks(hcd->core_if,
  70600. + &hcd_cil_callbacks, hcd);
  70601. +
  70602. + /* Initialize the non-periodic schedule. */
  70603. + DWC_LIST_INIT(&hcd->non_periodic_sched_inactive);
  70604. + DWC_LIST_INIT(&hcd->non_periodic_sched_active);
  70605. +
  70606. + /* Initialize the periodic schedule. */
  70607. + DWC_LIST_INIT(&hcd->periodic_sched_inactive);
  70608. + DWC_LIST_INIT(&hcd->periodic_sched_ready);
  70609. + DWC_LIST_INIT(&hcd->periodic_sched_assigned);
  70610. + DWC_LIST_INIT(&hcd->periodic_sched_queued);
  70611. + DWC_TAILQ_INIT(&hcd->completed_urb_list);
  70612. + /*
  70613. + * Create a host channel descriptor for each host channel implemented
  70614. + * in the controller. Initialize the channel descriptor array.
  70615. + */
  70616. + DWC_CIRCLEQ_INIT(&hcd->free_hc_list);
  70617. + num_channels = hcd->core_if->core_params->host_channels;
  70618. + DWC_MEMSET(hcd->hc_ptr_array, 0, sizeof(hcd->hc_ptr_array));
  70619. + for (i = 0; i < num_channels; i++) {
  70620. + channel = DWC_ALLOC(sizeof(dwc_hc_t));
  70621. + if (channel == NULL) {
  70622. + retval = -DWC_E_NO_MEMORY;
  70623. + DWC_ERROR("%s: host channel allocation failed\n",
  70624. + __func__);
  70625. + dwc_otg_hcd_free(hcd);
  70626. + goto out;
  70627. + }
  70628. + channel->hc_num = i;
  70629. + hcd->hc_ptr_array[i] = channel;
  70630. +#ifdef DEBUG
  70631. + hcd->core_if->hc_xfer_timer[i] =
  70632. + DWC_TIMER_ALLOC("hc timer", hc_xfer_timeout,
  70633. + &hcd->core_if->hc_xfer_info[i]);
  70634. +#endif
  70635. + DWC_DEBUGPL(DBG_HCDV, "HCD Added channel #%d, hc=%p\n", i,
  70636. + channel);
  70637. + }
  70638. +
  70639. + if (fiq_enable) {
  70640. + hcd->fiq_state = DWC_ALLOC(sizeof(struct fiq_state) + (sizeof(struct fiq_channel_state) * num_channels));
  70641. + if (!hcd->fiq_state) {
  70642. + retval = -DWC_E_NO_MEMORY;
  70643. + DWC_ERROR("%s: cannot allocate fiq_state structure\n", __func__);
  70644. + dwc_otg_hcd_free(hcd);
  70645. + goto out;
  70646. + }
  70647. + DWC_MEMSET(hcd->fiq_state, 0, (sizeof(struct fiq_state) + (sizeof(struct fiq_channel_state) * num_channels)));
  70648. +
  70649. + for (i = 0; i < num_channels; i++) {
  70650. + hcd->fiq_state->channel[i].fsm = FIQ_PASSTHROUGH;
  70651. + }
  70652. + hcd->fiq_state->dummy_send = DWC_ALLOC_ATOMIC(16);
  70653. +
  70654. + hcd->fiq_stack = DWC_ALLOC(sizeof(struct fiq_stack));
  70655. + if (!hcd->fiq_stack) {
  70656. + retval = -DWC_E_NO_MEMORY;
  70657. + DWC_ERROR("%s: cannot allocate fiq_stack structure\n", __func__);
  70658. + dwc_otg_hcd_free(hcd);
  70659. + goto out;
  70660. + }
  70661. + hcd->fiq_stack->magic1 = 0xDEADBEEF;
  70662. + hcd->fiq_stack->magic2 = 0xD00DFEED;
  70663. + hcd->fiq_state->gintmsk_saved.d32 = ~0;
  70664. + hcd->fiq_state->haintmsk_saved.b2.chint = ~0;
  70665. +
  70666. + /* This bit is terrible and uses no API, but necessary. The FIQ has no concept of DMA pools
  70667. + * (and if it did, would be a lot slower). This allocates a chunk of memory (~9kiB for 8 host channels)
  70668. + * for use as transaction bounce buffers in a 2-D array. Our access into this chunk is done by some
  70669. + * moderately readable array casts.
  70670. + */
  70671. + hcd->fiq_dmab = DWC_DMA_ALLOC((sizeof(struct fiq_dma_channel) * num_channels), &hcd->fiq_state->dma_base);
  70672. + DWC_WARN("FIQ DMA bounce buffers: virt = 0x%08x dma = 0x%08x len=%d",
  70673. + (unsigned int)hcd->fiq_dmab, (unsigned int)hcd->fiq_state->dma_base,
  70674. + sizeof(struct fiq_dma_channel) * num_channels);
  70675. +
  70676. + DWC_MEMSET(hcd->fiq_dmab, 0x6b, 9024);
  70677. +
  70678. + /* pointer for debug in fiq_print */
  70679. + hcd->fiq_state->fiq_dmab = hcd->fiq_dmab;
  70680. + if (fiq_fsm_enable) {
  70681. + int i;
  70682. + for (i=0; i < hcd->core_if->core_params->host_channels; i++) {
  70683. + dwc_otg_cleanup_fiq_channel(hcd, i);
  70684. + }
  70685. + DWC_PRINTF("FIQ FSM acceleration enabled for :\n%s%s%s",
  70686. + (fiq_fsm_mask & 0x1) ? "Non-periodic Split Transactions\n" : "",
  70687. + (fiq_fsm_mask & 0x2) ? "Periodic Split Transactions\n" : "",
  70688. + (fiq_fsm_mask & 0x4) ? "High-Speed Isochronous Endpoints\n" : "");
  70689. + }
  70690. + }
  70691. +
  70692. + /* Initialize the Connection timeout timer. */
  70693. + hcd->conn_timer = DWC_TIMER_ALLOC("Connection timer",
  70694. + dwc_otg_hcd_connect_timeout, 0);
  70695. +
  70696. + printk(KERN_DEBUG "dwc_otg: Microframe scheduler %s\n", microframe_schedule ? "enabled":"disabled");
  70697. + if (microframe_schedule)
  70698. + init_hcd_usecs(hcd);
  70699. +
  70700. + /* Initialize reset tasklet. */
  70701. + hcd->reset_tasklet = DWC_TASK_ALLOC("reset_tasklet", reset_tasklet_func, hcd);
  70702. +
  70703. + hcd->completion_tasklet = DWC_TASK_ALLOC("completion_tasklet",
  70704. + completion_tasklet_func, hcd);
  70705. +#ifdef DWC_DEV_SRPCAP
  70706. + if (hcd->core_if->power_down == 2) {
  70707. + /* Initialize Power on timer for Host power up in case hibernation */
  70708. + hcd->core_if->pwron_timer = DWC_TIMER_ALLOC("PWRON TIMER",
  70709. + dwc_otg_hcd_power_up, core_if);
  70710. + }
  70711. +#endif
  70712. +
  70713. + /*
  70714. + * Allocate space for storing data on status transactions. Normally no
  70715. + * data is sent, but this space acts as a bit bucket. This must be
  70716. + * done after usb_add_hcd since that function allocates the DMA buffer
  70717. + * pool.
  70718. + */
  70719. + if (hcd->core_if->dma_enable) {
  70720. + hcd->status_buf =
  70721. + DWC_DMA_ALLOC(DWC_OTG_HCD_STATUS_BUF_SIZE,
  70722. + &hcd->status_buf_dma);
  70723. + } else {
  70724. + hcd->status_buf = DWC_ALLOC(DWC_OTG_HCD_STATUS_BUF_SIZE);
  70725. + }
  70726. + if (!hcd->status_buf) {
  70727. + retval = -DWC_E_NO_MEMORY;
  70728. + DWC_ERROR("%s: status_buf allocation failed\n", __func__);
  70729. + dwc_otg_hcd_free(hcd);
  70730. + goto out;
  70731. + }
  70732. +
  70733. + hcd->otg_port = 1;
  70734. + hcd->frame_list = NULL;
  70735. + hcd->frame_list_dma = 0;
  70736. + hcd->periodic_qh_count = 0;
  70737. +
  70738. + DWC_MEMSET(hcd->hub_port, 0, sizeof(hcd->hub_port));
  70739. +#ifdef FIQ_DEBUG
  70740. + DWC_MEMSET(hcd->hub_port_alloc, -1, sizeof(hcd->hub_port_alloc));
  70741. +#endif
  70742. +
  70743. +out:
  70744. + return retval;
  70745. +}
  70746. +
  70747. +void dwc_otg_hcd_remove(dwc_otg_hcd_t * hcd)
  70748. +{
  70749. + /* Turn off all host-specific interrupts. */
  70750. + dwc_otg_disable_host_interrupts(hcd->core_if);
  70751. +
  70752. + dwc_otg_hcd_free(hcd);
  70753. +}
  70754. +
  70755. +/**
  70756. + * Initializes dynamic portions of the DWC_otg HCD state.
  70757. + */
  70758. +static void dwc_otg_hcd_reinit(dwc_otg_hcd_t * hcd)
  70759. +{
  70760. + int num_channels;
  70761. + int i;
  70762. + dwc_hc_t *channel;
  70763. + dwc_hc_t *channel_tmp;
  70764. +
  70765. + hcd->flags.d32 = 0;
  70766. +
  70767. + hcd->non_periodic_qh_ptr = &hcd->non_periodic_sched_active;
  70768. + if (!microframe_schedule) {
  70769. + hcd->non_periodic_channels = 0;
  70770. + hcd->periodic_channels = 0;
  70771. + } else {
  70772. + hcd->available_host_channels = hcd->core_if->core_params->host_channels;
  70773. + }
  70774. + /*
  70775. + * Put all channels in the free channel list and clean up channel
  70776. + * states.
  70777. + */
  70778. + DWC_CIRCLEQ_FOREACH_SAFE(channel, channel_tmp,
  70779. + &hcd->free_hc_list, hc_list_entry) {
  70780. + DWC_CIRCLEQ_REMOVE(&hcd->free_hc_list, channel, hc_list_entry);
  70781. + }
  70782. +
  70783. + num_channels = hcd->core_if->core_params->host_channels;
  70784. + for (i = 0; i < num_channels; i++) {
  70785. + channel = hcd->hc_ptr_array[i];
  70786. + DWC_CIRCLEQ_INSERT_TAIL(&hcd->free_hc_list, channel,
  70787. + hc_list_entry);
  70788. + dwc_otg_hc_cleanup(hcd->core_if, channel);
  70789. + }
  70790. +
  70791. + /* Initialize the DWC core for host mode operation. */
  70792. + dwc_otg_core_host_init(hcd->core_if);
  70793. +
  70794. + /* Set core_if's lock pointer to the hcd->lock */
  70795. + hcd->core_if->lock = hcd->lock;
  70796. +}
  70797. +
  70798. +/**
  70799. + * Assigns transactions from a QTD to a free host channel and initializes the
  70800. + * host channel to perform the transactions. The host channel is removed from
  70801. + * the free list.
  70802. + *
  70803. + * @param hcd The HCD state structure.
  70804. + * @param qh Transactions from the first QTD for this QH are selected and
  70805. + * assigned to a free host channel.
  70806. + */
  70807. +static void assign_and_init_hc(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  70808. +{
  70809. + dwc_hc_t *hc;
  70810. + dwc_otg_qtd_t *qtd;
  70811. + dwc_otg_hcd_urb_t *urb;
  70812. + void* ptr = NULL;
  70813. +
  70814. + qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  70815. +
  70816. + urb = qtd->urb;
  70817. +
  70818. + DWC_DEBUGPL(DBG_HCDV, "%s(%p,%p) - urb %x, actual_length %d\n", __func__, hcd, qh, (unsigned int)urb, urb->actual_length);
  70819. +
  70820. + if (((urb->actual_length < 0) || (urb->actual_length > urb->length)) && !dwc_otg_hcd_is_pipe_in(&urb->pipe_info))
  70821. + urb->actual_length = urb->length;
  70822. +
  70823. +
  70824. + hc = DWC_CIRCLEQ_FIRST(&hcd->free_hc_list);
  70825. +
  70826. + /* Remove the host channel from the free list. */
  70827. + DWC_CIRCLEQ_REMOVE_INIT(&hcd->free_hc_list, hc, hc_list_entry);
  70828. +
  70829. + qh->channel = hc;
  70830. +
  70831. + qtd->in_process = 1;
  70832. +
  70833. + /*
  70834. + * Use usb_pipedevice to determine device address. This address is
  70835. + * 0 before the SET_ADDRESS command and the correct address afterward.
  70836. + */
  70837. + hc->dev_addr = dwc_otg_hcd_get_dev_addr(&urb->pipe_info);
  70838. + hc->ep_num = dwc_otg_hcd_get_ep_num(&urb->pipe_info);
  70839. + hc->speed = qh->dev_speed;
  70840. + hc->max_packet = dwc_max_packet(qh->maxp);
  70841. +
  70842. + hc->xfer_started = 0;
  70843. + hc->halt_status = DWC_OTG_HC_XFER_NO_HALT_STATUS;
  70844. + if (!fiq_fsm_enable)
  70845. + hc->error_state = (qtd->error_count > 0);
  70846. + else
  70847. + hc->error_state = 0;
  70848. + hc->halt_on_queue = 0;
  70849. + hc->halt_pending = 0;
  70850. + hc->requests = 0;
  70851. +
  70852. + /*
  70853. + * The following values may be modified in the transfer type section
  70854. + * below. The xfer_len value may be reduced when the transfer is
  70855. + * started to accommodate the max widths of the XferSize and PktCnt
  70856. + * fields in the HCTSIZn register.
  70857. + */
  70858. +
  70859. + hc->ep_is_in = (dwc_otg_hcd_is_pipe_in(&urb->pipe_info) != 0);
  70860. + if (hc->ep_is_in) {
  70861. + hc->do_ping = 0;
  70862. + } else {
  70863. + hc->do_ping = qh->ping_state;
  70864. + }
  70865. +
  70866. + hc->data_pid_start = qh->data_toggle;
  70867. + hc->multi_count = 1;
  70868. +
  70869. + if (hcd->core_if->dma_enable) {
  70870. + hc->xfer_buff = (uint8_t *) urb->dma + urb->actual_length;
  70871. +
  70872. + /* For non-dword aligned case */
  70873. + if (((unsigned long)hc->xfer_buff & 0x3)
  70874. + && !hcd->core_if->dma_desc_enable) {
  70875. + ptr = (uint8_t *) urb->buf + urb->actual_length;
  70876. + }
  70877. + } else {
  70878. + hc->xfer_buff = (uint8_t *) urb->buf + urb->actual_length;
  70879. + }
  70880. + hc->xfer_len = urb->length - urb->actual_length;
  70881. + hc->xfer_count = 0;
  70882. +
  70883. + /*
  70884. + * Set the split attributes
  70885. + */
  70886. + hc->do_split = 0;
  70887. + if (qh->do_split) {
  70888. + uint32_t hub_addr, port_addr;
  70889. + hc->do_split = 1;
  70890. + hc->xact_pos = qtd->isoc_split_pos;
  70891. + /* We don't need to do complete splits anymore */
  70892. +// if(fiq_fsm_enable)
  70893. + if (0)
  70894. + hc->complete_split = qtd->complete_split = 0;
  70895. + else
  70896. + hc->complete_split = qtd->complete_split;
  70897. +
  70898. + hcd->fops->hub_info(hcd, urb->priv, &hub_addr, &port_addr);
  70899. + hc->hub_addr = (uint8_t) hub_addr;
  70900. + hc->port_addr = (uint8_t) port_addr;
  70901. + }
  70902. +
  70903. + switch (dwc_otg_hcd_get_pipe_type(&urb->pipe_info)) {
  70904. + case UE_CONTROL:
  70905. + hc->ep_type = DWC_OTG_EP_TYPE_CONTROL;
  70906. + switch (qtd->control_phase) {
  70907. + case DWC_OTG_CONTROL_SETUP:
  70908. + DWC_DEBUGPL(DBG_HCDV, " Control setup transaction\n");
  70909. + hc->do_ping = 0;
  70910. + hc->ep_is_in = 0;
  70911. + hc->data_pid_start = DWC_OTG_HC_PID_SETUP;
  70912. + if (hcd->core_if->dma_enable) {
  70913. + hc->xfer_buff = (uint8_t *) urb->setup_dma;
  70914. + } else {
  70915. + hc->xfer_buff = (uint8_t *) urb->setup_packet;
  70916. + }
  70917. + hc->xfer_len = 8;
  70918. + ptr = NULL;
  70919. + break;
  70920. + case DWC_OTG_CONTROL_DATA:
  70921. + DWC_DEBUGPL(DBG_HCDV, " Control data transaction\n");
  70922. + hc->data_pid_start = qtd->data_toggle;
  70923. + break;
  70924. + case DWC_OTG_CONTROL_STATUS:
  70925. + /*
  70926. + * Direction is opposite of data direction or IN if no
  70927. + * data.
  70928. + */
  70929. + DWC_DEBUGPL(DBG_HCDV, " Control status transaction\n");
  70930. + if (urb->length == 0) {
  70931. + hc->ep_is_in = 1;
  70932. + } else {
  70933. + hc->ep_is_in =
  70934. + dwc_otg_hcd_is_pipe_out(&urb->pipe_info);
  70935. + }
  70936. + if (hc->ep_is_in) {
  70937. + hc->do_ping = 0;
  70938. + }
  70939. +
  70940. + hc->data_pid_start = DWC_OTG_HC_PID_DATA1;
  70941. +
  70942. + hc->xfer_len = 0;
  70943. + if (hcd->core_if->dma_enable) {
  70944. + hc->xfer_buff = (uint8_t *) hcd->status_buf_dma;
  70945. + } else {
  70946. + hc->xfer_buff = (uint8_t *) hcd->status_buf;
  70947. + }
  70948. + ptr = NULL;
  70949. + break;
  70950. + }
  70951. + break;
  70952. + case UE_BULK:
  70953. + hc->ep_type = DWC_OTG_EP_TYPE_BULK;
  70954. + break;
  70955. + case UE_INTERRUPT:
  70956. + hc->ep_type = DWC_OTG_EP_TYPE_INTR;
  70957. + break;
  70958. + case UE_ISOCHRONOUS:
  70959. + {
  70960. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  70961. +
  70962. + hc->ep_type = DWC_OTG_EP_TYPE_ISOC;
  70963. +
  70964. + if (hcd->core_if->dma_desc_enable)
  70965. + break;
  70966. +
  70967. + frame_desc = &urb->iso_descs[qtd->isoc_frame_index];
  70968. +
  70969. + frame_desc->status = 0;
  70970. +
  70971. + if (hcd->core_if->dma_enable) {
  70972. + hc->xfer_buff = (uint8_t *) urb->dma;
  70973. + } else {
  70974. + hc->xfer_buff = (uint8_t *) urb->buf;
  70975. + }
  70976. + hc->xfer_buff +=
  70977. + frame_desc->offset + qtd->isoc_split_offset;
  70978. + hc->xfer_len =
  70979. + frame_desc->length - qtd->isoc_split_offset;
  70980. +
  70981. + /* For non-dword aligned buffers */
  70982. + if (((unsigned long)hc->xfer_buff & 0x3)
  70983. + && hcd->core_if->dma_enable) {
  70984. + ptr =
  70985. + (uint8_t *) urb->buf + frame_desc->offset +
  70986. + qtd->isoc_split_offset;
  70987. + } else
  70988. + ptr = NULL;
  70989. +
  70990. + if (hc->xact_pos == DWC_HCSPLIT_XACTPOS_ALL) {
  70991. + if (hc->xfer_len <= 188) {
  70992. + hc->xact_pos = DWC_HCSPLIT_XACTPOS_ALL;
  70993. + } else {
  70994. + hc->xact_pos =
  70995. + DWC_HCSPLIT_XACTPOS_BEGIN;
  70996. + }
  70997. + }
  70998. + }
  70999. + break;
  71000. + }
  71001. + /* non DWORD-aligned buffer case */
  71002. + if (ptr) {
  71003. + uint32_t buf_size;
  71004. + if (hc->ep_type != DWC_OTG_EP_TYPE_ISOC) {
  71005. + buf_size = hcd->core_if->core_params->max_transfer_size;
  71006. + } else {
  71007. + buf_size = 4096;
  71008. + }
  71009. + if (!qh->dw_align_buf) {
  71010. + qh->dw_align_buf = DWC_DMA_ALLOC_ATOMIC(buf_size,
  71011. + &qh->dw_align_buf_dma);
  71012. + if (!qh->dw_align_buf) {
  71013. + DWC_ERROR
  71014. + ("%s: Failed to allocate memory to handle "
  71015. + "non-dword aligned buffer case\n",
  71016. + __func__);
  71017. + return;
  71018. + }
  71019. + }
  71020. + if (!hc->ep_is_in) {
  71021. + dwc_memcpy(qh->dw_align_buf, ptr, hc->xfer_len);
  71022. + }
  71023. + hc->align_buff = qh->dw_align_buf_dma;
  71024. + } else {
  71025. + hc->align_buff = 0;
  71026. + }
  71027. +
  71028. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  71029. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  71030. + /*
  71031. + * This value may be modified when the transfer is started to
  71032. + * reflect the actual transfer length.
  71033. + */
  71034. + hc->multi_count = dwc_hb_mult(qh->maxp);
  71035. + }
  71036. +
  71037. + if (hcd->core_if->dma_desc_enable)
  71038. + hc->desc_list_addr = qh->desc_list_dma;
  71039. +
  71040. + dwc_otg_hc_init(hcd->core_if, hc);
  71041. + hc->qh = qh;
  71042. +}
  71043. +
  71044. +
  71045. +/**
  71046. + * fiq_fsm_transaction_suitable() - Test a QH for compatibility with the FIQ
  71047. + * @qh: pointer to the endpoint's queue head
  71048. + *
  71049. + * Transaction start/end control flow is grafted onto the existing dwc_otg
  71050. + * mechanisms, to avoid spaghettifying the functions more than they already are.
  71051. + * This function's eligibility check is altered by debug parameter.
  71052. + *
  71053. + * Returns: 0 for unsuitable, 1 implies the FIQ can be enabled for this transaction.
  71054. + */
  71055. +
  71056. +int fiq_fsm_transaction_suitable(dwc_otg_qh_t *qh)
  71057. +{
  71058. + if (qh->do_split) {
  71059. + switch (qh->ep_type) {
  71060. + case UE_CONTROL:
  71061. + case UE_BULK:
  71062. + if (fiq_fsm_mask & (1 << 0))
  71063. + return 1;
  71064. + break;
  71065. + case UE_INTERRUPT:
  71066. + case UE_ISOCHRONOUS:
  71067. + if (fiq_fsm_mask & (1 << 1))
  71068. + return 1;
  71069. + break;
  71070. + default:
  71071. + break;
  71072. + }
  71073. + } else if (qh->ep_type == UE_ISOCHRONOUS) {
  71074. + if (fiq_fsm_mask & (1 << 2)) {
  71075. + /* HS ISOCH support. We test for compatibility:
  71076. + * - DWORD aligned buffers
  71077. + * - Must be at least 2 transfers (otherwise pointless to use the FIQ)
  71078. + * If yes, then the fsm enqueue function will handle the state machine setup.
  71079. + */
  71080. + dwc_otg_qtd_t *qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  71081. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  71082. + struct dwc_otg_hcd_iso_packet_desc (*iso_descs)[0] = &urb->iso_descs;
  71083. + int nr_iso_frames = urb->packet_count;
  71084. + int i;
  71085. + uint32_t ptr;
  71086. +
  71087. + if (nr_iso_frames < 2)
  71088. + return 0;
  71089. + for (i = 0; i < nr_iso_frames; i++) {
  71090. + ptr = urb->dma + iso_descs[i]->offset;
  71091. + if (ptr & 0x3) {
  71092. + printk_ratelimited("%s: Non-Dword aligned isochronous frame offset."
  71093. + " Cannot queue FIQ-accelerated transfer to device %d endpoint %d\n",
  71094. + __FUNCTION__, qh->channel->dev_addr, qh->channel->ep_num);
  71095. + return 0;
  71096. + }
  71097. + }
  71098. + return 1;
  71099. + }
  71100. + }
  71101. + return 0;
  71102. +}
  71103. +
  71104. +/**
  71105. + * fiq_fsm_setup_periodic_dma() - Set up DMA bounce buffers
  71106. + * @hcd: Pointer to the dwc_otg_hcd struct
  71107. + * @qh: Pointer to the endpoint's queue head
  71108. + *
  71109. + * Periodic split transactions are transmitted modulo 188 bytes.
  71110. + * This necessitates slicing data up into buckets for isochronous out
  71111. + * and fixing up the DMA address for all IN transfers.
  71112. + *
  71113. + * Returns 1 if the DMA bounce buffers have been used, 0 if the default
  71114. + * HC buffer has been used.
  71115. + */
  71116. +int fiq_fsm_setup_periodic_dma(dwc_otg_hcd_t *hcd, struct fiq_channel_state *st, dwc_otg_qh_t *qh)
  71117. + {
  71118. + int i = 0;
  71119. + uint32_t frame_length, nrslots, last_size;
  71120. + uint8_t *ptr = NULL;
  71121. + dwc_hc_t *hc = qh->channel;
  71122. + struct fiq_dma_blob *blob;
  71123. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  71124. +
  71125. +
  71126. + for (i = 0; i < 6; i++) {
  71127. + st->dma_info.slot_len[i] = 255;
  71128. + }
  71129. + st->dma_info.index = 0;
  71130. + i = 0;
  71131. + if (hc->ep_is_in) {
  71132. + /*
  71133. + * Set dma_regs to bounce buffer. FIQ will update the
  71134. + * state depending on transaction progress.
  71135. + */
  71136. + blob = (struct fiq_dma_blob *) hcd->fiq_state->dma_base;
  71137. + st->hcdma_copy.d32 = (uint32_t) &blob->channel[hc->hc_num].index[0].buf[0];
  71138. + return 1;
  71139. + } else {
  71140. + if (qh->ep_type == UE_ISOCHRONOUS) {
  71141. +
  71142. + dwc_otg_qtd_t *qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  71143. +
  71144. + frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  71145. + frame_length = frame_desc->length;
  71146. +
  71147. + /* Virtual address for bounce buffers */
  71148. + blob = hcd->fiq_dmab;
  71149. +
  71150. + ptr = qtd->urb->buf + frame_desc->offset;
  71151. + nrslots = (frame_length + 187) / 188;
  71152. + last_size = frame_length % 188;
  71153. + //printk(KERN_INFO "len = %d nrslots = %d last_size=%d\n", frame_length, nrslots, last_size);
  71154. + if (frame_length == 0) {
  71155. + /*
  71156. + * for isochronous transactions, we must still transmit a packet
  71157. + * even if the length is zero.
  71158. + */
  71159. + st->dma_info.slot_len[0] = 0;
  71160. + st->nrpackets = 1;
  71161. + } else {
  71162. + do {
  71163. + if (i < nrslots - 1) {
  71164. + dwc_memcpy(&blob->channel[hc->hc_num].index[i].buf[0], ptr, 188);
  71165. + st->dma_info.slot_len[i] = 188;
  71166. + ptr += 188;
  71167. + } else {
  71168. + dwc_memcpy(&blob->channel[hc->hc_num].index[i].buf[0], ptr, last_size);
  71169. + st->dma_info.slot_len[i] = last_size;
  71170. + ptr += last_size;
  71171. + }
  71172. + i++;
  71173. + } while (i <= nrslots - 1);
  71174. + st->nrpackets = i;
  71175. + }
  71176. + ptr = qtd->urb->buf + frame_desc->offset;
  71177. + if(DWC_MEMCMP(&blob->channel[hc->hc_num].index[0].buf[0], ptr, frame_length))
  71178. + BUG();
  71179. + /* Point the HC at the DMA address of the bounce buffers */
  71180. + blob = (struct fiq_dma_blob *) hcd->fiq_state->dma_base;
  71181. + /* Bugette: for some reason, memcpy corrupts the data in the bounce buffers. May be a
  71182. + * cache coherency issue */
  71183. + //st->hcdma_copy.d32 = (uint32_t) &blob->channel[hc->hc_num].index[0].buf[0];
  71184. + //ptr = qtd->urb->buf + frame_desc->offset;
  71185. + st->hcdma_copy.d32 = (uint32_t) qtd->urb->dma + frame_desc->offset;
  71186. + if (st->hcdma_copy.d32 & 0x3)
  71187. + BUG();
  71188. + /* fixup xfersize to the actual packet size */
  71189. + st->hctsiz_copy.b.pid = 0;
  71190. + st->hctsiz_copy.b.xfersize = st->dma_info.slot_len[0];
  71191. + return 1;
  71192. + } else {
  71193. + /* For interrupt, single OUT packet required, goes in the SSPLIT from hc_buff. */
  71194. + return 0;
  71195. + }
  71196. + }
  71197. +}
  71198. +
  71199. +/*
  71200. + * Pushing a periodic request into the queue near the EOF1 point
  71201. + * in a microframe causes erroneous behaviour (frmovrun) interrupt.
  71202. + * Usually, the request goes out on the bus causing a transfer but
  71203. + * the core does not transfer the data to memory.
  71204. + * This guard interval (in number of 60MHz clocks) is required which
  71205. + * must cater for CPU latency between reading the value and enabling
  71206. + * the channel.
  71207. + */
  71208. +#define PERIODIC_FRREM_BACKOFF 1000
  71209. +
  71210. +int fiq_fsm_queue_isoc_transaction(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh)
  71211. +{
  71212. + dwc_hc_t *hc = qh->channel;
  71213. + dwc_otg_hc_regs_t *hc_regs = hcd->core_if->host_if->hc_regs[hc->hc_num];
  71214. + dwc_otg_qtd_t *qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  71215. + int frame;
  71216. + struct fiq_channel_state *st = &hcd->fiq_state->channel[hc->hc_num];
  71217. + int xfer_len, nrpackets;
  71218. + hcdma_data_t hcdma;
  71219. + hfnum_data_t hfnum;
  71220. +
  71221. + if (st->fsm != FIQ_PASSTHROUGH)
  71222. + return 0;
  71223. +
  71224. + st->nr_errors = 0;
  71225. +
  71226. + st->hcchar_copy.d32 = 0;
  71227. + st->hcchar_copy.b.mps = hc->max_packet;
  71228. + st->hcchar_copy.b.epdir = hc->ep_is_in;
  71229. + st->hcchar_copy.b.devaddr = hc->dev_addr;
  71230. + st->hcchar_copy.b.epnum = hc->ep_num;
  71231. + st->hcchar_copy.b.eptype = hc->ep_type;
  71232. +
  71233. + st->hcintmsk_copy.b.chhltd = 1;
  71234. +
  71235. + frame = dwc_otg_hcd_get_frame_number(hcd);
  71236. + st->hcchar_copy.b.oddfrm = (frame & 0x1) ? 0 : 1;
  71237. +
  71238. + st->hcchar_copy.b.lspddev = 0;
  71239. + /* Enable the channel later as a final register write. */
  71240. +
  71241. + st->hcsplt_copy.d32 = 0;
  71242. +
  71243. + st->hs_isoc_info.iso_desc = (struct dwc_otg_hcd_iso_packet_desc *) &qtd->urb->iso_descs;
  71244. + st->hs_isoc_info.nrframes = qtd->urb->packet_count;
  71245. + /* grab the next DMA address offset from the array */
  71246. + st->hcdma_copy.d32 = qtd->urb->dma;
  71247. + hcdma.d32 = st->hcdma_copy.d32 + st->hs_isoc_info.iso_desc[0].offset;
  71248. +
  71249. + /* We need to set multi_count. This is a bit tricky - has to be set per-transaction as
  71250. + * the core needs to be told to send the correct number. Caution: for IN transfers,
  71251. + * this is always set to the maximum size of the endpoint. */
  71252. + xfer_len = st->hs_isoc_info.iso_desc[0].length;
  71253. + nrpackets = (xfer_len + st->hcchar_copy.b.mps - 1) / st->hcchar_copy.b.mps;
  71254. + if (nrpackets == 0)
  71255. + nrpackets = 1;
  71256. + st->hcchar_copy.b.multicnt = nrpackets;
  71257. + st->hctsiz_copy.b.pktcnt = nrpackets;
  71258. +
  71259. + /* Initial PID also needs to be set */
  71260. + if (st->hcchar_copy.b.epdir == 0) {
  71261. + st->hctsiz_copy.b.xfersize = xfer_len;
  71262. + switch (st->hcchar_copy.b.multicnt) {
  71263. + case 1:
  71264. + st->hctsiz_copy.b.pid = DWC_PID_DATA0;
  71265. + break;
  71266. + case 2:
  71267. + case 3:
  71268. + st->hctsiz_copy.b.pid = DWC_PID_MDATA;
  71269. + break;
  71270. + }
  71271. +
  71272. + } else {
  71273. + st->hctsiz_copy.b.xfersize = nrpackets * st->hcchar_copy.b.mps;
  71274. + switch (st->hcchar_copy.b.multicnt) {
  71275. + case 1:
  71276. + st->hctsiz_copy.b.pid = DWC_PID_DATA0;
  71277. + break;
  71278. + case 2:
  71279. + st->hctsiz_copy.b.pid = DWC_PID_DATA1;
  71280. + break;
  71281. + case 3:
  71282. + st->hctsiz_copy.b.pid = DWC_PID_DATA2;
  71283. + break;
  71284. + }
  71285. + }
  71286. +
  71287. + fiq_print(FIQDBG_INT, hcd->fiq_state, "FSMQ %01d ", hc->hc_num);
  71288. + fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hcchar_copy.d32);
  71289. + fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hctsiz_copy.d32);
  71290. + fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hcdma_copy.d32);
  71291. + hfnum.d32 = DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hfnum);
  71292. + local_fiq_disable();
  71293. + DWC_WRITE_REG32(&hc_regs->hctsiz, st->hctsiz_copy.d32);
  71294. + DWC_WRITE_REG32(&hc_regs->hcsplt, st->hcsplt_copy.d32);
  71295. + DWC_WRITE_REG32(&hc_regs->hcdma, st->hcdma_copy.d32);
  71296. + DWC_WRITE_REG32(&hc_regs->hcchar, st->hcchar_copy.d32);
  71297. + DWC_WRITE_REG32(&hc_regs->hcintmsk, st->hcintmsk_copy.d32);
  71298. + if (hfnum.b.frrem < PERIODIC_FRREM_BACKOFF) {
  71299. + /* Prevent queueing near EOF1. Bad things happen if a periodic
  71300. + * split transaction is queued very close to EOF.
  71301. + */
  71302. + st->fsm = FIQ_HS_ISOC_SLEEPING;
  71303. + } else {
  71304. + st->fsm = FIQ_HS_ISOC_TURBO;
  71305. + st->hcchar_copy.b.chen = 1;
  71306. + DWC_WRITE_REG32(&hc_regs->hcchar, st->hcchar_copy.d32);
  71307. + }
  71308. + mb();
  71309. + st->hcchar_copy.b.chen = 0;
  71310. + local_fiq_enable();
  71311. + return 0;
  71312. +}
  71313. +
  71314. +
  71315. +/**
  71316. + * fiq_fsm_queue_split_transaction() - Set up a host channel and FIQ state
  71317. + * @hcd: Pointer to the dwc_otg_hcd struct
  71318. + * @qh: Pointer to the endpoint's queue head
  71319. + *
  71320. + * This overrides the dwc_otg driver's normal method of queueing a transaction.
  71321. + * Called from dwc_otg_hcd_queue_transactions(), this performs specific setup
  71322. + * for the nominated host channel.
  71323. + *
  71324. + * For periodic transfers, it also peeks at the FIQ state to see if an immediate
  71325. + * start is possible. If not, then the FIQ is left to start the transfer.
  71326. + */
  71327. +int fiq_fsm_queue_split_transaction(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh)
  71328. +{
  71329. + int start_immediate = 1, i;
  71330. + hfnum_data_t hfnum;
  71331. + dwc_hc_t *hc = qh->channel;
  71332. + dwc_otg_hc_regs_t *hc_regs = hcd->core_if->host_if->hc_regs[hc->hc_num];
  71333. + /* Program HC registers, setup FIQ_state, examine FIQ if periodic, start transfer (not if uframe 5) */
  71334. + int hub_addr, port_addr, frame, uframe;
  71335. + struct fiq_channel_state *st = &hcd->fiq_state->channel[hc->hc_num];
  71336. +
  71337. + if (st->fsm != FIQ_PASSTHROUGH)
  71338. + return 0;
  71339. + st->nr_errors = 0;
  71340. +
  71341. + st->hcchar_copy.d32 = 0;
  71342. + st->hcchar_copy.b.mps = hc->max_packet;
  71343. + st->hcchar_copy.b.epdir = hc->ep_is_in;
  71344. + st->hcchar_copy.b.devaddr = hc->dev_addr;
  71345. + st->hcchar_copy.b.epnum = hc->ep_num;
  71346. + st->hcchar_copy.b.eptype = hc->ep_type;
  71347. + if (hc->ep_type & 0x1) {
  71348. + if (hc->ep_is_in)
  71349. + st->hcchar_copy.b.multicnt = 3;
  71350. + else
  71351. + /* Docs say set this to 1, but driver sets to 0! */
  71352. + st->hcchar_copy.b.multicnt = 0;
  71353. + } else {
  71354. + st->hcchar_copy.b.multicnt = 1;
  71355. + st->hcchar_copy.b.oddfrm = 0;
  71356. + }
  71357. + st->hcchar_copy.b.lspddev = (hc->speed == DWC_OTG_EP_SPEED_LOW) ? 1 : 0;
  71358. + /* Enable the channel later as a final register write. */
  71359. +
  71360. + st->hcsplt_copy.d32 = 0;
  71361. + if(qh->do_split) {
  71362. + hcd->fops->hub_info(hcd, DWC_CIRCLEQ_FIRST(&qh->qtd_list)->urb->priv, &hub_addr, &port_addr);
  71363. + st->hcsplt_copy.b.compsplt = 0;
  71364. + st->hcsplt_copy.b.spltena = 1;
  71365. + // XACTPOS is for isoc-out only but needs initialising anyway.
  71366. + st->hcsplt_copy.b.xactpos = ISOC_XACTPOS_ALL;
  71367. + if((qh->ep_type == DWC_OTG_EP_TYPE_ISOC) && (!qh->ep_is_in)) {
  71368. + /* For packetsize 0 < L < 188, ISOC_XACTPOS_ALL.
  71369. + * for longer than this, ISOC_XACTPOS_BEGIN and the FIQ
  71370. + * will update as necessary.
  71371. + */
  71372. + if (hc->xfer_len > 188) {
  71373. + st->hcsplt_copy.b.xactpos = ISOC_XACTPOS_BEGIN;
  71374. + }
  71375. + }
  71376. + st->hcsplt_copy.b.hubaddr = (uint8_t) hub_addr;
  71377. + st->hcsplt_copy.b.prtaddr = (uint8_t) port_addr;
  71378. + st->hub_addr = hub_addr;
  71379. + st->port_addr = port_addr;
  71380. + }
  71381. +
  71382. + st->hctsiz_copy.d32 = 0;
  71383. + st->hctsiz_copy.b.dopng = 0;
  71384. + st->hctsiz_copy.b.pid = hc->data_pid_start;
  71385. +
  71386. + if (hc->ep_is_in || (hc->xfer_len > hc->max_packet)) {
  71387. + hc->xfer_len = hc->max_packet;
  71388. + } else if (!hc->ep_is_in && (hc->xfer_len > 188)) {
  71389. + hc->xfer_len = 188;
  71390. + }
  71391. + st->hctsiz_copy.b.xfersize = hc->xfer_len;
  71392. +
  71393. + st->hctsiz_copy.b.pktcnt = 1;
  71394. +
  71395. + if (hc->ep_type & 0x1) {
  71396. + /*
  71397. + * For potentially multi-packet transfers, must use the DMA bounce buffers. For IN transfers,
  71398. + * the DMA address is the address of the first 188byte slot buffer in the bounce buffer array.
  71399. + * For multi-packet OUT transfers, we need to copy the data into the bounce buffer array so the FIQ can punt
  71400. + * the right address out as necessary. hc->xfer_buff and hc->xfer_len have already been set
  71401. + * in assign_and_init_hc(), but this is for the eventual transaction completion only. The FIQ
  71402. + * must not touch internal driver state.
  71403. + */
  71404. + if(!fiq_fsm_setup_periodic_dma(hcd, st, qh)) {
  71405. + if (hc->align_buff) {
  71406. + st->hcdma_copy.d32 = hc->align_buff;
  71407. + } else {
  71408. + st->hcdma_copy.d32 = ((unsigned long) hc->xfer_buff & 0xFFFFFFFF);
  71409. + }
  71410. + }
  71411. + } else {
  71412. + if (hc->align_buff) {
  71413. + st->hcdma_copy.d32 = hc->align_buff;
  71414. + } else {
  71415. + st->hcdma_copy.d32 = ((unsigned long) hc->xfer_buff & 0xFFFFFFFF);
  71416. + }
  71417. + }
  71418. + /* The FIQ depends upon no other interrupts being enabled except channel halt.
  71419. + * Fixup channel interrupt mask. */
  71420. + st->hcintmsk_copy.d32 = 0;
  71421. + st->hcintmsk_copy.b.chhltd = 1;
  71422. + st->hcintmsk_copy.b.ahberr = 1;
  71423. +
  71424. + DWC_WRITE_REG32(&hc_regs->hcdma, st->hcdma_copy.d32);
  71425. + DWC_WRITE_REG32(&hc_regs->hctsiz, st->hctsiz_copy.d32);
  71426. + DWC_WRITE_REG32(&hc_regs->hcsplt, st->hcsplt_copy.d32);
  71427. + DWC_WRITE_REG32(&hc_regs->hcchar, st->hcchar_copy.d32);
  71428. + DWC_WRITE_REG32(&hc_regs->hcintmsk, st->hcintmsk_copy.d32);
  71429. +
  71430. + local_fiq_disable();
  71431. + mb();
  71432. +
  71433. + if (hc->ep_type & 0x1) {
  71434. + hfnum.d32 = DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hfnum);
  71435. + frame = (hfnum.b.frnum & ~0x7) >> 3;
  71436. + uframe = hfnum.b.frnum & 0x7;
  71437. + if (hfnum.b.frrem < PERIODIC_FRREM_BACKOFF) {
  71438. + /* Prevent queueing near EOF1. Bad things happen if a periodic
  71439. + * split transaction is queued very close to EOF.
  71440. + */
  71441. + start_immediate = 0;
  71442. + } else if (uframe == 5) {
  71443. + start_immediate = 0;
  71444. + } else if (hc->ep_type == UE_ISOCHRONOUS) {
  71445. + start_immediate = 0;
  71446. + } else {
  71447. + /* Search through all host channels to determine if a transaction
  71448. + * is currently in progress */
  71449. + for (i = 0; i < hcd->core_if->core_params->host_channels; i++) {
  71450. + if (i == hc->hc_num || hcd->fiq_state->channel[i].fsm == FIQ_PASSTHROUGH)
  71451. + continue;
  71452. + switch (hcd->fiq_state->channel[i].fsm) {
  71453. + /* TT is reserved for channels that are in the middle of a periodic
  71454. + * split transaction.
  71455. + */
  71456. + case FIQ_PER_SSPLIT_STARTED:
  71457. + case FIQ_PER_CSPLIT_WAIT:
  71458. + case FIQ_PER_CSPLIT_NYET1:
  71459. + case FIQ_PER_CSPLIT_POLL:
  71460. + case FIQ_PER_ISO_OUT_ACTIVE:
  71461. + case FIQ_PER_ISO_OUT_LAST:
  71462. + if (hcd->fiq_state->channel[i].hub_addr == hub_addr &&
  71463. + hcd->fiq_state->channel[i].port_addr == port_addr) {
  71464. + start_immediate = 0;
  71465. + }
  71466. + break;
  71467. + default:
  71468. + break;
  71469. + }
  71470. + if (!start_immediate)
  71471. + break;
  71472. + }
  71473. + }
  71474. + }
  71475. + fiq_print(FIQDBG_INT, hcd->fiq_state, "FSMQ %01d %01d", hc->hc_num, start_immediate);
  71476. + fiq_print(FIQDBG_INT, hcd->fiq_state, "%08d", hfnum.b.frrem);
  71477. + //fiq_print(FIQDBG_INT, hcd->fiq_state, "H:%02dP:%02d", hub_addr, port_addr);
  71478. + //fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hctsiz_copy.d32);
  71479. + //fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hcdma_copy.d32);
  71480. + switch (hc->ep_type) {
  71481. + case UE_CONTROL:
  71482. + case UE_BULK:
  71483. + st->fsm = FIQ_NP_SSPLIT_STARTED;
  71484. + break;
  71485. + case UE_ISOCHRONOUS:
  71486. + if (hc->ep_is_in) {
  71487. + if (start_immediate) {
  71488. + st->fsm = FIQ_PER_SSPLIT_STARTED;
  71489. + } else {
  71490. + st->fsm = FIQ_PER_SSPLIT_QUEUED;
  71491. + }
  71492. + } else {
  71493. + if (start_immediate) {
  71494. + /* Single-isoc OUT packets don't require FIQ involvement */
  71495. + if (st->nrpackets == 1) {
  71496. + st->fsm = FIQ_PER_ISO_OUT_LAST;
  71497. + } else {
  71498. + st->fsm = FIQ_PER_ISO_OUT_ACTIVE;
  71499. + }
  71500. + } else {
  71501. + st->fsm = FIQ_PER_ISO_OUT_PENDING;
  71502. + }
  71503. + }
  71504. + break;
  71505. + case UE_INTERRUPT:
  71506. + if (start_immediate) {
  71507. + st->fsm = FIQ_PER_SSPLIT_STARTED;
  71508. + } else {
  71509. + st->fsm = FIQ_PER_SSPLIT_QUEUED;
  71510. + }
  71511. + default:
  71512. + break;
  71513. + }
  71514. + if (start_immediate) {
  71515. + /* Set the oddfrm bit as close as possible to actual queueing */
  71516. + frame = dwc_otg_hcd_get_frame_number(hcd);
  71517. + st->expected_uframe = (frame + 1) & 0x3FFF;
  71518. + st->hcchar_copy.b.oddfrm = (frame & 0x1) ? 0 : 1;
  71519. + st->hcchar_copy.b.chen = 1;
  71520. + DWC_WRITE_REG32(&hc_regs->hcchar, st->hcchar_copy.d32);
  71521. + }
  71522. + mb();
  71523. + local_fiq_enable();
  71524. + return 0;
  71525. +}
  71526. +
  71527. +
  71528. +/**
  71529. + * This function selects transactions from the HCD transfer schedule and
  71530. + * assigns them to available host channels. It is called from HCD interrupt
  71531. + * handler functions.
  71532. + *
  71533. + * @param hcd The HCD state structure.
  71534. + *
  71535. + * @return The types of new transactions that were assigned to host channels.
  71536. + */
  71537. +dwc_otg_transaction_type_e dwc_otg_hcd_select_transactions(dwc_otg_hcd_t * hcd)
  71538. +{
  71539. + dwc_list_link_t *qh_ptr;
  71540. + dwc_otg_qh_t *qh;
  71541. + int num_channels;
  71542. + dwc_irqflags_t flags;
  71543. + dwc_spinlock_t *channel_lock = hcd->channel_lock;
  71544. + dwc_otg_transaction_type_e ret_val = DWC_OTG_TRANSACTION_NONE;
  71545. +
  71546. +#ifdef DEBUG_HOST_CHANNELS
  71547. + last_sel_trans_num_per_scheduled = 0;
  71548. + last_sel_trans_num_nonper_scheduled = 0;
  71549. + last_sel_trans_num_avail_hc_at_start = hcd->available_host_channels;
  71550. +#endif /* DEBUG_HOST_CHANNELS */
  71551. +
  71552. + /* Process entries in the periodic ready list. */
  71553. + qh_ptr = DWC_LIST_FIRST(&hcd->periodic_sched_ready);
  71554. +
  71555. + while (qh_ptr != &hcd->periodic_sched_ready &&
  71556. + !DWC_CIRCLEQ_EMPTY(&hcd->free_hc_list)) {
  71557. +
  71558. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  71559. +
  71560. + if (microframe_schedule) {
  71561. + // Make sure we leave one channel for non periodic transactions.
  71562. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  71563. + if (hcd->available_host_channels <= 1) {
  71564. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  71565. + break;
  71566. + }
  71567. + hcd->available_host_channels--;
  71568. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  71569. +#ifdef DEBUG_HOST_CHANNELS
  71570. + last_sel_trans_num_per_scheduled++;
  71571. +#endif /* DEBUG_HOST_CHANNELS */
  71572. + }
  71573. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  71574. + assign_and_init_hc(hcd, qh);
  71575. +
  71576. + /*
  71577. + * Move the QH from the periodic ready schedule to the
  71578. + * periodic assigned schedule.
  71579. + */
  71580. + qh_ptr = DWC_LIST_NEXT(qh_ptr);
  71581. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  71582. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_assigned,
  71583. + &qh->qh_list_entry);
  71584. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  71585. + }
  71586. +
  71587. + /*
  71588. + * Process entries in the inactive portion of the non-periodic
  71589. + * schedule. Some free host channels may not be used if they are
  71590. + * reserved for periodic transfers.
  71591. + */
  71592. + qh_ptr = hcd->non_periodic_sched_inactive.next;
  71593. + num_channels = hcd->core_if->core_params->host_channels;
  71594. + while (qh_ptr != &hcd->non_periodic_sched_inactive &&
  71595. + (microframe_schedule || hcd->non_periodic_channels <
  71596. + num_channels - hcd->periodic_channels) &&
  71597. + !DWC_CIRCLEQ_EMPTY(&hcd->free_hc_list)) {
  71598. +
  71599. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  71600. + /*
  71601. + * Check to see if this is a NAK'd retransmit, in which case ignore for retransmission
  71602. + * we hold off on bulk retransmissions to reduce NAK interrupt overhead for full-speed
  71603. + * cheeky devices that just hold off using NAKs
  71604. + */
  71605. + if (nak_holdoff && qh->do_split) {
  71606. + if (qh->nak_frame != 0xffff) {
  71607. + uint16_t next_frame = dwc_frame_num_inc(qh->nak_frame, (qh->ep_type == UE_BULK) ? nak_holdoff : 8);
  71608. + uint16_t frame = dwc_otg_hcd_get_frame_number(hcd);
  71609. + if (dwc_frame_num_le(frame, next_frame)) {
  71610. + if(dwc_frame_num_le(next_frame, hcd->fiq_state->next_sched_frame)) {
  71611. + hcd->fiq_state->next_sched_frame = next_frame;
  71612. + }
  71613. + qh_ptr = DWC_LIST_NEXT(qh_ptr);
  71614. + continue;
  71615. + } else {
  71616. + qh->nak_frame = 0xFFFF;
  71617. + }
  71618. + }
  71619. + }
  71620. +
  71621. + if (microframe_schedule) {
  71622. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  71623. + if (hcd->available_host_channels < 1) {
  71624. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  71625. + break;
  71626. + }
  71627. + hcd->available_host_channels--;
  71628. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  71629. +#ifdef DEBUG_HOST_CHANNELS
  71630. + last_sel_trans_num_nonper_scheduled++;
  71631. +#endif /* DEBUG_HOST_CHANNELS */
  71632. + }
  71633. +
  71634. + assign_and_init_hc(hcd, qh);
  71635. +
  71636. + /*
  71637. + * Move the QH from the non-periodic inactive schedule to the
  71638. + * non-periodic active schedule.
  71639. + */
  71640. + qh_ptr = DWC_LIST_NEXT(qh_ptr);
  71641. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  71642. + DWC_LIST_MOVE_HEAD(&hcd->non_periodic_sched_active,
  71643. + &qh->qh_list_entry);
  71644. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  71645. +
  71646. +
  71647. + if (!microframe_schedule)
  71648. + hcd->non_periodic_channels++;
  71649. + }
  71650. + /* we moved a non-periodic QH to the active schedule. If the inactive queue is empty,
  71651. + * stop the FIQ from kicking us. We could potentially still have elements here if we
  71652. + * ran out of host channels.
  71653. + */
  71654. + if (DWC_LIST_EMPTY(&hcd->non_periodic_sched_inactive)) {
  71655. + hcd->fiq_state->kick_np_queues = 0;
  71656. + } else {
  71657. + /* For each entry remaining in the NP inactive queue,
  71658. + * if this a NAK'd retransmit then don't set the kick flag.
  71659. + */
  71660. + if(nak_holdoff) {
  71661. + DWC_LIST_FOREACH(qh_ptr, &hcd->non_periodic_sched_inactive) {
  71662. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  71663. + if (qh->nak_frame == 0xFFFF) {
  71664. + hcd->fiq_state->kick_np_queues = 1;
  71665. + }
  71666. + }
  71667. + }
  71668. + }
  71669. + if(!DWC_LIST_EMPTY(&hcd->periodic_sched_assigned))
  71670. + ret_val |= DWC_OTG_TRANSACTION_PERIODIC;
  71671. +
  71672. + if(!DWC_LIST_EMPTY(&hcd->non_periodic_sched_active))
  71673. + ret_val |= DWC_OTG_TRANSACTION_NON_PERIODIC;
  71674. +
  71675. +
  71676. +#ifdef DEBUG_HOST_CHANNELS
  71677. + last_sel_trans_num_avail_hc_at_end = hcd->available_host_channels;
  71678. +#endif /* DEBUG_HOST_CHANNELS */
  71679. + return ret_val;
  71680. +}
  71681. +
  71682. +/**
  71683. + * Attempts to queue a single transaction request for a host channel
  71684. + * associated with either a periodic or non-periodic transfer. This function
  71685. + * assumes that there is space available in the appropriate request queue. For
  71686. + * an OUT transfer or SETUP transaction in Slave mode, it checks whether space
  71687. + * is available in the appropriate Tx FIFO.
  71688. + *
  71689. + * @param hcd The HCD state structure.
  71690. + * @param hc Host channel descriptor associated with either a periodic or
  71691. + * non-periodic transfer.
  71692. + * @param fifo_dwords_avail Number of DWORDs available in the periodic Tx
  71693. + * FIFO for periodic transfers or the non-periodic Tx FIFO for non-periodic
  71694. + * transfers.
  71695. + *
  71696. + * @return 1 if a request is queued and more requests may be needed to
  71697. + * complete the transfer, 0 if no more requests are required for this
  71698. + * transfer, -1 if there is insufficient space in the Tx FIFO.
  71699. + */
  71700. +static int queue_transaction(dwc_otg_hcd_t * hcd,
  71701. + dwc_hc_t * hc, uint16_t fifo_dwords_avail)
  71702. +{
  71703. + int retval;
  71704. +
  71705. + if (hcd->core_if->dma_enable) {
  71706. + if (hcd->core_if->dma_desc_enable) {
  71707. + if (!hc->xfer_started
  71708. + || (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)) {
  71709. + dwc_otg_hcd_start_xfer_ddma(hcd, hc->qh);
  71710. + hc->qh->ping_state = 0;
  71711. + }
  71712. + } else if (!hc->xfer_started) {
  71713. + dwc_otg_hc_start_transfer(hcd->core_if, hc);
  71714. + hc->qh->ping_state = 0;
  71715. + }
  71716. + retval = 0;
  71717. + } else if (hc->halt_pending) {
  71718. + /* Don't queue a request if the channel has been halted. */
  71719. + retval = 0;
  71720. + } else if (hc->halt_on_queue) {
  71721. + dwc_otg_hc_halt(hcd->core_if, hc, hc->halt_status);
  71722. + retval = 0;
  71723. + } else if (hc->do_ping) {
  71724. + if (!hc->xfer_started) {
  71725. + dwc_otg_hc_start_transfer(hcd->core_if, hc);
  71726. + }
  71727. + retval = 0;
  71728. + } else if (!hc->ep_is_in || hc->data_pid_start == DWC_OTG_HC_PID_SETUP) {
  71729. + if ((fifo_dwords_avail * 4) >= hc->max_packet) {
  71730. + if (!hc->xfer_started) {
  71731. + dwc_otg_hc_start_transfer(hcd->core_if, hc);
  71732. + retval = 1;
  71733. + } else {
  71734. + retval =
  71735. + dwc_otg_hc_continue_transfer(hcd->core_if,
  71736. + hc);
  71737. + }
  71738. + } else {
  71739. + retval = -1;
  71740. + }
  71741. + } else {
  71742. + if (!hc->xfer_started) {
  71743. + dwc_otg_hc_start_transfer(hcd->core_if, hc);
  71744. + retval = 1;
  71745. + } else {
  71746. + retval = dwc_otg_hc_continue_transfer(hcd->core_if, hc);
  71747. + }
  71748. + }
  71749. +
  71750. + return retval;
  71751. +}
  71752. +
  71753. +/**
  71754. + * Processes periodic channels for the next frame and queues transactions for
  71755. + * these channels to the DWC_otg controller. After queueing transactions, the
  71756. + * Periodic Tx FIFO Empty interrupt is enabled if there are more transactions
  71757. + * to queue as Periodic Tx FIFO or request queue space becomes available.
  71758. + * Otherwise, the Periodic Tx FIFO Empty interrupt is disabled.
  71759. + */
  71760. +static void process_periodic_channels(dwc_otg_hcd_t * hcd)
  71761. +{
  71762. + hptxsts_data_t tx_status;
  71763. + dwc_list_link_t *qh_ptr;
  71764. + dwc_otg_qh_t *qh;
  71765. + int status = 0;
  71766. + int no_queue_space = 0;
  71767. + int no_fifo_space = 0;
  71768. +
  71769. + dwc_otg_host_global_regs_t *host_regs;
  71770. + host_regs = hcd->core_if->host_if->host_global_regs;
  71771. +
  71772. + DWC_DEBUGPL(DBG_HCDV, "Queue periodic transactions\n");
  71773. +#ifdef DEBUG
  71774. + tx_status.d32 = DWC_READ_REG32(&host_regs->hptxsts);
  71775. + DWC_DEBUGPL(DBG_HCDV,
  71776. + " P Tx Req Queue Space Avail (before queue): %d\n",
  71777. + tx_status.b.ptxqspcavail);
  71778. + DWC_DEBUGPL(DBG_HCDV, " P Tx FIFO Space Avail (before queue): %d\n",
  71779. + tx_status.b.ptxfspcavail);
  71780. +#endif
  71781. +
  71782. + qh_ptr = hcd->periodic_sched_assigned.next;
  71783. + while (qh_ptr != &hcd->periodic_sched_assigned) {
  71784. + tx_status.d32 = DWC_READ_REG32(&host_regs->hptxsts);
  71785. + if (tx_status.b.ptxqspcavail == 0) {
  71786. + no_queue_space = 1;
  71787. + break;
  71788. + }
  71789. +
  71790. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  71791. +
  71792. + // Do not send a split start transaction any later than frame .6
  71793. + // Note, we have to schedule a periodic in .5 to make it go in .6
  71794. + if(fiq_fsm_enable && qh->do_split && ((dwc_otg_hcd_get_frame_number(hcd) + 1) & 7) > 6)
  71795. + {
  71796. + qh_ptr = qh_ptr->next;
  71797. + hcd->fiq_state->next_sched_frame = dwc_otg_hcd_get_frame_number(hcd) | 7;
  71798. + continue;
  71799. + }
  71800. +
  71801. + if (fiq_fsm_enable && fiq_fsm_transaction_suitable(qh)) {
  71802. + if (qh->do_split)
  71803. + fiq_fsm_queue_split_transaction(hcd, qh);
  71804. + else
  71805. + fiq_fsm_queue_isoc_transaction(hcd, qh);
  71806. + } else {
  71807. +
  71808. + /*
  71809. + * Set a flag if we're queueing high-bandwidth in slave mode.
  71810. + * The flag prevents any halts to get into the request queue in
  71811. + * the middle of multiple high-bandwidth packets getting queued.
  71812. + */
  71813. + if (!hcd->core_if->dma_enable && qh->channel->multi_count > 1) {
  71814. + hcd->core_if->queuing_high_bandwidth = 1;
  71815. + }
  71816. + status = queue_transaction(hcd, qh->channel,
  71817. + tx_status.b.ptxfspcavail);
  71818. + if (status < 0) {
  71819. + no_fifo_space = 1;
  71820. + break;
  71821. + }
  71822. + }
  71823. +
  71824. + /*
  71825. + * In Slave mode, stay on the current transfer until there is
  71826. + * nothing more to do or the high-bandwidth request count is
  71827. + * reached. In DMA mode, only need to queue one request. The
  71828. + * controller automatically handles multiple packets for
  71829. + * high-bandwidth transfers.
  71830. + */
  71831. + if (hcd->core_if->dma_enable || status == 0 ||
  71832. + qh->channel->requests == qh->channel->multi_count) {
  71833. + qh_ptr = qh_ptr->next;
  71834. + /*
  71835. + * Move the QH from the periodic assigned schedule to
  71836. + * the periodic queued schedule.
  71837. + */
  71838. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_queued,
  71839. + &qh->qh_list_entry);
  71840. +
  71841. + /* done queuing high bandwidth */
  71842. + hcd->core_if->queuing_high_bandwidth = 0;
  71843. + }
  71844. + }
  71845. +
  71846. + if (!hcd->core_if->dma_enable) {
  71847. + dwc_otg_core_global_regs_t *global_regs;
  71848. + gintmsk_data_t intr_mask = {.d32 = 0 };
  71849. +
  71850. + global_regs = hcd->core_if->core_global_regs;
  71851. + intr_mask.b.ptxfempty = 1;
  71852. +#ifdef DEBUG
  71853. + tx_status.d32 = DWC_READ_REG32(&host_regs->hptxsts);
  71854. + DWC_DEBUGPL(DBG_HCDV,
  71855. + " P Tx Req Queue Space Avail (after queue): %d\n",
  71856. + tx_status.b.ptxqspcavail);
  71857. + DWC_DEBUGPL(DBG_HCDV,
  71858. + " P Tx FIFO Space Avail (after queue): %d\n",
  71859. + tx_status.b.ptxfspcavail);
  71860. +#endif
  71861. + if (!DWC_LIST_EMPTY(&hcd->periodic_sched_assigned) ||
  71862. + no_queue_space || no_fifo_space) {
  71863. + /*
  71864. + * May need to queue more transactions as the request
  71865. + * queue or Tx FIFO empties. Enable the periodic Tx
  71866. + * FIFO empty interrupt. (Always use the half-empty
  71867. + * level to ensure that new requests are loaded as
  71868. + * soon as possible.)
  71869. + */
  71870. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0,
  71871. + intr_mask.d32);
  71872. + } else {
  71873. + /*
  71874. + * Disable the Tx FIFO empty interrupt since there are
  71875. + * no more transactions that need to be queued right
  71876. + * now. This function is called from interrupt
  71877. + * handlers to queue more transactions as transfer
  71878. + * states change.
  71879. + */
  71880. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32,
  71881. + 0);
  71882. + }
  71883. + }
  71884. +}
  71885. +
  71886. +/**
  71887. + * Processes active non-periodic channels and queues transactions for these
  71888. + * channels to the DWC_otg controller. After queueing transactions, the NP Tx
  71889. + * FIFO Empty interrupt is enabled if there are more transactions to queue as
  71890. + * NP Tx FIFO or request queue space becomes available. Otherwise, the NP Tx
  71891. + * FIFO Empty interrupt is disabled.
  71892. + */
  71893. +static void process_non_periodic_channels(dwc_otg_hcd_t * hcd)
  71894. +{
  71895. + gnptxsts_data_t tx_status;
  71896. + dwc_list_link_t *orig_qh_ptr;
  71897. + dwc_otg_qh_t *qh;
  71898. + int status;
  71899. + int no_queue_space = 0;
  71900. + int no_fifo_space = 0;
  71901. + int more_to_do = 0;
  71902. +
  71903. + dwc_otg_core_global_regs_t *global_regs =
  71904. + hcd->core_if->core_global_regs;
  71905. +
  71906. + DWC_DEBUGPL(DBG_HCDV, "Queue non-periodic transactions\n");
  71907. +#ifdef DEBUG
  71908. + tx_status.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  71909. + DWC_DEBUGPL(DBG_HCDV,
  71910. + " NP Tx Req Queue Space Avail (before queue): %d\n",
  71911. + tx_status.b.nptxqspcavail);
  71912. + DWC_DEBUGPL(DBG_HCDV, " NP Tx FIFO Space Avail (before queue): %d\n",
  71913. + tx_status.b.nptxfspcavail);
  71914. +#endif
  71915. + /*
  71916. + * Keep track of the starting point. Skip over the start-of-list
  71917. + * entry.
  71918. + */
  71919. + if (hcd->non_periodic_qh_ptr == &hcd->non_periodic_sched_active) {
  71920. + hcd->non_periodic_qh_ptr = hcd->non_periodic_qh_ptr->next;
  71921. + }
  71922. + orig_qh_ptr = hcd->non_periodic_qh_ptr;
  71923. +
  71924. + /*
  71925. + * Process once through the active list or until no more space is
  71926. + * available in the request queue or the Tx FIFO.
  71927. + */
  71928. + do {
  71929. + tx_status.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  71930. + if (!hcd->core_if->dma_enable && tx_status.b.nptxqspcavail == 0) {
  71931. + no_queue_space = 1;
  71932. + break;
  71933. + }
  71934. +
  71935. + qh = DWC_LIST_ENTRY(hcd->non_periodic_qh_ptr, dwc_otg_qh_t,
  71936. + qh_list_entry);
  71937. +
  71938. + if(fiq_fsm_enable && fiq_fsm_transaction_suitable(qh)) {
  71939. + fiq_fsm_queue_split_transaction(hcd, qh);
  71940. + } else {
  71941. + status = queue_transaction(hcd, qh->channel,
  71942. + tx_status.b.nptxfspcavail);
  71943. +
  71944. + if (status > 0) {
  71945. + more_to_do = 1;
  71946. + } else if (status < 0) {
  71947. + no_fifo_space = 1;
  71948. + break;
  71949. + }
  71950. + }
  71951. + /* Advance to next QH, skipping start-of-list entry. */
  71952. + hcd->non_periodic_qh_ptr = hcd->non_periodic_qh_ptr->next;
  71953. + if (hcd->non_periodic_qh_ptr == &hcd->non_periodic_sched_active) {
  71954. + hcd->non_periodic_qh_ptr =
  71955. + hcd->non_periodic_qh_ptr->next;
  71956. + }
  71957. +
  71958. + } while (hcd->non_periodic_qh_ptr != orig_qh_ptr);
  71959. +
  71960. + if (!hcd->core_if->dma_enable) {
  71961. + gintmsk_data_t intr_mask = {.d32 = 0 };
  71962. + intr_mask.b.nptxfempty = 1;
  71963. +
  71964. +#ifdef DEBUG
  71965. + tx_status.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  71966. + DWC_DEBUGPL(DBG_HCDV,
  71967. + " NP Tx Req Queue Space Avail (after queue): %d\n",
  71968. + tx_status.b.nptxqspcavail);
  71969. + DWC_DEBUGPL(DBG_HCDV,
  71970. + " NP Tx FIFO Space Avail (after queue): %d\n",
  71971. + tx_status.b.nptxfspcavail);
  71972. +#endif
  71973. + if (more_to_do || no_queue_space || no_fifo_space) {
  71974. + /*
  71975. + * May need to queue more transactions as the request
  71976. + * queue or Tx FIFO empties. Enable the non-periodic
  71977. + * Tx FIFO empty interrupt. (Always use the half-empty
  71978. + * level to ensure that new requests are loaded as
  71979. + * soon as possible.)
  71980. + */
  71981. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0,
  71982. + intr_mask.d32);
  71983. + } else {
  71984. + /*
  71985. + * Disable the Tx FIFO empty interrupt since there are
  71986. + * no more transactions that need to be queued right
  71987. + * now. This function is called from interrupt
  71988. + * handlers to queue more transactions as transfer
  71989. + * states change.
  71990. + */
  71991. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32,
  71992. + 0);
  71993. + }
  71994. + }
  71995. +}
  71996. +
  71997. +/**
  71998. + * This function processes the currently active host channels and queues
  71999. + * transactions for these channels to the DWC_otg controller. It is called
  72000. + * from HCD interrupt handler functions.
  72001. + *
  72002. + * @param hcd The HCD state structure.
  72003. + * @param tr_type The type(s) of transactions to queue (non-periodic,
  72004. + * periodic, or both).
  72005. + */
  72006. +void dwc_otg_hcd_queue_transactions(dwc_otg_hcd_t * hcd,
  72007. + dwc_otg_transaction_type_e tr_type)
  72008. +{
  72009. +#ifdef DEBUG_SOF
  72010. + DWC_DEBUGPL(DBG_HCD, "Queue Transactions\n");
  72011. +#endif
  72012. + /* Process host channels associated with periodic transfers. */
  72013. + if ((tr_type == DWC_OTG_TRANSACTION_PERIODIC ||
  72014. + tr_type == DWC_OTG_TRANSACTION_ALL) &&
  72015. + !DWC_LIST_EMPTY(&hcd->periodic_sched_assigned)) {
  72016. +
  72017. + process_periodic_channels(hcd);
  72018. + }
  72019. +
  72020. + /* Process host channels associated with non-periodic transfers. */
  72021. + if (tr_type == DWC_OTG_TRANSACTION_NON_PERIODIC ||
  72022. + tr_type == DWC_OTG_TRANSACTION_ALL) {
  72023. + if (!DWC_LIST_EMPTY(&hcd->non_periodic_sched_active)) {
  72024. + process_non_periodic_channels(hcd);
  72025. + } else {
  72026. + /*
  72027. + * Ensure NP Tx FIFO empty interrupt is disabled when
  72028. + * there are no non-periodic transfers to process.
  72029. + */
  72030. + gintmsk_data_t gintmsk = {.d32 = 0 };
  72031. + gintmsk.b.nptxfempty = 1;
  72032. + DWC_MODIFY_REG32(&hcd->core_if->
  72033. + core_global_regs->gintmsk, gintmsk.d32,
  72034. + 0);
  72035. + }
  72036. + }
  72037. +}
  72038. +
  72039. +#ifdef DWC_HS_ELECT_TST
  72040. +/*
  72041. + * Quick and dirty hack to implement the HS Electrical Test
  72042. + * SINGLE_STEP_GET_DEVICE_DESCRIPTOR feature.
  72043. + *
  72044. + * This code was copied from our userspace app "hset". It sends a
  72045. + * Get Device Descriptor control sequence in two parts, first the
  72046. + * Setup packet by itself, followed some time later by the In and
  72047. + * Ack packets. Rather than trying to figure out how to add this
  72048. + * functionality to the normal driver code, we just hijack the
  72049. + * hardware, using these two function to drive the hardware
  72050. + * directly.
  72051. + */
  72052. +
  72053. +static dwc_otg_core_global_regs_t *global_regs;
  72054. +static dwc_otg_host_global_regs_t *hc_global_regs;
  72055. +static dwc_otg_hc_regs_t *hc_regs;
  72056. +static uint32_t *data_fifo;
  72057. +
  72058. +static void do_setup(void)
  72059. +{
  72060. + gintsts_data_t gintsts;
  72061. + hctsiz_data_t hctsiz;
  72062. + hcchar_data_t hcchar;
  72063. + haint_data_t haint;
  72064. + hcint_data_t hcint;
  72065. +
  72066. + /* Enable HAINTs */
  72067. + DWC_WRITE_REG32(&hc_global_regs->haintmsk, 0x0001);
  72068. +
  72069. + /* Enable HCINTs */
  72070. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0x04a3);
  72071. +
  72072. + /* Read GINTSTS */
  72073. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  72074. +
  72075. + /* Read HAINT */
  72076. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  72077. +
  72078. + /* Read HCINT */
  72079. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  72080. +
  72081. + /* Read HCCHAR */
  72082. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  72083. +
  72084. + /* Clear HCINT */
  72085. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  72086. +
  72087. + /* Clear HAINT */
  72088. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  72089. +
  72090. + /* Clear GINTSTS */
  72091. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  72092. +
  72093. + /* Read GINTSTS */
  72094. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  72095. +
  72096. + /*
  72097. + * Send Setup packet (Get Device Descriptor)
  72098. + */
  72099. +
  72100. + /* Make sure channel is disabled */
  72101. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  72102. + if (hcchar.b.chen) {
  72103. + hcchar.b.chdis = 1;
  72104. +// hcchar.b.chen = 1;
  72105. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  72106. + //sleep(1);
  72107. + dwc_mdelay(1000);
  72108. +
  72109. + /* Read GINTSTS */
  72110. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  72111. +
  72112. + /* Read HAINT */
  72113. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  72114. +
  72115. + /* Read HCINT */
  72116. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  72117. +
  72118. + /* Read HCCHAR */
  72119. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  72120. +
  72121. + /* Clear HCINT */
  72122. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  72123. +
  72124. + /* Clear HAINT */
  72125. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  72126. +
  72127. + /* Clear GINTSTS */
  72128. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  72129. +
  72130. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  72131. + }
  72132. +
  72133. + /* Set HCTSIZ */
  72134. + hctsiz.d32 = 0;
  72135. + hctsiz.b.xfersize = 8;
  72136. + hctsiz.b.pktcnt = 1;
  72137. + hctsiz.b.pid = DWC_OTG_HC_PID_SETUP;
  72138. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  72139. +
  72140. + /* Set HCCHAR */
  72141. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  72142. + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
  72143. + hcchar.b.epdir = 0;
  72144. + hcchar.b.epnum = 0;
  72145. + hcchar.b.mps = 8;
  72146. + hcchar.b.chen = 1;
  72147. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  72148. +
  72149. + /* Fill FIFO with Setup data for Get Device Descriptor */
  72150. + data_fifo = (uint32_t *) ((char *)global_regs + 0x1000);
  72151. + DWC_WRITE_REG32(data_fifo++, 0x01000680);
  72152. + DWC_WRITE_REG32(data_fifo++, 0x00080000);
  72153. +
  72154. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  72155. +
  72156. + /* Wait for host channel interrupt */
  72157. + do {
  72158. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  72159. + } while (gintsts.b.hcintr == 0);
  72160. +
  72161. + /* Disable HCINTs */
  72162. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0x0000);
  72163. +
  72164. + /* Disable HAINTs */
  72165. + DWC_WRITE_REG32(&hc_global_regs->haintmsk, 0x0000);
  72166. +
  72167. + /* Read HAINT */
  72168. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  72169. +
  72170. + /* Read HCINT */
  72171. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  72172. +
  72173. + /* Read HCCHAR */
  72174. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  72175. +
  72176. + /* Clear HCINT */
  72177. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  72178. +
  72179. + /* Clear HAINT */
  72180. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  72181. +
  72182. + /* Clear GINTSTS */
  72183. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  72184. +
  72185. + /* Read GINTSTS */
  72186. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  72187. +}
  72188. +
  72189. +static void do_in_ack(void)
  72190. +{
  72191. + gintsts_data_t gintsts;
  72192. + hctsiz_data_t hctsiz;
  72193. + hcchar_data_t hcchar;
  72194. + haint_data_t haint;
  72195. + hcint_data_t hcint;
  72196. + host_grxsts_data_t grxsts;
  72197. +
  72198. + /* Enable HAINTs */
  72199. + DWC_WRITE_REG32(&hc_global_regs->haintmsk, 0x0001);
  72200. +
  72201. + /* Enable HCINTs */
  72202. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0x04a3);
  72203. +
  72204. + /* Read GINTSTS */
  72205. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  72206. +
  72207. + /* Read HAINT */
  72208. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  72209. +
  72210. + /* Read HCINT */
  72211. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  72212. +
  72213. + /* Read HCCHAR */
  72214. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  72215. +
  72216. + /* Clear HCINT */
  72217. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  72218. +
  72219. + /* Clear HAINT */
  72220. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  72221. +
  72222. + /* Clear GINTSTS */
  72223. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  72224. +
  72225. + /* Read GINTSTS */
  72226. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  72227. +
  72228. + /*
  72229. + * Receive Control In packet
  72230. + */
  72231. +
  72232. + /* Make sure channel is disabled */
  72233. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  72234. + if (hcchar.b.chen) {
  72235. + hcchar.b.chdis = 1;
  72236. + hcchar.b.chen = 1;
  72237. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  72238. + //sleep(1);
  72239. + dwc_mdelay(1000);
  72240. +
  72241. + /* Read GINTSTS */
  72242. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  72243. +
  72244. + /* Read HAINT */
  72245. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  72246. +
  72247. + /* Read HCINT */
  72248. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  72249. +
  72250. + /* Read HCCHAR */
  72251. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  72252. +
  72253. + /* Clear HCINT */
  72254. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  72255. +
  72256. + /* Clear HAINT */
  72257. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  72258. +
  72259. + /* Clear GINTSTS */
  72260. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  72261. +
  72262. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  72263. + }
  72264. +
  72265. + /* Set HCTSIZ */
  72266. + hctsiz.d32 = 0;
  72267. + hctsiz.b.xfersize = 8;
  72268. + hctsiz.b.pktcnt = 1;
  72269. + hctsiz.b.pid = DWC_OTG_HC_PID_DATA1;
  72270. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  72271. +
  72272. + /* Set HCCHAR */
  72273. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  72274. + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
  72275. + hcchar.b.epdir = 1;
  72276. + hcchar.b.epnum = 0;
  72277. + hcchar.b.mps = 8;
  72278. + hcchar.b.chen = 1;
  72279. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  72280. +
  72281. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  72282. +
  72283. + /* Wait for receive status queue interrupt */
  72284. + do {
  72285. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  72286. + } while (gintsts.b.rxstsqlvl == 0);
  72287. +
  72288. + /* Read RXSTS */
  72289. + grxsts.d32 = DWC_READ_REG32(&global_regs->grxstsp);
  72290. +
  72291. + /* Clear RXSTSQLVL in GINTSTS */
  72292. + gintsts.d32 = 0;
  72293. + gintsts.b.rxstsqlvl = 1;
  72294. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  72295. +
  72296. + switch (grxsts.b.pktsts) {
  72297. + case DWC_GRXSTS_PKTSTS_IN:
  72298. + /* Read the data into the host buffer */
  72299. + if (grxsts.b.bcnt > 0) {
  72300. + int i;
  72301. + int word_count = (grxsts.b.bcnt + 3) / 4;
  72302. +
  72303. + data_fifo = (uint32_t *) ((char *)global_regs + 0x1000);
  72304. +
  72305. + for (i = 0; i < word_count; i++) {
  72306. + (void)DWC_READ_REG32(data_fifo++);
  72307. + }
  72308. + }
  72309. + break;
  72310. +
  72311. + default:
  72312. + break;
  72313. + }
  72314. +
  72315. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  72316. +
  72317. + /* Wait for receive status queue interrupt */
  72318. + do {
  72319. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  72320. + } while (gintsts.b.rxstsqlvl == 0);
  72321. +
  72322. + /* Read RXSTS */
  72323. + grxsts.d32 = DWC_READ_REG32(&global_regs->grxstsp);
  72324. +
  72325. + /* Clear RXSTSQLVL in GINTSTS */
  72326. + gintsts.d32 = 0;
  72327. + gintsts.b.rxstsqlvl = 1;
  72328. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  72329. +
  72330. + switch (grxsts.b.pktsts) {
  72331. + case DWC_GRXSTS_PKTSTS_IN_XFER_COMP:
  72332. + break;
  72333. +
  72334. + default:
  72335. + break;
  72336. + }
  72337. +
  72338. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  72339. +
  72340. + /* Wait for host channel interrupt */
  72341. + do {
  72342. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  72343. + } while (gintsts.b.hcintr == 0);
  72344. +
  72345. + /* Read HAINT */
  72346. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  72347. +
  72348. + /* Read HCINT */
  72349. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  72350. +
  72351. + /* Read HCCHAR */
  72352. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  72353. +
  72354. + /* Clear HCINT */
  72355. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  72356. +
  72357. + /* Clear HAINT */
  72358. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  72359. +
  72360. + /* Clear GINTSTS */
  72361. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  72362. +
  72363. + /* Read GINTSTS */
  72364. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  72365. +
  72366. +// usleep(100000);
  72367. +// mdelay(100);
  72368. + dwc_mdelay(1);
  72369. +
  72370. + /*
  72371. + * Send handshake packet
  72372. + */
  72373. +
  72374. + /* Read HAINT */
  72375. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  72376. +
  72377. + /* Read HCINT */
  72378. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  72379. +
  72380. + /* Read HCCHAR */
  72381. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  72382. +
  72383. + /* Clear HCINT */
  72384. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  72385. +
  72386. + /* Clear HAINT */
  72387. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  72388. +
  72389. + /* Clear GINTSTS */
  72390. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  72391. +
  72392. + /* Read GINTSTS */
  72393. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  72394. +
  72395. + /* Make sure channel is disabled */
  72396. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  72397. + if (hcchar.b.chen) {
  72398. + hcchar.b.chdis = 1;
  72399. + hcchar.b.chen = 1;
  72400. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  72401. + //sleep(1);
  72402. + dwc_mdelay(1000);
  72403. +
  72404. + /* Read GINTSTS */
  72405. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  72406. +
  72407. + /* Read HAINT */
  72408. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  72409. +
  72410. + /* Read HCINT */
  72411. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  72412. +
  72413. + /* Read HCCHAR */
  72414. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  72415. +
  72416. + /* Clear HCINT */
  72417. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  72418. +
  72419. + /* Clear HAINT */
  72420. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  72421. +
  72422. + /* Clear GINTSTS */
  72423. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  72424. +
  72425. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  72426. + }
  72427. +
  72428. + /* Set HCTSIZ */
  72429. + hctsiz.d32 = 0;
  72430. + hctsiz.b.xfersize = 0;
  72431. + hctsiz.b.pktcnt = 1;
  72432. + hctsiz.b.pid = DWC_OTG_HC_PID_DATA1;
  72433. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  72434. +
  72435. + /* Set HCCHAR */
  72436. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  72437. + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
  72438. + hcchar.b.epdir = 0;
  72439. + hcchar.b.epnum = 0;
  72440. + hcchar.b.mps = 8;
  72441. + hcchar.b.chen = 1;
  72442. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  72443. +
  72444. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  72445. +
  72446. + /* Wait for host channel interrupt */
  72447. + do {
  72448. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  72449. + } while (gintsts.b.hcintr == 0);
  72450. +
  72451. + /* Disable HCINTs */
  72452. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0x0000);
  72453. +
  72454. + /* Disable HAINTs */
  72455. + DWC_WRITE_REG32(&hc_global_regs->haintmsk, 0x0000);
  72456. +
  72457. + /* Read HAINT */
  72458. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  72459. +
  72460. + /* Read HCINT */
  72461. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  72462. +
  72463. + /* Read HCCHAR */
  72464. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  72465. +
  72466. + /* Clear HCINT */
  72467. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  72468. +
  72469. + /* Clear HAINT */
  72470. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  72471. +
  72472. + /* Clear GINTSTS */
  72473. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  72474. +
  72475. + /* Read GINTSTS */
  72476. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  72477. +}
  72478. +#endif
  72479. +
  72480. +/** Handles hub class-specific requests. */
  72481. +int dwc_otg_hcd_hub_control(dwc_otg_hcd_t * dwc_otg_hcd,
  72482. + uint16_t typeReq,
  72483. + uint16_t wValue,
  72484. + uint16_t wIndex, uint8_t * buf, uint16_t wLength)
  72485. +{
  72486. + int retval = 0;
  72487. +
  72488. + dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
  72489. + usb_hub_descriptor_t *hub_desc;
  72490. + hprt0_data_t hprt0 = {.d32 = 0 };
  72491. +
  72492. + uint32_t port_status;
  72493. +
  72494. + switch (typeReq) {
  72495. + case UCR_CLEAR_HUB_FEATURE:
  72496. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  72497. + "ClearHubFeature 0x%x\n", wValue);
  72498. + switch (wValue) {
  72499. + case UHF_C_HUB_LOCAL_POWER:
  72500. + case UHF_C_HUB_OVER_CURRENT:
  72501. + /* Nothing required here */
  72502. + break;
  72503. + default:
  72504. + retval = -DWC_E_INVALID;
  72505. + DWC_ERROR("DWC OTG HCD - "
  72506. + "ClearHubFeature request %xh unknown\n",
  72507. + wValue);
  72508. + }
  72509. + break;
  72510. + case UCR_CLEAR_PORT_FEATURE:
  72511. +#ifdef CONFIG_USB_DWC_OTG_LPM
  72512. + if (wValue != UHF_PORT_L1)
  72513. +#endif
  72514. + if (!wIndex || wIndex > 1)
  72515. + goto error;
  72516. +
  72517. + switch (wValue) {
  72518. + case UHF_PORT_ENABLE:
  72519. + DWC_DEBUGPL(DBG_ANY, "DWC OTG HCD HUB CONTROL - "
  72520. + "ClearPortFeature USB_PORT_FEAT_ENABLE\n");
  72521. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  72522. + hprt0.b.prtena = 1;
  72523. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  72524. + break;
  72525. + case UHF_PORT_SUSPEND:
  72526. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  72527. + "ClearPortFeature USB_PORT_FEAT_SUSPEND\n");
  72528. +
  72529. + if (core_if->power_down == 2) {
  72530. + dwc_otg_host_hibernation_restore(core_if, 0, 0);
  72531. + } else {
  72532. + DWC_WRITE_REG32(core_if->pcgcctl, 0);
  72533. + dwc_mdelay(5);
  72534. +
  72535. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  72536. + hprt0.b.prtres = 1;
  72537. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  72538. + hprt0.b.prtsusp = 0;
  72539. + /* Clear Resume bit */
  72540. + dwc_mdelay(100);
  72541. + hprt0.b.prtres = 0;
  72542. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  72543. + }
  72544. + break;
  72545. +#ifdef CONFIG_USB_DWC_OTG_LPM
  72546. + case UHF_PORT_L1:
  72547. + {
  72548. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  72549. + glpmcfg_data_t lpmcfg = {.d32 = 0 };
  72550. +
  72551. + lpmcfg.d32 =
  72552. + DWC_READ_REG32(&core_if->
  72553. + core_global_regs->glpmcfg);
  72554. + lpmcfg.b.en_utmi_sleep = 0;
  72555. + lpmcfg.b.hird_thres &= (~(1 << 4));
  72556. + lpmcfg.b.prt_sleep_sts = 1;
  72557. + DWC_WRITE_REG32(&core_if->
  72558. + core_global_regs->glpmcfg,
  72559. + lpmcfg.d32);
  72560. +
  72561. + /* Clear Enbl_L1Gating bit. */
  72562. + pcgcctl.b.enbl_sleep_gating = 1;
  72563. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32,
  72564. + 0);
  72565. +
  72566. + dwc_mdelay(5);
  72567. +
  72568. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  72569. + hprt0.b.prtres = 1;
  72570. + DWC_WRITE_REG32(core_if->host_if->hprt0,
  72571. + hprt0.d32);
  72572. + /* This bit will be cleared in wakeup interrupt handle */
  72573. + break;
  72574. + }
  72575. +#endif
  72576. + case UHF_PORT_POWER:
  72577. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  72578. + "ClearPortFeature USB_PORT_FEAT_POWER\n");
  72579. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  72580. + hprt0.b.prtpwr = 0;
  72581. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  72582. + break;
  72583. + case UHF_PORT_INDICATOR:
  72584. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  72585. + "ClearPortFeature USB_PORT_FEAT_INDICATOR\n");
  72586. + /* Port inidicator not supported */
  72587. + break;
  72588. + case UHF_C_PORT_CONNECTION:
  72589. + /* Clears drivers internal connect status change
  72590. + * flag */
  72591. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  72592. + "ClearPortFeature USB_PORT_FEAT_C_CONNECTION\n");
  72593. + dwc_otg_hcd->flags.b.port_connect_status_change = 0;
  72594. + break;
  72595. + case UHF_C_PORT_RESET:
  72596. + /* Clears the driver's internal Port Reset Change
  72597. + * flag */
  72598. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  72599. + "ClearPortFeature USB_PORT_FEAT_C_RESET\n");
  72600. + dwc_otg_hcd->flags.b.port_reset_change = 0;
  72601. + break;
  72602. + case UHF_C_PORT_ENABLE:
  72603. + /* Clears the driver's internal Port
  72604. + * Enable/Disable Change flag */
  72605. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  72606. + "ClearPortFeature USB_PORT_FEAT_C_ENABLE\n");
  72607. + dwc_otg_hcd->flags.b.port_enable_change = 0;
  72608. + break;
  72609. + case UHF_C_PORT_SUSPEND:
  72610. + /* Clears the driver's internal Port Suspend
  72611. + * Change flag, which is set when resume signaling on
  72612. + * the host port is complete */
  72613. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  72614. + "ClearPortFeature USB_PORT_FEAT_C_SUSPEND\n");
  72615. + dwc_otg_hcd->flags.b.port_suspend_change = 0;
  72616. + break;
  72617. +#ifdef CONFIG_USB_DWC_OTG_LPM
  72618. + case UHF_C_PORT_L1:
  72619. + dwc_otg_hcd->flags.b.port_l1_change = 0;
  72620. + break;
  72621. +#endif
  72622. + case UHF_C_PORT_OVER_CURRENT:
  72623. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  72624. + "ClearPortFeature USB_PORT_FEAT_C_OVER_CURRENT\n");
  72625. + dwc_otg_hcd->flags.b.port_over_current_change = 0;
  72626. + break;
  72627. + default:
  72628. + retval = -DWC_E_INVALID;
  72629. + DWC_ERROR("DWC OTG HCD - "
  72630. + "ClearPortFeature request %xh "
  72631. + "unknown or unsupported\n", wValue);
  72632. + }
  72633. + break;
  72634. + case UCR_GET_HUB_DESCRIPTOR:
  72635. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  72636. + "GetHubDescriptor\n");
  72637. + hub_desc = (usb_hub_descriptor_t *) buf;
  72638. + hub_desc->bDescLength = 9;
  72639. + hub_desc->bDescriptorType = 0x29;
  72640. + hub_desc->bNbrPorts = 1;
  72641. + USETW(hub_desc->wHubCharacteristics, 0x08);
  72642. + hub_desc->bPwrOn2PwrGood = 1;
  72643. + hub_desc->bHubContrCurrent = 0;
  72644. + hub_desc->DeviceRemovable[0] = 0;
  72645. + hub_desc->DeviceRemovable[1] = 0xff;
  72646. + break;
  72647. + case UCR_GET_HUB_STATUS:
  72648. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  72649. + "GetHubStatus\n");
  72650. + DWC_MEMSET(buf, 0, 4);
  72651. + break;
  72652. + case UCR_GET_PORT_STATUS:
  72653. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  72654. + "GetPortStatus wIndex = 0x%04x FLAGS=0x%08x\n",
  72655. + wIndex, dwc_otg_hcd->flags.d32);
  72656. + if (!wIndex || wIndex > 1)
  72657. + goto error;
  72658. +
  72659. + port_status = 0;
  72660. +
  72661. + if (dwc_otg_hcd->flags.b.port_connect_status_change)
  72662. + port_status |= (1 << UHF_C_PORT_CONNECTION);
  72663. +
  72664. + if (dwc_otg_hcd->flags.b.port_enable_change)
  72665. + port_status |= (1 << UHF_C_PORT_ENABLE);
  72666. +
  72667. + if (dwc_otg_hcd->flags.b.port_suspend_change)
  72668. + port_status |= (1 << UHF_C_PORT_SUSPEND);
  72669. +
  72670. + if (dwc_otg_hcd->flags.b.port_l1_change)
  72671. + port_status |= (1 << UHF_C_PORT_L1);
  72672. +
  72673. + if (dwc_otg_hcd->flags.b.port_reset_change) {
  72674. + port_status |= (1 << UHF_C_PORT_RESET);
  72675. + }
  72676. +
  72677. + if (dwc_otg_hcd->flags.b.port_over_current_change) {
  72678. + DWC_WARN("Overcurrent change detected\n");
  72679. + port_status |= (1 << UHF_C_PORT_OVER_CURRENT);
  72680. + }
  72681. +
  72682. + if (!dwc_otg_hcd->flags.b.port_connect_status) {
  72683. + /*
  72684. + * The port is disconnected, which means the core is
  72685. + * either in device mode or it soon will be. Just
  72686. + * return 0's for the remainder of the port status
  72687. + * since the port register can't be read if the core
  72688. + * is in device mode.
  72689. + */
  72690. + *((__le32 *) buf) = dwc_cpu_to_le32(&port_status);
  72691. + break;
  72692. + }
  72693. +
  72694. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  72695. + DWC_DEBUGPL(DBG_HCDV, " HPRT0: 0x%08x\n", hprt0.d32);
  72696. +
  72697. + if (hprt0.b.prtconnsts)
  72698. + port_status |= (1 << UHF_PORT_CONNECTION);
  72699. +
  72700. + if (hprt0.b.prtena)
  72701. + port_status |= (1 << UHF_PORT_ENABLE);
  72702. +
  72703. + if (hprt0.b.prtsusp)
  72704. + port_status |= (1 << UHF_PORT_SUSPEND);
  72705. +
  72706. + if (hprt0.b.prtovrcurract)
  72707. + port_status |= (1 << UHF_PORT_OVER_CURRENT);
  72708. +
  72709. + if (hprt0.b.prtrst)
  72710. + port_status |= (1 << UHF_PORT_RESET);
  72711. +
  72712. + if (hprt0.b.prtpwr)
  72713. + port_status |= (1 << UHF_PORT_POWER);
  72714. +
  72715. + if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_HIGH_SPEED)
  72716. + port_status |= (1 << UHF_PORT_HIGH_SPEED);
  72717. + else if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_LOW_SPEED)
  72718. + port_status |= (1 << UHF_PORT_LOW_SPEED);
  72719. +
  72720. + if (hprt0.b.prttstctl)
  72721. + port_status |= (1 << UHF_PORT_TEST);
  72722. + if (dwc_otg_get_lpm_portsleepstatus(dwc_otg_hcd->core_if)) {
  72723. + port_status |= (1 << UHF_PORT_L1);
  72724. + }
  72725. + /*
  72726. + For Synopsys HW emulation of Power down wkup_control asserts the
  72727. + hreset_n and prst_n on suspned. This causes the HPRT0 to be zero.
  72728. + We intentionally tell the software that port is in L2Suspend state.
  72729. + Only for STE.
  72730. + */
  72731. + if ((core_if->power_down == 2)
  72732. + && (core_if->hibernation_suspend == 1)) {
  72733. + port_status |= (1 << UHF_PORT_SUSPEND);
  72734. + }
  72735. + /* USB_PORT_FEAT_INDICATOR unsupported always 0 */
  72736. +
  72737. + *((__le32 *) buf) = dwc_cpu_to_le32(&port_status);
  72738. +
  72739. + break;
  72740. + case UCR_SET_HUB_FEATURE:
  72741. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  72742. + "SetHubFeature\n");
  72743. + /* No HUB features supported */
  72744. + break;
  72745. + case UCR_SET_PORT_FEATURE:
  72746. + if (wValue != UHF_PORT_TEST && (!wIndex || wIndex > 1))
  72747. + goto error;
  72748. +
  72749. + if (!dwc_otg_hcd->flags.b.port_connect_status) {
  72750. + /*
  72751. + * The port is disconnected, which means the core is
  72752. + * either in device mode or it soon will be. Just
  72753. + * return without doing anything since the port
  72754. + * register can't be written if the core is in device
  72755. + * mode.
  72756. + */
  72757. + break;
  72758. + }
  72759. +
  72760. + switch (wValue) {
  72761. + case UHF_PORT_SUSPEND:
  72762. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  72763. + "SetPortFeature - USB_PORT_FEAT_SUSPEND\n");
  72764. + if (dwc_otg_hcd_otg_port(dwc_otg_hcd) != wIndex) {
  72765. + goto error;
  72766. + }
  72767. + if (core_if->power_down == 2) {
  72768. + int timeout = 300;
  72769. + dwc_irqflags_t flags;
  72770. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  72771. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  72772. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  72773. +#ifdef DWC_DEV_SRPCAP
  72774. + int32_t otg_cap_param = core_if->core_params->otg_cap;
  72775. +#endif
  72776. + DWC_PRINTF("Preparing for complete power-off\n");
  72777. +
  72778. + /* Save registers before hibernation */
  72779. + dwc_otg_save_global_regs(core_if);
  72780. + dwc_otg_save_host_regs(core_if);
  72781. +
  72782. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  72783. + hprt0.b.prtsusp = 1;
  72784. + hprt0.b.prtena = 0;
  72785. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  72786. + /* Spin hprt0.b.prtsusp to became 1 */
  72787. + do {
  72788. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  72789. + if (hprt0.b.prtsusp) {
  72790. + break;
  72791. + }
  72792. + dwc_mdelay(1);
  72793. + } while (--timeout);
  72794. + if (!timeout) {
  72795. + DWC_WARN("Suspend wasn't genereted\n");
  72796. + }
  72797. + dwc_udelay(10);
  72798. +
  72799. + /*
  72800. + * We need to disable interrupts to prevent servicing of any IRQ
  72801. + * during going to hibernation
  72802. + */
  72803. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &flags);
  72804. + core_if->lx_state = DWC_OTG_L2;
  72805. +#ifdef DWC_DEV_SRPCAP
  72806. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  72807. + hprt0.b.prtpwr = 0;
  72808. + hprt0.b.prtena = 0;
  72809. + DWC_WRITE_REG32(core_if->host_if->hprt0,
  72810. + hprt0.d32);
  72811. +#endif
  72812. + gusbcfg.d32 =
  72813. + DWC_READ_REG32(&core_if->core_global_regs->
  72814. + gusbcfg);
  72815. + if (gusbcfg.b.ulpi_utmi_sel == 1) {
  72816. + /* ULPI interface */
  72817. + /* Suspend the Phy Clock */
  72818. + pcgcctl.d32 = 0;
  72819. + pcgcctl.b.stoppclk = 1;
  72820. + DWC_MODIFY_REG32(core_if->pcgcctl, 0,
  72821. + pcgcctl.d32);
  72822. + dwc_udelay(10);
  72823. + gpwrdn.b.pmuactv = 1;
  72824. + DWC_MODIFY_REG32(&core_if->
  72825. + core_global_regs->
  72826. + gpwrdn, 0, gpwrdn.d32);
  72827. + } else {
  72828. + /* UTMI+ Interface */
  72829. + gpwrdn.b.pmuactv = 1;
  72830. + DWC_MODIFY_REG32(&core_if->
  72831. + core_global_regs->
  72832. + gpwrdn, 0, gpwrdn.d32);
  72833. + dwc_udelay(10);
  72834. + pcgcctl.b.stoppclk = 1;
  72835. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  72836. + dwc_udelay(10);
  72837. + }
  72838. +#ifdef DWC_DEV_SRPCAP
  72839. + gpwrdn.d32 = 0;
  72840. + gpwrdn.b.dis_vbus = 1;
  72841. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  72842. + gpwrdn, 0, gpwrdn.d32);
  72843. +#endif
  72844. + gpwrdn.d32 = 0;
  72845. + gpwrdn.b.pmuintsel = 1;
  72846. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  72847. + gpwrdn, 0, gpwrdn.d32);
  72848. + dwc_udelay(10);
  72849. +
  72850. + gpwrdn.d32 = 0;
  72851. +#ifdef DWC_DEV_SRPCAP
  72852. + gpwrdn.b.srp_det_msk = 1;
  72853. +#endif
  72854. + gpwrdn.b.disconn_det_msk = 1;
  72855. + gpwrdn.b.lnstchng_msk = 1;
  72856. + gpwrdn.b.sts_chngint_msk = 1;
  72857. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  72858. + gpwrdn, 0, gpwrdn.d32);
  72859. + dwc_udelay(10);
  72860. +
  72861. + /* Enable Power Down Clamp and all interrupts in GPWRDN */
  72862. + gpwrdn.d32 = 0;
  72863. + gpwrdn.b.pwrdnclmp = 1;
  72864. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  72865. + gpwrdn, 0, gpwrdn.d32);
  72866. + dwc_udelay(10);
  72867. +
  72868. + /* Switch off VDD */
  72869. + gpwrdn.d32 = 0;
  72870. + gpwrdn.b.pwrdnswtch = 1;
  72871. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  72872. + gpwrdn, 0, gpwrdn.d32);
  72873. +
  72874. +#ifdef DWC_DEV_SRPCAP
  72875. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE)
  72876. + {
  72877. + core_if->pwron_timer_started = 1;
  72878. + DWC_TIMER_SCHEDULE(core_if->pwron_timer, 6000 /* 6 secs */ );
  72879. + }
  72880. +#endif
  72881. + /* Save gpwrdn register for further usage if stschng interrupt */
  72882. + core_if->gr_backup->gpwrdn_local =
  72883. + DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  72884. +
  72885. + /* Set flag to indicate that we are in hibernation */
  72886. + core_if->hibernation_suspend = 1;
  72887. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock,flags);
  72888. +
  72889. + DWC_PRINTF("Host hibernation completed\n");
  72890. + // Exit from case statement
  72891. + break;
  72892. +
  72893. + }
  72894. + if (dwc_otg_hcd_otg_port(dwc_otg_hcd) == wIndex &&
  72895. + dwc_otg_hcd->fops->get_b_hnp_enable(dwc_otg_hcd)) {
  72896. + gotgctl_data_t gotgctl = {.d32 = 0 };
  72897. + gotgctl.b.hstsethnpen = 1;
  72898. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  72899. + gotgctl, 0, gotgctl.d32);
  72900. + core_if->op_state = A_SUSPEND;
  72901. + }
  72902. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  72903. + hprt0.b.prtsusp = 1;
  72904. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  72905. + {
  72906. + dwc_irqflags_t flags;
  72907. + /* Update lx_state */
  72908. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &flags);
  72909. + core_if->lx_state = DWC_OTG_L2;
  72910. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, flags);
  72911. + }
  72912. + /* Suspend the Phy Clock */
  72913. + {
  72914. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  72915. + pcgcctl.b.stoppclk = 1;
  72916. + DWC_MODIFY_REG32(core_if->pcgcctl, 0,
  72917. + pcgcctl.d32);
  72918. + dwc_udelay(10);
  72919. + }
  72920. +
  72921. + /* For HNP the bus must be suspended for at least 200ms. */
  72922. + if (dwc_otg_hcd->fops->get_b_hnp_enable(dwc_otg_hcd)) {
  72923. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  72924. + pcgcctl.b.stoppclk = 1;
  72925. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  72926. + dwc_mdelay(200);
  72927. + }
  72928. +
  72929. + /** @todo - check how sw can wait for 1 sec to check asesvld??? */
  72930. +#if 0 //vahrama !!!!!!!!!!!!!!!!!!
  72931. + if (core_if->adp_enable) {
  72932. + gotgctl_data_t gotgctl = {.d32 = 0 };
  72933. + gpwrdn_data_t gpwrdn;
  72934. +
  72935. + while (gotgctl.b.asesvld == 1) {
  72936. + gotgctl.d32 =
  72937. + DWC_READ_REG32(&core_if->
  72938. + core_global_regs->
  72939. + gotgctl);
  72940. + dwc_mdelay(100);
  72941. + }
  72942. +
  72943. + /* Enable Power Down Logic */
  72944. + gpwrdn.d32 = 0;
  72945. + gpwrdn.b.pmuactv = 1;
  72946. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  72947. + gpwrdn, 0, gpwrdn.d32);
  72948. +
  72949. + /* Unmask SRP detected interrupt from Power Down Logic */
  72950. + gpwrdn.d32 = 0;
  72951. + gpwrdn.b.srp_det_msk = 1;
  72952. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  72953. + gpwrdn, 0, gpwrdn.d32);
  72954. +
  72955. + dwc_otg_adp_probe_start(core_if);
  72956. + }
  72957. +#endif
  72958. + break;
  72959. + case UHF_PORT_POWER:
  72960. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  72961. + "SetPortFeature - USB_PORT_FEAT_POWER\n");
  72962. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  72963. + hprt0.b.prtpwr = 1;
  72964. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  72965. + break;
  72966. + case UHF_PORT_RESET:
  72967. + if ((core_if->power_down == 2)
  72968. + && (core_if->hibernation_suspend == 1)) {
  72969. + /* If we are going to exit from Hibernated
  72970. + * state via USB RESET.
  72971. + */
  72972. + dwc_otg_host_hibernation_restore(core_if, 0, 1);
  72973. + } else {
  72974. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  72975. +
  72976. + DWC_DEBUGPL(DBG_HCD,
  72977. + "DWC OTG HCD HUB CONTROL - "
  72978. + "SetPortFeature - USB_PORT_FEAT_RESET\n");
  72979. + {
  72980. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  72981. + pcgcctl.b.enbl_sleep_gating = 1;
  72982. + pcgcctl.b.stoppclk = 1;
  72983. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  72984. + DWC_WRITE_REG32(core_if->pcgcctl, 0);
  72985. + }
  72986. +#ifdef CONFIG_USB_DWC_OTG_LPM
  72987. + {
  72988. + glpmcfg_data_t lpmcfg;
  72989. + lpmcfg.d32 =
  72990. + DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  72991. + if (lpmcfg.b.prt_sleep_sts) {
  72992. + lpmcfg.b.en_utmi_sleep = 0;
  72993. + lpmcfg.b.hird_thres &= (~(1 << 4));
  72994. + DWC_WRITE_REG32
  72995. + (&core_if->core_global_regs->glpmcfg,
  72996. + lpmcfg.d32);
  72997. + dwc_mdelay(1);
  72998. + }
  72999. + }
  73000. +#endif
  73001. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  73002. + /* Clear suspend bit if resetting from suspended state. */
  73003. + hprt0.b.prtsusp = 0;
  73004. + /* When B-Host the Port reset bit is set in
  73005. + * the Start HCD Callback function, so that
  73006. + * the reset is started within 1ms of the HNP
  73007. + * success interrupt. */
  73008. + if (!dwc_otg_hcd_is_b_host(dwc_otg_hcd)) {
  73009. + hprt0.b.prtpwr = 1;
  73010. + hprt0.b.prtrst = 1;
  73011. + DWC_PRINTF("Indeed it is in host mode hprt0 = %08x\n",hprt0.d32);
  73012. + DWC_WRITE_REG32(core_if->host_if->hprt0,
  73013. + hprt0.d32);
  73014. + }
  73015. + /* Clear reset bit in 10ms (FS/LS) or 50ms (HS) */
  73016. + dwc_mdelay(60);
  73017. + hprt0.b.prtrst = 0;
  73018. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  73019. + core_if->lx_state = DWC_OTG_L0; /* Now back to the on state */
  73020. + }
  73021. + break;
  73022. +#ifdef DWC_HS_ELECT_TST
  73023. + case UHF_PORT_TEST:
  73024. + {
  73025. + uint32_t t;
  73026. + gintmsk_data_t gintmsk;
  73027. +
  73028. + t = (wIndex >> 8); /* MSB wIndex USB */
  73029. + DWC_DEBUGPL(DBG_HCD,
  73030. + "DWC OTG HCD HUB CONTROL - "
  73031. + "SetPortFeature - USB_PORT_FEAT_TEST %d\n",
  73032. + t);
  73033. + DWC_WARN("USB_PORT_FEAT_TEST %d\n", t);
  73034. + if (t < 6) {
  73035. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  73036. + hprt0.b.prttstctl = t;
  73037. + DWC_WRITE_REG32(core_if->host_if->hprt0,
  73038. + hprt0.d32);
  73039. + } else {
  73040. + /* Setup global vars with reg addresses (quick and
  73041. + * dirty hack, should be cleaned up)
  73042. + */
  73043. + global_regs = core_if->core_global_regs;
  73044. + hc_global_regs =
  73045. + core_if->host_if->host_global_regs;
  73046. + hc_regs =
  73047. + (dwc_otg_hc_regs_t *) ((char *)
  73048. + global_regs +
  73049. + 0x500);
  73050. + data_fifo =
  73051. + (uint32_t *) ((char *)global_regs +
  73052. + 0x1000);
  73053. +
  73054. + if (t == 6) { /* HS_HOST_PORT_SUSPEND_RESUME */
  73055. + /* Save current interrupt mask */
  73056. + gintmsk.d32 =
  73057. + DWC_READ_REG32
  73058. + (&global_regs->gintmsk);
  73059. +
  73060. + /* Disable all interrupts while we muck with
  73061. + * the hardware directly
  73062. + */
  73063. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  73064. +
  73065. + /* 15 second delay per the test spec */
  73066. + dwc_mdelay(15000);
  73067. +
  73068. + /* Drive suspend on the root port */
  73069. + hprt0.d32 =
  73070. + dwc_otg_read_hprt0(core_if);
  73071. + hprt0.b.prtsusp = 1;
  73072. + hprt0.b.prtres = 0;
  73073. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  73074. +
  73075. + /* 15 second delay per the test spec */
  73076. + dwc_mdelay(15000);
  73077. +
  73078. + /* Drive resume on the root port */
  73079. + hprt0.d32 =
  73080. + dwc_otg_read_hprt0(core_if);
  73081. + hprt0.b.prtsusp = 0;
  73082. + hprt0.b.prtres = 1;
  73083. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  73084. + dwc_mdelay(100);
  73085. +
  73086. + /* Clear the resume bit */
  73087. + hprt0.b.prtres = 0;
  73088. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  73089. +
  73090. + /* Restore interrupts */
  73091. + DWC_WRITE_REG32(&global_regs->gintmsk, gintmsk.d32);
  73092. + } else if (t == 7) { /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR setup */
  73093. + /* Save current interrupt mask */
  73094. + gintmsk.d32 =
  73095. + DWC_READ_REG32
  73096. + (&global_regs->gintmsk);
  73097. +
  73098. + /* Disable all interrupts while we muck with
  73099. + * the hardware directly
  73100. + */
  73101. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  73102. +
  73103. + /* 15 second delay per the test spec */
  73104. + dwc_mdelay(15000);
  73105. +
  73106. + /* Send the Setup packet */
  73107. + do_setup();
  73108. +
  73109. + /* 15 second delay so nothing else happens for awhile */
  73110. + dwc_mdelay(15000);
  73111. +
  73112. + /* Restore interrupts */
  73113. + DWC_WRITE_REG32(&global_regs->gintmsk, gintmsk.d32);
  73114. + } else if (t == 8) { /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR execute */
  73115. + /* Save current interrupt mask */
  73116. + gintmsk.d32 =
  73117. + DWC_READ_REG32
  73118. + (&global_regs->gintmsk);
  73119. +
  73120. + /* Disable all interrupts while we muck with
  73121. + * the hardware directly
  73122. + */
  73123. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  73124. +
  73125. + /* Send the Setup packet */
  73126. + do_setup();
  73127. +
  73128. + /* 15 second delay so nothing else happens for awhile */
  73129. + dwc_mdelay(15000);
  73130. +
  73131. + /* Send the In and Ack packets */
  73132. + do_in_ack();
  73133. +
  73134. + /* 15 second delay so nothing else happens for awhile */
  73135. + dwc_mdelay(15000);
  73136. +
  73137. + /* Restore interrupts */
  73138. + DWC_WRITE_REG32(&global_regs->gintmsk, gintmsk.d32);
  73139. + }
  73140. + }
  73141. + break;
  73142. + }
  73143. +#endif /* DWC_HS_ELECT_TST */
  73144. +
  73145. + case UHF_PORT_INDICATOR:
  73146. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  73147. + "SetPortFeature - USB_PORT_FEAT_INDICATOR\n");
  73148. + /* Not supported */
  73149. + break;
  73150. + default:
  73151. + retval = -DWC_E_INVALID;
  73152. + DWC_ERROR("DWC OTG HCD - "
  73153. + "SetPortFeature request %xh "
  73154. + "unknown or unsupported\n", wValue);
  73155. + break;
  73156. + }
  73157. + break;
  73158. +#ifdef CONFIG_USB_DWC_OTG_LPM
  73159. + case UCR_SET_AND_TEST_PORT_FEATURE:
  73160. + if (wValue != UHF_PORT_L1) {
  73161. + goto error;
  73162. + }
  73163. + {
  73164. + int portnum, hird, devaddr, remwake;
  73165. + glpmcfg_data_t lpmcfg;
  73166. + uint32_t time_usecs;
  73167. + gintsts_data_t gintsts;
  73168. + gintmsk_data_t gintmsk;
  73169. +
  73170. + if (!dwc_otg_get_param_lpm_enable(core_if)) {
  73171. + goto error;
  73172. + }
  73173. + if (wValue != UHF_PORT_L1 || wLength != 1) {
  73174. + goto error;
  73175. + }
  73176. + /* Check if the port currently is in SLEEP state */
  73177. + lpmcfg.d32 =
  73178. + DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  73179. + if (lpmcfg.b.prt_sleep_sts) {
  73180. + DWC_INFO("Port is already in sleep mode\n");
  73181. + buf[0] = 0; /* Return success */
  73182. + break;
  73183. + }
  73184. +
  73185. + portnum = wIndex & 0xf;
  73186. + hird = (wIndex >> 4) & 0xf;
  73187. + devaddr = (wIndex >> 8) & 0x7f;
  73188. + remwake = (wIndex >> 15);
  73189. +
  73190. + if (portnum != 1) {
  73191. + retval = -DWC_E_INVALID;
  73192. + DWC_WARN
  73193. + ("Wrong port number(%d) in SetandTestPortFeature request\n",
  73194. + portnum);
  73195. + break;
  73196. + }
  73197. +
  73198. + DWC_PRINTF
  73199. + ("SetandTestPortFeature request: portnum = %d, hird = %d, devaddr = %d, rewake = %d\n",
  73200. + portnum, hird, devaddr, remwake);
  73201. + /* Disable LPM interrupt */
  73202. + gintmsk.d32 = 0;
  73203. + gintmsk.b.lpmtranrcvd = 1;
  73204. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk,
  73205. + gintmsk.d32, 0);
  73206. +
  73207. + if (dwc_otg_hcd_send_lpm
  73208. + (dwc_otg_hcd, devaddr, hird, remwake)) {
  73209. + retval = -DWC_E_INVALID;
  73210. + break;
  73211. + }
  73212. +
  73213. + time_usecs = 10 * (lpmcfg.b.retry_count + 1);
  73214. + /* We will consider timeout if time_usecs microseconds pass,
  73215. + * and we don't receive LPM transaction status.
  73216. + * After receiving non-error responce(ACK/NYET/STALL) from device,
  73217. + * core will set lpmtranrcvd bit.
  73218. + */
  73219. + do {
  73220. + gintsts.d32 =
  73221. + DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  73222. + if (gintsts.b.lpmtranrcvd) {
  73223. + break;
  73224. + }
  73225. + dwc_udelay(1);
  73226. + } while (--time_usecs);
  73227. + /* lpm_int bit will be cleared in LPM interrupt handler */
  73228. +
  73229. + /* Now fill status
  73230. + * 0x00 - Success
  73231. + * 0x10 - NYET
  73232. + * 0x11 - Timeout
  73233. + */
  73234. + if (!gintsts.b.lpmtranrcvd) {
  73235. + buf[0] = 0x3; /* Completion code is Timeout */
  73236. + dwc_otg_hcd_free_hc_from_lpm(dwc_otg_hcd);
  73237. + } else {
  73238. + lpmcfg.d32 =
  73239. + DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  73240. + if (lpmcfg.b.lpm_resp == 0x3) {
  73241. + /* ACK responce from the device */
  73242. + buf[0] = 0x00; /* Success */
  73243. + } else if (lpmcfg.b.lpm_resp == 0x2) {
  73244. + /* NYET responce from the device */
  73245. + buf[0] = 0x2;
  73246. + } else {
  73247. + /* Otherwise responce with Timeout */
  73248. + buf[0] = 0x3;
  73249. + }
  73250. + }
  73251. + DWC_PRINTF("Device responce to LPM trans is %x\n",
  73252. + lpmcfg.b.lpm_resp);
  73253. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0,
  73254. + gintmsk.d32);
  73255. +
  73256. + break;
  73257. + }
  73258. +#endif /* CONFIG_USB_DWC_OTG_LPM */
  73259. + default:
  73260. +error:
  73261. + retval = -DWC_E_INVALID;
  73262. + DWC_WARN("DWC OTG HCD - "
  73263. + "Unknown hub control request type or invalid typeReq: %xh wIndex: %xh wValue: %xh\n",
  73264. + typeReq, wIndex, wValue);
  73265. + break;
  73266. + }
  73267. +
  73268. + return retval;
  73269. +}
  73270. +
  73271. +#ifdef CONFIG_USB_DWC_OTG_LPM
  73272. +/** Returns index of host channel to perform LPM transaction. */
  73273. +int dwc_otg_hcd_get_hc_for_lpm_tran(dwc_otg_hcd_t * hcd, uint8_t devaddr)
  73274. +{
  73275. + dwc_otg_core_if_t *core_if = hcd->core_if;
  73276. + dwc_hc_t *hc;
  73277. + hcchar_data_t hcchar;
  73278. + gintmsk_data_t gintmsk = {.d32 = 0 };
  73279. +
  73280. + if (DWC_CIRCLEQ_EMPTY(&hcd->free_hc_list)) {
  73281. + DWC_PRINTF("No free channel to select for LPM transaction\n");
  73282. + return -1;
  73283. + }
  73284. +
  73285. + hc = DWC_CIRCLEQ_FIRST(&hcd->free_hc_list);
  73286. +
  73287. + /* Mask host channel interrupts. */
  73288. + gintmsk.b.hcintr = 1;
  73289. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, gintmsk.d32, 0);
  73290. +
  73291. + /* Fill fields that core needs for LPM transaction */
  73292. + hcchar.b.devaddr = devaddr;
  73293. + hcchar.b.epnum = 0;
  73294. + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
  73295. + hcchar.b.mps = 64;
  73296. + hcchar.b.lspddev = (hc->speed == DWC_OTG_EP_SPEED_LOW);
  73297. + hcchar.b.epdir = 0; /* OUT */
  73298. + DWC_WRITE_REG32(&core_if->host_if->hc_regs[hc->hc_num]->hcchar,
  73299. + hcchar.d32);
  73300. +
  73301. + /* Remove the host channel from the free list. */
  73302. + DWC_CIRCLEQ_REMOVE_INIT(&hcd->free_hc_list, hc, hc_list_entry);
  73303. +
  73304. + DWC_PRINTF("hcnum = %d devaddr = %d\n", hc->hc_num, devaddr);
  73305. +
  73306. + return hc->hc_num;
  73307. +}
  73308. +
  73309. +/** Release hc after performing LPM transaction */
  73310. +void dwc_otg_hcd_free_hc_from_lpm(dwc_otg_hcd_t * hcd)
  73311. +{
  73312. + dwc_hc_t *hc;
  73313. + glpmcfg_data_t lpmcfg;
  73314. + uint8_t hc_num;
  73315. +
  73316. + lpmcfg.d32 = DWC_READ_REG32(&hcd->core_if->core_global_regs->glpmcfg);
  73317. + hc_num = lpmcfg.b.lpm_chan_index;
  73318. +
  73319. + hc = hcd->hc_ptr_array[hc_num];
  73320. +
  73321. + DWC_PRINTF("Freeing channel %d after LPM\n", hc_num);
  73322. + /* Return host channel to free list */
  73323. + DWC_CIRCLEQ_INSERT_TAIL(&hcd->free_hc_list, hc, hc_list_entry);
  73324. +}
  73325. +
  73326. +int dwc_otg_hcd_send_lpm(dwc_otg_hcd_t * hcd, uint8_t devaddr, uint8_t hird,
  73327. + uint8_t bRemoteWake)
  73328. +{
  73329. + glpmcfg_data_t lpmcfg;
  73330. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  73331. + int channel;
  73332. +
  73333. + channel = dwc_otg_hcd_get_hc_for_lpm_tran(hcd, devaddr);
  73334. + if (channel < 0) {
  73335. + return channel;
  73336. + }
  73337. +
  73338. + pcgcctl.b.enbl_sleep_gating = 1;
  73339. + DWC_MODIFY_REG32(hcd->core_if->pcgcctl, 0, pcgcctl.d32);
  73340. +
  73341. + /* Read LPM config register */
  73342. + lpmcfg.d32 = DWC_READ_REG32(&hcd->core_if->core_global_regs->glpmcfg);
  73343. +
  73344. + /* Program LPM transaction fields */
  73345. + lpmcfg.b.rem_wkup_en = bRemoteWake;
  73346. + lpmcfg.b.hird = hird;
  73347. + lpmcfg.b.hird_thres = 0x1c;
  73348. + lpmcfg.b.lpm_chan_index = channel;
  73349. + lpmcfg.b.en_utmi_sleep = 1;
  73350. + /* Program LPM config register */
  73351. + DWC_WRITE_REG32(&hcd->core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  73352. +
  73353. + /* Send LPM transaction */
  73354. + lpmcfg.b.send_lpm = 1;
  73355. + DWC_WRITE_REG32(&hcd->core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  73356. +
  73357. + return 0;
  73358. +}
  73359. +
  73360. +#endif /* CONFIG_USB_DWC_OTG_LPM */
  73361. +
  73362. +int dwc_otg_hcd_is_status_changed(dwc_otg_hcd_t * hcd, int port)
  73363. +{
  73364. + int retval;
  73365. +
  73366. + if (port != 1) {
  73367. + return -DWC_E_INVALID;
  73368. + }
  73369. +
  73370. + retval = (hcd->flags.b.port_connect_status_change ||
  73371. + hcd->flags.b.port_reset_change ||
  73372. + hcd->flags.b.port_enable_change ||
  73373. + hcd->flags.b.port_suspend_change ||
  73374. + hcd->flags.b.port_over_current_change);
  73375. +#ifdef DEBUG
  73376. + if (retval) {
  73377. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB STATUS DATA:"
  73378. + " Root port status changed\n");
  73379. + DWC_DEBUGPL(DBG_HCDV, " port_connect_status_change: %d\n",
  73380. + hcd->flags.b.port_connect_status_change);
  73381. + DWC_DEBUGPL(DBG_HCDV, " port_reset_change: %d\n",
  73382. + hcd->flags.b.port_reset_change);
  73383. + DWC_DEBUGPL(DBG_HCDV, " port_enable_change: %d\n",
  73384. + hcd->flags.b.port_enable_change);
  73385. + DWC_DEBUGPL(DBG_HCDV, " port_suspend_change: %d\n",
  73386. + hcd->flags.b.port_suspend_change);
  73387. + DWC_DEBUGPL(DBG_HCDV, " port_over_current_change: %d\n",
  73388. + hcd->flags.b.port_over_current_change);
  73389. + }
  73390. +#endif
  73391. + return retval;
  73392. +}
  73393. +
  73394. +int dwc_otg_hcd_get_frame_number(dwc_otg_hcd_t * dwc_otg_hcd)
  73395. +{
  73396. + hfnum_data_t hfnum;
  73397. + hfnum.d32 =
  73398. + DWC_READ_REG32(&dwc_otg_hcd->core_if->host_if->host_global_regs->
  73399. + hfnum);
  73400. +
  73401. +#ifdef DEBUG_SOF
  73402. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD GET FRAME NUMBER %d\n",
  73403. + hfnum.b.frnum);
  73404. +#endif
  73405. + return hfnum.b.frnum;
  73406. +}
  73407. +
  73408. +int dwc_otg_hcd_start(dwc_otg_hcd_t * hcd,
  73409. + struct dwc_otg_hcd_function_ops *fops)
  73410. +{
  73411. + int retval = 0;
  73412. +
  73413. + hcd->fops = fops;
  73414. + if (!dwc_otg_is_device_mode(hcd->core_if) &&
  73415. + (!hcd->core_if->adp_enable || hcd->core_if->adp.adp_started)) {
  73416. + dwc_otg_hcd_reinit(hcd);
  73417. + } else {
  73418. + retval = -DWC_E_NO_DEVICE;
  73419. + }
  73420. +
  73421. + return retval;
  73422. +}
  73423. +
  73424. +void *dwc_otg_hcd_get_priv_data(dwc_otg_hcd_t * hcd)
  73425. +{
  73426. + return hcd->priv;
  73427. +}
  73428. +
  73429. +void dwc_otg_hcd_set_priv_data(dwc_otg_hcd_t * hcd, void *priv_data)
  73430. +{
  73431. + hcd->priv = priv_data;
  73432. +}
  73433. +
  73434. +uint32_t dwc_otg_hcd_otg_port(dwc_otg_hcd_t * hcd)
  73435. +{
  73436. + return hcd->otg_port;
  73437. +}
  73438. +
  73439. +uint32_t dwc_otg_hcd_is_b_host(dwc_otg_hcd_t * hcd)
  73440. +{
  73441. + uint32_t is_b_host;
  73442. + if (hcd->core_if->op_state == B_HOST) {
  73443. + is_b_host = 1;
  73444. + } else {
  73445. + is_b_host = 0;
  73446. + }
  73447. +
  73448. + return is_b_host;
  73449. +}
  73450. +
  73451. +dwc_otg_hcd_urb_t *dwc_otg_hcd_urb_alloc(dwc_otg_hcd_t * hcd,
  73452. + int iso_desc_count, int atomic_alloc)
  73453. +{
  73454. + dwc_otg_hcd_urb_t *dwc_otg_urb;
  73455. + uint32_t size;
  73456. +
  73457. + size =
  73458. + sizeof(*dwc_otg_urb) +
  73459. + iso_desc_count * sizeof(struct dwc_otg_hcd_iso_packet_desc);
  73460. + if (atomic_alloc)
  73461. + dwc_otg_urb = DWC_ALLOC_ATOMIC(size);
  73462. + else
  73463. + dwc_otg_urb = DWC_ALLOC(size);
  73464. +
  73465. + if (dwc_otg_urb)
  73466. + dwc_otg_urb->packet_count = iso_desc_count;
  73467. + else {
  73468. + DWC_ERROR("**** DWC OTG HCD URB alloc - "
  73469. + "%salloc of %db failed\n",
  73470. + atomic_alloc?"atomic ":"", size);
  73471. + }
  73472. + return dwc_otg_urb;
  73473. +}
  73474. +
  73475. +void dwc_otg_hcd_urb_set_pipeinfo(dwc_otg_hcd_urb_t * dwc_otg_urb,
  73476. + uint8_t dev_addr, uint8_t ep_num,
  73477. + uint8_t ep_type, uint8_t ep_dir, uint16_t mps)
  73478. +{
  73479. + dwc_otg_hcd_fill_pipe(&dwc_otg_urb->pipe_info, dev_addr, ep_num,
  73480. + ep_type, ep_dir, mps);
  73481. +#if 0
  73482. + DWC_PRINTF
  73483. + ("addr = %d, ep_num = %d, ep_dir = 0x%x, ep_type = 0x%x, mps = %d\n",
  73484. + dev_addr, ep_num, ep_dir, ep_type, mps);
  73485. +#endif
  73486. +}
  73487. +
  73488. +void dwc_otg_hcd_urb_set_params(dwc_otg_hcd_urb_t * dwc_otg_urb,
  73489. + void *urb_handle, void *buf, dwc_dma_t dma,
  73490. + uint32_t buflen, void *setup_packet,
  73491. + dwc_dma_t setup_dma, uint32_t flags,
  73492. + uint16_t interval)
  73493. +{
  73494. + dwc_otg_urb->priv = urb_handle;
  73495. + dwc_otg_urb->buf = buf;
  73496. + dwc_otg_urb->dma = dma;
  73497. + dwc_otg_urb->length = buflen;
  73498. + dwc_otg_urb->setup_packet = setup_packet;
  73499. + dwc_otg_urb->setup_dma = setup_dma;
  73500. + dwc_otg_urb->flags = flags;
  73501. + dwc_otg_urb->interval = interval;
  73502. + dwc_otg_urb->status = -DWC_E_IN_PROGRESS;
  73503. +}
  73504. +
  73505. +uint32_t dwc_otg_hcd_urb_get_status(dwc_otg_hcd_urb_t * dwc_otg_urb)
  73506. +{
  73507. + return dwc_otg_urb->status;
  73508. +}
  73509. +
  73510. +uint32_t dwc_otg_hcd_urb_get_actual_length(dwc_otg_hcd_urb_t * dwc_otg_urb)
  73511. +{
  73512. + return dwc_otg_urb->actual_length;
  73513. +}
  73514. +
  73515. +uint32_t dwc_otg_hcd_urb_get_error_count(dwc_otg_hcd_urb_t * dwc_otg_urb)
  73516. +{
  73517. + return dwc_otg_urb->error_count;
  73518. +}
  73519. +
  73520. +void dwc_otg_hcd_urb_set_iso_desc_params(dwc_otg_hcd_urb_t * dwc_otg_urb,
  73521. + int desc_num, uint32_t offset,
  73522. + uint32_t length)
  73523. +{
  73524. + dwc_otg_urb->iso_descs[desc_num].offset = offset;
  73525. + dwc_otg_urb->iso_descs[desc_num].length = length;
  73526. +}
  73527. +
  73528. +uint32_t dwc_otg_hcd_urb_get_iso_desc_status(dwc_otg_hcd_urb_t * dwc_otg_urb,
  73529. + int desc_num)
  73530. +{
  73531. + return dwc_otg_urb->iso_descs[desc_num].status;
  73532. +}
  73533. +
  73534. +uint32_t dwc_otg_hcd_urb_get_iso_desc_actual_length(dwc_otg_hcd_urb_t *
  73535. + dwc_otg_urb, int desc_num)
  73536. +{
  73537. + return dwc_otg_urb->iso_descs[desc_num].actual_length;
  73538. +}
  73539. +
  73540. +int dwc_otg_hcd_is_bandwidth_allocated(dwc_otg_hcd_t * hcd, void *ep_handle)
  73541. +{
  73542. + int allocated = 0;
  73543. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  73544. +
  73545. + if (qh) {
  73546. + if (!DWC_LIST_EMPTY(&qh->qh_list_entry)) {
  73547. + allocated = 1;
  73548. + }
  73549. + }
  73550. + return allocated;
  73551. +}
  73552. +
  73553. +int dwc_otg_hcd_is_bandwidth_freed(dwc_otg_hcd_t * hcd, void *ep_handle)
  73554. +{
  73555. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  73556. + int freed = 0;
  73557. + DWC_ASSERT(qh, "qh is not allocated\n");
  73558. +
  73559. + if (DWC_LIST_EMPTY(&qh->qh_list_entry)) {
  73560. + freed = 1;
  73561. + }
  73562. +
  73563. + return freed;
  73564. +}
  73565. +
  73566. +uint8_t dwc_otg_hcd_get_ep_bandwidth(dwc_otg_hcd_t * hcd, void *ep_handle)
  73567. +{
  73568. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  73569. + DWC_ASSERT(qh, "qh is not allocated\n");
  73570. + return qh->usecs;
  73571. +}
  73572. +
  73573. +void dwc_otg_hcd_dump_state(dwc_otg_hcd_t * hcd)
  73574. +{
  73575. +#ifdef DEBUG
  73576. + int num_channels;
  73577. + int i;
  73578. + gnptxsts_data_t np_tx_status;
  73579. + hptxsts_data_t p_tx_status;
  73580. +
  73581. + num_channels = hcd->core_if->core_params->host_channels;
  73582. + DWC_PRINTF("\n");
  73583. + DWC_PRINTF
  73584. + ("************************************************************\n");
  73585. + DWC_PRINTF("HCD State:\n");
  73586. + DWC_PRINTF(" Num channels: %d\n", num_channels);
  73587. + for (i = 0; i < num_channels; i++) {
  73588. + dwc_hc_t *hc = hcd->hc_ptr_array[i];
  73589. + DWC_PRINTF(" Channel %d:\n", i);
  73590. + DWC_PRINTF(" dev_addr: %d, ep_num: %d, ep_is_in: %d\n",
  73591. + hc->dev_addr, hc->ep_num, hc->ep_is_in);
  73592. + DWC_PRINTF(" speed: %d\n", hc->speed);
  73593. + DWC_PRINTF(" ep_type: %d\n", hc->ep_type);
  73594. + DWC_PRINTF(" max_packet: %d\n", hc->max_packet);
  73595. + DWC_PRINTF(" data_pid_start: %d\n", hc->data_pid_start);
  73596. + DWC_PRINTF(" multi_count: %d\n", hc->multi_count);
  73597. + DWC_PRINTF(" xfer_started: %d\n", hc->xfer_started);
  73598. + DWC_PRINTF(" xfer_buff: %p\n", hc->xfer_buff);
  73599. + DWC_PRINTF(" xfer_len: %d\n", hc->xfer_len);
  73600. + DWC_PRINTF(" xfer_count: %d\n", hc->xfer_count);
  73601. + DWC_PRINTF(" halt_on_queue: %d\n", hc->halt_on_queue);
  73602. + DWC_PRINTF(" halt_pending: %d\n", hc->halt_pending);
  73603. + DWC_PRINTF(" halt_status: %d\n", hc->halt_status);
  73604. + DWC_PRINTF(" do_split: %d\n", hc->do_split);
  73605. + DWC_PRINTF(" complete_split: %d\n", hc->complete_split);
  73606. + DWC_PRINTF(" hub_addr: %d\n", hc->hub_addr);
  73607. + DWC_PRINTF(" port_addr: %d\n", hc->port_addr);
  73608. + DWC_PRINTF(" xact_pos: %d\n", hc->xact_pos);
  73609. + DWC_PRINTF(" requests: %d\n", hc->requests);
  73610. + DWC_PRINTF(" qh: %p\n", hc->qh);
  73611. + if (hc->xfer_started) {
  73612. + hfnum_data_t hfnum;
  73613. + hcchar_data_t hcchar;
  73614. + hctsiz_data_t hctsiz;
  73615. + hcint_data_t hcint;
  73616. + hcintmsk_data_t hcintmsk;
  73617. + hfnum.d32 =
  73618. + DWC_READ_REG32(&hcd->core_if->
  73619. + host_if->host_global_regs->hfnum);
  73620. + hcchar.d32 =
  73621. + DWC_READ_REG32(&hcd->core_if->host_if->
  73622. + hc_regs[i]->hcchar);
  73623. + hctsiz.d32 =
  73624. + DWC_READ_REG32(&hcd->core_if->host_if->
  73625. + hc_regs[i]->hctsiz);
  73626. + hcint.d32 =
  73627. + DWC_READ_REG32(&hcd->core_if->host_if->
  73628. + hc_regs[i]->hcint);
  73629. + hcintmsk.d32 =
  73630. + DWC_READ_REG32(&hcd->core_if->host_if->
  73631. + hc_regs[i]->hcintmsk);
  73632. + DWC_PRINTF(" hfnum: 0x%08x\n", hfnum.d32);
  73633. + DWC_PRINTF(" hcchar: 0x%08x\n", hcchar.d32);
  73634. + DWC_PRINTF(" hctsiz: 0x%08x\n", hctsiz.d32);
  73635. + DWC_PRINTF(" hcint: 0x%08x\n", hcint.d32);
  73636. + DWC_PRINTF(" hcintmsk: 0x%08x\n", hcintmsk.d32);
  73637. + }
  73638. + if (hc->xfer_started && hc->qh) {
  73639. + dwc_otg_qtd_t *qtd;
  73640. + dwc_otg_hcd_urb_t *urb;
  73641. +
  73642. + DWC_CIRCLEQ_FOREACH(qtd, &hc->qh->qtd_list, qtd_list_entry) {
  73643. + if (!qtd->in_process)
  73644. + break;
  73645. +
  73646. + urb = qtd->urb;
  73647. + DWC_PRINTF(" URB Info:\n");
  73648. + DWC_PRINTF(" qtd: %p, urb: %p\n", qtd, urb);
  73649. + if (urb) {
  73650. + DWC_PRINTF(" Dev: %d, EP: %d %s\n",
  73651. + dwc_otg_hcd_get_dev_addr(&urb->
  73652. + pipe_info),
  73653. + dwc_otg_hcd_get_ep_num(&urb->
  73654. + pipe_info),
  73655. + dwc_otg_hcd_is_pipe_in(&urb->
  73656. + pipe_info) ?
  73657. + "IN" : "OUT");
  73658. + DWC_PRINTF(" Max packet size: %d\n",
  73659. + dwc_otg_hcd_get_mps(&urb->
  73660. + pipe_info));
  73661. + DWC_PRINTF(" transfer_buffer: %p\n",
  73662. + urb->buf);
  73663. + DWC_PRINTF(" transfer_dma: %p\n",
  73664. + (void *)urb->dma);
  73665. + DWC_PRINTF(" transfer_buffer_length: %d\n",
  73666. + urb->length);
  73667. + DWC_PRINTF(" actual_length: %d\n",
  73668. + urb->actual_length);
  73669. + }
  73670. + }
  73671. + }
  73672. + }
  73673. + DWC_PRINTF(" non_periodic_channels: %d\n", hcd->non_periodic_channels);
  73674. + DWC_PRINTF(" periodic_channels: %d\n", hcd->periodic_channels);
  73675. + DWC_PRINTF(" periodic_usecs: %d\n", hcd->periodic_usecs);
  73676. + np_tx_status.d32 =
  73677. + DWC_READ_REG32(&hcd->core_if->core_global_regs->gnptxsts);
  73678. + DWC_PRINTF(" NP Tx Req Queue Space Avail: %d\n",
  73679. + np_tx_status.b.nptxqspcavail);
  73680. + DWC_PRINTF(" NP Tx FIFO Space Avail: %d\n",
  73681. + np_tx_status.b.nptxfspcavail);
  73682. + p_tx_status.d32 =
  73683. + DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hptxsts);
  73684. + DWC_PRINTF(" P Tx Req Queue Space Avail: %d\n",
  73685. + p_tx_status.b.ptxqspcavail);
  73686. + DWC_PRINTF(" P Tx FIFO Space Avail: %d\n", p_tx_status.b.ptxfspcavail);
  73687. + dwc_otg_hcd_dump_frrem(hcd);
  73688. + dwc_otg_dump_global_registers(hcd->core_if);
  73689. + dwc_otg_dump_host_registers(hcd->core_if);
  73690. + DWC_PRINTF
  73691. + ("************************************************************\n");
  73692. + DWC_PRINTF("\n");
  73693. +#endif
  73694. +}
  73695. +
  73696. +#ifdef DEBUG
  73697. +void dwc_print_setup_data(uint8_t * setup)
  73698. +{
  73699. + int i;
  73700. + if (CHK_DEBUG_LEVEL(DBG_HCD)) {
  73701. + DWC_PRINTF("Setup Data = MSB ");
  73702. + for (i = 7; i >= 0; i--)
  73703. + DWC_PRINTF("%02x ", setup[i]);
  73704. + DWC_PRINTF("\n");
  73705. + DWC_PRINTF(" bmRequestType Tranfer = %s\n",
  73706. + (setup[0] & 0x80) ? "Device-to-Host" :
  73707. + "Host-to-Device");
  73708. + DWC_PRINTF(" bmRequestType Type = ");
  73709. + switch ((setup[0] & 0x60) >> 5) {
  73710. + case 0:
  73711. + DWC_PRINTF("Standard\n");
  73712. + break;
  73713. + case 1:
  73714. + DWC_PRINTF("Class\n");
  73715. + break;
  73716. + case 2:
  73717. + DWC_PRINTF("Vendor\n");
  73718. + break;
  73719. + case 3:
  73720. + DWC_PRINTF("Reserved\n");
  73721. + break;
  73722. + }
  73723. + DWC_PRINTF(" bmRequestType Recipient = ");
  73724. + switch (setup[0] & 0x1f) {
  73725. + case 0:
  73726. + DWC_PRINTF("Device\n");
  73727. + break;
  73728. + case 1:
  73729. + DWC_PRINTF("Interface\n");
  73730. + break;
  73731. + case 2:
  73732. + DWC_PRINTF("Endpoint\n");
  73733. + break;
  73734. + case 3:
  73735. + DWC_PRINTF("Other\n");
  73736. + break;
  73737. + default:
  73738. + DWC_PRINTF("Reserved\n");
  73739. + break;
  73740. + }
  73741. + DWC_PRINTF(" bRequest = 0x%0x\n", setup[1]);
  73742. + DWC_PRINTF(" wValue = 0x%0x\n", *((uint16_t *) & setup[2]));
  73743. + DWC_PRINTF(" wIndex = 0x%0x\n", *((uint16_t *) & setup[4]));
  73744. + DWC_PRINTF(" wLength = 0x%0x\n\n", *((uint16_t *) & setup[6]));
  73745. + }
  73746. +}
  73747. +#endif
  73748. +
  73749. +void dwc_otg_hcd_dump_frrem(dwc_otg_hcd_t * hcd)
  73750. +{
  73751. +#if 0
  73752. + DWC_PRINTF("Frame remaining at SOF:\n");
  73753. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  73754. + hcd->frrem_samples, hcd->frrem_accum,
  73755. + (hcd->frrem_samples > 0) ?
  73756. + hcd->frrem_accum / hcd->frrem_samples : 0);
  73757. +
  73758. + DWC_PRINTF("\n");
  73759. + DWC_PRINTF("Frame remaining at start_transfer (uframe 7):\n");
  73760. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  73761. + hcd->core_if->hfnum_7_samples,
  73762. + hcd->core_if->hfnum_7_frrem_accum,
  73763. + (hcd->core_if->hfnum_7_samples >
  73764. + 0) ? hcd->core_if->hfnum_7_frrem_accum /
  73765. + hcd->core_if->hfnum_7_samples : 0);
  73766. + DWC_PRINTF("Frame remaining at start_transfer (uframe 0):\n");
  73767. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  73768. + hcd->core_if->hfnum_0_samples,
  73769. + hcd->core_if->hfnum_0_frrem_accum,
  73770. + (hcd->core_if->hfnum_0_samples >
  73771. + 0) ? hcd->core_if->hfnum_0_frrem_accum /
  73772. + hcd->core_if->hfnum_0_samples : 0);
  73773. + DWC_PRINTF("Frame remaining at start_transfer (uframe 1-6):\n");
  73774. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  73775. + hcd->core_if->hfnum_other_samples,
  73776. + hcd->core_if->hfnum_other_frrem_accum,
  73777. + (hcd->core_if->hfnum_other_samples >
  73778. + 0) ? hcd->core_if->hfnum_other_frrem_accum /
  73779. + hcd->core_if->hfnum_other_samples : 0);
  73780. +
  73781. + DWC_PRINTF("\n");
  73782. + DWC_PRINTF("Frame remaining at sample point A (uframe 7):\n");
  73783. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  73784. + hcd->hfnum_7_samples_a, hcd->hfnum_7_frrem_accum_a,
  73785. + (hcd->hfnum_7_samples_a > 0) ?
  73786. + hcd->hfnum_7_frrem_accum_a / hcd->hfnum_7_samples_a : 0);
  73787. + DWC_PRINTF("Frame remaining at sample point A (uframe 0):\n");
  73788. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  73789. + hcd->hfnum_0_samples_a, hcd->hfnum_0_frrem_accum_a,
  73790. + (hcd->hfnum_0_samples_a > 0) ?
  73791. + hcd->hfnum_0_frrem_accum_a / hcd->hfnum_0_samples_a : 0);
  73792. + DWC_PRINTF("Frame remaining at sample point A (uframe 1-6):\n");
  73793. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  73794. + hcd->hfnum_other_samples_a, hcd->hfnum_other_frrem_accum_a,
  73795. + (hcd->hfnum_other_samples_a > 0) ?
  73796. + hcd->hfnum_other_frrem_accum_a /
  73797. + hcd->hfnum_other_samples_a : 0);
  73798. +
  73799. + DWC_PRINTF("\n");
  73800. + DWC_PRINTF("Frame remaining at sample point B (uframe 7):\n");
  73801. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  73802. + hcd->hfnum_7_samples_b, hcd->hfnum_7_frrem_accum_b,
  73803. + (hcd->hfnum_7_samples_b > 0) ?
  73804. + hcd->hfnum_7_frrem_accum_b / hcd->hfnum_7_samples_b : 0);
  73805. + DWC_PRINTF("Frame remaining at sample point B (uframe 0):\n");
  73806. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  73807. + hcd->hfnum_0_samples_b, hcd->hfnum_0_frrem_accum_b,
  73808. + (hcd->hfnum_0_samples_b > 0) ?
  73809. + hcd->hfnum_0_frrem_accum_b / hcd->hfnum_0_samples_b : 0);
  73810. + DWC_PRINTF("Frame remaining at sample point B (uframe 1-6):\n");
  73811. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  73812. + hcd->hfnum_other_samples_b, hcd->hfnum_other_frrem_accum_b,
  73813. + (hcd->hfnum_other_samples_b > 0) ?
  73814. + hcd->hfnum_other_frrem_accum_b /
  73815. + hcd->hfnum_other_samples_b : 0);
  73816. +#endif
  73817. +}
  73818. +
  73819. +#endif /* DWC_DEVICE_ONLY */
  73820. diff -Nur linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_hcd_ddma.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_ddma.c
  73821. --- linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_hcd_ddma.c 1970-01-01 01:00:00.000000000 +0100
  73822. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_ddma.c 2014-04-24 15:37:13.314990533 +0200
  73823. @@ -0,0 +1,1132 @@
  73824. +/*==========================================================================
  73825. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_ddma.c $
  73826. + * $Revision: #10 $
  73827. + * $Date: 2011/10/20 $
  73828. + * $Change: 1869464 $
  73829. + *
  73830. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  73831. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  73832. + * otherwise expressly agreed to in writing between Synopsys and you.
  73833. + *
  73834. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  73835. + * any End User Software License Agreement or Agreement for Licensed Product
  73836. + * with Synopsys or any supplement thereto. You are permitted to use and
  73837. + * redistribute this Software in source and binary forms, with or without
  73838. + * modification, provided that redistributions of source code must retain this
  73839. + * notice. You may not view, use, disclose, copy or distribute this file or
  73840. + * any information contained herein except pursuant to this license grant from
  73841. + * Synopsys. If you do not agree with this notice, including the disclaimer
  73842. + * below, then you are not authorized to use the Software.
  73843. + *
  73844. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  73845. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  73846. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  73847. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  73848. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  73849. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  73850. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  73851. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  73852. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  73853. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  73854. + * DAMAGE.
  73855. + * ========================================================================== */
  73856. +#ifndef DWC_DEVICE_ONLY
  73857. +
  73858. +/** @file
  73859. + * This file contains Descriptor DMA support implementation for host mode.
  73860. + */
  73861. +
  73862. +#include "dwc_otg_hcd.h"
  73863. +#include "dwc_otg_regs.h"
  73864. +
  73865. +extern bool microframe_schedule;
  73866. +
  73867. +static inline uint8_t frame_list_idx(uint16_t frame)
  73868. +{
  73869. + return (frame & (MAX_FRLIST_EN_NUM - 1));
  73870. +}
  73871. +
  73872. +static inline uint16_t desclist_idx_inc(uint16_t idx, uint16_t inc, uint8_t speed)
  73873. +{
  73874. + return (idx + inc) &
  73875. + (((speed ==
  73876. + DWC_OTG_EP_SPEED_HIGH) ? MAX_DMA_DESC_NUM_HS_ISOC :
  73877. + MAX_DMA_DESC_NUM_GENERIC) - 1);
  73878. +}
  73879. +
  73880. +static inline uint16_t desclist_idx_dec(uint16_t idx, uint16_t inc, uint8_t speed)
  73881. +{
  73882. + return (idx - inc) &
  73883. + (((speed ==
  73884. + DWC_OTG_EP_SPEED_HIGH) ? MAX_DMA_DESC_NUM_HS_ISOC :
  73885. + MAX_DMA_DESC_NUM_GENERIC) - 1);
  73886. +}
  73887. +
  73888. +static inline uint16_t max_desc_num(dwc_otg_qh_t * qh)
  73889. +{
  73890. + return (((qh->ep_type == UE_ISOCHRONOUS)
  73891. + && (qh->dev_speed == DWC_OTG_EP_SPEED_HIGH))
  73892. + ? MAX_DMA_DESC_NUM_HS_ISOC : MAX_DMA_DESC_NUM_GENERIC);
  73893. +}
  73894. +static inline uint16_t frame_incr_val(dwc_otg_qh_t * qh)
  73895. +{
  73896. + return ((qh->dev_speed == DWC_OTG_EP_SPEED_HIGH)
  73897. + ? ((qh->interval + 8 - 1) / 8)
  73898. + : qh->interval);
  73899. +}
  73900. +
  73901. +static int desc_list_alloc(dwc_otg_qh_t * qh)
  73902. +{
  73903. + int retval = 0;
  73904. +
  73905. + qh->desc_list = (dwc_otg_host_dma_desc_t *)
  73906. + DWC_DMA_ALLOC(sizeof(dwc_otg_host_dma_desc_t) * max_desc_num(qh),
  73907. + &qh->desc_list_dma);
  73908. +
  73909. + if (!qh->desc_list) {
  73910. + retval = -DWC_E_NO_MEMORY;
  73911. + DWC_ERROR("%s: DMA descriptor list allocation failed\n", __func__);
  73912. +
  73913. + }
  73914. +
  73915. + dwc_memset(qh->desc_list, 0x00,
  73916. + sizeof(dwc_otg_host_dma_desc_t) * max_desc_num(qh));
  73917. +
  73918. + qh->n_bytes =
  73919. + (uint32_t *) DWC_ALLOC(sizeof(uint32_t) * max_desc_num(qh));
  73920. +
  73921. + if (!qh->n_bytes) {
  73922. + retval = -DWC_E_NO_MEMORY;
  73923. + DWC_ERROR
  73924. + ("%s: Failed to allocate array for descriptors' size actual values\n",
  73925. + __func__);
  73926. +
  73927. + }
  73928. + return retval;
  73929. +
  73930. +}
  73931. +
  73932. +static void desc_list_free(dwc_otg_qh_t * qh)
  73933. +{
  73934. + if (qh->desc_list) {
  73935. + DWC_DMA_FREE(max_desc_num(qh), qh->desc_list,
  73936. + qh->desc_list_dma);
  73937. + qh->desc_list = NULL;
  73938. + }
  73939. +
  73940. + if (qh->n_bytes) {
  73941. + DWC_FREE(qh->n_bytes);
  73942. + qh->n_bytes = NULL;
  73943. + }
  73944. +}
  73945. +
  73946. +static int frame_list_alloc(dwc_otg_hcd_t * hcd)
  73947. +{
  73948. + int retval = 0;
  73949. + if (hcd->frame_list)
  73950. + return 0;
  73951. +
  73952. + hcd->frame_list = DWC_DMA_ALLOC(4 * MAX_FRLIST_EN_NUM,
  73953. + &hcd->frame_list_dma);
  73954. + if (!hcd->frame_list) {
  73955. + retval = -DWC_E_NO_MEMORY;
  73956. + DWC_ERROR("%s: Frame List allocation failed\n", __func__);
  73957. + }
  73958. +
  73959. + dwc_memset(hcd->frame_list, 0x00, 4 * MAX_FRLIST_EN_NUM);
  73960. +
  73961. + return retval;
  73962. +}
  73963. +
  73964. +static void frame_list_free(dwc_otg_hcd_t * hcd)
  73965. +{
  73966. + if (!hcd->frame_list)
  73967. + return;
  73968. +
  73969. + DWC_DMA_FREE(4 * MAX_FRLIST_EN_NUM, hcd->frame_list, hcd->frame_list_dma);
  73970. + hcd->frame_list = NULL;
  73971. +}
  73972. +
  73973. +static void per_sched_enable(dwc_otg_hcd_t * hcd, uint16_t fr_list_en)
  73974. +{
  73975. +
  73976. + hcfg_data_t hcfg;
  73977. +
  73978. + hcfg.d32 = DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hcfg);
  73979. +
  73980. + if (hcfg.b.perschedena) {
  73981. + /* already enabled */
  73982. + return;
  73983. + }
  73984. +
  73985. + DWC_WRITE_REG32(&hcd->core_if->host_if->host_global_regs->hflbaddr,
  73986. + hcd->frame_list_dma);
  73987. +
  73988. + switch (fr_list_en) {
  73989. + case 64:
  73990. + hcfg.b.frlisten = 3;
  73991. + break;
  73992. + case 32:
  73993. + hcfg.b.frlisten = 2;
  73994. + break;
  73995. + case 16:
  73996. + hcfg.b.frlisten = 1;
  73997. + break;
  73998. + case 8:
  73999. + hcfg.b.frlisten = 0;
  74000. + break;
  74001. + default:
  74002. + break;
  74003. + }
  74004. +
  74005. + hcfg.b.perschedena = 1;
  74006. +
  74007. + DWC_DEBUGPL(DBG_HCD, "Enabling Periodic schedule\n");
  74008. + DWC_WRITE_REG32(&hcd->core_if->host_if->host_global_regs->hcfg, hcfg.d32);
  74009. +
  74010. +}
  74011. +
  74012. +static void per_sched_disable(dwc_otg_hcd_t * hcd)
  74013. +{
  74014. + hcfg_data_t hcfg;
  74015. +
  74016. + hcfg.d32 = DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hcfg);
  74017. +
  74018. + if (!hcfg.b.perschedena) {
  74019. + /* already disabled */
  74020. + return;
  74021. + }
  74022. + hcfg.b.perschedena = 0;
  74023. +
  74024. + DWC_DEBUGPL(DBG_HCD, "Disabling Periodic schedule\n");
  74025. + DWC_WRITE_REG32(&hcd->core_if->host_if->host_global_regs->hcfg, hcfg.d32);
  74026. +}
  74027. +
  74028. +/*
  74029. + * Activates/Deactivates FrameList entries for the channel
  74030. + * based on endpoint servicing period.
  74031. + */
  74032. +void update_frame_list(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh, uint8_t enable)
  74033. +{
  74034. + uint16_t i, j, inc;
  74035. + dwc_hc_t *hc = NULL;
  74036. +
  74037. + if (!qh->channel) {
  74038. + DWC_ERROR("qh->channel = %p", qh->channel);
  74039. + return;
  74040. + }
  74041. +
  74042. + if (!hcd) {
  74043. + DWC_ERROR("------hcd = %p", hcd);
  74044. + return;
  74045. + }
  74046. +
  74047. + if (!hcd->frame_list) {
  74048. + DWC_ERROR("-------hcd->frame_list = %p", hcd->frame_list);
  74049. + return;
  74050. + }
  74051. +
  74052. + hc = qh->channel;
  74053. + inc = frame_incr_val(qh);
  74054. + if (qh->ep_type == UE_ISOCHRONOUS)
  74055. + i = frame_list_idx(qh->sched_frame);
  74056. + else
  74057. + i = 0;
  74058. +
  74059. + j = i;
  74060. + do {
  74061. + if (enable)
  74062. + hcd->frame_list[j] |= (1 << hc->hc_num);
  74063. + else
  74064. + hcd->frame_list[j] &= ~(1 << hc->hc_num);
  74065. + j = (j + inc) & (MAX_FRLIST_EN_NUM - 1);
  74066. + }
  74067. + while (j != i);
  74068. + if (!enable)
  74069. + return;
  74070. + hc->schinfo = 0;
  74071. + if (qh->channel->speed == DWC_OTG_EP_SPEED_HIGH) {
  74072. + j = 1;
  74073. + /* TODO - check this */
  74074. + inc = (8 + qh->interval - 1) / qh->interval;
  74075. + for (i = 0; i < inc; i++) {
  74076. + hc->schinfo |= j;
  74077. + j = j << qh->interval;
  74078. + }
  74079. + } else {
  74080. + hc->schinfo = 0xff;
  74081. + }
  74082. +}
  74083. +
  74084. +#if 1
  74085. +void dump_frame_list(dwc_otg_hcd_t * hcd)
  74086. +{
  74087. + int i = 0;
  74088. + DWC_PRINTF("--FRAME LIST (hex) --\n");
  74089. + for (i = 0; i < MAX_FRLIST_EN_NUM; i++) {
  74090. + DWC_PRINTF("%x\t", hcd->frame_list[i]);
  74091. + if (!(i % 8) && i)
  74092. + DWC_PRINTF("\n");
  74093. + }
  74094. + DWC_PRINTF("\n----\n");
  74095. +
  74096. +}
  74097. +#endif
  74098. +
  74099. +static void release_channel_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  74100. +{
  74101. + dwc_irqflags_t flags;
  74102. + dwc_spinlock_t *channel_lock = hcd->channel_lock;
  74103. +
  74104. + dwc_hc_t *hc = qh->channel;
  74105. + if (dwc_qh_is_non_per(qh)) {
  74106. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  74107. + if (!microframe_schedule)
  74108. + hcd->non_periodic_channels--;
  74109. + else
  74110. + hcd->available_host_channels++;
  74111. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  74112. + } else
  74113. + update_frame_list(hcd, qh, 0);
  74114. +
  74115. + /*
  74116. + * The condition is added to prevent double cleanup try in case of device
  74117. + * disconnect. See channel cleanup in dwc_otg_hcd_disconnect_cb().
  74118. + */
  74119. + if (hc->qh) {
  74120. + dwc_otg_hc_cleanup(hcd->core_if, hc);
  74121. + DWC_CIRCLEQ_INSERT_TAIL(&hcd->free_hc_list, hc, hc_list_entry);
  74122. + hc->qh = NULL;
  74123. + }
  74124. +
  74125. + qh->channel = NULL;
  74126. + qh->ntd = 0;
  74127. +
  74128. + if (qh->desc_list) {
  74129. + dwc_memset(qh->desc_list, 0x00,
  74130. + sizeof(dwc_otg_host_dma_desc_t) * max_desc_num(qh));
  74131. + }
  74132. +}
  74133. +
  74134. +/**
  74135. + * Initializes a QH structure's Descriptor DMA related members.
  74136. + * Allocates memory for descriptor list.
  74137. + * On first periodic QH, allocates memory for FrameList
  74138. + * and enables periodic scheduling.
  74139. + *
  74140. + * @param hcd The HCD state structure for the DWC OTG controller.
  74141. + * @param qh The QH to init.
  74142. + *
  74143. + * @return 0 if successful, negative error code otherwise.
  74144. + */
  74145. +int dwc_otg_hcd_qh_init_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  74146. +{
  74147. + int retval = 0;
  74148. +
  74149. + if (qh->do_split) {
  74150. + DWC_ERROR("SPLIT Transfers are not supported in Descriptor DMA.\n");
  74151. + return -1;
  74152. + }
  74153. +
  74154. + retval = desc_list_alloc(qh);
  74155. +
  74156. + if ((retval == 0)
  74157. + && (qh->ep_type == UE_ISOCHRONOUS || qh->ep_type == UE_INTERRUPT)) {
  74158. + if (!hcd->frame_list) {
  74159. + retval = frame_list_alloc(hcd);
  74160. + /* Enable periodic schedule on first periodic QH */
  74161. + if (retval == 0)
  74162. + per_sched_enable(hcd, MAX_FRLIST_EN_NUM);
  74163. + }
  74164. + }
  74165. +
  74166. + qh->ntd = 0;
  74167. +
  74168. + return retval;
  74169. +}
  74170. +
  74171. +/**
  74172. + * Frees descriptor list memory associated with the QH.
  74173. + * If QH is periodic and the last, frees FrameList memory
  74174. + * and disables periodic scheduling.
  74175. + *
  74176. + * @param hcd The HCD state structure for the DWC OTG controller.
  74177. + * @param qh The QH to init.
  74178. + */
  74179. +void dwc_otg_hcd_qh_free_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  74180. +{
  74181. + desc_list_free(qh);
  74182. +
  74183. + /*
  74184. + * Channel still assigned due to some reasons.
  74185. + * Seen on Isoc URB dequeue. Channel halted but no subsequent
  74186. + * ChHalted interrupt to release the channel. Afterwards
  74187. + * when it comes here from endpoint disable routine
  74188. + * channel remains assigned.
  74189. + */
  74190. + if (qh->channel)
  74191. + release_channel_ddma(hcd, qh);
  74192. +
  74193. + if ((qh->ep_type == UE_ISOCHRONOUS || qh->ep_type == UE_INTERRUPT)
  74194. + && (microframe_schedule || !hcd->periodic_channels) && hcd->frame_list) {
  74195. +
  74196. + per_sched_disable(hcd);
  74197. + frame_list_free(hcd);
  74198. + }
  74199. +}
  74200. +
  74201. +static uint8_t frame_to_desc_idx(dwc_otg_qh_t * qh, uint16_t frame_idx)
  74202. +{
  74203. + if (qh->dev_speed == DWC_OTG_EP_SPEED_HIGH) {
  74204. + /*
  74205. + * Descriptor set(8 descriptors) index
  74206. + * which is 8-aligned.
  74207. + */
  74208. + return (frame_idx & ((MAX_DMA_DESC_NUM_HS_ISOC / 8) - 1)) * 8;
  74209. + } else {
  74210. + return (frame_idx & (MAX_DMA_DESC_NUM_GENERIC - 1));
  74211. + }
  74212. +}
  74213. +
  74214. +/*
  74215. + * Determine starting frame for Isochronous transfer.
  74216. + * Few frames skipped to prevent race condition with HC.
  74217. + */
  74218. +static uint8_t calc_starting_frame(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh,
  74219. + uint8_t * skip_frames)
  74220. +{
  74221. + uint16_t frame = 0;
  74222. + hcd->frame_number = dwc_otg_hcd_get_frame_number(hcd);
  74223. +
  74224. + /* sched_frame is always frame number(not uFrame) both in FS and HS !! */
  74225. +
  74226. + /*
  74227. + * skip_frames is used to limit activated descriptors number
  74228. + * to avoid the situation when HC services the last activated
  74229. + * descriptor firstly.
  74230. + * Example for FS:
  74231. + * Current frame is 1, scheduled frame is 3. Since HC always fetches the descriptor
  74232. + * corresponding to curr_frame+1, the descriptor corresponding to frame 2
  74233. + * will be fetched. If the number of descriptors is max=64 (or greather) the
  74234. + * list will be fully programmed with Active descriptors and it is possible
  74235. + * case(rare) that the latest descriptor(considering rollback) corresponding
  74236. + * to frame 2 will be serviced first. HS case is more probable because, in fact,
  74237. + * up to 11 uframes(16 in the code) may be skipped.
  74238. + */
  74239. + if (qh->dev_speed == DWC_OTG_EP_SPEED_HIGH) {
  74240. + /*
  74241. + * Consider uframe counter also, to start xfer asap.
  74242. + * If half of the frame elapsed skip 2 frames otherwise
  74243. + * just 1 frame.
  74244. + * Starting descriptor index must be 8-aligned, so
  74245. + * if the current frame is near to complete the next one
  74246. + * is skipped as well.
  74247. + */
  74248. +
  74249. + if (dwc_micro_frame_num(hcd->frame_number) >= 5) {
  74250. + *skip_frames = 2 * 8;
  74251. + frame = dwc_frame_num_inc(hcd->frame_number, *skip_frames);
  74252. + } else {
  74253. + *skip_frames = 1 * 8;
  74254. + frame = dwc_frame_num_inc(hcd->frame_number, *skip_frames);
  74255. + }
  74256. +
  74257. + frame = dwc_full_frame_num(frame);
  74258. + } else {
  74259. + /*
  74260. + * Two frames are skipped for FS - the current and the next.
  74261. + * But for descriptor programming, 1 frame(descriptor) is enough,
  74262. + * see example above.
  74263. + */
  74264. + *skip_frames = 1;
  74265. + frame = dwc_frame_num_inc(hcd->frame_number, 2);
  74266. + }
  74267. +
  74268. + return frame;
  74269. +}
  74270. +
  74271. +/*
  74272. + * Calculate initial descriptor index for isochronous transfer
  74273. + * based on scheduled frame.
  74274. + */
  74275. +static uint8_t recalc_initial_desc_idx(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  74276. +{
  74277. + uint16_t frame = 0, fr_idx, fr_idx_tmp;
  74278. + uint8_t skip_frames = 0;
  74279. + /*
  74280. + * With current ISOC processing algorithm the channel is being
  74281. + * released when no more QTDs in the list(qh->ntd == 0).
  74282. + * Thus this function is called only when qh->ntd == 0 and qh->channel == 0.
  74283. + *
  74284. + * So qh->channel != NULL branch is not used and just not removed from the
  74285. + * source file. It is required for another possible approach which is,
  74286. + * do not disable and release the channel when ISOC session completed,
  74287. + * just move QH to inactive schedule until new QTD arrives.
  74288. + * On new QTD, the QH moved back to 'ready' schedule,
  74289. + * starting frame and therefore starting desc_index are recalculated.
  74290. + * In this case channel is released only on ep_disable.
  74291. + */
  74292. +
  74293. + /* Calculate starting descriptor index. For INTERRUPT endpoint it is always 0. */
  74294. + if (qh->channel) {
  74295. + frame = calc_starting_frame(hcd, qh, &skip_frames);
  74296. + /*
  74297. + * Calculate initial descriptor index based on FrameList current bitmap
  74298. + * and servicing period.
  74299. + */
  74300. + fr_idx_tmp = frame_list_idx(frame);
  74301. + fr_idx =
  74302. + (MAX_FRLIST_EN_NUM + frame_list_idx(qh->sched_frame) -
  74303. + fr_idx_tmp)
  74304. + % frame_incr_val(qh);
  74305. + fr_idx = (fr_idx + fr_idx_tmp) % MAX_FRLIST_EN_NUM;
  74306. + } else {
  74307. + qh->sched_frame = calc_starting_frame(hcd, qh, &skip_frames);
  74308. + fr_idx = frame_list_idx(qh->sched_frame);
  74309. + }
  74310. +
  74311. + qh->td_first = qh->td_last = frame_to_desc_idx(qh, fr_idx);
  74312. +
  74313. + return skip_frames;
  74314. +}
  74315. +
  74316. +#define ISOC_URB_GIVEBACK_ASAP
  74317. +
  74318. +#define MAX_ISOC_XFER_SIZE_FS 1023
  74319. +#define MAX_ISOC_XFER_SIZE_HS 3072
  74320. +#define DESCNUM_THRESHOLD 4
  74321. +
  74322. +static void init_isoc_dma_desc(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh,
  74323. + uint8_t skip_frames)
  74324. +{
  74325. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  74326. + dwc_otg_qtd_t *qtd;
  74327. + dwc_otg_host_dma_desc_t *dma_desc;
  74328. + uint16_t idx, inc, n_desc, ntd_max, max_xfer_size;
  74329. +
  74330. + idx = qh->td_last;
  74331. + inc = qh->interval;
  74332. + n_desc = 0;
  74333. +
  74334. + ntd_max = (max_desc_num(qh) + qh->interval - 1) / qh->interval;
  74335. + if (skip_frames && !qh->channel)
  74336. + ntd_max = ntd_max - skip_frames / qh->interval;
  74337. +
  74338. + max_xfer_size =
  74339. + (qh->dev_speed ==
  74340. + DWC_OTG_EP_SPEED_HIGH) ? MAX_ISOC_XFER_SIZE_HS :
  74341. + MAX_ISOC_XFER_SIZE_FS;
  74342. +
  74343. + DWC_CIRCLEQ_FOREACH(qtd, &qh->qtd_list, qtd_list_entry) {
  74344. + while ((qh->ntd < ntd_max)
  74345. + && (qtd->isoc_frame_index_last <
  74346. + qtd->urb->packet_count)) {
  74347. +
  74348. + dma_desc = &qh->desc_list[idx];
  74349. + dwc_memset(dma_desc, 0x00, sizeof(dwc_otg_host_dma_desc_t));
  74350. +
  74351. + frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index_last];
  74352. +
  74353. + if (frame_desc->length > max_xfer_size)
  74354. + qh->n_bytes[idx] = max_xfer_size;
  74355. + else
  74356. + qh->n_bytes[idx] = frame_desc->length;
  74357. + dma_desc->status.b_isoc.n_bytes = qh->n_bytes[idx];
  74358. + dma_desc->status.b_isoc.a = 1;
  74359. + dma_desc->status.b_isoc.sts = 0;
  74360. +
  74361. + dma_desc->buf = qtd->urb->dma + frame_desc->offset;
  74362. +
  74363. + qh->ntd++;
  74364. +
  74365. + qtd->isoc_frame_index_last++;
  74366. +
  74367. +#ifdef ISOC_URB_GIVEBACK_ASAP
  74368. + /*
  74369. + * Set IOC for each descriptor corresponding to the
  74370. + * last frame of the URB.
  74371. + */
  74372. + if (qtd->isoc_frame_index_last ==
  74373. + qtd->urb->packet_count)
  74374. + dma_desc->status.b_isoc.ioc = 1;
  74375. +
  74376. +#endif
  74377. + idx = desclist_idx_inc(idx, inc, qh->dev_speed);
  74378. + n_desc++;
  74379. +
  74380. + }
  74381. + qtd->in_process = 1;
  74382. + }
  74383. +
  74384. + qh->td_last = idx;
  74385. +
  74386. +#ifdef ISOC_URB_GIVEBACK_ASAP
  74387. + /* Set IOC for the last descriptor if descriptor list is full */
  74388. + if (qh->ntd == ntd_max) {
  74389. + idx = desclist_idx_dec(qh->td_last, inc, qh->dev_speed);
  74390. + qh->desc_list[idx].status.b_isoc.ioc = 1;
  74391. + }
  74392. +#else
  74393. + /*
  74394. + * Set IOC bit only for one descriptor.
  74395. + * Always try to be ahead of HW processing,
  74396. + * i.e. on IOC generation driver activates next descriptors but
  74397. + * core continues to process descriptors followed the one with IOC set.
  74398. + */
  74399. +
  74400. + if (n_desc > DESCNUM_THRESHOLD) {
  74401. + /*
  74402. + * Move IOC "up". Required even if there is only one QTD
  74403. + * in the list, cause QTDs migth continue to be queued,
  74404. + * but during the activation it was only one queued.
  74405. + * Actually more than one QTD might be in the list if this function called
  74406. + * from XferCompletion - QTDs was queued during HW processing of the previous
  74407. + * descriptor chunk.
  74408. + */
  74409. + idx = dwc_desclist_idx_dec(idx, inc * ((qh->ntd + 1) / 2), qh->dev_speed);
  74410. + } else {
  74411. + /*
  74412. + * Set the IOC for the latest descriptor
  74413. + * if either number of descriptor is not greather than threshold
  74414. + * or no more new descriptors activated.
  74415. + */
  74416. + idx = dwc_desclist_idx_dec(qh->td_last, inc, qh->dev_speed);
  74417. + }
  74418. +
  74419. + qh->desc_list[idx].status.b_isoc.ioc = 1;
  74420. +#endif
  74421. +}
  74422. +
  74423. +static void init_non_isoc_dma_desc(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  74424. +{
  74425. +
  74426. + dwc_hc_t *hc;
  74427. + dwc_otg_host_dma_desc_t *dma_desc;
  74428. + dwc_otg_qtd_t *qtd;
  74429. + int num_packets, len, n_desc = 0;
  74430. +
  74431. + hc = qh->channel;
  74432. +
  74433. + /*
  74434. + * Start with hc->xfer_buff initialized in
  74435. + * assign_and_init_hc(), then if SG transfer consists of multiple URBs,
  74436. + * this pointer re-assigned to the buffer of the currently processed QTD.
  74437. + * For non-SG request there is always one QTD active.
  74438. + */
  74439. +
  74440. + DWC_CIRCLEQ_FOREACH(qtd, &qh->qtd_list, qtd_list_entry) {
  74441. +
  74442. + if (n_desc) {
  74443. + /* SG request - more than 1 QTDs */
  74444. + hc->xfer_buff = (uint8_t *)qtd->urb->dma + qtd->urb->actual_length;
  74445. + hc->xfer_len = qtd->urb->length - qtd->urb->actual_length;
  74446. + }
  74447. +
  74448. + qtd->n_desc = 0;
  74449. +
  74450. + do {
  74451. + dma_desc = &qh->desc_list[n_desc];
  74452. + len = hc->xfer_len;
  74453. +
  74454. + if (len > MAX_DMA_DESC_SIZE)
  74455. + len = MAX_DMA_DESC_SIZE - hc->max_packet + 1;
  74456. +
  74457. + if (hc->ep_is_in) {
  74458. + if (len > 0) {
  74459. + num_packets = (len + hc->max_packet - 1) / hc->max_packet;
  74460. + } else {
  74461. + /* Need 1 packet for transfer length of 0. */
  74462. + num_packets = 1;
  74463. + }
  74464. + /* Always program an integral # of max packets for IN transfers. */
  74465. + len = num_packets * hc->max_packet;
  74466. + }
  74467. +
  74468. + dma_desc->status.b.n_bytes = len;
  74469. +
  74470. + qh->n_bytes[n_desc] = len;
  74471. +
  74472. + if ((qh->ep_type == UE_CONTROL)
  74473. + && (qtd->control_phase == DWC_OTG_CONTROL_SETUP))
  74474. + dma_desc->status.b.sup = 1; /* Setup Packet */
  74475. +
  74476. + dma_desc->status.b.a = 1; /* Active descriptor */
  74477. + dma_desc->status.b.sts = 0;
  74478. +
  74479. + dma_desc->buf =
  74480. + ((unsigned long)hc->xfer_buff & 0xffffffff);
  74481. +
  74482. + /*
  74483. + * Last descriptor(or single) of IN transfer
  74484. + * with actual size less than MaxPacket.
  74485. + */
  74486. + if (len > hc->xfer_len) {
  74487. + hc->xfer_len = 0;
  74488. + } else {
  74489. + hc->xfer_buff += len;
  74490. + hc->xfer_len -= len;
  74491. + }
  74492. +
  74493. + qtd->n_desc++;
  74494. + n_desc++;
  74495. + }
  74496. + while ((hc->xfer_len > 0) && (n_desc != MAX_DMA_DESC_NUM_GENERIC));
  74497. +
  74498. +
  74499. + qtd->in_process = 1;
  74500. +
  74501. + if (qh->ep_type == UE_CONTROL)
  74502. + break;
  74503. +
  74504. + if (n_desc == MAX_DMA_DESC_NUM_GENERIC)
  74505. + break;
  74506. + }
  74507. +
  74508. + if (n_desc) {
  74509. + /* Request Transfer Complete interrupt for the last descriptor */
  74510. + qh->desc_list[n_desc - 1].status.b.ioc = 1;
  74511. + /* End of List indicator */
  74512. + qh->desc_list[n_desc - 1].status.b.eol = 1;
  74513. +
  74514. + hc->ntd = n_desc;
  74515. + }
  74516. +}
  74517. +
  74518. +/**
  74519. + * For Control and Bulk endpoints initializes descriptor list
  74520. + * and starts the transfer.
  74521. + *
  74522. + * For Interrupt and Isochronous endpoints initializes descriptor list
  74523. + * then updates FrameList, marking appropriate entries as active.
  74524. + * In case of Isochronous, the starting descriptor index is calculated based
  74525. + * on the scheduled frame, but only on the first transfer descriptor within a session.
  74526. + * Then starts the transfer via enabling the channel.
  74527. + * For Isochronous endpoint the channel is not halted on XferComplete
  74528. + * interrupt so remains assigned to the endpoint(QH) until session is done.
  74529. + *
  74530. + * @param hcd The HCD state structure for the DWC OTG controller.
  74531. + * @param qh The QH to init.
  74532. + *
  74533. + * @return 0 if successful, negative error code otherwise.
  74534. + */
  74535. +void dwc_otg_hcd_start_xfer_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  74536. +{
  74537. + /* Channel is already assigned */
  74538. + dwc_hc_t *hc = qh->channel;
  74539. + uint8_t skip_frames = 0;
  74540. +
  74541. + switch (hc->ep_type) {
  74542. + case DWC_OTG_EP_TYPE_CONTROL:
  74543. + case DWC_OTG_EP_TYPE_BULK:
  74544. + init_non_isoc_dma_desc(hcd, qh);
  74545. +
  74546. + dwc_otg_hc_start_transfer_ddma(hcd->core_if, hc);
  74547. + break;
  74548. + case DWC_OTG_EP_TYPE_INTR:
  74549. + init_non_isoc_dma_desc(hcd, qh);
  74550. +
  74551. + update_frame_list(hcd, qh, 1);
  74552. +
  74553. + dwc_otg_hc_start_transfer_ddma(hcd->core_if, hc);
  74554. + break;
  74555. + case DWC_OTG_EP_TYPE_ISOC:
  74556. +
  74557. + if (!qh->ntd)
  74558. + skip_frames = recalc_initial_desc_idx(hcd, qh);
  74559. +
  74560. + init_isoc_dma_desc(hcd, qh, skip_frames);
  74561. +
  74562. + if (!hc->xfer_started) {
  74563. +
  74564. + update_frame_list(hcd, qh, 1);
  74565. +
  74566. + /*
  74567. + * Always set to max, instead of actual size.
  74568. + * Otherwise ntd will be changed with
  74569. + * channel being enabled. Not recommended.
  74570. + *
  74571. + */
  74572. + hc->ntd = max_desc_num(qh);
  74573. + /* Enable channel only once for ISOC */
  74574. + dwc_otg_hc_start_transfer_ddma(hcd->core_if, hc);
  74575. + }
  74576. +
  74577. + break;
  74578. + default:
  74579. +
  74580. + break;
  74581. + }
  74582. +}
  74583. +
  74584. +static void complete_isoc_xfer_ddma(dwc_otg_hcd_t * hcd,
  74585. + dwc_hc_t * hc,
  74586. + dwc_otg_hc_regs_t * hc_regs,
  74587. + dwc_otg_halt_status_e halt_status)
  74588. +{
  74589. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  74590. + dwc_otg_qtd_t *qtd, *qtd_tmp;
  74591. + dwc_otg_qh_t *qh;
  74592. + dwc_otg_host_dma_desc_t *dma_desc;
  74593. + uint16_t idx, remain;
  74594. + uint8_t urb_compl;
  74595. +
  74596. + qh = hc->qh;
  74597. + idx = qh->td_first;
  74598. +
  74599. + if (hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE) {
  74600. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &hc->qh->qtd_list, qtd_list_entry)
  74601. + qtd->in_process = 0;
  74602. + return;
  74603. + } else if ((halt_status == DWC_OTG_HC_XFER_AHB_ERR) ||
  74604. + (halt_status == DWC_OTG_HC_XFER_BABBLE_ERR)) {
  74605. + /*
  74606. + * Channel is halted in these error cases.
  74607. + * Considered as serious issues.
  74608. + * Complete all URBs marking all frames as failed,
  74609. + * irrespective whether some of the descriptors(frames) succeeded or no.
  74610. + * Pass error code to completion routine as well, to
  74611. + * update urb->status, some of class drivers might use it to stop
  74612. + * queing transfer requests.
  74613. + */
  74614. + int err = (halt_status == DWC_OTG_HC_XFER_AHB_ERR)
  74615. + ? (-DWC_E_IO)
  74616. + : (-DWC_E_OVERFLOW);
  74617. +
  74618. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &hc->qh->qtd_list, qtd_list_entry) {
  74619. + for (idx = 0; idx < qtd->urb->packet_count; idx++) {
  74620. + frame_desc = &qtd->urb->iso_descs[idx];
  74621. + frame_desc->status = err;
  74622. + }
  74623. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, err);
  74624. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  74625. + }
  74626. + return;
  74627. + }
  74628. +
  74629. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &hc->qh->qtd_list, qtd_list_entry) {
  74630. +
  74631. + if (!qtd->in_process)
  74632. + break;
  74633. +
  74634. + urb_compl = 0;
  74635. +
  74636. + do {
  74637. +
  74638. + dma_desc = &qh->desc_list[idx];
  74639. +
  74640. + frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  74641. + remain = hc->ep_is_in ? dma_desc->status.b_isoc.n_bytes : 0;
  74642. +
  74643. + if (dma_desc->status.b_isoc.sts == DMA_DESC_STS_PKTERR) {
  74644. + /*
  74645. + * XactError or, unable to complete all the transactions
  74646. + * in the scheduled micro-frame/frame,
  74647. + * both indicated by DMA_DESC_STS_PKTERR.
  74648. + */
  74649. + qtd->urb->error_count++;
  74650. + frame_desc->actual_length = qh->n_bytes[idx] - remain;
  74651. + frame_desc->status = -DWC_E_PROTOCOL;
  74652. + } else {
  74653. + /* Success */
  74654. +
  74655. + frame_desc->actual_length = qh->n_bytes[idx] - remain;
  74656. + frame_desc->status = 0;
  74657. + }
  74658. +
  74659. + if (++qtd->isoc_frame_index == qtd->urb->packet_count) {
  74660. + /*
  74661. + * urb->status is not used for isoc transfers here.
  74662. + * The individual frame_desc status are used instead.
  74663. + */
  74664. +
  74665. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  74666. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  74667. +
  74668. + /*
  74669. + * This check is necessary because urb_dequeue can be called
  74670. + * from urb complete callback(sound driver example).
  74671. + * All pending URBs are dequeued there, so no need for
  74672. + * further processing.
  74673. + */
  74674. + if (hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE) {
  74675. + return;
  74676. + }
  74677. +
  74678. + urb_compl = 1;
  74679. +
  74680. + }
  74681. +
  74682. + qh->ntd--;
  74683. +
  74684. + /* Stop if IOC requested descriptor reached */
  74685. + if (dma_desc->status.b_isoc.ioc) {
  74686. + idx = desclist_idx_inc(idx, qh->interval, hc->speed);
  74687. + goto stop_scan;
  74688. + }
  74689. +
  74690. + idx = desclist_idx_inc(idx, qh->interval, hc->speed);
  74691. +
  74692. + if (urb_compl)
  74693. + break;
  74694. + }
  74695. + while (idx != qh->td_first);
  74696. + }
  74697. +stop_scan:
  74698. + qh->td_first = idx;
  74699. +}
  74700. +
  74701. +uint8_t update_non_isoc_urb_state_ddma(dwc_otg_hcd_t * hcd,
  74702. + dwc_hc_t * hc,
  74703. + dwc_otg_qtd_t * qtd,
  74704. + dwc_otg_host_dma_desc_t * dma_desc,
  74705. + dwc_otg_halt_status_e halt_status,
  74706. + uint32_t n_bytes, uint8_t * xfer_done)
  74707. +{
  74708. +
  74709. + uint16_t remain = hc->ep_is_in ? dma_desc->status.b.n_bytes : 0;
  74710. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  74711. +
  74712. + if (halt_status == DWC_OTG_HC_XFER_AHB_ERR) {
  74713. + urb->status = -DWC_E_IO;
  74714. + return 1;
  74715. + }
  74716. + if (dma_desc->status.b.sts == DMA_DESC_STS_PKTERR) {
  74717. + switch (halt_status) {
  74718. + case DWC_OTG_HC_XFER_STALL:
  74719. + urb->status = -DWC_E_PIPE;
  74720. + break;
  74721. + case DWC_OTG_HC_XFER_BABBLE_ERR:
  74722. + urb->status = -DWC_E_OVERFLOW;
  74723. + break;
  74724. + case DWC_OTG_HC_XFER_XACT_ERR:
  74725. + urb->status = -DWC_E_PROTOCOL;
  74726. + break;
  74727. + default:
  74728. + DWC_ERROR("%s: Unhandled descriptor error status (%d)\n", __func__,
  74729. + halt_status);
  74730. + break;
  74731. + }
  74732. + return 1;
  74733. + }
  74734. +
  74735. + if (dma_desc->status.b.a == 1) {
  74736. + DWC_DEBUGPL(DBG_HCDV,
  74737. + "Active descriptor encountered on channel %d\n",
  74738. + hc->hc_num);
  74739. + return 0;
  74740. + }
  74741. +
  74742. + if (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL) {
  74743. + if (qtd->control_phase == DWC_OTG_CONTROL_DATA) {
  74744. + urb->actual_length += n_bytes - remain;
  74745. + if (remain || urb->actual_length == urb->length) {
  74746. + /*
  74747. + * For Control Data stage do not set urb->status=0 to prevent
  74748. + * URB callback. Set it when Status phase done. See below.
  74749. + */
  74750. + *xfer_done = 1;
  74751. + }
  74752. +
  74753. + } else if (qtd->control_phase == DWC_OTG_CONTROL_STATUS) {
  74754. + urb->status = 0;
  74755. + *xfer_done = 1;
  74756. + }
  74757. + /* No handling for SETUP stage */
  74758. + } else {
  74759. + /* BULK and INTR */
  74760. + urb->actual_length += n_bytes - remain;
  74761. + if (remain || urb->actual_length == urb->length) {
  74762. + urb->status = 0;
  74763. + *xfer_done = 1;
  74764. + }
  74765. + }
  74766. +
  74767. + return 0;
  74768. +}
  74769. +
  74770. +static void complete_non_isoc_xfer_ddma(dwc_otg_hcd_t * hcd,
  74771. + dwc_hc_t * hc,
  74772. + dwc_otg_hc_regs_t * hc_regs,
  74773. + dwc_otg_halt_status_e halt_status)
  74774. +{
  74775. + dwc_otg_hcd_urb_t *urb = NULL;
  74776. + dwc_otg_qtd_t *qtd, *qtd_tmp;
  74777. + dwc_otg_qh_t *qh;
  74778. + dwc_otg_host_dma_desc_t *dma_desc;
  74779. + uint32_t n_bytes, n_desc, i;
  74780. + uint8_t failed = 0, xfer_done;
  74781. +
  74782. + n_desc = 0;
  74783. +
  74784. + qh = hc->qh;
  74785. +
  74786. + if (hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE) {
  74787. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &hc->qh->qtd_list, qtd_list_entry) {
  74788. + qtd->in_process = 0;
  74789. + }
  74790. + return;
  74791. + }
  74792. +
  74793. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &qh->qtd_list, qtd_list_entry) {
  74794. +
  74795. + urb = qtd->urb;
  74796. +
  74797. + n_bytes = 0;
  74798. + xfer_done = 0;
  74799. +
  74800. + for (i = 0; i < qtd->n_desc; i++) {
  74801. + dma_desc = &qh->desc_list[n_desc];
  74802. +
  74803. + n_bytes = qh->n_bytes[n_desc];
  74804. +
  74805. + failed =
  74806. + update_non_isoc_urb_state_ddma(hcd, hc, qtd,
  74807. + dma_desc,
  74808. + halt_status, n_bytes,
  74809. + &xfer_done);
  74810. +
  74811. + if (failed
  74812. + || (xfer_done
  74813. + && (urb->status != -DWC_E_IN_PROGRESS))) {
  74814. +
  74815. + hcd->fops->complete(hcd, urb->priv, urb,
  74816. + urb->status);
  74817. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  74818. +
  74819. + if (failed)
  74820. + goto stop_scan;
  74821. + } else if (qh->ep_type == UE_CONTROL) {
  74822. + if (qtd->control_phase == DWC_OTG_CONTROL_SETUP) {
  74823. + if (urb->length > 0) {
  74824. + qtd->control_phase = DWC_OTG_CONTROL_DATA;
  74825. + } else {
  74826. + qtd->control_phase = DWC_OTG_CONTROL_STATUS;
  74827. + }
  74828. + DWC_DEBUGPL(DBG_HCDV, " Control setup transaction done\n");
  74829. + } else if (qtd->control_phase == DWC_OTG_CONTROL_DATA) {
  74830. + if (xfer_done) {
  74831. + qtd->control_phase = DWC_OTG_CONTROL_STATUS;
  74832. + DWC_DEBUGPL(DBG_HCDV, " Control data transfer done\n");
  74833. + } else if (i + 1 == qtd->n_desc) {
  74834. + /*
  74835. + * Last descriptor for Control data stage which is
  74836. + * not completed yet.
  74837. + */
  74838. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  74839. + }
  74840. + }
  74841. + }
  74842. +
  74843. + n_desc++;
  74844. + }
  74845. +
  74846. + }
  74847. +
  74848. +stop_scan:
  74849. +
  74850. + if (qh->ep_type != UE_CONTROL) {
  74851. + /*
  74852. + * Resetting the data toggle for bulk
  74853. + * and interrupt endpoints in case of stall. See handle_hc_stall_intr()
  74854. + */
  74855. + if (halt_status == DWC_OTG_HC_XFER_STALL)
  74856. + qh->data_toggle = DWC_OTG_HC_PID_DATA0;
  74857. + else
  74858. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  74859. + }
  74860. +
  74861. + if (halt_status == DWC_OTG_HC_XFER_COMPLETE) {
  74862. + hcint_data_t hcint;
  74863. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  74864. + if (hcint.b.nyet) {
  74865. + /*
  74866. + * Got a NYET on the last transaction of the transfer. It
  74867. + * means that the endpoint should be in the PING state at the
  74868. + * beginning of the next transfer.
  74869. + */
  74870. + qh->ping_state = 1;
  74871. + clear_hc_int(hc_regs, nyet);
  74872. + }
  74873. +
  74874. + }
  74875. +
  74876. +}
  74877. +
  74878. +/**
  74879. + * This function is called from interrupt handlers.
  74880. + * Scans the descriptor list, updates URB's status and
  74881. + * calls completion routine for the URB if it's done.
  74882. + * Releases the channel to be used by other transfers.
  74883. + * In case of Isochronous endpoint the channel is not halted until
  74884. + * the end of the session, i.e. QTD list is empty.
  74885. + * If periodic channel released the FrameList is updated accordingly.
  74886. + *
  74887. + * Calls transaction selection routines to activate pending transfers.
  74888. + *
  74889. + * @param hcd The HCD state structure for the DWC OTG controller.
  74890. + * @param hc Host channel, the transfer is completed on.
  74891. + * @param hc_regs Host channel registers.
  74892. + * @param halt_status Reason the channel is being halted,
  74893. + * or just XferComplete for isochronous transfer
  74894. + */
  74895. +void dwc_otg_hcd_complete_xfer_ddma(dwc_otg_hcd_t * hcd,
  74896. + dwc_hc_t * hc,
  74897. + dwc_otg_hc_regs_t * hc_regs,
  74898. + dwc_otg_halt_status_e halt_status)
  74899. +{
  74900. + uint8_t continue_isoc_xfer = 0;
  74901. + dwc_otg_transaction_type_e tr_type;
  74902. + dwc_otg_qh_t *qh = hc->qh;
  74903. +
  74904. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  74905. +
  74906. + complete_isoc_xfer_ddma(hcd, hc, hc_regs, halt_status);
  74907. +
  74908. + /* Release the channel if halted or session completed */
  74909. + if (halt_status != DWC_OTG_HC_XFER_COMPLETE ||
  74910. + DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  74911. +
  74912. + /* Halt the channel if session completed */
  74913. + if (halt_status == DWC_OTG_HC_XFER_COMPLETE) {
  74914. + dwc_otg_hc_halt(hcd->core_if, hc, halt_status);
  74915. + }
  74916. +
  74917. + release_channel_ddma(hcd, qh);
  74918. + dwc_otg_hcd_qh_remove(hcd, qh);
  74919. + } else {
  74920. + /* Keep in assigned schedule to continue transfer */
  74921. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_assigned,
  74922. + &qh->qh_list_entry);
  74923. + continue_isoc_xfer = 1;
  74924. +
  74925. + }
  74926. + /** @todo Consider the case when period exceeds FrameList size.
  74927. + * Frame Rollover interrupt should be used.
  74928. + */
  74929. + } else {
  74930. + /* Scan descriptor list to complete the URB(s), then release the channel */
  74931. + complete_non_isoc_xfer_ddma(hcd, hc, hc_regs, halt_status);
  74932. +
  74933. + release_channel_ddma(hcd, qh);
  74934. + dwc_otg_hcd_qh_remove(hcd, qh);
  74935. +
  74936. + if (!DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  74937. + /* Add back to inactive non-periodic schedule on normal completion */
  74938. + dwc_otg_hcd_qh_add(hcd, qh);
  74939. + }
  74940. +
  74941. + }
  74942. + tr_type = dwc_otg_hcd_select_transactions(hcd);
  74943. + if (tr_type != DWC_OTG_TRANSACTION_NONE || continue_isoc_xfer) {
  74944. + if (continue_isoc_xfer) {
  74945. + if (tr_type == DWC_OTG_TRANSACTION_NONE) {
  74946. + tr_type = DWC_OTG_TRANSACTION_PERIODIC;
  74947. + } else if (tr_type == DWC_OTG_TRANSACTION_NON_PERIODIC) {
  74948. + tr_type = DWC_OTG_TRANSACTION_ALL;
  74949. + }
  74950. + }
  74951. + dwc_otg_hcd_queue_transactions(hcd, tr_type);
  74952. + }
  74953. +}
  74954. +
  74955. +#endif /* DWC_DEVICE_ONLY */
  74956. diff -Nur linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_hcd.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd.h
  74957. --- linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_hcd.h 1970-01-01 01:00:00.000000000 +0100
  74958. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd.h 2014-04-24 15:37:13.314990533 +0200
  74959. @@ -0,0 +1,862 @@
  74960. +/* ==========================================================================
  74961. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd.h $
  74962. + * $Revision: #58 $
  74963. + * $Date: 2011/09/15 $
  74964. + * $Change: 1846647 $
  74965. + *
  74966. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  74967. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  74968. + * otherwise expressly agreed to in writing between Synopsys and you.
  74969. + *
  74970. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  74971. + * any End User Software License Agreement or Agreement for Licensed Product
  74972. + * with Synopsys or any supplement thereto. You are permitted to use and
  74973. + * redistribute this Software in source and binary forms, with or without
  74974. + * modification, provided that redistributions of source code must retain this
  74975. + * notice. You may not view, use, disclose, copy or distribute this file or
  74976. + * any information contained herein except pursuant to this license grant from
  74977. + * Synopsys. If you do not agree with this notice, including the disclaimer
  74978. + * below, then you are not authorized to use the Software.
  74979. + *
  74980. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  74981. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  74982. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  74983. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  74984. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  74985. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  74986. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  74987. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  74988. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  74989. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  74990. + * DAMAGE.
  74991. + * ========================================================================== */
  74992. +#ifndef DWC_DEVICE_ONLY
  74993. +#ifndef __DWC_HCD_H__
  74994. +#define __DWC_HCD_H__
  74995. +
  74996. +#include "dwc_otg_os_dep.h"
  74997. +#include "usb.h"
  74998. +#include "dwc_otg_hcd_if.h"
  74999. +#include "dwc_otg_core_if.h"
  75000. +#include "dwc_list.h"
  75001. +#include "dwc_otg_cil.h"
  75002. +#include "dwc_otg_fiq_fsm.h"
  75003. +
  75004. +
  75005. +/**
  75006. + * @file
  75007. + *
  75008. + * This file contains the structures, constants, and interfaces for
  75009. + * the Host Contoller Driver (HCD).
  75010. + *
  75011. + * The Host Controller Driver (HCD) is responsible for translating requests
  75012. + * from the USB Driver into the appropriate actions on the DWC_otg controller.
  75013. + * It isolates the USBD from the specifics of the controller by providing an
  75014. + * API to the USBD.
  75015. + */
  75016. +
  75017. +struct dwc_otg_hcd_pipe_info {
  75018. + uint8_t dev_addr;
  75019. + uint8_t ep_num;
  75020. + uint8_t pipe_type;
  75021. + uint8_t pipe_dir;
  75022. + uint16_t mps;
  75023. +};
  75024. +
  75025. +struct dwc_otg_hcd_iso_packet_desc {
  75026. + uint32_t offset;
  75027. + uint32_t length;
  75028. + uint32_t actual_length;
  75029. + uint32_t status;
  75030. +};
  75031. +
  75032. +struct dwc_otg_qtd;
  75033. +
  75034. +struct dwc_otg_hcd_urb {
  75035. + void *priv;
  75036. + struct dwc_otg_qtd *qtd;
  75037. + void *buf;
  75038. + dwc_dma_t dma;
  75039. + void *setup_packet;
  75040. + dwc_dma_t setup_dma;
  75041. + uint32_t length;
  75042. + uint32_t actual_length;
  75043. + uint32_t status;
  75044. + uint32_t error_count;
  75045. + uint32_t packet_count;
  75046. + uint32_t flags;
  75047. + uint16_t interval;
  75048. + struct dwc_otg_hcd_pipe_info pipe_info;
  75049. + struct dwc_otg_hcd_iso_packet_desc iso_descs[0];
  75050. +};
  75051. +
  75052. +static inline uint8_t dwc_otg_hcd_get_ep_num(struct dwc_otg_hcd_pipe_info *pipe)
  75053. +{
  75054. + return pipe->ep_num;
  75055. +}
  75056. +
  75057. +static inline uint8_t dwc_otg_hcd_get_pipe_type(struct dwc_otg_hcd_pipe_info
  75058. + *pipe)
  75059. +{
  75060. + return pipe->pipe_type;
  75061. +}
  75062. +
  75063. +static inline uint16_t dwc_otg_hcd_get_mps(struct dwc_otg_hcd_pipe_info *pipe)
  75064. +{
  75065. + return pipe->mps;
  75066. +}
  75067. +
  75068. +static inline uint8_t dwc_otg_hcd_get_dev_addr(struct dwc_otg_hcd_pipe_info
  75069. + *pipe)
  75070. +{
  75071. + return pipe->dev_addr;
  75072. +}
  75073. +
  75074. +static inline uint8_t dwc_otg_hcd_is_pipe_isoc(struct dwc_otg_hcd_pipe_info
  75075. + *pipe)
  75076. +{
  75077. + return (pipe->pipe_type == UE_ISOCHRONOUS);
  75078. +}
  75079. +
  75080. +static inline uint8_t dwc_otg_hcd_is_pipe_int(struct dwc_otg_hcd_pipe_info
  75081. + *pipe)
  75082. +{
  75083. + return (pipe->pipe_type == UE_INTERRUPT);
  75084. +}
  75085. +
  75086. +static inline uint8_t dwc_otg_hcd_is_pipe_bulk(struct dwc_otg_hcd_pipe_info
  75087. + *pipe)
  75088. +{
  75089. + return (pipe->pipe_type == UE_BULK);
  75090. +}
  75091. +
  75092. +static inline uint8_t dwc_otg_hcd_is_pipe_control(struct dwc_otg_hcd_pipe_info
  75093. + *pipe)
  75094. +{
  75095. + return (pipe->pipe_type == UE_CONTROL);
  75096. +}
  75097. +
  75098. +static inline uint8_t dwc_otg_hcd_is_pipe_in(struct dwc_otg_hcd_pipe_info *pipe)
  75099. +{
  75100. + return (pipe->pipe_dir == UE_DIR_IN);
  75101. +}
  75102. +
  75103. +static inline uint8_t dwc_otg_hcd_is_pipe_out(struct dwc_otg_hcd_pipe_info
  75104. + *pipe)
  75105. +{
  75106. + return (!dwc_otg_hcd_is_pipe_in(pipe));
  75107. +}
  75108. +
  75109. +static inline void dwc_otg_hcd_fill_pipe(struct dwc_otg_hcd_pipe_info *pipe,
  75110. + uint8_t devaddr, uint8_t ep_num,
  75111. + uint8_t pipe_type, uint8_t pipe_dir,
  75112. + uint16_t mps)
  75113. +{
  75114. + pipe->dev_addr = devaddr;
  75115. + pipe->ep_num = ep_num;
  75116. + pipe->pipe_type = pipe_type;
  75117. + pipe->pipe_dir = pipe_dir;
  75118. + pipe->mps = mps;
  75119. +}
  75120. +
  75121. +/**
  75122. + * Phases for control transfers.
  75123. + */
  75124. +typedef enum dwc_otg_control_phase {
  75125. + DWC_OTG_CONTROL_SETUP,
  75126. + DWC_OTG_CONTROL_DATA,
  75127. + DWC_OTG_CONTROL_STATUS
  75128. +} dwc_otg_control_phase_e;
  75129. +
  75130. +/** Transaction types. */
  75131. +typedef enum dwc_otg_transaction_type {
  75132. + DWC_OTG_TRANSACTION_NONE = 0,
  75133. + DWC_OTG_TRANSACTION_PERIODIC = 1,
  75134. + DWC_OTG_TRANSACTION_NON_PERIODIC = 2,
  75135. + DWC_OTG_TRANSACTION_ALL = DWC_OTG_TRANSACTION_PERIODIC + DWC_OTG_TRANSACTION_NON_PERIODIC
  75136. +} dwc_otg_transaction_type_e;
  75137. +
  75138. +struct dwc_otg_qh;
  75139. +
  75140. +/**
  75141. + * A Queue Transfer Descriptor (QTD) holds the state of a bulk, control,
  75142. + * interrupt, or isochronous transfer. A single QTD is created for each URB
  75143. + * (of one of these types) submitted to the HCD. The transfer associated with
  75144. + * a QTD may require one or multiple transactions.
  75145. + *
  75146. + * A QTD is linked to a Queue Head, which is entered in either the
  75147. + * non-periodic or periodic schedule for execution. When a QTD is chosen for
  75148. + * execution, some or all of its transactions may be executed. After
  75149. + * execution, the state of the QTD is updated. The QTD may be retired if all
  75150. + * its transactions are complete or if an error occurred. Otherwise, it
  75151. + * remains in the schedule so more transactions can be executed later.
  75152. + */
  75153. +typedef struct dwc_otg_qtd {
  75154. + /**
  75155. + * Determines the PID of the next data packet for the data phase of
  75156. + * control transfers. Ignored for other transfer types.<br>
  75157. + * One of the following values:
  75158. + * - DWC_OTG_HC_PID_DATA0
  75159. + * - DWC_OTG_HC_PID_DATA1
  75160. + */
  75161. + uint8_t data_toggle;
  75162. +
  75163. + /** Current phase for control transfers (Setup, Data, or Status). */
  75164. + dwc_otg_control_phase_e control_phase;
  75165. +
  75166. + /** Keep track of the current split type
  75167. + * for FS/LS endpoints on a HS Hub */
  75168. + uint8_t complete_split;
  75169. +
  75170. + /** How many bytes transferred during SSPLIT OUT */
  75171. + uint32_t ssplit_out_xfer_count;
  75172. +
  75173. + /**
  75174. + * Holds the number of bus errors that have occurred for a transaction
  75175. + * within this transfer.
  75176. + */
  75177. + uint8_t error_count;
  75178. +
  75179. + /**
  75180. + * Index of the next frame descriptor for an isochronous transfer. A
  75181. + * frame descriptor describes the buffer position and length of the
  75182. + * data to be transferred in the next scheduled (micro)frame of an
  75183. + * isochronous transfer. It also holds status for that transaction.
  75184. + * The frame index starts at 0.
  75185. + */
  75186. + uint16_t isoc_frame_index;
  75187. +
  75188. + /** Position of the ISOC split on full/low speed */
  75189. + uint8_t isoc_split_pos;
  75190. +
  75191. + /** Position of the ISOC split in the buffer for the current frame */
  75192. + uint16_t isoc_split_offset;
  75193. +
  75194. + /** URB for this transfer */
  75195. + struct dwc_otg_hcd_urb *urb;
  75196. +
  75197. + struct dwc_otg_qh *qh;
  75198. +
  75199. + /** This list of QTDs */
  75200. + DWC_CIRCLEQ_ENTRY(dwc_otg_qtd) qtd_list_entry;
  75201. +
  75202. + /** Indicates if this QTD is currently processed by HW. */
  75203. + uint8_t in_process;
  75204. +
  75205. + /** Number of DMA descriptors for this QTD */
  75206. + uint8_t n_desc;
  75207. +
  75208. + /**
  75209. + * Last activated frame(packet) index.
  75210. + * Used in Descriptor DMA mode only.
  75211. + */
  75212. + uint16_t isoc_frame_index_last;
  75213. +
  75214. +} dwc_otg_qtd_t;
  75215. +
  75216. +DWC_CIRCLEQ_HEAD(dwc_otg_qtd_list, dwc_otg_qtd);
  75217. +
  75218. +/**
  75219. + * A Queue Head (QH) holds the static characteristics of an endpoint and
  75220. + * maintains a list of transfers (QTDs) for that endpoint. A QH structure may
  75221. + * be entered in either the non-periodic or periodic schedule.
  75222. + */
  75223. +typedef struct dwc_otg_qh {
  75224. + /**
  75225. + * Endpoint type.
  75226. + * One of the following values:
  75227. + * - UE_CONTROL
  75228. + * - UE_BULK
  75229. + * - UE_INTERRUPT
  75230. + * - UE_ISOCHRONOUS
  75231. + */
  75232. + uint8_t ep_type;
  75233. + uint8_t ep_is_in;
  75234. +
  75235. + /** wMaxPacketSize Field of Endpoint Descriptor. */
  75236. + uint16_t maxp;
  75237. +
  75238. + /**
  75239. + * Device speed.
  75240. + * One of the following values:
  75241. + * - DWC_OTG_EP_SPEED_LOW
  75242. + * - DWC_OTG_EP_SPEED_FULL
  75243. + * - DWC_OTG_EP_SPEED_HIGH
  75244. + */
  75245. + uint8_t dev_speed;
  75246. +
  75247. + /**
  75248. + * Determines the PID of the next data packet for non-control
  75249. + * transfers. Ignored for control transfers.<br>
  75250. + * One of the following values:
  75251. + * - DWC_OTG_HC_PID_DATA0
  75252. + * - DWC_OTG_HC_PID_DATA1
  75253. + */
  75254. + uint8_t data_toggle;
  75255. +
  75256. + /** Ping state if 1. */
  75257. + uint8_t ping_state;
  75258. +
  75259. + /**
  75260. + * List of QTDs for this QH.
  75261. + */
  75262. + struct dwc_otg_qtd_list qtd_list;
  75263. +
  75264. + /** Host channel currently processing transfers for this QH. */
  75265. + struct dwc_hc *channel;
  75266. +
  75267. + /** Full/low speed endpoint on high-speed hub requires split. */
  75268. + uint8_t do_split;
  75269. +
  75270. + /** @name Periodic schedule information */
  75271. + /** @{ */
  75272. +
  75273. + /** Bandwidth in microseconds per (micro)frame. */
  75274. + uint16_t usecs;
  75275. +
  75276. + /** Interval between transfers in (micro)frames. */
  75277. + uint16_t interval;
  75278. +
  75279. + /**
  75280. + * (micro)frame to initialize a periodic transfer. The transfer
  75281. + * executes in the following (micro)frame.
  75282. + */
  75283. + uint16_t sched_frame;
  75284. +
  75285. + /*
  75286. + ** Frame a NAK was received on this queue head, used to minimise NAK retransmission
  75287. + */
  75288. + uint16_t nak_frame;
  75289. +
  75290. + /** (micro)frame at which last start split was initialized. */
  75291. + uint16_t start_split_frame;
  75292. +
  75293. + /** @} */
  75294. +
  75295. + /**
  75296. + * Used instead of original buffer if
  75297. + * it(physical address) is not dword-aligned.
  75298. + */
  75299. + uint8_t *dw_align_buf;
  75300. + dwc_dma_t dw_align_buf_dma;
  75301. +
  75302. + /** Entry for QH in either the periodic or non-periodic schedule. */
  75303. + dwc_list_link_t qh_list_entry;
  75304. +
  75305. + /** @name Descriptor DMA support */
  75306. + /** @{ */
  75307. +
  75308. + /** Descriptor List. */
  75309. + dwc_otg_host_dma_desc_t *desc_list;
  75310. +
  75311. + /** Descriptor List physical address. */
  75312. + dwc_dma_t desc_list_dma;
  75313. +
  75314. + /**
  75315. + * Xfer Bytes array.
  75316. + * Each element corresponds to a descriptor and indicates
  75317. + * original XferSize size value for the descriptor.
  75318. + */
  75319. + uint32_t *n_bytes;
  75320. +
  75321. + /** Actual number of transfer descriptors in a list. */
  75322. + uint16_t ntd;
  75323. +
  75324. + /** First activated isochronous transfer descriptor index. */
  75325. + uint8_t td_first;
  75326. + /** Last activated isochronous transfer descriptor index. */
  75327. + uint8_t td_last;
  75328. +
  75329. + /** @} */
  75330. +
  75331. +
  75332. + uint16_t speed;
  75333. + uint16_t frame_usecs[8];
  75334. +
  75335. + uint32_t skip_count;
  75336. +} dwc_otg_qh_t;
  75337. +
  75338. +DWC_CIRCLEQ_HEAD(hc_list, dwc_hc);
  75339. +
  75340. +typedef struct urb_tq_entry {
  75341. + struct urb *urb;
  75342. + DWC_TAILQ_ENTRY(urb_tq_entry) urb_tq_entries;
  75343. +} urb_tq_entry_t;
  75344. +
  75345. +DWC_TAILQ_HEAD(urb_list, urb_tq_entry);
  75346. +
  75347. +/**
  75348. + * This structure holds the state of the HCD, including the non-periodic and
  75349. + * periodic schedules.
  75350. + */
  75351. +struct dwc_otg_hcd {
  75352. + /** The DWC otg device pointer */
  75353. + struct dwc_otg_device *otg_dev;
  75354. + /** DWC OTG Core Interface Layer */
  75355. + dwc_otg_core_if_t *core_if;
  75356. +
  75357. + /** Function HCD driver callbacks */
  75358. + struct dwc_otg_hcd_function_ops *fops;
  75359. +
  75360. + /** Internal DWC HCD Flags */
  75361. + volatile union dwc_otg_hcd_internal_flags {
  75362. + uint32_t d32;
  75363. + struct {
  75364. + unsigned port_connect_status_change:1;
  75365. + unsigned port_connect_status:1;
  75366. + unsigned port_reset_change:1;
  75367. + unsigned port_enable_change:1;
  75368. + unsigned port_suspend_change:1;
  75369. + unsigned port_over_current_change:1;
  75370. + unsigned port_l1_change:1;
  75371. + unsigned reserved:26;
  75372. + } b;
  75373. + } flags;
  75374. +
  75375. + /**
  75376. + * Inactive items in the non-periodic schedule. This is a list of
  75377. + * Queue Heads. Transfers associated with these Queue Heads are not
  75378. + * currently assigned to a host channel.
  75379. + */
  75380. + dwc_list_link_t non_periodic_sched_inactive;
  75381. +
  75382. + /**
  75383. + * Active items in the non-periodic schedule. This is a list of
  75384. + * Queue Heads. Transfers associated with these Queue Heads are
  75385. + * currently assigned to a host channel.
  75386. + */
  75387. + dwc_list_link_t non_periodic_sched_active;
  75388. +
  75389. + /**
  75390. + * Pointer to the next Queue Head to process in the active
  75391. + * non-periodic schedule.
  75392. + */
  75393. + dwc_list_link_t *non_periodic_qh_ptr;
  75394. +
  75395. + /**
  75396. + * Inactive items in the periodic schedule. This is a list of QHs for
  75397. + * periodic transfers that are _not_ scheduled for the next frame.
  75398. + * Each QH in the list has an interval counter that determines when it
  75399. + * needs to be scheduled for execution. This scheduling mechanism
  75400. + * allows only a simple calculation for periodic bandwidth used (i.e.
  75401. + * must assume that all periodic transfers may need to execute in the
  75402. + * same frame). However, it greatly simplifies scheduling and should
  75403. + * be sufficient for the vast majority of OTG hosts, which need to
  75404. + * connect to a small number of peripherals at one time.
  75405. + *
  75406. + * Items move from this list to periodic_sched_ready when the QH
  75407. + * interval counter is 0 at SOF.
  75408. + */
  75409. + dwc_list_link_t periodic_sched_inactive;
  75410. +
  75411. + /**
  75412. + * List of periodic QHs that are ready for execution in the next
  75413. + * frame, but have not yet been assigned to host channels.
  75414. + *
  75415. + * Items move from this list to periodic_sched_assigned as host
  75416. + * channels become available during the current frame.
  75417. + */
  75418. + dwc_list_link_t periodic_sched_ready;
  75419. +
  75420. + /**
  75421. + * List of periodic QHs to be executed in the next frame that are
  75422. + * assigned to host channels.
  75423. + *
  75424. + * Items move from this list to periodic_sched_queued as the
  75425. + * transactions for the QH are queued to the DWC_otg controller.
  75426. + */
  75427. + dwc_list_link_t periodic_sched_assigned;
  75428. +
  75429. + /**
  75430. + * List of periodic QHs that have been queued for execution.
  75431. + *
  75432. + * Items move from this list to either periodic_sched_inactive or
  75433. + * periodic_sched_ready when the channel associated with the transfer
  75434. + * is released. If the interval for the QH is 1, the item moves to
  75435. + * periodic_sched_ready because it must be rescheduled for the next
  75436. + * frame. Otherwise, the item moves to periodic_sched_inactive.
  75437. + */
  75438. + dwc_list_link_t periodic_sched_queued;
  75439. +
  75440. + /**
  75441. + * Total bandwidth claimed so far for periodic transfers. This value
  75442. + * is in microseconds per (micro)frame. The assumption is that all
  75443. + * periodic transfers may occur in the same (micro)frame.
  75444. + */
  75445. + uint16_t periodic_usecs;
  75446. +
  75447. + /**
  75448. + * Total bandwidth claimed so far for all periodic transfers
  75449. + * in a frame.
  75450. + * This will include a mixture of HS and FS transfers.
  75451. + * Units are microseconds per (micro)frame.
  75452. + * We have a budget per frame and have to schedule
  75453. + * transactions accordingly.
  75454. + * Watch out for the fact that things are actually scheduled for the
  75455. + * "next frame".
  75456. + */
  75457. + uint16_t frame_usecs[8];
  75458. +
  75459. +
  75460. + /**
  75461. + * Frame number read from the core at SOF. The value ranges from 0 to
  75462. + * DWC_HFNUM_MAX_FRNUM.
  75463. + */
  75464. + uint16_t frame_number;
  75465. +
  75466. + /**
  75467. + * Count of periodic QHs, if using several eps. For SOF enable/disable.
  75468. + */
  75469. + uint16_t periodic_qh_count;
  75470. +
  75471. + /**
  75472. + * Free host channels in the controller. This is a list of
  75473. + * dwc_hc_t items.
  75474. + */
  75475. + struct hc_list free_hc_list;
  75476. + /**
  75477. + * Number of host channels assigned to periodic transfers. Currently
  75478. + * assuming that there is a dedicated host channel for each periodic
  75479. + * transaction and at least one host channel available for
  75480. + * non-periodic transactions.
  75481. + */
  75482. + int periodic_channels; /* microframe_schedule==0 */
  75483. +
  75484. + /**
  75485. + * Number of host channels assigned to non-periodic transfers.
  75486. + */
  75487. + int non_periodic_channels; /* microframe_schedule==0 */
  75488. +
  75489. + /**
  75490. + * Number of host channels assigned to non-periodic transfers.
  75491. + */
  75492. + int available_host_channels;
  75493. +
  75494. + /**
  75495. + * Array of pointers to the host channel descriptors. Allows accessing
  75496. + * a host channel descriptor given the host channel number. This is
  75497. + * useful in interrupt handlers.
  75498. + */
  75499. + struct dwc_hc *hc_ptr_array[MAX_EPS_CHANNELS];
  75500. +
  75501. + /**
  75502. + * Buffer to use for any data received during the status phase of a
  75503. + * control transfer. Normally no data is transferred during the status
  75504. + * phase. This buffer is used as a bit bucket.
  75505. + */
  75506. + uint8_t *status_buf;
  75507. +
  75508. + /**
  75509. + * DMA address for status_buf.
  75510. + */
  75511. + dma_addr_t status_buf_dma;
  75512. +#define DWC_OTG_HCD_STATUS_BUF_SIZE 64
  75513. +
  75514. + /**
  75515. + * Connection timer. An OTG host must display a message if the device
  75516. + * does not connect. Started when the VBus power is turned on via
  75517. + * sysfs attribute "buspower".
  75518. + */
  75519. + dwc_timer_t *conn_timer;
  75520. +
  75521. + /* Tasket to do a reset */
  75522. + dwc_tasklet_t *reset_tasklet;
  75523. +
  75524. + dwc_tasklet_t *completion_tasklet;
  75525. + struct urb_list completed_urb_list;
  75526. +
  75527. + /* */
  75528. + dwc_spinlock_t *lock;
  75529. + dwc_spinlock_t *channel_lock;
  75530. + /**
  75531. + * Private data that could be used by OS wrapper.
  75532. + */
  75533. + void *priv;
  75534. +
  75535. + uint8_t otg_port;
  75536. +
  75537. + /** Frame List */
  75538. + uint32_t *frame_list;
  75539. +
  75540. + /** Hub - Port assignment */
  75541. + int hub_port[128];
  75542. +#ifdef FIQ_DEBUG
  75543. + int hub_port_alloc[2048];
  75544. +#endif
  75545. +
  75546. + /** Frame List DMA address */
  75547. + dma_addr_t frame_list_dma;
  75548. +
  75549. + struct fiq_stack *fiq_stack;
  75550. + struct fiq_state *fiq_state;
  75551. +
  75552. + /** Virtual address for split transaction DMA bounce buffers */
  75553. + struct fiq_dma_blob *fiq_dmab;
  75554. +
  75555. +#ifdef DEBUG
  75556. + uint32_t frrem_samples;
  75557. + uint64_t frrem_accum;
  75558. +
  75559. + uint32_t hfnum_7_samples_a;
  75560. + uint64_t hfnum_7_frrem_accum_a;
  75561. + uint32_t hfnum_0_samples_a;
  75562. + uint64_t hfnum_0_frrem_accum_a;
  75563. + uint32_t hfnum_other_samples_a;
  75564. + uint64_t hfnum_other_frrem_accum_a;
  75565. +
  75566. + uint32_t hfnum_7_samples_b;
  75567. + uint64_t hfnum_7_frrem_accum_b;
  75568. + uint32_t hfnum_0_samples_b;
  75569. + uint64_t hfnum_0_frrem_accum_b;
  75570. + uint32_t hfnum_other_samples_b;
  75571. + uint64_t hfnum_other_frrem_accum_b;
  75572. +#endif
  75573. +};
  75574. +
  75575. +/** @name Transaction Execution Functions */
  75576. +/** @{ */
  75577. +extern dwc_otg_transaction_type_e dwc_otg_hcd_select_transactions(dwc_otg_hcd_t
  75578. + * hcd);
  75579. +extern void dwc_otg_hcd_queue_transactions(dwc_otg_hcd_t * hcd,
  75580. + dwc_otg_transaction_type_e tr_type);
  75581. +
  75582. +int dwc_otg_hcd_allocate_port(dwc_otg_hcd_t * hcd, dwc_otg_qh_t *qh);
  75583. +void dwc_otg_hcd_release_port(dwc_otg_hcd_t * dwc_otg_hcd, dwc_otg_qh_t *qh);
  75584. +
  75585. +extern int fiq_fsm_queue_transaction(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh);
  75586. +extern int fiq_fsm_transaction_suitable(dwc_otg_qh_t *qh);
  75587. +extern void dwc_otg_cleanup_fiq_channel(dwc_otg_hcd_t *hcd, uint32_t num);
  75588. +
  75589. +/** @} */
  75590. +
  75591. +/** @name Interrupt Handler Functions */
  75592. +/** @{ */
  75593. +extern int32_t dwc_otg_hcd_handle_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  75594. +extern int32_t dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  75595. +extern int32_t dwc_otg_hcd_handle_rx_status_q_level_intr(dwc_otg_hcd_t *
  75596. + dwc_otg_hcd);
  75597. +extern int32_t dwc_otg_hcd_handle_np_tx_fifo_empty_intr(dwc_otg_hcd_t *
  75598. + dwc_otg_hcd);
  75599. +extern int32_t dwc_otg_hcd_handle_perio_tx_fifo_empty_intr(dwc_otg_hcd_t *
  75600. + dwc_otg_hcd);
  75601. +extern int32_t dwc_otg_hcd_handle_incomplete_periodic_intr(dwc_otg_hcd_t *
  75602. + dwc_otg_hcd);
  75603. +extern int32_t dwc_otg_hcd_handle_port_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  75604. +extern int32_t dwc_otg_hcd_handle_conn_id_status_change_intr(dwc_otg_hcd_t *
  75605. + dwc_otg_hcd);
  75606. +extern int32_t dwc_otg_hcd_handle_disconnect_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  75607. +extern int32_t dwc_otg_hcd_handle_hc_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  75608. +extern int32_t dwc_otg_hcd_handle_hc_n_intr(dwc_otg_hcd_t * dwc_otg_hcd,
  75609. + uint32_t num);
  75610. +extern int32_t dwc_otg_hcd_handle_session_req_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  75611. +extern int32_t dwc_otg_hcd_handle_wakeup_detected_intr(dwc_otg_hcd_t *
  75612. + dwc_otg_hcd);
  75613. +/** @} */
  75614. +
  75615. +/** @name Schedule Queue Functions */
  75616. +/** @{ */
  75617. +
  75618. +/* Implemented in dwc_otg_hcd_queue.c */
  75619. +extern dwc_otg_qh_t *dwc_otg_hcd_qh_create(dwc_otg_hcd_t * hcd,
  75620. + dwc_otg_hcd_urb_t * urb, int atomic_alloc);
  75621. +extern void dwc_otg_hcd_qh_free(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  75622. +extern int dwc_otg_hcd_qh_add(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  75623. +extern void dwc_otg_hcd_qh_remove(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  75624. +extern void dwc_otg_hcd_qh_deactivate(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh,
  75625. + int sched_csplit);
  75626. +
  75627. +/** Remove and free a QH */
  75628. +static inline void dwc_otg_hcd_qh_remove_and_free(dwc_otg_hcd_t * hcd,
  75629. + dwc_otg_qh_t * qh)
  75630. +{
  75631. + dwc_irqflags_t flags;
  75632. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  75633. + dwc_otg_hcd_qh_remove(hcd, qh);
  75634. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  75635. + dwc_otg_hcd_qh_free(hcd, qh);
  75636. +}
  75637. +
  75638. +/** Allocates memory for a QH structure.
  75639. + * @return Returns the memory allocate or NULL on error. */
  75640. +static inline dwc_otg_qh_t *dwc_otg_hcd_qh_alloc(int atomic_alloc)
  75641. +{
  75642. + if (atomic_alloc)
  75643. + return (dwc_otg_qh_t *) DWC_ALLOC_ATOMIC(sizeof(dwc_otg_qh_t));
  75644. + else
  75645. + return (dwc_otg_qh_t *) DWC_ALLOC(sizeof(dwc_otg_qh_t));
  75646. +}
  75647. +
  75648. +extern dwc_otg_qtd_t *dwc_otg_hcd_qtd_create(dwc_otg_hcd_urb_t * urb,
  75649. + int atomic_alloc);
  75650. +extern void dwc_otg_hcd_qtd_init(dwc_otg_qtd_t * qtd, dwc_otg_hcd_urb_t * urb);
  75651. +extern int dwc_otg_hcd_qtd_add(dwc_otg_qtd_t * qtd, dwc_otg_hcd_t * dwc_otg_hcd,
  75652. + dwc_otg_qh_t ** qh, int atomic_alloc);
  75653. +
  75654. +/** Allocates memory for a QTD structure.
  75655. + * @return Returns the memory allocate or NULL on error. */
  75656. +static inline dwc_otg_qtd_t *dwc_otg_hcd_qtd_alloc(int atomic_alloc)
  75657. +{
  75658. + if (atomic_alloc)
  75659. + return (dwc_otg_qtd_t *) DWC_ALLOC_ATOMIC(sizeof(dwc_otg_qtd_t));
  75660. + else
  75661. + return (dwc_otg_qtd_t *) DWC_ALLOC(sizeof(dwc_otg_qtd_t));
  75662. +}
  75663. +
  75664. +/** Frees the memory for a QTD structure. QTD should already be removed from
  75665. + * list.
  75666. + * @param qtd QTD to free.*/
  75667. +static inline void dwc_otg_hcd_qtd_free(dwc_otg_qtd_t * qtd)
  75668. +{
  75669. + DWC_FREE(qtd);
  75670. +}
  75671. +
  75672. +/** Removes a QTD from list.
  75673. + * @param hcd HCD instance.
  75674. + * @param qtd QTD to remove from list.
  75675. + * @param qh QTD belongs to.
  75676. + */
  75677. +static inline void dwc_otg_hcd_qtd_remove(dwc_otg_hcd_t * hcd,
  75678. + dwc_otg_qtd_t * qtd,
  75679. + dwc_otg_qh_t * qh)
  75680. +{
  75681. + DWC_CIRCLEQ_REMOVE(&qh->qtd_list, qtd, qtd_list_entry);
  75682. +}
  75683. +
  75684. +/** Remove and free a QTD
  75685. + * Need to disable IRQ and hold hcd lock while calling this function out of
  75686. + * interrupt servicing chain */
  75687. +static inline void dwc_otg_hcd_qtd_remove_and_free(dwc_otg_hcd_t * hcd,
  75688. + dwc_otg_qtd_t * qtd,
  75689. + dwc_otg_qh_t * qh)
  75690. +{
  75691. + dwc_otg_hcd_qtd_remove(hcd, qtd, qh);
  75692. + dwc_otg_hcd_qtd_free(qtd);
  75693. +}
  75694. +
  75695. +/** @} */
  75696. +
  75697. +/** @name Descriptor DMA Supporting Functions */
  75698. +/** @{ */
  75699. +
  75700. +extern void dwc_otg_hcd_start_xfer_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  75701. +extern void dwc_otg_hcd_complete_xfer_ddma(dwc_otg_hcd_t * hcd,
  75702. + dwc_hc_t * hc,
  75703. + dwc_otg_hc_regs_t * hc_regs,
  75704. + dwc_otg_halt_status_e halt_status);
  75705. +
  75706. +extern int dwc_otg_hcd_qh_init_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  75707. +extern void dwc_otg_hcd_qh_free_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  75708. +
  75709. +/** @} */
  75710. +
  75711. +/** @name Internal Functions */
  75712. +/** @{ */
  75713. +dwc_otg_qh_t *dwc_urb_to_qh(dwc_otg_hcd_urb_t * urb);
  75714. +/** @} */
  75715. +
  75716. +#ifdef CONFIG_USB_DWC_OTG_LPM
  75717. +extern int dwc_otg_hcd_get_hc_for_lpm_tran(dwc_otg_hcd_t * hcd,
  75718. + uint8_t devaddr);
  75719. +extern void dwc_otg_hcd_free_hc_from_lpm(dwc_otg_hcd_t * hcd);
  75720. +#endif
  75721. +
  75722. +/** Gets the QH that contains the list_head */
  75723. +#define dwc_list_to_qh(_list_head_ptr_) container_of(_list_head_ptr_, dwc_otg_qh_t, qh_list_entry)
  75724. +
  75725. +/** Gets the QTD that contains the list_head */
  75726. +#define dwc_list_to_qtd(_list_head_ptr_) container_of(_list_head_ptr_, dwc_otg_qtd_t, qtd_list_entry)
  75727. +
  75728. +/** Check if QH is non-periodic */
  75729. +#define dwc_qh_is_non_per(_qh_ptr_) ((_qh_ptr_->ep_type == UE_BULK) || \
  75730. + (_qh_ptr_->ep_type == UE_CONTROL))
  75731. +
  75732. +/** High bandwidth multiplier as encoded in highspeed endpoint descriptors */
  75733. +#define dwc_hb_mult(wMaxPacketSize) (1 + (((wMaxPacketSize) >> 11) & 0x03))
  75734. +
  75735. +/** Packet size for any kind of endpoint descriptor */
  75736. +#define dwc_max_packet(wMaxPacketSize) ((wMaxPacketSize) & 0x07ff)
  75737. +
  75738. +/**
  75739. + * Returns true if _frame1 is less than or equal to _frame2. The comparison is
  75740. + * done modulo DWC_HFNUM_MAX_FRNUM. This accounts for the rollover of the
  75741. + * frame number when the max frame number is reached.
  75742. + */
  75743. +static inline int dwc_frame_num_le(uint16_t frame1, uint16_t frame2)
  75744. +{
  75745. + return ((frame2 - frame1) & DWC_HFNUM_MAX_FRNUM) <=
  75746. + (DWC_HFNUM_MAX_FRNUM >> 1);
  75747. +}
  75748. +
  75749. +/**
  75750. + * Returns true if _frame1 is greater than _frame2. The comparison is done
  75751. + * modulo DWC_HFNUM_MAX_FRNUM. This accounts for the rollover of the frame
  75752. + * number when the max frame number is reached.
  75753. + */
  75754. +static inline int dwc_frame_num_gt(uint16_t frame1, uint16_t frame2)
  75755. +{
  75756. + return (frame1 != frame2) &&
  75757. + (((frame1 - frame2) & DWC_HFNUM_MAX_FRNUM) <
  75758. + (DWC_HFNUM_MAX_FRNUM >> 1));
  75759. +}
  75760. +
  75761. +/**
  75762. + * Increments _frame by the amount specified by _inc. The addition is done
  75763. + * modulo DWC_HFNUM_MAX_FRNUM. Returns the incremented value.
  75764. + */
  75765. +static inline uint16_t dwc_frame_num_inc(uint16_t frame, uint16_t inc)
  75766. +{
  75767. + return (frame + inc) & DWC_HFNUM_MAX_FRNUM;
  75768. +}
  75769. +
  75770. +static inline uint16_t dwc_full_frame_num(uint16_t frame)
  75771. +{
  75772. + return (frame & DWC_HFNUM_MAX_FRNUM) >> 3;
  75773. +}
  75774. +
  75775. +static inline uint16_t dwc_micro_frame_num(uint16_t frame)
  75776. +{
  75777. + return frame & 0x7;
  75778. +}
  75779. +
  75780. +void dwc_otg_hcd_save_data_toggle(dwc_hc_t * hc,
  75781. + dwc_otg_hc_regs_t * hc_regs,
  75782. + dwc_otg_qtd_t * qtd);
  75783. +
  75784. +#ifdef DEBUG
  75785. +/**
  75786. + * Macro to sample the remaining PHY clocks left in the current frame. This
  75787. + * may be used during debugging to determine the average time it takes to
  75788. + * execute sections of code. There are two possible sample points, "a" and
  75789. + * "b", so the _letter argument must be one of these values.
  75790. + *
  75791. + * To dump the average sample times, read the "hcd_frrem" sysfs attribute. For
  75792. + * example, "cat /sys/devices/lm0/hcd_frrem".
  75793. + */
  75794. +#define dwc_sample_frrem(_hcd, _qh, _letter) \
  75795. +{ \
  75796. + hfnum_data_t hfnum; \
  75797. + dwc_otg_qtd_t *qtd; \
  75798. + qtd = list_entry(_qh->qtd_list.next, dwc_otg_qtd_t, qtd_list_entry); \
  75799. + if (usb_pipeint(qtd->urb->pipe) && _qh->start_split_frame != 0 && !qtd->complete_split) { \
  75800. + hfnum.d32 = DWC_READ_REG32(&_hcd->core_if->host_if->host_global_regs->hfnum); \
  75801. + switch (hfnum.b.frnum & 0x7) { \
  75802. + case 7: \
  75803. + _hcd->hfnum_7_samples_##_letter++; \
  75804. + _hcd->hfnum_7_frrem_accum_##_letter += hfnum.b.frrem; \
  75805. + break; \
  75806. + case 0: \
  75807. + _hcd->hfnum_0_samples_##_letter++; \
  75808. + _hcd->hfnum_0_frrem_accum_##_letter += hfnum.b.frrem; \
  75809. + break; \
  75810. + default: \
  75811. + _hcd->hfnum_other_samples_##_letter++; \
  75812. + _hcd->hfnum_other_frrem_accum_##_letter += hfnum.b.frrem; \
  75813. + break; \
  75814. + } \
  75815. + } \
  75816. +}
  75817. +#else
  75818. +#define dwc_sample_frrem(_hcd, _qh, _letter)
  75819. +#endif
  75820. +#endif
  75821. +#endif /* DWC_DEVICE_ONLY */
  75822. diff -Nur linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_hcd_if.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_if.h
  75823. --- linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_hcd_if.h 1970-01-01 01:00:00.000000000 +0100
  75824. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_if.h 2014-04-24 15:37:13.314990533 +0200
  75825. @@ -0,0 +1,417 @@
  75826. +/* ==========================================================================
  75827. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_if.h $
  75828. + * $Revision: #12 $
  75829. + * $Date: 2011/10/26 $
  75830. + * $Change: 1873028 $
  75831. + *
  75832. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  75833. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  75834. + * otherwise expressly agreed to in writing between Synopsys and you.
  75835. + *
  75836. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  75837. + * any End User Software License Agreement or Agreement for Licensed Product
  75838. + * with Synopsys or any supplement thereto. You are permitted to use and
  75839. + * redistribute this Software in source and binary forms, with or without
  75840. + * modification, provided that redistributions of source code must retain this
  75841. + * notice. You may not view, use, disclose, copy or distribute this file or
  75842. + * any information contained herein except pursuant to this license grant from
  75843. + * Synopsys. If you do not agree with this notice, including the disclaimer
  75844. + * below, then you are not authorized to use the Software.
  75845. + *
  75846. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  75847. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  75848. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  75849. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  75850. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  75851. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  75852. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  75853. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  75854. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  75855. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  75856. + * DAMAGE.
  75857. + * ========================================================================== */
  75858. +#ifndef DWC_DEVICE_ONLY
  75859. +#ifndef __DWC_HCD_IF_H__
  75860. +#define __DWC_HCD_IF_H__
  75861. +
  75862. +#include "dwc_otg_core_if.h"
  75863. +
  75864. +/** @file
  75865. + * This file defines DWC_OTG HCD Core API.
  75866. + */
  75867. +
  75868. +struct dwc_otg_hcd;
  75869. +typedef struct dwc_otg_hcd dwc_otg_hcd_t;
  75870. +
  75871. +struct dwc_otg_hcd_urb;
  75872. +typedef struct dwc_otg_hcd_urb dwc_otg_hcd_urb_t;
  75873. +
  75874. +/** @name HCD Function Driver Callbacks */
  75875. +/** @{ */
  75876. +
  75877. +/** This function is called whenever core switches to host mode. */
  75878. +typedef int (*dwc_otg_hcd_start_cb_t) (dwc_otg_hcd_t * hcd);
  75879. +
  75880. +/** This function is called when device has been disconnected */
  75881. +typedef int (*dwc_otg_hcd_disconnect_cb_t) (dwc_otg_hcd_t * hcd);
  75882. +
  75883. +/** Wrapper provides this function to HCD to core, so it can get hub information to which device is connected */
  75884. +typedef int (*dwc_otg_hcd_hub_info_from_urb_cb_t) (dwc_otg_hcd_t * hcd,
  75885. + void *urb_handle,
  75886. + uint32_t * hub_addr,
  75887. + uint32_t * port_addr);
  75888. +/** Via this function HCD core gets device speed */
  75889. +typedef int (*dwc_otg_hcd_speed_from_urb_cb_t) (dwc_otg_hcd_t * hcd,
  75890. + void *urb_handle);
  75891. +
  75892. +/** This function is called when urb is completed */
  75893. +typedef int (*dwc_otg_hcd_complete_urb_cb_t) (dwc_otg_hcd_t * hcd,
  75894. + void *urb_handle,
  75895. + dwc_otg_hcd_urb_t * dwc_otg_urb,
  75896. + int32_t status);
  75897. +
  75898. +/** Via this function HCD core gets b_hnp_enable parameter */
  75899. +typedef int (*dwc_otg_hcd_get_b_hnp_enable) (dwc_otg_hcd_t * hcd);
  75900. +
  75901. +struct dwc_otg_hcd_function_ops {
  75902. + dwc_otg_hcd_start_cb_t start;
  75903. + dwc_otg_hcd_disconnect_cb_t disconnect;
  75904. + dwc_otg_hcd_hub_info_from_urb_cb_t hub_info;
  75905. + dwc_otg_hcd_speed_from_urb_cb_t speed;
  75906. + dwc_otg_hcd_complete_urb_cb_t complete;
  75907. + dwc_otg_hcd_get_b_hnp_enable get_b_hnp_enable;
  75908. +};
  75909. +/** @} */
  75910. +
  75911. +/** @name HCD Core API */
  75912. +/** @{ */
  75913. +/** This function allocates dwc_otg_hcd structure and returns pointer on it. */
  75914. +extern dwc_otg_hcd_t *dwc_otg_hcd_alloc_hcd(void);
  75915. +
  75916. +/** This function should be called to initiate HCD Core.
  75917. + *
  75918. + * @param hcd The HCD
  75919. + * @param core_if The DWC_OTG Core
  75920. + *
  75921. + * Returns -DWC_E_NO_MEMORY if no enough memory.
  75922. + * Returns 0 on success
  75923. + */
  75924. +extern int dwc_otg_hcd_init(dwc_otg_hcd_t * hcd, dwc_otg_core_if_t * core_if);
  75925. +
  75926. +/** Frees HCD
  75927. + *
  75928. + * @param hcd The HCD
  75929. + */
  75930. +extern void dwc_otg_hcd_remove(dwc_otg_hcd_t * hcd);
  75931. +
  75932. +/** This function should be called on every hardware interrupt.
  75933. + *
  75934. + * @param dwc_otg_hcd The HCD
  75935. + *
  75936. + * Returns non zero if interrupt is handled
  75937. + * Return 0 if interrupt is not handled
  75938. + */
  75939. +extern int32_t dwc_otg_hcd_handle_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  75940. +
  75941. +/** This function is used to handle the fast interrupt
  75942. + *
  75943. + */
  75944. +extern void __attribute__ ((naked)) dwc_otg_hcd_handle_fiq(void);
  75945. +
  75946. +/**
  75947. + * Returns private data set by
  75948. + * dwc_otg_hcd_set_priv_data function.
  75949. + *
  75950. + * @param hcd The HCD
  75951. + */
  75952. +extern void *dwc_otg_hcd_get_priv_data(dwc_otg_hcd_t * hcd);
  75953. +
  75954. +/**
  75955. + * Set private data.
  75956. + *
  75957. + * @param hcd The HCD
  75958. + * @param priv_data pointer to be stored in private data
  75959. + */
  75960. +extern void dwc_otg_hcd_set_priv_data(dwc_otg_hcd_t * hcd, void *priv_data);
  75961. +
  75962. +/**
  75963. + * This function initializes the HCD Core.
  75964. + *
  75965. + * @param hcd The HCD
  75966. + * @param fops The Function Driver Operations data structure containing pointers to all callbacks.
  75967. + *
  75968. + * Returns -DWC_E_NO_DEVICE if Core is currently is in device mode.
  75969. + * Returns 0 on success
  75970. + */
  75971. +extern int dwc_otg_hcd_start(dwc_otg_hcd_t * hcd,
  75972. + struct dwc_otg_hcd_function_ops *fops);
  75973. +
  75974. +/**
  75975. + * Halts the DWC_otg host mode operations in a clean manner. USB transfers are
  75976. + * stopped.
  75977. + *
  75978. + * @param hcd The HCD
  75979. + */
  75980. +extern void dwc_otg_hcd_stop(dwc_otg_hcd_t * hcd);
  75981. +
  75982. +/**
  75983. + * Handles hub class-specific requests.
  75984. + *
  75985. + * @param dwc_otg_hcd The HCD
  75986. + * @param typeReq Request Type
  75987. + * @param wValue wValue from control request
  75988. + * @param wIndex wIndex from control request
  75989. + * @param buf data buffer
  75990. + * @param wLength data buffer length
  75991. + *
  75992. + * Returns -DWC_E_INVALID if invalid argument is passed
  75993. + * Returns 0 on success
  75994. + */
  75995. +extern int dwc_otg_hcd_hub_control(dwc_otg_hcd_t * dwc_otg_hcd,
  75996. + uint16_t typeReq, uint16_t wValue,
  75997. + uint16_t wIndex, uint8_t * buf,
  75998. + uint16_t wLength);
  75999. +
  76000. +/**
  76001. + * Returns otg port number.
  76002. + *
  76003. + * @param hcd The HCD
  76004. + */
  76005. +extern uint32_t dwc_otg_hcd_otg_port(dwc_otg_hcd_t * hcd);
  76006. +
  76007. +/**
  76008. + * Returns OTG version - either 1.3 or 2.0.
  76009. + *
  76010. + * @param core_if The core_if structure pointer
  76011. + */
  76012. +extern uint16_t dwc_otg_get_otg_version(dwc_otg_core_if_t * core_if);
  76013. +
  76014. +/**
  76015. + * Returns 1 if currently core is acting as B host, and 0 otherwise.
  76016. + *
  76017. + * @param hcd The HCD
  76018. + */
  76019. +extern uint32_t dwc_otg_hcd_is_b_host(dwc_otg_hcd_t * hcd);
  76020. +
  76021. +/**
  76022. + * Returns current frame number.
  76023. + *
  76024. + * @param hcd The HCD
  76025. + */
  76026. +extern int dwc_otg_hcd_get_frame_number(dwc_otg_hcd_t * hcd);
  76027. +
  76028. +/**
  76029. + * Dumps hcd state.
  76030. + *
  76031. + * @param hcd The HCD
  76032. + */
  76033. +extern void dwc_otg_hcd_dump_state(dwc_otg_hcd_t * hcd);
  76034. +
  76035. +/**
  76036. + * Dump the average frame remaining at SOF. This can be used to
  76037. + * determine average interrupt latency. Frame remaining is also shown for
  76038. + * start transfer and two additional sample points.
  76039. + * Currently this function is not implemented.
  76040. + *
  76041. + * @param hcd The HCD
  76042. + */
  76043. +extern void dwc_otg_hcd_dump_frrem(dwc_otg_hcd_t * hcd);
  76044. +
  76045. +/**
  76046. + * Sends LPM transaction to the local device.
  76047. + *
  76048. + * @param hcd The HCD
  76049. + * @param devaddr Device Address
  76050. + * @param hird Host initiated resume duration
  76051. + * @param bRemoteWake Value of bRemoteWake field in LPM transaction
  76052. + *
  76053. + * Returns negative value if sending LPM transaction was not succeeded.
  76054. + * Returns 0 on success.
  76055. + */
  76056. +extern int dwc_otg_hcd_send_lpm(dwc_otg_hcd_t * hcd, uint8_t devaddr,
  76057. + uint8_t hird, uint8_t bRemoteWake);
  76058. +
  76059. +/* URB interface */
  76060. +
  76061. +/**
  76062. + * Allocates memory for dwc_otg_hcd_urb structure.
  76063. + * Allocated memory should be freed by call of DWC_FREE.
  76064. + *
  76065. + * @param hcd The HCD
  76066. + * @param iso_desc_count Count of ISOC descriptors
  76067. + * @param atomic_alloc Specefies whether to perform atomic allocation.
  76068. + */
  76069. +extern dwc_otg_hcd_urb_t *dwc_otg_hcd_urb_alloc(dwc_otg_hcd_t * hcd,
  76070. + int iso_desc_count,
  76071. + int atomic_alloc);
  76072. +
  76073. +/**
  76074. + * Set pipe information in URB.
  76075. + *
  76076. + * @param hcd_urb DWC_OTG URB
  76077. + * @param devaddr Device Address
  76078. + * @param ep_num Endpoint Number
  76079. + * @param ep_type Endpoint Type
  76080. + * @param ep_dir Endpoint Direction
  76081. + * @param mps Max Packet Size
  76082. + */
  76083. +extern void dwc_otg_hcd_urb_set_pipeinfo(dwc_otg_hcd_urb_t * hcd_urb,
  76084. + uint8_t devaddr, uint8_t ep_num,
  76085. + uint8_t ep_type, uint8_t ep_dir,
  76086. + uint16_t mps);
  76087. +
  76088. +/* Transfer flags */
  76089. +#define URB_GIVEBACK_ASAP 0x1
  76090. +#define URB_SEND_ZERO_PACKET 0x2
  76091. +
  76092. +/**
  76093. + * Sets dwc_otg_hcd_urb parameters.
  76094. + *
  76095. + * @param urb DWC_OTG URB allocated by dwc_otg_hcd_urb_alloc function.
  76096. + * @param urb_handle Unique handle for request, this will be passed back
  76097. + * to function driver in completion callback.
  76098. + * @param buf The buffer for the data
  76099. + * @param dma The DMA buffer for the data
  76100. + * @param buflen Transfer length
  76101. + * @param sp Buffer for setup data
  76102. + * @param sp_dma DMA address of setup data buffer
  76103. + * @param flags Transfer flags
  76104. + * @param interval Polling interval for interrupt or isochronous transfers.
  76105. + */
  76106. +extern void dwc_otg_hcd_urb_set_params(dwc_otg_hcd_urb_t * urb,
  76107. + void *urb_handle, void *buf,
  76108. + dwc_dma_t dma, uint32_t buflen, void *sp,
  76109. + dwc_dma_t sp_dma, uint32_t flags,
  76110. + uint16_t interval);
  76111. +
  76112. +/** Gets status from dwc_otg_hcd_urb
  76113. + *
  76114. + * @param dwc_otg_urb DWC_OTG URB
  76115. + */
  76116. +extern uint32_t dwc_otg_hcd_urb_get_status(dwc_otg_hcd_urb_t * dwc_otg_urb);
  76117. +
  76118. +/** Gets actual length from dwc_otg_hcd_urb
  76119. + *
  76120. + * @param dwc_otg_urb DWC_OTG URB
  76121. + */
  76122. +extern uint32_t dwc_otg_hcd_urb_get_actual_length(dwc_otg_hcd_urb_t *
  76123. + dwc_otg_urb);
  76124. +
  76125. +/** Gets error count from dwc_otg_hcd_urb. Only for ISOC URBs
  76126. + *
  76127. + * @param dwc_otg_urb DWC_OTG URB
  76128. + */
  76129. +extern uint32_t dwc_otg_hcd_urb_get_error_count(dwc_otg_hcd_urb_t *
  76130. + dwc_otg_urb);
  76131. +
  76132. +/** Set ISOC descriptor offset and length
  76133. + *
  76134. + * @param dwc_otg_urb DWC_OTG URB
  76135. + * @param desc_num ISOC descriptor number
  76136. + * @param offset Offset from beginig of buffer.
  76137. + * @param length Transaction length
  76138. + */
  76139. +extern void dwc_otg_hcd_urb_set_iso_desc_params(dwc_otg_hcd_urb_t * dwc_otg_urb,
  76140. + int desc_num, uint32_t offset,
  76141. + uint32_t length);
  76142. +
  76143. +/** Get status of ISOC descriptor, specified by desc_num
  76144. + *
  76145. + * @param dwc_otg_urb DWC_OTG URB
  76146. + * @param desc_num ISOC descriptor number
  76147. + */
  76148. +extern uint32_t dwc_otg_hcd_urb_get_iso_desc_status(dwc_otg_hcd_urb_t *
  76149. + dwc_otg_urb, int desc_num);
  76150. +
  76151. +/** Get actual length of ISOC descriptor, specified by desc_num
  76152. + *
  76153. + * @param dwc_otg_urb DWC_OTG URB
  76154. + * @param desc_num ISOC descriptor number
  76155. + */
  76156. +extern uint32_t dwc_otg_hcd_urb_get_iso_desc_actual_length(dwc_otg_hcd_urb_t *
  76157. + dwc_otg_urb,
  76158. + int desc_num);
  76159. +
  76160. +/** Queue URB. After transfer is completes, the complete callback will be called with the URB status
  76161. + *
  76162. + * @param dwc_otg_hcd The HCD
  76163. + * @param dwc_otg_urb DWC_OTG URB
  76164. + * @param ep_handle Out parameter for returning endpoint handle
  76165. + * @param atomic_alloc Flag to do atomic allocation if needed
  76166. + *
  76167. + * Returns -DWC_E_NO_DEVICE if no device is connected.
  76168. + * Returns -DWC_E_NO_MEMORY if there is no enough memory.
  76169. + * Returns 0 on success.
  76170. + */
  76171. +extern int dwc_otg_hcd_urb_enqueue(dwc_otg_hcd_t * dwc_otg_hcd,
  76172. + dwc_otg_hcd_urb_t * dwc_otg_urb,
  76173. + void **ep_handle, int atomic_alloc);
  76174. +
  76175. +/** De-queue the specified URB
  76176. + *
  76177. + * @param dwc_otg_hcd The HCD
  76178. + * @param dwc_otg_urb DWC_OTG URB
  76179. + */
  76180. +extern int dwc_otg_hcd_urb_dequeue(dwc_otg_hcd_t * dwc_otg_hcd,
  76181. + dwc_otg_hcd_urb_t * dwc_otg_urb);
  76182. +
  76183. +/** Frees resources in the DWC_otg controller related to a given endpoint.
  76184. + * Any URBs for the endpoint must already be dequeued.
  76185. + *
  76186. + * @param hcd The HCD
  76187. + * @param ep_handle Endpoint handle, returned by dwc_otg_hcd_urb_enqueue function
  76188. + * @param retry Number of retries if there are queued transfers.
  76189. + *
  76190. + * Returns -DWC_E_INVALID if invalid arguments are passed.
  76191. + * Returns 0 on success
  76192. + */
  76193. +extern int dwc_otg_hcd_endpoint_disable(dwc_otg_hcd_t * hcd, void *ep_handle,
  76194. + int retry);
  76195. +
  76196. +/* Resets the data toggle in qh structure. This function can be called from
  76197. + * usb_clear_halt routine.
  76198. + *
  76199. + * @param hcd The HCD
  76200. + * @param ep_handle Endpoint handle, returned by dwc_otg_hcd_urb_enqueue function
  76201. + *
  76202. + * Returns -DWC_E_INVALID if invalid arguments are passed.
  76203. + * Returns 0 on success
  76204. + */
  76205. +extern int dwc_otg_hcd_endpoint_reset(dwc_otg_hcd_t * hcd, void *ep_handle);
  76206. +
  76207. +/** Returns 1 if status of specified port is changed and 0 otherwise.
  76208. + *
  76209. + * @param hcd The HCD
  76210. + * @param port Port number
  76211. + */
  76212. +extern int dwc_otg_hcd_is_status_changed(dwc_otg_hcd_t * hcd, int port);
  76213. +
  76214. +/** Call this function to check if bandwidth was allocated for specified endpoint.
  76215. + * Only for ISOC and INTERRUPT endpoints.
  76216. + *
  76217. + * @param hcd The HCD
  76218. + * @param ep_handle Endpoint handle
  76219. + */
  76220. +extern int dwc_otg_hcd_is_bandwidth_allocated(dwc_otg_hcd_t * hcd,
  76221. + void *ep_handle);
  76222. +
  76223. +/** Call this function to check if bandwidth was freed for specified endpoint.
  76224. + *
  76225. + * @param hcd The HCD
  76226. + * @param ep_handle Endpoint handle
  76227. + */
  76228. +extern int dwc_otg_hcd_is_bandwidth_freed(dwc_otg_hcd_t * hcd, void *ep_handle);
  76229. +
  76230. +/** Returns bandwidth allocated for specified endpoint in microseconds.
  76231. + * Only for ISOC and INTERRUPT endpoints.
  76232. + *
  76233. + * @param hcd The HCD
  76234. + * @param ep_handle Endpoint handle
  76235. + */
  76236. +extern uint8_t dwc_otg_hcd_get_ep_bandwidth(dwc_otg_hcd_t * hcd,
  76237. + void *ep_handle);
  76238. +
  76239. +/** @} */
  76240. +
  76241. +#endif /* __DWC_HCD_IF_H__ */
  76242. +#endif /* DWC_DEVICE_ONLY */
  76243. diff -Nur linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c
  76244. --- linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c 1970-01-01 01:00:00.000000000 +0100
  76245. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c 2014-04-24 15:37:13.314990533 +0200
  76246. @@ -0,0 +1,2674 @@
  76247. +/* ==========================================================================
  76248. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_intr.c $
  76249. + * $Revision: #89 $
  76250. + * $Date: 2011/10/20 $
  76251. + * $Change: 1869487 $
  76252. + *
  76253. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  76254. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  76255. + * otherwise expressly agreed to in writing between Synopsys and you.
  76256. + *
  76257. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  76258. + * any End User Software License Agreement or Agreement for Licensed Product
  76259. + * with Synopsys or any supplement thereto. You are permitted to use and
  76260. + * redistribute this Software in source and binary forms, with or without
  76261. + * modification, provided that redistributions of source code must retain this
  76262. + * notice. You may not view, use, disclose, copy or distribute this file or
  76263. + * any information contained herein except pursuant to this license grant from
  76264. + * Synopsys. If you do not agree with this notice, including the disclaimer
  76265. + * below, then you are not authorized to use the Software.
  76266. + *
  76267. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  76268. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  76269. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  76270. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  76271. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  76272. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  76273. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  76274. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  76275. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  76276. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  76277. + * DAMAGE.
  76278. + * ========================================================================== */
  76279. +#ifndef DWC_DEVICE_ONLY
  76280. +
  76281. +#include "dwc_otg_hcd.h"
  76282. +#include "dwc_otg_regs.h"
  76283. +
  76284. +#include <linux/jiffies.h>
  76285. +#include <mach/hardware.h>
  76286. +#include <asm/fiq.h>
  76287. +
  76288. +
  76289. +extern bool microframe_schedule;
  76290. +
  76291. +/** @file
  76292. + * This file contains the implementation of the HCD Interrupt handlers.
  76293. + */
  76294. +
  76295. +int fiq_done, int_done;
  76296. +
  76297. +#ifdef FIQ_DEBUG
  76298. +char buffer[1000*16];
  76299. +int wptr;
  76300. +void notrace _fiq_print(FIQDBG_T dbg_lvl, char *fmt, ...)
  76301. +{
  76302. + FIQDBG_T dbg_lvl_req = FIQDBG_PORTHUB;
  76303. + va_list args;
  76304. + char text[17];
  76305. + hfnum_data_t hfnum = { .d32 = FIQ_READ(dwc_regs_base + 0x408) };
  76306. +
  76307. + if(dbg_lvl & dbg_lvl_req || dbg_lvl == FIQDBG_ERR)
  76308. + {
  76309. + local_fiq_disable();
  76310. + snprintf(text, 9, "%4d%d:%d ", hfnum.b.frnum/8, hfnum.b.frnum%8, 8 - hfnum.b.frrem/937);
  76311. + va_start(args, fmt);
  76312. + vsnprintf(text+8, 9, fmt, args);
  76313. + va_end(args);
  76314. +
  76315. + memcpy(buffer + wptr, text, 16);
  76316. + wptr = (wptr + 16) % sizeof(buffer);
  76317. + local_fiq_enable();
  76318. + }
  76319. +}
  76320. +#endif
  76321. +
  76322. +/** This function handles interrupts for the HCD. */
  76323. +int32_t dwc_otg_hcd_handle_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  76324. +{
  76325. + int retval = 0;
  76326. + static int last_time;
  76327. + dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
  76328. + gintsts_data_t gintsts;
  76329. + gintmsk_data_t gintmsk;
  76330. + hfnum_data_t hfnum;
  76331. + haintmsk_data_t haintmsk;
  76332. +
  76333. +#ifdef DEBUG
  76334. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  76335. +
  76336. +#endif
  76337. +
  76338. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  76339. + gintmsk.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  76340. +
  76341. + /* Exit from ISR if core is hibernated */
  76342. + if (core_if->hibernation_suspend == 1) {
  76343. + goto exit_handler_routine;
  76344. + }
  76345. + DWC_SPINLOCK(dwc_otg_hcd->lock);
  76346. + /* Check if HOST Mode */
  76347. + if (dwc_otg_is_host_mode(core_if)) {
  76348. + local_fiq_disable();
  76349. + /* Pull in from the FIQ's disabled mask */
  76350. + gintmsk.d32 = gintmsk.d32 | ~(dwc_otg_hcd->fiq_state->gintmsk_saved.d32);
  76351. + dwc_otg_hcd->fiq_state->gintmsk_saved.d32 = ~0;
  76352. +
  76353. +
  76354. + if (fiq_fsm_enable && ( 0x0000FFFF & ~(dwc_otg_hcd->fiq_state->haintmsk_saved.b2.chint))) {
  76355. + gintsts.b.hcintr = 1;
  76356. + }
  76357. +
  76358. + /* Danger will robinson: fake a SOF if necessary */
  76359. + if (fiq_fsm_enable && (dwc_otg_hcd->fiq_state->gintmsk_saved.b.sofintr == 1)) {
  76360. + gintsts.b.sofintr = 1;
  76361. + }
  76362. + gintsts.d32 &= gintmsk.d32;
  76363. +
  76364. + local_fiq_enable();
  76365. + if (!gintsts.d32) {
  76366. + goto exit_handler_routine;
  76367. + }
  76368. +
  76369. +#ifdef DEBUG
  76370. + // We should be OK doing this because the common interrupts should already have been serviced
  76371. + /* Don't print debug message in the interrupt handler on SOF */
  76372. +#ifndef DEBUG_SOF
  76373. + if (gintsts.d32 != DWC_SOF_INTR_MASK)
  76374. +#endif
  76375. + DWC_DEBUGPL(DBG_HCDI, "\n");
  76376. +#endif
  76377. +
  76378. +#ifdef DEBUG
  76379. +#ifndef DEBUG_SOF
  76380. + if (gintsts.d32 != DWC_SOF_INTR_MASK)
  76381. +#endif
  76382. + DWC_DEBUGPL(DBG_HCDI,
  76383. + "DWC OTG HCD Interrupt Detected gintsts&gintmsk=0x%08x core_if=%p\n",
  76384. + gintsts.d32, core_if);
  76385. +#endif
  76386. + hfnum.d32 = DWC_READ_REG32(&dwc_otg_hcd->core_if->host_if->host_global_regs->hfnum);
  76387. + if (gintsts.b.sofintr) {
  76388. + retval |= dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd);
  76389. + }
  76390. +
  76391. + if (gintsts.b.rxstsqlvl) {
  76392. + retval |=
  76393. + dwc_otg_hcd_handle_rx_status_q_level_intr
  76394. + (dwc_otg_hcd);
  76395. + }
  76396. + if (gintsts.b.nptxfempty) {
  76397. + retval |=
  76398. + dwc_otg_hcd_handle_np_tx_fifo_empty_intr
  76399. + (dwc_otg_hcd);
  76400. + }
  76401. + if (gintsts.b.i2cintr) {
  76402. + /** @todo Implement i2cintr handler. */
  76403. + }
  76404. + if (gintsts.b.portintr) {
  76405. +
  76406. + gintmsk_data_t gintmsk = { .b.portintr = 1};
  76407. + retval |= dwc_otg_hcd_handle_port_intr(dwc_otg_hcd);
  76408. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, gintmsk.d32);
  76409. + }
  76410. + if (gintsts.b.hcintr) {
  76411. + retval |= dwc_otg_hcd_handle_hc_intr(dwc_otg_hcd);
  76412. + }
  76413. + if (gintsts.b.ptxfempty) {
  76414. + retval |=
  76415. + dwc_otg_hcd_handle_perio_tx_fifo_empty_intr
  76416. + (dwc_otg_hcd);
  76417. + }
  76418. +#ifdef DEBUG
  76419. +#ifndef DEBUG_SOF
  76420. + if (gintsts.d32 != DWC_SOF_INTR_MASK)
  76421. +#endif
  76422. + {
  76423. + DWC_DEBUGPL(DBG_HCDI,
  76424. + "DWC OTG HCD Finished Servicing Interrupts\n");
  76425. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD gintsts=0x%08x\n",
  76426. + DWC_READ_REG32(&global_regs->gintsts));
  76427. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD gintmsk=0x%08x\n",
  76428. + DWC_READ_REG32(&global_regs->gintmsk));
  76429. + }
  76430. +#endif
  76431. +
  76432. +#ifdef DEBUG
  76433. +#ifndef DEBUG_SOF
  76434. + if (gintsts.d32 != DWC_SOF_INTR_MASK)
  76435. +#endif
  76436. + DWC_DEBUGPL(DBG_HCDI, "\n");
  76437. +#endif
  76438. +
  76439. + }
  76440. +
  76441. +exit_handler_routine:
  76442. + if (fiq_enable) {
  76443. + gintmsk_data_t gintmsk_new;
  76444. + haintmsk_data_t haintmsk_new;
  76445. + local_fiq_disable();
  76446. + gintmsk_new.d32 = *(volatile uint32_t *)&dwc_otg_hcd->fiq_state->gintmsk_saved.d32;
  76447. + if(fiq_fsm_enable)
  76448. + haintmsk_new.d32 = *(volatile uint32_t *)&dwc_otg_hcd->fiq_state->haintmsk_saved.d32;
  76449. + else
  76450. + haintmsk_new.d32 = 0x0000FFFF;
  76451. +
  76452. + /* The FIQ could have sneaked another interrupt in. If so, don't clear MPHI */
  76453. + if ((gintmsk_new.d32 == ~0) && (haintmsk_new.d32 == 0x0000FFFF)) {
  76454. + DWC_WRITE_REG32(dwc_otg_hcd->fiq_state->mphi_regs.intstat, (1<<16));
  76455. + if (dwc_otg_hcd->fiq_state->mphi_int_count >= 50) {
  76456. + fiq_print(FIQDBG_INT, dwc_otg_hcd->fiq_state, "MPHI CLR");
  76457. + DWC_WRITE_REG32(dwc_otg_hcd->fiq_state->mphi_regs.ctrl, ((1<<31) + (1<<16)));
  76458. + while (!(DWC_READ_REG32(dwc_otg_hcd->fiq_state->mphi_regs.ctrl) & (1 << 17)))
  76459. + ;
  76460. + DWC_WRITE_REG32(dwc_otg_hcd->fiq_state->mphi_regs.ctrl, (1<<31));
  76461. + dwc_otg_hcd->fiq_state->mphi_int_count = 0;
  76462. + }
  76463. + int_done++;
  76464. + }
  76465. + haintmsk.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->haintmsk);
  76466. + /* Re-enable interrupts that the FIQ masked (first time round) */
  76467. + FIQ_WRITE(dwc_otg_hcd->fiq_state->dwc_regs_base + GINTMSK, gintmsk.d32);
  76468. + local_fiq_enable();
  76469. +
  76470. + if ((jiffies / HZ) > last_time) {
  76471. + //dwc_otg_qh_t *qh;
  76472. + //dwc_list_link_t *cur;
  76473. + /* Once a second output the fiq and irq numbers, useful for debug */
  76474. + last_time = jiffies / HZ;
  76475. + // DWC_WARN("np_kick=%d AHC=%d sched_frame=%d cur_frame=%d int_done=%d fiq_done=%d",
  76476. + // dwc_otg_hcd->fiq_state->kick_np_queues, dwc_otg_hcd->available_host_channels,
  76477. + // dwc_otg_hcd->fiq_state->next_sched_frame, hfnum.b.frnum, int_done, dwc_otg_hcd->fiq_state->fiq_done);
  76478. + //printk(KERN_WARNING "Periodic queues:\n");
  76479. + }
  76480. + }
  76481. +
  76482. + DWC_SPINUNLOCK(dwc_otg_hcd->lock);
  76483. + return retval;
  76484. +}
  76485. +
  76486. +#ifdef DWC_TRACK_MISSED_SOFS
  76487. +
  76488. +#warning Compiling code to track missed SOFs
  76489. +#define FRAME_NUM_ARRAY_SIZE 1000
  76490. +/**
  76491. + * This function is for debug only.
  76492. + */
  76493. +static inline void track_missed_sofs(uint16_t curr_frame_number)
  76494. +{
  76495. + static uint16_t frame_num_array[FRAME_NUM_ARRAY_SIZE];
  76496. + static uint16_t last_frame_num_array[FRAME_NUM_ARRAY_SIZE];
  76497. + static int frame_num_idx = 0;
  76498. + static uint16_t last_frame_num = DWC_HFNUM_MAX_FRNUM;
  76499. + static int dumped_frame_num_array = 0;
  76500. +
  76501. + if (frame_num_idx < FRAME_NUM_ARRAY_SIZE) {
  76502. + if (((last_frame_num + 1) & DWC_HFNUM_MAX_FRNUM) !=
  76503. + curr_frame_number) {
  76504. + frame_num_array[frame_num_idx] = curr_frame_number;
  76505. + last_frame_num_array[frame_num_idx++] = last_frame_num;
  76506. + }
  76507. + } else if (!dumped_frame_num_array) {
  76508. + int i;
  76509. + DWC_PRINTF("Frame Last Frame\n");
  76510. + DWC_PRINTF("----- ----------\n");
  76511. + for (i = 0; i < FRAME_NUM_ARRAY_SIZE; i++) {
  76512. + DWC_PRINTF("0x%04x 0x%04x\n",
  76513. + frame_num_array[i], last_frame_num_array[i]);
  76514. + }
  76515. + dumped_frame_num_array = 1;
  76516. + }
  76517. + last_frame_num = curr_frame_number;
  76518. +}
  76519. +#endif
  76520. +
  76521. +/**
  76522. + * Handles the start-of-frame interrupt in host mode. Non-periodic
  76523. + * transactions may be queued to the DWC_otg controller for the current
  76524. + * (micro)frame. Periodic transactions may be queued to the controller for the
  76525. + * next (micro)frame.
  76526. + */
  76527. +int32_t dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd_t * hcd)
  76528. +{
  76529. + hfnum_data_t hfnum;
  76530. + gintsts_data_t gintsts = { .d32 = 0 };
  76531. + dwc_list_link_t *qh_entry;
  76532. + dwc_otg_qh_t *qh;
  76533. + dwc_otg_transaction_type_e tr_type;
  76534. + int did_something = 0;
  76535. + int32_t next_sched_frame = -1;
  76536. +
  76537. + hfnum.d32 =
  76538. + DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hfnum);
  76539. +
  76540. +#ifdef DEBUG_SOF
  76541. + DWC_DEBUGPL(DBG_HCD, "--Start of Frame Interrupt--\n");
  76542. +#endif
  76543. + hcd->frame_number = hfnum.b.frnum;
  76544. +
  76545. +#ifdef DEBUG
  76546. + hcd->frrem_accum += hfnum.b.frrem;
  76547. + hcd->frrem_samples++;
  76548. +#endif
  76549. +
  76550. +#ifdef DWC_TRACK_MISSED_SOFS
  76551. + track_missed_sofs(hcd->frame_number);
  76552. +#endif
  76553. + /* Determine whether any periodic QHs should be executed. */
  76554. + qh_entry = DWC_LIST_FIRST(&hcd->periodic_sched_inactive);
  76555. + while (qh_entry != &hcd->periodic_sched_inactive) {
  76556. + qh = DWC_LIST_ENTRY(qh_entry, dwc_otg_qh_t, qh_list_entry);
  76557. + qh_entry = qh_entry->next;
  76558. + if (dwc_frame_num_le(qh->sched_frame, hcd->frame_number)) {
  76559. +
  76560. + /*
  76561. + * Move QH to the ready list to be executed next
  76562. + * (micro)frame.
  76563. + */
  76564. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_ready,
  76565. + &qh->qh_list_entry);
  76566. +
  76567. + did_something = 1;
  76568. + }
  76569. + else
  76570. + {
  76571. + if(next_sched_frame < 0 || dwc_frame_num_le(qh->sched_frame, next_sched_frame))
  76572. + {
  76573. + next_sched_frame = qh->sched_frame;
  76574. + }
  76575. + }
  76576. + }
  76577. +
  76578. + hcd->fiq_state->next_sched_frame = next_sched_frame;
  76579. +
  76580. + tr_type = dwc_otg_hcd_select_transactions(hcd);
  76581. + if (tr_type != DWC_OTG_TRANSACTION_NONE) {
  76582. + dwc_otg_hcd_queue_transactions(hcd, tr_type);
  76583. + did_something = 1;
  76584. + }
  76585. +
  76586. + /* Clear interrupt - but do not trample on the FIQ sof */
  76587. + if (!fiq_fsm_enable) {
  76588. + gintsts.b.sofintr = 1;
  76589. + DWC_WRITE_REG32(&hcd->core_if->core_global_regs->gintsts, gintsts.d32);
  76590. + }
  76591. + return 1;
  76592. +}
  76593. +
  76594. +/** Handles the Rx Status Queue Level Interrupt, which indicates that there is at
  76595. + * least one packet in the Rx FIFO. The packets are moved from the FIFO to
  76596. + * memory if the DWC_otg controller is operating in Slave mode. */
  76597. +int32_t dwc_otg_hcd_handle_rx_status_q_level_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  76598. +{
  76599. + host_grxsts_data_t grxsts;
  76600. + dwc_hc_t *hc = NULL;
  76601. +
  76602. + DWC_DEBUGPL(DBG_HCD, "--RxStsQ Level Interrupt--\n");
  76603. +
  76604. + grxsts.d32 =
  76605. + DWC_READ_REG32(&dwc_otg_hcd->core_if->core_global_regs->grxstsp);
  76606. +
  76607. + hc = dwc_otg_hcd->hc_ptr_array[grxsts.b.chnum];
  76608. + if (!hc) {
  76609. + DWC_ERROR("Unable to get corresponding channel\n");
  76610. + return 0;
  76611. + }
  76612. +
  76613. + /* Packet Status */
  76614. + DWC_DEBUGPL(DBG_HCDV, " Ch num = %d\n", grxsts.b.chnum);
  76615. + DWC_DEBUGPL(DBG_HCDV, " Count = %d\n", grxsts.b.bcnt);
  76616. + DWC_DEBUGPL(DBG_HCDV, " DPID = %d, hc.dpid = %d\n", grxsts.b.dpid,
  76617. + hc->data_pid_start);
  76618. + DWC_DEBUGPL(DBG_HCDV, " PStatus = %d\n", grxsts.b.pktsts);
  76619. +
  76620. + switch (grxsts.b.pktsts) {
  76621. + case DWC_GRXSTS_PKTSTS_IN:
  76622. + /* Read the data into the host buffer. */
  76623. + if (grxsts.b.bcnt > 0) {
  76624. + dwc_otg_read_packet(dwc_otg_hcd->core_if,
  76625. + hc->xfer_buff, grxsts.b.bcnt);
  76626. +
  76627. + /* Update the HC fields for the next packet received. */
  76628. + hc->xfer_count += grxsts.b.bcnt;
  76629. + hc->xfer_buff += grxsts.b.bcnt;
  76630. + }
  76631. +
  76632. + case DWC_GRXSTS_PKTSTS_IN_XFER_COMP:
  76633. + case DWC_GRXSTS_PKTSTS_DATA_TOGGLE_ERR:
  76634. + case DWC_GRXSTS_PKTSTS_CH_HALTED:
  76635. + /* Handled in interrupt, just ignore data */
  76636. + break;
  76637. + default:
  76638. + DWC_ERROR("RX_STS_Q Interrupt: Unknown status %d\n",
  76639. + grxsts.b.pktsts);
  76640. + break;
  76641. + }
  76642. +
  76643. + return 1;
  76644. +}
  76645. +
  76646. +/** This interrupt occurs when the non-periodic Tx FIFO is half-empty. More
  76647. + * data packets may be written to the FIFO for OUT transfers. More requests
  76648. + * may be written to the non-periodic request queue for IN transfers. This
  76649. + * interrupt is enabled only in Slave mode. */
  76650. +int32_t dwc_otg_hcd_handle_np_tx_fifo_empty_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  76651. +{
  76652. + DWC_DEBUGPL(DBG_HCD, "--Non-Periodic TxFIFO Empty Interrupt--\n");
  76653. + dwc_otg_hcd_queue_transactions(dwc_otg_hcd,
  76654. + DWC_OTG_TRANSACTION_NON_PERIODIC);
  76655. + return 1;
  76656. +}
  76657. +
  76658. +/** This interrupt occurs when the periodic Tx FIFO is half-empty. More data
  76659. + * packets may be written to the FIFO for OUT transfers. More requests may be
  76660. + * written to the periodic request queue for IN transfers. This interrupt is
  76661. + * enabled only in Slave mode. */
  76662. +int32_t dwc_otg_hcd_handle_perio_tx_fifo_empty_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  76663. +{
  76664. + DWC_DEBUGPL(DBG_HCD, "--Periodic TxFIFO Empty Interrupt--\n");
  76665. + dwc_otg_hcd_queue_transactions(dwc_otg_hcd,
  76666. + DWC_OTG_TRANSACTION_PERIODIC);
  76667. + return 1;
  76668. +}
  76669. +
  76670. +/** There are multiple conditions that can cause a port interrupt. This function
  76671. + * determines which interrupt conditions have occurred and handles them
  76672. + * appropriately. */
  76673. +int32_t dwc_otg_hcd_handle_port_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  76674. +{
  76675. + int retval = 0;
  76676. + hprt0_data_t hprt0;
  76677. + hprt0_data_t hprt0_modify;
  76678. +
  76679. + hprt0.d32 = DWC_READ_REG32(dwc_otg_hcd->core_if->host_if->hprt0);
  76680. + hprt0_modify.d32 = DWC_READ_REG32(dwc_otg_hcd->core_if->host_if->hprt0);
  76681. +
  76682. + /* Clear appropriate bits in HPRT0 to clear the interrupt bit in
  76683. + * GINTSTS */
  76684. +
  76685. + hprt0_modify.b.prtena = 0;
  76686. + hprt0_modify.b.prtconndet = 0;
  76687. + hprt0_modify.b.prtenchng = 0;
  76688. + hprt0_modify.b.prtovrcurrchng = 0;
  76689. +
  76690. + /* Port Connect Detected
  76691. + * Set flag and clear if detected */
  76692. + if (dwc_otg_hcd->core_if->hibernation_suspend == 1) {
  76693. + // Dont modify port status if we are in hibernation state
  76694. + hprt0_modify.b.prtconndet = 1;
  76695. + hprt0_modify.b.prtenchng = 1;
  76696. + DWC_WRITE_REG32(dwc_otg_hcd->core_if->host_if->hprt0, hprt0_modify.d32);
  76697. + hprt0.d32 = DWC_READ_REG32(dwc_otg_hcd->core_if->host_if->hprt0);
  76698. + return retval;
  76699. + }
  76700. +
  76701. + if (hprt0.b.prtconndet) {
  76702. + /** @todo - check if steps performed in 'else' block should be perfromed regardles adp */
  76703. + if (dwc_otg_hcd->core_if->adp_enable &&
  76704. + dwc_otg_hcd->core_if->adp.vbuson_timer_started == 1) {
  76705. + DWC_PRINTF("PORT CONNECT DETECTED ----------------\n");
  76706. + DWC_TIMER_CANCEL(dwc_otg_hcd->core_if->adp.vbuson_timer);
  76707. + dwc_otg_hcd->core_if->adp.vbuson_timer_started = 0;
  76708. + /* TODO - check if this is required, as
  76709. + * host initialization was already performed
  76710. + * after initial ADP probing
  76711. + */
  76712. + /*dwc_otg_hcd->core_if->adp.vbuson_timer_started = 0;
  76713. + dwc_otg_core_init(dwc_otg_hcd->core_if);
  76714. + dwc_otg_enable_global_interrupts(dwc_otg_hcd->core_if);
  76715. + cil_hcd_start(dwc_otg_hcd->core_if);*/
  76716. + } else {
  76717. +
  76718. + DWC_DEBUGPL(DBG_HCD, "--Port Interrupt HPRT0=0x%08x "
  76719. + "Port Connect Detected--\n", hprt0.d32);
  76720. + dwc_otg_hcd->flags.b.port_connect_status_change = 1;
  76721. + dwc_otg_hcd->flags.b.port_connect_status = 1;
  76722. + hprt0_modify.b.prtconndet = 1;
  76723. +
  76724. + /* B-Device has connected, Delete the connection timer. */
  76725. + DWC_TIMER_CANCEL(dwc_otg_hcd->conn_timer);
  76726. + }
  76727. + /* The Hub driver asserts a reset when it sees port connect
  76728. + * status change flag */
  76729. + retval |= 1;
  76730. + }
  76731. +
  76732. + /* Port Enable Changed
  76733. + * Clear if detected - Set internal flag if disabled */
  76734. + if (hprt0.b.prtenchng) {
  76735. + DWC_DEBUGPL(DBG_HCD, " --Port Interrupt HPRT0=0x%08x "
  76736. + "Port Enable Changed--\n", hprt0.d32);
  76737. + hprt0_modify.b.prtenchng = 1;
  76738. + if (hprt0.b.prtena == 1) {
  76739. + hfir_data_t hfir;
  76740. + int do_reset = 0;
  76741. + dwc_otg_core_params_t *params =
  76742. + dwc_otg_hcd->core_if->core_params;
  76743. + dwc_otg_core_global_regs_t *global_regs =
  76744. + dwc_otg_hcd->core_if->core_global_regs;
  76745. + dwc_otg_host_if_t *host_if =
  76746. + dwc_otg_hcd->core_if->host_if;
  76747. +
  76748. + /* Every time when port enables calculate
  76749. + * HFIR.FrInterval
  76750. + */
  76751. + hfir.d32 = DWC_READ_REG32(&host_if->host_global_regs->hfir);
  76752. + hfir.b.frint = calc_frame_interval(dwc_otg_hcd->core_if);
  76753. + DWC_WRITE_REG32(&host_if->host_global_regs->hfir, hfir.d32);
  76754. +
  76755. + /* Check if we need to adjust the PHY clock speed for
  76756. + * low power and adjust it */
  76757. + if (params->host_support_fs_ls_low_power) {
  76758. + gusbcfg_data_t usbcfg;
  76759. +
  76760. + usbcfg.d32 =
  76761. + DWC_READ_REG32(&global_regs->gusbcfg);
  76762. +
  76763. + if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_LOW_SPEED
  76764. + || hprt0.b.prtspd ==
  76765. + DWC_HPRT0_PRTSPD_FULL_SPEED) {
  76766. + /*
  76767. + * Low power
  76768. + */
  76769. + hcfg_data_t hcfg;
  76770. + if (usbcfg.b.phylpwrclksel == 0) {
  76771. + /* Set PHY low power clock select for FS/LS devices */
  76772. + usbcfg.b.phylpwrclksel = 1;
  76773. + DWC_WRITE_REG32
  76774. + (&global_regs->gusbcfg,
  76775. + usbcfg.d32);
  76776. + do_reset = 1;
  76777. + }
  76778. +
  76779. + hcfg.d32 =
  76780. + DWC_READ_REG32
  76781. + (&host_if->host_global_regs->hcfg);
  76782. +
  76783. + if (hprt0.b.prtspd ==
  76784. + DWC_HPRT0_PRTSPD_LOW_SPEED
  76785. + && params->host_ls_low_power_phy_clk
  76786. + ==
  76787. + DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ)
  76788. + {
  76789. + /* 6 MHZ */
  76790. + DWC_DEBUGPL(DBG_CIL,
  76791. + "FS_PHY programming HCFG to 6 MHz (Low Power)\n");
  76792. + if (hcfg.b.fslspclksel !=
  76793. + DWC_HCFG_6_MHZ) {
  76794. + hcfg.b.fslspclksel =
  76795. + DWC_HCFG_6_MHZ;
  76796. + DWC_WRITE_REG32
  76797. + (&host_if->host_global_regs->hcfg,
  76798. + hcfg.d32);
  76799. + do_reset = 1;
  76800. + }
  76801. + } else {
  76802. + /* 48 MHZ */
  76803. + DWC_DEBUGPL(DBG_CIL,
  76804. + "FS_PHY programming HCFG to 48 MHz ()\n");
  76805. + if (hcfg.b.fslspclksel !=
  76806. + DWC_HCFG_48_MHZ) {
  76807. + hcfg.b.fslspclksel =
  76808. + DWC_HCFG_48_MHZ;
  76809. + DWC_WRITE_REG32
  76810. + (&host_if->host_global_regs->hcfg,
  76811. + hcfg.d32);
  76812. + do_reset = 1;
  76813. + }
  76814. + }
  76815. + } else {
  76816. + /*
  76817. + * Not low power
  76818. + */
  76819. + if (usbcfg.b.phylpwrclksel == 1) {
  76820. + usbcfg.b.phylpwrclksel = 0;
  76821. + DWC_WRITE_REG32
  76822. + (&global_regs->gusbcfg,
  76823. + usbcfg.d32);
  76824. + do_reset = 1;
  76825. + }
  76826. + }
  76827. +
  76828. + if (do_reset) {
  76829. + DWC_TASK_SCHEDULE(dwc_otg_hcd->reset_tasklet);
  76830. + }
  76831. + }
  76832. +
  76833. + if (!do_reset) {
  76834. + /* Port has been enabled set the reset change flag */
  76835. + dwc_otg_hcd->flags.b.port_reset_change = 1;
  76836. + }
  76837. + } else {
  76838. + dwc_otg_hcd->flags.b.port_enable_change = 1;
  76839. + }
  76840. + retval |= 1;
  76841. + }
  76842. +
  76843. + /** Overcurrent Change Interrupt */
  76844. + if (hprt0.b.prtovrcurrchng) {
  76845. + DWC_DEBUGPL(DBG_HCD, " --Port Interrupt HPRT0=0x%08x "
  76846. + "Port Overcurrent Changed--\n", hprt0.d32);
  76847. + dwc_otg_hcd->flags.b.port_over_current_change = 1;
  76848. + hprt0_modify.b.prtovrcurrchng = 1;
  76849. + retval |= 1;
  76850. + }
  76851. +
  76852. + /* Clear Port Interrupts */
  76853. + DWC_WRITE_REG32(dwc_otg_hcd->core_if->host_if->hprt0, hprt0_modify.d32);
  76854. +
  76855. + return retval;
  76856. +}
  76857. +
  76858. +/** This interrupt indicates that one or more host channels has a pending
  76859. + * interrupt. There are multiple conditions that can cause each host channel
  76860. + * interrupt. This function determines which conditions have occurred for each
  76861. + * host channel interrupt and handles them appropriately. */
  76862. +int32_t dwc_otg_hcd_handle_hc_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  76863. +{
  76864. + int i;
  76865. + int retval = 0;
  76866. + haint_data_t haint = { .d32 = 0 } ;
  76867. +
  76868. + /* Clear appropriate bits in HCINTn to clear the interrupt bit in
  76869. + * GINTSTS */
  76870. +
  76871. + if (!fiq_fsm_enable)
  76872. + haint.d32 = dwc_otg_read_host_all_channels_intr(dwc_otg_hcd->core_if);
  76873. +
  76874. + // Overwrite with saved interrupts from fiq handler
  76875. + if(fiq_fsm_enable)
  76876. + {
  76877. + /* check the mask? */
  76878. + local_fiq_disable();
  76879. + haint.b2.chint |= ~(dwc_otg_hcd->fiq_state->haintmsk_saved.b2.chint);
  76880. + dwc_otg_hcd->fiq_state->haintmsk_saved.b2.chint = ~0;
  76881. + local_fiq_enable();
  76882. + }
  76883. +
  76884. + for (i = 0; i < dwc_otg_hcd->core_if->core_params->host_channels; i++) {
  76885. + if (haint.b2.chint & (1 << i)) {
  76886. + retval |= dwc_otg_hcd_handle_hc_n_intr(dwc_otg_hcd, i);
  76887. + }
  76888. + }
  76889. +
  76890. + return retval;
  76891. +}
  76892. +
  76893. +/**
  76894. + * Gets the actual length of a transfer after the transfer halts. _halt_status
  76895. + * holds the reason for the halt.
  76896. + *
  76897. + * For IN transfers where halt_status is DWC_OTG_HC_XFER_COMPLETE,
  76898. + * *short_read is set to 1 upon return if less than the requested
  76899. + * number of bytes were transferred. Otherwise, *short_read is set to 0 upon
  76900. + * return. short_read may also be NULL on entry, in which case it remains
  76901. + * unchanged.
  76902. + */
  76903. +static uint32_t get_actual_xfer_length(dwc_hc_t * hc,
  76904. + dwc_otg_hc_regs_t * hc_regs,
  76905. + dwc_otg_qtd_t * qtd,
  76906. + dwc_otg_halt_status_e halt_status,
  76907. + int *short_read)
  76908. +{
  76909. + hctsiz_data_t hctsiz;
  76910. + uint32_t length;
  76911. +
  76912. + if (short_read != NULL) {
  76913. + *short_read = 0;
  76914. + }
  76915. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  76916. +
  76917. + if (halt_status == DWC_OTG_HC_XFER_COMPLETE) {
  76918. + if (hc->ep_is_in) {
  76919. + length = hc->xfer_len - hctsiz.b.xfersize;
  76920. + if (short_read != NULL) {
  76921. + *short_read = (hctsiz.b.xfersize != 0);
  76922. + }
  76923. + } else if (hc->qh->do_split) {
  76924. + //length = split_out_xfersize[hc->hc_num];
  76925. + length = qtd->ssplit_out_xfer_count;
  76926. + } else {
  76927. + length = hc->xfer_len;
  76928. + }
  76929. + } else {
  76930. + /*
  76931. + * Must use the hctsiz.pktcnt field to determine how much data
  76932. + * has been transferred. This field reflects the number of
  76933. + * packets that have been transferred via the USB. This is
  76934. + * always an integral number of packets if the transfer was
  76935. + * halted before its normal completion. (Can't use the
  76936. + * hctsiz.xfersize field because that reflects the number of
  76937. + * bytes transferred via the AHB, not the USB).
  76938. + */
  76939. + length =
  76940. + (hc->start_pkt_count - hctsiz.b.pktcnt) * hc->max_packet;
  76941. + }
  76942. +
  76943. + return length;
  76944. +}
  76945. +
  76946. +/**
  76947. + * Updates the state of the URB after a Transfer Complete interrupt on the
  76948. + * host channel. Updates the actual_length field of the URB based on the
  76949. + * number of bytes transferred via the host channel. Sets the URB status
  76950. + * if the data transfer is finished.
  76951. + *
  76952. + * @return 1 if the data transfer specified by the URB is completely finished,
  76953. + * 0 otherwise.
  76954. + */
  76955. +static int update_urb_state_xfer_comp(dwc_hc_t * hc,
  76956. + dwc_otg_hc_regs_t * hc_regs,
  76957. + dwc_otg_hcd_urb_t * urb,
  76958. + dwc_otg_qtd_t * qtd)
  76959. +{
  76960. + int xfer_done = 0;
  76961. + int short_read = 0;
  76962. +
  76963. + int xfer_length;
  76964. +
  76965. + xfer_length = get_actual_xfer_length(hc, hc_regs, qtd,
  76966. + DWC_OTG_HC_XFER_COMPLETE,
  76967. + &short_read);
  76968. +
  76969. + /* non DWORD-aligned buffer case handling. */
  76970. + if (hc->align_buff && xfer_length && hc->ep_is_in) {
  76971. + dwc_memcpy(urb->buf + urb->actual_length, hc->qh->dw_align_buf,
  76972. + xfer_length);
  76973. + }
  76974. +
  76975. + urb->actual_length += xfer_length;
  76976. +
  76977. + if (xfer_length && (hc->ep_type == DWC_OTG_EP_TYPE_BULK) &&
  76978. + (urb->flags & URB_SEND_ZERO_PACKET)
  76979. + && (urb->actual_length == urb->length)
  76980. + && !(urb->length % hc->max_packet)) {
  76981. + xfer_done = 0;
  76982. + } else if (short_read || urb->actual_length >= urb->length) {
  76983. + xfer_done = 1;
  76984. + urb->status = 0;
  76985. + }
  76986. +
  76987. +#ifdef DEBUG
  76988. + {
  76989. + hctsiz_data_t hctsiz;
  76990. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  76991. + DWC_DEBUGPL(DBG_HCDV, "DWC_otg: %s: %s, channel %d\n",
  76992. + __func__, (hc->ep_is_in ? "IN" : "OUT"),
  76993. + hc->hc_num);
  76994. + DWC_DEBUGPL(DBG_HCDV, " hc->xfer_len %d\n", hc->xfer_len);
  76995. + DWC_DEBUGPL(DBG_HCDV, " hctsiz.xfersize %d\n",
  76996. + hctsiz.b.xfersize);
  76997. + DWC_DEBUGPL(DBG_HCDV, " urb->transfer_buffer_length %d\n",
  76998. + urb->length);
  76999. + DWC_DEBUGPL(DBG_HCDV, " urb->actual_length %d\n",
  77000. + urb->actual_length);
  77001. + DWC_DEBUGPL(DBG_HCDV, " short_read %d, xfer_done %d\n",
  77002. + short_read, xfer_done);
  77003. + }
  77004. +#endif
  77005. +
  77006. + return xfer_done;
  77007. +}
  77008. +
  77009. +/*
  77010. + * Save the starting data toggle for the next transfer. The data toggle is
  77011. + * saved in the QH for non-control transfers and it's saved in the QTD for
  77012. + * control transfers.
  77013. + */
  77014. +void dwc_otg_hcd_save_data_toggle(dwc_hc_t * hc,
  77015. + dwc_otg_hc_regs_t * hc_regs, dwc_otg_qtd_t * qtd)
  77016. +{
  77017. + hctsiz_data_t hctsiz;
  77018. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  77019. +
  77020. + if (hc->ep_type != DWC_OTG_EP_TYPE_CONTROL) {
  77021. + dwc_otg_qh_t *qh = hc->qh;
  77022. + if (hctsiz.b.pid == DWC_HCTSIZ_DATA0) {
  77023. + qh->data_toggle = DWC_OTG_HC_PID_DATA0;
  77024. + } else {
  77025. + qh->data_toggle = DWC_OTG_HC_PID_DATA1;
  77026. + }
  77027. + } else {
  77028. + if (hctsiz.b.pid == DWC_HCTSIZ_DATA0) {
  77029. + qtd->data_toggle = DWC_OTG_HC_PID_DATA0;
  77030. + } else {
  77031. + qtd->data_toggle = DWC_OTG_HC_PID_DATA1;
  77032. + }
  77033. + }
  77034. +}
  77035. +
  77036. +/**
  77037. + * Updates the state of an Isochronous URB when the transfer is stopped for
  77038. + * any reason. The fields of the current entry in the frame descriptor array
  77039. + * are set based on the transfer state and the input _halt_status. Completes
  77040. + * the Isochronous URB if all the URB frames have been completed.
  77041. + *
  77042. + * @return DWC_OTG_HC_XFER_COMPLETE if there are more frames remaining to be
  77043. + * transferred in the URB. Otherwise return DWC_OTG_HC_XFER_URB_COMPLETE.
  77044. + */
  77045. +static dwc_otg_halt_status_e
  77046. +update_isoc_urb_state(dwc_otg_hcd_t * hcd,
  77047. + dwc_hc_t * hc,
  77048. + dwc_otg_hc_regs_t * hc_regs,
  77049. + dwc_otg_qtd_t * qtd, dwc_otg_halt_status_e halt_status)
  77050. +{
  77051. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  77052. + dwc_otg_halt_status_e ret_val = halt_status;
  77053. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  77054. +
  77055. + frame_desc = &urb->iso_descs[qtd->isoc_frame_index];
  77056. + switch (halt_status) {
  77057. + case DWC_OTG_HC_XFER_COMPLETE:
  77058. + frame_desc->status = 0;
  77059. + frame_desc->actual_length =
  77060. + get_actual_xfer_length(hc, hc_regs, qtd, halt_status, NULL);
  77061. +
  77062. + /* non DWORD-aligned buffer case handling. */
  77063. + if (hc->align_buff && frame_desc->actual_length && hc->ep_is_in) {
  77064. + dwc_memcpy(urb->buf + frame_desc->offset + qtd->isoc_split_offset,
  77065. + hc->qh->dw_align_buf, frame_desc->actual_length);
  77066. + }
  77067. +
  77068. + break;
  77069. + case DWC_OTG_HC_XFER_FRAME_OVERRUN:
  77070. + urb->error_count++;
  77071. + if (hc->ep_is_in) {
  77072. + frame_desc->status = -DWC_E_NO_STREAM_RES;
  77073. + } else {
  77074. + frame_desc->status = -DWC_E_COMMUNICATION;
  77075. + }
  77076. + frame_desc->actual_length = 0;
  77077. + break;
  77078. + case DWC_OTG_HC_XFER_BABBLE_ERR:
  77079. + urb->error_count++;
  77080. + frame_desc->status = -DWC_E_OVERFLOW;
  77081. + /* Don't need to update actual_length in this case. */
  77082. + break;
  77083. + case DWC_OTG_HC_XFER_XACT_ERR:
  77084. + urb->error_count++;
  77085. + frame_desc->status = -DWC_E_PROTOCOL;
  77086. + frame_desc->actual_length =
  77087. + get_actual_xfer_length(hc, hc_regs, qtd, halt_status, NULL);
  77088. +
  77089. + /* non DWORD-aligned buffer case handling. */
  77090. + if (hc->align_buff && frame_desc->actual_length && hc->ep_is_in) {
  77091. + dwc_memcpy(urb->buf + frame_desc->offset + qtd->isoc_split_offset,
  77092. + hc->qh->dw_align_buf, frame_desc->actual_length);
  77093. + }
  77094. + /* Skip whole frame */
  77095. + if (hc->qh->do_split && (hc->ep_type == DWC_OTG_EP_TYPE_ISOC) &&
  77096. + hc->ep_is_in && hcd->core_if->dma_enable) {
  77097. + qtd->complete_split = 0;
  77098. + qtd->isoc_split_offset = 0;
  77099. + }
  77100. +
  77101. + break;
  77102. + default:
  77103. + DWC_ASSERT(1, "Unhandled _halt_status (%d)\n", halt_status);
  77104. + break;
  77105. + }
  77106. + if (++qtd->isoc_frame_index == urb->packet_count) {
  77107. + /*
  77108. + * urb->status is not used for isoc transfers.
  77109. + * The individual frame_desc statuses are used instead.
  77110. + */
  77111. + hcd->fops->complete(hcd, urb->priv, urb, 0);
  77112. + ret_val = DWC_OTG_HC_XFER_URB_COMPLETE;
  77113. + } else {
  77114. + ret_val = DWC_OTG_HC_XFER_COMPLETE;
  77115. + }
  77116. + return ret_val;
  77117. +}
  77118. +
  77119. +/**
  77120. + * Frees the first QTD in the QH's list if free_qtd is 1. For non-periodic
  77121. + * QHs, removes the QH from the active non-periodic schedule. If any QTDs are
  77122. + * still linked to the QH, the QH is added to the end of the inactive
  77123. + * non-periodic schedule. For periodic QHs, removes the QH from the periodic
  77124. + * schedule if no more QTDs are linked to the QH.
  77125. + */
  77126. +static void deactivate_qh(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh, int free_qtd)
  77127. +{
  77128. + int continue_split = 0;
  77129. + dwc_otg_qtd_t *qtd;
  77130. +
  77131. + DWC_DEBUGPL(DBG_HCDV, " %s(%p,%p,%d)\n", __func__, hcd, qh, free_qtd);
  77132. +
  77133. + qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  77134. +
  77135. + if (qtd->complete_split) {
  77136. + continue_split = 1;
  77137. + } else if (qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_MID ||
  77138. + qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_END) {
  77139. + continue_split = 1;
  77140. + }
  77141. +
  77142. + if (free_qtd) {
  77143. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  77144. + continue_split = 0;
  77145. + }
  77146. +
  77147. + qh->channel = NULL;
  77148. + dwc_otg_hcd_qh_deactivate(hcd, qh, continue_split);
  77149. +}
  77150. +
  77151. +/**
  77152. + * Releases a host channel for use by other transfers. Attempts to select and
  77153. + * queue more transactions since at least one host channel is available.
  77154. + *
  77155. + * @param hcd The HCD state structure.
  77156. + * @param hc The host channel to release.
  77157. + * @param qtd The QTD associated with the host channel. This QTD may be freed
  77158. + * if the transfer is complete or an error has occurred.
  77159. + * @param halt_status Reason the channel is being released. This status
  77160. + * determines the actions taken by this function.
  77161. + */
  77162. +static void release_channel(dwc_otg_hcd_t * hcd,
  77163. + dwc_hc_t * hc,
  77164. + dwc_otg_qtd_t * qtd,
  77165. + dwc_otg_halt_status_e halt_status)
  77166. +{
  77167. + dwc_otg_transaction_type_e tr_type;
  77168. + int free_qtd;
  77169. + dwc_irqflags_t flags;
  77170. + dwc_spinlock_t *channel_lock = hcd->channel_lock;
  77171. +
  77172. + int hog_port = 0;
  77173. +
  77174. + DWC_DEBUGPL(DBG_HCDV, " %s: channel %d, halt_status %d, xfer_len %d\n",
  77175. + __func__, hc->hc_num, halt_status, hc->xfer_len);
  77176. +
  77177. + if(fiq_fsm_enable && hc->do_split) {
  77178. + if(!hc->ep_is_in && hc->ep_type == UE_ISOCHRONOUS) {
  77179. + if(hc->xact_pos == DWC_HCSPLIT_XACTPOS_MID ||
  77180. + hc->xact_pos == DWC_HCSPLIT_XACTPOS_BEGIN) {
  77181. + hog_port = 0;
  77182. + }
  77183. + }
  77184. + }
  77185. +
  77186. + switch (halt_status) {
  77187. + case DWC_OTG_HC_XFER_URB_COMPLETE:
  77188. + free_qtd = 1;
  77189. + break;
  77190. + case DWC_OTG_HC_XFER_AHB_ERR:
  77191. + case DWC_OTG_HC_XFER_STALL:
  77192. + case DWC_OTG_HC_XFER_BABBLE_ERR:
  77193. + free_qtd = 1;
  77194. + break;
  77195. + case DWC_OTG_HC_XFER_XACT_ERR:
  77196. + if (qtd->error_count >= 3) {
  77197. + DWC_DEBUGPL(DBG_HCDV,
  77198. + " Complete URB with transaction error\n");
  77199. + free_qtd = 1;
  77200. + qtd->urb->status = -DWC_E_PROTOCOL;
  77201. + hcd->fops->complete(hcd, qtd->urb->priv,
  77202. + qtd->urb, -DWC_E_PROTOCOL);
  77203. + } else {
  77204. + free_qtd = 0;
  77205. + }
  77206. + break;
  77207. + case DWC_OTG_HC_XFER_URB_DEQUEUE:
  77208. + /*
  77209. + * The QTD has already been removed and the QH has been
  77210. + * deactivated. Don't want to do anything except release the
  77211. + * host channel and try to queue more transfers.
  77212. + */
  77213. + goto cleanup;
  77214. + case DWC_OTG_HC_XFER_NO_HALT_STATUS:
  77215. + free_qtd = 0;
  77216. + break;
  77217. + case DWC_OTG_HC_XFER_PERIODIC_INCOMPLETE:
  77218. + DWC_DEBUGPL(DBG_HCDV,
  77219. + " Complete URB with I/O error\n");
  77220. + free_qtd = 1;
  77221. + qtd->urb->status = -DWC_E_IO;
  77222. + hcd->fops->complete(hcd, qtd->urb->priv,
  77223. + qtd->urb, -DWC_E_IO);
  77224. + break;
  77225. + default:
  77226. + free_qtd = 0;
  77227. + break;
  77228. + }
  77229. +
  77230. + deactivate_qh(hcd, hc->qh, free_qtd);
  77231. +
  77232. +cleanup:
  77233. + /*
  77234. + * Release the host channel for use by other transfers. The cleanup
  77235. + * function clears the channel interrupt enables and conditions, so
  77236. + * there's no need to clear the Channel Halted interrupt separately.
  77237. + */
  77238. + if (fiq_fsm_enable && hcd->fiq_state->channel[hc->hc_num].fsm != FIQ_PASSTHROUGH)
  77239. + dwc_otg_cleanup_fiq_channel(hcd, hc->hc_num);
  77240. + dwc_otg_hc_cleanup(hcd->core_if, hc);
  77241. + DWC_CIRCLEQ_INSERT_TAIL(&hcd->free_hc_list, hc, hc_list_entry);
  77242. +
  77243. + if (!microframe_schedule) {
  77244. + switch (hc->ep_type) {
  77245. + case DWC_OTG_EP_TYPE_CONTROL:
  77246. + case DWC_OTG_EP_TYPE_BULK:
  77247. + hcd->non_periodic_channels--;
  77248. + break;
  77249. +
  77250. + default:
  77251. + /*
  77252. + * Don't release reservations for periodic channels here.
  77253. + * That's done when a periodic transfer is descheduled (i.e.
  77254. + * when the QH is removed from the periodic schedule).
  77255. + */
  77256. + break;
  77257. + }
  77258. + } else {
  77259. +
  77260. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  77261. + hcd->available_host_channels++;
  77262. + fiq_print(FIQDBG_INT, hcd->fiq_state, "AHC = %d ", hcd->available_host_channels);
  77263. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  77264. + }
  77265. +
  77266. + /* Try to queue more transfers now that there's a free channel. */
  77267. + tr_type = dwc_otg_hcd_select_transactions(hcd);
  77268. + if (tr_type != DWC_OTG_TRANSACTION_NONE) {
  77269. + dwc_otg_hcd_queue_transactions(hcd, tr_type);
  77270. + }
  77271. +}
  77272. +
  77273. +/**
  77274. + * Halts a host channel. If the channel cannot be halted immediately because
  77275. + * the request queue is full, this function ensures that the FIFO empty
  77276. + * interrupt for the appropriate queue is enabled so that the halt request can
  77277. + * be queued when there is space in the request queue.
  77278. + *
  77279. + * This function may also be called in DMA mode. In that case, the channel is
  77280. + * simply released since the core always halts the channel automatically in
  77281. + * DMA mode.
  77282. + */
  77283. +static void halt_channel(dwc_otg_hcd_t * hcd,
  77284. + dwc_hc_t * hc,
  77285. + dwc_otg_qtd_t * qtd, dwc_otg_halt_status_e halt_status)
  77286. +{
  77287. + if (hcd->core_if->dma_enable) {
  77288. + release_channel(hcd, hc, qtd, halt_status);
  77289. + return;
  77290. + }
  77291. +
  77292. + /* Slave mode processing... */
  77293. + dwc_otg_hc_halt(hcd->core_if, hc, halt_status);
  77294. +
  77295. + if (hc->halt_on_queue) {
  77296. + gintmsk_data_t gintmsk = {.d32 = 0 };
  77297. + dwc_otg_core_global_regs_t *global_regs;
  77298. + global_regs = hcd->core_if->core_global_regs;
  77299. +
  77300. + if (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL ||
  77301. + hc->ep_type == DWC_OTG_EP_TYPE_BULK) {
  77302. + /*
  77303. + * Make sure the Non-periodic Tx FIFO empty interrupt
  77304. + * is enabled so that the non-periodic schedule will
  77305. + * be processed.
  77306. + */
  77307. + gintmsk.b.nptxfempty = 1;
  77308. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0, gintmsk.d32);
  77309. + } else {
  77310. + /*
  77311. + * Move the QH from the periodic queued schedule to
  77312. + * the periodic assigned schedule. This allows the
  77313. + * halt to be queued when the periodic schedule is
  77314. + * processed.
  77315. + */
  77316. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_assigned,
  77317. + &hc->qh->qh_list_entry);
  77318. +
  77319. + /*
  77320. + * Make sure the Periodic Tx FIFO Empty interrupt is
  77321. + * enabled so that the periodic schedule will be
  77322. + * processed.
  77323. + */
  77324. + gintmsk.b.ptxfempty = 1;
  77325. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0, gintmsk.d32);
  77326. + }
  77327. + }
  77328. +}
  77329. +
  77330. +/**
  77331. + * Performs common cleanup for non-periodic transfers after a Transfer
  77332. + * Complete interrupt. This function should be called after any endpoint type
  77333. + * specific handling is finished to release the host channel.
  77334. + */
  77335. +static void complete_non_periodic_xfer(dwc_otg_hcd_t * hcd,
  77336. + dwc_hc_t * hc,
  77337. + dwc_otg_hc_regs_t * hc_regs,
  77338. + dwc_otg_qtd_t * qtd,
  77339. + dwc_otg_halt_status_e halt_status)
  77340. +{
  77341. + hcint_data_t hcint;
  77342. +
  77343. + qtd->error_count = 0;
  77344. +
  77345. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  77346. + if (hcint.b.nyet) {
  77347. + /*
  77348. + * Got a NYET on the last transaction of the transfer. This
  77349. + * means that the endpoint should be in the PING state at the
  77350. + * beginning of the next transfer.
  77351. + */
  77352. + hc->qh->ping_state = 1;
  77353. + clear_hc_int(hc_regs, nyet);
  77354. + }
  77355. +
  77356. + /*
  77357. + * Always halt and release the host channel to make it available for
  77358. + * more transfers. There may still be more phases for a control
  77359. + * transfer or more data packets for a bulk transfer at this point,
  77360. + * but the host channel is still halted. A channel will be reassigned
  77361. + * to the transfer when the non-periodic schedule is processed after
  77362. + * the channel is released. This allows transactions to be queued
  77363. + * properly via dwc_otg_hcd_queue_transactions, which also enables the
  77364. + * Tx FIFO Empty interrupt if necessary.
  77365. + */
  77366. + if (hc->ep_is_in) {
  77367. + /*
  77368. + * IN transfers in Slave mode require an explicit disable to
  77369. + * halt the channel. (In DMA mode, this call simply releases
  77370. + * the channel.)
  77371. + */
  77372. + halt_channel(hcd, hc, qtd, halt_status);
  77373. + } else {
  77374. + /*
  77375. + * The channel is automatically disabled by the core for OUT
  77376. + * transfers in Slave mode.
  77377. + */
  77378. + release_channel(hcd, hc, qtd, halt_status);
  77379. + }
  77380. +}
  77381. +
  77382. +/**
  77383. + * Performs common cleanup for periodic transfers after a Transfer Complete
  77384. + * interrupt. This function should be called after any endpoint type specific
  77385. + * handling is finished to release the host channel.
  77386. + */
  77387. +static void complete_periodic_xfer(dwc_otg_hcd_t * hcd,
  77388. + dwc_hc_t * hc,
  77389. + dwc_otg_hc_regs_t * hc_regs,
  77390. + dwc_otg_qtd_t * qtd,
  77391. + dwc_otg_halt_status_e halt_status)
  77392. +{
  77393. + hctsiz_data_t hctsiz;
  77394. + qtd->error_count = 0;
  77395. +
  77396. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  77397. + if (!hc->ep_is_in || hctsiz.b.pktcnt == 0) {
  77398. + /* Core halts channel in these cases. */
  77399. + release_channel(hcd, hc, qtd, halt_status);
  77400. + } else {
  77401. + /* Flush any outstanding requests from the Tx queue. */
  77402. + halt_channel(hcd, hc, qtd, halt_status);
  77403. + }
  77404. +}
  77405. +
  77406. +static int32_t handle_xfercomp_isoc_split_in(dwc_otg_hcd_t * hcd,
  77407. + dwc_hc_t * hc,
  77408. + dwc_otg_hc_regs_t * hc_regs,
  77409. + dwc_otg_qtd_t * qtd)
  77410. +{
  77411. + uint32_t len;
  77412. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  77413. + frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  77414. +
  77415. + len = get_actual_xfer_length(hc, hc_regs, qtd,
  77416. + DWC_OTG_HC_XFER_COMPLETE, NULL);
  77417. +
  77418. + if (!len) {
  77419. + qtd->complete_split = 0;
  77420. + qtd->isoc_split_offset = 0;
  77421. + return 0;
  77422. + }
  77423. + frame_desc->actual_length += len;
  77424. +
  77425. + if (hc->align_buff && len)
  77426. + dwc_memcpy(qtd->urb->buf + frame_desc->offset +
  77427. + qtd->isoc_split_offset, hc->qh->dw_align_buf, len);
  77428. + qtd->isoc_split_offset += len;
  77429. +
  77430. + if (frame_desc->length == frame_desc->actual_length) {
  77431. + frame_desc->status = 0;
  77432. + qtd->isoc_frame_index++;
  77433. + qtd->complete_split = 0;
  77434. + qtd->isoc_split_offset = 0;
  77435. + }
  77436. +
  77437. + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
  77438. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  77439. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  77440. + } else {
  77441. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  77442. + }
  77443. +
  77444. + return 1; /* Indicates that channel released */
  77445. +}
  77446. +
  77447. +/**
  77448. + * Handles a host channel Transfer Complete interrupt. This handler may be
  77449. + * called in either DMA mode or Slave mode.
  77450. + */
  77451. +static int32_t handle_hc_xfercomp_intr(dwc_otg_hcd_t * hcd,
  77452. + dwc_hc_t * hc,
  77453. + dwc_otg_hc_regs_t * hc_regs,
  77454. + dwc_otg_qtd_t * qtd)
  77455. +{
  77456. + int urb_xfer_done;
  77457. + dwc_otg_halt_status_e halt_status = DWC_OTG_HC_XFER_COMPLETE;
  77458. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  77459. + int pipe_type = dwc_otg_hcd_get_pipe_type(&urb->pipe_info);
  77460. +
  77461. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  77462. + "Transfer Complete--\n", hc->hc_num);
  77463. +
  77464. + if (hcd->core_if->dma_desc_enable) {
  77465. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs, halt_status);
  77466. + if (pipe_type == UE_ISOCHRONOUS) {
  77467. + /* Do not disable the interrupt, just clear it */
  77468. + clear_hc_int(hc_regs, xfercomp);
  77469. + return 1;
  77470. + }
  77471. + goto handle_xfercomp_done;
  77472. + }
  77473. +
  77474. + /*
  77475. + * Handle xfer complete on CSPLIT.
  77476. + */
  77477. +
  77478. + if (hc->qh->do_split) {
  77479. + if ((hc->ep_type == DWC_OTG_EP_TYPE_ISOC) && hc->ep_is_in
  77480. + && hcd->core_if->dma_enable) {
  77481. + if (qtd->complete_split
  77482. + && handle_xfercomp_isoc_split_in(hcd, hc, hc_regs,
  77483. + qtd))
  77484. + goto handle_xfercomp_done;
  77485. + } else {
  77486. + qtd->complete_split = 0;
  77487. + }
  77488. + }
  77489. +
  77490. + /* Update the QTD and URB states. */
  77491. + switch (pipe_type) {
  77492. + case UE_CONTROL:
  77493. + switch (qtd->control_phase) {
  77494. + case DWC_OTG_CONTROL_SETUP:
  77495. + if (urb->length > 0) {
  77496. + qtd->control_phase = DWC_OTG_CONTROL_DATA;
  77497. + } else {
  77498. + qtd->control_phase = DWC_OTG_CONTROL_STATUS;
  77499. + }
  77500. + DWC_DEBUGPL(DBG_HCDV,
  77501. + " Control setup transaction done\n");
  77502. + halt_status = DWC_OTG_HC_XFER_COMPLETE;
  77503. + break;
  77504. + case DWC_OTG_CONTROL_DATA:{
  77505. + urb_xfer_done =
  77506. + update_urb_state_xfer_comp(hc, hc_regs, urb,
  77507. + qtd);
  77508. + if (urb_xfer_done) {
  77509. + qtd->control_phase =
  77510. + DWC_OTG_CONTROL_STATUS;
  77511. + DWC_DEBUGPL(DBG_HCDV,
  77512. + " Control data transfer done\n");
  77513. + } else {
  77514. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  77515. + }
  77516. + halt_status = DWC_OTG_HC_XFER_COMPLETE;
  77517. + break;
  77518. + }
  77519. + case DWC_OTG_CONTROL_STATUS:
  77520. + DWC_DEBUGPL(DBG_HCDV, " Control transfer complete\n");
  77521. + if (urb->status == -DWC_E_IN_PROGRESS) {
  77522. + urb->status = 0;
  77523. + }
  77524. + hcd->fops->complete(hcd, urb->priv, urb, urb->status);
  77525. + halt_status = DWC_OTG_HC_XFER_URB_COMPLETE;
  77526. + break;
  77527. + }
  77528. +
  77529. + complete_non_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
  77530. + break;
  77531. + case UE_BULK:
  77532. + DWC_DEBUGPL(DBG_HCDV, " Bulk transfer complete\n");
  77533. + urb_xfer_done =
  77534. + update_urb_state_xfer_comp(hc, hc_regs, urb, qtd);
  77535. + if (urb_xfer_done) {
  77536. + hcd->fops->complete(hcd, urb->priv, urb, urb->status);
  77537. + halt_status = DWC_OTG_HC_XFER_URB_COMPLETE;
  77538. + } else {
  77539. + halt_status = DWC_OTG_HC_XFER_COMPLETE;
  77540. + }
  77541. +
  77542. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  77543. + complete_non_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
  77544. + break;
  77545. + case UE_INTERRUPT:
  77546. + DWC_DEBUGPL(DBG_HCDV, " Interrupt transfer complete\n");
  77547. + urb_xfer_done =
  77548. + update_urb_state_xfer_comp(hc, hc_regs, urb, qtd);
  77549. +
  77550. + /*
  77551. + * Interrupt URB is done on the first transfer complete
  77552. + * interrupt.
  77553. + */
  77554. + if (urb_xfer_done) {
  77555. + hcd->fops->complete(hcd, urb->priv, urb, urb->status);
  77556. + halt_status = DWC_OTG_HC_XFER_URB_COMPLETE;
  77557. + } else {
  77558. + halt_status = DWC_OTG_HC_XFER_COMPLETE;
  77559. + }
  77560. +
  77561. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  77562. + complete_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
  77563. + break;
  77564. + case UE_ISOCHRONOUS:
  77565. + DWC_DEBUGPL(DBG_HCDV, " Isochronous transfer complete\n");
  77566. + if (qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_ALL) {
  77567. + halt_status =
  77568. + update_isoc_urb_state(hcd, hc, hc_regs, qtd,
  77569. + DWC_OTG_HC_XFER_COMPLETE);
  77570. + }
  77571. + complete_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
  77572. + break;
  77573. + }
  77574. +
  77575. +handle_xfercomp_done:
  77576. + disable_hc_int(hc_regs, xfercompl);
  77577. +
  77578. + return 1;
  77579. +}
  77580. +
  77581. +/**
  77582. + * Handles a host channel STALL interrupt. This handler may be called in
  77583. + * either DMA mode or Slave mode.
  77584. + */
  77585. +static int32_t handle_hc_stall_intr(dwc_otg_hcd_t * hcd,
  77586. + dwc_hc_t * hc,
  77587. + dwc_otg_hc_regs_t * hc_regs,
  77588. + dwc_otg_qtd_t * qtd)
  77589. +{
  77590. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  77591. + int pipe_type = dwc_otg_hcd_get_pipe_type(&urb->pipe_info);
  77592. +
  77593. + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
  77594. + "STALL Received--\n", hc->hc_num);
  77595. +
  77596. + if (hcd->core_if->dma_desc_enable) {
  77597. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs, DWC_OTG_HC_XFER_STALL);
  77598. + goto handle_stall_done;
  77599. + }
  77600. +
  77601. + if (pipe_type == UE_CONTROL) {
  77602. + hcd->fops->complete(hcd, urb->priv, urb, -DWC_E_PIPE);
  77603. + }
  77604. +
  77605. + if (pipe_type == UE_BULK || pipe_type == UE_INTERRUPT) {
  77606. + hcd->fops->complete(hcd, urb->priv, urb, -DWC_E_PIPE);
  77607. + /*
  77608. + * USB protocol requires resetting the data toggle for bulk
  77609. + * and interrupt endpoints when a CLEAR_FEATURE(ENDPOINT_HALT)
  77610. + * setup command is issued to the endpoint. Anticipate the
  77611. + * CLEAR_FEATURE command since a STALL has occurred and reset
  77612. + * the data toggle now.
  77613. + */
  77614. + hc->qh->data_toggle = 0;
  77615. + }
  77616. +
  77617. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_STALL);
  77618. +
  77619. +handle_stall_done:
  77620. + disable_hc_int(hc_regs, stall);
  77621. +
  77622. + return 1;
  77623. +}
  77624. +
  77625. +/*
  77626. + * Updates the state of the URB when a transfer has been stopped due to an
  77627. + * abnormal condition before the transfer completes. Modifies the
  77628. + * actual_length field of the URB to reflect the number of bytes that have
  77629. + * actually been transferred via the host channel.
  77630. + */
  77631. +static void update_urb_state_xfer_intr(dwc_hc_t * hc,
  77632. + dwc_otg_hc_regs_t * hc_regs,
  77633. + dwc_otg_hcd_urb_t * urb,
  77634. + dwc_otg_qtd_t * qtd,
  77635. + dwc_otg_halt_status_e halt_status)
  77636. +{
  77637. + uint32_t bytes_transferred = get_actual_xfer_length(hc, hc_regs, qtd,
  77638. + halt_status, NULL);
  77639. + /* non DWORD-aligned buffer case handling. */
  77640. + if (hc->align_buff && bytes_transferred && hc->ep_is_in) {
  77641. + dwc_memcpy(urb->buf + urb->actual_length, hc->qh->dw_align_buf,
  77642. + bytes_transferred);
  77643. + }
  77644. +
  77645. + urb->actual_length += bytes_transferred;
  77646. +
  77647. +#ifdef DEBUG
  77648. + {
  77649. + hctsiz_data_t hctsiz;
  77650. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  77651. + DWC_DEBUGPL(DBG_HCDV, "DWC_otg: %s: %s, channel %d\n",
  77652. + __func__, (hc->ep_is_in ? "IN" : "OUT"),
  77653. + hc->hc_num);
  77654. + DWC_DEBUGPL(DBG_HCDV, " hc->start_pkt_count %d\n",
  77655. + hc->start_pkt_count);
  77656. + DWC_DEBUGPL(DBG_HCDV, " hctsiz.pktcnt %d\n", hctsiz.b.pktcnt);
  77657. + DWC_DEBUGPL(DBG_HCDV, " hc->max_packet %d\n", hc->max_packet);
  77658. + DWC_DEBUGPL(DBG_HCDV, " bytes_transferred %d\n",
  77659. + bytes_transferred);
  77660. + DWC_DEBUGPL(DBG_HCDV, " urb->actual_length %d\n",
  77661. + urb->actual_length);
  77662. + DWC_DEBUGPL(DBG_HCDV, " urb->transfer_buffer_length %d\n",
  77663. + urb->length);
  77664. + }
  77665. +#endif
  77666. +}
  77667. +
  77668. +/**
  77669. + * Handles a host channel NAK interrupt. This handler may be called in either
  77670. + * DMA mode or Slave mode.
  77671. + */
  77672. +static int32_t handle_hc_nak_intr(dwc_otg_hcd_t * hcd,
  77673. + dwc_hc_t * hc,
  77674. + dwc_otg_hc_regs_t * hc_regs,
  77675. + dwc_otg_qtd_t * qtd)
  77676. +{
  77677. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  77678. + "NAK Received--\n", hc->hc_num);
  77679. +
  77680. + /*
  77681. + * When we get bulk NAKs then remember this so we holdoff on this qh until
  77682. + * the beginning of the next frame
  77683. + */
  77684. + switch(dwc_otg_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  77685. + case UE_BULK:
  77686. + case UE_CONTROL:
  77687. + if (nak_holdoff && qtd->qh->do_split)
  77688. + hc->qh->nak_frame = dwc_otg_hcd_get_frame_number(hcd);
  77689. + }
  77690. +
  77691. + /*
  77692. + * Handle NAK for IN/OUT SSPLIT/CSPLIT transfers, bulk, control, and
  77693. + * interrupt. Re-start the SSPLIT transfer.
  77694. + */
  77695. + if (hc->do_split) {
  77696. + if (hc->complete_split) {
  77697. + qtd->error_count = 0;
  77698. + }
  77699. + qtd->complete_split = 0;
  77700. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NAK);
  77701. + goto handle_nak_done;
  77702. + }
  77703. +
  77704. + switch (dwc_otg_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  77705. + case UE_CONTROL:
  77706. + case UE_BULK:
  77707. + if (hcd->core_if->dma_enable && hc->ep_is_in) {
  77708. + /*
  77709. + * NAK interrupts are enabled on bulk/control IN
  77710. + * transfers in DMA mode for the sole purpose of
  77711. + * resetting the error count after a transaction error
  77712. + * occurs. The core will continue transferring data.
  77713. + * Disable other interrupts unmasked for the same
  77714. + * reason.
  77715. + */
  77716. + disable_hc_int(hc_regs, datatglerr);
  77717. + disable_hc_int(hc_regs, ack);
  77718. + qtd->error_count = 0;
  77719. + goto handle_nak_done;
  77720. + }
  77721. +
  77722. + /*
  77723. + * NAK interrupts normally occur during OUT transfers in DMA
  77724. + * or Slave mode. For IN transfers, more requests will be
  77725. + * queued as request queue space is available.
  77726. + */
  77727. + qtd->error_count = 0;
  77728. +
  77729. + if (!hc->qh->ping_state) {
  77730. + update_urb_state_xfer_intr(hc, hc_regs,
  77731. + qtd->urb, qtd,
  77732. + DWC_OTG_HC_XFER_NAK);
  77733. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  77734. +
  77735. + if (hc->speed == DWC_OTG_EP_SPEED_HIGH)
  77736. + hc->qh->ping_state = 1;
  77737. + }
  77738. +
  77739. + /*
  77740. + * Halt the channel so the transfer can be re-started from
  77741. + * the appropriate point or the PING protocol will
  77742. + * start/continue.
  77743. + */
  77744. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NAK);
  77745. + break;
  77746. + case UE_INTERRUPT:
  77747. + qtd->error_count = 0;
  77748. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NAK);
  77749. + break;
  77750. + case UE_ISOCHRONOUS:
  77751. + /* Should never get called for isochronous transfers. */
  77752. + DWC_ASSERT(1, "NACK interrupt for ISOC transfer\n");
  77753. + break;
  77754. + }
  77755. +
  77756. +handle_nak_done:
  77757. + disable_hc_int(hc_regs, nak);
  77758. +
  77759. + return 1;
  77760. +}
  77761. +
  77762. +/**
  77763. + * Handles a host channel ACK interrupt. This interrupt is enabled when
  77764. + * performing the PING protocol in Slave mode, when errors occur during
  77765. + * either Slave mode or DMA mode, and during Start Split transactions.
  77766. + */
  77767. +static int32_t handle_hc_ack_intr(dwc_otg_hcd_t * hcd,
  77768. + dwc_hc_t * hc,
  77769. + dwc_otg_hc_regs_t * hc_regs,
  77770. + dwc_otg_qtd_t * qtd)
  77771. +{
  77772. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  77773. + "ACK Received--\n", hc->hc_num);
  77774. +
  77775. + if (hc->do_split) {
  77776. + /*
  77777. + * Handle ACK on SSPLIT.
  77778. + * ACK should not occur in CSPLIT.
  77779. + */
  77780. + if (!hc->ep_is_in && hc->data_pid_start != DWC_OTG_HC_PID_SETUP) {
  77781. + qtd->ssplit_out_xfer_count = hc->xfer_len;
  77782. + }
  77783. + if (!(hc->ep_type == DWC_OTG_EP_TYPE_ISOC && !hc->ep_is_in)) {
  77784. + /* Don't need complete for isochronous out transfers. */
  77785. + qtd->complete_split = 1;
  77786. + }
  77787. +
  77788. + /* ISOC OUT */
  77789. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC && !hc->ep_is_in) {
  77790. + switch (hc->xact_pos) {
  77791. + case DWC_HCSPLIT_XACTPOS_ALL:
  77792. + break;
  77793. + case DWC_HCSPLIT_XACTPOS_END:
  77794. + qtd->isoc_split_pos = DWC_HCSPLIT_XACTPOS_ALL;
  77795. + qtd->isoc_split_offset = 0;
  77796. + break;
  77797. + case DWC_HCSPLIT_XACTPOS_BEGIN:
  77798. + case DWC_HCSPLIT_XACTPOS_MID:
  77799. + /*
  77800. + * For BEGIN or MID, calculate the length for
  77801. + * the next microframe to determine the correct
  77802. + * SSPLIT token, either MID or END.
  77803. + */
  77804. + {
  77805. + struct dwc_otg_hcd_iso_packet_desc
  77806. + *frame_desc;
  77807. +
  77808. + frame_desc =
  77809. + &qtd->urb->
  77810. + iso_descs[qtd->isoc_frame_index];
  77811. + qtd->isoc_split_offset += 188;
  77812. +
  77813. + if ((frame_desc->length -
  77814. + qtd->isoc_split_offset) <= 188) {
  77815. + qtd->isoc_split_pos =
  77816. + DWC_HCSPLIT_XACTPOS_END;
  77817. + } else {
  77818. + qtd->isoc_split_pos =
  77819. + DWC_HCSPLIT_XACTPOS_MID;
  77820. + }
  77821. +
  77822. + }
  77823. + break;
  77824. + }
  77825. + } else {
  77826. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_ACK);
  77827. + }
  77828. + } else {
  77829. + /*
  77830. + * An unmasked ACK on a non-split DMA transaction is
  77831. + * for the sole purpose of resetting error counts. Disable other
  77832. + * interrupts unmasked for the same reason.
  77833. + */
  77834. + if(hcd->core_if->dma_enable) {
  77835. + disable_hc_int(hc_regs, datatglerr);
  77836. + disable_hc_int(hc_regs, nak);
  77837. + }
  77838. + qtd->error_count = 0;
  77839. +
  77840. + if (hc->qh->ping_state) {
  77841. + hc->qh->ping_state = 0;
  77842. + /*
  77843. + * Halt the channel so the transfer can be re-started
  77844. + * from the appropriate point. This only happens in
  77845. + * Slave mode. In DMA mode, the ping_state is cleared
  77846. + * when the transfer is started because the core
  77847. + * automatically executes the PING, then the transfer.
  77848. + */
  77849. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_ACK);
  77850. + }
  77851. + }
  77852. +
  77853. + /*
  77854. + * If the ACK occurred when _not_ in the PING state, let the channel
  77855. + * continue transferring data after clearing the error count.
  77856. + */
  77857. +
  77858. + disable_hc_int(hc_regs, ack);
  77859. +
  77860. + return 1;
  77861. +}
  77862. +
  77863. +/**
  77864. + * Handles a host channel NYET interrupt. This interrupt should only occur on
  77865. + * Bulk and Control OUT endpoints and for complete split transactions. If a
  77866. + * NYET occurs at the same time as a Transfer Complete interrupt, it is
  77867. + * handled in the xfercomp interrupt handler, not here. This handler may be
  77868. + * called in either DMA mode or Slave mode.
  77869. + */
  77870. +static int32_t handle_hc_nyet_intr(dwc_otg_hcd_t * hcd,
  77871. + dwc_hc_t * hc,
  77872. + dwc_otg_hc_regs_t * hc_regs,
  77873. + dwc_otg_qtd_t * qtd)
  77874. +{
  77875. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  77876. + "NYET Received--\n", hc->hc_num);
  77877. +
  77878. + /*
  77879. + * NYET on CSPLIT
  77880. + * re-do the CSPLIT immediately on non-periodic
  77881. + */
  77882. + if (hc->do_split && hc->complete_split) {
  77883. + if (hc->ep_is_in && (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)
  77884. + && hcd->core_if->dma_enable) {
  77885. + qtd->complete_split = 0;
  77886. + qtd->isoc_split_offset = 0;
  77887. + if (++qtd->isoc_frame_index == qtd->urb->packet_count) {
  77888. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  77889. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  77890. + }
  77891. + else
  77892. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  77893. + goto handle_nyet_done;
  77894. + }
  77895. +
  77896. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  77897. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  77898. + int frnum = dwc_otg_hcd_get_frame_number(hcd);
  77899. +
  77900. + // With the FIQ running we only ever see the failed NYET
  77901. + if (dwc_full_frame_num(frnum) !=
  77902. + dwc_full_frame_num(hc->qh->sched_frame) ||
  77903. + fiq_fsm_enable) {
  77904. + /*
  77905. + * No longer in the same full speed frame.
  77906. + * Treat this as a transaction error.
  77907. + */
  77908. +#if 0
  77909. + /** @todo Fix system performance so this can
  77910. + * be treated as an error. Right now complete
  77911. + * splits cannot be scheduled precisely enough
  77912. + * due to other system activity, so this error
  77913. + * occurs regularly in Slave mode.
  77914. + */
  77915. + qtd->error_count++;
  77916. +#endif
  77917. + qtd->complete_split = 0;
  77918. + halt_channel(hcd, hc, qtd,
  77919. + DWC_OTG_HC_XFER_XACT_ERR);
  77920. + /** @todo add support for isoc release */
  77921. + goto handle_nyet_done;
  77922. + }
  77923. + }
  77924. +
  77925. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NYET);
  77926. + goto handle_nyet_done;
  77927. + }
  77928. +
  77929. + hc->qh->ping_state = 1;
  77930. + qtd->error_count = 0;
  77931. +
  77932. + update_urb_state_xfer_intr(hc, hc_regs, qtd->urb, qtd,
  77933. + DWC_OTG_HC_XFER_NYET);
  77934. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  77935. +
  77936. + /*
  77937. + * Halt the channel and re-start the transfer so the PING
  77938. + * protocol will start.
  77939. + */
  77940. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NYET);
  77941. +
  77942. +handle_nyet_done:
  77943. + disable_hc_int(hc_regs, nyet);
  77944. + return 1;
  77945. +}
  77946. +
  77947. +/**
  77948. + * Handles a host channel babble interrupt. This handler may be called in
  77949. + * either DMA mode or Slave mode.
  77950. + */
  77951. +static int32_t handle_hc_babble_intr(dwc_otg_hcd_t * hcd,
  77952. + dwc_hc_t * hc,
  77953. + dwc_otg_hc_regs_t * hc_regs,
  77954. + dwc_otg_qtd_t * qtd)
  77955. +{
  77956. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  77957. + "Babble Error--\n", hc->hc_num);
  77958. +
  77959. + if (hcd->core_if->dma_desc_enable) {
  77960. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs,
  77961. + DWC_OTG_HC_XFER_BABBLE_ERR);
  77962. + goto handle_babble_done;
  77963. + }
  77964. +
  77965. + if (hc->ep_type != DWC_OTG_EP_TYPE_ISOC) {
  77966. + hcd->fops->complete(hcd, qtd->urb->priv,
  77967. + qtd->urb, -DWC_E_OVERFLOW);
  77968. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_BABBLE_ERR);
  77969. + } else {
  77970. + dwc_otg_halt_status_e halt_status;
  77971. + halt_status = update_isoc_urb_state(hcd, hc, hc_regs, qtd,
  77972. + DWC_OTG_HC_XFER_BABBLE_ERR);
  77973. + halt_channel(hcd, hc, qtd, halt_status);
  77974. + }
  77975. +
  77976. +handle_babble_done:
  77977. + disable_hc_int(hc_regs, bblerr);
  77978. + return 1;
  77979. +}
  77980. +
  77981. +/**
  77982. + * Handles a host channel AHB error interrupt. This handler is only called in
  77983. + * DMA mode.
  77984. + */
  77985. +static int32_t handle_hc_ahberr_intr(dwc_otg_hcd_t * hcd,
  77986. + dwc_hc_t * hc,
  77987. + dwc_otg_hc_regs_t * hc_regs,
  77988. + dwc_otg_qtd_t * qtd)
  77989. +{
  77990. + hcchar_data_t hcchar;
  77991. + hcsplt_data_t hcsplt;
  77992. + hctsiz_data_t hctsiz;
  77993. + uint32_t hcdma;
  77994. + char *pipetype, *speed;
  77995. +
  77996. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  77997. +
  77998. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  77999. + "AHB Error--\n", hc->hc_num);
  78000. +
  78001. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  78002. + hcsplt.d32 = DWC_READ_REG32(&hc_regs->hcsplt);
  78003. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  78004. + hcdma = DWC_READ_REG32(&hc_regs->hcdma);
  78005. +
  78006. + DWC_ERROR("AHB ERROR, Channel %d\n", hc->hc_num);
  78007. + DWC_ERROR(" hcchar 0x%08x, hcsplt 0x%08x\n", hcchar.d32, hcsplt.d32);
  78008. + DWC_ERROR(" hctsiz 0x%08x, hcdma 0x%08x\n", hctsiz.d32, hcdma);
  78009. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Enqueue\n");
  78010. + DWC_ERROR(" Device address: %d\n",
  78011. + dwc_otg_hcd_get_dev_addr(&urb->pipe_info));
  78012. + DWC_ERROR(" Endpoint: %d, %s\n",
  78013. + dwc_otg_hcd_get_ep_num(&urb->pipe_info),
  78014. + (dwc_otg_hcd_is_pipe_in(&urb->pipe_info) ? "IN" : "OUT"));
  78015. +
  78016. + switch (dwc_otg_hcd_get_pipe_type(&urb->pipe_info)) {
  78017. + case UE_CONTROL:
  78018. + pipetype = "CONTROL";
  78019. + break;
  78020. + case UE_BULK:
  78021. + pipetype = "BULK";
  78022. + break;
  78023. + case UE_INTERRUPT:
  78024. + pipetype = "INTERRUPT";
  78025. + break;
  78026. + case UE_ISOCHRONOUS:
  78027. + pipetype = "ISOCHRONOUS";
  78028. + break;
  78029. + default:
  78030. + pipetype = "UNKNOWN";
  78031. + break;
  78032. + }
  78033. +
  78034. + DWC_ERROR(" Endpoint type: %s\n", pipetype);
  78035. +
  78036. + switch (hc->speed) {
  78037. + case DWC_OTG_EP_SPEED_HIGH:
  78038. + speed = "HIGH";
  78039. + break;
  78040. + case DWC_OTG_EP_SPEED_FULL:
  78041. + speed = "FULL";
  78042. + break;
  78043. + case DWC_OTG_EP_SPEED_LOW:
  78044. + speed = "LOW";
  78045. + break;
  78046. + default:
  78047. + speed = "UNKNOWN";
  78048. + break;
  78049. + };
  78050. +
  78051. + DWC_ERROR(" Speed: %s\n", speed);
  78052. +
  78053. + DWC_ERROR(" Max packet size: %d\n",
  78054. + dwc_otg_hcd_get_mps(&urb->pipe_info));
  78055. + DWC_ERROR(" Data buffer length: %d\n", urb->length);
  78056. + DWC_ERROR(" Transfer buffer: %p, Transfer DMA: %p\n",
  78057. + urb->buf, (void *)urb->dma);
  78058. + DWC_ERROR(" Setup buffer: %p, Setup DMA: %p\n",
  78059. + urb->setup_packet, (void *)urb->setup_dma);
  78060. + DWC_ERROR(" Interval: %d\n", urb->interval);
  78061. +
  78062. + /* Core haltes the channel for Descriptor DMA mode */
  78063. + if (hcd->core_if->dma_desc_enable) {
  78064. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs,
  78065. + DWC_OTG_HC_XFER_AHB_ERR);
  78066. + goto handle_ahberr_done;
  78067. + }
  78068. +
  78069. + hcd->fops->complete(hcd, urb->priv, urb, -DWC_E_IO);
  78070. +
  78071. + /*
  78072. + * Force a channel halt. Don't call halt_channel because that won't
  78073. + * write to the HCCHARn register in DMA mode to force the halt.
  78074. + */
  78075. + dwc_otg_hc_halt(hcd->core_if, hc, DWC_OTG_HC_XFER_AHB_ERR);
  78076. +handle_ahberr_done:
  78077. + disable_hc_int(hc_regs, ahberr);
  78078. + return 1;
  78079. +}
  78080. +
  78081. +/**
  78082. + * Handles a host channel transaction error interrupt. This handler may be
  78083. + * called in either DMA mode or Slave mode.
  78084. + */
  78085. +static int32_t handle_hc_xacterr_intr(dwc_otg_hcd_t * hcd,
  78086. + dwc_hc_t * hc,
  78087. + dwc_otg_hc_regs_t * hc_regs,
  78088. + dwc_otg_qtd_t * qtd)
  78089. +{
  78090. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  78091. + "Transaction Error--\n", hc->hc_num);
  78092. +
  78093. + if (hcd->core_if->dma_desc_enable) {
  78094. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs,
  78095. + DWC_OTG_HC_XFER_XACT_ERR);
  78096. + goto handle_xacterr_done;
  78097. + }
  78098. +
  78099. + switch (dwc_otg_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  78100. + case UE_CONTROL:
  78101. + case UE_BULK:
  78102. + qtd->error_count++;
  78103. + if (!hc->qh->ping_state) {
  78104. +
  78105. + update_urb_state_xfer_intr(hc, hc_regs,
  78106. + qtd->urb, qtd,
  78107. + DWC_OTG_HC_XFER_XACT_ERR);
  78108. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  78109. + if (!hc->ep_is_in && hc->speed == DWC_OTG_EP_SPEED_HIGH) {
  78110. + hc->qh->ping_state = 1;
  78111. + }
  78112. + }
  78113. +
  78114. + /*
  78115. + * Halt the channel so the transfer can be re-started from
  78116. + * the appropriate point or the PING protocol will start.
  78117. + */
  78118. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  78119. + break;
  78120. + case UE_INTERRUPT:
  78121. + qtd->error_count++;
  78122. + if (hc->do_split && hc->complete_split) {
  78123. + qtd->complete_split = 0;
  78124. + }
  78125. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  78126. + break;
  78127. + case UE_ISOCHRONOUS:
  78128. + {
  78129. + dwc_otg_halt_status_e halt_status;
  78130. + halt_status =
  78131. + update_isoc_urb_state(hcd, hc, hc_regs, qtd,
  78132. + DWC_OTG_HC_XFER_XACT_ERR);
  78133. +
  78134. + halt_channel(hcd, hc, qtd, halt_status);
  78135. + }
  78136. + break;
  78137. + }
  78138. +handle_xacterr_done:
  78139. + disable_hc_int(hc_regs, xacterr);
  78140. +
  78141. + return 1;
  78142. +}
  78143. +
  78144. +/**
  78145. + * Handles a host channel frame overrun interrupt. This handler may be called
  78146. + * in either DMA mode or Slave mode.
  78147. + */
  78148. +static int32_t handle_hc_frmovrun_intr(dwc_otg_hcd_t * hcd,
  78149. + dwc_hc_t * hc,
  78150. + dwc_otg_hc_regs_t * hc_regs,
  78151. + dwc_otg_qtd_t * qtd)
  78152. +{
  78153. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  78154. + "Frame Overrun--\n", hc->hc_num);
  78155. +
  78156. + switch (dwc_otg_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  78157. + case UE_CONTROL:
  78158. + case UE_BULK:
  78159. + break;
  78160. + case UE_INTERRUPT:
  78161. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_FRAME_OVERRUN);
  78162. + break;
  78163. + case UE_ISOCHRONOUS:
  78164. + {
  78165. + dwc_otg_halt_status_e halt_status;
  78166. + halt_status =
  78167. + update_isoc_urb_state(hcd, hc, hc_regs, qtd,
  78168. + DWC_OTG_HC_XFER_FRAME_OVERRUN);
  78169. +
  78170. + halt_channel(hcd, hc, qtd, halt_status);
  78171. + }
  78172. + break;
  78173. + }
  78174. +
  78175. + disable_hc_int(hc_regs, frmovrun);
  78176. +
  78177. + return 1;
  78178. +}
  78179. +
  78180. +/**
  78181. + * Handles a host channel data toggle error interrupt. This handler may be
  78182. + * called in either DMA mode or Slave mode.
  78183. + */
  78184. +static int32_t handle_hc_datatglerr_intr(dwc_otg_hcd_t * hcd,
  78185. + dwc_hc_t * hc,
  78186. + dwc_otg_hc_regs_t * hc_regs,
  78187. + dwc_otg_qtd_t * qtd)
  78188. +{
  78189. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  78190. + "Data Toggle Error on %s transfer--\n",
  78191. + hc->hc_num, (hc->ep_is_in ? "IN" : "OUT"));
  78192. +
  78193. + /* Data toggles on split transactions cause the hc to halt.
  78194. + * restart transfer */
  78195. + if(hc->qh->do_split)
  78196. + {
  78197. + qtd->error_count++;
  78198. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  78199. + update_urb_state_xfer_intr(hc, hc_regs,
  78200. + qtd->urb, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  78201. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  78202. + } else if (hc->ep_is_in) {
  78203. + /* An unmasked data toggle error on a non-split DMA transaction is
  78204. + * for the sole purpose of resetting error counts. Disable other
  78205. + * interrupts unmasked for the same reason.
  78206. + */
  78207. + if(hcd->core_if->dma_enable) {
  78208. + disable_hc_int(hc_regs, ack);
  78209. + disable_hc_int(hc_regs, nak);
  78210. + }
  78211. + qtd->error_count = 0;
  78212. + }
  78213. +
  78214. + disable_hc_int(hc_regs, datatglerr);
  78215. +
  78216. + return 1;
  78217. +}
  78218. +
  78219. +#ifdef DEBUG
  78220. +/**
  78221. + * This function is for debug only. It checks that a valid halt status is set
  78222. + * and that HCCHARn.chdis is clear. If there's a problem, corrective action is
  78223. + * taken and a warning is issued.
  78224. + * @return 1 if halt status is ok, 0 otherwise.
  78225. + */
  78226. +static inline int halt_status_ok(dwc_otg_hcd_t * hcd,
  78227. + dwc_hc_t * hc,
  78228. + dwc_otg_hc_regs_t * hc_regs,
  78229. + dwc_otg_qtd_t * qtd)
  78230. +{
  78231. + hcchar_data_t hcchar;
  78232. + hctsiz_data_t hctsiz;
  78233. + hcint_data_t hcint;
  78234. + hcintmsk_data_t hcintmsk;
  78235. + hcsplt_data_t hcsplt;
  78236. +
  78237. + if (hc->halt_status == DWC_OTG_HC_XFER_NO_HALT_STATUS) {
  78238. + /*
  78239. + * This code is here only as a check. This condition should
  78240. + * never happen. Ignore the halt if it does occur.
  78241. + */
  78242. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  78243. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  78244. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  78245. + hcintmsk.d32 = DWC_READ_REG32(&hc_regs->hcintmsk);
  78246. + hcsplt.d32 = DWC_READ_REG32(&hc_regs->hcsplt);
  78247. + DWC_WARN
  78248. + ("%s: hc->halt_status == DWC_OTG_HC_XFER_NO_HALT_STATUS, "
  78249. + "channel %d, hcchar 0x%08x, hctsiz 0x%08x, "
  78250. + "hcint 0x%08x, hcintmsk 0x%08x, "
  78251. + "hcsplt 0x%08x, qtd->complete_split %d\n", __func__,
  78252. + hc->hc_num, hcchar.d32, hctsiz.d32, hcint.d32,
  78253. + hcintmsk.d32, hcsplt.d32, qtd->complete_split);
  78254. +
  78255. + DWC_WARN("%s: no halt status, channel %d, ignoring interrupt\n",
  78256. + __func__, hc->hc_num);
  78257. + DWC_WARN("\n");
  78258. + clear_hc_int(hc_regs, chhltd);
  78259. + return 0;
  78260. + }
  78261. +
  78262. + /*
  78263. + * This code is here only as a check. hcchar.chdis should
  78264. + * never be set when the halt interrupt occurs. Halt the
  78265. + * channel again if it does occur.
  78266. + */
  78267. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  78268. + if (hcchar.b.chdis) {
  78269. + DWC_WARN("%s: hcchar.chdis set unexpectedly, "
  78270. + "hcchar 0x%08x, trying to halt again\n",
  78271. + __func__, hcchar.d32);
  78272. + clear_hc_int(hc_regs, chhltd);
  78273. + hc->halt_pending = 0;
  78274. + halt_channel(hcd, hc, qtd, hc->halt_status);
  78275. + return 0;
  78276. + }
  78277. +
  78278. + return 1;
  78279. +}
  78280. +#endif
  78281. +
  78282. +/**
  78283. + * Handles a host Channel Halted interrupt in DMA mode. This handler
  78284. + * determines the reason the channel halted and proceeds accordingly.
  78285. + */
  78286. +static void handle_hc_chhltd_intr_dma(dwc_otg_hcd_t * hcd,
  78287. + dwc_hc_t * hc,
  78288. + dwc_otg_hc_regs_t * hc_regs,
  78289. + dwc_otg_qtd_t * qtd)
  78290. +{
  78291. + int out_nak_enh = 0;
  78292. + hcint_data_t hcint;
  78293. + hcintmsk_data_t hcintmsk;
  78294. + /* For core with OUT NAK enhancement, the flow for high-
  78295. + * speed CONTROL/BULK OUT is handled a little differently.
  78296. + */
  78297. + if (hcd->core_if->snpsid >= OTG_CORE_REV_2_71a) {
  78298. + if (hc->speed == DWC_OTG_EP_SPEED_HIGH && !hc->ep_is_in &&
  78299. + (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL ||
  78300. + hc->ep_type == DWC_OTG_EP_TYPE_BULK)) {
  78301. + out_nak_enh = 1;
  78302. + }
  78303. + }
  78304. +
  78305. + if (hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE ||
  78306. + (hc->halt_status == DWC_OTG_HC_XFER_AHB_ERR
  78307. + && !hcd->core_if->dma_desc_enable)) {
  78308. + /*
  78309. + * Just release the channel. A dequeue can happen on a
  78310. + * transfer timeout. In the case of an AHB Error, the channel
  78311. + * was forced to halt because there's no way to gracefully
  78312. + * recover.
  78313. + */
  78314. + if (hcd->core_if->dma_desc_enable)
  78315. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs,
  78316. + hc->halt_status);
  78317. + else
  78318. + release_channel(hcd, hc, qtd, hc->halt_status);
  78319. + return;
  78320. + }
  78321. +
  78322. + /* Read the HCINTn register to determine the cause for the halt. */
  78323. +
  78324. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  78325. + hcintmsk.d32 = DWC_READ_REG32(&hc_regs->hcintmsk);
  78326. +
  78327. + if (hcint.b.xfercomp) {
  78328. + /** @todo This is here because of a possible hardware bug. Spec
  78329. + * says that on SPLIT-ISOC OUT transfers in DMA mode that a HALT
  78330. + * interrupt w/ACK bit set should occur, but I only see the
  78331. + * XFERCOMP bit, even with it masked out. This is a workaround
  78332. + * for that behavior. Should fix this when hardware is fixed.
  78333. + */
  78334. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC && !hc->ep_is_in) {
  78335. + handle_hc_ack_intr(hcd, hc, hc_regs, qtd);
  78336. + }
  78337. + handle_hc_xfercomp_intr(hcd, hc, hc_regs, qtd);
  78338. + } else if (hcint.b.stall) {
  78339. + handle_hc_stall_intr(hcd, hc, hc_regs, qtd);
  78340. + } else if (hcint.b.xacterr && !hcd->core_if->dma_desc_enable) {
  78341. + if (out_nak_enh) {
  78342. + if (hcint.b.nyet || hcint.b.nak || hcint.b.ack) {
  78343. + DWC_DEBUGPL(DBG_HCD, "XactErr with NYET/NAK/ACK\n");
  78344. + qtd->error_count = 0;
  78345. + } else {
  78346. + DWC_DEBUGPL(DBG_HCD, "XactErr without NYET/NAK/ACK\n");
  78347. + }
  78348. + }
  78349. +
  78350. + /*
  78351. + * Must handle xacterr before nak or ack. Could get a xacterr
  78352. + * at the same time as either of these on a BULK/CONTROL OUT
  78353. + * that started with a PING. The xacterr takes precedence.
  78354. + */
  78355. + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
  78356. + } else if (hcint.b.xcs_xact && hcd->core_if->dma_desc_enable) {
  78357. + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
  78358. + } else if (hcint.b.ahberr && hcd->core_if->dma_desc_enable) {
  78359. + handle_hc_ahberr_intr(hcd, hc, hc_regs, qtd);
  78360. + } else if (hcint.b.bblerr) {
  78361. + handle_hc_babble_intr(hcd, hc, hc_regs, qtd);
  78362. + } else if (hcint.b.frmovrun) {
  78363. + handle_hc_frmovrun_intr(hcd, hc, hc_regs, qtd);
  78364. + } else if (hcint.b.datatglerr) {
  78365. + handle_hc_datatglerr_intr(hcd, hc, hc_regs, qtd);
  78366. + } else if (!out_nak_enh) {
  78367. + if (hcint.b.nyet) {
  78368. + /*
  78369. + * Must handle nyet before nak or ack. Could get a nyet at the
  78370. + * same time as either of those on a BULK/CONTROL OUT that
  78371. + * started with a PING. The nyet takes precedence.
  78372. + */
  78373. + handle_hc_nyet_intr(hcd, hc, hc_regs, qtd);
  78374. + } else if (hcint.b.nak && !hcintmsk.b.nak) {
  78375. + /*
  78376. + * If nak is not masked, it's because a non-split IN transfer
  78377. + * is in an error state. In that case, the nak is handled by
  78378. + * the nak interrupt handler, not here. Handle nak here for
  78379. + * BULK/CONTROL OUT transfers, which halt on a NAK to allow
  78380. + * rewinding the buffer pointer.
  78381. + */
  78382. + handle_hc_nak_intr(hcd, hc, hc_regs, qtd);
  78383. + } else if (hcint.b.ack && !hcintmsk.b.ack) {
  78384. + /*
  78385. + * If ack is not masked, it's because a non-split IN transfer
  78386. + * is in an error state. In that case, the ack is handled by
  78387. + * the ack interrupt handler, not here. Handle ack here for
  78388. + * split transfers. Start splits halt on ACK.
  78389. + */
  78390. + handle_hc_ack_intr(hcd, hc, hc_regs, qtd);
  78391. + } else {
  78392. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  78393. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  78394. + /*
  78395. + * A periodic transfer halted with no other channel
  78396. + * interrupts set. Assume it was halted by the core
  78397. + * because it could not be completed in its scheduled
  78398. + * (micro)frame.
  78399. + */
  78400. +#ifdef DEBUG
  78401. + DWC_PRINTF
  78402. + ("%s: Halt channel %d (assume incomplete periodic transfer)\n",
  78403. + __func__, hc->hc_num);
  78404. +#endif
  78405. + halt_channel(hcd, hc, qtd,
  78406. + DWC_OTG_HC_XFER_PERIODIC_INCOMPLETE);
  78407. + } else {
  78408. + DWC_ERROR
  78409. + ("%s: Channel %d, DMA Mode -- ChHltd set, but reason "
  78410. + "for halting is unknown, hcint 0x%08x, intsts 0x%08x\n",
  78411. + __func__, hc->hc_num, hcint.d32,
  78412. + DWC_READ_REG32(&hcd->
  78413. + core_if->core_global_regs->
  78414. + gintsts));
  78415. + /* Failthrough: use 3-strikes rule */
  78416. + qtd->error_count++;
  78417. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  78418. + update_urb_state_xfer_intr(hc, hc_regs,
  78419. + qtd->urb, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  78420. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  78421. + }
  78422. +
  78423. + }
  78424. + } else {
  78425. + DWC_PRINTF("NYET/NAK/ACK/other in non-error case, 0x%08x\n",
  78426. + hcint.d32);
  78427. + /* Failthrough: use 3-strikes rule */
  78428. + qtd->error_count++;
  78429. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  78430. + update_urb_state_xfer_intr(hc, hc_regs,
  78431. + qtd->urb, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  78432. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  78433. + }
  78434. +}
  78435. +
  78436. +/**
  78437. + * Handles a host channel Channel Halted interrupt.
  78438. + *
  78439. + * In slave mode, this handler is called only when the driver specifically
  78440. + * requests a halt. This occurs during handling other host channel interrupts
  78441. + * (e.g. nak, xacterr, stall, nyet, etc.).
  78442. + *
  78443. + * In DMA mode, this is the interrupt that occurs when the core has finished
  78444. + * processing a transfer on a channel. Other host channel interrupts (except
  78445. + * ahberr) are disabled in DMA mode.
  78446. + */
  78447. +static int32_t handle_hc_chhltd_intr(dwc_otg_hcd_t * hcd,
  78448. + dwc_hc_t * hc,
  78449. + dwc_otg_hc_regs_t * hc_regs,
  78450. + dwc_otg_qtd_t * qtd)
  78451. +{
  78452. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  78453. + "Channel Halted--\n", hc->hc_num);
  78454. +
  78455. + if (hcd->core_if->dma_enable) {
  78456. + handle_hc_chhltd_intr_dma(hcd, hc, hc_regs, qtd);
  78457. + } else {
  78458. +#ifdef DEBUG
  78459. + if (!halt_status_ok(hcd, hc, hc_regs, qtd)) {
  78460. + return 1;
  78461. + }
  78462. +#endif
  78463. + release_channel(hcd, hc, qtd, hc->halt_status);
  78464. + }
  78465. +
  78466. + return 1;
  78467. +}
  78468. +
  78469. +
  78470. +/**
  78471. + * dwc_otg_fiq_unmangle_isoc() - Update the iso_frame_desc structure on
  78472. + * FIQ transfer completion
  78473. + * @hcd: Pointer to dwc_otg_hcd struct
  78474. + * @num: Host channel number
  78475. + *
  78476. + * 1. Un-mangle the status as recorded in each iso_frame_desc status
  78477. + * 2. Copy it from the dwc_otg_urb into the real URB
  78478. + */
  78479. +void dwc_otg_fiq_unmangle_isoc(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh, dwc_otg_qtd_t *qtd, uint32_t num)
  78480. +{
  78481. + struct dwc_otg_hcd_urb *dwc_urb = qtd->urb;
  78482. + int nr_frames = dwc_urb->packet_count;
  78483. + int i;
  78484. + hcint_data_t frame_hcint;
  78485. +
  78486. + for (i = 0; i < nr_frames; i++) {
  78487. + frame_hcint.d32 = dwc_urb->iso_descs[i].status;
  78488. + if (frame_hcint.b.xfercomp) {
  78489. + dwc_urb->iso_descs[i].status = 0;
  78490. + dwc_urb->actual_length += dwc_urb->iso_descs[i].actual_length;
  78491. + } else if (frame_hcint.b.frmovrun) {
  78492. + if (qh->ep_is_in)
  78493. + dwc_urb->iso_descs[i].status = -DWC_E_NO_STREAM_RES;
  78494. + else
  78495. + dwc_urb->iso_descs[i].status = -DWC_E_COMMUNICATION;
  78496. + dwc_urb->error_count++;
  78497. + dwc_urb->iso_descs[i].actual_length = 0;
  78498. + } else if (frame_hcint.b.xacterr) {
  78499. + dwc_urb->iso_descs[i].status = -DWC_E_PROTOCOL;
  78500. + dwc_urb->error_count++;
  78501. + dwc_urb->iso_descs[i].actual_length = 0;
  78502. + } else if (frame_hcint.b.bblerr) {
  78503. + dwc_urb->iso_descs[i].status = -DWC_E_OVERFLOW;
  78504. + dwc_urb->error_count++;
  78505. + dwc_urb->iso_descs[i].actual_length = 0;
  78506. + } else {
  78507. + /* Something went wrong */
  78508. + dwc_urb->iso_descs[i].status = -1;
  78509. + dwc_urb->iso_descs[i].actual_length = 0;
  78510. + dwc_urb->error_count++;
  78511. + }
  78512. + }
  78513. + //printk_ratelimited(KERN_INFO "%s: HS isochronous of %d/%d frames with %d errors complete\n",
  78514. + // __FUNCTION__, i, dwc_urb->packet_count, dwc_urb->error_count);
  78515. + hcd->fops->complete(hcd, dwc_urb->priv, dwc_urb, 0);
  78516. + release_channel(hcd, qh->channel, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  78517. +}
  78518. +
  78519. +/**
  78520. + * dwc_otg_fiq_unsetup_per_dma() - Remove data from bounce buffers for split transactions
  78521. + * @hcd: Pointer to dwc_otg_hcd struct
  78522. + * @num: Host channel number
  78523. + *
  78524. + * Copies data from the FIQ bounce buffers into the URB's transfer buffer. Does not modify URB state.
  78525. + * Returns total length of data or -1 if the buffers were not used.
  78526. + *
  78527. + */
  78528. +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)
  78529. +{
  78530. + dwc_hc_t *hc = qh->channel;
  78531. + struct fiq_dma_blob *blob = hcd->fiq_dmab;
  78532. + struct fiq_channel_state *st = &hcd->fiq_state->channel[num];
  78533. + uint8_t *ptr = NULL;
  78534. + int index = 0, len = 0;
  78535. + int i = 0;
  78536. + if (hc->ep_is_in) {
  78537. + /* Copy data out of the DMA bounce buffers to the URB's buffer.
  78538. + * The align_buf is ignored as this is ignored on FSM enqueue. */
  78539. + ptr = qtd->urb->buf;
  78540. + if (qh->ep_type == UE_ISOCHRONOUS) {
  78541. + /* Isoc IN transactions - grab the offset of the iso_frame_desc into the URB transfer buffer */
  78542. + index = qtd->isoc_frame_index;
  78543. + ptr += qtd->urb->iso_descs[index].offset;
  78544. + } else {
  78545. + /* Need to increment by actual_length for interrupt IN */
  78546. + ptr += qtd->urb->actual_length;
  78547. + }
  78548. +
  78549. + for (i = 0; i < st->nrpackets; i++) {
  78550. + len += st->dma_info.slot_len[i];
  78551. + dwc_memcpy(ptr, &blob->channel[num].index[i].buf[0], st->dma_info.slot_len[i]);
  78552. + ptr += st->dma_info.slot_len[i];
  78553. + }
  78554. + return len;
  78555. + } else {
  78556. + /* OUT endpoints - nothing to do. */
  78557. + return -1;
  78558. + }
  78559. +
  78560. +}
  78561. +/**
  78562. + * dwc_otg_hcd_handle_hc_fsm() - handle an unmasked channel interrupt
  78563. + * from a channel handled in the FIQ
  78564. + * @hcd: Pointer to dwc_otg_hcd struct
  78565. + * @num: Host channel number
  78566. + *
  78567. + * If a host channel interrupt was received by the IRQ and this was a channel
  78568. + * used by the FIQ, the execution flow for transfer completion is substantially
  78569. + * different from the normal (messy) path. This function and its friends handles
  78570. + * channel cleanup and transaction completion from a FIQ transaction.
  78571. + */
  78572. +int32_t dwc_otg_hcd_handle_hc_fsm(dwc_otg_hcd_t *hcd, uint32_t num)
  78573. +{
  78574. + struct fiq_channel_state *st = &hcd->fiq_state->channel[num];
  78575. + dwc_hc_t *hc = hcd->hc_ptr_array[num];
  78576. + dwc_otg_qtd_t *qtd = DWC_CIRCLEQ_FIRST(&hc->qh->qtd_list);
  78577. + dwc_otg_qh_t *qh = hc->qh;
  78578. + dwc_otg_hc_regs_t *hc_regs = hcd->core_if->host_if->hc_regs[num];
  78579. + hcint_data_t hcint = hcd->fiq_state->channel[num].hcint_copy;
  78580. + int hostchannels = 0;
  78581. + int ret = 0;
  78582. + fiq_print(FIQDBG_INT, hcd->fiq_state, "OUT %01d %01d ", num , st->fsm);
  78583. +
  78584. + hostchannels = hcd->available_host_channels;
  78585. + switch (st->fsm) {
  78586. + case FIQ_TEST:
  78587. + break;
  78588. +
  78589. + case FIQ_DEQUEUE_ISSUED:
  78590. + /* hc_halt was called. QTD no longer exists. */
  78591. + /* TODO: for a nonperiodic split transaction, need to issue a
  78592. + * CLEAR_TT_BUFFER hub command if we were in the start-split phase.
  78593. + */
  78594. + release_channel(hcd, hc, NULL, hc->halt_status);
  78595. + ret = 1;
  78596. + break;
  78597. +
  78598. + case FIQ_NP_SPLIT_DONE:
  78599. + /* Nonperiodic transaction complete. */
  78600. + if (!hc->ep_is_in) {
  78601. + qtd->ssplit_out_xfer_count = hc->xfer_len;
  78602. + }
  78603. + if (hcint.b.xfercomp) {
  78604. + handle_hc_xfercomp_intr(hcd, hc, hc_regs, qtd);
  78605. + } else if (hcint.b.nak) {
  78606. + handle_hc_nak_intr(hcd, hc, hc_regs, qtd);
  78607. + }
  78608. + ret = 1;
  78609. + break;
  78610. +
  78611. + case FIQ_NP_SPLIT_HS_ABORTED:
  78612. + /* A HS abort is a 3-strikes on the HS bus at any point in the transaction.
  78613. + * Normally a CLEAR_TT_BUFFER hub command would be required: we can't do that
  78614. + * because there's no guarantee which order a non-periodic split happened in.
  78615. + * We could end up clearing a perfectly good transaction out of the buffer.
  78616. + */
  78617. + if (hcint.b.xacterr) {
  78618. + qtd->error_count += st->nr_errors;
  78619. + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
  78620. + } else if (hcint.b.ahberr) {
  78621. + handle_hc_ahberr_intr(hcd, hc, hc_regs, qtd);
  78622. + } else {
  78623. + local_fiq_disable();
  78624. + BUG();
  78625. + }
  78626. + break;
  78627. +
  78628. + case FIQ_NP_SPLIT_LS_ABORTED:
  78629. + /* A few cases can cause this - either an unknown state on a SSPLIT or
  78630. + * STALL/data toggle error response on a CSPLIT */
  78631. + if (hcint.b.stall) {
  78632. + handle_hc_stall_intr(hcd, hc, hc_regs, qtd);
  78633. + } else if (hcint.b.datatglerr) {
  78634. + handle_hc_datatglerr_intr(hcd, hc, hc_regs, qtd);
  78635. + } else if (hcint.b.ahberr) {
  78636. + handle_hc_ahberr_intr(hcd, hc, hc_regs, qtd);
  78637. + } else {
  78638. + local_fiq_disable();
  78639. + BUG();
  78640. + }
  78641. + break;
  78642. +
  78643. + case FIQ_PER_SPLIT_DONE:
  78644. + /* Isoc IN or Interrupt IN/OUT */
  78645. +
  78646. + /* Flow control here is different from the normal execution by the driver.
  78647. + * We need to completely ignore most of the driver's method of handling
  78648. + * split transactions and do it ourselves.
  78649. + */
  78650. + if (hc->ep_type == UE_INTERRUPT) {
  78651. + if (hc->ep_is_in) {
  78652. + if (hcint.b.nak) {
  78653. + handle_hc_nak_intr(hcd, hc, hc_regs, qtd);
  78654. + } else {
  78655. + int len;
  78656. + len = dwc_otg_fiq_unsetup_per_dma(hcd, hc->qh, qtd, num);
  78657. + //printk(KERN_NOTICE "FIQ Transaction: hc=%d len=%d urb_len = %d\n", num, len, qtd->urb->length);
  78658. + qtd->urb->actual_length += len;
  78659. + if (qtd->urb->actual_length >= qtd->urb->length) {
  78660. + qtd->urb->status = 0;
  78661. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, qtd->urb->status);
  78662. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  78663. + } else {
  78664. + /* Interrupt transfer not complete yet - is it a short read? */
  78665. + if (len < hc->max_packet) {
  78666. + /* Interrupt transaction complete */
  78667. + qtd->urb->status = 0;
  78668. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, qtd->urb->status);
  78669. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  78670. + } else {
  78671. + /* Further transactions required */
  78672. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
  78673. + }
  78674. +
  78675. + }
  78676. +
  78677. + }
  78678. +
  78679. + } else {
  78680. + /* Interrupt OUT complete. */
  78681. + qtd->urb->actual_length += hc->xfer_len;
  78682. + if (qtd->urb->actual_length >= qtd->urb->length) {
  78683. + qtd->urb->status = 0;
  78684. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, qtd->urb->status);
  78685. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  78686. + } else {
  78687. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
  78688. + }
  78689. + }
  78690. + } else {
  78691. + /* ISOC IN complete. */
  78692. + struct dwc_otg_hcd_iso_packet_desc *frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  78693. + int len = 0;
  78694. + /* Record errors, update qtd. */
  78695. + if (st->nr_errors) {
  78696. + frame_desc->actual_length = 0;
  78697. + frame_desc->status = -DWC_E_PROTOCOL;
  78698. + } else {
  78699. + frame_desc->status = 0;
  78700. + /* Unswizzle dma */
  78701. + len = dwc_otg_fiq_unsetup_per_dma(hcd, qh, qtd, num);
  78702. + frame_desc->actual_length = len;
  78703. + }
  78704. + qtd->isoc_frame_index++;
  78705. + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
  78706. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  78707. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  78708. + } else {
  78709. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
  78710. + }
  78711. + }
  78712. + break;
  78713. +
  78714. + case FIQ_PER_ISO_OUT_DONE: {
  78715. + struct dwc_otg_hcd_iso_packet_desc *frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  78716. + /* Record errors, update qtd. */
  78717. + if (st->nr_errors) {
  78718. + frame_desc->actual_length = 0;
  78719. + frame_desc->status = -DWC_E_PROTOCOL;
  78720. + } else {
  78721. + frame_desc->status = 0;
  78722. + frame_desc->actual_length = frame_desc->length;
  78723. + }
  78724. + qtd->isoc_frame_index++;
  78725. + qtd->isoc_split_offset = 0;
  78726. + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
  78727. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  78728. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  78729. + } else {
  78730. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
  78731. + }
  78732. + }
  78733. + break;
  78734. +
  78735. + case FIQ_PER_SPLIT_NYET_ABORTED:
  78736. + /* Doh. lost the data. */
  78737. + printk_ratelimited(KERN_INFO "Transfer to device %d endpoint 0x%x failed "
  78738. + "- FIQ reported NYET. Data may have been lost.\n",
  78739. + hc->dev_addr, hc->ep_num);
  78740. + if (hc->ep_type == UE_ISOCHRONOUS) {
  78741. + struct dwc_otg_hcd_iso_packet_desc *frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  78742. + /* Record errors, update qtd. */
  78743. + frame_desc->actual_length = 0;
  78744. + frame_desc->status = -DWC_E_PROTOCOL;
  78745. + qtd->isoc_frame_index++;
  78746. + qtd->isoc_split_offset = 0;
  78747. + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
  78748. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  78749. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  78750. + } else {
  78751. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
  78752. + }
  78753. + } else {
  78754. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  78755. + }
  78756. + break;
  78757. +
  78758. + case FIQ_HS_ISOC_DONE:
  78759. + /* The FIQ has performed a whole pile of isochronous transactions.
  78760. + * The status is recorded as the interrupt state should the transaction
  78761. + * fail.
  78762. + */
  78763. + dwc_otg_fiq_unmangle_isoc(hcd, qh, qtd, num);
  78764. + break;
  78765. +
  78766. + case FIQ_PER_SPLIT_LS_ABORTED:
  78767. + if (hcint.b.xacterr) {
  78768. + /* Hub has responded with an ERR packet. Device
  78769. + * has been unplugged or the port has been disabled.
  78770. + * TODO: need to issue a reset to the hub port. */
  78771. + qtd->error_count += 3;
  78772. + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
  78773. + } else {
  78774. + printk_ratelimited(KERN_INFO "Transfer to device %d endpoint 0x%x failed "
  78775. + "- FIQ reported FSM=%d. Data may have been lost.\n",
  78776. + st->fsm, hc->dev_addr, hc->ep_num);
  78777. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  78778. + }
  78779. + break;
  78780. +
  78781. + case FIQ_PER_SPLIT_HS_ABORTED:
  78782. + /* Either the SSPLIT phase suffered transaction errors or something
  78783. + * unexpected happened.
  78784. + */
  78785. + qtd->error_count += 3;
  78786. + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
  78787. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  78788. + break;
  78789. +
  78790. + case FIQ_PER_SPLIT_TIMEOUT:
  78791. + /* Couldn't complete in the nominated frame */
  78792. + printk_ratelimited(KERN_INFO "Transfer to device %d endpoint 0x%x failed "
  78793. + "- FIQ timed out. Data may have been lost.\n",
  78794. + hc->dev_addr, hc->ep_num);
  78795. + if (hc->ep_type == UE_ISOCHRONOUS) {
  78796. + struct dwc_otg_hcd_iso_packet_desc *frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  78797. + /* Record errors, update qtd. */
  78798. + frame_desc->actual_length = 0;
  78799. + if (hc->ep_is_in) {
  78800. + frame_desc->status = -DWC_E_NO_STREAM_RES;
  78801. + } else {
  78802. + frame_desc->status = -DWC_E_COMMUNICATION;
  78803. + }
  78804. + qtd->isoc_frame_index++;
  78805. + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
  78806. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  78807. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  78808. + } else {
  78809. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
  78810. + }
  78811. + } else {
  78812. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  78813. + }
  78814. + break;
  78815. +
  78816. + default:
  78817. + local_fiq_disable();
  78818. + DWC_WARN("unexpected state received on hc=%d fsm=%d", hc->hc_num, st->fsm);
  78819. + BUG();
  78820. + }
  78821. + //if (hostchannels != hcd->available_host_channels) {
  78822. + /* should have incremented by now! */
  78823. + // BUG();
  78824. +// }
  78825. + return ret;
  78826. +}
  78827. +
  78828. +/** Handles interrupt for a specific Host Channel */
  78829. +int32_t dwc_otg_hcd_handle_hc_n_intr(dwc_otg_hcd_t * dwc_otg_hcd, uint32_t num)
  78830. +{
  78831. + int retval = 0;
  78832. + hcint_data_t hcint;
  78833. + hcintmsk_data_t hcintmsk;
  78834. + dwc_hc_t *hc;
  78835. + dwc_otg_hc_regs_t *hc_regs;
  78836. + dwc_otg_qtd_t *qtd;
  78837. +
  78838. + DWC_DEBUGPL(DBG_HCDV, "--Host Channel Interrupt--, Channel %d\n", num);
  78839. +
  78840. + hc = dwc_otg_hcd->hc_ptr_array[num];
  78841. + hc_regs = dwc_otg_hcd->core_if->host_if->hc_regs[num];
  78842. + if(hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE) {
  78843. + /* We are responding to a channel disable. Driver
  78844. + * state is cleared - our qtd has gone away.
  78845. + */
  78846. + release_channel(dwc_otg_hcd, hc, NULL, hc->halt_status);
  78847. + return 1;
  78848. + }
  78849. +
  78850. + /*
  78851. + * FSM mode: Check to see if this is a HC interrupt from a channel handled by the FIQ.
  78852. + * Execution path is fundamentally different for the channels after a FIQ has completed
  78853. + * a split transaction.
  78854. + */
  78855. +
  78856. +
  78857. + if (fiq_fsm_enable) {
  78858. + if (*(volatile uint32_t *)&dwc_otg_hcd->fiq_state->channel[num].fsm != FIQ_PASSTHROUGH) {
  78859. + dwc_otg_hcd_handle_hc_fsm(dwc_otg_hcd, num);
  78860. + return 1;
  78861. + }
  78862. + }
  78863. + qtd = DWC_CIRCLEQ_FIRST(&hc->qh->qtd_list);
  78864. +
  78865. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  78866. + hcintmsk.d32 = DWC_READ_REG32(&hc_regs->hcintmsk);
  78867. + hcint.d32 = hcint.d32 & hcintmsk.d32;
  78868. + if (!dwc_otg_hcd->core_if->dma_enable) {
  78869. + if (hcint.b.chhltd && hcint.d32 != 0x2) {
  78870. + hcint.b.chhltd = 0;
  78871. + }
  78872. + }
  78873. +
  78874. + if (hcint.b.xfercomp) {
  78875. + retval |=
  78876. + handle_hc_xfercomp_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  78877. + /*
  78878. + * If NYET occurred at same time as Xfer Complete, the NYET is
  78879. + * handled by the Xfer Complete interrupt handler. Don't want
  78880. + * to call the NYET interrupt handler in this case.
  78881. + */
  78882. + hcint.b.nyet = 0;
  78883. + }
  78884. + if (hcint.b.chhltd) {
  78885. + retval |= handle_hc_chhltd_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  78886. + }
  78887. + if (hcint.b.ahberr) {
  78888. + retval |= handle_hc_ahberr_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  78889. + }
  78890. + if (hcint.b.stall) {
  78891. + retval |= handle_hc_stall_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  78892. + }
  78893. + if (hcint.b.nak) {
  78894. + retval |= handle_hc_nak_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  78895. + }
  78896. + if (hcint.b.ack) {
  78897. + if(!hcint.b.chhltd)
  78898. + retval |= handle_hc_ack_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  78899. + }
  78900. + if (hcint.b.nyet) {
  78901. + retval |= handle_hc_nyet_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  78902. + }
  78903. + if (hcint.b.xacterr) {
  78904. + retval |= handle_hc_xacterr_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  78905. + }
  78906. + if (hcint.b.bblerr) {
  78907. + retval |= handle_hc_babble_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  78908. + }
  78909. + if (hcint.b.frmovrun) {
  78910. + retval |=
  78911. + handle_hc_frmovrun_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  78912. + }
  78913. + if (hcint.b.datatglerr) {
  78914. + retval |=
  78915. + handle_hc_datatglerr_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  78916. + }
  78917. +
  78918. + return retval;
  78919. +}
  78920. +#endif /* DWC_DEVICE_ONLY */
  78921. diff -Nur linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c
  78922. --- linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c 1970-01-01 01:00:00.000000000 +0100
  78923. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c 2014-04-24 15:37:13.314990533 +0200
  78924. @@ -0,0 +1,981 @@
  78925. +
  78926. +/* ==========================================================================
  78927. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_linux.c $
  78928. + * $Revision: #20 $
  78929. + * $Date: 2011/10/26 $
  78930. + * $Change: 1872981 $
  78931. + *
  78932. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  78933. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  78934. + * otherwise expressly agreed to in writing between Synopsys and you.
  78935. + *
  78936. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  78937. + * any End User Software License Agreement or Agreement for Licensed Product
  78938. + * with Synopsys or any supplement thereto. You are permitted to use and
  78939. + * redistribute this Software in source and binary forms, with or without
  78940. + * modification, provided that redistributions of source code must retain this
  78941. + * notice. You may not view, use, disclose, copy or distribute this file or
  78942. + * any information contained herein except pursuant to this license grant from
  78943. + * Synopsys. If you do not agree with this notice, including the disclaimer
  78944. + * below, then you are not authorized to use the Software.
  78945. + *
  78946. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  78947. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  78948. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  78949. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  78950. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  78951. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  78952. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  78953. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  78954. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  78955. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  78956. + * DAMAGE.
  78957. + * ========================================================================== */
  78958. +#ifndef DWC_DEVICE_ONLY
  78959. +
  78960. +/**
  78961. + * @file
  78962. + *
  78963. + * This file contains the implementation of the HCD. In Linux, the HCD
  78964. + * implements the hc_driver API.
  78965. + */
  78966. +#include <linux/kernel.h>
  78967. +#include <linux/module.h>
  78968. +#include <linux/moduleparam.h>
  78969. +#include <linux/init.h>
  78970. +#include <linux/device.h>
  78971. +#include <linux/errno.h>
  78972. +#include <linux/list.h>
  78973. +#include <linux/interrupt.h>
  78974. +#include <linux/string.h>
  78975. +#include <linux/dma-mapping.h>
  78976. +#include <linux/version.h>
  78977. +#include <asm/io.h>
  78978. +#include <asm/fiq.h>
  78979. +#include <linux/usb.h>
  78980. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35)
  78981. +#include <../drivers/usb/core/hcd.h>
  78982. +#else
  78983. +#include <linux/usb/hcd.h>
  78984. +#endif
  78985. +#include <asm/bug.h>
  78986. +
  78987. +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30))
  78988. +#define USB_URB_EP_LINKING 1
  78989. +#else
  78990. +#define USB_URB_EP_LINKING 0
  78991. +#endif
  78992. +
  78993. +#include "dwc_otg_hcd_if.h"
  78994. +#include "dwc_otg_dbg.h"
  78995. +#include "dwc_otg_driver.h"
  78996. +#include "dwc_otg_hcd.h"
  78997. +
  78998. +extern unsigned char _dwc_otg_fiq_stub, _dwc_otg_fiq_stub_end;
  78999. +
  79000. +/**
  79001. + * Gets the endpoint number from a _bEndpointAddress argument. The endpoint is
  79002. + * qualified with its direction (possible 32 endpoints per device).
  79003. + */
  79004. +#define dwc_ep_addr_to_endpoint(_bEndpointAddress_) ((_bEndpointAddress_ & USB_ENDPOINT_NUMBER_MASK) | \
  79005. + ((_bEndpointAddress_ & USB_DIR_IN) != 0) << 4)
  79006. +
  79007. +static const char dwc_otg_hcd_name[] = "dwc_otg_hcd";
  79008. +
  79009. +extern bool fiq_enable;
  79010. +
  79011. +/** @name Linux HC Driver API Functions */
  79012. +/** @{ */
  79013. +/* manage i/o requests, device state */
  79014. +static int dwc_otg_urb_enqueue(struct usb_hcd *hcd,
  79015. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  79016. + struct usb_host_endpoint *ep,
  79017. +#endif
  79018. + struct urb *urb, gfp_t mem_flags);
  79019. +
  79020. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
  79021. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  79022. +static int dwc_otg_urb_dequeue(struct usb_hcd *hcd, struct urb *urb);
  79023. +#endif
  79024. +#else /* kernels at or post 2.6.30 */
  79025. +static int dwc_otg_urb_dequeue(struct usb_hcd *hcd,
  79026. + struct urb *urb, int status);
  79027. +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30) */
  79028. +
  79029. +static void endpoint_disable(struct usb_hcd *hcd, struct usb_host_endpoint *ep);
  79030. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
  79031. +static void endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep);
  79032. +#endif
  79033. +static irqreturn_t dwc_otg_hcd_irq(struct usb_hcd *hcd);
  79034. +extern int hcd_start(struct usb_hcd *hcd);
  79035. +extern void hcd_stop(struct usb_hcd *hcd);
  79036. +static int get_frame_number(struct usb_hcd *hcd);
  79037. +extern int hub_status_data(struct usb_hcd *hcd, char *buf);
  79038. +extern int hub_control(struct usb_hcd *hcd,
  79039. + u16 typeReq,
  79040. + u16 wValue, u16 wIndex, char *buf, u16 wLength);
  79041. +
  79042. +struct wrapper_priv_data {
  79043. + dwc_otg_hcd_t *dwc_otg_hcd;
  79044. +};
  79045. +
  79046. +/** @} */
  79047. +
  79048. +static struct hc_driver dwc_otg_hc_driver = {
  79049. +
  79050. + .description = dwc_otg_hcd_name,
  79051. + .product_desc = "DWC OTG Controller",
  79052. + .hcd_priv_size = sizeof(struct wrapper_priv_data),
  79053. +
  79054. + .irq = dwc_otg_hcd_irq,
  79055. +
  79056. + .flags = HCD_MEMORY | HCD_USB2,
  79057. +
  79058. + //.reset =
  79059. + .start = hcd_start,
  79060. + //.suspend =
  79061. + //.resume =
  79062. + .stop = hcd_stop,
  79063. +
  79064. + .urb_enqueue = dwc_otg_urb_enqueue,
  79065. + .urb_dequeue = dwc_otg_urb_dequeue,
  79066. + .endpoint_disable = endpoint_disable,
  79067. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
  79068. + .endpoint_reset = endpoint_reset,
  79069. +#endif
  79070. + .get_frame_number = get_frame_number,
  79071. +
  79072. + .hub_status_data = hub_status_data,
  79073. + .hub_control = hub_control,
  79074. + //.bus_suspend =
  79075. + //.bus_resume =
  79076. +};
  79077. +
  79078. +/** Gets the dwc_otg_hcd from a struct usb_hcd */
  79079. +static inline dwc_otg_hcd_t *hcd_to_dwc_otg_hcd(struct usb_hcd *hcd)
  79080. +{
  79081. + struct wrapper_priv_data *p;
  79082. + p = (struct wrapper_priv_data *)(hcd->hcd_priv);
  79083. + return p->dwc_otg_hcd;
  79084. +}
  79085. +
  79086. +/** Gets the struct usb_hcd that contains a dwc_otg_hcd_t. */
  79087. +static inline struct usb_hcd *dwc_otg_hcd_to_hcd(dwc_otg_hcd_t * dwc_otg_hcd)
  79088. +{
  79089. + return dwc_otg_hcd_get_priv_data(dwc_otg_hcd);
  79090. +}
  79091. +
  79092. +/** Gets the usb_host_endpoint associated with an URB. */
  79093. +inline struct usb_host_endpoint *dwc_urb_to_endpoint(struct urb *urb)
  79094. +{
  79095. + struct usb_device *dev = urb->dev;
  79096. + int ep_num = usb_pipeendpoint(urb->pipe);
  79097. +
  79098. + if (usb_pipein(urb->pipe))
  79099. + return dev->ep_in[ep_num];
  79100. + else
  79101. + return dev->ep_out[ep_num];
  79102. +}
  79103. +
  79104. +static int _disconnect(dwc_otg_hcd_t * hcd)
  79105. +{
  79106. + struct usb_hcd *usb_hcd = dwc_otg_hcd_to_hcd(hcd);
  79107. +
  79108. + usb_hcd->self.is_b_host = 0;
  79109. + return 0;
  79110. +}
  79111. +
  79112. +static int _start(dwc_otg_hcd_t * hcd)
  79113. +{
  79114. + struct usb_hcd *usb_hcd = dwc_otg_hcd_to_hcd(hcd);
  79115. +
  79116. + usb_hcd->self.is_b_host = dwc_otg_hcd_is_b_host(hcd);
  79117. + hcd_start(usb_hcd);
  79118. +
  79119. + return 0;
  79120. +}
  79121. +
  79122. +static int _hub_info(dwc_otg_hcd_t * hcd, void *urb_handle, uint32_t * hub_addr,
  79123. + uint32_t * port_addr)
  79124. +{
  79125. + struct urb *urb = (struct urb *)urb_handle;
  79126. + struct usb_bus *bus;
  79127. +#if 1 //GRAYG - temporary
  79128. + if (NULL == urb_handle)
  79129. + DWC_ERROR("**** %s - NULL URB handle\n", __func__);//GRAYG
  79130. + if (NULL == urb->dev)
  79131. + DWC_ERROR("**** %s - URB has no device\n", __func__);//GRAYG
  79132. + if (NULL == port_addr)
  79133. + DWC_ERROR("**** %s - NULL port_address\n", __func__);//GRAYG
  79134. +#endif
  79135. + if (urb->dev->tt) {
  79136. + if (NULL == urb->dev->tt->hub) {
  79137. + DWC_ERROR("**** %s - (URB's transactor has no TT - giving no hub)\n",
  79138. + __func__); //GRAYG
  79139. + //*hub_addr = (u8)usb_pipedevice(urb->pipe); //GRAYG
  79140. + *hub_addr = 0; //GRAYG
  79141. + // we probably shouldn't have a transaction translator if
  79142. + // there's no associated hub?
  79143. + } else {
  79144. + bus = hcd_to_bus(dwc_otg_hcd_to_hcd(hcd));
  79145. + if (urb->dev->tt->hub == bus->root_hub)
  79146. + *hub_addr = 0;
  79147. + else
  79148. + *hub_addr = urb->dev->tt->hub->devnum;
  79149. + }
  79150. + *port_addr = urb->dev->tt->multi ? urb->dev->ttport : 1;
  79151. + } else {
  79152. + *hub_addr = 0;
  79153. + *port_addr = urb->dev->ttport;
  79154. + }
  79155. + return 0;
  79156. +}
  79157. +
  79158. +static int _speed(dwc_otg_hcd_t * hcd, void *urb_handle)
  79159. +{
  79160. + struct urb *urb = (struct urb *)urb_handle;
  79161. + return urb->dev->speed;
  79162. +}
  79163. +
  79164. +static int _get_b_hnp_enable(dwc_otg_hcd_t * hcd)
  79165. +{
  79166. + struct usb_hcd *usb_hcd = dwc_otg_hcd_to_hcd(hcd);
  79167. + return usb_hcd->self.b_hnp_enable;
  79168. +}
  79169. +
  79170. +static void allocate_bus_bandwidth(struct usb_hcd *hcd, uint32_t bw,
  79171. + struct urb *urb)
  79172. +{
  79173. + hcd_to_bus(hcd)->bandwidth_allocated += bw / urb->interval;
  79174. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  79175. + hcd_to_bus(hcd)->bandwidth_isoc_reqs++;
  79176. + } else {
  79177. + hcd_to_bus(hcd)->bandwidth_int_reqs++;
  79178. + }
  79179. +}
  79180. +
  79181. +static void free_bus_bandwidth(struct usb_hcd *hcd, uint32_t bw,
  79182. + struct urb *urb)
  79183. +{
  79184. + hcd_to_bus(hcd)->bandwidth_allocated -= bw / urb->interval;
  79185. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  79186. + hcd_to_bus(hcd)->bandwidth_isoc_reqs--;
  79187. + } else {
  79188. + hcd_to_bus(hcd)->bandwidth_int_reqs--;
  79189. + }
  79190. +}
  79191. +
  79192. +/**
  79193. + * Sets the final status of an URB and returns it to the device driver. Any
  79194. + * required cleanup of the URB is performed. The HCD lock should be held on
  79195. + * entry.
  79196. + */
  79197. +static int _complete(dwc_otg_hcd_t * hcd, void *urb_handle,
  79198. + dwc_otg_hcd_urb_t * dwc_otg_urb, int32_t status)
  79199. +{
  79200. + struct urb *urb = (struct urb *)urb_handle;
  79201. + urb_tq_entry_t *new_entry;
  79202. + int rc = 0;
  79203. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  79204. + DWC_PRINTF("%s: urb %p, device %d, ep %d %s, status=%d\n",
  79205. + __func__, urb, usb_pipedevice(urb->pipe),
  79206. + usb_pipeendpoint(urb->pipe),
  79207. + usb_pipein(urb->pipe) ? "IN" : "OUT", status);
  79208. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  79209. + int i;
  79210. + for (i = 0; i < urb->number_of_packets; i++) {
  79211. + DWC_PRINTF(" ISO Desc %d status: %d\n",
  79212. + i, urb->iso_frame_desc[i].status);
  79213. + }
  79214. + }
  79215. + }
  79216. + new_entry = DWC_ALLOC_ATOMIC(sizeof(urb_tq_entry_t));
  79217. + urb->actual_length = dwc_otg_hcd_urb_get_actual_length(dwc_otg_urb);
  79218. + /* Convert status value. */
  79219. + switch (status) {
  79220. + case -DWC_E_PROTOCOL:
  79221. + status = -EPROTO;
  79222. + break;
  79223. + case -DWC_E_IN_PROGRESS:
  79224. + status = -EINPROGRESS;
  79225. + break;
  79226. + case -DWC_E_PIPE:
  79227. + status = -EPIPE;
  79228. + break;
  79229. + case -DWC_E_IO:
  79230. + status = -EIO;
  79231. + break;
  79232. + case -DWC_E_TIMEOUT:
  79233. + status = -ETIMEDOUT;
  79234. + break;
  79235. + case -DWC_E_OVERFLOW:
  79236. + status = -EOVERFLOW;
  79237. + break;
  79238. + case -DWC_E_SHUTDOWN:
  79239. + status = -ESHUTDOWN;
  79240. + break;
  79241. + default:
  79242. + if (status) {
  79243. + DWC_PRINTF("Uknown urb status %d\n", status);
  79244. +
  79245. + }
  79246. + }
  79247. +
  79248. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  79249. + int i;
  79250. +
  79251. + urb->error_count = dwc_otg_hcd_urb_get_error_count(dwc_otg_urb);
  79252. + for (i = 0; i < urb->number_of_packets; ++i) {
  79253. + urb->iso_frame_desc[i].actual_length =
  79254. + dwc_otg_hcd_urb_get_iso_desc_actual_length
  79255. + (dwc_otg_urb, i);
  79256. + urb->iso_frame_desc[i].status =
  79257. + dwc_otg_hcd_urb_get_iso_desc_status(dwc_otg_urb, i);
  79258. + }
  79259. + }
  79260. +
  79261. + urb->status = status;
  79262. + urb->hcpriv = NULL;
  79263. + if (!status) {
  79264. + if ((urb->transfer_flags & URB_SHORT_NOT_OK) &&
  79265. + (urb->actual_length < urb->transfer_buffer_length)) {
  79266. + urb->status = -EREMOTEIO;
  79267. + }
  79268. + }
  79269. +
  79270. + if ((usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) ||
  79271. + (usb_pipetype(urb->pipe) == PIPE_INTERRUPT)) {
  79272. + struct usb_host_endpoint *ep = dwc_urb_to_endpoint(urb);
  79273. + if (ep) {
  79274. + free_bus_bandwidth(dwc_otg_hcd_to_hcd(hcd),
  79275. + dwc_otg_hcd_get_ep_bandwidth(hcd,
  79276. + ep->hcpriv),
  79277. + urb);
  79278. + }
  79279. + }
  79280. + DWC_FREE(dwc_otg_urb);
  79281. + if (!new_entry) {
  79282. + DWC_ERROR("dwc_otg_hcd: complete: cannot allocate URB TQ entry\n");
  79283. + urb->status = -EPROTO;
  79284. + /* don't schedule the tasklet -
  79285. + * directly return the packet here with error. */
  79286. +#if USB_URB_EP_LINKING
  79287. + usb_hcd_unlink_urb_from_ep(dwc_otg_hcd_to_hcd(hcd), urb);
  79288. +#endif
  79289. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  79290. + usb_hcd_giveback_urb(dwc_otg_hcd_to_hcd(hcd), urb);
  79291. +#else
  79292. + usb_hcd_giveback_urb(dwc_otg_hcd_to_hcd(hcd), urb, urb->status);
  79293. +#endif
  79294. + } else {
  79295. + new_entry->urb = urb;
  79296. +#if USB_URB_EP_LINKING
  79297. + rc = usb_hcd_check_unlink_urb(dwc_otg_hcd_to_hcd(hcd), urb, urb->status);
  79298. + if(0 == rc) {
  79299. + usb_hcd_unlink_urb_from_ep(dwc_otg_hcd_to_hcd(hcd), urb);
  79300. + }
  79301. +#endif
  79302. + if(0 == rc) {
  79303. + DWC_TAILQ_INSERT_TAIL(&hcd->completed_urb_list, new_entry,
  79304. + urb_tq_entries);
  79305. + DWC_TASK_HI_SCHEDULE(hcd->completion_tasklet);
  79306. + }
  79307. + }
  79308. + return 0;
  79309. +}
  79310. +
  79311. +static struct dwc_otg_hcd_function_ops hcd_fops = {
  79312. + .start = _start,
  79313. + .disconnect = _disconnect,
  79314. + .hub_info = _hub_info,
  79315. + .speed = _speed,
  79316. + .complete = _complete,
  79317. + .get_b_hnp_enable = _get_b_hnp_enable,
  79318. +};
  79319. +
  79320. +static struct fiq_handler fh = {
  79321. + .name = "usb_fiq",
  79322. +};
  79323. +
  79324. +
  79325. +
  79326. +/**
  79327. + * Initializes the HCD. This function allocates memory for and initializes the
  79328. + * static parts of the usb_hcd and dwc_otg_hcd structures. It also registers the
  79329. + * USB bus with the core and calls the hc_driver->start() function. It returns
  79330. + * a negative error on failure.
  79331. + */
  79332. +int hcd_init(dwc_bus_dev_t *_dev)
  79333. +{
  79334. + struct usb_hcd *hcd = NULL;
  79335. + dwc_otg_hcd_t *dwc_otg_hcd = NULL;
  79336. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  79337. + int retval = 0;
  79338. + u64 dmamask;
  79339. + struct pt_regs regs;
  79340. +
  79341. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD INIT otg_dev=%p\n", otg_dev);
  79342. +
  79343. + /* Set device flags indicating whether the HCD supports DMA. */
  79344. + if (dwc_otg_is_dma_enable(otg_dev->core_if))
  79345. + dmamask = DMA_BIT_MASK(32);
  79346. + else
  79347. + dmamask = 0;
  79348. +
  79349. +#if defined(LM_INTERFACE) || defined(PLATFORM_INTERFACE)
  79350. + dma_set_mask(&_dev->dev, dmamask);
  79351. + dma_set_coherent_mask(&_dev->dev, dmamask);
  79352. +#elif defined(PCI_INTERFACE)
  79353. + pci_set_dma_mask(_dev, dmamask);
  79354. + pci_set_consistent_dma_mask(_dev, dmamask);
  79355. +#endif
  79356. +
  79357. + /*
  79358. + * Allocate memory for the base HCD plus the DWC OTG HCD.
  79359. + * Initialize the base HCD.
  79360. + */
  79361. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
  79362. + hcd = usb_create_hcd(&dwc_otg_hc_driver, &_dev->dev, _dev->dev.bus_id);
  79363. +#else
  79364. + hcd = usb_create_hcd(&dwc_otg_hc_driver, &_dev->dev, dev_name(&_dev->dev));
  79365. + hcd->has_tt = 1;
  79366. +// hcd->uses_new_polling = 1;
  79367. +// hcd->poll_rh = 0;
  79368. +#endif
  79369. + if (!hcd) {
  79370. + retval = -ENOMEM;
  79371. + goto error1;
  79372. + }
  79373. +
  79374. + hcd->regs = otg_dev->os_dep.base;
  79375. +
  79376. +
  79377. + /* Initialize the DWC OTG HCD. */
  79378. + dwc_otg_hcd = dwc_otg_hcd_alloc_hcd();
  79379. + if (!dwc_otg_hcd) {
  79380. + goto error2;
  79381. + }
  79382. + ((struct wrapper_priv_data *)(hcd->hcd_priv))->dwc_otg_hcd =
  79383. + dwc_otg_hcd;
  79384. + otg_dev->hcd = dwc_otg_hcd;
  79385. +
  79386. + if (dwc_otg_hcd_init(dwc_otg_hcd, otg_dev->core_if)) {
  79387. + goto error2;
  79388. + }
  79389. +
  79390. + if (fiq_enable)
  79391. + {
  79392. + if (claim_fiq(&fh)) {
  79393. + DWC_ERROR("Can't claim FIQ");
  79394. + goto error2;
  79395. + }
  79396. +
  79397. + DWC_WARN("FIQ at 0x%08x", (fiq_fsm_enable ? (int)&dwc_otg_fiq_fsm : (int)&dwc_otg_fiq_nop));
  79398. + DWC_WARN("FIQ ASM at 0x%08x length %d", (int)&_dwc_otg_fiq_stub, (int)(&_dwc_otg_fiq_stub_end - &_dwc_otg_fiq_stub));
  79399. +
  79400. + set_fiq_handler((void *) &_dwc_otg_fiq_stub, &_dwc_otg_fiq_stub_end - &_dwc_otg_fiq_stub);
  79401. + memset(&regs,0,sizeof(regs));
  79402. +
  79403. + regs.ARM_r8 = (long) dwc_otg_hcd->fiq_state;
  79404. + if (fiq_fsm_enable) {
  79405. + regs.ARM_r9 = dwc_otg_hcd->core_if->core_params->host_channels;
  79406. + //regs.ARM_r10 = dwc_otg_hcd->dma;
  79407. + regs.ARM_fp = (long) dwc_otg_fiq_fsm;
  79408. + } else {
  79409. + regs.ARM_fp = (long) dwc_otg_fiq_nop;
  79410. + }
  79411. +
  79412. + regs.ARM_sp = (long) dwc_otg_hcd->fiq_stack + (sizeof(struct fiq_stack) - 4);
  79413. +
  79414. +// __show_regs(&regs);
  79415. + set_fiq_regs(&regs);
  79416. +
  79417. + //Set the mphi periph to the required registers
  79418. + dwc_otg_hcd->fiq_state->mphi_regs.base = otg_dev->os_dep.mphi_base;
  79419. + dwc_otg_hcd->fiq_state->mphi_regs.ctrl = otg_dev->os_dep.mphi_base + 0x4c;
  79420. + dwc_otg_hcd->fiq_state->mphi_regs.outdda = otg_dev->os_dep.mphi_base + 0x28;
  79421. + dwc_otg_hcd->fiq_state->mphi_regs.outddb = otg_dev->os_dep.mphi_base + 0x2c;
  79422. + dwc_otg_hcd->fiq_state->mphi_regs.intstat = otg_dev->os_dep.mphi_base + 0x50;
  79423. + dwc_otg_hcd->fiq_state->dwc_regs_base = otg_dev->os_dep.base;
  79424. + DWC_WARN("MPHI regs_base at 0x%08x", (int)dwc_otg_hcd->fiq_state->mphi_regs.base);
  79425. + //Enable mphi peripheral
  79426. + writel((1<<31),dwc_otg_hcd->fiq_state->mphi_regs.ctrl);
  79427. +#ifdef DEBUG
  79428. + if (readl(dwc_otg_hcd->fiq_state->mphi_regs.ctrl) & 0x80000000)
  79429. + DWC_WARN("MPHI periph has been enabled");
  79430. + else
  79431. + DWC_WARN("MPHI periph has NOT been enabled");
  79432. +#endif
  79433. + // Enable FIQ interrupt from USB peripheral
  79434. + enable_fiq(INTERRUPT_VC_USB);
  79435. + local_fiq_enable();
  79436. + }
  79437. +
  79438. +
  79439. + otg_dev->hcd->otg_dev = otg_dev;
  79440. + hcd->self.otg_port = dwc_otg_hcd_otg_port(dwc_otg_hcd);
  79441. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33) //don't support for LM(with 2.6.20.1 kernel)
  79442. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35) //version field absent later
  79443. + hcd->self.otg_version = dwc_otg_get_otg_version(otg_dev->core_if);
  79444. +#endif
  79445. + /* Don't support SG list at this point */
  79446. + hcd->self.sg_tablesize = 0;
  79447. +#endif
  79448. + /*
  79449. + * Finish generic HCD initialization and start the HCD. This function
  79450. + * allocates the DMA buffer pool, registers the USB bus, requests the
  79451. + * IRQ line, and calls hcd_start method.
  79452. + */
  79453. +#ifdef PLATFORM_INTERFACE
  79454. + retval = usb_add_hcd(hcd, platform_get_irq(_dev, 0), IRQF_SHARED | IRQF_DISABLED);
  79455. +#else
  79456. + retval = usb_add_hcd(hcd, _dev->irq, IRQF_SHARED | IRQF_DISABLED);
  79457. +#endif
  79458. + if (retval < 0) {
  79459. + goto error2;
  79460. + }
  79461. +
  79462. + dwc_otg_hcd_set_priv_data(dwc_otg_hcd, hcd);
  79463. + return 0;
  79464. +
  79465. +error2:
  79466. + usb_put_hcd(hcd);
  79467. +error1:
  79468. + return retval;
  79469. +}
  79470. +
  79471. +/**
  79472. + * Removes the HCD.
  79473. + * Frees memory and resources associated with the HCD and deregisters the bus.
  79474. + */
  79475. +void hcd_remove(dwc_bus_dev_t *_dev)
  79476. +{
  79477. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  79478. + dwc_otg_hcd_t *dwc_otg_hcd;
  79479. + struct usb_hcd *hcd;
  79480. +
  79481. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD REMOVE otg_dev=%p\n", otg_dev);
  79482. +
  79483. + if (!otg_dev) {
  79484. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev NULL!\n", __func__);
  79485. + return;
  79486. + }
  79487. +
  79488. + dwc_otg_hcd = otg_dev->hcd;
  79489. +
  79490. + if (!dwc_otg_hcd) {
  79491. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->hcd NULL!\n", __func__);
  79492. + return;
  79493. + }
  79494. +
  79495. + hcd = dwc_otg_hcd_to_hcd(dwc_otg_hcd);
  79496. +
  79497. + if (!hcd) {
  79498. + DWC_DEBUGPL(DBG_ANY,
  79499. + "%s: dwc_otg_hcd_to_hcd(dwc_otg_hcd) NULL!\n",
  79500. + __func__);
  79501. + return;
  79502. + }
  79503. + usb_remove_hcd(hcd);
  79504. + dwc_otg_hcd_set_priv_data(dwc_otg_hcd, NULL);
  79505. + dwc_otg_hcd_remove(dwc_otg_hcd);
  79506. + usb_put_hcd(hcd);
  79507. +}
  79508. +
  79509. +/* =========================================================================
  79510. + * Linux HC Driver Functions
  79511. + * ========================================================================= */
  79512. +
  79513. +/** Initializes the DWC_otg controller and its root hub and prepares it for host
  79514. + * mode operation. Activates the root port. Returns 0 on success and a negative
  79515. + * error code on failure. */
  79516. +int hcd_start(struct usb_hcd *hcd)
  79517. +{
  79518. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  79519. + struct usb_bus *bus;
  79520. +
  79521. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD START\n");
  79522. + bus = hcd_to_bus(hcd);
  79523. +
  79524. + hcd->state = HC_STATE_RUNNING;
  79525. + if (dwc_otg_hcd_start(dwc_otg_hcd, &hcd_fops)) {
  79526. + return 0;
  79527. + }
  79528. +
  79529. + /* Initialize and connect root hub if one is not already attached */
  79530. + if (bus->root_hub) {
  79531. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Has Root Hub\n");
  79532. + /* Inform the HUB driver to resume. */
  79533. + usb_hcd_resume_root_hub(hcd);
  79534. + }
  79535. +
  79536. + return 0;
  79537. +}
  79538. +
  79539. +/**
  79540. + * Halts the DWC_otg host mode operations in a clean manner. USB transfers are
  79541. + * stopped.
  79542. + */
  79543. +void hcd_stop(struct usb_hcd *hcd)
  79544. +{
  79545. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  79546. +
  79547. + dwc_otg_hcd_stop(dwc_otg_hcd);
  79548. +}
  79549. +
  79550. +/** Returns the current frame number. */
  79551. +static int get_frame_number(struct usb_hcd *hcd)
  79552. +{
  79553. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  79554. +
  79555. + return dwc_otg_hcd_get_frame_number(dwc_otg_hcd);
  79556. +}
  79557. +
  79558. +#ifdef DEBUG
  79559. +static void dump_urb_info(struct urb *urb, char *fn_name)
  79560. +{
  79561. + DWC_PRINTF("%s, urb %p\n", fn_name, urb);
  79562. + DWC_PRINTF(" Device address: %d\n", usb_pipedevice(urb->pipe));
  79563. + DWC_PRINTF(" Endpoint: %d, %s\n", usb_pipeendpoint(urb->pipe),
  79564. + (usb_pipein(urb->pipe) ? "IN" : "OUT"));
  79565. + DWC_PRINTF(" Endpoint type: %s\n", ( {
  79566. + char *pipetype;
  79567. + switch (usb_pipetype(urb->pipe)) {
  79568. +case PIPE_CONTROL:
  79569. +pipetype = "CONTROL"; break; case PIPE_BULK:
  79570. +pipetype = "BULK"; break; case PIPE_INTERRUPT:
  79571. +pipetype = "INTERRUPT"; break; case PIPE_ISOCHRONOUS:
  79572. +pipetype = "ISOCHRONOUS"; break; default:
  79573. + pipetype = "UNKNOWN"; break;};
  79574. + pipetype;}
  79575. + )) ;
  79576. + DWC_PRINTF(" Speed: %s\n", ( {
  79577. + char *speed; switch (urb->dev->speed) {
  79578. +case USB_SPEED_HIGH:
  79579. +speed = "HIGH"; break; case USB_SPEED_FULL:
  79580. +speed = "FULL"; break; case USB_SPEED_LOW:
  79581. +speed = "LOW"; break; default:
  79582. + speed = "UNKNOWN"; break;};
  79583. + speed;}
  79584. + )) ;
  79585. + DWC_PRINTF(" Max packet size: %d\n",
  79586. + usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe)));
  79587. + DWC_PRINTF(" Data buffer length: %d\n", urb->transfer_buffer_length);
  79588. + DWC_PRINTF(" Transfer buffer: %p, Transfer DMA: %p\n",
  79589. + urb->transfer_buffer, (void *)urb->transfer_dma);
  79590. + DWC_PRINTF(" Setup buffer: %p, Setup DMA: %p\n",
  79591. + urb->setup_packet, (void *)urb->setup_dma);
  79592. + DWC_PRINTF(" Interval: %d\n", urb->interval);
  79593. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  79594. + int i;
  79595. + for (i = 0; i < urb->number_of_packets; i++) {
  79596. + DWC_PRINTF(" ISO Desc %d:\n", i);
  79597. + DWC_PRINTF(" offset: %d, length %d\n",
  79598. + urb->iso_frame_desc[i].offset,
  79599. + urb->iso_frame_desc[i].length);
  79600. + }
  79601. + }
  79602. +}
  79603. +#endif
  79604. +
  79605. +/** Starts processing a USB transfer request specified by a USB Request Block
  79606. + * (URB). mem_flags indicates the type of memory allocation to use while
  79607. + * processing this URB. */
  79608. +static int dwc_otg_urb_enqueue(struct usb_hcd *hcd,
  79609. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  79610. + struct usb_host_endpoint *ep,
  79611. +#endif
  79612. + struct urb *urb, gfp_t mem_flags)
  79613. +{
  79614. + int retval = 0;
  79615. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28)
  79616. + struct usb_host_endpoint *ep = urb->ep;
  79617. +#endif
  79618. + dwc_irqflags_t irqflags;
  79619. + void **ref_ep_hcpriv = &ep->hcpriv;
  79620. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  79621. + dwc_otg_hcd_urb_t *dwc_otg_urb;
  79622. + int i;
  79623. + int alloc_bandwidth = 0;
  79624. + uint8_t ep_type = 0;
  79625. + uint32_t flags = 0;
  79626. + void *buf;
  79627. +
  79628. +#ifdef DEBUG
  79629. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  79630. + dump_urb_info(urb, "dwc_otg_urb_enqueue");
  79631. + }
  79632. +#endif
  79633. +
  79634. + if (!urb->transfer_buffer && urb->transfer_buffer_length)
  79635. + return -EINVAL;
  79636. +
  79637. + if ((usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS)
  79638. + || (usb_pipetype(urb->pipe) == PIPE_INTERRUPT)) {
  79639. + if (!dwc_otg_hcd_is_bandwidth_allocated
  79640. + (dwc_otg_hcd, ref_ep_hcpriv)) {
  79641. + alloc_bandwidth = 1;
  79642. + }
  79643. + }
  79644. +
  79645. + switch (usb_pipetype(urb->pipe)) {
  79646. + case PIPE_CONTROL:
  79647. + ep_type = USB_ENDPOINT_XFER_CONTROL;
  79648. + break;
  79649. + case PIPE_ISOCHRONOUS:
  79650. + ep_type = USB_ENDPOINT_XFER_ISOC;
  79651. + break;
  79652. + case PIPE_BULK:
  79653. + ep_type = USB_ENDPOINT_XFER_BULK;
  79654. + break;
  79655. + case PIPE_INTERRUPT:
  79656. + ep_type = USB_ENDPOINT_XFER_INT;
  79657. + break;
  79658. + default:
  79659. + DWC_WARN("Wrong EP type - %d\n", usb_pipetype(urb->pipe));
  79660. + }
  79661. +
  79662. + /* # of packets is often 0 - do we really need to call this then? */
  79663. + dwc_otg_urb = dwc_otg_hcd_urb_alloc(dwc_otg_hcd,
  79664. + urb->number_of_packets,
  79665. + mem_flags == GFP_ATOMIC ? 1 : 0);
  79666. +
  79667. + if(dwc_otg_urb == NULL)
  79668. + return -ENOMEM;
  79669. +
  79670. + if (!dwc_otg_urb && urb->number_of_packets)
  79671. + return -ENOMEM;
  79672. +
  79673. + dwc_otg_hcd_urb_set_pipeinfo(dwc_otg_urb, usb_pipedevice(urb->pipe),
  79674. + usb_pipeendpoint(urb->pipe), ep_type,
  79675. + usb_pipein(urb->pipe),
  79676. + usb_maxpacket(urb->dev, urb->pipe,
  79677. + !(usb_pipein(urb->pipe))));
  79678. +
  79679. + buf = urb->transfer_buffer;
  79680. + if (hcd->self.uses_dma) {
  79681. + /*
  79682. + * Calculate virtual address from physical address,
  79683. + * because some class driver may not fill transfer_buffer.
  79684. + * In Buffer DMA mode virual address is used,
  79685. + * when handling non DWORD aligned buffers.
  79686. + */
  79687. + //buf = phys_to_virt(urb->transfer_dma);
  79688. + // DMA addresses are bus addresses not physical addresses!
  79689. + buf = dma_to_virt(&urb->dev->dev, urb->transfer_dma);
  79690. + }
  79691. +
  79692. + if (!(urb->transfer_flags & URB_NO_INTERRUPT))
  79693. + flags |= URB_GIVEBACK_ASAP;
  79694. + if (urb->transfer_flags & URB_ZERO_PACKET)
  79695. + flags |= URB_SEND_ZERO_PACKET;
  79696. +
  79697. + dwc_otg_hcd_urb_set_params(dwc_otg_urb, urb, buf,
  79698. + urb->transfer_dma,
  79699. + urb->transfer_buffer_length,
  79700. + urb->setup_packet,
  79701. + urb->setup_dma, flags, urb->interval);
  79702. +
  79703. + for (i = 0; i < urb->number_of_packets; ++i) {
  79704. + dwc_otg_hcd_urb_set_iso_desc_params(dwc_otg_urb, i,
  79705. + urb->
  79706. + iso_frame_desc[i].offset,
  79707. + urb->
  79708. + iso_frame_desc[i].length);
  79709. + }
  79710. +
  79711. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &irqflags);
  79712. + urb->hcpriv = dwc_otg_urb;
  79713. +#if USB_URB_EP_LINKING
  79714. + retval = usb_hcd_link_urb_to_ep(hcd, urb);
  79715. + if (0 == retval)
  79716. +#endif
  79717. + {
  79718. + retval = dwc_otg_hcd_urb_enqueue(dwc_otg_hcd, dwc_otg_urb,
  79719. + /*(dwc_otg_qh_t **)*/
  79720. + ref_ep_hcpriv, 1);
  79721. + if (0 == retval) {
  79722. + if (alloc_bandwidth) {
  79723. + allocate_bus_bandwidth(hcd,
  79724. + dwc_otg_hcd_get_ep_bandwidth(
  79725. + dwc_otg_hcd, *ref_ep_hcpriv),
  79726. + urb);
  79727. + }
  79728. + } else {
  79729. + DWC_DEBUGPL(DBG_HCD, "DWC OTG dwc_otg_hcd_urb_enqueue failed rc %d\n", retval);
  79730. +#if USB_URB_EP_LINKING
  79731. + usb_hcd_unlink_urb_from_ep(hcd, urb);
  79732. +#endif
  79733. + DWC_FREE(dwc_otg_urb);
  79734. + urb->hcpriv = NULL;
  79735. + if (retval == -DWC_E_NO_DEVICE)
  79736. + retval = -ENODEV;
  79737. + }
  79738. + }
  79739. +#if USB_URB_EP_LINKING
  79740. + else
  79741. + {
  79742. + DWC_FREE(dwc_otg_urb);
  79743. + urb->hcpriv = NULL;
  79744. + }
  79745. +#endif
  79746. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, irqflags);
  79747. + return retval;
  79748. +}
  79749. +
  79750. +/** Aborts/cancels a USB transfer request. Always returns 0 to indicate
  79751. + * success. */
  79752. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  79753. +static int dwc_otg_urb_dequeue(struct usb_hcd *hcd, struct urb *urb)
  79754. +#else
  79755. +static int dwc_otg_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
  79756. +#endif
  79757. +{
  79758. + dwc_irqflags_t flags;
  79759. + dwc_otg_hcd_t *dwc_otg_hcd;
  79760. + int rc;
  79761. +
  79762. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Dequeue\n");
  79763. +
  79764. + dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  79765. +
  79766. +#ifdef DEBUG
  79767. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  79768. + dump_urb_info(urb, "dwc_otg_urb_dequeue");
  79769. + }
  79770. +#endif
  79771. +
  79772. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &flags);
  79773. + rc = usb_hcd_check_unlink_urb(hcd, urb, status);
  79774. + if (0 == rc) {
  79775. + if(urb->hcpriv != NULL) {
  79776. + dwc_otg_hcd_urb_dequeue(dwc_otg_hcd,
  79777. + (dwc_otg_hcd_urb_t *)urb->hcpriv);
  79778. +
  79779. + DWC_FREE(urb->hcpriv);
  79780. + urb->hcpriv = NULL;
  79781. + }
  79782. + }
  79783. +
  79784. + if (0 == rc) {
  79785. + /* Higher layer software sets URB status. */
  79786. +#if USB_URB_EP_LINKING
  79787. + usb_hcd_unlink_urb_from_ep(hcd, urb);
  79788. +#endif
  79789. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, flags);
  79790. +
  79791. +
  79792. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  79793. + usb_hcd_giveback_urb(hcd, urb);
  79794. +#else
  79795. + usb_hcd_giveback_urb(hcd, urb, status);
  79796. +#endif
  79797. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  79798. + DWC_PRINTF("Called usb_hcd_giveback_urb() \n");
  79799. + DWC_PRINTF(" 1urb->status = %d\n", urb->status);
  79800. + }
  79801. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Dequeue OK\n");
  79802. + } else {
  79803. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, flags);
  79804. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Dequeue failed - rc %d\n",
  79805. + rc);
  79806. + }
  79807. +
  79808. + return rc;
  79809. +}
  79810. +
  79811. +/* Frees resources in the DWC_otg controller related to a given endpoint. Also
  79812. + * clears state in the HCD related to the endpoint. Any URBs for the endpoint
  79813. + * must already be dequeued. */
  79814. +static void endpoint_disable(struct usb_hcd *hcd, struct usb_host_endpoint *ep)
  79815. +{
  79816. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  79817. +
  79818. + DWC_DEBUGPL(DBG_HCD,
  79819. + "DWC OTG HCD EP DISABLE: _bEndpointAddress=0x%02x, "
  79820. + "endpoint=%d\n", ep->desc.bEndpointAddress,
  79821. + dwc_ep_addr_to_endpoint(ep->desc.bEndpointAddress));
  79822. + dwc_otg_hcd_endpoint_disable(dwc_otg_hcd, ep->hcpriv, 250);
  79823. + ep->hcpriv = NULL;
  79824. +}
  79825. +
  79826. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
  79827. +/* Resets endpoint specific parameter values, in current version used to reset
  79828. + * the data toggle(as a WA). This function can be called from usb_clear_halt routine */
  79829. +static void endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep)
  79830. +{
  79831. + dwc_irqflags_t flags;
  79832. + struct usb_device *udev = NULL;
  79833. + int epnum = usb_endpoint_num(&ep->desc);
  79834. + int is_out = usb_endpoint_dir_out(&ep->desc);
  79835. + int is_control = usb_endpoint_xfer_control(&ep->desc);
  79836. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  79837. + struct device *dev = DWC_OTG_OS_GETDEV(dwc_otg_hcd->otg_dev->os_dep);
  79838. +
  79839. + if (dev)
  79840. + udev = to_usb_device(dev);
  79841. + else
  79842. + return;
  79843. +
  79844. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD EP RESET: Endpoint Num=0x%02d\n", epnum);
  79845. +
  79846. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &flags);
  79847. + usb_settoggle(udev, epnum, is_out, 0);
  79848. + if (is_control)
  79849. + usb_settoggle(udev, epnum, !is_out, 0);
  79850. +
  79851. + if (ep->hcpriv) {
  79852. + dwc_otg_hcd_endpoint_reset(dwc_otg_hcd, ep->hcpriv);
  79853. + }
  79854. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, flags);
  79855. +}
  79856. +#endif
  79857. +
  79858. +/** Handles host mode interrupts for the DWC_otg controller. Returns IRQ_NONE if
  79859. + * there was no interrupt to handle. Returns IRQ_HANDLED if there was a valid
  79860. + * interrupt.
  79861. + *
  79862. + * This function is called by the USB core when an interrupt occurs */
  79863. +static irqreturn_t dwc_otg_hcd_irq(struct usb_hcd *hcd)
  79864. +{
  79865. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  79866. + int32_t retval = dwc_otg_hcd_handle_intr(dwc_otg_hcd);
  79867. + if (retval != 0) {
  79868. + S3C2410X_CLEAR_EINTPEND();
  79869. + }
  79870. + return IRQ_RETVAL(retval);
  79871. +}
  79872. +
  79873. +/** Creates Status Change bitmap for the root hub and root port. The bitmap is
  79874. + * returned in buf. Bit 0 is the status change indicator for the root hub. Bit 1
  79875. + * is the status change indicator for the single root port. Returns 1 if either
  79876. + * change indicator is 1, otherwise returns 0. */
  79877. +int hub_status_data(struct usb_hcd *hcd, char *buf)
  79878. +{
  79879. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  79880. +
  79881. + buf[0] = 0;
  79882. + buf[0] |= (dwc_otg_hcd_is_status_changed(dwc_otg_hcd, 1)) << 1;
  79883. +
  79884. + return (buf[0] != 0);
  79885. +}
  79886. +
  79887. +/** Handles hub class-specific requests. */
  79888. +int hub_control(struct usb_hcd *hcd,
  79889. + u16 typeReq, u16 wValue, u16 wIndex, char *buf, u16 wLength)
  79890. +{
  79891. + int retval;
  79892. +
  79893. + retval = dwc_otg_hcd_hub_control(hcd_to_dwc_otg_hcd(hcd),
  79894. + typeReq, wValue, wIndex, buf, wLength);
  79895. +
  79896. + switch (retval) {
  79897. + case -DWC_E_INVALID:
  79898. + retval = -EINVAL;
  79899. + break;
  79900. + }
  79901. +
  79902. + return retval;
  79903. +}
  79904. +
  79905. +#endif /* DWC_DEVICE_ONLY */
  79906. diff -Nur linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c
  79907. --- linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c 1970-01-01 01:00:00.000000000 +0100
  79908. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c 2014-04-24 15:37:13.314990533 +0200
  79909. @@ -0,0 +1,942 @@
  79910. +/* ==========================================================================
  79911. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_queue.c $
  79912. + * $Revision: #44 $
  79913. + * $Date: 2011/10/26 $
  79914. + * $Change: 1873028 $
  79915. + *
  79916. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  79917. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  79918. + * otherwise expressly agreed to in writing between Synopsys and you.
  79919. + *
  79920. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  79921. + * any End User Software License Agreement or Agreement for Licensed Product
  79922. + * with Synopsys or any supplement thereto. You are permitted to use and
  79923. + * redistribute this Software in source and binary forms, with or without
  79924. + * modification, provided that redistributions of source code must retain this
  79925. + * notice. You may not view, use, disclose, copy or distribute this file or
  79926. + * any information contained herein except pursuant to this license grant from
  79927. + * Synopsys. If you do not agree with this notice, including the disclaimer
  79928. + * below, then you are not authorized to use the Software.
  79929. + *
  79930. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  79931. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  79932. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  79933. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  79934. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  79935. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  79936. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  79937. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  79938. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  79939. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  79940. + * DAMAGE.
  79941. + * ========================================================================== */
  79942. +#ifndef DWC_DEVICE_ONLY
  79943. +
  79944. +/**
  79945. + * @file
  79946. + *
  79947. + * This file contains the functions to manage Queue Heads and Queue
  79948. + * Transfer Descriptors.
  79949. + */
  79950. +
  79951. +#include "dwc_otg_hcd.h"
  79952. +#include "dwc_otg_regs.h"
  79953. +
  79954. +extern bool microframe_schedule;
  79955. +
  79956. +/**
  79957. + * Free each QTD in the QH's QTD-list then free the QH. QH should already be
  79958. + * removed from a list. QTD list should already be empty if called from URB
  79959. + * Dequeue.
  79960. + *
  79961. + * @param hcd HCD instance.
  79962. + * @param qh The QH to free.
  79963. + */
  79964. +void dwc_otg_hcd_qh_free(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  79965. +{
  79966. + dwc_otg_qtd_t *qtd, *qtd_tmp;
  79967. +
  79968. + /* Free each QTD in the QTD list */
  79969. + DWC_SPINLOCK(hcd->lock);
  79970. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &qh->qtd_list, qtd_list_entry) {
  79971. + DWC_CIRCLEQ_REMOVE(&qh->qtd_list, qtd, qtd_list_entry);
  79972. + dwc_otg_hcd_qtd_free(qtd);
  79973. + }
  79974. +
  79975. + if (hcd->core_if->dma_desc_enable) {
  79976. + dwc_otg_hcd_qh_free_ddma(hcd, qh);
  79977. + } else if (qh->dw_align_buf) {
  79978. + uint32_t buf_size;
  79979. + if (qh->ep_type == UE_ISOCHRONOUS) {
  79980. + buf_size = 4096;
  79981. + } else {
  79982. + buf_size = hcd->core_if->core_params->max_transfer_size;
  79983. + }
  79984. + DWC_DMA_FREE(buf_size, qh->dw_align_buf, qh->dw_align_buf_dma);
  79985. + }
  79986. +
  79987. + DWC_FREE(qh);
  79988. + DWC_SPINUNLOCK(hcd->lock);
  79989. + return;
  79990. +}
  79991. +
  79992. +#define BitStuffTime(bytecount) ((8 * 7* bytecount) / 6)
  79993. +#define HS_HOST_DELAY 5 /* nanoseconds */
  79994. +#define FS_LS_HOST_DELAY 1000 /* nanoseconds */
  79995. +#define HUB_LS_SETUP 333 /* nanoseconds */
  79996. +#define NS_TO_US(ns) ((ns + 500) / 1000)
  79997. + /* convert & round nanoseconds to microseconds */
  79998. +
  79999. +static uint32_t calc_bus_time(int speed, int is_in, int is_isoc, int bytecount)
  80000. +{
  80001. + unsigned long retval;
  80002. +
  80003. + switch (speed) {
  80004. + case USB_SPEED_HIGH:
  80005. + if (is_isoc) {
  80006. + retval =
  80007. + ((38 * 8 * 2083) +
  80008. + (2083 * (3 + BitStuffTime(bytecount)))) / 1000 +
  80009. + HS_HOST_DELAY;
  80010. + } else {
  80011. + retval =
  80012. + ((55 * 8 * 2083) +
  80013. + (2083 * (3 + BitStuffTime(bytecount)))) / 1000 +
  80014. + HS_HOST_DELAY;
  80015. + }
  80016. + break;
  80017. + case USB_SPEED_FULL:
  80018. + if (is_isoc) {
  80019. + retval =
  80020. + (8354 * (31 + 10 * BitStuffTime(bytecount))) / 1000;
  80021. + if (is_in) {
  80022. + retval = 7268 + FS_LS_HOST_DELAY + retval;
  80023. + } else {
  80024. + retval = 6265 + FS_LS_HOST_DELAY + retval;
  80025. + }
  80026. + } else {
  80027. + retval =
  80028. + (8354 * (31 + 10 * BitStuffTime(bytecount))) / 1000;
  80029. + retval = 9107 + FS_LS_HOST_DELAY + retval;
  80030. + }
  80031. + break;
  80032. + case USB_SPEED_LOW:
  80033. + if (is_in) {
  80034. + retval =
  80035. + (67667 * (31 + 10 * BitStuffTime(bytecount))) /
  80036. + 1000;
  80037. + retval =
  80038. + 64060 + (2 * HUB_LS_SETUP) + FS_LS_HOST_DELAY +
  80039. + retval;
  80040. + } else {
  80041. + retval =
  80042. + (66700 * (31 + 10 * BitStuffTime(bytecount))) /
  80043. + 1000;
  80044. + retval =
  80045. + 64107 + (2 * HUB_LS_SETUP) + FS_LS_HOST_DELAY +
  80046. + retval;
  80047. + }
  80048. + break;
  80049. + default:
  80050. + DWC_WARN("Unknown device speed\n");
  80051. + retval = -1;
  80052. + }
  80053. +
  80054. + return NS_TO_US(retval);
  80055. +}
  80056. +
  80057. +/**
  80058. + * Initializes a QH structure.
  80059. + *
  80060. + * @param hcd The HCD state structure for the DWC OTG controller.
  80061. + * @param qh The QH to init.
  80062. + * @param urb Holds the information about the device/endpoint that we need
  80063. + * to initialize the QH.
  80064. + */
  80065. +#define SCHEDULE_SLOP 10
  80066. +void qh_init(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh, dwc_otg_hcd_urb_t * urb)
  80067. +{
  80068. + char *speed, *type;
  80069. + int dev_speed;
  80070. + uint32_t hub_addr, hub_port;
  80071. +
  80072. + dwc_memset(qh, 0, sizeof(dwc_otg_qh_t));
  80073. +
  80074. + /* Initialize QH */
  80075. + qh->ep_type = dwc_otg_hcd_get_pipe_type(&urb->pipe_info);
  80076. + qh->ep_is_in = dwc_otg_hcd_is_pipe_in(&urb->pipe_info) ? 1 : 0;
  80077. +
  80078. + qh->data_toggle = DWC_OTG_HC_PID_DATA0;
  80079. + qh->maxp = dwc_otg_hcd_get_mps(&urb->pipe_info);
  80080. + DWC_CIRCLEQ_INIT(&qh->qtd_list);
  80081. + DWC_LIST_INIT(&qh->qh_list_entry);
  80082. + qh->channel = NULL;
  80083. +
  80084. + /* FS/LS Enpoint on HS Hub
  80085. + * NOT virtual root hub */
  80086. + dev_speed = hcd->fops->speed(hcd, urb->priv);
  80087. +
  80088. + hcd->fops->hub_info(hcd, urb->priv, &hub_addr, &hub_port);
  80089. + qh->do_split = 0;
  80090. + if (microframe_schedule)
  80091. + qh->speed = dev_speed;
  80092. +
  80093. + qh->nak_frame = 0xffff;
  80094. +
  80095. + if (((dev_speed == USB_SPEED_LOW) ||
  80096. + (dev_speed == USB_SPEED_FULL)) &&
  80097. + (hub_addr != 0 && hub_addr != 1)) {
  80098. + DWC_DEBUGPL(DBG_HCD,
  80099. + "QH init: EP %d: TT found at hub addr %d, for port %d\n",
  80100. + dwc_otg_hcd_get_ep_num(&urb->pipe_info), hub_addr,
  80101. + hub_port);
  80102. + qh->do_split = 1;
  80103. + qh->skip_count = 0;
  80104. + }
  80105. +
  80106. + if (qh->ep_type == UE_INTERRUPT || qh->ep_type == UE_ISOCHRONOUS) {
  80107. + /* Compute scheduling parameters once and save them. */
  80108. + hprt0_data_t hprt;
  80109. +
  80110. + /** @todo Account for split transfers in the bus time. */
  80111. + int bytecount =
  80112. + dwc_hb_mult(qh->maxp) * dwc_max_packet(qh->maxp);
  80113. +
  80114. + qh->usecs =
  80115. + calc_bus_time((qh->do_split ? USB_SPEED_HIGH : dev_speed),
  80116. + qh->ep_is_in, (qh->ep_type == UE_ISOCHRONOUS),
  80117. + bytecount);
  80118. + /* Start in a slightly future (micro)frame. */
  80119. + qh->sched_frame = dwc_frame_num_inc(hcd->frame_number,
  80120. + SCHEDULE_SLOP);
  80121. + qh->interval = urb->interval;
  80122. +
  80123. +#if 0
  80124. + /* Increase interrupt polling rate for debugging. */
  80125. + if (qh->ep_type == UE_INTERRUPT) {
  80126. + qh->interval = 8;
  80127. + }
  80128. +#endif
  80129. + hprt.d32 = DWC_READ_REG32(hcd->core_if->host_if->hprt0);
  80130. + if ((hprt.b.prtspd == DWC_HPRT0_PRTSPD_HIGH_SPEED) &&
  80131. + ((dev_speed == USB_SPEED_LOW) ||
  80132. + (dev_speed == USB_SPEED_FULL))) {
  80133. + qh->interval *= 8;
  80134. + qh->sched_frame |= 0x7;
  80135. + qh->start_split_frame = qh->sched_frame;
  80136. + }
  80137. +
  80138. + }
  80139. +
  80140. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD QH Initialized\n");
  80141. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - qh = %p\n", qh);
  80142. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Device Address = %d\n",
  80143. + dwc_otg_hcd_get_dev_addr(&urb->pipe_info));
  80144. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Endpoint %d, %s\n",
  80145. + dwc_otg_hcd_get_ep_num(&urb->pipe_info),
  80146. + dwc_otg_hcd_is_pipe_in(&urb->pipe_info) ? "IN" : "OUT");
  80147. + switch (dev_speed) {
  80148. + case USB_SPEED_LOW:
  80149. + qh->dev_speed = DWC_OTG_EP_SPEED_LOW;
  80150. + speed = "low";
  80151. + break;
  80152. + case USB_SPEED_FULL:
  80153. + qh->dev_speed = DWC_OTG_EP_SPEED_FULL;
  80154. + speed = "full";
  80155. + break;
  80156. + case USB_SPEED_HIGH:
  80157. + qh->dev_speed = DWC_OTG_EP_SPEED_HIGH;
  80158. + speed = "high";
  80159. + break;
  80160. + default:
  80161. + speed = "?";
  80162. + break;
  80163. + }
  80164. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Speed = %s\n", speed);
  80165. +
  80166. + switch (qh->ep_type) {
  80167. + case UE_ISOCHRONOUS:
  80168. + type = "isochronous";
  80169. + break;
  80170. + case UE_INTERRUPT:
  80171. + type = "interrupt";
  80172. + break;
  80173. + case UE_CONTROL:
  80174. + type = "control";
  80175. + break;
  80176. + case UE_BULK:
  80177. + type = "bulk";
  80178. + break;
  80179. + default:
  80180. + type = "?";
  80181. + break;
  80182. + }
  80183. +
  80184. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Type = %s\n", type);
  80185. +
  80186. +#ifdef DEBUG
  80187. + if (qh->ep_type == UE_INTERRUPT) {
  80188. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - usecs = %d\n",
  80189. + qh->usecs);
  80190. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - interval = %d\n",
  80191. + qh->interval);
  80192. + }
  80193. +#endif
  80194. +
  80195. +}
  80196. +
  80197. +/**
  80198. + * This function allocates and initializes a QH.
  80199. + *
  80200. + * @param hcd The HCD state structure for the DWC OTG controller.
  80201. + * @param urb Holds the information about the device/endpoint that we need
  80202. + * to initialize the QH.
  80203. + * @param atomic_alloc Flag to do atomic allocation if needed
  80204. + *
  80205. + * @return Returns pointer to the newly allocated QH, or NULL on error. */
  80206. +dwc_otg_qh_t *dwc_otg_hcd_qh_create(dwc_otg_hcd_t * hcd,
  80207. + dwc_otg_hcd_urb_t * urb, int atomic_alloc)
  80208. +{
  80209. + dwc_otg_qh_t *qh;
  80210. +
  80211. + /* Allocate memory */
  80212. + /** @todo add memflags argument */
  80213. + qh = dwc_otg_hcd_qh_alloc(atomic_alloc);
  80214. + if (qh == NULL) {
  80215. + DWC_ERROR("qh allocation failed");
  80216. + return NULL;
  80217. + }
  80218. +
  80219. + qh_init(hcd, qh, urb);
  80220. +
  80221. + if (hcd->core_if->dma_desc_enable
  80222. + && (dwc_otg_hcd_qh_init_ddma(hcd, qh) < 0)) {
  80223. + dwc_otg_hcd_qh_free(hcd, qh);
  80224. + return NULL;
  80225. + }
  80226. +
  80227. + return qh;
  80228. +}
  80229. +
  80230. +/* microframe_schedule=0 start */
  80231. +
  80232. +/**
  80233. + * Checks that a channel is available for a periodic transfer.
  80234. + *
  80235. + * @return 0 if successful, negative error code otherise.
  80236. + */
  80237. +static int periodic_channel_available(dwc_otg_hcd_t * hcd)
  80238. +{
  80239. + /*
  80240. + * Currently assuming that there is a dedicated host channnel for each
  80241. + * periodic transaction plus at least one host channel for
  80242. + * non-periodic transactions.
  80243. + */
  80244. + int status;
  80245. + int num_channels;
  80246. +
  80247. + num_channels = hcd->core_if->core_params->host_channels;
  80248. + if ((hcd->periodic_channels + hcd->non_periodic_channels < num_channels)
  80249. + && (hcd->periodic_channels < num_channels - 1)) {
  80250. + status = 0;
  80251. + } else {
  80252. + DWC_INFO("%s: Total channels: %d, Periodic: %d, Non-periodic: %d\n",
  80253. + __func__, num_channels, hcd->periodic_channels, hcd->non_periodic_channels); //NOTICE
  80254. + status = -DWC_E_NO_SPACE;
  80255. + }
  80256. +
  80257. + return status;
  80258. +}
  80259. +
  80260. +/**
  80261. + * Checks that there is sufficient bandwidth for the specified QH in the
  80262. + * periodic schedule. For simplicity, this calculation assumes that all the
  80263. + * transfers in the periodic schedule may occur in the same (micro)frame.
  80264. + *
  80265. + * @param hcd The HCD state structure for the DWC OTG controller.
  80266. + * @param qh QH containing periodic bandwidth required.
  80267. + *
  80268. + * @return 0 if successful, negative error code otherwise.
  80269. + */
  80270. +static int check_periodic_bandwidth(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  80271. +{
  80272. + int status;
  80273. + int16_t max_claimed_usecs;
  80274. +
  80275. + status = 0;
  80276. +
  80277. + if ((qh->dev_speed == DWC_OTG_EP_SPEED_HIGH) || qh->do_split) {
  80278. + /*
  80279. + * High speed mode.
  80280. + * Max periodic usecs is 80% x 125 usec = 100 usec.
  80281. + */
  80282. +
  80283. + max_claimed_usecs = 100 - qh->usecs;
  80284. + } else {
  80285. + /*
  80286. + * Full speed mode.
  80287. + * Max periodic usecs is 90% x 1000 usec = 900 usec.
  80288. + */
  80289. + max_claimed_usecs = 900 - qh->usecs;
  80290. + }
  80291. +
  80292. + if (hcd->periodic_usecs > max_claimed_usecs) {
  80293. + DWC_INFO("%s: already claimed usecs %d, required usecs %d\n", __func__, hcd->periodic_usecs, qh->usecs); //NOTICE
  80294. + status = -DWC_E_NO_SPACE;
  80295. + }
  80296. +
  80297. + return status;
  80298. +}
  80299. +
  80300. +/* microframe_schedule=0 end */
  80301. +
  80302. +/**
  80303. + * Microframe scheduler
  80304. + * track the total use in hcd->frame_usecs
  80305. + * keep each qh use in qh->frame_usecs
  80306. + * when surrendering the qh then donate the time back
  80307. + */
  80308. +const unsigned short max_uframe_usecs[]={ 100, 100, 100, 100, 100, 100, 30, 0 };
  80309. +
  80310. +/*
  80311. + * called from dwc_otg_hcd.c:dwc_otg_hcd_init
  80312. + */
  80313. +int init_hcd_usecs(dwc_otg_hcd_t *_hcd)
  80314. +{
  80315. + int i;
  80316. + for (i=0; i<8; i++) {
  80317. + _hcd->frame_usecs[i] = max_uframe_usecs[i];
  80318. + }
  80319. + return 0;
  80320. +}
  80321. +
  80322. +static int find_single_uframe(dwc_otg_hcd_t * _hcd, dwc_otg_qh_t * _qh)
  80323. +{
  80324. + int i;
  80325. + unsigned short utime;
  80326. + int t_left;
  80327. + int ret;
  80328. + int done;
  80329. +
  80330. + ret = -1;
  80331. + utime = _qh->usecs;
  80332. + t_left = utime;
  80333. + i = 0;
  80334. + done = 0;
  80335. + while (done == 0) {
  80336. + /* At the start _hcd->frame_usecs[i] = max_uframe_usecs[i]; */
  80337. + if (utime <= _hcd->frame_usecs[i]) {
  80338. + _hcd->frame_usecs[i] -= utime;
  80339. + _qh->frame_usecs[i] += utime;
  80340. + t_left -= utime;
  80341. + ret = i;
  80342. + done = 1;
  80343. + return ret;
  80344. + } else {
  80345. + i++;
  80346. + if (i == 8) {
  80347. + done = 1;
  80348. + ret = -1;
  80349. + }
  80350. + }
  80351. + }
  80352. + return ret;
  80353. + }
  80354. +
  80355. +/*
  80356. + * use this for FS apps that can span multiple uframes
  80357. + */
  80358. +static int find_multi_uframe(dwc_otg_hcd_t * _hcd, dwc_otg_qh_t * _qh)
  80359. +{
  80360. + int i;
  80361. + int j;
  80362. + unsigned short utime;
  80363. + int t_left;
  80364. + int ret;
  80365. + int done;
  80366. + unsigned short xtime;
  80367. +
  80368. + ret = -1;
  80369. + utime = _qh->usecs;
  80370. + t_left = utime;
  80371. + i = 0;
  80372. + done = 0;
  80373. +loop:
  80374. + while (done == 0) {
  80375. + if(_hcd->frame_usecs[i] <= 0) {
  80376. + i++;
  80377. + if (i == 8) {
  80378. + done = 1;
  80379. + ret = -1;
  80380. + }
  80381. + goto loop;
  80382. + }
  80383. +
  80384. + /*
  80385. + * we need n consecutive slots
  80386. + * so use j as a start slot j plus j+1 must be enough time (for now)
  80387. + */
  80388. + xtime= _hcd->frame_usecs[i];
  80389. + for (j = i+1 ; j < 8 ; j++ ) {
  80390. + /*
  80391. + * if we add this frame remaining time to xtime we may
  80392. + * be OK, if not we need to test j for a complete frame
  80393. + */
  80394. + if ((xtime+_hcd->frame_usecs[j]) < utime) {
  80395. + if (_hcd->frame_usecs[j] < max_uframe_usecs[j]) {
  80396. + j = 8;
  80397. + ret = -1;
  80398. + continue;
  80399. + }
  80400. + }
  80401. + if (xtime >= utime) {
  80402. + ret = i;
  80403. + j = 8; /* stop loop with a good value ret */
  80404. + continue;
  80405. + }
  80406. + /* add the frame time to x time */
  80407. + xtime += _hcd->frame_usecs[j];
  80408. + /* we must have a fully available next frame or break */
  80409. + if ((xtime < utime)
  80410. + && (_hcd->frame_usecs[j] == max_uframe_usecs[j])) {
  80411. + ret = -1;
  80412. + j = 8; /* stop loop with a bad value ret */
  80413. + continue;
  80414. + }
  80415. + }
  80416. + if (ret >= 0) {
  80417. + t_left = utime;
  80418. + for (j = i; (t_left>0) && (j < 8); j++ ) {
  80419. + t_left -= _hcd->frame_usecs[j];
  80420. + if ( t_left <= 0 ) {
  80421. + _qh->frame_usecs[j] += _hcd->frame_usecs[j] + t_left;
  80422. + _hcd->frame_usecs[j]= -t_left;
  80423. + ret = i;
  80424. + done = 1;
  80425. + } else {
  80426. + _qh->frame_usecs[j] += _hcd->frame_usecs[j];
  80427. + _hcd->frame_usecs[j] = 0;
  80428. + }
  80429. + }
  80430. + } else {
  80431. + i++;
  80432. + if (i == 8) {
  80433. + done = 1;
  80434. + ret = -1;
  80435. + }
  80436. + }
  80437. + }
  80438. + return ret;
  80439. +}
  80440. +
  80441. +static int find_uframe(dwc_otg_hcd_t * _hcd, dwc_otg_qh_t * _qh)
  80442. +{
  80443. + int ret;
  80444. + ret = -1;
  80445. +
  80446. + if (_qh->speed == USB_SPEED_HIGH) {
  80447. + /* if this is a hs transaction we need a full frame */
  80448. + ret = find_single_uframe(_hcd, _qh);
  80449. + } else {
  80450. + /* if this is a fs transaction we may need a sequence of frames */
  80451. + ret = find_multi_uframe(_hcd, _qh);
  80452. + }
  80453. + return ret;
  80454. +}
  80455. +
  80456. +/**
  80457. + * Checks that the max transfer size allowed in a host channel is large enough
  80458. + * to handle the maximum data transfer in a single (micro)frame for a periodic
  80459. + * transfer.
  80460. + *
  80461. + * @param hcd The HCD state structure for the DWC OTG controller.
  80462. + * @param qh QH for a periodic endpoint.
  80463. + *
  80464. + * @return 0 if successful, negative error code otherwise.
  80465. + */
  80466. +static int check_max_xfer_size(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  80467. +{
  80468. + int status;
  80469. + uint32_t max_xfer_size;
  80470. + uint32_t max_channel_xfer_size;
  80471. +
  80472. + status = 0;
  80473. +
  80474. + max_xfer_size = dwc_max_packet(qh->maxp) * dwc_hb_mult(qh->maxp);
  80475. + max_channel_xfer_size = hcd->core_if->core_params->max_transfer_size;
  80476. +
  80477. + if (max_xfer_size > max_channel_xfer_size) {
  80478. + DWC_INFO("%s: Periodic xfer length %d > " "max xfer length for channel %d\n",
  80479. + __func__, max_xfer_size, max_channel_xfer_size); //NOTICE
  80480. + status = -DWC_E_NO_SPACE;
  80481. + }
  80482. +
  80483. + return status;
  80484. +}
  80485. +
  80486. +
  80487. +
  80488. +/**
  80489. + * Schedules an interrupt or isochronous transfer in the periodic schedule.
  80490. + *
  80491. + * @param hcd The HCD state structure for the DWC OTG controller.
  80492. + * @param qh QH for the periodic transfer. The QH should already contain the
  80493. + * scheduling information.
  80494. + *
  80495. + * @return 0 if successful, negative error code otherwise.
  80496. + */
  80497. +static int schedule_periodic(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  80498. +{
  80499. + int status = 0;
  80500. +
  80501. + if (microframe_schedule) {
  80502. + int frame;
  80503. + status = find_uframe(hcd, qh);
  80504. + frame = -1;
  80505. + if (status == 0) {
  80506. + frame = 7;
  80507. + } else {
  80508. + if (status > 0 )
  80509. + frame = status-1;
  80510. + }
  80511. +
  80512. + /* Set the new frame up */
  80513. + if (frame > -1) {
  80514. + qh->sched_frame &= ~0x7;
  80515. + qh->sched_frame |= (frame & 7);
  80516. + }
  80517. +
  80518. + if (status != -1)
  80519. + status = 0;
  80520. + } else {
  80521. + status = periodic_channel_available(hcd);
  80522. + if (status) {
  80523. + DWC_INFO("%s: No host channel available for periodic " "transfer.\n", __func__); //NOTICE
  80524. + return status;
  80525. + }
  80526. +
  80527. + status = check_periodic_bandwidth(hcd, qh);
  80528. + }
  80529. + if (status) {
  80530. + DWC_INFO("%s: Insufficient periodic bandwidth for "
  80531. + "periodic transfer.\n", __func__);
  80532. + return status;
  80533. + }
  80534. + status = check_max_xfer_size(hcd, qh);
  80535. + if (status) {
  80536. + DWC_INFO("%s: Channel max transfer size too small "
  80537. + "for periodic transfer.\n", __func__);
  80538. + return status;
  80539. + }
  80540. +
  80541. + if (hcd->core_if->dma_desc_enable) {
  80542. + /* Don't rely on SOF and start in ready schedule */
  80543. + DWC_LIST_INSERT_TAIL(&hcd->periodic_sched_ready, &qh->qh_list_entry);
  80544. + }
  80545. + else {
  80546. + if(DWC_LIST_EMPTY(&hcd->periodic_sched_inactive) || dwc_frame_num_le(qh->sched_frame, hcd->fiq_state->next_sched_frame))
  80547. + {
  80548. + hcd->fiq_state->next_sched_frame = qh->sched_frame;
  80549. +
  80550. + }
  80551. + /* Always start in the inactive schedule. */
  80552. + DWC_LIST_INSERT_TAIL(&hcd->periodic_sched_inactive, &qh->qh_list_entry);
  80553. + }
  80554. +
  80555. + if (!microframe_schedule) {
  80556. + /* Reserve the periodic channel. */
  80557. + hcd->periodic_channels++;
  80558. + }
  80559. +
  80560. + /* Update claimed usecs per (micro)frame. */
  80561. + hcd->periodic_usecs += qh->usecs;
  80562. +
  80563. + return status;
  80564. +}
  80565. +
  80566. +
  80567. +/**
  80568. + * This function adds a QH to either the non periodic or periodic schedule if
  80569. + * it is not already in the schedule. If the QH is already in the schedule, no
  80570. + * action is taken.
  80571. + *
  80572. + * @return 0 if successful, negative error code otherwise.
  80573. + */
  80574. +int dwc_otg_hcd_qh_add(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  80575. +{
  80576. + int status = 0;
  80577. + gintmsk_data_t intr_mask = {.d32 = 0 };
  80578. +
  80579. + if (!DWC_LIST_EMPTY(&qh->qh_list_entry)) {
  80580. + /* QH already in a schedule. */
  80581. + return status;
  80582. + }
  80583. +
  80584. + /* Add the new QH to the appropriate schedule */
  80585. + if (dwc_qh_is_non_per(qh)) {
  80586. + /* Always start in the inactive schedule. */
  80587. + DWC_LIST_INSERT_TAIL(&hcd->non_periodic_sched_inactive,
  80588. + &qh->qh_list_entry);
  80589. + //hcd->fiq_state->kick_np_queues = 1;
  80590. + } else {
  80591. + status = schedule_periodic(hcd, qh);
  80592. + if ( !hcd->periodic_qh_count ) {
  80593. + intr_mask.b.sofintr = 1;
  80594. + DWC_MODIFY_REG32(&hcd->core_if->core_global_regs->gintmsk,
  80595. + intr_mask.d32, intr_mask.d32);
  80596. + }
  80597. + hcd->periodic_qh_count++;
  80598. + }
  80599. +
  80600. + return status;
  80601. +}
  80602. +
  80603. +/**
  80604. + * Removes an interrupt or isochronous transfer from the periodic schedule.
  80605. + *
  80606. + * @param hcd The HCD state structure for the DWC OTG controller.
  80607. + * @param qh QH for the periodic transfer.
  80608. + */
  80609. +static void deschedule_periodic(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  80610. +{
  80611. + int i;
  80612. + DWC_LIST_REMOVE_INIT(&qh->qh_list_entry);
  80613. +
  80614. + /* Update claimed usecs per (micro)frame. */
  80615. + hcd->periodic_usecs -= qh->usecs;
  80616. +
  80617. + if (!microframe_schedule) {
  80618. + /* Release the periodic channel reservation. */
  80619. + hcd->periodic_channels--;
  80620. + } else {
  80621. + for (i = 0; i < 8; i++) {
  80622. + hcd->frame_usecs[i] += qh->frame_usecs[i];
  80623. + qh->frame_usecs[i] = 0;
  80624. + }
  80625. + }
  80626. +}
  80627. +
  80628. +/**
  80629. + * Removes a QH from either the non-periodic or periodic schedule. Memory is
  80630. + * not freed.
  80631. + *
  80632. + * @param hcd The HCD state structure.
  80633. + * @param qh QH to remove from schedule. */
  80634. +void dwc_otg_hcd_qh_remove(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  80635. +{
  80636. + gintmsk_data_t intr_mask = {.d32 = 0 };
  80637. +
  80638. + if (DWC_LIST_EMPTY(&qh->qh_list_entry)) {
  80639. + /* QH is not in a schedule. */
  80640. + return;
  80641. + }
  80642. +
  80643. + if (dwc_qh_is_non_per(qh)) {
  80644. + if (hcd->non_periodic_qh_ptr == &qh->qh_list_entry) {
  80645. + hcd->non_periodic_qh_ptr =
  80646. + hcd->non_periodic_qh_ptr->next;
  80647. + }
  80648. + DWC_LIST_REMOVE_INIT(&qh->qh_list_entry);
  80649. + //if (!DWC_LIST_EMPTY(&hcd->non_periodic_sched_inactive))
  80650. + // hcd->fiq_state->kick_np_queues = 1;
  80651. + } else {
  80652. + deschedule_periodic(hcd, qh);
  80653. + hcd->periodic_qh_count--;
  80654. + if( !hcd->periodic_qh_count && !fiq_fsm_enable ) {
  80655. + intr_mask.b.sofintr = 1;
  80656. + DWC_MODIFY_REG32(&hcd->core_if->core_global_regs->gintmsk,
  80657. + intr_mask.d32, 0);
  80658. + }
  80659. + }
  80660. +}
  80661. +
  80662. +/**
  80663. + * Deactivates a QH. For non-periodic QHs, removes the QH from the active
  80664. + * non-periodic schedule. The QH is added to the inactive non-periodic
  80665. + * schedule if any QTDs are still attached to the QH.
  80666. + *
  80667. + * For periodic QHs, the QH is removed from the periodic queued schedule. If
  80668. + * there are any QTDs still attached to the QH, the QH is added to either the
  80669. + * periodic inactive schedule or the periodic ready schedule and its next
  80670. + * scheduled frame is calculated. The QH is placed in the ready schedule if
  80671. + * the scheduled frame has been reached already. Otherwise it's placed in the
  80672. + * inactive schedule. If there are no QTDs attached to the QH, the QH is
  80673. + * completely removed from the periodic schedule.
  80674. + */
  80675. +void dwc_otg_hcd_qh_deactivate(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh,
  80676. + int sched_next_periodic_split)
  80677. +{
  80678. + if (dwc_qh_is_non_per(qh)) {
  80679. + dwc_otg_hcd_qh_remove(hcd, qh);
  80680. + if (!DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  80681. + /* Add back to inactive non-periodic schedule. */
  80682. + dwc_otg_hcd_qh_add(hcd, qh);
  80683. + //hcd->fiq_state->kick_np_queues = 1;
  80684. + }
  80685. + } else {
  80686. + uint16_t frame_number = dwc_otg_hcd_get_frame_number(hcd);
  80687. +
  80688. + if (qh->do_split) {
  80689. + /* Schedule the next continuing periodic split transfer */
  80690. + if (sched_next_periodic_split) {
  80691. +
  80692. + qh->sched_frame = frame_number;
  80693. +
  80694. + if (dwc_frame_num_le(frame_number,
  80695. + dwc_frame_num_inc
  80696. + (qh->start_split_frame,
  80697. + 1))) {
  80698. + /*
  80699. + * Allow one frame to elapse after start
  80700. + * split microframe before scheduling
  80701. + * complete split, but DONT if we are
  80702. + * doing the next start split in the
  80703. + * same frame for an ISOC out.
  80704. + */
  80705. + if ((qh->ep_type != UE_ISOCHRONOUS) ||
  80706. + (qh->ep_is_in != 0)) {
  80707. + qh->sched_frame =
  80708. + dwc_frame_num_inc(qh->sched_frame, 1);
  80709. + }
  80710. + }
  80711. + } else {
  80712. + qh->sched_frame =
  80713. + dwc_frame_num_inc(qh->start_split_frame,
  80714. + qh->interval);
  80715. + if (dwc_frame_num_le
  80716. + (qh->sched_frame, frame_number)) {
  80717. + qh->sched_frame = frame_number;
  80718. + }
  80719. + qh->sched_frame |= 0x7;
  80720. + qh->start_split_frame = qh->sched_frame;
  80721. + }
  80722. + } else {
  80723. + qh->sched_frame =
  80724. + dwc_frame_num_inc(qh->sched_frame, qh->interval);
  80725. + if (dwc_frame_num_le(qh->sched_frame, frame_number)) {
  80726. + qh->sched_frame = frame_number;
  80727. + }
  80728. + }
  80729. +
  80730. + if (DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  80731. + dwc_otg_hcd_qh_remove(hcd, qh);
  80732. + } else {
  80733. + /*
  80734. + * Remove from periodic_sched_queued and move to
  80735. + * appropriate queue.
  80736. + */
  80737. + if ((microframe_schedule && dwc_frame_num_le(qh->sched_frame, frame_number)) ||
  80738. + (!microframe_schedule && qh->sched_frame == frame_number)) {
  80739. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_ready,
  80740. + &qh->qh_list_entry);
  80741. + } else {
  80742. + if(!dwc_frame_num_le(hcd->fiq_state->next_sched_frame, qh->sched_frame))
  80743. + {
  80744. + hcd->fiq_state->next_sched_frame = qh->sched_frame;
  80745. + }
  80746. +
  80747. + DWC_LIST_MOVE_HEAD
  80748. + (&hcd->periodic_sched_inactive,
  80749. + &qh->qh_list_entry);
  80750. + }
  80751. + }
  80752. + }
  80753. +}
  80754. +
  80755. +/**
  80756. + * This function allocates and initializes a QTD.
  80757. + *
  80758. + * @param urb The URB to create a QTD from. Each URB-QTD pair will end up
  80759. + * pointing to each other so each pair should have a unique correlation.
  80760. + * @param atomic_alloc Flag to do atomic alloc if needed
  80761. + *
  80762. + * @return Returns pointer to the newly allocated QTD, or NULL on error. */
  80763. +dwc_otg_qtd_t *dwc_otg_hcd_qtd_create(dwc_otg_hcd_urb_t * urb, int atomic_alloc)
  80764. +{
  80765. + dwc_otg_qtd_t *qtd;
  80766. +
  80767. + qtd = dwc_otg_hcd_qtd_alloc(atomic_alloc);
  80768. + if (qtd == NULL) {
  80769. + return NULL;
  80770. + }
  80771. +
  80772. + dwc_otg_hcd_qtd_init(qtd, urb);
  80773. + return qtd;
  80774. +}
  80775. +
  80776. +/**
  80777. + * Initializes a QTD structure.
  80778. + *
  80779. + * @param qtd The QTD to initialize.
  80780. + * @param urb The URB to use for initialization. */
  80781. +void dwc_otg_hcd_qtd_init(dwc_otg_qtd_t * qtd, dwc_otg_hcd_urb_t * urb)
  80782. +{
  80783. + dwc_memset(qtd, 0, sizeof(dwc_otg_qtd_t));
  80784. + qtd->urb = urb;
  80785. + if (dwc_otg_hcd_get_pipe_type(&urb->pipe_info) == UE_CONTROL) {
  80786. + /*
  80787. + * The only time the QTD data toggle is used is on the data
  80788. + * phase of control transfers. This phase always starts with
  80789. + * DATA1.
  80790. + */
  80791. + qtd->data_toggle = DWC_OTG_HC_PID_DATA1;
  80792. + qtd->control_phase = DWC_OTG_CONTROL_SETUP;
  80793. + }
  80794. +
  80795. + /* start split */
  80796. + qtd->complete_split = 0;
  80797. + qtd->isoc_split_pos = DWC_HCSPLIT_XACTPOS_ALL;
  80798. + qtd->isoc_split_offset = 0;
  80799. + qtd->in_process = 0;
  80800. +
  80801. + /* Store the qtd ptr in the urb to reference what QTD. */
  80802. + urb->qtd = qtd;
  80803. + return;
  80804. +}
  80805. +
  80806. +/**
  80807. + * This function adds a QTD to the QTD-list of a QH. It will find the correct
  80808. + * QH to place the QTD into. If it does not find a QH, then it will create a
  80809. + * new QH. If the QH to which the QTD is added is not currently scheduled, it
  80810. + * is placed into the proper schedule based on its EP type.
  80811. + * HCD lock must be held and interrupts must be disabled on entry
  80812. + *
  80813. + * @param[in] qtd The QTD to add
  80814. + * @param[in] hcd The DWC HCD structure
  80815. + * @param[out] qh out parameter to return queue head
  80816. + * @param atomic_alloc Flag to do atomic alloc if needed
  80817. + *
  80818. + * @return 0 if successful, negative error code otherwise.
  80819. + */
  80820. +int dwc_otg_hcd_qtd_add(dwc_otg_qtd_t * qtd,
  80821. + dwc_otg_hcd_t * hcd, dwc_otg_qh_t ** qh, int atomic_alloc)
  80822. +{
  80823. + int retval = 0;
  80824. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  80825. +
  80826. + /*
  80827. + * Get the QH which holds the QTD-list to insert to. Create QH if it
  80828. + * doesn't exist.
  80829. + */
  80830. + if (*qh == NULL) {
  80831. + *qh = dwc_otg_hcd_qh_create(hcd, urb, atomic_alloc);
  80832. + if (*qh == NULL) {
  80833. + retval = -DWC_E_NO_MEMORY;
  80834. + goto done;
  80835. + } else {
  80836. + if (fiq_enable)
  80837. + hcd->fiq_state->kick_np_queues = 1;
  80838. + }
  80839. + }
  80840. + retval = dwc_otg_hcd_qh_add(hcd, *qh);
  80841. + if (retval == 0) {
  80842. + DWC_CIRCLEQ_INSERT_TAIL(&((*qh)->qtd_list), qtd,
  80843. + qtd_list_entry);
  80844. + qtd->qh = *qh;
  80845. + }
  80846. +done:
  80847. +
  80848. + return retval;
  80849. +}
  80850. +
  80851. +#endif /* DWC_DEVICE_ONLY */
  80852. diff -Nur linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_os_dep.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_os_dep.h
  80853. --- linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_os_dep.h 1970-01-01 01:00:00.000000000 +0100
  80854. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_os_dep.h 2014-04-24 15:37:13.314990533 +0200
  80855. @@ -0,0 +1,188 @@
  80856. +#ifndef _DWC_OS_DEP_H_
  80857. +#define _DWC_OS_DEP_H_
  80858. +
  80859. +/**
  80860. + * @file
  80861. + *
  80862. + * This file contains OS dependent structures.
  80863. + *
  80864. + */
  80865. +
  80866. +#include <linux/kernel.h>
  80867. +#include <linux/module.h>
  80868. +#include <linux/moduleparam.h>
  80869. +#include <linux/init.h>
  80870. +#include <linux/device.h>
  80871. +#include <linux/errno.h>
  80872. +#include <linux/types.h>
  80873. +#include <linux/slab.h>
  80874. +#include <linux/list.h>
  80875. +#include <linux/interrupt.h>
  80876. +#include <linux/ctype.h>
  80877. +#include <linux/string.h>
  80878. +#include <linux/dma-mapping.h>
  80879. +#include <linux/jiffies.h>
  80880. +#include <linux/delay.h>
  80881. +#include <linux/timer.h>
  80882. +#include <linux/workqueue.h>
  80883. +#include <linux/stat.h>
  80884. +#include <linux/pci.h>
  80885. +
  80886. +#include <linux/version.h>
  80887. +
  80888. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
  80889. +# include <linux/irq.h>
  80890. +#endif
  80891. +
  80892. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21)
  80893. +# include <linux/usb/ch9.h>
  80894. +#else
  80895. +# include <linux/usb_ch9.h>
  80896. +#endif
  80897. +
  80898. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
  80899. +# include <linux/usb/gadget.h>
  80900. +#else
  80901. +# include <linux/usb_gadget.h>
  80902. +#endif
  80903. +
  80904. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
  80905. +# include <asm/irq.h>
  80906. +#endif
  80907. +
  80908. +#ifdef PCI_INTERFACE
  80909. +# include <asm/io.h>
  80910. +#endif
  80911. +
  80912. +#ifdef LM_INTERFACE
  80913. +# include <asm/unaligned.h>
  80914. +# include <asm/sizes.h>
  80915. +# include <asm/param.h>
  80916. +# include <asm/io.h>
  80917. +# if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30))
  80918. +# include <asm/arch/hardware.h>
  80919. +# include <asm/arch/lm.h>
  80920. +# include <asm/arch/irqs.h>
  80921. +# include <asm/arch/regs-irq.h>
  80922. +# else
  80923. +/* in 2.6.31, at least, we seem to have lost the generic LM infrastructure -
  80924. + here we assume that the machine architecture provides definitions
  80925. + in its own header
  80926. +*/
  80927. +# include <mach/lm.h>
  80928. +# include <mach/hardware.h>
  80929. +# endif
  80930. +#endif
  80931. +
  80932. +#ifdef PLATFORM_INTERFACE
  80933. +#include <linux/platform_device.h>
  80934. +#include <asm/mach/map.h>
  80935. +#endif
  80936. +
  80937. +/** The OS page size */
  80938. +#define DWC_OS_PAGE_SIZE PAGE_SIZE
  80939. +
  80940. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14)
  80941. +typedef int gfp_t;
  80942. +#endif
  80943. +
  80944. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
  80945. +# define IRQF_SHARED SA_SHIRQ
  80946. +#endif
  80947. +
  80948. +typedef struct os_dependent {
  80949. + /** Base address returned from ioremap() */
  80950. + void *base;
  80951. +
  80952. + /** Register offset for Diagnostic API */
  80953. + uint32_t reg_offset;
  80954. +
  80955. + /** Base address for MPHI peripheral */
  80956. + void *mphi_base;
  80957. +
  80958. +#ifdef LM_INTERFACE
  80959. + struct lm_device *lmdev;
  80960. +#elif defined(PCI_INTERFACE)
  80961. + struct pci_dev *pcidev;
  80962. +
  80963. + /** Start address of a PCI region */
  80964. + resource_size_t rsrc_start;
  80965. +
  80966. + /** Length address of a PCI region */
  80967. + resource_size_t rsrc_len;
  80968. +#elif defined(PLATFORM_INTERFACE)
  80969. + struct platform_device *platformdev;
  80970. +#endif
  80971. +
  80972. +} os_dependent_t;
  80973. +
  80974. +#ifdef __cplusplus
  80975. +}
  80976. +#endif
  80977. +
  80978. +
  80979. +
  80980. +/* Type for the our device on the chosen bus */
  80981. +#if defined(LM_INTERFACE)
  80982. +typedef struct lm_device dwc_bus_dev_t;
  80983. +#elif defined(PCI_INTERFACE)
  80984. +typedef struct pci_dev dwc_bus_dev_t;
  80985. +#elif defined(PLATFORM_INTERFACE)
  80986. +typedef struct platform_device dwc_bus_dev_t;
  80987. +#endif
  80988. +
  80989. +/* Helper macro to retrieve drvdata from the device on the chosen bus */
  80990. +#if defined(LM_INTERFACE)
  80991. +#define DWC_OTG_BUSDRVDATA(_dev) lm_get_drvdata(_dev)
  80992. +#elif defined(PCI_INTERFACE)
  80993. +#define DWC_OTG_BUSDRVDATA(_dev) pci_get_drvdata(_dev)
  80994. +#elif defined(PLATFORM_INTERFACE)
  80995. +#define DWC_OTG_BUSDRVDATA(_dev) platform_get_drvdata(_dev)
  80996. +#endif
  80997. +
  80998. +/**
  80999. + * Helper macro returning the otg_device structure of a given struct device
  81000. + *
  81001. + * c.f. static dwc_otg_device_t *dwc_otg_drvdev(struct device *_dev)
  81002. + */
  81003. +#ifdef LM_INTERFACE
  81004. +#define DWC_OTG_GETDRVDEV(_var, _dev) do { \
  81005. + struct lm_device *lm_dev = \
  81006. + container_of(_dev, struct lm_device, dev); \
  81007. + _var = lm_get_drvdata(lm_dev); \
  81008. + } while (0)
  81009. +
  81010. +#elif defined(PCI_INTERFACE)
  81011. +#define DWC_OTG_GETDRVDEV(_var, _dev) do { \
  81012. + _var = dev_get_drvdata(_dev); \
  81013. + } while (0)
  81014. +
  81015. +#elif defined(PLATFORM_INTERFACE)
  81016. +#define DWC_OTG_GETDRVDEV(_var, _dev) do { \
  81017. + struct platform_device *platform_dev = \
  81018. + container_of(_dev, struct platform_device, dev); \
  81019. + _var = platform_get_drvdata(platform_dev); \
  81020. + } while (0)
  81021. +#endif
  81022. +
  81023. +
  81024. +/**
  81025. + * Helper macro returning the struct dev of the given struct os_dependent
  81026. + *
  81027. + * c.f. static struct device *dwc_otg_getdev(struct os_dependent *osdep)
  81028. + */
  81029. +#ifdef LM_INTERFACE
  81030. +#define DWC_OTG_OS_GETDEV(_osdep) \
  81031. + ((_osdep).lmdev == NULL? NULL: &(_osdep).lmdev->dev)
  81032. +#elif defined(PCI_INTERFACE)
  81033. +#define DWC_OTG_OS_GETDEV(_osdep) \
  81034. + ((_osdep).pci_dev == NULL? NULL: &(_osdep).pci_dev->dev)
  81035. +#elif defined(PLATFORM_INTERFACE)
  81036. +#define DWC_OTG_OS_GETDEV(_osdep) \
  81037. + ((_osdep).platformdev == NULL? NULL: &(_osdep).platformdev->dev)
  81038. +#endif
  81039. +
  81040. +
  81041. +
  81042. +
  81043. +#endif /* _DWC_OS_DEP_H_ */
  81044. diff -Nur linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_pcd.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd.c
  81045. --- linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_pcd.c 1970-01-01 01:00:00.000000000 +0100
  81046. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd.c 2014-04-24 15:37:13.314990533 +0200
  81047. @@ -0,0 +1,2708 @@
  81048. +/* ==========================================================================
  81049. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd.c $
  81050. + * $Revision: #101 $
  81051. + * $Date: 2012/08/10 $
  81052. + * $Change: 2047372 $
  81053. + *
  81054. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  81055. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  81056. + * otherwise expressly agreed to in writing between Synopsys and you.
  81057. + *
  81058. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  81059. + * any End User Software License Agreement or Agreement for Licensed Product
  81060. + * with Synopsys or any supplement thereto. You are permitted to use and
  81061. + * redistribute this Software in source and binary forms, with or without
  81062. + * modification, provided that redistributions of source code must retain this
  81063. + * notice. You may not view, use, disclose, copy or distribute this file or
  81064. + * any information contained herein except pursuant to this license grant from
  81065. + * Synopsys. If you do not agree with this notice, including the disclaimer
  81066. + * below, then you are not authorized to use the Software.
  81067. + *
  81068. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  81069. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  81070. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  81071. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  81072. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  81073. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  81074. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  81075. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  81076. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  81077. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  81078. + * DAMAGE.
  81079. + * ========================================================================== */
  81080. +#ifndef DWC_HOST_ONLY
  81081. +
  81082. +/** @file
  81083. + * This file implements PCD Core. All code in this file is portable and doesn't
  81084. + * use any OS specific functions.
  81085. + * PCD Core provides Interface, defined in <code><dwc_otg_pcd_if.h></code>
  81086. + * header file, which can be used to implement OS specific PCD interface.
  81087. + *
  81088. + * An important function of the PCD is managing interrupts generated
  81089. + * by the DWC_otg controller. The implementation of the DWC_otg device
  81090. + * mode interrupt service routines is in dwc_otg_pcd_intr.c.
  81091. + *
  81092. + * @todo Add Device Mode test modes (Test J mode, Test K mode, etc).
  81093. + * @todo Does it work when the request size is greater than DEPTSIZ
  81094. + * transfer size
  81095. + *
  81096. + */
  81097. +
  81098. +#include "dwc_otg_pcd.h"
  81099. +
  81100. +#ifdef DWC_UTE_CFI
  81101. +#include "dwc_otg_cfi.h"
  81102. +
  81103. +extern int init_cfi(cfiobject_t * cfiobj);
  81104. +#endif
  81105. +
  81106. +/**
  81107. + * Choose endpoint from ep arrays using usb_ep structure.
  81108. + */
  81109. +static dwc_otg_pcd_ep_t *get_ep_from_handle(dwc_otg_pcd_t * pcd, void *handle)
  81110. +{
  81111. + int i;
  81112. + if (pcd->ep0.priv == handle) {
  81113. + return &pcd->ep0;
  81114. + }
  81115. + for (i = 0; i < MAX_EPS_CHANNELS - 1; i++) {
  81116. + if (pcd->in_ep[i].priv == handle)
  81117. + return &pcd->in_ep[i];
  81118. + if (pcd->out_ep[i].priv == handle)
  81119. + return &pcd->out_ep[i];
  81120. + }
  81121. +
  81122. + return NULL;
  81123. +}
  81124. +
  81125. +/**
  81126. + * This function completes a request. It call's the request call back.
  81127. + */
  81128. +void dwc_otg_request_done(dwc_otg_pcd_ep_t * ep, dwc_otg_pcd_request_t * req,
  81129. + int32_t status)
  81130. +{
  81131. + unsigned stopped = ep->stopped;
  81132. +
  81133. + DWC_DEBUGPL(DBG_PCDV, "%s(ep %p req %p)\n", __func__, ep, req);
  81134. + DWC_CIRCLEQ_REMOVE_INIT(&ep->queue, req, queue_entry);
  81135. +
  81136. + /* don't modify queue heads during completion callback */
  81137. + ep->stopped = 1;
  81138. + /* spin_unlock/spin_lock now done in fops->complete() */
  81139. + ep->pcd->fops->complete(ep->pcd, ep->priv, req->priv, status,
  81140. + req->actual);
  81141. +
  81142. + if (ep->pcd->request_pending > 0) {
  81143. + --ep->pcd->request_pending;
  81144. + }
  81145. +
  81146. + ep->stopped = stopped;
  81147. + DWC_FREE(req);
  81148. +}
  81149. +
  81150. +/**
  81151. + * This function terminates all the requsts in the EP request queue.
  81152. + */
  81153. +void dwc_otg_request_nuke(dwc_otg_pcd_ep_t * ep)
  81154. +{
  81155. + dwc_otg_pcd_request_t *req;
  81156. +
  81157. + ep->stopped = 1;
  81158. +
  81159. + /* called with irqs blocked?? */
  81160. + while (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  81161. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  81162. + dwc_otg_request_done(ep, req, -DWC_E_SHUTDOWN);
  81163. + }
  81164. +}
  81165. +
  81166. +void dwc_otg_pcd_start(dwc_otg_pcd_t * pcd,
  81167. + const struct dwc_otg_pcd_function_ops *fops)
  81168. +{
  81169. + pcd->fops = fops;
  81170. +}
  81171. +
  81172. +/**
  81173. + * PCD Callback function for initializing the PCD when switching to
  81174. + * device mode.
  81175. + *
  81176. + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
  81177. + */
  81178. +static int32_t dwc_otg_pcd_start_cb(void *p)
  81179. +{
  81180. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) p;
  81181. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  81182. +
  81183. + /*
  81184. + * Initialized the Core for Device mode.
  81185. + */
  81186. + if (dwc_otg_is_device_mode(core_if)) {
  81187. + dwc_otg_core_dev_init(core_if);
  81188. + /* Set core_if's lock pointer to the pcd->lock */
  81189. + core_if->lock = pcd->lock;
  81190. + }
  81191. + return 1;
  81192. +}
  81193. +
  81194. +/** CFI-specific buffer allocation function for EP */
  81195. +#ifdef DWC_UTE_CFI
  81196. +uint8_t *cfiw_ep_alloc_buffer(dwc_otg_pcd_t * pcd, void *pep, dwc_dma_t * addr,
  81197. + size_t buflen, int flags)
  81198. +{
  81199. + dwc_otg_pcd_ep_t *ep;
  81200. + ep = get_ep_from_handle(pcd, pep);
  81201. + if (!ep) {
  81202. + DWC_WARN("bad ep\n");
  81203. + return -DWC_E_INVALID;
  81204. + }
  81205. +
  81206. + return pcd->cfi->ops.ep_alloc_buf(pcd->cfi, pcd, ep, addr, buflen,
  81207. + flags);
  81208. +}
  81209. +#else
  81210. +uint8_t *cfiw_ep_alloc_buffer(dwc_otg_pcd_t * pcd, void *pep, dwc_dma_t * addr,
  81211. + size_t buflen, int flags);
  81212. +#endif
  81213. +
  81214. +/**
  81215. + * PCD Callback function for notifying the PCD when resuming from
  81216. + * suspend.
  81217. + *
  81218. + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
  81219. + */
  81220. +static int32_t dwc_otg_pcd_resume_cb(void *p)
  81221. +{
  81222. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) p;
  81223. +
  81224. + if (pcd->fops->resume) {
  81225. + pcd->fops->resume(pcd);
  81226. + }
  81227. +
  81228. + /* Stop the SRP timeout timer. */
  81229. + if ((GET_CORE_IF(pcd)->core_params->phy_type != DWC_PHY_TYPE_PARAM_FS)
  81230. + || (!GET_CORE_IF(pcd)->core_params->i2c_enable)) {
  81231. + if (GET_CORE_IF(pcd)->srp_timer_started) {
  81232. + GET_CORE_IF(pcd)->srp_timer_started = 0;
  81233. + DWC_TIMER_CANCEL(GET_CORE_IF(pcd)->srp_timer);
  81234. + }
  81235. + }
  81236. + return 1;
  81237. +}
  81238. +
  81239. +/**
  81240. + * PCD Callback function for notifying the PCD device is suspended.
  81241. + *
  81242. + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
  81243. + */
  81244. +static int32_t dwc_otg_pcd_suspend_cb(void *p)
  81245. +{
  81246. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) p;
  81247. +
  81248. + if (pcd->fops->suspend) {
  81249. + DWC_SPINUNLOCK(pcd->lock);
  81250. + pcd->fops->suspend(pcd);
  81251. + DWC_SPINLOCK(pcd->lock);
  81252. + }
  81253. +
  81254. + return 1;
  81255. +}
  81256. +
  81257. +/**
  81258. + * PCD Callback function for stopping the PCD when switching to Host
  81259. + * mode.
  81260. + *
  81261. + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
  81262. + */
  81263. +static int32_t dwc_otg_pcd_stop_cb(void *p)
  81264. +{
  81265. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) p;
  81266. + extern void dwc_otg_pcd_stop(dwc_otg_pcd_t * _pcd);
  81267. +
  81268. + dwc_otg_pcd_stop(pcd);
  81269. + return 1;
  81270. +}
  81271. +
  81272. +/**
  81273. + * PCD Callback structure for handling mode switching.
  81274. + */
  81275. +static dwc_otg_cil_callbacks_t pcd_callbacks = {
  81276. + .start = dwc_otg_pcd_start_cb,
  81277. + .stop = dwc_otg_pcd_stop_cb,
  81278. + .suspend = dwc_otg_pcd_suspend_cb,
  81279. + .resume_wakeup = dwc_otg_pcd_resume_cb,
  81280. + .p = 0, /* Set at registration */
  81281. +};
  81282. +
  81283. +/**
  81284. + * This function allocates a DMA Descriptor chain for the Endpoint
  81285. + * buffer to be used for a transfer to/from the specified endpoint.
  81286. + */
  81287. +dwc_otg_dev_dma_desc_t *dwc_otg_ep_alloc_desc_chain(dwc_dma_t * dma_desc_addr,
  81288. + uint32_t count)
  81289. +{
  81290. + return DWC_DMA_ALLOC_ATOMIC(count * sizeof(dwc_otg_dev_dma_desc_t),
  81291. + dma_desc_addr);
  81292. +}
  81293. +
  81294. +/**
  81295. + * This function frees a DMA Descriptor chain that was allocated by ep_alloc_desc.
  81296. + */
  81297. +void dwc_otg_ep_free_desc_chain(dwc_otg_dev_dma_desc_t * desc_addr,
  81298. + uint32_t dma_desc_addr, uint32_t count)
  81299. +{
  81300. + DWC_DMA_FREE(count * sizeof(dwc_otg_dev_dma_desc_t), desc_addr,
  81301. + dma_desc_addr);
  81302. +}
  81303. +
  81304. +#ifdef DWC_EN_ISOC
  81305. +
  81306. +/**
  81307. + * This function initializes a descriptor chain for Isochronous transfer
  81308. + *
  81309. + * @param core_if Programming view of DWC_otg controller.
  81310. + * @param dwc_ep The EP to start the transfer on.
  81311. + *
  81312. + */
  81313. +void dwc_otg_iso_ep_start_ddma_transfer(dwc_otg_core_if_t * core_if,
  81314. + dwc_ep_t * dwc_ep)
  81315. +{
  81316. +
  81317. + dsts_data_t dsts = {.d32 = 0 };
  81318. + depctl_data_t depctl = {.d32 = 0 };
  81319. + volatile uint32_t *addr;
  81320. + int i, j;
  81321. + uint32_t len;
  81322. +
  81323. + if (dwc_ep->is_in)
  81324. + dwc_ep->desc_cnt = dwc_ep->buf_proc_intrvl / dwc_ep->bInterval;
  81325. + else
  81326. + dwc_ep->desc_cnt =
  81327. + dwc_ep->buf_proc_intrvl * dwc_ep->pkt_per_frm /
  81328. + dwc_ep->bInterval;
  81329. +
  81330. + /** Allocate descriptors for double buffering */
  81331. + dwc_ep->iso_desc_addr =
  81332. + dwc_otg_ep_alloc_desc_chain(&dwc_ep->iso_dma_desc_addr,
  81333. + dwc_ep->desc_cnt * 2);
  81334. + if (dwc_ep->desc_addr) {
  81335. + DWC_WARN("%s, can't allocate DMA descriptor chain\n", __func__);
  81336. + return;
  81337. + }
  81338. +
  81339. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  81340. +
  81341. + /** ISO OUT EP */
  81342. + if (dwc_ep->is_in == 0) {
  81343. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  81344. + dwc_otg_dev_dma_desc_t *dma_desc = dwc_ep->iso_desc_addr;
  81345. + dma_addr_t dma_ad;
  81346. + uint32_t data_per_desc;
  81347. + dwc_otg_dev_out_ep_regs_t *out_regs =
  81348. + core_if->dev_if->out_ep_regs[dwc_ep->num];
  81349. + int offset;
  81350. +
  81351. + addr = &core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl;
  81352. + dma_ad = (dma_addr_t) DWC_READ_REG32(&(out_regs->doepdma));
  81353. +
  81354. + /** Buffer 0 descriptors setup */
  81355. + dma_ad = dwc_ep->dma_addr0;
  81356. +
  81357. + sts.b_iso_out.bs = BS_HOST_READY;
  81358. + sts.b_iso_out.rxsts = 0;
  81359. + sts.b_iso_out.l = 0;
  81360. + sts.b_iso_out.sp = 0;
  81361. + sts.b_iso_out.ioc = 0;
  81362. + sts.b_iso_out.pid = 0;
  81363. + sts.b_iso_out.framenum = 0;
  81364. +
  81365. + offset = 0;
  81366. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  81367. + i += dwc_ep->pkt_per_frm) {
  81368. +
  81369. + for (j = 0; j < dwc_ep->pkt_per_frm; ++j) {
  81370. + uint32_t len = (j + 1) * dwc_ep->maxpacket;
  81371. + if (len > dwc_ep->data_per_frame)
  81372. + data_per_desc =
  81373. + dwc_ep->data_per_frame -
  81374. + j * dwc_ep->maxpacket;
  81375. + else
  81376. + data_per_desc = dwc_ep->maxpacket;
  81377. + len = data_per_desc % 4;
  81378. + if (len)
  81379. + data_per_desc += 4 - len;
  81380. +
  81381. + sts.b_iso_out.rxbytes = data_per_desc;
  81382. + dma_desc->buf = dma_ad;
  81383. + dma_desc->status.d32 = sts.d32;
  81384. +
  81385. + offset += data_per_desc;
  81386. + dma_desc++;
  81387. + dma_ad += data_per_desc;
  81388. + }
  81389. + }
  81390. +
  81391. + for (j = 0; j < dwc_ep->pkt_per_frm - 1; ++j) {
  81392. + uint32_t len = (j + 1) * dwc_ep->maxpacket;
  81393. + if (len > dwc_ep->data_per_frame)
  81394. + data_per_desc =
  81395. + dwc_ep->data_per_frame -
  81396. + j * dwc_ep->maxpacket;
  81397. + else
  81398. + data_per_desc = dwc_ep->maxpacket;
  81399. + len = data_per_desc % 4;
  81400. + if (len)
  81401. + data_per_desc += 4 - len;
  81402. + sts.b_iso_out.rxbytes = data_per_desc;
  81403. + dma_desc->buf = dma_ad;
  81404. + dma_desc->status.d32 = sts.d32;
  81405. +
  81406. + offset += data_per_desc;
  81407. + dma_desc++;
  81408. + dma_ad += data_per_desc;
  81409. + }
  81410. +
  81411. + sts.b_iso_out.ioc = 1;
  81412. + len = (j + 1) * dwc_ep->maxpacket;
  81413. + if (len > dwc_ep->data_per_frame)
  81414. + data_per_desc =
  81415. + dwc_ep->data_per_frame - j * dwc_ep->maxpacket;
  81416. + else
  81417. + data_per_desc = dwc_ep->maxpacket;
  81418. + len = data_per_desc % 4;
  81419. + if (len)
  81420. + data_per_desc += 4 - len;
  81421. + sts.b_iso_out.rxbytes = data_per_desc;
  81422. +
  81423. + dma_desc->buf = dma_ad;
  81424. + dma_desc->status.d32 = sts.d32;
  81425. + dma_desc++;
  81426. +
  81427. + /** Buffer 1 descriptors setup */
  81428. + sts.b_iso_out.ioc = 0;
  81429. + dma_ad = dwc_ep->dma_addr1;
  81430. +
  81431. + offset = 0;
  81432. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  81433. + i += dwc_ep->pkt_per_frm) {
  81434. + for (j = 0; j < dwc_ep->pkt_per_frm; ++j) {
  81435. + uint32_t len = (j + 1) * dwc_ep->maxpacket;
  81436. + if (len > dwc_ep->data_per_frame)
  81437. + data_per_desc =
  81438. + dwc_ep->data_per_frame -
  81439. + j * dwc_ep->maxpacket;
  81440. + else
  81441. + data_per_desc = dwc_ep->maxpacket;
  81442. + len = data_per_desc % 4;
  81443. + if (len)
  81444. + data_per_desc += 4 - len;
  81445. +
  81446. + data_per_desc =
  81447. + sts.b_iso_out.rxbytes = data_per_desc;
  81448. + dma_desc->buf = dma_ad;
  81449. + dma_desc->status.d32 = sts.d32;
  81450. +
  81451. + offset += data_per_desc;
  81452. + dma_desc++;
  81453. + dma_ad += data_per_desc;
  81454. + }
  81455. + }
  81456. + for (j = 0; j < dwc_ep->pkt_per_frm - 1; ++j) {
  81457. + data_per_desc =
  81458. + ((j + 1) * dwc_ep->maxpacket >
  81459. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  81460. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  81461. + data_per_desc +=
  81462. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  81463. + sts.b_iso_out.rxbytes = data_per_desc;
  81464. + dma_desc->buf = dma_ad;
  81465. + dma_desc->status.d32 = sts.d32;
  81466. +
  81467. + offset += data_per_desc;
  81468. + dma_desc++;
  81469. + dma_ad += data_per_desc;
  81470. + }
  81471. +
  81472. + sts.b_iso_out.ioc = 1;
  81473. + sts.b_iso_out.l = 1;
  81474. + data_per_desc =
  81475. + ((j + 1) * dwc_ep->maxpacket >
  81476. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  81477. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  81478. + data_per_desc +=
  81479. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  81480. + sts.b_iso_out.rxbytes = data_per_desc;
  81481. +
  81482. + dma_desc->buf = dma_ad;
  81483. + dma_desc->status.d32 = sts.d32;
  81484. +
  81485. + dwc_ep->next_frame = 0;
  81486. +
  81487. + /** Write dma_ad into DOEPDMA register */
  81488. + DWC_WRITE_REG32(&(out_regs->doepdma),
  81489. + (uint32_t) dwc_ep->iso_dma_desc_addr);
  81490. +
  81491. + }
  81492. + /** ISO IN EP */
  81493. + else {
  81494. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  81495. + dwc_otg_dev_dma_desc_t *dma_desc = dwc_ep->iso_desc_addr;
  81496. + dma_addr_t dma_ad;
  81497. + dwc_otg_dev_in_ep_regs_t *in_regs =
  81498. + core_if->dev_if->in_ep_regs[dwc_ep->num];
  81499. + unsigned int frmnumber;
  81500. + fifosize_data_t txfifosize, rxfifosize;
  81501. +
  81502. + txfifosize.d32 =
  81503. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[dwc_ep->num]->
  81504. + dtxfsts);
  81505. + rxfifosize.d32 =
  81506. + DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  81507. +
  81508. + addr = &core_if->dev_if->in_ep_regs[dwc_ep->num]->diepctl;
  81509. +
  81510. + dma_ad = dwc_ep->dma_addr0;
  81511. +
  81512. + dsts.d32 =
  81513. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  81514. +
  81515. + sts.b_iso_in.bs = BS_HOST_READY;
  81516. + sts.b_iso_in.txsts = 0;
  81517. + sts.b_iso_in.sp =
  81518. + (dwc_ep->data_per_frame % dwc_ep->maxpacket) ? 1 : 0;
  81519. + sts.b_iso_in.ioc = 0;
  81520. + sts.b_iso_in.pid = dwc_ep->pkt_per_frm;
  81521. +
  81522. + frmnumber = dwc_ep->next_frame;
  81523. +
  81524. + sts.b_iso_in.framenum = frmnumber;
  81525. + sts.b_iso_in.txbytes = dwc_ep->data_per_frame;
  81526. + sts.b_iso_in.l = 0;
  81527. +
  81528. + /** Buffer 0 descriptors setup */
  81529. + for (i = 0; i < dwc_ep->desc_cnt - 1; i++) {
  81530. + dma_desc->buf = dma_ad;
  81531. + dma_desc->status.d32 = sts.d32;
  81532. + dma_desc++;
  81533. +
  81534. + dma_ad += dwc_ep->data_per_frame;
  81535. + sts.b_iso_in.framenum += dwc_ep->bInterval;
  81536. + }
  81537. +
  81538. + sts.b_iso_in.ioc = 1;
  81539. + dma_desc->buf = dma_ad;
  81540. + dma_desc->status.d32 = sts.d32;
  81541. + ++dma_desc;
  81542. +
  81543. + /** Buffer 1 descriptors setup */
  81544. + sts.b_iso_in.ioc = 0;
  81545. + dma_ad = dwc_ep->dma_addr1;
  81546. +
  81547. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  81548. + i += dwc_ep->pkt_per_frm) {
  81549. + dma_desc->buf = dma_ad;
  81550. + dma_desc->status.d32 = sts.d32;
  81551. + dma_desc++;
  81552. +
  81553. + dma_ad += dwc_ep->data_per_frame;
  81554. + sts.b_iso_in.framenum += dwc_ep->bInterval;
  81555. +
  81556. + sts.b_iso_in.ioc = 0;
  81557. + }
  81558. + sts.b_iso_in.ioc = 1;
  81559. + sts.b_iso_in.l = 1;
  81560. +
  81561. + dma_desc->buf = dma_ad;
  81562. + dma_desc->status.d32 = sts.d32;
  81563. +
  81564. + dwc_ep->next_frame = sts.b_iso_in.framenum + dwc_ep->bInterval;
  81565. +
  81566. + /** Write dma_ad into diepdma register */
  81567. + DWC_WRITE_REG32(&(in_regs->diepdma),
  81568. + (uint32_t) dwc_ep->iso_dma_desc_addr);
  81569. + }
  81570. + /** Enable endpoint, clear nak */
  81571. + depctl.d32 = 0;
  81572. + depctl.b.epena = 1;
  81573. + depctl.b.usbactep = 1;
  81574. + depctl.b.cnak = 1;
  81575. +
  81576. + DWC_MODIFY_REG32(addr, depctl.d32, depctl.d32);
  81577. + depctl.d32 = DWC_READ_REG32(addr);
  81578. +}
  81579. +
  81580. +/**
  81581. + * This function initializes a descriptor chain for Isochronous transfer
  81582. + *
  81583. + * @param core_if Programming view of DWC_otg controller.
  81584. + * @param ep The EP to start the transfer on.
  81585. + *
  81586. + */
  81587. +void dwc_otg_iso_ep_start_buf_transfer(dwc_otg_core_if_t * core_if,
  81588. + dwc_ep_t * ep)
  81589. +{
  81590. + depctl_data_t depctl = {.d32 = 0 };
  81591. + volatile uint32_t *addr;
  81592. +
  81593. + if (ep->is_in) {
  81594. + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
  81595. + } else {
  81596. + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
  81597. + }
  81598. +
  81599. + if (core_if->dma_enable == 0 || core_if->dma_desc_enable != 0) {
  81600. + return;
  81601. + } else {
  81602. + deptsiz_data_t deptsiz = {.d32 = 0 };
  81603. +
  81604. + ep->xfer_len =
  81605. + ep->data_per_frame * ep->buf_proc_intrvl / ep->bInterval;
  81606. + ep->pkt_cnt =
  81607. + (ep->xfer_len - 1 + ep->maxpacket) / ep->maxpacket;
  81608. + ep->xfer_count = 0;
  81609. + ep->xfer_buff =
  81610. + (ep->proc_buf_num) ? ep->xfer_buff1 : ep->xfer_buff0;
  81611. + ep->dma_addr =
  81612. + (ep->proc_buf_num) ? ep->dma_addr1 : ep->dma_addr0;
  81613. +
  81614. + if (ep->is_in) {
  81615. + /* Program the transfer size and packet count
  81616. + * as follows: xfersize = N * maxpacket +
  81617. + * short_packet pktcnt = N + (short_packet
  81618. + * exist ? 1 : 0)
  81619. + */
  81620. + deptsiz.b.mc = ep->pkt_per_frm;
  81621. + deptsiz.b.xfersize = ep->xfer_len;
  81622. + deptsiz.b.pktcnt =
  81623. + (ep->xfer_len - 1 + ep->maxpacket) / ep->maxpacket;
  81624. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  81625. + dieptsiz, deptsiz.d32);
  81626. +
  81627. + /* Write the DMA register */
  81628. + DWC_WRITE_REG32(&
  81629. + (core_if->dev_if->in_ep_regs[ep->num]->
  81630. + diepdma), (uint32_t) ep->dma_addr);
  81631. +
  81632. + } else {
  81633. + deptsiz.b.pktcnt =
  81634. + (ep->xfer_len + (ep->maxpacket - 1)) /
  81635. + ep->maxpacket;
  81636. + deptsiz.b.xfersize = deptsiz.b.pktcnt * ep->maxpacket;
  81637. +
  81638. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[ep->num]->
  81639. + doeptsiz, deptsiz.d32);
  81640. +
  81641. + /* Write the DMA register */
  81642. + DWC_WRITE_REG32(&
  81643. + (core_if->dev_if->out_ep_regs[ep->num]->
  81644. + doepdma), (uint32_t) ep->dma_addr);
  81645. +
  81646. + }
  81647. + /** Enable endpoint, clear nak */
  81648. + depctl.d32 = 0;
  81649. + depctl.b.epena = 1;
  81650. + depctl.b.cnak = 1;
  81651. +
  81652. + DWC_MODIFY_REG32(addr, depctl.d32, depctl.d32);
  81653. + }
  81654. +}
  81655. +
  81656. +/**
  81657. + * This function does the setup for a data transfer for an EP and
  81658. + * starts the transfer. For an IN transfer, the packets will be
  81659. + * loaded into the appropriate Tx FIFO in the ISR. For OUT transfers,
  81660. + * the packets are unloaded from the Rx FIFO in the ISR.
  81661. + *
  81662. + * @param core_if Programming view of DWC_otg controller.
  81663. + * @param ep The EP to start the transfer on.
  81664. + */
  81665. +
  81666. +static void dwc_otg_iso_ep_start_transfer(dwc_otg_core_if_t * core_if,
  81667. + dwc_ep_t * ep)
  81668. +{
  81669. + if (core_if->dma_enable) {
  81670. + if (core_if->dma_desc_enable) {
  81671. + if (ep->is_in) {
  81672. + ep->desc_cnt = ep->pkt_cnt / ep->pkt_per_frm;
  81673. + } else {
  81674. + ep->desc_cnt = ep->pkt_cnt;
  81675. + }
  81676. + dwc_otg_iso_ep_start_ddma_transfer(core_if, ep);
  81677. + } else {
  81678. + if (core_if->pti_enh_enable) {
  81679. + dwc_otg_iso_ep_start_buf_transfer(core_if, ep);
  81680. + } else {
  81681. + ep->cur_pkt_addr =
  81682. + (ep->proc_buf_num) ? ep->xfer_buff1 : ep->
  81683. + xfer_buff0;
  81684. + ep->cur_pkt_dma_addr =
  81685. + (ep->proc_buf_num) ? ep->dma_addr1 : ep->
  81686. + dma_addr0;
  81687. + dwc_otg_iso_ep_start_frm_transfer(core_if, ep);
  81688. + }
  81689. + }
  81690. + } else {
  81691. + ep->cur_pkt_addr =
  81692. + (ep->proc_buf_num) ? ep->xfer_buff1 : ep->xfer_buff0;
  81693. + ep->cur_pkt_dma_addr =
  81694. + (ep->proc_buf_num) ? ep->dma_addr1 : ep->dma_addr0;
  81695. + dwc_otg_iso_ep_start_frm_transfer(core_if, ep);
  81696. + }
  81697. +}
  81698. +
  81699. +/**
  81700. + * This function stops transfer for an EP and
  81701. + * resets the ep's variables.
  81702. + *
  81703. + * @param core_if Programming view of DWC_otg controller.
  81704. + * @param ep The EP to start the transfer on.
  81705. + */
  81706. +
  81707. +void dwc_otg_iso_ep_stop_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  81708. +{
  81709. + depctl_data_t depctl = {.d32 = 0 };
  81710. + volatile uint32_t *addr;
  81711. +
  81712. + if (ep->is_in == 1) {
  81713. + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
  81714. + } else {
  81715. + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
  81716. + }
  81717. +
  81718. + /* disable the ep */
  81719. + depctl.d32 = DWC_READ_REG32(addr);
  81720. +
  81721. + depctl.b.epdis = 1;
  81722. + depctl.b.snak = 1;
  81723. +
  81724. + DWC_WRITE_REG32(addr, depctl.d32);
  81725. +
  81726. + if (core_if->dma_desc_enable &&
  81727. + ep->iso_desc_addr && ep->iso_dma_desc_addr) {
  81728. + dwc_otg_ep_free_desc_chain(ep->iso_desc_addr,
  81729. + ep->iso_dma_desc_addr,
  81730. + ep->desc_cnt * 2);
  81731. + }
  81732. +
  81733. + /* reset varibales */
  81734. + ep->dma_addr0 = 0;
  81735. + ep->dma_addr1 = 0;
  81736. + ep->xfer_buff0 = 0;
  81737. + ep->xfer_buff1 = 0;
  81738. + ep->data_per_frame = 0;
  81739. + ep->data_pattern_frame = 0;
  81740. + ep->sync_frame = 0;
  81741. + ep->buf_proc_intrvl = 0;
  81742. + ep->bInterval = 0;
  81743. + ep->proc_buf_num = 0;
  81744. + ep->pkt_per_frm = 0;
  81745. + ep->pkt_per_frm = 0;
  81746. + ep->desc_cnt = 0;
  81747. + ep->iso_desc_addr = 0;
  81748. + ep->iso_dma_desc_addr = 0;
  81749. +}
  81750. +
  81751. +int dwc_otg_pcd_iso_ep_start(dwc_otg_pcd_t * pcd, void *ep_handle,
  81752. + uint8_t * buf0, uint8_t * buf1, dwc_dma_t dma0,
  81753. + dwc_dma_t dma1, int sync_frame, int dp_frame,
  81754. + int data_per_frame, int start_frame,
  81755. + int buf_proc_intrvl, void *req_handle,
  81756. + int atomic_alloc)
  81757. +{
  81758. + dwc_otg_pcd_ep_t *ep;
  81759. + dwc_irqflags_t flags = 0;
  81760. + dwc_ep_t *dwc_ep;
  81761. + int32_t frm_data;
  81762. + dsts_data_t dsts;
  81763. + dwc_otg_core_if_t *core_if;
  81764. +
  81765. + ep = get_ep_from_handle(pcd, ep_handle);
  81766. +
  81767. + if (!ep || !ep->desc || ep->dwc_ep.num == 0) {
  81768. + DWC_WARN("bad ep\n");
  81769. + return -DWC_E_INVALID;
  81770. + }
  81771. +
  81772. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  81773. + core_if = GET_CORE_IF(pcd);
  81774. + dwc_ep = &ep->dwc_ep;
  81775. +
  81776. + if (ep->iso_req_handle) {
  81777. + DWC_WARN("ISO request in progress\n");
  81778. + }
  81779. +
  81780. + dwc_ep->dma_addr0 = dma0;
  81781. + dwc_ep->dma_addr1 = dma1;
  81782. +
  81783. + dwc_ep->xfer_buff0 = buf0;
  81784. + dwc_ep->xfer_buff1 = buf1;
  81785. +
  81786. + dwc_ep->data_per_frame = data_per_frame;
  81787. +
  81788. + /** @todo - pattern data support is to be implemented in the future */
  81789. + dwc_ep->data_pattern_frame = dp_frame;
  81790. + dwc_ep->sync_frame = sync_frame;
  81791. +
  81792. + dwc_ep->buf_proc_intrvl = buf_proc_intrvl;
  81793. +
  81794. + dwc_ep->bInterval = 1 << (ep->desc->bInterval - 1);
  81795. +
  81796. + dwc_ep->proc_buf_num = 0;
  81797. +
  81798. + dwc_ep->pkt_per_frm = 0;
  81799. + frm_data = ep->dwc_ep.data_per_frame;
  81800. + while (frm_data > 0) {
  81801. + dwc_ep->pkt_per_frm++;
  81802. + frm_data -= ep->dwc_ep.maxpacket;
  81803. + }
  81804. +
  81805. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  81806. +
  81807. + if (start_frame == -1) {
  81808. + dwc_ep->next_frame = dsts.b.soffn + 1;
  81809. + if (dwc_ep->bInterval != 1) {
  81810. + dwc_ep->next_frame =
  81811. + dwc_ep->next_frame + (dwc_ep->bInterval - 1 -
  81812. + dwc_ep->next_frame %
  81813. + dwc_ep->bInterval);
  81814. + }
  81815. + } else {
  81816. + dwc_ep->next_frame = start_frame;
  81817. + }
  81818. +
  81819. + if (!core_if->pti_enh_enable) {
  81820. + dwc_ep->pkt_cnt =
  81821. + dwc_ep->buf_proc_intrvl * dwc_ep->pkt_per_frm /
  81822. + dwc_ep->bInterval;
  81823. + } else {
  81824. + dwc_ep->pkt_cnt =
  81825. + (dwc_ep->data_per_frame *
  81826. + (dwc_ep->buf_proc_intrvl / dwc_ep->bInterval)
  81827. + - 1 + dwc_ep->maxpacket) / dwc_ep->maxpacket;
  81828. + }
  81829. +
  81830. + if (core_if->dma_desc_enable) {
  81831. + dwc_ep->desc_cnt =
  81832. + dwc_ep->buf_proc_intrvl * dwc_ep->pkt_per_frm /
  81833. + dwc_ep->bInterval;
  81834. + }
  81835. +
  81836. + if (atomic_alloc) {
  81837. + dwc_ep->pkt_info =
  81838. + DWC_ALLOC_ATOMIC(sizeof(iso_pkt_info_t) * dwc_ep->pkt_cnt);
  81839. + } else {
  81840. + dwc_ep->pkt_info =
  81841. + DWC_ALLOC(sizeof(iso_pkt_info_t) * dwc_ep->pkt_cnt);
  81842. + }
  81843. + if (!dwc_ep->pkt_info) {
  81844. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  81845. + return -DWC_E_NO_MEMORY;
  81846. + }
  81847. + if (core_if->pti_enh_enable) {
  81848. + dwc_memset(dwc_ep->pkt_info, 0,
  81849. + sizeof(iso_pkt_info_t) * dwc_ep->pkt_cnt);
  81850. + }
  81851. +
  81852. + dwc_ep->cur_pkt = 0;
  81853. + ep->iso_req_handle = req_handle;
  81854. +
  81855. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  81856. + dwc_otg_iso_ep_start_transfer(core_if, dwc_ep);
  81857. + return 0;
  81858. +}
  81859. +
  81860. +int dwc_otg_pcd_iso_ep_stop(dwc_otg_pcd_t * pcd, void *ep_handle,
  81861. + void *req_handle)
  81862. +{
  81863. + dwc_irqflags_t flags = 0;
  81864. + dwc_otg_pcd_ep_t *ep;
  81865. + dwc_ep_t *dwc_ep;
  81866. +
  81867. + ep = get_ep_from_handle(pcd, ep_handle);
  81868. + if (!ep || !ep->desc || ep->dwc_ep.num == 0) {
  81869. + DWC_WARN("bad ep\n");
  81870. + return -DWC_E_INVALID;
  81871. + }
  81872. + dwc_ep = &ep->dwc_ep;
  81873. +
  81874. + dwc_otg_iso_ep_stop_transfer(GET_CORE_IF(pcd), dwc_ep);
  81875. +
  81876. + DWC_FREE(dwc_ep->pkt_info);
  81877. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  81878. + if (ep->iso_req_handle != req_handle) {
  81879. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  81880. + return -DWC_E_INVALID;
  81881. + }
  81882. +
  81883. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  81884. +
  81885. + ep->iso_req_handle = 0;
  81886. + return 0;
  81887. +}
  81888. +
  81889. +/**
  81890. + * This function is used for perodical data exchnage between PCD and gadget drivers.
  81891. + * for Isochronous EPs
  81892. + *
  81893. + * - Every time a sync period completes this function is called to
  81894. + * perform data exchange between PCD and gadget
  81895. + */
  81896. +void dwc_otg_iso_buffer_done(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * ep,
  81897. + void *req_handle)
  81898. +{
  81899. + int i;
  81900. + dwc_ep_t *dwc_ep;
  81901. +
  81902. + dwc_ep = &ep->dwc_ep;
  81903. +
  81904. + DWC_SPINUNLOCK(ep->pcd->lock);
  81905. + pcd->fops->isoc_complete(pcd, ep->priv, ep->iso_req_handle,
  81906. + dwc_ep->proc_buf_num ^ 0x1);
  81907. + DWC_SPINLOCK(ep->pcd->lock);
  81908. +
  81909. + for (i = 0; i < dwc_ep->pkt_cnt; ++i) {
  81910. + dwc_ep->pkt_info[i].status = 0;
  81911. + dwc_ep->pkt_info[i].offset = 0;
  81912. + dwc_ep->pkt_info[i].length = 0;
  81913. + }
  81914. +}
  81915. +
  81916. +int dwc_otg_pcd_get_iso_packet_count(dwc_otg_pcd_t * pcd, void *ep_handle,
  81917. + void *iso_req_handle)
  81918. +{
  81919. + dwc_otg_pcd_ep_t *ep;
  81920. + dwc_ep_t *dwc_ep;
  81921. +
  81922. + ep = get_ep_from_handle(pcd, ep_handle);
  81923. + if (!ep->desc || ep->dwc_ep.num == 0) {
  81924. + DWC_WARN("bad ep\n");
  81925. + return -DWC_E_INVALID;
  81926. + }
  81927. + dwc_ep = &ep->dwc_ep;
  81928. +
  81929. + return dwc_ep->pkt_cnt;
  81930. +}
  81931. +
  81932. +void dwc_otg_pcd_get_iso_packet_params(dwc_otg_pcd_t * pcd, void *ep_handle,
  81933. + void *iso_req_handle, int packet,
  81934. + int *status, int *actual, int *offset)
  81935. +{
  81936. + dwc_otg_pcd_ep_t *ep;
  81937. + dwc_ep_t *dwc_ep;
  81938. +
  81939. + ep = get_ep_from_handle(pcd, ep_handle);
  81940. + if (!ep)
  81941. + DWC_WARN("bad ep\n");
  81942. +
  81943. + dwc_ep = &ep->dwc_ep;
  81944. +
  81945. + *status = dwc_ep->pkt_info[packet].status;
  81946. + *actual = dwc_ep->pkt_info[packet].length;
  81947. + *offset = dwc_ep->pkt_info[packet].offset;
  81948. +}
  81949. +
  81950. +#endif /* DWC_EN_ISOC */
  81951. +
  81952. +static void dwc_otg_pcd_init_ep(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * pcd_ep,
  81953. + uint32_t is_in, uint32_t ep_num)
  81954. +{
  81955. + /* Init EP structure */
  81956. + pcd_ep->desc = 0;
  81957. + pcd_ep->pcd = pcd;
  81958. + pcd_ep->stopped = 1;
  81959. + pcd_ep->queue_sof = 0;
  81960. +
  81961. + /* Init DWC ep structure */
  81962. + pcd_ep->dwc_ep.is_in = is_in;
  81963. + pcd_ep->dwc_ep.num = ep_num;
  81964. + pcd_ep->dwc_ep.active = 0;
  81965. + pcd_ep->dwc_ep.tx_fifo_num = 0;
  81966. + /* Control until ep is actvated */
  81967. + pcd_ep->dwc_ep.type = DWC_OTG_EP_TYPE_CONTROL;
  81968. + pcd_ep->dwc_ep.maxpacket = MAX_PACKET_SIZE;
  81969. + pcd_ep->dwc_ep.dma_addr = 0;
  81970. + pcd_ep->dwc_ep.start_xfer_buff = 0;
  81971. + pcd_ep->dwc_ep.xfer_buff = 0;
  81972. + pcd_ep->dwc_ep.xfer_len = 0;
  81973. + pcd_ep->dwc_ep.xfer_count = 0;
  81974. + pcd_ep->dwc_ep.sent_zlp = 0;
  81975. + pcd_ep->dwc_ep.total_len = 0;
  81976. + pcd_ep->dwc_ep.desc_addr = 0;
  81977. + pcd_ep->dwc_ep.dma_desc_addr = 0;
  81978. + DWC_CIRCLEQ_INIT(&pcd_ep->queue);
  81979. +}
  81980. +
  81981. +/**
  81982. + * Initialize ep's
  81983. + */
  81984. +static void dwc_otg_pcd_reinit(dwc_otg_pcd_t * pcd)
  81985. +{
  81986. + int i;
  81987. + uint32_t hwcfg1;
  81988. + dwc_otg_pcd_ep_t *ep;
  81989. + int in_ep_cntr, out_ep_cntr;
  81990. + uint32_t num_in_eps = (GET_CORE_IF(pcd))->dev_if->num_in_eps;
  81991. + uint32_t num_out_eps = (GET_CORE_IF(pcd))->dev_if->num_out_eps;
  81992. +
  81993. + /**
  81994. + * Initialize the EP0 structure.
  81995. + */
  81996. + ep = &pcd->ep0;
  81997. + dwc_otg_pcd_init_ep(pcd, ep, 0, 0);
  81998. +
  81999. + in_ep_cntr = 0;
  82000. + hwcfg1 = (GET_CORE_IF(pcd))->hwcfg1.d32 >> 3;
  82001. + for (i = 1; in_ep_cntr < num_in_eps; i++) {
  82002. + if ((hwcfg1 & 0x1) == 0) {
  82003. + dwc_otg_pcd_ep_t *ep = &pcd->in_ep[in_ep_cntr];
  82004. + in_ep_cntr++;
  82005. + /**
  82006. + * @todo NGS: Add direction to EP, based on contents
  82007. + * of HWCFG1. Need a copy of HWCFG1 in pcd structure?
  82008. + * sprintf(";r
  82009. + */
  82010. + dwc_otg_pcd_init_ep(pcd, ep, 1 /* IN */ , i);
  82011. +
  82012. + DWC_CIRCLEQ_INIT(&ep->queue);
  82013. + }
  82014. + hwcfg1 >>= 2;
  82015. + }
  82016. +
  82017. + out_ep_cntr = 0;
  82018. + hwcfg1 = (GET_CORE_IF(pcd))->hwcfg1.d32 >> 2;
  82019. + for (i = 1; out_ep_cntr < num_out_eps; i++) {
  82020. + if ((hwcfg1 & 0x1) == 0) {
  82021. + dwc_otg_pcd_ep_t *ep = &pcd->out_ep[out_ep_cntr];
  82022. + out_ep_cntr++;
  82023. + /**
  82024. + * @todo NGS: Add direction to EP, based on contents
  82025. + * of HWCFG1. Need a copy of HWCFG1 in pcd structure?
  82026. + * sprintf(";r
  82027. + */
  82028. + dwc_otg_pcd_init_ep(pcd, ep, 0 /* OUT */ , i);
  82029. + DWC_CIRCLEQ_INIT(&ep->queue);
  82030. + }
  82031. + hwcfg1 >>= 2;
  82032. + }
  82033. +
  82034. + pcd->ep0state = EP0_DISCONNECT;
  82035. + pcd->ep0.dwc_ep.maxpacket = MAX_EP0_SIZE;
  82036. + pcd->ep0.dwc_ep.type = DWC_OTG_EP_TYPE_CONTROL;
  82037. +}
  82038. +
  82039. +/**
  82040. + * This function is called when the SRP timer expires. The SRP should
  82041. + * complete within 6 seconds.
  82042. + */
  82043. +static void srp_timeout(void *ptr)
  82044. +{
  82045. + gotgctl_data_t gotgctl;
  82046. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) ptr;
  82047. + volatile uint32_t *addr = &core_if->core_global_regs->gotgctl;
  82048. +
  82049. + gotgctl.d32 = DWC_READ_REG32(addr);
  82050. +
  82051. + core_if->srp_timer_started = 0;
  82052. +
  82053. + if (core_if->adp_enable) {
  82054. + if (gotgctl.b.bsesvld == 0) {
  82055. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  82056. + DWC_PRINTF("SRP Timeout BSESSVLD = 0\n");
  82057. + /* Power off the core */
  82058. + if (core_if->power_down == 2) {
  82059. + gpwrdn.b.pwrdnswtch = 1;
  82060. + DWC_MODIFY_REG32(&core_if->
  82061. + core_global_regs->gpwrdn,
  82062. + gpwrdn.d32, 0);
  82063. + }
  82064. +
  82065. + gpwrdn.d32 = 0;
  82066. + gpwrdn.b.pmuintsel = 1;
  82067. + gpwrdn.b.pmuactv = 1;
  82068. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0,
  82069. + gpwrdn.d32);
  82070. + dwc_otg_adp_probe_start(core_if);
  82071. + } else {
  82072. + DWC_PRINTF("SRP Timeout BSESSVLD = 1\n");
  82073. + core_if->op_state = B_PERIPHERAL;
  82074. + dwc_otg_core_init(core_if);
  82075. + dwc_otg_enable_global_interrupts(core_if);
  82076. + cil_pcd_start(core_if);
  82077. + }
  82078. + }
  82079. +
  82080. + if ((core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS) &&
  82081. + (core_if->core_params->i2c_enable)) {
  82082. + DWC_PRINTF("SRP Timeout\n");
  82083. +
  82084. + if ((core_if->srp_success) && (gotgctl.b.bsesvld)) {
  82085. + if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
  82086. + core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
  82087. + }
  82088. +
  82089. + /* Clear Session Request */
  82090. + gotgctl.d32 = 0;
  82091. + gotgctl.b.sesreq = 1;
  82092. + DWC_MODIFY_REG32(&core_if->core_global_regs->gotgctl,
  82093. + gotgctl.d32, 0);
  82094. +
  82095. + core_if->srp_success = 0;
  82096. + } else {
  82097. + __DWC_ERROR("Device not connected/responding\n");
  82098. + gotgctl.b.sesreq = 0;
  82099. + DWC_WRITE_REG32(addr, gotgctl.d32);
  82100. + }
  82101. + } else if (gotgctl.b.sesreq) {
  82102. + DWC_PRINTF("SRP Timeout\n");
  82103. +
  82104. + __DWC_ERROR("Device not connected/responding\n");
  82105. + gotgctl.b.sesreq = 0;
  82106. + DWC_WRITE_REG32(addr, gotgctl.d32);
  82107. + } else {
  82108. + DWC_PRINTF(" SRP GOTGCTL=%0x\n", gotgctl.d32);
  82109. + }
  82110. +}
  82111. +
  82112. +/**
  82113. + * Tasklet
  82114. + *
  82115. + */
  82116. +extern void start_next_request(dwc_otg_pcd_ep_t * ep);
  82117. +
  82118. +static void start_xfer_tasklet_func(void *data)
  82119. +{
  82120. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) data;
  82121. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  82122. +
  82123. + int i;
  82124. + depctl_data_t diepctl;
  82125. +
  82126. + DWC_DEBUGPL(DBG_PCDV, "Start xfer tasklet\n");
  82127. +
  82128. + diepctl.d32 = DWC_READ_REG32(&core_if->dev_if->in_ep_regs[0]->diepctl);
  82129. +
  82130. + if (pcd->ep0.queue_sof) {
  82131. + pcd->ep0.queue_sof = 0;
  82132. + start_next_request(&pcd->ep0);
  82133. + // break;
  82134. + }
  82135. +
  82136. + for (i = 0; i < core_if->dev_if->num_in_eps; i++) {
  82137. + depctl_data_t diepctl;
  82138. + diepctl.d32 =
  82139. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[i]->diepctl);
  82140. +
  82141. + if (pcd->in_ep[i].queue_sof) {
  82142. + pcd->in_ep[i].queue_sof = 0;
  82143. + start_next_request(&pcd->in_ep[i]);
  82144. + // break;
  82145. + }
  82146. + }
  82147. +
  82148. + return;
  82149. +}
  82150. +
  82151. +/**
  82152. + * This function initialized the PCD portion of the driver.
  82153. + *
  82154. + */
  82155. +dwc_otg_pcd_t *dwc_otg_pcd_init(dwc_otg_core_if_t * core_if)
  82156. +{
  82157. + dwc_otg_pcd_t *pcd = NULL;
  82158. + dwc_otg_dev_if_t *dev_if;
  82159. + int i;
  82160. +
  82161. + /*
  82162. + * Allocate PCD structure
  82163. + */
  82164. + pcd = DWC_ALLOC(sizeof(dwc_otg_pcd_t));
  82165. +
  82166. + if (pcd == NULL) {
  82167. + return NULL;
  82168. + }
  82169. +
  82170. + pcd->lock = DWC_SPINLOCK_ALLOC();
  82171. + DWC_DEBUGPL(DBG_HCDV, "Init of PCD %p given core_if %p\n",
  82172. + pcd, core_if);//GRAYG
  82173. + if (!pcd->lock) {
  82174. + DWC_ERROR("Could not allocate lock for pcd");
  82175. + DWC_FREE(pcd);
  82176. + return NULL;
  82177. + }
  82178. + /* Set core_if's lock pointer to hcd->lock */
  82179. + core_if->lock = pcd->lock;
  82180. + pcd->core_if = core_if;
  82181. +
  82182. + dev_if = core_if->dev_if;
  82183. + dev_if->isoc_ep = NULL;
  82184. +
  82185. + if (core_if->hwcfg4.b.ded_fifo_en) {
  82186. + DWC_PRINTF("Dedicated Tx FIFOs mode\n");
  82187. + } else {
  82188. + DWC_PRINTF("Shared Tx FIFO mode\n");
  82189. + }
  82190. +
  82191. + /*
  82192. + * Initialized the Core for Device mode here if there is nod ADP support.
  82193. + * Otherwise it will be done later in dwc_otg_adp_start routine.
  82194. + */
  82195. + if (dwc_otg_is_device_mode(core_if) /*&& !core_if->adp_enable*/) {
  82196. + dwc_otg_core_dev_init(core_if);
  82197. + }
  82198. +
  82199. + /*
  82200. + * Register the PCD Callbacks.
  82201. + */
  82202. + dwc_otg_cil_register_pcd_callbacks(core_if, &pcd_callbacks, pcd);
  82203. +
  82204. + /*
  82205. + * Initialize the DMA buffer for SETUP packets
  82206. + */
  82207. + if (GET_CORE_IF(pcd)->dma_enable) {
  82208. + pcd->setup_pkt =
  82209. + DWC_DMA_ALLOC(sizeof(*pcd->setup_pkt) * 5,
  82210. + &pcd->setup_pkt_dma_handle);
  82211. + if (pcd->setup_pkt == NULL) {
  82212. + DWC_FREE(pcd);
  82213. + return NULL;
  82214. + }
  82215. +
  82216. + pcd->status_buf =
  82217. + DWC_DMA_ALLOC(sizeof(uint16_t),
  82218. + &pcd->status_buf_dma_handle);
  82219. + if (pcd->status_buf == NULL) {
  82220. + DWC_DMA_FREE(sizeof(*pcd->setup_pkt) * 5,
  82221. + pcd->setup_pkt, pcd->setup_pkt_dma_handle);
  82222. + DWC_FREE(pcd);
  82223. + return NULL;
  82224. + }
  82225. +
  82226. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  82227. + dev_if->setup_desc_addr[0] =
  82228. + dwc_otg_ep_alloc_desc_chain
  82229. + (&dev_if->dma_setup_desc_addr[0], 1);
  82230. + dev_if->setup_desc_addr[1] =
  82231. + dwc_otg_ep_alloc_desc_chain
  82232. + (&dev_if->dma_setup_desc_addr[1], 1);
  82233. + dev_if->in_desc_addr =
  82234. + dwc_otg_ep_alloc_desc_chain
  82235. + (&dev_if->dma_in_desc_addr, 1);
  82236. + dev_if->out_desc_addr =
  82237. + dwc_otg_ep_alloc_desc_chain
  82238. + (&dev_if->dma_out_desc_addr, 1);
  82239. + pcd->data_terminated = 0;
  82240. +
  82241. + if (dev_if->setup_desc_addr[0] == 0
  82242. + || dev_if->setup_desc_addr[1] == 0
  82243. + || dev_if->in_desc_addr == 0
  82244. + || dev_if->out_desc_addr == 0) {
  82245. +
  82246. + if (dev_if->out_desc_addr)
  82247. + dwc_otg_ep_free_desc_chain
  82248. + (dev_if->out_desc_addr,
  82249. + dev_if->dma_out_desc_addr, 1);
  82250. + if (dev_if->in_desc_addr)
  82251. + dwc_otg_ep_free_desc_chain
  82252. + (dev_if->in_desc_addr,
  82253. + dev_if->dma_in_desc_addr, 1);
  82254. + if (dev_if->setup_desc_addr[1])
  82255. + dwc_otg_ep_free_desc_chain
  82256. + (dev_if->setup_desc_addr[1],
  82257. + dev_if->dma_setup_desc_addr[1], 1);
  82258. + if (dev_if->setup_desc_addr[0])
  82259. + dwc_otg_ep_free_desc_chain
  82260. + (dev_if->setup_desc_addr[0],
  82261. + dev_if->dma_setup_desc_addr[0], 1);
  82262. +
  82263. + DWC_DMA_FREE(sizeof(*pcd->setup_pkt) * 5,
  82264. + pcd->setup_pkt,
  82265. + pcd->setup_pkt_dma_handle);
  82266. + DWC_DMA_FREE(sizeof(*pcd->status_buf),
  82267. + pcd->status_buf,
  82268. + pcd->status_buf_dma_handle);
  82269. +
  82270. + DWC_FREE(pcd);
  82271. +
  82272. + return NULL;
  82273. + }
  82274. + }
  82275. + } else {
  82276. + pcd->setup_pkt = DWC_ALLOC(sizeof(*pcd->setup_pkt) * 5);
  82277. + if (pcd->setup_pkt == NULL) {
  82278. + DWC_FREE(pcd);
  82279. + return NULL;
  82280. + }
  82281. +
  82282. + pcd->status_buf = DWC_ALLOC(sizeof(uint16_t));
  82283. + if (pcd->status_buf == NULL) {
  82284. + DWC_FREE(pcd->setup_pkt);
  82285. + DWC_FREE(pcd);
  82286. + return NULL;
  82287. + }
  82288. + }
  82289. +
  82290. + dwc_otg_pcd_reinit(pcd);
  82291. +
  82292. + /* Allocate the cfi object for the PCD */
  82293. +#ifdef DWC_UTE_CFI
  82294. + pcd->cfi = DWC_ALLOC(sizeof(cfiobject_t));
  82295. + if (NULL == pcd->cfi)
  82296. + goto fail;
  82297. + if (init_cfi(pcd->cfi)) {
  82298. + CFI_INFO("%s: Failed to init the CFI object\n", __func__);
  82299. + goto fail;
  82300. + }
  82301. +#endif
  82302. +
  82303. + /* Initialize tasklets */
  82304. + pcd->start_xfer_tasklet = DWC_TASK_ALLOC("xfer_tasklet",
  82305. + start_xfer_tasklet_func, pcd);
  82306. + pcd->test_mode_tasklet = DWC_TASK_ALLOC("test_mode_tasklet",
  82307. + do_test_mode, pcd);
  82308. +
  82309. + /* Initialize SRP timer */
  82310. + core_if->srp_timer = DWC_TIMER_ALLOC("SRP TIMER", srp_timeout, core_if);
  82311. +
  82312. + if (core_if->core_params->dev_out_nak) {
  82313. + /**
  82314. + * Initialize xfer timeout timer. Implemented for
  82315. + * 2.93a feature "Device DDMA OUT NAK Enhancement"
  82316. + */
  82317. + for(i = 0; i < MAX_EPS_CHANNELS; i++) {
  82318. + pcd->core_if->ep_xfer_timer[i] =
  82319. + DWC_TIMER_ALLOC("ep timer", ep_xfer_timeout,
  82320. + &pcd->core_if->ep_xfer_info[i]);
  82321. + }
  82322. + }
  82323. +
  82324. + return pcd;
  82325. +#ifdef DWC_UTE_CFI
  82326. +fail:
  82327. +#endif
  82328. + if (pcd->setup_pkt)
  82329. + DWC_FREE(pcd->setup_pkt);
  82330. + if (pcd->status_buf)
  82331. + DWC_FREE(pcd->status_buf);
  82332. +#ifdef DWC_UTE_CFI
  82333. + if (pcd->cfi)
  82334. + DWC_FREE(pcd->cfi);
  82335. +#endif
  82336. + if (pcd)
  82337. + DWC_FREE(pcd);
  82338. + return NULL;
  82339. +
  82340. +}
  82341. +
  82342. +/**
  82343. + * Remove PCD specific data
  82344. + */
  82345. +void dwc_otg_pcd_remove(dwc_otg_pcd_t * pcd)
  82346. +{
  82347. + dwc_otg_dev_if_t *dev_if = GET_CORE_IF(pcd)->dev_if;
  82348. + int i;
  82349. + if (pcd->core_if->core_params->dev_out_nak) {
  82350. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  82351. + DWC_TIMER_CANCEL(pcd->core_if->ep_xfer_timer[i]);
  82352. + pcd->core_if->ep_xfer_info[i].state = 0;
  82353. + }
  82354. + }
  82355. +
  82356. + if (GET_CORE_IF(pcd)->dma_enable) {
  82357. + DWC_DMA_FREE(sizeof(*pcd->setup_pkt) * 5, pcd->setup_pkt,
  82358. + pcd->setup_pkt_dma_handle);
  82359. + DWC_DMA_FREE(sizeof(uint16_t), pcd->status_buf,
  82360. + pcd->status_buf_dma_handle);
  82361. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  82362. + dwc_otg_ep_free_desc_chain(dev_if->setup_desc_addr[0],
  82363. + dev_if->dma_setup_desc_addr
  82364. + [0], 1);
  82365. + dwc_otg_ep_free_desc_chain(dev_if->setup_desc_addr[1],
  82366. + dev_if->dma_setup_desc_addr
  82367. + [1], 1);
  82368. + dwc_otg_ep_free_desc_chain(dev_if->in_desc_addr,
  82369. + dev_if->dma_in_desc_addr, 1);
  82370. + dwc_otg_ep_free_desc_chain(dev_if->out_desc_addr,
  82371. + dev_if->dma_out_desc_addr,
  82372. + 1);
  82373. + }
  82374. + } else {
  82375. + DWC_FREE(pcd->setup_pkt);
  82376. + DWC_FREE(pcd->status_buf);
  82377. + }
  82378. + DWC_SPINLOCK_FREE(pcd->lock);
  82379. + /* Set core_if's lock pointer to NULL */
  82380. + pcd->core_if->lock = NULL;
  82381. +
  82382. + DWC_TASK_FREE(pcd->start_xfer_tasklet);
  82383. + DWC_TASK_FREE(pcd->test_mode_tasklet);
  82384. + if (pcd->core_if->core_params->dev_out_nak) {
  82385. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  82386. + if (pcd->core_if->ep_xfer_timer[i]) {
  82387. + DWC_TIMER_FREE(pcd->core_if->ep_xfer_timer[i]);
  82388. + }
  82389. + }
  82390. + }
  82391. +
  82392. +/* Release the CFI object's dynamic memory */
  82393. +#ifdef DWC_UTE_CFI
  82394. + if (pcd->cfi->ops.release) {
  82395. + pcd->cfi->ops.release(pcd->cfi);
  82396. + }
  82397. +#endif
  82398. +
  82399. + DWC_FREE(pcd);
  82400. +}
  82401. +
  82402. +/**
  82403. + * Returns whether registered pcd is dual speed or not
  82404. + */
  82405. +uint32_t dwc_otg_pcd_is_dualspeed(dwc_otg_pcd_t * pcd)
  82406. +{
  82407. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  82408. +
  82409. + if ((core_if->core_params->speed == DWC_SPEED_PARAM_FULL) ||
  82410. + ((core_if->hwcfg2.b.hs_phy_type == 2) &&
  82411. + (core_if->hwcfg2.b.fs_phy_type == 1) &&
  82412. + (core_if->core_params->ulpi_fs_ls))) {
  82413. + return 0;
  82414. + }
  82415. +
  82416. + return 1;
  82417. +}
  82418. +
  82419. +/**
  82420. + * Returns whether registered pcd is OTG capable or not
  82421. + */
  82422. +uint32_t dwc_otg_pcd_is_otg(dwc_otg_pcd_t * pcd)
  82423. +{
  82424. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  82425. + gusbcfg_data_t usbcfg = {.d32 = 0 };
  82426. +
  82427. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  82428. + if (!usbcfg.b.srpcap || !usbcfg.b.hnpcap) {
  82429. + return 0;
  82430. + }
  82431. +
  82432. + return 1;
  82433. +}
  82434. +
  82435. +/**
  82436. + * This function assigns periodic Tx FIFO to an periodic EP
  82437. + * in shared Tx FIFO mode
  82438. + */
  82439. +static uint32_t assign_tx_fifo(dwc_otg_core_if_t * core_if)
  82440. +{
  82441. + uint32_t TxMsk = 1;
  82442. + int i;
  82443. +
  82444. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; ++i) {
  82445. + if ((TxMsk & core_if->tx_msk) == 0) {
  82446. + core_if->tx_msk |= TxMsk;
  82447. + return i + 1;
  82448. + }
  82449. + TxMsk <<= 1;
  82450. + }
  82451. + return 0;
  82452. +}
  82453. +
  82454. +/**
  82455. + * This function assigns periodic Tx FIFO to an periodic EP
  82456. + * in shared Tx FIFO mode
  82457. + */
  82458. +static uint32_t assign_perio_tx_fifo(dwc_otg_core_if_t * core_if)
  82459. +{
  82460. + uint32_t PerTxMsk = 1;
  82461. + int i;
  82462. + for (i = 0; i < core_if->hwcfg4.b.num_dev_perio_in_ep; ++i) {
  82463. + if ((PerTxMsk & core_if->p_tx_msk) == 0) {
  82464. + core_if->p_tx_msk |= PerTxMsk;
  82465. + return i + 1;
  82466. + }
  82467. + PerTxMsk <<= 1;
  82468. + }
  82469. + return 0;
  82470. +}
  82471. +
  82472. +/**
  82473. + * This function releases periodic Tx FIFO
  82474. + * in shared Tx FIFO mode
  82475. + */
  82476. +static void release_perio_tx_fifo(dwc_otg_core_if_t * core_if,
  82477. + uint32_t fifo_num)
  82478. +{
  82479. + core_if->p_tx_msk =
  82480. + (core_if->p_tx_msk & (1 << (fifo_num - 1))) ^ core_if->p_tx_msk;
  82481. +}
  82482. +
  82483. +/**
  82484. + * This function releases periodic Tx FIFO
  82485. + * in shared Tx FIFO mode
  82486. + */
  82487. +static void release_tx_fifo(dwc_otg_core_if_t * core_if, uint32_t fifo_num)
  82488. +{
  82489. + core_if->tx_msk =
  82490. + (core_if->tx_msk & (1 << (fifo_num - 1))) ^ core_if->tx_msk;
  82491. +}
  82492. +
  82493. +/**
  82494. + * This function is being called from gadget
  82495. + * to enable PCD endpoint.
  82496. + */
  82497. +int dwc_otg_pcd_ep_enable(dwc_otg_pcd_t * pcd,
  82498. + const uint8_t * ep_desc, void *usb_ep)
  82499. +{
  82500. + int num, dir;
  82501. + dwc_otg_pcd_ep_t *ep = NULL;
  82502. + const usb_endpoint_descriptor_t *desc;
  82503. + dwc_irqflags_t flags;
  82504. + fifosize_data_t dptxfsiz = {.d32 = 0 };
  82505. + gdfifocfg_data_t gdfifocfg = {.d32 = 0 };
  82506. + gdfifocfg_data_t gdfifocfgbase = {.d32 = 0 };
  82507. + int retval = 0;
  82508. + int i, epcount;
  82509. +
  82510. + desc = (const usb_endpoint_descriptor_t *)ep_desc;
  82511. +
  82512. + if (!desc) {
  82513. + pcd->ep0.priv = usb_ep;
  82514. + ep = &pcd->ep0;
  82515. + retval = -DWC_E_INVALID;
  82516. + goto out;
  82517. + }
  82518. +
  82519. + num = UE_GET_ADDR(desc->bEndpointAddress);
  82520. + dir = UE_GET_DIR(desc->bEndpointAddress);
  82521. +
  82522. + if (!desc->wMaxPacketSize) {
  82523. + DWC_WARN("bad maxpacketsize\n");
  82524. + retval = -DWC_E_INVALID;
  82525. + goto out;
  82526. + }
  82527. +
  82528. + if (dir == UE_DIR_IN) {
  82529. + epcount = pcd->core_if->dev_if->num_in_eps;
  82530. + for (i = 0; i < epcount; i++) {
  82531. + if (num == pcd->in_ep[i].dwc_ep.num) {
  82532. + ep = &pcd->in_ep[i];
  82533. + break;
  82534. + }
  82535. + }
  82536. + } else {
  82537. + epcount = pcd->core_if->dev_if->num_out_eps;
  82538. + for (i = 0; i < epcount; i++) {
  82539. + if (num == pcd->out_ep[i].dwc_ep.num) {
  82540. + ep = &pcd->out_ep[i];
  82541. + break;
  82542. + }
  82543. + }
  82544. + }
  82545. +
  82546. + if (!ep) {
  82547. + DWC_WARN("bad address\n");
  82548. + retval = -DWC_E_INVALID;
  82549. + goto out;
  82550. + }
  82551. +
  82552. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  82553. +
  82554. + ep->desc = desc;
  82555. + ep->priv = usb_ep;
  82556. +
  82557. + /*
  82558. + * Activate the EP
  82559. + */
  82560. + ep->stopped = 0;
  82561. +
  82562. + ep->dwc_ep.is_in = (dir == UE_DIR_IN);
  82563. + ep->dwc_ep.maxpacket = UGETW(desc->wMaxPacketSize);
  82564. +
  82565. + ep->dwc_ep.type = desc->bmAttributes & UE_XFERTYPE;
  82566. +
  82567. + if (ep->dwc_ep.is_in) {
  82568. + if (!GET_CORE_IF(pcd)->en_multiple_tx_fifo) {
  82569. + ep->dwc_ep.tx_fifo_num = 0;
  82570. +
  82571. + if (ep->dwc_ep.type == UE_ISOCHRONOUS) {
  82572. + /*
  82573. + * if ISOC EP then assign a Periodic Tx FIFO.
  82574. + */
  82575. + ep->dwc_ep.tx_fifo_num =
  82576. + assign_perio_tx_fifo(GET_CORE_IF(pcd));
  82577. + }
  82578. + } else {
  82579. + /*
  82580. + * if Dedicated FIFOs mode is on then assign a Tx FIFO.
  82581. + */
  82582. + ep->dwc_ep.tx_fifo_num =
  82583. + assign_tx_fifo(GET_CORE_IF(pcd));
  82584. + }
  82585. +
  82586. + /* Calculating EP info controller base address */
  82587. + if (ep->dwc_ep.tx_fifo_num
  82588. + && GET_CORE_IF(pcd)->en_multiple_tx_fifo) {
  82589. + gdfifocfg.d32 =
  82590. + DWC_READ_REG32(&GET_CORE_IF(pcd)->
  82591. + core_global_regs->gdfifocfg);
  82592. + gdfifocfgbase.d32 = gdfifocfg.d32 >> 16;
  82593. + dptxfsiz.d32 =
  82594. + (DWC_READ_REG32
  82595. + (&GET_CORE_IF(pcd)->core_global_regs->
  82596. + dtxfsiz[ep->dwc_ep.tx_fifo_num - 1]) >> 16);
  82597. + gdfifocfg.b.epinfobase =
  82598. + gdfifocfgbase.d32 + dptxfsiz.d32;
  82599. + if (GET_CORE_IF(pcd)->snpsid <= OTG_CORE_REV_2_94a) {
  82600. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->
  82601. + core_global_regs->gdfifocfg,
  82602. + gdfifocfg.d32);
  82603. + }
  82604. + }
  82605. + }
  82606. + /* Set initial data PID. */
  82607. + if (ep->dwc_ep.type == UE_BULK) {
  82608. + ep->dwc_ep.data_pid_start = 0;
  82609. + }
  82610. +
  82611. + /* Alloc DMA Descriptors */
  82612. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  82613. +#ifndef DWC_UTE_PER_IO
  82614. + if (ep->dwc_ep.type != UE_ISOCHRONOUS) {
  82615. +#endif
  82616. + ep->dwc_ep.desc_addr =
  82617. + dwc_otg_ep_alloc_desc_chain(&ep->
  82618. + dwc_ep.dma_desc_addr,
  82619. + MAX_DMA_DESC_CNT);
  82620. + if (!ep->dwc_ep.desc_addr) {
  82621. + DWC_WARN("%s, can't allocate DMA descriptor\n",
  82622. + __func__);
  82623. + retval = -DWC_E_SHUTDOWN;
  82624. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  82625. + goto out;
  82626. + }
  82627. +#ifndef DWC_UTE_PER_IO
  82628. + }
  82629. +#endif
  82630. + }
  82631. +
  82632. + DWC_DEBUGPL(DBG_PCD, "Activate %s: type=%d, mps=%d desc=%p\n",
  82633. + (ep->dwc_ep.is_in ? "IN" : "OUT"),
  82634. + ep->dwc_ep.type, ep->dwc_ep.maxpacket, ep->desc);
  82635. +#ifdef DWC_UTE_PER_IO
  82636. + ep->dwc_ep.xiso_bInterval = 1 << (ep->desc->bInterval - 1);
  82637. +#endif
  82638. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  82639. + ep->dwc_ep.bInterval = 1 << (ep->desc->bInterval - 1);
  82640. + ep->dwc_ep.frame_num = 0xFFFFFFFF;
  82641. + }
  82642. +
  82643. + dwc_otg_ep_activate(GET_CORE_IF(pcd), &ep->dwc_ep);
  82644. +
  82645. +#ifdef DWC_UTE_CFI
  82646. + if (pcd->cfi->ops.ep_enable) {
  82647. + pcd->cfi->ops.ep_enable(pcd->cfi, pcd, ep);
  82648. + }
  82649. +#endif
  82650. +
  82651. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  82652. +
  82653. +out:
  82654. + return retval;
  82655. +}
  82656. +
  82657. +/**
  82658. + * This function is being called from gadget
  82659. + * to disable PCD endpoint.
  82660. + */
  82661. +int dwc_otg_pcd_ep_disable(dwc_otg_pcd_t * pcd, void *ep_handle)
  82662. +{
  82663. + dwc_otg_pcd_ep_t *ep;
  82664. + dwc_irqflags_t flags;
  82665. + dwc_otg_dev_dma_desc_t *desc_addr;
  82666. + dwc_dma_t dma_desc_addr;
  82667. + gdfifocfg_data_t gdfifocfgbase = {.d32 = 0 };
  82668. + gdfifocfg_data_t gdfifocfg = {.d32 = 0 };
  82669. + fifosize_data_t dptxfsiz = {.d32 = 0 };
  82670. +
  82671. + ep = get_ep_from_handle(pcd, ep_handle);
  82672. +
  82673. + if (!ep || !ep->desc) {
  82674. + DWC_DEBUGPL(DBG_PCD, "bad ep address\n");
  82675. + return -DWC_E_INVALID;
  82676. + }
  82677. +
  82678. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  82679. +
  82680. + dwc_otg_request_nuke(ep);
  82681. +
  82682. + dwc_otg_ep_deactivate(GET_CORE_IF(pcd), &ep->dwc_ep);
  82683. + if (pcd->core_if->core_params->dev_out_nak) {
  82684. + DWC_TIMER_CANCEL(pcd->core_if->ep_xfer_timer[ep->dwc_ep.num]);
  82685. + pcd->core_if->ep_xfer_info[ep->dwc_ep.num].state = 0;
  82686. + }
  82687. + ep->desc = NULL;
  82688. + ep->stopped = 1;
  82689. +
  82690. + gdfifocfg.d32 =
  82691. + DWC_READ_REG32(&GET_CORE_IF(pcd)->core_global_regs->gdfifocfg);
  82692. + gdfifocfgbase.d32 = gdfifocfg.d32 >> 16;
  82693. +
  82694. + if (ep->dwc_ep.is_in) {
  82695. + if (GET_CORE_IF(pcd)->en_multiple_tx_fifo) {
  82696. + /* Flush the Tx FIFO */
  82697. + dwc_otg_flush_tx_fifo(GET_CORE_IF(pcd),
  82698. + ep->dwc_ep.tx_fifo_num);
  82699. + }
  82700. + release_perio_tx_fifo(GET_CORE_IF(pcd), ep->dwc_ep.tx_fifo_num);
  82701. + release_tx_fifo(GET_CORE_IF(pcd), ep->dwc_ep.tx_fifo_num);
  82702. + if (GET_CORE_IF(pcd)->en_multiple_tx_fifo) {
  82703. + /* Decreasing EPinfo Base Addr */
  82704. + dptxfsiz.d32 =
  82705. + (DWC_READ_REG32
  82706. + (&GET_CORE_IF(pcd)->
  82707. + core_global_regs->dtxfsiz[ep->dwc_ep.tx_fifo_num-1]) >> 16);
  82708. + gdfifocfg.b.epinfobase = gdfifocfgbase.d32 - dptxfsiz.d32;
  82709. + if (GET_CORE_IF(pcd)->snpsid <= OTG_CORE_REV_2_94a) {
  82710. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gdfifocfg,
  82711. + gdfifocfg.d32);
  82712. + }
  82713. + }
  82714. + }
  82715. +
  82716. + /* Free DMA Descriptors */
  82717. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  82718. + if (ep->dwc_ep.type != UE_ISOCHRONOUS) {
  82719. + desc_addr = ep->dwc_ep.desc_addr;
  82720. + dma_desc_addr = ep->dwc_ep.dma_desc_addr;
  82721. +
  82722. + /* Cannot call dma_free_coherent() with IRQs disabled */
  82723. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  82724. + dwc_otg_ep_free_desc_chain(desc_addr, dma_desc_addr,
  82725. + MAX_DMA_DESC_CNT);
  82726. +
  82727. + goto out_unlocked;
  82728. + }
  82729. + }
  82730. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  82731. +
  82732. +out_unlocked:
  82733. + DWC_DEBUGPL(DBG_PCD, "%d %s disabled\n", ep->dwc_ep.num,
  82734. + ep->dwc_ep.is_in ? "IN" : "OUT");
  82735. + return 0;
  82736. +
  82737. +}
  82738. +
  82739. +/******************************************************************************/
  82740. +#ifdef DWC_UTE_PER_IO
  82741. +
  82742. +/**
  82743. + * Free the request and its extended parts
  82744. + *
  82745. + */
  82746. +void dwc_pcd_xiso_ereq_free(dwc_otg_pcd_ep_t * ep, dwc_otg_pcd_request_t * req)
  82747. +{
  82748. + DWC_FREE(req->ext_req.per_io_frame_descs);
  82749. + DWC_FREE(req);
  82750. +}
  82751. +
  82752. +/**
  82753. + * Start the next request in the endpoint's queue.
  82754. + *
  82755. + */
  82756. +int dwc_otg_pcd_xiso_start_next_request(dwc_otg_pcd_t * pcd,
  82757. + dwc_otg_pcd_ep_t * ep)
  82758. +{
  82759. + int i;
  82760. + dwc_otg_pcd_request_t *req = NULL;
  82761. + dwc_ep_t *dwcep = NULL;
  82762. + struct dwc_iso_xreq_port *ereq = NULL;
  82763. + struct dwc_iso_pkt_desc_port *ddesc_iso;
  82764. + uint16_t nat;
  82765. + depctl_data_t diepctl;
  82766. +
  82767. + dwcep = &ep->dwc_ep;
  82768. +
  82769. + if (dwcep->xiso_active_xfers > 0) {
  82770. +#if 0 //Disable this to decrease s/w overhead that is crucial for Isoc transfers
  82771. + DWC_WARN("There are currently active transfers for EP%d \
  82772. + (active=%d; queued=%d)", dwcep->num, dwcep->xiso_active_xfers,
  82773. + dwcep->xiso_queued_xfers);
  82774. +#endif
  82775. + return 0;
  82776. + }
  82777. +
  82778. + nat = UGETW(ep->desc->wMaxPacketSize);
  82779. + nat = (nat >> 11) & 0x03;
  82780. +
  82781. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  82782. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  82783. + ereq = &req->ext_req;
  82784. + ep->stopped = 0;
  82785. +
  82786. + /* Get the frame number */
  82787. + dwcep->xiso_frame_num =
  82788. + dwc_otg_get_frame_number(GET_CORE_IF(pcd));
  82789. + DWC_DEBUG("FRM_NUM=%d", dwcep->xiso_frame_num);
  82790. +
  82791. + ddesc_iso = ereq->per_io_frame_descs;
  82792. +
  82793. + if (dwcep->is_in) {
  82794. + /* Setup DMA Descriptor chain for IN Isoc request */
  82795. + for (i = 0; i < ereq->pio_pkt_count; i++) {
  82796. + //if ((i % (nat + 1)) == 0)
  82797. + if ( i > 0 )
  82798. + dwcep->xiso_frame_num =
  82799. + (dwcep->xiso_bInterval +
  82800. + dwcep->xiso_frame_num) & 0x3FFF;
  82801. + dwcep->desc_addr[i].buf =
  82802. + req->dma + ddesc_iso[i].offset;
  82803. + dwcep->desc_addr[i].status.b_iso_in.txbytes =
  82804. + ddesc_iso[i].length;
  82805. + dwcep->desc_addr[i].status.b_iso_in.framenum =
  82806. + dwcep->xiso_frame_num;
  82807. + dwcep->desc_addr[i].status.b_iso_in.bs =
  82808. + BS_HOST_READY;
  82809. + dwcep->desc_addr[i].status.b_iso_in.txsts = 0;
  82810. + dwcep->desc_addr[i].status.b_iso_in.sp =
  82811. + (ddesc_iso[i].length %
  82812. + dwcep->maxpacket) ? 1 : 0;
  82813. + dwcep->desc_addr[i].status.b_iso_in.ioc = 0;
  82814. + dwcep->desc_addr[i].status.b_iso_in.pid = nat + 1;
  82815. + dwcep->desc_addr[i].status.b_iso_in.l = 0;
  82816. +
  82817. + /* Process the last descriptor */
  82818. + if (i == ereq->pio_pkt_count - 1) {
  82819. + dwcep->desc_addr[i].status.b_iso_in.ioc = 1;
  82820. + dwcep->desc_addr[i].status.b_iso_in.l = 1;
  82821. + }
  82822. + }
  82823. +
  82824. + /* Setup and start the transfer for this endpoint */
  82825. + dwcep->xiso_active_xfers++;
  82826. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->dev_if->
  82827. + in_ep_regs[dwcep->num]->diepdma,
  82828. + dwcep->dma_desc_addr);
  82829. + diepctl.d32 = 0;
  82830. + diepctl.b.epena = 1;
  82831. + diepctl.b.cnak = 1;
  82832. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->dev_if->
  82833. + in_ep_regs[dwcep->num]->diepctl, 0,
  82834. + diepctl.d32);
  82835. + } else {
  82836. + /* Setup DMA Descriptor chain for OUT Isoc request */
  82837. + for (i = 0; i < ereq->pio_pkt_count; i++) {
  82838. + //if ((i % (nat + 1)) == 0)
  82839. + dwcep->xiso_frame_num = (dwcep->xiso_bInterval +
  82840. + dwcep->xiso_frame_num) & 0x3FFF;
  82841. + dwcep->desc_addr[i].buf =
  82842. + req->dma + ddesc_iso[i].offset;
  82843. + dwcep->desc_addr[i].status.b_iso_out.rxbytes =
  82844. + ddesc_iso[i].length;
  82845. + dwcep->desc_addr[i].status.b_iso_out.framenum =
  82846. + dwcep->xiso_frame_num;
  82847. + dwcep->desc_addr[i].status.b_iso_out.bs =
  82848. + BS_HOST_READY;
  82849. + dwcep->desc_addr[i].status.b_iso_out.rxsts = 0;
  82850. + dwcep->desc_addr[i].status.b_iso_out.sp =
  82851. + (ddesc_iso[i].length %
  82852. + dwcep->maxpacket) ? 1 : 0;
  82853. + dwcep->desc_addr[i].status.b_iso_out.ioc = 0;
  82854. + dwcep->desc_addr[i].status.b_iso_out.pid = nat + 1;
  82855. + dwcep->desc_addr[i].status.b_iso_out.l = 0;
  82856. +
  82857. + /* Process the last descriptor */
  82858. + if (i == ereq->pio_pkt_count - 1) {
  82859. + dwcep->desc_addr[i].status.b_iso_out.ioc = 1;
  82860. + dwcep->desc_addr[i].status.b_iso_out.l = 1;
  82861. + }
  82862. + }
  82863. +
  82864. + /* Setup and start the transfer for this endpoint */
  82865. + dwcep->xiso_active_xfers++;
  82866. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->
  82867. + dev_if->out_ep_regs[dwcep->num]->
  82868. + doepdma, dwcep->dma_desc_addr);
  82869. + diepctl.d32 = 0;
  82870. + diepctl.b.epena = 1;
  82871. + diepctl.b.cnak = 1;
  82872. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->
  82873. + dev_if->out_ep_regs[dwcep->num]->
  82874. + doepctl, 0, diepctl.d32);
  82875. + }
  82876. +
  82877. + } else {
  82878. + ep->stopped = 1;
  82879. + }
  82880. +
  82881. + return 0;
  82882. +}
  82883. +
  82884. +/**
  82885. + * - Remove the request from the queue
  82886. + */
  82887. +void complete_xiso_ep(dwc_otg_pcd_ep_t * ep)
  82888. +{
  82889. + dwc_otg_pcd_request_t *req = NULL;
  82890. + struct dwc_iso_xreq_port *ereq = NULL;
  82891. + struct dwc_iso_pkt_desc_port *ddesc_iso = NULL;
  82892. + dwc_ep_t *dwcep = NULL;
  82893. + int i;
  82894. +
  82895. + //DWC_DEBUG();
  82896. + dwcep = &ep->dwc_ep;
  82897. +
  82898. + /* Get the first pending request from the queue */
  82899. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  82900. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  82901. + if (!req) {
  82902. + DWC_PRINTF("complete_ep 0x%p, req = NULL!\n", ep);
  82903. + return;
  82904. + }
  82905. + dwcep->xiso_active_xfers--;
  82906. + dwcep->xiso_queued_xfers--;
  82907. + /* Remove this request from the queue */
  82908. + DWC_CIRCLEQ_REMOVE_INIT(&ep->queue, req, queue_entry);
  82909. + } else {
  82910. + DWC_PRINTF("complete_ep 0x%p, ep->queue empty!\n", ep);
  82911. + return;
  82912. + }
  82913. +
  82914. + ep->stopped = 1;
  82915. + ereq = &req->ext_req;
  82916. + ddesc_iso = ereq->per_io_frame_descs;
  82917. +
  82918. + if (dwcep->xiso_active_xfers < 0) {
  82919. + DWC_WARN("EP#%d (xiso_active_xfers=%d)", dwcep->num,
  82920. + dwcep->xiso_active_xfers);
  82921. + }
  82922. +
  82923. + /* Fill the Isoc descs of portable extended req from dma descriptors */
  82924. + for (i = 0; i < ereq->pio_pkt_count; i++) {
  82925. + if (dwcep->is_in) { /* IN endpoints */
  82926. + ddesc_iso[i].actual_length = ddesc_iso[i].length -
  82927. + dwcep->desc_addr[i].status.b_iso_in.txbytes;
  82928. + ddesc_iso[i].status =
  82929. + dwcep->desc_addr[i].status.b_iso_in.txsts;
  82930. + } else { /* OUT endpoints */
  82931. + ddesc_iso[i].actual_length = ddesc_iso[i].length -
  82932. + dwcep->desc_addr[i].status.b_iso_out.rxbytes;
  82933. + ddesc_iso[i].status =
  82934. + dwcep->desc_addr[i].status.b_iso_out.rxsts;
  82935. + }
  82936. + }
  82937. +
  82938. + DWC_SPINUNLOCK(ep->pcd->lock);
  82939. +
  82940. + /* Call the completion function in the non-portable logic */
  82941. + ep->pcd->fops->xisoc_complete(ep->pcd, ep->priv, req->priv, 0,
  82942. + &req->ext_req);
  82943. +
  82944. + DWC_SPINLOCK(ep->pcd->lock);
  82945. +
  82946. + /* Free the request - specific freeing needed for extended request object */
  82947. + dwc_pcd_xiso_ereq_free(ep, req);
  82948. +
  82949. + /* Start the next request */
  82950. + dwc_otg_pcd_xiso_start_next_request(ep->pcd, ep);
  82951. +
  82952. + return;
  82953. +}
  82954. +
  82955. +/**
  82956. + * Create and initialize the Isoc pkt descriptors of the extended request.
  82957. + *
  82958. + */
  82959. +static int dwc_otg_pcd_xiso_create_pkt_descs(dwc_otg_pcd_request_t * req,
  82960. + void *ereq_nonport,
  82961. + int atomic_alloc)
  82962. +{
  82963. + struct dwc_iso_xreq_port *ereq = NULL;
  82964. + struct dwc_iso_xreq_port *req_mapped = NULL;
  82965. + struct dwc_iso_pkt_desc_port *ipds = NULL; /* To be created in this function */
  82966. + uint32_t pkt_count;
  82967. + int i;
  82968. +
  82969. + ereq = &req->ext_req;
  82970. + req_mapped = (struct dwc_iso_xreq_port *)ereq_nonport;
  82971. + pkt_count = req_mapped->pio_pkt_count;
  82972. +
  82973. + /* Create the isoc descs */
  82974. + if (atomic_alloc) {
  82975. + ipds = DWC_ALLOC_ATOMIC(sizeof(*ipds) * pkt_count);
  82976. + } else {
  82977. + ipds = DWC_ALLOC(sizeof(*ipds) * pkt_count);
  82978. + }
  82979. +
  82980. + if (!ipds) {
  82981. + DWC_ERROR("Failed to allocate isoc descriptors");
  82982. + return -DWC_E_NO_MEMORY;
  82983. + }
  82984. +
  82985. + /* Initialize the extended request fields */
  82986. + ereq->per_io_frame_descs = ipds;
  82987. + ereq->error_count = 0;
  82988. + ereq->pio_alloc_pkt_count = pkt_count;
  82989. + ereq->pio_pkt_count = pkt_count;
  82990. + ereq->tr_sub_flags = req_mapped->tr_sub_flags;
  82991. +
  82992. + /* Init the Isoc descriptors */
  82993. + for (i = 0; i < pkt_count; i++) {
  82994. + ipds[i].length = req_mapped->per_io_frame_descs[i].length;
  82995. + ipds[i].offset = req_mapped->per_io_frame_descs[i].offset;
  82996. + ipds[i].status = req_mapped->per_io_frame_descs[i].status; /* 0 */
  82997. + ipds[i].actual_length =
  82998. + req_mapped->per_io_frame_descs[i].actual_length;
  82999. + }
  83000. +
  83001. + return 0;
  83002. +}
  83003. +
  83004. +static void prn_ext_request(struct dwc_iso_xreq_port *ereq)
  83005. +{
  83006. + struct dwc_iso_pkt_desc_port *xfd = NULL;
  83007. + int i;
  83008. +
  83009. + DWC_DEBUG("per_io_frame_descs=%p", ereq->per_io_frame_descs);
  83010. + DWC_DEBUG("tr_sub_flags=%d", ereq->tr_sub_flags);
  83011. + DWC_DEBUG("error_count=%d", ereq->error_count);
  83012. + DWC_DEBUG("pio_alloc_pkt_count=%d", ereq->pio_alloc_pkt_count);
  83013. + DWC_DEBUG("pio_pkt_count=%d", ereq->pio_pkt_count);
  83014. + DWC_DEBUG("res=%d", ereq->res);
  83015. +
  83016. + for (i = 0; i < ereq->pio_pkt_count; i++) {
  83017. + xfd = &ereq->per_io_frame_descs[0];
  83018. + DWC_DEBUG("FD #%d", i);
  83019. +
  83020. + DWC_DEBUG("xfd->actual_length=%d", xfd->actual_length);
  83021. + DWC_DEBUG("xfd->length=%d", xfd->length);
  83022. + DWC_DEBUG("xfd->offset=%d", xfd->offset);
  83023. + DWC_DEBUG("xfd->status=%d", xfd->status);
  83024. + }
  83025. +}
  83026. +
  83027. +/**
  83028. + *
  83029. + */
  83030. +int dwc_otg_pcd_xiso_ep_queue(dwc_otg_pcd_t * pcd, void *ep_handle,
  83031. + uint8_t * buf, dwc_dma_t dma_buf, uint32_t buflen,
  83032. + int zero, void *req_handle, int atomic_alloc,
  83033. + void *ereq_nonport)
  83034. +{
  83035. + dwc_otg_pcd_request_t *req = NULL;
  83036. + dwc_otg_pcd_ep_t *ep;
  83037. + dwc_irqflags_t flags;
  83038. + int res;
  83039. +
  83040. + ep = get_ep_from_handle(pcd, ep_handle);
  83041. + if (!ep) {
  83042. + DWC_WARN("bad ep\n");
  83043. + return -DWC_E_INVALID;
  83044. + }
  83045. +
  83046. + /* We support this extension only for DDMA mode */
  83047. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC)
  83048. + if (!GET_CORE_IF(pcd)->dma_desc_enable)
  83049. + return -DWC_E_INVALID;
  83050. +
  83051. + /* Create a dwc_otg_pcd_request_t object */
  83052. + if (atomic_alloc) {
  83053. + req = DWC_ALLOC_ATOMIC(sizeof(*req));
  83054. + } else {
  83055. + req = DWC_ALLOC(sizeof(*req));
  83056. + }
  83057. +
  83058. + if (!req) {
  83059. + return -DWC_E_NO_MEMORY;
  83060. + }
  83061. +
  83062. + /* Create the Isoc descs for this request which shall be the exact match
  83063. + * of the structure sent to us from the non-portable logic */
  83064. + res =
  83065. + dwc_otg_pcd_xiso_create_pkt_descs(req, ereq_nonport, atomic_alloc);
  83066. + if (res) {
  83067. + DWC_WARN("Failed to init the Isoc descriptors");
  83068. + DWC_FREE(req);
  83069. + return res;
  83070. + }
  83071. +
  83072. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  83073. +
  83074. + DWC_CIRCLEQ_INIT_ENTRY(req, queue_entry);
  83075. + req->buf = buf;
  83076. + req->dma = dma_buf;
  83077. + req->length = buflen;
  83078. + req->sent_zlp = zero;
  83079. + req->priv = req_handle;
  83080. +
  83081. + //DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  83082. + ep->dwc_ep.dma_addr = dma_buf;
  83083. + ep->dwc_ep.start_xfer_buff = buf;
  83084. + ep->dwc_ep.xfer_buff = buf;
  83085. + ep->dwc_ep.xfer_len = 0;
  83086. + ep->dwc_ep.xfer_count = 0;
  83087. + ep->dwc_ep.sent_zlp = 0;
  83088. + ep->dwc_ep.total_len = buflen;
  83089. +
  83090. + /* Add this request to the tail */
  83091. + DWC_CIRCLEQ_INSERT_TAIL(&ep->queue, req, queue_entry);
  83092. + ep->dwc_ep.xiso_queued_xfers++;
  83093. +
  83094. +//DWC_DEBUG("CP_0");
  83095. +//DWC_DEBUG("req->ext_req.tr_sub_flags=%d", req->ext_req.tr_sub_flags);
  83096. +//prn_ext_request((struct dwc_iso_xreq_port *) ereq_nonport);
  83097. +//prn_ext_request(&req->ext_req);
  83098. +
  83099. + //DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  83100. +
  83101. + /* If the req->status == ASAP then check if there is any active transfer
  83102. + * for this endpoint. If no active transfers, then get the first entry
  83103. + * from the queue and start that transfer
  83104. + */
  83105. + if (req->ext_req.tr_sub_flags == DWC_EREQ_TF_ASAP) {
  83106. + res = dwc_otg_pcd_xiso_start_next_request(pcd, ep);
  83107. + if (res) {
  83108. + DWC_WARN("Failed to start the next Isoc transfer");
  83109. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  83110. + DWC_FREE(req);
  83111. + return res;
  83112. + }
  83113. + }
  83114. +
  83115. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  83116. + return 0;
  83117. +}
  83118. +
  83119. +#endif
  83120. +/* END ifdef DWC_UTE_PER_IO ***************************************************/
  83121. +int dwc_otg_pcd_ep_queue(dwc_otg_pcd_t * pcd, void *ep_handle,
  83122. + uint8_t * buf, dwc_dma_t dma_buf, uint32_t buflen,
  83123. + int zero, void *req_handle, int atomic_alloc)
  83124. +{
  83125. + dwc_irqflags_t flags;
  83126. + dwc_otg_pcd_request_t *req;
  83127. + dwc_otg_pcd_ep_t *ep;
  83128. + uint32_t max_transfer;
  83129. +
  83130. + ep = get_ep_from_handle(pcd, ep_handle);
  83131. + if (!ep || (!ep->desc && ep->dwc_ep.num != 0)) {
  83132. + DWC_WARN("bad ep\n");
  83133. + return -DWC_E_INVALID;
  83134. + }
  83135. +
  83136. + if (atomic_alloc) {
  83137. + req = DWC_ALLOC_ATOMIC(sizeof(*req));
  83138. + } else {
  83139. + req = DWC_ALLOC(sizeof(*req));
  83140. + }
  83141. +
  83142. + if (!req) {
  83143. + return -DWC_E_NO_MEMORY;
  83144. + }
  83145. + DWC_CIRCLEQ_INIT_ENTRY(req, queue_entry);
  83146. + if (!GET_CORE_IF(pcd)->core_params->opt) {
  83147. + if (ep->dwc_ep.num != 0) {
  83148. + DWC_ERROR("queue req %p, len %d buf %p\n",
  83149. + req_handle, buflen, buf);
  83150. + }
  83151. + }
  83152. +
  83153. + req->buf = buf;
  83154. + req->dma = dma_buf;
  83155. + req->length = buflen;
  83156. + req->sent_zlp = zero;
  83157. + req->priv = req_handle;
  83158. + req->dw_align_buf = NULL;
  83159. + if ((dma_buf & 0x3) && GET_CORE_IF(pcd)->dma_enable
  83160. + && !GET_CORE_IF(pcd)->dma_desc_enable)
  83161. + req->dw_align_buf = DWC_DMA_ALLOC(buflen,
  83162. + &req->dw_align_buf_dma);
  83163. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  83164. +
  83165. + /*
  83166. + * After adding request to the queue for IN ISOC wait for In Token Received
  83167. + * when TX FIFO is empty interrupt and for OUT ISOC wait for OUT Token
  83168. + * Received when EP is disabled interrupt to obtain starting microframe
  83169. + * (odd/even) start transfer
  83170. + */
  83171. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  83172. + if (req != 0) {
  83173. + depctl_data_t depctl = {.d32 =
  83174. + DWC_READ_REG32(&pcd->core_if->dev_if->
  83175. + in_ep_regs[ep->dwc_ep.num]->
  83176. + diepctl) };
  83177. + ++pcd->request_pending;
  83178. +
  83179. + DWC_CIRCLEQ_INSERT_TAIL(&ep->queue, req, queue_entry);
  83180. + if (ep->dwc_ep.is_in) {
  83181. + depctl.b.cnak = 1;
  83182. + DWC_WRITE_REG32(&pcd->core_if->dev_if->
  83183. + in_ep_regs[ep->dwc_ep.num]->
  83184. + diepctl, depctl.d32);
  83185. + }
  83186. +
  83187. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  83188. + }
  83189. + return 0;
  83190. + }
  83191. +
  83192. + /*
  83193. + * For EP0 IN without premature status, zlp is required?
  83194. + */
  83195. + if (ep->dwc_ep.num == 0 && ep->dwc_ep.is_in) {
  83196. + DWC_DEBUGPL(DBG_PCDV, "%d-OUT ZLP\n", ep->dwc_ep.num);
  83197. + //_req->zero = 1;
  83198. + }
  83199. +
  83200. + /* Start the transfer */
  83201. + if (DWC_CIRCLEQ_EMPTY(&ep->queue) && !ep->stopped) {
  83202. + /* EP0 Transfer? */
  83203. + if (ep->dwc_ep.num == 0) {
  83204. + switch (pcd->ep0state) {
  83205. + case EP0_IN_DATA_PHASE:
  83206. + DWC_DEBUGPL(DBG_PCD,
  83207. + "%s ep0: EP0_IN_DATA_PHASE\n",
  83208. + __func__);
  83209. + break;
  83210. +
  83211. + case EP0_OUT_DATA_PHASE:
  83212. + DWC_DEBUGPL(DBG_PCD,
  83213. + "%s ep0: EP0_OUT_DATA_PHASE\n",
  83214. + __func__);
  83215. + if (pcd->request_config) {
  83216. + /* Complete STATUS PHASE */
  83217. + ep->dwc_ep.is_in = 1;
  83218. + pcd->ep0state = EP0_IN_STATUS_PHASE;
  83219. + }
  83220. + break;
  83221. +
  83222. + case EP0_IN_STATUS_PHASE:
  83223. + DWC_DEBUGPL(DBG_PCD,
  83224. + "%s ep0: EP0_IN_STATUS_PHASE\n",
  83225. + __func__);
  83226. + break;
  83227. +
  83228. + default:
  83229. + DWC_DEBUGPL(DBG_ANY, "ep0: odd state %d\n",
  83230. + pcd->ep0state);
  83231. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  83232. + return -DWC_E_SHUTDOWN;
  83233. + }
  83234. +
  83235. + ep->dwc_ep.dma_addr = dma_buf;
  83236. + ep->dwc_ep.start_xfer_buff = buf;
  83237. + ep->dwc_ep.xfer_buff = buf;
  83238. + ep->dwc_ep.xfer_len = buflen;
  83239. + ep->dwc_ep.xfer_count = 0;
  83240. + ep->dwc_ep.sent_zlp = 0;
  83241. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  83242. +
  83243. + if (zero) {
  83244. + if ((ep->dwc_ep.xfer_len %
  83245. + ep->dwc_ep.maxpacket == 0)
  83246. + && (ep->dwc_ep.xfer_len != 0)) {
  83247. + ep->dwc_ep.sent_zlp = 1;
  83248. + }
  83249. +
  83250. + }
  83251. +
  83252. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd),
  83253. + &ep->dwc_ep);
  83254. + } // non-ep0 endpoints
  83255. + else {
  83256. +#ifdef DWC_UTE_CFI
  83257. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  83258. + /* store the request length */
  83259. + ep->dwc_ep.cfi_req_len = buflen;
  83260. + pcd->cfi->ops.build_descriptors(pcd->cfi, pcd,
  83261. + ep, req);
  83262. + } else {
  83263. +#endif
  83264. + max_transfer =
  83265. + GET_CORE_IF(ep->pcd)->core_params->
  83266. + max_transfer_size;
  83267. +
  83268. + /* Setup and start the Transfer */
  83269. + if (req->dw_align_buf){
  83270. + if (ep->dwc_ep.is_in)
  83271. + dwc_memcpy(req->dw_align_buf,
  83272. + buf, buflen);
  83273. + ep->dwc_ep.dma_addr =
  83274. + req->dw_align_buf_dma;
  83275. + ep->dwc_ep.start_xfer_buff =
  83276. + req->dw_align_buf;
  83277. + ep->dwc_ep.xfer_buff =
  83278. + req->dw_align_buf;
  83279. + } else {
  83280. + ep->dwc_ep.dma_addr = dma_buf;
  83281. + ep->dwc_ep.start_xfer_buff = buf;
  83282. + ep->dwc_ep.xfer_buff = buf;
  83283. + }
  83284. + ep->dwc_ep.xfer_len = 0;
  83285. + ep->dwc_ep.xfer_count = 0;
  83286. + ep->dwc_ep.sent_zlp = 0;
  83287. + ep->dwc_ep.total_len = buflen;
  83288. +
  83289. + ep->dwc_ep.maxxfer = max_transfer;
  83290. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  83291. + uint32_t out_max_xfer =
  83292. + DDMA_MAX_TRANSFER_SIZE -
  83293. + (DDMA_MAX_TRANSFER_SIZE % 4);
  83294. + if (ep->dwc_ep.is_in) {
  83295. + if (ep->dwc_ep.maxxfer >
  83296. + DDMA_MAX_TRANSFER_SIZE) {
  83297. + ep->dwc_ep.maxxfer =
  83298. + DDMA_MAX_TRANSFER_SIZE;
  83299. + }
  83300. + } else {
  83301. + if (ep->dwc_ep.maxxfer >
  83302. + out_max_xfer) {
  83303. + ep->dwc_ep.maxxfer =
  83304. + out_max_xfer;
  83305. + }
  83306. + }
  83307. + }
  83308. + if (ep->dwc_ep.maxxfer < ep->dwc_ep.total_len) {
  83309. + ep->dwc_ep.maxxfer -=
  83310. + (ep->dwc_ep.maxxfer %
  83311. + ep->dwc_ep.maxpacket);
  83312. + }
  83313. +
  83314. + if (zero) {
  83315. + if ((ep->dwc_ep.total_len %
  83316. + ep->dwc_ep.maxpacket == 0)
  83317. + && (ep->dwc_ep.total_len != 0)) {
  83318. + ep->dwc_ep.sent_zlp = 1;
  83319. + }
  83320. + }
  83321. +#ifdef DWC_UTE_CFI
  83322. + }
  83323. +#endif
  83324. + dwc_otg_ep_start_transfer(GET_CORE_IF(pcd),
  83325. + &ep->dwc_ep);
  83326. + }
  83327. + }
  83328. +
  83329. + if (req != 0) {
  83330. + ++pcd->request_pending;
  83331. + DWC_CIRCLEQ_INSERT_TAIL(&ep->queue, req, queue_entry);
  83332. + if (ep->dwc_ep.is_in && ep->stopped
  83333. + && !(GET_CORE_IF(pcd)->dma_enable)) {
  83334. + /** @todo NGS Create a function for this. */
  83335. + diepmsk_data_t diepmsk = {.d32 = 0 };
  83336. + diepmsk.b.intktxfemp = 1;
  83337. + if (GET_CORE_IF(pcd)->multiproc_int_enable) {
  83338. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->
  83339. + dev_if->dev_global_regs->diepeachintmsk
  83340. + [ep->dwc_ep.num], 0,
  83341. + diepmsk.d32);
  83342. + } else {
  83343. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->
  83344. + dev_if->dev_global_regs->
  83345. + diepmsk, 0, diepmsk.d32);
  83346. + }
  83347. +
  83348. + }
  83349. + }
  83350. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  83351. +
  83352. + return 0;
  83353. +}
  83354. +
  83355. +int dwc_otg_pcd_ep_dequeue(dwc_otg_pcd_t * pcd, void *ep_handle,
  83356. + void *req_handle)
  83357. +{
  83358. + dwc_irqflags_t flags;
  83359. + dwc_otg_pcd_request_t *req;
  83360. + dwc_otg_pcd_ep_t *ep;
  83361. +
  83362. + ep = get_ep_from_handle(pcd, ep_handle);
  83363. + if (!ep || (!ep->desc && ep->dwc_ep.num != 0)) {
  83364. + DWC_WARN("bad argument\n");
  83365. + return -DWC_E_INVALID;
  83366. + }
  83367. +
  83368. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  83369. +
  83370. + /* make sure it's actually queued on this endpoint */
  83371. + DWC_CIRCLEQ_FOREACH(req, &ep->queue, queue_entry) {
  83372. + if (req->priv == (void *)req_handle) {
  83373. + break;
  83374. + }
  83375. + }
  83376. +
  83377. + if (req->priv != (void *)req_handle) {
  83378. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  83379. + return -DWC_E_INVALID;
  83380. + }
  83381. +
  83382. + if (!DWC_CIRCLEQ_EMPTY_ENTRY(req, queue_entry)) {
  83383. + dwc_otg_request_done(ep, req, -DWC_E_RESTART);
  83384. + } else {
  83385. + req = NULL;
  83386. + }
  83387. +
  83388. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  83389. +
  83390. + return req ? 0 : -DWC_E_SHUTDOWN;
  83391. +
  83392. +}
  83393. +
  83394. +/**
  83395. + * dwc_otg_pcd_ep_wedge - sets the halt feature and ignores clear requests
  83396. + *
  83397. + * Use this to stall an endpoint and ignore CLEAR_FEATURE(HALT_ENDPOINT)
  83398. + * requests. If the gadget driver clears the halt status, it will
  83399. + * automatically unwedge the endpoint.
  83400. + *
  83401. + * Returns zero on success, else negative DWC error code.
  83402. + */
  83403. +int dwc_otg_pcd_ep_wedge(dwc_otg_pcd_t * pcd, void *ep_handle)
  83404. +{
  83405. + dwc_otg_pcd_ep_t *ep;
  83406. + dwc_irqflags_t flags;
  83407. + int retval = 0;
  83408. +
  83409. + ep = get_ep_from_handle(pcd, ep_handle);
  83410. +
  83411. + if ((!ep->desc && ep != &pcd->ep0) ||
  83412. + (ep->desc && (ep->desc->bmAttributes == UE_ISOCHRONOUS))) {
  83413. + DWC_WARN("%s, bad ep\n", __func__);
  83414. + return -DWC_E_INVALID;
  83415. + }
  83416. +
  83417. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  83418. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  83419. + DWC_WARN("%d %s XFer In process\n", ep->dwc_ep.num,
  83420. + ep->dwc_ep.is_in ? "IN" : "OUT");
  83421. + retval = -DWC_E_AGAIN;
  83422. + } else {
  83423. + /* This code needs to be reviewed */
  83424. + if (ep->dwc_ep.is_in == 1 && GET_CORE_IF(pcd)->dma_desc_enable) {
  83425. + dtxfsts_data_t txstatus;
  83426. + fifosize_data_t txfifosize;
  83427. +
  83428. + txfifosize.d32 =
  83429. + DWC_READ_REG32(&GET_CORE_IF(pcd)->
  83430. + core_global_regs->dtxfsiz[ep->dwc_ep.
  83431. + tx_fifo_num]);
  83432. + txstatus.d32 =
  83433. + DWC_READ_REG32(&GET_CORE_IF(pcd)->
  83434. + dev_if->in_ep_regs[ep->dwc_ep.num]->
  83435. + dtxfsts);
  83436. +
  83437. + if (txstatus.b.txfspcavail < txfifosize.b.depth) {
  83438. + DWC_WARN("%s() Data In Tx Fifo\n", __func__);
  83439. + retval = -DWC_E_AGAIN;
  83440. + } else {
  83441. + if (ep->dwc_ep.num == 0) {
  83442. + pcd->ep0state = EP0_STALL;
  83443. + }
  83444. +
  83445. + ep->stopped = 1;
  83446. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd),
  83447. + &ep->dwc_ep);
  83448. + }
  83449. + } else {
  83450. + if (ep->dwc_ep.num == 0) {
  83451. + pcd->ep0state = EP0_STALL;
  83452. + }
  83453. +
  83454. + ep->stopped = 1;
  83455. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd), &ep->dwc_ep);
  83456. + }
  83457. + }
  83458. +
  83459. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  83460. +
  83461. + return retval;
  83462. +}
  83463. +
  83464. +int dwc_otg_pcd_ep_halt(dwc_otg_pcd_t * pcd, void *ep_handle, int value)
  83465. +{
  83466. + dwc_otg_pcd_ep_t *ep;
  83467. + dwc_irqflags_t flags;
  83468. + int retval = 0;
  83469. +
  83470. + ep = get_ep_from_handle(pcd, ep_handle);
  83471. +
  83472. + if (!ep || (!ep->desc && ep != &pcd->ep0) ||
  83473. + (ep->desc && (ep->desc->bmAttributes == UE_ISOCHRONOUS))) {
  83474. + DWC_WARN("%s, bad ep\n", __func__);
  83475. + return -DWC_E_INVALID;
  83476. + }
  83477. +
  83478. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  83479. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  83480. + DWC_WARN("%d %s XFer In process\n", ep->dwc_ep.num,
  83481. + ep->dwc_ep.is_in ? "IN" : "OUT");
  83482. + retval = -DWC_E_AGAIN;
  83483. + } else if (value == 0) {
  83484. + dwc_otg_ep_clear_stall(GET_CORE_IF(pcd), &ep->dwc_ep);
  83485. + } else if (value == 1) {
  83486. + if (ep->dwc_ep.is_in == 1 && GET_CORE_IF(pcd)->dma_desc_enable) {
  83487. + dtxfsts_data_t txstatus;
  83488. + fifosize_data_t txfifosize;
  83489. +
  83490. + txfifosize.d32 =
  83491. + DWC_READ_REG32(&GET_CORE_IF(pcd)->core_global_regs->
  83492. + dtxfsiz[ep->dwc_ep.tx_fifo_num]);
  83493. + txstatus.d32 =
  83494. + DWC_READ_REG32(&GET_CORE_IF(pcd)->dev_if->
  83495. + in_ep_regs[ep->dwc_ep.num]->dtxfsts);
  83496. +
  83497. + if (txstatus.b.txfspcavail < txfifosize.b.depth) {
  83498. + DWC_WARN("%s() Data In Tx Fifo\n", __func__);
  83499. + retval = -DWC_E_AGAIN;
  83500. + } else {
  83501. + if (ep->dwc_ep.num == 0) {
  83502. + pcd->ep0state = EP0_STALL;
  83503. + }
  83504. +
  83505. + ep->stopped = 1;
  83506. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd),
  83507. + &ep->dwc_ep);
  83508. + }
  83509. + } else {
  83510. + if (ep->dwc_ep.num == 0) {
  83511. + pcd->ep0state = EP0_STALL;
  83512. + }
  83513. +
  83514. + ep->stopped = 1;
  83515. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd), &ep->dwc_ep);
  83516. + }
  83517. + } else if (value == 2) {
  83518. + ep->dwc_ep.stall_clear_flag = 0;
  83519. + } else if (value == 3) {
  83520. + ep->dwc_ep.stall_clear_flag = 1;
  83521. + }
  83522. +
  83523. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  83524. +
  83525. + return retval;
  83526. +}
  83527. +
  83528. +/**
  83529. + * This function initiates remote wakeup of the host from suspend state.
  83530. + */
  83531. +void dwc_otg_pcd_rem_wkup_from_suspend(dwc_otg_pcd_t * pcd, int set)
  83532. +{
  83533. + dctl_data_t dctl = { 0 };
  83534. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  83535. + dsts_data_t dsts;
  83536. +
  83537. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  83538. + if (!dsts.b.suspsts) {
  83539. + DWC_WARN("Remote wakeup while is not in suspend state\n");
  83540. + }
  83541. + /* Check if DEVICE_REMOTE_WAKEUP feature enabled */
  83542. + if (pcd->remote_wakeup_enable) {
  83543. + if (set) {
  83544. +
  83545. + if (core_if->adp_enable) {
  83546. + gpwrdn_data_t gpwrdn;
  83547. +
  83548. + dwc_otg_adp_probe_stop(core_if);
  83549. +
  83550. + /* Mask SRP detected interrupt from Power Down Logic */
  83551. + gpwrdn.d32 = 0;
  83552. + gpwrdn.b.srp_det_msk = 1;
  83553. + DWC_MODIFY_REG32(&core_if->
  83554. + core_global_regs->gpwrdn,
  83555. + gpwrdn.d32, 0);
  83556. +
  83557. + /* Disable Power Down Logic */
  83558. + gpwrdn.d32 = 0;
  83559. + gpwrdn.b.pmuactv = 1;
  83560. + DWC_MODIFY_REG32(&core_if->
  83561. + core_global_regs->gpwrdn,
  83562. + gpwrdn.d32, 0);
  83563. +
  83564. + /*
  83565. + * Initialize the Core for Device mode.
  83566. + */
  83567. + core_if->op_state = B_PERIPHERAL;
  83568. + dwc_otg_core_init(core_if);
  83569. + dwc_otg_enable_global_interrupts(core_if);
  83570. + cil_pcd_start(core_if);
  83571. +
  83572. + dwc_otg_initiate_srp(core_if);
  83573. + }
  83574. +
  83575. + dctl.b.rmtwkupsig = 1;
  83576. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  83577. + dctl, 0, dctl.d32);
  83578. + DWC_DEBUGPL(DBG_PCD, "Set Remote Wakeup\n");
  83579. +
  83580. + dwc_mdelay(2);
  83581. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  83582. + dctl, dctl.d32, 0);
  83583. + DWC_DEBUGPL(DBG_PCD, "Clear Remote Wakeup\n");
  83584. + }
  83585. + } else {
  83586. + DWC_DEBUGPL(DBG_PCD, "Remote Wakeup is disabled\n");
  83587. + }
  83588. +}
  83589. +
  83590. +#ifdef CONFIG_USB_DWC_OTG_LPM
  83591. +/**
  83592. + * This function initiates remote wakeup of the host from L1 sleep state.
  83593. + */
  83594. +void dwc_otg_pcd_rem_wkup_from_sleep(dwc_otg_pcd_t * pcd, int set)
  83595. +{
  83596. + glpmcfg_data_t lpmcfg;
  83597. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  83598. +
  83599. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  83600. +
  83601. + /* Check if we are in L1 state */
  83602. + if (!lpmcfg.b.prt_sleep_sts) {
  83603. + DWC_DEBUGPL(DBG_PCD, "Device is not in sleep state\n");
  83604. + return;
  83605. + }
  83606. +
  83607. + /* Check if host allows remote wakeup */
  83608. + if (!lpmcfg.b.rem_wkup_en) {
  83609. + DWC_DEBUGPL(DBG_PCD, "Host does not allow remote wakeup\n");
  83610. + return;
  83611. + }
  83612. +
  83613. + /* Check if Resume OK */
  83614. + if (!lpmcfg.b.sleep_state_resumeok) {
  83615. + DWC_DEBUGPL(DBG_PCD, "Sleep state resume is not OK\n");
  83616. + return;
  83617. + }
  83618. +
  83619. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  83620. + lpmcfg.b.en_utmi_sleep = 0;
  83621. + lpmcfg.b.hird_thres &= (~(1 << 4));
  83622. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  83623. +
  83624. + if (set) {
  83625. + dctl_data_t dctl = {.d32 = 0 };
  83626. + dctl.b.rmtwkupsig = 1;
  83627. + /* Set RmtWkUpSig bit to start remote wakup signaling.
  83628. + * Hardware will automatically clear this bit.
  83629. + */
  83630. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl,
  83631. + 0, dctl.d32);
  83632. + DWC_DEBUGPL(DBG_PCD, "Set Remote Wakeup\n");
  83633. + }
  83634. +
  83635. +}
  83636. +#endif
  83637. +
  83638. +/**
  83639. + * Performs remote wakeup.
  83640. + */
  83641. +void dwc_otg_pcd_remote_wakeup(dwc_otg_pcd_t * pcd, int set)
  83642. +{
  83643. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  83644. + dwc_irqflags_t flags;
  83645. + if (dwc_otg_is_device_mode(core_if)) {
  83646. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  83647. +#ifdef CONFIG_USB_DWC_OTG_LPM
  83648. + if (core_if->lx_state == DWC_OTG_L1) {
  83649. + dwc_otg_pcd_rem_wkup_from_sleep(pcd, set);
  83650. + } else {
  83651. +#endif
  83652. + dwc_otg_pcd_rem_wkup_from_suspend(pcd, set);
  83653. +#ifdef CONFIG_USB_DWC_OTG_LPM
  83654. + }
  83655. +#endif
  83656. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  83657. + }
  83658. + return;
  83659. +}
  83660. +
  83661. +void dwc_otg_pcd_disconnect_us(dwc_otg_pcd_t * pcd, int no_of_usecs)
  83662. +{
  83663. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  83664. + dctl_data_t dctl = { 0 };
  83665. +
  83666. + if (dwc_otg_is_device_mode(core_if)) {
  83667. + dctl.b.sftdiscon = 1;
  83668. + DWC_PRINTF("Soft disconnect for %d useconds\n",no_of_usecs);
  83669. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  83670. + dwc_udelay(no_of_usecs);
  83671. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32,0);
  83672. +
  83673. + } else{
  83674. + DWC_PRINTF("NOT SUPPORTED IN HOST MODE\n");
  83675. + }
  83676. + return;
  83677. +
  83678. +}
  83679. +
  83680. +int dwc_otg_pcd_wakeup(dwc_otg_pcd_t * pcd)
  83681. +{
  83682. + dsts_data_t dsts;
  83683. + gotgctl_data_t gotgctl;
  83684. +
  83685. + /*
  83686. + * This function starts the Protocol if no session is in progress. If
  83687. + * a session is already in progress, but the device is suspended,
  83688. + * remote wakeup signaling is started.
  83689. + */
  83690. +
  83691. + /* Check if valid session */
  83692. + gotgctl.d32 =
  83693. + DWC_READ_REG32(&(GET_CORE_IF(pcd)->core_global_regs->gotgctl));
  83694. + if (gotgctl.b.bsesvld) {
  83695. + /* Check if suspend state */
  83696. + dsts.d32 =
  83697. + DWC_READ_REG32(&
  83698. + (GET_CORE_IF(pcd)->dev_if->
  83699. + dev_global_regs->dsts));
  83700. + if (dsts.b.suspsts) {
  83701. + dwc_otg_pcd_remote_wakeup(pcd, 1);
  83702. + }
  83703. + } else {
  83704. + dwc_otg_pcd_initiate_srp(pcd);
  83705. + }
  83706. +
  83707. + return 0;
  83708. +
  83709. +}
  83710. +
  83711. +/**
  83712. + * Start the SRP timer to detect when the SRP does not complete within
  83713. + * 6 seconds.
  83714. + *
  83715. + * @param pcd the pcd structure.
  83716. + */
  83717. +void dwc_otg_pcd_initiate_srp(dwc_otg_pcd_t * pcd)
  83718. +{
  83719. + dwc_irqflags_t flags;
  83720. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  83721. + dwc_otg_initiate_srp(GET_CORE_IF(pcd));
  83722. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  83723. +}
  83724. +
  83725. +int dwc_otg_pcd_get_frame_number(dwc_otg_pcd_t * pcd)
  83726. +{
  83727. + return dwc_otg_get_frame_number(GET_CORE_IF(pcd));
  83728. +}
  83729. +
  83730. +int dwc_otg_pcd_is_lpm_enabled(dwc_otg_pcd_t * pcd)
  83731. +{
  83732. + return GET_CORE_IF(pcd)->core_params->lpm_enable;
  83733. +}
  83734. +
  83735. +uint32_t get_b_hnp_enable(dwc_otg_pcd_t * pcd)
  83736. +{
  83737. + return pcd->b_hnp_enable;
  83738. +}
  83739. +
  83740. +uint32_t get_a_hnp_support(dwc_otg_pcd_t * pcd)
  83741. +{
  83742. + return pcd->a_hnp_support;
  83743. +}
  83744. +
  83745. +uint32_t get_a_alt_hnp_support(dwc_otg_pcd_t * pcd)
  83746. +{
  83747. + return pcd->a_alt_hnp_support;
  83748. +}
  83749. +
  83750. +int dwc_otg_pcd_get_rmwkup_enable(dwc_otg_pcd_t * pcd)
  83751. +{
  83752. + return pcd->remote_wakeup_enable;
  83753. +}
  83754. +
  83755. +#endif /* DWC_HOST_ONLY */
  83756. diff -Nur linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_pcd.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd.h
  83757. --- linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_pcd.h 1970-01-01 01:00:00.000000000 +0100
  83758. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd.h 2014-04-24 15:35:04.177565820 +0200
  83759. @@ -0,0 +1,266 @@
  83760. +/* ==========================================================================
  83761. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd.h $
  83762. + * $Revision: #48 $
  83763. + * $Date: 2012/08/10 $
  83764. + * $Change: 2047372 $
  83765. + *
  83766. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  83767. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  83768. + * otherwise expressly agreed to in writing between Synopsys and you.
  83769. + *
  83770. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  83771. + * any End User Software License Agreement or Agreement for Licensed Product
  83772. + * with Synopsys or any supplement thereto. You are permitted to use and
  83773. + * redistribute this Software in source and binary forms, with or without
  83774. + * modification, provided that redistributions of source code must retain this
  83775. + * notice. You may not view, use, disclose, copy or distribute this file or
  83776. + * any information contained herein except pursuant to this license grant from
  83777. + * Synopsys. If you do not agree with this notice, including the disclaimer
  83778. + * below, then you are not authorized to use the Software.
  83779. + *
  83780. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  83781. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  83782. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  83783. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  83784. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  83785. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  83786. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  83787. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  83788. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  83789. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  83790. + * DAMAGE.
  83791. + * ========================================================================== */
  83792. +#ifndef DWC_HOST_ONLY
  83793. +#if !defined(__DWC_PCD_H__)
  83794. +#define __DWC_PCD_H__
  83795. +
  83796. +#include "dwc_otg_os_dep.h"
  83797. +#include "usb.h"
  83798. +#include "dwc_otg_cil.h"
  83799. +#include "dwc_otg_pcd_if.h"
  83800. +struct cfiobject;
  83801. +
  83802. +/**
  83803. + * @file
  83804. + *
  83805. + * This file contains the structures, constants, and interfaces for
  83806. + * the Perpherial Contoller Driver (PCD).
  83807. + *
  83808. + * The Peripheral Controller Driver (PCD) for Linux will implement the
  83809. + * Gadget API, so that the existing Gadget drivers can be used. For
  83810. + * the Mass Storage Function driver the File-backed USB Storage Gadget
  83811. + * (FBS) driver will be used. The FBS driver supports the
  83812. + * Control-Bulk (CB), Control-Bulk-Interrupt (CBI), and Bulk-Only
  83813. + * transports.
  83814. + *
  83815. + */
  83816. +
  83817. +/** Invalid DMA Address */
  83818. +#define DWC_DMA_ADDR_INVALID (~(dwc_dma_t)0)
  83819. +
  83820. +/** Max Transfer size for any EP */
  83821. +#define DDMA_MAX_TRANSFER_SIZE 65535
  83822. +
  83823. +/**
  83824. + * Get the pointer to the core_if from the pcd pointer.
  83825. + */
  83826. +#define GET_CORE_IF( _pcd ) (_pcd->core_if)
  83827. +
  83828. +/**
  83829. + * States of EP0.
  83830. + */
  83831. +typedef enum ep0_state {
  83832. + EP0_DISCONNECT, /* no host */
  83833. + EP0_IDLE,
  83834. + EP0_IN_DATA_PHASE,
  83835. + EP0_OUT_DATA_PHASE,
  83836. + EP0_IN_STATUS_PHASE,
  83837. + EP0_OUT_STATUS_PHASE,
  83838. + EP0_STALL,
  83839. +} ep0state_e;
  83840. +
  83841. +/** Fordward declaration.*/
  83842. +struct dwc_otg_pcd;
  83843. +
  83844. +/** DWC_otg iso request structure.
  83845. + *
  83846. + */
  83847. +typedef struct usb_iso_request dwc_otg_pcd_iso_request_t;
  83848. +
  83849. +#ifdef DWC_UTE_PER_IO
  83850. +
  83851. +/**
  83852. + * This shall be the exact analogy of the same type structure defined in the
  83853. + * usb_gadget.h. Each descriptor contains
  83854. + */
  83855. +struct dwc_iso_pkt_desc_port {
  83856. + uint32_t offset;
  83857. + uint32_t length; /* expected length */
  83858. + uint32_t actual_length;
  83859. + uint32_t status;
  83860. +};
  83861. +
  83862. +struct dwc_iso_xreq_port {
  83863. + /** transfer/submission flag */
  83864. + uint32_t tr_sub_flags;
  83865. + /** Start the request ASAP */
  83866. +#define DWC_EREQ_TF_ASAP 0x00000002
  83867. + /** Just enqueue the request w/o initiating a transfer */
  83868. +#define DWC_EREQ_TF_ENQUEUE 0x00000004
  83869. +
  83870. + /**
  83871. + * count of ISO packets attached to this request - shall
  83872. + * not exceed the pio_alloc_pkt_count
  83873. + */
  83874. + uint32_t pio_pkt_count;
  83875. + /** count of ISO packets allocated for this request */
  83876. + uint32_t pio_alloc_pkt_count;
  83877. + /** number of ISO packet errors */
  83878. + uint32_t error_count;
  83879. + /** reserved for future extension */
  83880. + uint32_t res;
  83881. + /** Will be allocated and freed in the UTE gadget and based on the CFC value */
  83882. + struct dwc_iso_pkt_desc_port *per_io_frame_descs;
  83883. +};
  83884. +#endif
  83885. +/** DWC_otg request structure.
  83886. + * This structure is a list of requests.
  83887. + */
  83888. +typedef struct dwc_otg_pcd_request {
  83889. + void *priv;
  83890. + void *buf;
  83891. + dwc_dma_t dma;
  83892. + uint32_t length;
  83893. + uint32_t actual;
  83894. + unsigned sent_zlp:1;
  83895. + /**
  83896. + * Used instead of original buffer if
  83897. + * it(physical address) is not dword-aligned.
  83898. + **/
  83899. + uint8_t *dw_align_buf;
  83900. + dwc_dma_t dw_align_buf_dma;
  83901. +
  83902. + DWC_CIRCLEQ_ENTRY(dwc_otg_pcd_request) queue_entry;
  83903. +#ifdef DWC_UTE_PER_IO
  83904. + struct dwc_iso_xreq_port ext_req;
  83905. + //void *priv_ereq_nport; /* */
  83906. +#endif
  83907. +} dwc_otg_pcd_request_t;
  83908. +
  83909. +DWC_CIRCLEQ_HEAD(req_list, dwc_otg_pcd_request);
  83910. +
  83911. +/** PCD EP structure.
  83912. + * This structure describes an EP, there is an array of EPs in the PCD
  83913. + * structure.
  83914. + */
  83915. +typedef struct dwc_otg_pcd_ep {
  83916. + /** USB EP Descriptor */
  83917. + const usb_endpoint_descriptor_t *desc;
  83918. +
  83919. + /** queue of dwc_otg_pcd_requests. */
  83920. + struct req_list queue;
  83921. + unsigned stopped:1;
  83922. + unsigned disabling:1;
  83923. + unsigned dma:1;
  83924. + unsigned queue_sof:1;
  83925. +
  83926. +#ifdef DWC_EN_ISOC
  83927. + /** ISOC req handle passed */
  83928. + void *iso_req_handle;
  83929. +#endif //_EN_ISOC_
  83930. +
  83931. + /** DWC_otg ep data. */
  83932. + dwc_ep_t dwc_ep;
  83933. +
  83934. + /** Pointer to PCD */
  83935. + struct dwc_otg_pcd *pcd;
  83936. +
  83937. + void *priv;
  83938. +} dwc_otg_pcd_ep_t;
  83939. +
  83940. +/** DWC_otg PCD Structure.
  83941. + * This structure encapsulates the data for the dwc_otg PCD.
  83942. + */
  83943. +struct dwc_otg_pcd {
  83944. + const struct dwc_otg_pcd_function_ops *fops;
  83945. + /** The DWC otg device pointer */
  83946. + struct dwc_otg_device *otg_dev;
  83947. + /** Core Interface */
  83948. + dwc_otg_core_if_t *core_if;
  83949. + /** State of EP0 */
  83950. + ep0state_e ep0state;
  83951. + /** EP0 Request is pending */
  83952. + unsigned ep0_pending:1;
  83953. + /** Indicates when SET CONFIGURATION Request is in process */
  83954. + unsigned request_config:1;
  83955. + /** The state of the Remote Wakeup Enable. */
  83956. + unsigned remote_wakeup_enable:1;
  83957. + /** The state of the B-Device HNP Enable. */
  83958. + unsigned b_hnp_enable:1;
  83959. + /** The state of A-Device HNP Support. */
  83960. + unsigned a_hnp_support:1;
  83961. + /** The state of the A-Device Alt HNP support. */
  83962. + unsigned a_alt_hnp_support:1;
  83963. + /** Count of pending Requests */
  83964. + unsigned request_pending;
  83965. +
  83966. + /** SETUP packet for EP0
  83967. + * This structure is allocated as a DMA buffer on PCD initialization
  83968. + * with enough space for up to 3 setup packets.
  83969. + */
  83970. + union {
  83971. + usb_device_request_t req;
  83972. + uint32_t d32[2];
  83973. + } *setup_pkt;
  83974. +
  83975. + dwc_dma_t setup_pkt_dma_handle;
  83976. +
  83977. + /* Additional buffer and flag for CTRL_WR premature case */
  83978. + uint8_t *backup_buf;
  83979. + unsigned data_terminated;
  83980. +
  83981. + /** 2-byte dma buffer used to return status from GET_STATUS */
  83982. + uint16_t *status_buf;
  83983. + dwc_dma_t status_buf_dma_handle;
  83984. +
  83985. + /** EP0 */
  83986. + dwc_otg_pcd_ep_t ep0;
  83987. +
  83988. + /** Array of IN EPs. */
  83989. + dwc_otg_pcd_ep_t in_ep[MAX_EPS_CHANNELS - 1];
  83990. + /** Array of OUT EPs. */
  83991. + dwc_otg_pcd_ep_t out_ep[MAX_EPS_CHANNELS - 1];
  83992. + /** number of valid EPs in the above array. */
  83993. +// unsigned num_eps : 4;
  83994. + dwc_spinlock_t *lock;
  83995. +
  83996. + /** Tasklet to defer starting of TEST mode transmissions until
  83997. + * Status Phase has been completed.
  83998. + */
  83999. + dwc_tasklet_t *test_mode_tasklet;
  84000. +
  84001. + /** Tasklet to delay starting of xfer in DMA mode */
  84002. + dwc_tasklet_t *start_xfer_tasklet;
  84003. +
  84004. + /** The test mode to enter when the tasklet is executed. */
  84005. + unsigned test_mode;
  84006. + /** The cfi_api structure that implements most of the CFI API
  84007. + * and OTG specific core configuration functionality
  84008. + */
  84009. +#ifdef DWC_UTE_CFI
  84010. + struct cfiobject *cfi;
  84011. +#endif
  84012. +
  84013. +};
  84014. +
  84015. +//FIXME this functions should be static, and this prototypes should be removed
  84016. +extern void dwc_otg_request_nuke(dwc_otg_pcd_ep_t * ep);
  84017. +extern void dwc_otg_request_done(dwc_otg_pcd_ep_t * ep,
  84018. + dwc_otg_pcd_request_t * req, int32_t status);
  84019. +
  84020. +void dwc_otg_iso_buffer_done(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * ep,
  84021. + void *req_handle);
  84022. +
  84023. +extern void do_test_mode(void *data);
  84024. +#endif
  84025. +#endif /* DWC_HOST_ONLY */
  84026. diff -Nur linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_pcd_if.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd_if.h
  84027. --- linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_pcd_if.h 1970-01-01 01:00:00.000000000 +0100
  84028. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd_if.h 2014-04-24 15:35:04.177565820 +0200
  84029. @@ -0,0 +1,360 @@
  84030. +/* ==========================================================================
  84031. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd_if.h $
  84032. + * $Revision: #11 $
  84033. + * $Date: 2011/10/26 $
  84034. + * $Change: 1873028 $
  84035. + *
  84036. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  84037. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  84038. + * otherwise expressly agreed to in writing between Synopsys and you.
  84039. + *
  84040. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  84041. + * any End User Software License Agreement or Agreement for Licensed Product
  84042. + * with Synopsys or any supplement thereto. You are permitted to use and
  84043. + * redistribute this Software in source and binary forms, with or without
  84044. + * modification, provided that redistributions of source code must retain this
  84045. + * notice. You may not view, use, disclose, copy or distribute this file or
  84046. + * any information contained herein except pursuant to this license grant from
  84047. + * Synopsys. If you do not agree with this notice, including the disclaimer
  84048. + * below, then you are not authorized to use the Software.
  84049. + *
  84050. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  84051. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  84052. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  84053. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  84054. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  84055. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  84056. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  84057. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  84058. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  84059. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  84060. + * DAMAGE.
  84061. + * ========================================================================== */
  84062. +#ifndef DWC_HOST_ONLY
  84063. +
  84064. +#if !defined(__DWC_PCD_IF_H__)
  84065. +#define __DWC_PCD_IF_H__
  84066. +
  84067. +//#include "dwc_os.h"
  84068. +#include "dwc_otg_core_if.h"
  84069. +
  84070. +/** @file
  84071. + * This file defines DWC_OTG PCD Core API.
  84072. + */
  84073. +
  84074. +struct dwc_otg_pcd;
  84075. +typedef struct dwc_otg_pcd dwc_otg_pcd_t;
  84076. +
  84077. +/** Maxpacket size for EP0 */
  84078. +#define MAX_EP0_SIZE 64
  84079. +/** Maxpacket size for any EP */
  84080. +#define MAX_PACKET_SIZE 1024
  84081. +
  84082. +/** @name Function Driver Callbacks */
  84083. +/** @{ */
  84084. +
  84085. +/** This function will be called whenever a previously queued request has
  84086. + * completed. The status value will be set to -DWC_E_SHUTDOWN to indicated a
  84087. + * failed or aborted transfer, or -DWC_E_RESTART to indicate the device was reset,
  84088. + * or -DWC_E_TIMEOUT to indicate it timed out, or -DWC_E_INVALID to indicate invalid
  84089. + * parameters. */
  84090. +typedef int (*dwc_completion_cb_t) (dwc_otg_pcd_t * pcd, void *ep_handle,
  84091. + void *req_handle, int32_t status,
  84092. + uint32_t actual);
  84093. +/**
  84094. + * This function will be called whenever a previousle queued ISOC request has
  84095. + * completed. Count of ISOC packets could be read using dwc_otg_pcd_get_iso_packet_count
  84096. + * function.
  84097. + * The status of each ISOC packet could be read using dwc_otg_pcd_get_iso_packet_*
  84098. + * functions.
  84099. + */
  84100. +typedef int (*dwc_isoc_completion_cb_t) (dwc_otg_pcd_t * pcd, void *ep_handle,
  84101. + void *req_handle, int proc_buf_num);
  84102. +/** This function should handle any SETUP request that cannot be handled by the
  84103. + * PCD Core. This includes most GET_DESCRIPTORs, SET_CONFIGS, Any
  84104. + * class-specific requests, etc. The function must non-blocking.
  84105. + *
  84106. + * Returns 0 on success.
  84107. + * Returns -DWC_E_NOT_SUPPORTED if the request is not supported.
  84108. + * Returns -DWC_E_INVALID if the setup request had invalid parameters or bytes.
  84109. + * Returns -DWC_E_SHUTDOWN on any other error. */
  84110. +typedef int (*dwc_setup_cb_t) (dwc_otg_pcd_t * pcd, uint8_t * bytes);
  84111. +/** This is called whenever the device has been disconnected. The function
  84112. + * driver should take appropriate action to clean up all pending requests in the
  84113. + * PCD Core, remove all endpoints (except ep0), and initialize back to reset
  84114. + * state. */
  84115. +typedef int (*dwc_disconnect_cb_t) (dwc_otg_pcd_t * pcd);
  84116. +/** This function is called when device has been connected. */
  84117. +typedef int (*dwc_connect_cb_t) (dwc_otg_pcd_t * pcd, int speed);
  84118. +/** This function is called when device has been suspended */
  84119. +typedef int (*dwc_suspend_cb_t) (dwc_otg_pcd_t * pcd);
  84120. +/** This function is called when device has received LPM tokens, i.e.
  84121. + * device has been sent to sleep state. */
  84122. +typedef int (*dwc_sleep_cb_t) (dwc_otg_pcd_t * pcd);
  84123. +/** This function is called when device has been resumed
  84124. + * from suspend(L2) or L1 sleep state. */
  84125. +typedef int (*dwc_resume_cb_t) (dwc_otg_pcd_t * pcd);
  84126. +/** This function is called whenever hnp params has been changed.
  84127. + * User can call get_b_hnp_enable, get_a_hnp_support, get_a_alt_hnp_support functions
  84128. + * to get hnp parameters. */
  84129. +typedef int (*dwc_hnp_params_changed_cb_t) (dwc_otg_pcd_t * pcd);
  84130. +/** This function is called whenever USB RESET is detected. */
  84131. +typedef int (*dwc_reset_cb_t) (dwc_otg_pcd_t * pcd);
  84132. +
  84133. +typedef int (*cfi_setup_cb_t) (dwc_otg_pcd_t * pcd, void *ctrl_req_bytes);
  84134. +
  84135. +/**
  84136. + *
  84137. + * @param ep_handle Void pointer to the usb_ep structure
  84138. + * @param ereq_port Pointer to the extended request structure created in the
  84139. + * portable part.
  84140. + */
  84141. +typedef int (*xiso_completion_cb_t) (dwc_otg_pcd_t * pcd, void *ep_handle,
  84142. + void *req_handle, int32_t status,
  84143. + void *ereq_port);
  84144. +/** Function Driver Ops Data Structure */
  84145. +struct dwc_otg_pcd_function_ops {
  84146. + dwc_connect_cb_t connect;
  84147. + dwc_disconnect_cb_t disconnect;
  84148. + dwc_setup_cb_t setup;
  84149. + dwc_completion_cb_t complete;
  84150. + dwc_isoc_completion_cb_t isoc_complete;
  84151. + dwc_suspend_cb_t suspend;
  84152. + dwc_sleep_cb_t sleep;
  84153. + dwc_resume_cb_t resume;
  84154. + dwc_reset_cb_t reset;
  84155. + dwc_hnp_params_changed_cb_t hnp_changed;
  84156. + cfi_setup_cb_t cfi_setup;
  84157. +#ifdef DWC_UTE_PER_IO
  84158. + xiso_completion_cb_t xisoc_complete;
  84159. +#endif
  84160. +};
  84161. +/** @} */
  84162. +
  84163. +/** @name Function Driver Functions */
  84164. +/** @{ */
  84165. +
  84166. +/** Call this function to get pointer on dwc_otg_pcd_t,
  84167. + * this pointer will be used for all PCD API functions.
  84168. + *
  84169. + * @param core_if The DWC_OTG Core
  84170. + */
  84171. +extern dwc_otg_pcd_t *dwc_otg_pcd_init(dwc_otg_core_if_t * core_if);
  84172. +
  84173. +/** Frees PCD allocated by dwc_otg_pcd_init
  84174. + *
  84175. + * @param pcd The PCD
  84176. + */
  84177. +extern void dwc_otg_pcd_remove(dwc_otg_pcd_t * pcd);
  84178. +
  84179. +/** Call this to bind the function driver to the PCD Core.
  84180. + *
  84181. + * @param pcd Pointer on dwc_otg_pcd_t returned by dwc_otg_pcd_init function.
  84182. + * @param fops The Function Driver Ops data structure containing pointers to all callbacks.
  84183. + */
  84184. +extern void dwc_otg_pcd_start(dwc_otg_pcd_t * pcd,
  84185. + const struct dwc_otg_pcd_function_ops *fops);
  84186. +
  84187. +/** Enables an endpoint for use. This function enables an endpoint in
  84188. + * the PCD. The endpoint is described by the ep_desc which has the
  84189. + * same format as a USB ep descriptor. The ep_handle parameter is used to refer
  84190. + * to the endpoint from other API functions and in callbacks. Normally this
  84191. + * should be called after a SET_CONFIGURATION/SET_INTERFACE to configure the
  84192. + * core for that interface.
  84193. + *
  84194. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  84195. + * Returns -DWC_E_SHUTDOWN if any other error ocurred.
  84196. + * Returns 0 on success.
  84197. + *
  84198. + * @param pcd The PCD
  84199. + * @param ep_desc Endpoint descriptor
  84200. + * @param usb_ep Handle on endpoint, that will be used to identify endpoint.
  84201. + */
  84202. +extern int dwc_otg_pcd_ep_enable(dwc_otg_pcd_t * pcd,
  84203. + const uint8_t * ep_desc, void *usb_ep);
  84204. +
  84205. +/** Disable the endpoint referenced by ep_handle.
  84206. + *
  84207. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  84208. + * Returns -DWC_E_SHUTDOWN if any other error occurred.
  84209. + * Returns 0 on success. */
  84210. +extern int dwc_otg_pcd_ep_disable(dwc_otg_pcd_t * pcd, void *ep_handle);
  84211. +
  84212. +/** Queue a data transfer request on the endpoint referenced by ep_handle.
  84213. + * After the transfer is completes, the complete callback will be called with
  84214. + * the request status.
  84215. + *
  84216. + * @param pcd The PCD
  84217. + * @param ep_handle The handle of the endpoint
  84218. + * @param buf The buffer for the data
  84219. + * @param dma_buf The DMA buffer for the data
  84220. + * @param buflen The length of the data transfer
  84221. + * @param zero Specifies whether to send zero length last packet.
  84222. + * @param req_handle Set this handle to any value to use to reference this
  84223. + * request in the ep_dequeue function or from the complete callback
  84224. + * @param atomic_alloc If driver need to perform atomic allocations
  84225. + * for internal data structures.
  84226. + *
  84227. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  84228. + * Returns -DWC_E_SHUTDOWN if any other error ocurred.
  84229. + * Returns 0 on success. */
  84230. +extern int dwc_otg_pcd_ep_queue(dwc_otg_pcd_t * pcd, void *ep_handle,
  84231. + uint8_t * buf, dwc_dma_t dma_buf,
  84232. + uint32_t buflen, int zero, void *req_handle,
  84233. + int atomic_alloc);
  84234. +#ifdef DWC_UTE_PER_IO
  84235. +/**
  84236. + *
  84237. + * @param ereq_nonport Pointer to the extended request part of the
  84238. + * usb_request structure defined in usb_gadget.h file.
  84239. + */
  84240. +extern int dwc_otg_pcd_xiso_ep_queue(dwc_otg_pcd_t * pcd, void *ep_handle,
  84241. + uint8_t * buf, dwc_dma_t dma_buf,
  84242. + uint32_t buflen, int zero,
  84243. + void *req_handle, int atomic_alloc,
  84244. + void *ereq_nonport);
  84245. +
  84246. +#endif
  84247. +
  84248. +/** De-queue the specified data transfer that has not yet completed.
  84249. + *
  84250. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  84251. + * Returns -DWC_E_SHUTDOWN if any other error ocurred.
  84252. + * Returns 0 on success. */
  84253. +extern int dwc_otg_pcd_ep_dequeue(dwc_otg_pcd_t * pcd, void *ep_handle,
  84254. + void *req_handle);
  84255. +
  84256. +/** Halt (STALL) an endpoint or clear it.
  84257. + *
  84258. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  84259. + * Returns -DWC_E_SHUTDOWN if any other error ocurred.
  84260. + * Returns -DWC_E_AGAIN if the STALL cannot be sent and must be tried again later
  84261. + * Returns 0 on success. */
  84262. +extern int dwc_otg_pcd_ep_halt(dwc_otg_pcd_t * pcd, void *ep_handle, int value);
  84263. +
  84264. +/** This function */
  84265. +extern int dwc_otg_pcd_ep_wedge(dwc_otg_pcd_t * pcd, void *ep_handle);
  84266. +
  84267. +/** This function should be called on every hardware interrupt */
  84268. +extern int32_t dwc_otg_pcd_handle_intr(dwc_otg_pcd_t * pcd);
  84269. +
  84270. +/** This function returns current frame number */
  84271. +extern int dwc_otg_pcd_get_frame_number(dwc_otg_pcd_t * pcd);
  84272. +
  84273. +/**
  84274. + * Start isochronous transfers on the endpoint referenced by ep_handle.
  84275. + * For isochronous transfers duble buffering is used.
  84276. + * After processing each of buffers comlete callback will be called with
  84277. + * status for each transaction.
  84278. + *
  84279. + * @param pcd The PCD
  84280. + * @param ep_handle The handle of the endpoint
  84281. + * @param buf0 The virtual address of first data buffer
  84282. + * @param buf1 The virtual address of second data buffer
  84283. + * @param dma0 The DMA address of first data buffer
  84284. + * @param dma1 The DMA address of second data buffer
  84285. + * @param sync_frame Data pattern frame number
  84286. + * @param dp_frame Data size for pattern frame
  84287. + * @param data_per_frame Data size for regular frame
  84288. + * @param start_frame Frame number to start transfers, if -1 then start transfers ASAP.
  84289. + * @param buf_proc_intrvl Interval of ISOC Buffer processing
  84290. + * @param req_handle Handle of ISOC request
  84291. + * @param atomic_alloc Specefies whether to perform atomic allocation for
  84292. + * internal data structures.
  84293. + *
  84294. + * Returns -DWC_E_NO_MEMORY if there is no enough memory.
  84295. + * Returns -DWC_E_INVALID if incorrect arguments are passed to the function.
  84296. + * Returns -DW_E_SHUTDOWN for any other error.
  84297. + * Returns 0 on success
  84298. + */
  84299. +extern int dwc_otg_pcd_iso_ep_start(dwc_otg_pcd_t * pcd, void *ep_handle,
  84300. + uint8_t * buf0, uint8_t * buf1,
  84301. + dwc_dma_t dma0, dwc_dma_t dma1,
  84302. + int sync_frame, int dp_frame,
  84303. + int data_per_frame, int start_frame,
  84304. + int buf_proc_intrvl, void *req_handle,
  84305. + int atomic_alloc);
  84306. +
  84307. +/** Stop ISOC transfers on endpoint referenced by ep_handle.
  84308. + *
  84309. + * @param pcd The PCD
  84310. + * @param ep_handle The handle of the endpoint
  84311. + * @param req_handle Handle of ISOC request
  84312. + *
  84313. + * Returns -DWC_E_INVALID if incorrect arguments are passed to the function
  84314. + * Returns 0 on success
  84315. + */
  84316. +int dwc_otg_pcd_iso_ep_stop(dwc_otg_pcd_t * pcd, void *ep_handle,
  84317. + void *req_handle);
  84318. +
  84319. +/** Get ISOC packet status.
  84320. + *
  84321. + * @param pcd The PCD
  84322. + * @param ep_handle The handle of the endpoint
  84323. + * @param iso_req_handle Isochronoush request handle
  84324. + * @param packet Number of packet
  84325. + * @param status Out parameter for returning status
  84326. + * @param actual Out parameter for returning actual length
  84327. + * @param offset Out parameter for returning offset
  84328. + *
  84329. + */
  84330. +extern void dwc_otg_pcd_get_iso_packet_params(dwc_otg_pcd_t * pcd,
  84331. + void *ep_handle,
  84332. + void *iso_req_handle, int packet,
  84333. + int *status, int *actual,
  84334. + int *offset);
  84335. +
  84336. +/** Get ISOC packet count.
  84337. + *
  84338. + * @param pcd The PCD
  84339. + * @param ep_handle The handle of the endpoint
  84340. + * @param iso_req_handle
  84341. + */
  84342. +extern int dwc_otg_pcd_get_iso_packet_count(dwc_otg_pcd_t * pcd,
  84343. + void *ep_handle,
  84344. + void *iso_req_handle);
  84345. +
  84346. +/** This function starts the SRP Protocol if no session is in progress. If
  84347. + * a session is already in progress, but the device is suspended,
  84348. + * remote wakeup signaling is started.
  84349. + */
  84350. +extern int dwc_otg_pcd_wakeup(dwc_otg_pcd_t * pcd);
  84351. +
  84352. +/** This function returns 1 if LPM support is enabled, and 0 otherwise. */
  84353. +extern int dwc_otg_pcd_is_lpm_enabled(dwc_otg_pcd_t * pcd);
  84354. +
  84355. +/** This function returns 1 if remote wakeup is allowed and 0, otherwise. */
  84356. +extern int dwc_otg_pcd_get_rmwkup_enable(dwc_otg_pcd_t * pcd);
  84357. +
  84358. +/** Initiate SRP */
  84359. +extern void dwc_otg_pcd_initiate_srp(dwc_otg_pcd_t * pcd);
  84360. +
  84361. +/** Starts remote wakeup signaling. */
  84362. +extern void dwc_otg_pcd_remote_wakeup(dwc_otg_pcd_t * pcd, int set);
  84363. +
  84364. +/** Starts micorsecond soft disconnect. */
  84365. +extern void dwc_otg_pcd_disconnect_us(dwc_otg_pcd_t * pcd, int no_of_usecs);
  84366. +/** This function returns whether device is dualspeed.*/
  84367. +extern uint32_t dwc_otg_pcd_is_dualspeed(dwc_otg_pcd_t * pcd);
  84368. +
  84369. +/** This function returns whether device is otg. */
  84370. +extern uint32_t dwc_otg_pcd_is_otg(dwc_otg_pcd_t * pcd);
  84371. +
  84372. +/** These functions allow to get hnp parameters */
  84373. +extern uint32_t get_b_hnp_enable(dwc_otg_pcd_t * pcd);
  84374. +extern uint32_t get_a_hnp_support(dwc_otg_pcd_t * pcd);
  84375. +extern uint32_t get_a_alt_hnp_support(dwc_otg_pcd_t * pcd);
  84376. +
  84377. +/** CFI specific Interface functions */
  84378. +/** Allocate a cfi buffer */
  84379. +extern uint8_t *cfiw_ep_alloc_buffer(dwc_otg_pcd_t * pcd, void *pep,
  84380. + dwc_dma_t * addr, size_t buflen,
  84381. + int flags);
  84382. +
  84383. +/******************************************************************************/
  84384. +
  84385. +/** @} */
  84386. +
  84387. +#endif /* __DWC_PCD_IF_H__ */
  84388. +
  84389. +#endif /* DWC_HOST_ONLY */
  84390. diff -Nur linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_pcd_intr.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd_intr.c
  84391. --- linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_pcd_intr.c 1970-01-01 01:00:00.000000000 +0100
  84392. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd_intr.c 2014-04-24 15:37:13.314990533 +0200
  84393. @@ -0,0 +1,5147 @@
  84394. +/* ==========================================================================
  84395. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd_intr.c $
  84396. + * $Revision: #116 $
  84397. + * $Date: 2012/08/10 $
  84398. + * $Change: 2047372 $
  84399. + *
  84400. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  84401. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  84402. + * otherwise expressly agreed to in writing between Synopsys and you.
  84403. + *
  84404. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  84405. + * any End User Software License Agreement or Agreement for Licensed Product
  84406. + * with Synopsys or any supplement thereto. You are permitted to use and
  84407. + * redistribute this Software in source and binary forms, with or without
  84408. + * modification, provided that redistributions of source code must retain this
  84409. + * notice. You may not view, use, disclose, copy or distribute this file or
  84410. + * any information contained herein except pursuant to this license grant from
  84411. + * Synopsys. If you do not agree with this notice, including the disclaimer
  84412. + * below, then you are not authorized to use the Software.
  84413. + *
  84414. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  84415. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  84416. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  84417. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  84418. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  84419. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  84420. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  84421. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  84422. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  84423. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  84424. + * DAMAGE.
  84425. + * ========================================================================== */
  84426. +#ifndef DWC_HOST_ONLY
  84427. +
  84428. +#include "dwc_otg_pcd.h"
  84429. +
  84430. +#ifdef DWC_UTE_CFI
  84431. +#include "dwc_otg_cfi.h"
  84432. +#endif
  84433. +
  84434. +#ifdef DWC_UTE_PER_IO
  84435. +extern void complete_xiso_ep(dwc_otg_pcd_ep_t * ep);
  84436. +#endif
  84437. +//#define PRINT_CFI_DMA_DESCS
  84438. +
  84439. +#define DEBUG_EP0
  84440. +
  84441. +/**
  84442. + * This function updates OTG.
  84443. + */
  84444. +static void dwc_otg_pcd_update_otg(dwc_otg_pcd_t * pcd, const unsigned reset)
  84445. +{
  84446. +
  84447. + if (reset) {
  84448. + pcd->b_hnp_enable = 0;
  84449. + pcd->a_hnp_support = 0;
  84450. + pcd->a_alt_hnp_support = 0;
  84451. + }
  84452. +
  84453. + if (pcd->fops->hnp_changed) {
  84454. + pcd->fops->hnp_changed(pcd);
  84455. + }
  84456. +}
  84457. +
  84458. +/** @file
  84459. + * This file contains the implementation of the PCD Interrupt handlers.
  84460. + *
  84461. + * The PCD handles the device interrupts. Many conditions can cause a
  84462. + * device interrupt. When an interrupt occurs, the device interrupt
  84463. + * service routine determines the cause of the interrupt and
  84464. + * dispatches handling to the appropriate function. These interrupt
  84465. + * handling functions are described below.
  84466. + * All interrupt registers are processed from LSB to MSB.
  84467. + */
  84468. +
  84469. +/**
  84470. + * This function prints the ep0 state for debug purposes.
  84471. + */
  84472. +static inline void print_ep0_state(dwc_otg_pcd_t * pcd)
  84473. +{
  84474. +#ifdef DEBUG
  84475. + char str[40];
  84476. +
  84477. + switch (pcd->ep0state) {
  84478. + case EP0_DISCONNECT:
  84479. + dwc_strcpy(str, "EP0_DISCONNECT");
  84480. + break;
  84481. + case EP0_IDLE:
  84482. + dwc_strcpy(str, "EP0_IDLE");
  84483. + break;
  84484. + case EP0_IN_DATA_PHASE:
  84485. + dwc_strcpy(str, "EP0_IN_DATA_PHASE");
  84486. + break;
  84487. + case EP0_OUT_DATA_PHASE:
  84488. + dwc_strcpy(str, "EP0_OUT_DATA_PHASE");
  84489. + break;
  84490. + case EP0_IN_STATUS_PHASE:
  84491. + dwc_strcpy(str, "EP0_IN_STATUS_PHASE");
  84492. + break;
  84493. + case EP0_OUT_STATUS_PHASE:
  84494. + dwc_strcpy(str, "EP0_OUT_STATUS_PHASE");
  84495. + break;
  84496. + case EP0_STALL:
  84497. + dwc_strcpy(str, "EP0_STALL");
  84498. + break;
  84499. + default:
  84500. + dwc_strcpy(str, "EP0_INVALID");
  84501. + }
  84502. +
  84503. + DWC_DEBUGPL(DBG_ANY, "%s(%d)\n", str, pcd->ep0state);
  84504. +#endif
  84505. +}
  84506. +
  84507. +/**
  84508. + * This function calculate the size of the payload in the memory
  84509. + * for out endpoints and prints size for debug purposes(used in
  84510. + * 2.93a DevOutNak feature).
  84511. + */
  84512. +static inline void print_memory_payload(dwc_otg_pcd_t * pcd, dwc_ep_t * ep)
  84513. +{
  84514. +#ifdef DEBUG
  84515. + deptsiz_data_t deptsiz_init = {.d32 = 0 };
  84516. + deptsiz_data_t deptsiz_updt = {.d32 = 0 };
  84517. + int pack_num;
  84518. + unsigned payload;
  84519. +
  84520. + deptsiz_init.d32 = pcd->core_if->start_doeptsiz_val[ep->num];
  84521. + deptsiz_updt.d32 =
  84522. + DWC_READ_REG32(&pcd->core_if->dev_if->
  84523. + out_ep_regs[ep->num]->doeptsiz);
  84524. + /* Payload will be */
  84525. + payload = deptsiz_init.b.xfersize - deptsiz_updt.b.xfersize;
  84526. + /* Packet count is decremented every time a packet
  84527. + * is written to the RxFIFO not in to the external memory
  84528. + * So, if payload == 0, then it means no packet was sent to ext memory*/
  84529. + pack_num = (!payload) ? 0 : (deptsiz_init.b.pktcnt - deptsiz_updt.b.pktcnt);
  84530. + DWC_DEBUGPL(DBG_PCDV,
  84531. + "Payload for EP%d-%s\n",
  84532. + ep->num, (ep->is_in ? "IN" : "OUT"));
  84533. + DWC_DEBUGPL(DBG_PCDV,
  84534. + "Number of transfered bytes = 0x%08x\n", payload);
  84535. + DWC_DEBUGPL(DBG_PCDV,
  84536. + "Number of transfered packets = %d\n", pack_num);
  84537. +#endif
  84538. +}
  84539. +
  84540. +
  84541. +#ifdef DWC_UTE_CFI
  84542. +static inline void print_desc(struct dwc_otg_dma_desc *ddesc,
  84543. + const uint8_t * epname, int descnum)
  84544. +{
  84545. + CFI_INFO
  84546. + ("%s DMA_DESC(%d) buf=0x%08x bytes=0x%04x; sp=0x%x; l=0x%x; sts=0x%02x; bs=0x%02x\n",
  84547. + epname, descnum, ddesc->buf, ddesc->status.b.bytes,
  84548. + ddesc->status.b.sp, ddesc->status.b.l, ddesc->status.b.sts,
  84549. + ddesc->status.b.bs);
  84550. +}
  84551. +#endif
  84552. +
  84553. +/**
  84554. + * This function returns pointer to in ep struct with number ep_num
  84555. + */
  84556. +static inline dwc_otg_pcd_ep_t *get_in_ep(dwc_otg_pcd_t * pcd, uint32_t ep_num)
  84557. +{
  84558. + int i;
  84559. + int num_in_eps = GET_CORE_IF(pcd)->dev_if->num_in_eps;
  84560. + if (ep_num == 0) {
  84561. + return &pcd->ep0;
  84562. + } else {
  84563. + for (i = 0; i < num_in_eps; ++i) {
  84564. + if (pcd->in_ep[i].dwc_ep.num == ep_num)
  84565. + return &pcd->in_ep[i];
  84566. + }
  84567. + return 0;
  84568. + }
  84569. +}
  84570. +
  84571. +/**
  84572. + * This function returns pointer to out ep struct with number ep_num
  84573. + */
  84574. +static inline dwc_otg_pcd_ep_t *get_out_ep(dwc_otg_pcd_t * pcd, uint32_t ep_num)
  84575. +{
  84576. + int i;
  84577. + int num_out_eps = GET_CORE_IF(pcd)->dev_if->num_out_eps;
  84578. + if (ep_num == 0) {
  84579. + return &pcd->ep0;
  84580. + } else {
  84581. + for (i = 0; i < num_out_eps; ++i) {
  84582. + if (pcd->out_ep[i].dwc_ep.num == ep_num)
  84583. + return &pcd->out_ep[i];
  84584. + }
  84585. + return 0;
  84586. + }
  84587. +}
  84588. +
  84589. +/**
  84590. + * This functions gets a pointer to an EP from the wIndex address
  84591. + * value of the control request.
  84592. + */
  84593. +dwc_otg_pcd_ep_t *get_ep_by_addr(dwc_otg_pcd_t * pcd, u16 wIndex)
  84594. +{
  84595. + dwc_otg_pcd_ep_t *ep;
  84596. + uint32_t ep_num = UE_GET_ADDR(wIndex);
  84597. +
  84598. + if (ep_num == 0) {
  84599. + ep = &pcd->ep0;
  84600. + } else if (UE_GET_DIR(wIndex) == UE_DIR_IN) { /* in ep */
  84601. + ep = &pcd->in_ep[ep_num - 1];
  84602. + } else {
  84603. + ep = &pcd->out_ep[ep_num - 1];
  84604. + }
  84605. +
  84606. + return ep;
  84607. +}
  84608. +
  84609. +/**
  84610. + * This function checks the EP request queue, if the queue is not
  84611. + * empty the next request is started.
  84612. + */
  84613. +void start_next_request(dwc_otg_pcd_ep_t * ep)
  84614. +{
  84615. + dwc_otg_pcd_request_t *req = 0;
  84616. + uint32_t max_transfer =
  84617. + GET_CORE_IF(ep->pcd)->core_params->max_transfer_size;
  84618. +
  84619. +#ifdef DWC_UTE_CFI
  84620. + struct dwc_otg_pcd *pcd;
  84621. + pcd = ep->pcd;
  84622. +#endif
  84623. +
  84624. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  84625. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  84626. +
  84627. +#ifdef DWC_UTE_CFI
  84628. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  84629. + ep->dwc_ep.cfi_req_len = req->length;
  84630. + pcd->cfi->ops.build_descriptors(pcd->cfi, pcd, ep, req);
  84631. + } else {
  84632. +#endif
  84633. + /* Setup and start the Transfer */
  84634. + if (req->dw_align_buf) {
  84635. + ep->dwc_ep.dma_addr = req->dw_align_buf_dma;
  84636. + ep->dwc_ep.start_xfer_buff = req->dw_align_buf;
  84637. + ep->dwc_ep.xfer_buff = req->dw_align_buf;
  84638. + } else {
  84639. + ep->dwc_ep.dma_addr = req->dma;
  84640. + ep->dwc_ep.start_xfer_buff = req->buf;
  84641. + ep->dwc_ep.xfer_buff = req->buf;
  84642. + }
  84643. + ep->dwc_ep.sent_zlp = 0;
  84644. + ep->dwc_ep.total_len = req->length;
  84645. + ep->dwc_ep.xfer_len = 0;
  84646. + ep->dwc_ep.xfer_count = 0;
  84647. +
  84648. + ep->dwc_ep.maxxfer = max_transfer;
  84649. + if (GET_CORE_IF(ep->pcd)->dma_desc_enable) {
  84650. + uint32_t out_max_xfer = DDMA_MAX_TRANSFER_SIZE
  84651. + - (DDMA_MAX_TRANSFER_SIZE % 4);
  84652. + if (ep->dwc_ep.is_in) {
  84653. + if (ep->dwc_ep.maxxfer >
  84654. + DDMA_MAX_TRANSFER_SIZE) {
  84655. + ep->dwc_ep.maxxfer =
  84656. + DDMA_MAX_TRANSFER_SIZE;
  84657. + }
  84658. + } else {
  84659. + if (ep->dwc_ep.maxxfer > out_max_xfer) {
  84660. + ep->dwc_ep.maxxfer =
  84661. + out_max_xfer;
  84662. + }
  84663. + }
  84664. + }
  84665. + if (ep->dwc_ep.maxxfer < ep->dwc_ep.total_len) {
  84666. + ep->dwc_ep.maxxfer -=
  84667. + (ep->dwc_ep.maxxfer % ep->dwc_ep.maxpacket);
  84668. + }
  84669. + if (req->sent_zlp) {
  84670. + if ((ep->dwc_ep.total_len %
  84671. + ep->dwc_ep.maxpacket == 0)
  84672. + && (ep->dwc_ep.total_len != 0)) {
  84673. + ep->dwc_ep.sent_zlp = 1;
  84674. + }
  84675. +
  84676. + }
  84677. +#ifdef DWC_UTE_CFI
  84678. + }
  84679. +#endif
  84680. + dwc_otg_ep_start_transfer(GET_CORE_IF(ep->pcd), &ep->dwc_ep);
  84681. + } else if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  84682. + DWC_PRINTF("There are no more ISOC requests \n");
  84683. + ep->dwc_ep.frame_num = 0xFFFFFFFF;
  84684. + }
  84685. +}
  84686. +
  84687. +/**
  84688. + * This function handles the SOF Interrupts. At this time the SOF
  84689. + * Interrupt is disabled.
  84690. + */
  84691. +int32_t dwc_otg_pcd_handle_sof_intr(dwc_otg_pcd_t * pcd)
  84692. +{
  84693. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  84694. +
  84695. + gintsts_data_t gintsts;
  84696. +
  84697. + DWC_DEBUGPL(DBG_PCD, "SOF\n");
  84698. +
  84699. + /* Clear interrupt */
  84700. + gintsts.d32 = 0;
  84701. + gintsts.b.sofintr = 1;
  84702. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  84703. +
  84704. + return 1;
  84705. +}
  84706. +
  84707. +/**
  84708. + * This function handles the Rx Status Queue Level Interrupt, which
  84709. + * indicates that there is a least one packet in the Rx FIFO. The
  84710. + * packets are moved from the FIFO to memory, where they will be
  84711. + * processed when the Endpoint Interrupt Register indicates Transfer
  84712. + * Complete or SETUP Phase Done.
  84713. + *
  84714. + * Repeat the following until the Rx Status Queue is empty:
  84715. + * -# Read the Receive Status Pop Register (GRXSTSP) to get Packet
  84716. + * info
  84717. + * -# If Receive FIFO is empty then skip to step Clear the interrupt
  84718. + * and exit
  84719. + * -# If SETUP Packet call dwc_otg_read_setup_packet to copy the
  84720. + * SETUP data to the buffer
  84721. + * -# If OUT Data Packet call dwc_otg_read_packet to copy the data
  84722. + * to the destination buffer
  84723. + */
  84724. +int32_t dwc_otg_pcd_handle_rx_status_q_level_intr(dwc_otg_pcd_t * pcd)
  84725. +{
  84726. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  84727. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  84728. + gintmsk_data_t gintmask = {.d32 = 0 };
  84729. + device_grxsts_data_t status;
  84730. + dwc_otg_pcd_ep_t *ep;
  84731. + gintsts_data_t gintsts;
  84732. +#ifdef DEBUG
  84733. + static char *dpid_str[] = { "D0", "D2", "D1", "MDATA" };
  84734. +#endif
  84735. +
  84736. + //DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, _pcd);
  84737. + /* Disable the Rx Status Queue Level interrupt */
  84738. + gintmask.b.rxstsqlvl = 1;
  84739. + DWC_MODIFY_REG32(&global_regs->gintmsk, gintmask.d32, 0);
  84740. +
  84741. + /* Get the Status from the top of the FIFO */
  84742. + status.d32 = DWC_READ_REG32(&global_regs->grxstsp);
  84743. +
  84744. + DWC_DEBUGPL(DBG_PCD, "EP:%d BCnt:%d DPID:%s "
  84745. + "pktsts:%x Frame:%d(0x%0x)\n",
  84746. + status.b.epnum, status.b.bcnt,
  84747. + dpid_str[status.b.dpid],
  84748. + status.b.pktsts, status.b.fn, status.b.fn);
  84749. + /* Get pointer to EP structure */
  84750. + ep = get_out_ep(pcd, status.b.epnum);
  84751. +
  84752. + switch (status.b.pktsts) {
  84753. + case DWC_DSTS_GOUT_NAK:
  84754. + DWC_DEBUGPL(DBG_PCDV, "Global OUT NAK\n");
  84755. + break;
  84756. + case DWC_STS_DATA_UPDT:
  84757. + DWC_DEBUGPL(DBG_PCDV, "OUT Data Packet\n");
  84758. + if (status.b.bcnt && ep->dwc_ep.xfer_buff) {
  84759. + /** @todo NGS Check for buffer overflow? */
  84760. + dwc_otg_read_packet(core_if,
  84761. + ep->dwc_ep.xfer_buff,
  84762. + status.b.bcnt);
  84763. + ep->dwc_ep.xfer_count += status.b.bcnt;
  84764. + ep->dwc_ep.xfer_buff += status.b.bcnt;
  84765. + }
  84766. + break;
  84767. + case DWC_STS_XFER_COMP:
  84768. + DWC_DEBUGPL(DBG_PCDV, "OUT Complete\n");
  84769. + break;
  84770. + case DWC_DSTS_SETUP_COMP:
  84771. +#ifdef DEBUG_EP0
  84772. + DWC_DEBUGPL(DBG_PCDV, "Setup Complete\n");
  84773. +#endif
  84774. + break;
  84775. + case DWC_DSTS_SETUP_UPDT:
  84776. + dwc_otg_read_setup_packet(core_if, pcd->setup_pkt->d32);
  84777. +#ifdef DEBUG_EP0
  84778. + DWC_DEBUGPL(DBG_PCD,
  84779. + "SETUP PKT: %02x.%02x v%04x i%04x l%04x\n",
  84780. + pcd->setup_pkt->req.bmRequestType,
  84781. + pcd->setup_pkt->req.bRequest,
  84782. + UGETW(pcd->setup_pkt->req.wValue),
  84783. + UGETW(pcd->setup_pkt->req.wIndex),
  84784. + UGETW(pcd->setup_pkt->req.wLength));
  84785. +#endif
  84786. + ep->dwc_ep.xfer_count += status.b.bcnt;
  84787. + break;
  84788. + default:
  84789. + DWC_DEBUGPL(DBG_PCDV, "Invalid Packet Status (0x%0x)\n",
  84790. + status.b.pktsts);
  84791. + break;
  84792. + }
  84793. +
  84794. + /* Enable the Rx Status Queue Level interrupt */
  84795. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0, gintmask.d32);
  84796. + /* Clear interrupt */
  84797. + gintsts.d32 = 0;
  84798. + gintsts.b.rxstsqlvl = 1;
  84799. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  84800. +
  84801. + //DWC_DEBUGPL(DBG_PCDV, "EXIT: %s\n", __func__);
  84802. + return 1;
  84803. +}
  84804. +
  84805. +/**
  84806. + * This function examines the Device IN Token Learning Queue to
  84807. + * determine the EP number of the last IN token received. This
  84808. + * implementation is for the Mass Storage device where there are only
  84809. + * 2 IN EPs (Control-IN and BULK-IN).
  84810. + *
  84811. + * The EP numbers for the first six IN Tokens are in DTKNQR1 and there
  84812. + * are 8 EP Numbers in each of the other possible DTKNQ Registers.
  84813. + *
  84814. + * @param core_if Programming view of DWC_otg controller.
  84815. + *
  84816. + */
  84817. +static inline int get_ep_of_last_in_token(dwc_otg_core_if_t * core_if)
  84818. +{
  84819. + dwc_otg_device_global_regs_t *dev_global_regs =
  84820. + core_if->dev_if->dev_global_regs;
  84821. + const uint32_t TOKEN_Q_DEPTH = core_if->hwcfg2.b.dev_token_q_depth;
  84822. + /* Number of Token Queue Registers */
  84823. + const int DTKNQ_REG_CNT = (TOKEN_Q_DEPTH + 7) / 8;
  84824. + dtknq1_data_t dtknqr1;
  84825. + uint32_t in_tkn_epnums[4];
  84826. + int ndx = 0;
  84827. + int i = 0;
  84828. + volatile uint32_t *addr = &dev_global_regs->dtknqr1;
  84829. + int epnum = 0;
  84830. +
  84831. + //DWC_DEBUGPL(DBG_PCD,"dev_token_q_depth=%d\n",TOKEN_Q_DEPTH);
  84832. +
  84833. + /* Read the DTKNQ Registers */
  84834. + for (i = 0; i < DTKNQ_REG_CNT; i++) {
  84835. + in_tkn_epnums[i] = DWC_READ_REG32(addr);
  84836. + DWC_DEBUGPL(DBG_PCDV, "DTKNQR%d=0x%08x\n", i + 1,
  84837. + in_tkn_epnums[i]);
  84838. + if (addr == &dev_global_regs->dvbusdis) {
  84839. + addr = &dev_global_regs->dtknqr3_dthrctl;
  84840. + } else {
  84841. + ++addr;
  84842. + }
  84843. +
  84844. + }
  84845. +
  84846. + /* Copy the DTKNQR1 data to the bit field. */
  84847. + dtknqr1.d32 = in_tkn_epnums[0];
  84848. + /* Get the EP numbers */
  84849. + in_tkn_epnums[0] = dtknqr1.b.epnums0_5;
  84850. + ndx = dtknqr1.b.intknwptr - 1;
  84851. +
  84852. + //DWC_DEBUGPL(DBG_PCDV,"ndx=%d\n",ndx);
  84853. + if (ndx == -1) {
  84854. + /** @todo Find a simpler way to calculate the max
  84855. + * queue position.*/
  84856. + int cnt = TOKEN_Q_DEPTH;
  84857. + if (TOKEN_Q_DEPTH <= 6) {
  84858. + cnt = TOKEN_Q_DEPTH - 1;
  84859. + } else if (TOKEN_Q_DEPTH <= 14) {
  84860. + cnt = TOKEN_Q_DEPTH - 7;
  84861. + } else if (TOKEN_Q_DEPTH <= 22) {
  84862. + cnt = TOKEN_Q_DEPTH - 15;
  84863. + } else {
  84864. + cnt = TOKEN_Q_DEPTH - 23;
  84865. + }
  84866. + epnum = (in_tkn_epnums[DTKNQ_REG_CNT - 1] >> (cnt * 4)) & 0xF;
  84867. + } else {
  84868. + if (ndx <= 5) {
  84869. + epnum = (in_tkn_epnums[0] >> (ndx * 4)) & 0xF;
  84870. + } else if (ndx <= 13) {
  84871. + ndx -= 6;
  84872. + epnum = (in_tkn_epnums[1] >> (ndx * 4)) & 0xF;
  84873. + } else if (ndx <= 21) {
  84874. + ndx -= 14;
  84875. + epnum = (in_tkn_epnums[2] >> (ndx * 4)) & 0xF;
  84876. + } else if (ndx <= 29) {
  84877. + ndx -= 22;
  84878. + epnum = (in_tkn_epnums[3] >> (ndx * 4)) & 0xF;
  84879. + }
  84880. + }
  84881. + //DWC_DEBUGPL(DBG_PCD,"epnum=%d\n",epnum);
  84882. + return epnum;
  84883. +}
  84884. +
  84885. +/**
  84886. + * This interrupt occurs when the non-periodic Tx FIFO is half-empty.
  84887. + * The active request is checked for the next packet to be loaded into
  84888. + * the non-periodic Tx FIFO.
  84889. + */
  84890. +int32_t dwc_otg_pcd_handle_np_tx_fifo_empty_intr(dwc_otg_pcd_t * pcd)
  84891. +{
  84892. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  84893. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  84894. + dwc_otg_dev_in_ep_regs_t *ep_regs;
  84895. + gnptxsts_data_t txstatus = {.d32 = 0 };
  84896. + gintsts_data_t gintsts;
  84897. +
  84898. + int epnum = 0;
  84899. + dwc_otg_pcd_ep_t *ep = 0;
  84900. + uint32_t len = 0;
  84901. + int dwords;
  84902. +
  84903. + /* Get the epnum from the IN Token Learning Queue. */
  84904. + epnum = get_ep_of_last_in_token(core_if);
  84905. + ep = get_in_ep(pcd, epnum);
  84906. +
  84907. + DWC_DEBUGPL(DBG_PCD, "NP TxFifo Empty: %d \n", epnum);
  84908. +
  84909. + ep_regs = core_if->dev_if->in_ep_regs[epnum];
  84910. +
  84911. + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
  84912. + if (len > ep->dwc_ep.maxpacket) {
  84913. + len = ep->dwc_ep.maxpacket;
  84914. + }
  84915. + dwords = (len + 3) / 4;
  84916. +
  84917. + /* While there is space in the queue and space in the FIFO and
  84918. + * More data to tranfer, Write packets to the Tx FIFO */
  84919. + txstatus.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  84920. + DWC_DEBUGPL(DBG_PCDV, "b4 GNPTXSTS=0x%08x\n", txstatus.d32);
  84921. +
  84922. + while (txstatus.b.nptxqspcavail > 0 &&
  84923. + txstatus.b.nptxfspcavail > dwords &&
  84924. + ep->dwc_ep.xfer_count < ep->dwc_ep.xfer_len) {
  84925. + /* Write the FIFO */
  84926. + dwc_otg_ep_write_packet(core_if, &ep->dwc_ep, 0);
  84927. + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
  84928. +
  84929. + if (len > ep->dwc_ep.maxpacket) {
  84930. + len = ep->dwc_ep.maxpacket;
  84931. + }
  84932. +
  84933. + dwords = (len + 3) / 4;
  84934. + txstatus.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  84935. + DWC_DEBUGPL(DBG_PCDV, "GNPTXSTS=0x%08x\n", txstatus.d32);
  84936. + }
  84937. +
  84938. + DWC_DEBUGPL(DBG_PCDV, "GNPTXSTS=0x%08x\n",
  84939. + DWC_READ_REG32(&global_regs->gnptxsts));
  84940. +
  84941. + /* Clear interrupt */
  84942. + gintsts.d32 = 0;
  84943. + gintsts.b.nptxfempty = 1;
  84944. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  84945. +
  84946. + return 1;
  84947. +}
  84948. +
  84949. +/**
  84950. + * This function is called when dedicated Tx FIFO Empty interrupt occurs.
  84951. + * The active request is checked for the next packet to be loaded into
  84952. + * apropriate Tx FIFO.
  84953. + */
  84954. +static int32_t write_empty_tx_fifo(dwc_otg_pcd_t * pcd, uint32_t epnum)
  84955. +{
  84956. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  84957. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  84958. + dwc_otg_dev_in_ep_regs_t *ep_regs;
  84959. + dtxfsts_data_t txstatus = {.d32 = 0 };
  84960. + dwc_otg_pcd_ep_t *ep = 0;
  84961. + uint32_t len = 0;
  84962. + int dwords;
  84963. +
  84964. + ep = get_in_ep(pcd, epnum);
  84965. +
  84966. + DWC_DEBUGPL(DBG_PCD, "Dedicated TxFifo Empty: %d \n", epnum);
  84967. +
  84968. + ep_regs = core_if->dev_if->in_ep_regs[epnum];
  84969. +
  84970. + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
  84971. +
  84972. + if (len > ep->dwc_ep.maxpacket) {
  84973. + len = ep->dwc_ep.maxpacket;
  84974. + }
  84975. +
  84976. + dwords = (len + 3) / 4;
  84977. +
  84978. + /* While there is space in the queue and space in the FIFO and
  84979. + * More data to tranfer, Write packets to the Tx FIFO */
  84980. + txstatus.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts);
  84981. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", epnum, txstatus.d32);
  84982. +
  84983. + while (txstatus.b.txfspcavail > dwords &&
  84984. + ep->dwc_ep.xfer_count < ep->dwc_ep.xfer_len &&
  84985. + ep->dwc_ep.xfer_len != 0) {
  84986. + /* Write the FIFO */
  84987. + dwc_otg_ep_write_packet(core_if, &ep->dwc_ep, 0);
  84988. +
  84989. + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
  84990. + if (len > ep->dwc_ep.maxpacket) {
  84991. + len = ep->dwc_ep.maxpacket;
  84992. + }
  84993. +
  84994. + dwords = (len + 3) / 4;
  84995. + txstatus.d32 =
  84996. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts);
  84997. + DWC_DEBUGPL(DBG_PCDV, "dtxfsts[%d]=0x%08x\n", epnum,
  84998. + txstatus.d32);
  84999. + }
  85000. +
  85001. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", epnum,
  85002. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts));
  85003. +
  85004. + return 1;
  85005. +}
  85006. +
  85007. +/**
  85008. + * This function is called when the Device is disconnected. It stops
  85009. + * any active requests and informs the Gadget driver of the
  85010. + * disconnect.
  85011. + */
  85012. +void dwc_otg_pcd_stop(dwc_otg_pcd_t * pcd)
  85013. +{
  85014. + int i, num_in_eps, num_out_eps;
  85015. + dwc_otg_pcd_ep_t *ep;
  85016. +
  85017. + gintmsk_data_t intr_mask = {.d32 = 0 };
  85018. +
  85019. + DWC_SPINLOCK(pcd->lock);
  85020. +
  85021. + num_in_eps = GET_CORE_IF(pcd)->dev_if->num_in_eps;
  85022. + num_out_eps = GET_CORE_IF(pcd)->dev_if->num_out_eps;
  85023. +
  85024. + DWC_DEBUGPL(DBG_PCDV, "%s() \n", __func__);
  85025. + /* don't disconnect drivers more than once */
  85026. + if (pcd->ep0state == EP0_DISCONNECT) {
  85027. + DWC_DEBUGPL(DBG_ANY, "%s() Already Disconnected\n", __func__);
  85028. + DWC_SPINUNLOCK(pcd->lock);
  85029. + return;
  85030. + }
  85031. + pcd->ep0state = EP0_DISCONNECT;
  85032. +
  85033. + /* Reset the OTG state. */
  85034. + dwc_otg_pcd_update_otg(pcd, 1);
  85035. +
  85036. + /* Disable the NP Tx Fifo Empty Interrupt. */
  85037. + intr_mask.b.nptxfempty = 1;
  85038. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  85039. + intr_mask.d32, 0);
  85040. +
  85041. + /* Flush the FIFOs */
  85042. + /**@todo NGS Flush Periodic FIFOs */
  85043. + dwc_otg_flush_tx_fifo(GET_CORE_IF(pcd), 0x10);
  85044. + dwc_otg_flush_rx_fifo(GET_CORE_IF(pcd));
  85045. +
  85046. + /* prevent new request submissions, kill any outstanding requests */
  85047. + ep = &pcd->ep0;
  85048. + dwc_otg_request_nuke(ep);
  85049. + /* prevent new request submissions, kill any outstanding requests */
  85050. + for (i = 0; i < num_in_eps; i++) {
  85051. + dwc_otg_pcd_ep_t *ep = &pcd->in_ep[i];
  85052. + dwc_otg_request_nuke(ep);
  85053. + }
  85054. + /* prevent new request submissions, kill any outstanding requests */
  85055. + for (i = 0; i < num_out_eps; i++) {
  85056. + dwc_otg_pcd_ep_t *ep = &pcd->out_ep[i];
  85057. + dwc_otg_request_nuke(ep);
  85058. + }
  85059. +
  85060. + /* report disconnect; the driver is already quiesced */
  85061. + if (pcd->fops->disconnect) {
  85062. + DWC_SPINUNLOCK(pcd->lock);
  85063. + pcd->fops->disconnect(pcd);
  85064. + DWC_SPINLOCK(pcd->lock);
  85065. + }
  85066. + DWC_SPINUNLOCK(pcd->lock);
  85067. +}
  85068. +
  85069. +/**
  85070. + * This interrupt indicates that ...
  85071. + */
  85072. +int32_t dwc_otg_pcd_handle_i2c_intr(dwc_otg_pcd_t * pcd)
  85073. +{
  85074. + gintmsk_data_t intr_mask = {.d32 = 0 };
  85075. + gintsts_data_t gintsts;
  85076. +
  85077. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n", "i2cintr");
  85078. + intr_mask.b.i2cintr = 1;
  85079. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  85080. + intr_mask.d32, 0);
  85081. +
  85082. + /* Clear interrupt */
  85083. + gintsts.d32 = 0;
  85084. + gintsts.b.i2cintr = 1;
  85085. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  85086. + gintsts.d32);
  85087. + return 1;
  85088. +}
  85089. +
  85090. +/**
  85091. + * This interrupt indicates that ...
  85092. + */
  85093. +int32_t dwc_otg_pcd_handle_early_suspend_intr(dwc_otg_pcd_t * pcd)
  85094. +{
  85095. + gintsts_data_t gintsts;
  85096. +#if defined(VERBOSE)
  85097. + DWC_PRINTF("Early Suspend Detected\n");
  85098. +#endif
  85099. +
  85100. + /* Clear interrupt */
  85101. + gintsts.d32 = 0;
  85102. + gintsts.b.erlysuspend = 1;
  85103. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  85104. + gintsts.d32);
  85105. + return 1;
  85106. +}
  85107. +
  85108. +/**
  85109. + * This function configures EPO to receive SETUP packets.
  85110. + *
  85111. + * @todo NGS: Update the comments from the HW FS.
  85112. + *
  85113. + * -# Program the following fields in the endpoint specific registers
  85114. + * for Control OUT EP 0, in order to receive a setup packet
  85115. + * - DOEPTSIZ0.Packet Count = 3 (To receive up to 3 back to back
  85116. + * setup packets)
  85117. + * - DOEPTSIZE0.Transfer Size = 24 Bytes (To receive up to 3 back
  85118. + * to back setup packets)
  85119. + * - In DMA mode, DOEPDMA0 Register with a memory address to
  85120. + * store any setup packets received
  85121. + *
  85122. + * @param core_if Programming view of DWC_otg controller.
  85123. + * @param pcd Programming view of the PCD.
  85124. + */
  85125. +static inline void ep0_out_start(dwc_otg_core_if_t * core_if,
  85126. + dwc_otg_pcd_t * pcd)
  85127. +{
  85128. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  85129. + deptsiz0_data_t doeptsize0 = {.d32 = 0 };
  85130. + dwc_otg_dev_dma_desc_t *dma_desc;
  85131. + depctl_data_t doepctl = {.d32 = 0 };
  85132. +
  85133. +#ifdef VERBOSE
  85134. + DWC_DEBUGPL(DBG_PCDV, "%s() doepctl0=%0x\n", __func__,
  85135. + DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl));
  85136. +#endif
  85137. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  85138. + doepctl.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl);
  85139. + if (doepctl.b.epena) {
  85140. + return;
  85141. + }
  85142. + }
  85143. +
  85144. + doeptsize0.b.supcnt = 3;
  85145. + doeptsize0.b.pktcnt = 1;
  85146. + doeptsize0.b.xfersize = 8 * 3;
  85147. +
  85148. + if (core_if->dma_enable) {
  85149. + if (!core_if->dma_desc_enable) {
  85150. + /** put here as for Hermes mode deptisz register should not be written */
  85151. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doeptsiz,
  85152. + doeptsize0.d32);
  85153. +
  85154. + /** @todo dma needs to handle multiple setup packets (up to 3) */
  85155. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doepdma,
  85156. + pcd->setup_pkt_dma_handle);
  85157. + } else {
  85158. + dev_if->setup_desc_index =
  85159. + (dev_if->setup_desc_index + 1) & 1;
  85160. + dma_desc =
  85161. + dev_if->setup_desc_addr[dev_if->setup_desc_index];
  85162. +
  85163. + /** DMA Descriptor Setup */
  85164. + dma_desc->status.b.bs = BS_HOST_BUSY;
  85165. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  85166. + dma_desc->status.b.sr = 0;
  85167. + dma_desc->status.b.mtrf = 0;
  85168. + }
  85169. + dma_desc->status.b.l = 1;
  85170. + dma_desc->status.b.ioc = 1;
  85171. + dma_desc->status.b.bytes = pcd->ep0.dwc_ep.maxpacket;
  85172. + dma_desc->buf = pcd->setup_pkt_dma_handle;
  85173. + dma_desc->status.b.sts = 0;
  85174. + dma_desc->status.b.bs = BS_HOST_READY;
  85175. +
  85176. + /** DOEPDMA0 Register write */
  85177. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doepdma,
  85178. + dev_if->dma_setup_desc_addr
  85179. + [dev_if->setup_desc_index]);
  85180. + }
  85181. +
  85182. + } else {
  85183. + /** put here as for Hermes mode deptisz register should not be written */
  85184. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doeptsiz,
  85185. + doeptsize0.d32);
  85186. + }
  85187. +
  85188. + /** DOEPCTL0 Register write cnak will be set after setup interrupt */
  85189. + doepctl.d32 = 0;
  85190. + doepctl.b.epena = 1;
  85191. + if (core_if->snpsid <= OTG_CORE_REV_2_94a) {
  85192. + doepctl.b.cnak = 1;
  85193. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doepctl, doepctl.d32);
  85194. + } else {
  85195. + DWC_MODIFY_REG32(&dev_if->out_ep_regs[0]->doepctl, 0, doepctl.d32);
  85196. + }
  85197. +
  85198. +#ifdef VERBOSE
  85199. + DWC_DEBUGPL(DBG_PCDV, "doepctl0=%0x\n",
  85200. + DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl));
  85201. + DWC_DEBUGPL(DBG_PCDV, "diepctl0=%0x\n",
  85202. + DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl));
  85203. +#endif
  85204. +}
  85205. +
  85206. +/**
  85207. + * This interrupt occurs when a USB Reset is detected. When the USB
  85208. + * Reset Interrupt occurs the device state is set to DEFAULT and the
  85209. + * EP0 state is set to IDLE.
  85210. + * -# Set the NAK bit for all OUT endpoints (DOEPCTLn.SNAK = 1)
  85211. + * -# Unmask the following interrupt bits
  85212. + * - DAINTMSK.INEP0 = 1 (Control 0 IN endpoint)
  85213. + * - DAINTMSK.OUTEP0 = 1 (Control 0 OUT endpoint)
  85214. + * - DOEPMSK.SETUP = 1
  85215. + * - DOEPMSK.XferCompl = 1
  85216. + * - DIEPMSK.XferCompl = 1
  85217. + * - DIEPMSK.TimeOut = 1
  85218. + * -# Program the following fields in the endpoint specific registers
  85219. + * for Control OUT EP 0, in order to receive a setup packet
  85220. + * - DOEPTSIZ0.Packet Count = 3 (To receive up to 3 back to back
  85221. + * setup packets)
  85222. + * - DOEPTSIZE0.Transfer Size = 24 Bytes (To receive up to 3 back
  85223. + * to back setup packets)
  85224. + * - In DMA mode, DOEPDMA0 Register with a memory address to
  85225. + * store any setup packets received
  85226. + * At this point, all the required initialization, except for enabling
  85227. + * the control 0 OUT endpoint is done, for receiving SETUP packets.
  85228. + */
  85229. +int32_t dwc_otg_pcd_handle_usb_reset_intr(dwc_otg_pcd_t * pcd)
  85230. +{
  85231. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  85232. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  85233. + depctl_data_t doepctl = {.d32 = 0 };
  85234. + depctl_data_t diepctl = {.d32 = 0 };
  85235. + daint_data_t daintmsk = {.d32 = 0 };
  85236. + doepmsk_data_t doepmsk = {.d32 = 0 };
  85237. + diepmsk_data_t diepmsk = {.d32 = 0 };
  85238. + dcfg_data_t dcfg = {.d32 = 0 };
  85239. + grstctl_t resetctl = {.d32 = 0 };
  85240. + dctl_data_t dctl = {.d32 = 0 };
  85241. + int i = 0;
  85242. + gintsts_data_t gintsts;
  85243. + pcgcctl_data_t power = {.d32 = 0 };
  85244. +
  85245. + power.d32 = DWC_READ_REG32(core_if->pcgcctl);
  85246. + if (power.b.stoppclk) {
  85247. + power.d32 = 0;
  85248. + power.b.stoppclk = 1;
  85249. + DWC_MODIFY_REG32(core_if->pcgcctl, power.d32, 0);
  85250. +
  85251. + power.b.pwrclmp = 1;
  85252. + DWC_MODIFY_REG32(core_if->pcgcctl, power.d32, 0);
  85253. +
  85254. + power.b.rstpdwnmodule = 1;
  85255. + DWC_MODIFY_REG32(core_if->pcgcctl, power.d32, 0);
  85256. + }
  85257. +
  85258. + core_if->lx_state = DWC_OTG_L0;
  85259. +
  85260. + DWC_PRINTF("USB RESET\n");
  85261. +#ifdef DWC_EN_ISOC
  85262. + for (i = 1; i < 16; ++i) {
  85263. + dwc_otg_pcd_ep_t *ep;
  85264. + dwc_ep_t *dwc_ep;
  85265. + ep = get_in_ep(pcd, i);
  85266. + if (ep != 0) {
  85267. + dwc_ep = &ep->dwc_ep;
  85268. + dwc_ep->next_frame = 0xffffffff;
  85269. + }
  85270. + }
  85271. +#endif /* DWC_EN_ISOC */
  85272. +
  85273. + /* reset the HNP settings */
  85274. + dwc_otg_pcd_update_otg(pcd, 1);
  85275. +
  85276. + /* Clear the Remote Wakeup Signalling */
  85277. + dctl.b.rmtwkupsig = 1;
  85278. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32, 0);
  85279. +
  85280. + /* Set NAK for all OUT EPs */
  85281. + doepctl.b.snak = 1;
  85282. + for (i = 0; i <= dev_if->num_out_eps; i++) {
  85283. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepctl, doepctl.d32);
  85284. + }
  85285. +
  85286. + /* Flush the NP Tx FIFO */
  85287. + dwc_otg_flush_tx_fifo(core_if, 0x10);
  85288. + /* Flush the Learning Queue */
  85289. + resetctl.b.intknqflsh = 1;
  85290. + DWC_WRITE_REG32(&core_if->core_global_regs->grstctl, resetctl.d32);
  85291. +
  85292. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable) {
  85293. + core_if->start_predict = 0;
  85294. + for (i = 0; i<= core_if->dev_if->num_in_eps; ++i) {
  85295. + core_if->nextep_seq[i] = 0xff; // 0xff - EP not active
  85296. + }
  85297. + core_if->nextep_seq[0] = 0;
  85298. + core_if->first_in_nextep_seq = 0;
  85299. + diepctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl);
  85300. + diepctl.b.nextep = 0;
  85301. + DWC_WRITE_REG32(&dev_if->in_ep_regs[0]->diepctl, diepctl.d32);
  85302. +
  85303. + /* Update IN Endpoint Mismatch Count by active IN NP EP count + 1 */
  85304. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  85305. + dcfg.b.epmscnt = 2;
  85306. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  85307. +
  85308. + DWC_DEBUGPL(DBG_PCDV,
  85309. + "%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  85310. + __func__, core_if->first_in_nextep_seq);
  85311. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  85312. + DWC_DEBUGPL(DBG_PCDV, "%2d\n", core_if->nextep_seq[i]);
  85313. + }
  85314. + }
  85315. +
  85316. + if (core_if->multiproc_int_enable) {
  85317. + daintmsk.b.inep0 = 1;
  85318. + daintmsk.b.outep0 = 1;
  85319. + DWC_WRITE_REG32(&dev_if->dev_global_regs->deachintmsk,
  85320. + daintmsk.d32);
  85321. +
  85322. + doepmsk.b.setup = 1;
  85323. + doepmsk.b.xfercompl = 1;
  85324. + doepmsk.b.ahberr = 1;
  85325. + doepmsk.b.epdisabled = 1;
  85326. +
  85327. + if ((core_if->dma_desc_enable) ||
  85328. + (core_if->dma_enable
  85329. + && core_if->snpsid >= OTG_CORE_REV_3_00a)) {
  85330. + doepmsk.b.stsphsercvd = 1;
  85331. + }
  85332. + if (core_if->dma_desc_enable)
  85333. + doepmsk.b.bna = 1;
  85334. +/*
  85335. + doepmsk.b.babble = 1;
  85336. + doepmsk.b.nyet = 1;
  85337. +
  85338. + if (core_if->dma_enable) {
  85339. + doepmsk.b.nak = 1;
  85340. + }
  85341. +*/
  85342. + DWC_WRITE_REG32(&dev_if->dev_global_regs->doepeachintmsk[0],
  85343. + doepmsk.d32);
  85344. +
  85345. + diepmsk.b.xfercompl = 1;
  85346. + diepmsk.b.timeout = 1;
  85347. + diepmsk.b.epdisabled = 1;
  85348. + diepmsk.b.ahberr = 1;
  85349. + diepmsk.b.intknepmis = 1;
  85350. + if (!core_if->en_multiple_tx_fifo && core_if->dma_enable)
  85351. + diepmsk.b.intknepmis = 0;
  85352. +
  85353. +/* if (core_if->dma_desc_enable) {
  85354. + diepmsk.b.bna = 1;
  85355. + }
  85356. +*/
  85357. +/*
  85358. + if (core_if->dma_enable) {
  85359. + diepmsk.b.nak = 1;
  85360. + }
  85361. +*/
  85362. + DWC_WRITE_REG32(&dev_if->dev_global_regs->diepeachintmsk[0],
  85363. + diepmsk.d32);
  85364. + } else {
  85365. + daintmsk.b.inep0 = 1;
  85366. + daintmsk.b.outep0 = 1;
  85367. + DWC_WRITE_REG32(&dev_if->dev_global_regs->daintmsk,
  85368. + daintmsk.d32);
  85369. +
  85370. + doepmsk.b.setup = 1;
  85371. + doepmsk.b.xfercompl = 1;
  85372. + doepmsk.b.ahberr = 1;
  85373. + doepmsk.b.epdisabled = 1;
  85374. +
  85375. + if ((core_if->dma_desc_enable) ||
  85376. + (core_if->dma_enable
  85377. + && core_if->snpsid >= OTG_CORE_REV_3_00a)) {
  85378. + doepmsk.b.stsphsercvd = 1;
  85379. + }
  85380. + if (core_if->dma_desc_enable)
  85381. + doepmsk.b.bna = 1;
  85382. + DWC_WRITE_REG32(&dev_if->dev_global_regs->doepmsk, doepmsk.d32);
  85383. +
  85384. + diepmsk.b.xfercompl = 1;
  85385. + diepmsk.b.timeout = 1;
  85386. + diepmsk.b.epdisabled = 1;
  85387. + diepmsk.b.ahberr = 1;
  85388. + if (!core_if->en_multiple_tx_fifo && core_if->dma_enable)
  85389. + diepmsk.b.intknepmis = 0;
  85390. +/*
  85391. + if (core_if->dma_desc_enable) {
  85392. + diepmsk.b.bna = 1;
  85393. + }
  85394. +*/
  85395. +
  85396. + DWC_WRITE_REG32(&dev_if->dev_global_regs->diepmsk, diepmsk.d32);
  85397. + }
  85398. +
  85399. + /* Reset Device Address */
  85400. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  85401. + dcfg.b.devaddr = 0;
  85402. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  85403. +
  85404. + /* setup EP0 to receive SETUP packets */
  85405. + if (core_if->snpsid <= OTG_CORE_REV_2_94a)
  85406. + ep0_out_start(core_if, pcd);
  85407. +
  85408. + /* Clear interrupt */
  85409. + gintsts.d32 = 0;
  85410. + gintsts.b.usbreset = 1;
  85411. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  85412. +
  85413. + return 1;
  85414. +}
  85415. +
  85416. +/**
  85417. + * Get the device speed from the device status register and convert it
  85418. + * to USB speed constant.
  85419. + *
  85420. + * @param core_if Programming view of DWC_otg controller.
  85421. + */
  85422. +static int get_device_speed(dwc_otg_core_if_t * core_if)
  85423. +{
  85424. + dsts_data_t dsts;
  85425. + int speed = 0;
  85426. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  85427. +
  85428. + switch (dsts.b.enumspd) {
  85429. + case DWC_DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ:
  85430. + speed = USB_SPEED_HIGH;
  85431. + break;
  85432. + case DWC_DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ:
  85433. + case DWC_DSTS_ENUMSPD_FS_PHY_48MHZ:
  85434. + speed = USB_SPEED_FULL;
  85435. + break;
  85436. +
  85437. + case DWC_DSTS_ENUMSPD_LS_PHY_6MHZ:
  85438. + speed = USB_SPEED_LOW;
  85439. + break;
  85440. + }
  85441. +
  85442. + return speed;
  85443. +}
  85444. +
  85445. +/**
  85446. + * Read the device status register and set the device speed in the
  85447. + * data structure.
  85448. + * Set up EP0 to receive SETUP packets by calling dwc_ep0_activate.
  85449. + */
  85450. +int32_t dwc_otg_pcd_handle_enum_done_intr(dwc_otg_pcd_t * pcd)
  85451. +{
  85452. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  85453. + gintsts_data_t gintsts;
  85454. + gusbcfg_data_t gusbcfg;
  85455. + dwc_otg_core_global_regs_t *global_regs =
  85456. + GET_CORE_IF(pcd)->core_global_regs;
  85457. + uint8_t utmi16b, utmi8b;
  85458. + int speed;
  85459. + DWC_DEBUGPL(DBG_PCD, "SPEED ENUM\n");
  85460. +
  85461. + if (GET_CORE_IF(pcd)->snpsid >= OTG_CORE_REV_2_60a) {
  85462. + utmi16b = 6; //vahrama old value was 6;
  85463. + utmi8b = 9;
  85464. + } else {
  85465. + utmi16b = 4;
  85466. + utmi8b = 8;
  85467. + }
  85468. + dwc_otg_ep0_activate(GET_CORE_IF(pcd), &ep0->dwc_ep);
  85469. + if (GET_CORE_IF(pcd)->snpsid >= OTG_CORE_REV_3_00a) {
  85470. + ep0_out_start(GET_CORE_IF(pcd), pcd);
  85471. + }
  85472. +
  85473. +#ifdef DEBUG_EP0
  85474. + print_ep0_state(pcd);
  85475. +#endif
  85476. +
  85477. + if (pcd->ep0state == EP0_DISCONNECT) {
  85478. + pcd->ep0state = EP0_IDLE;
  85479. + } else if (pcd->ep0state == EP0_STALL) {
  85480. + pcd->ep0state = EP0_IDLE;
  85481. + }
  85482. +
  85483. + pcd->ep0state = EP0_IDLE;
  85484. +
  85485. + ep0->stopped = 0;
  85486. +
  85487. + speed = get_device_speed(GET_CORE_IF(pcd));
  85488. + pcd->fops->connect(pcd, speed);
  85489. +
  85490. + /* Set USB turnaround time based on device speed and PHY interface. */
  85491. + gusbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  85492. + if (speed == USB_SPEED_HIGH) {
  85493. + if (GET_CORE_IF(pcd)->hwcfg2.b.hs_phy_type ==
  85494. + DWC_HWCFG2_HS_PHY_TYPE_ULPI) {
  85495. + /* ULPI interface */
  85496. + gusbcfg.b.usbtrdtim = 9;
  85497. + }
  85498. + if (GET_CORE_IF(pcd)->hwcfg2.b.hs_phy_type ==
  85499. + DWC_HWCFG2_HS_PHY_TYPE_UTMI) {
  85500. + /* UTMI+ interface */
  85501. + if (GET_CORE_IF(pcd)->hwcfg4.b.utmi_phy_data_width == 0) {
  85502. + gusbcfg.b.usbtrdtim = utmi8b;
  85503. + } else if (GET_CORE_IF(pcd)->hwcfg4.
  85504. + b.utmi_phy_data_width == 1) {
  85505. + gusbcfg.b.usbtrdtim = utmi16b;
  85506. + } else if (GET_CORE_IF(pcd)->
  85507. + core_params->phy_utmi_width == 8) {
  85508. + gusbcfg.b.usbtrdtim = utmi8b;
  85509. + } else {
  85510. + gusbcfg.b.usbtrdtim = utmi16b;
  85511. + }
  85512. + }
  85513. + if (GET_CORE_IF(pcd)->hwcfg2.b.hs_phy_type ==
  85514. + DWC_HWCFG2_HS_PHY_TYPE_UTMI_ULPI) {
  85515. + /* UTMI+ OR ULPI interface */
  85516. + if (gusbcfg.b.ulpi_utmi_sel == 1) {
  85517. + /* ULPI interface */
  85518. + gusbcfg.b.usbtrdtim = 9;
  85519. + } else {
  85520. + /* UTMI+ interface */
  85521. + if (GET_CORE_IF(pcd)->
  85522. + core_params->phy_utmi_width == 16) {
  85523. + gusbcfg.b.usbtrdtim = utmi16b;
  85524. + } else {
  85525. + gusbcfg.b.usbtrdtim = utmi8b;
  85526. + }
  85527. + }
  85528. + }
  85529. + } else {
  85530. + /* Full or low speed */
  85531. + gusbcfg.b.usbtrdtim = 9;
  85532. + }
  85533. + DWC_WRITE_REG32(&global_regs->gusbcfg, gusbcfg.d32);
  85534. +
  85535. + /* Clear interrupt */
  85536. + gintsts.d32 = 0;
  85537. + gintsts.b.enumdone = 1;
  85538. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  85539. + gintsts.d32);
  85540. + return 1;
  85541. +}
  85542. +
  85543. +/**
  85544. + * This interrupt indicates that the ISO OUT Packet was dropped due to
  85545. + * Rx FIFO full or Rx Status Queue Full. If this interrupt occurs
  85546. + * read all the data from the Rx FIFO.
  85547. + */
  85548. +int32_t dwc_otg_pcd_handle_isoc_out_packet_dropped_intr(dwc_otg_pcd_t * pcd)
  85549. +{
  85550. + gintmsk_data_t intr_mask = {.d32 = 0 };
  85551. + gintsts_data_t gintsts;
  85552. +
  85553. + DWC_WARN("INTERRUPT Handler not implemented for %s\n",
  85554. + "ISOC Out Dropped");
  85555. +
  85556. + intr_mask.b.isooutdrop = 1;
  85557. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  85558. + intr_mask.d32, 0);
  85559. +
  85560. + /* Clear interrupt */
  85561. + gintsts.d32 = 0;
  85562. + gintsts.b.isooutdrop = 1;
  85563. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  85564. + gintsts.d32);
  85565. +
  85566. + return 1;
  85567. +}
  85568. +
  85569. +/**
  85570. + * This interrupt indicates the end of the portion of the micro-frame
  85571. + * for periodic transactions. If there is a periodic transaction for
  85572. + * the next frame, load the packets into the EP periodic Tx FIFO.
  85573. + */
  85574. +int32_t dwc_otg_pcd_handle_end_periodic_frame_intr(dwc_otg_pcd_t * pcd)
  85575. +{
  85576. + gintmsk_data_t intr_mask = {.d32 = 0 };
  85577. + gintsts_data_t gintsts;
  85578. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n", "EOP");
  85579. +
  85580. + intr_mask.b.eopframe = 1;
  85581. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  85582. + intr_mask.d32, 0);
  85583. +
  85584. + /* Clear interrupt */
  85585. + gintsts.d32 = 0;
  85586. + gintsts.b.eopframe = 1;
  85587. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  85588. + gintsts.d32);
  85589. +
  85590. + return 1;
  85591. +}
  85592. +
  85593. +/**
  85594. + * This interrupt indicates that EP of the packet on the top of the
  85595. + * non-periodic Tx FIFO does not match EP of the IN Token received.
  85596. + *
  85597. + * The "Device IN Token Queue" Registers are read to determine the
  85598. + * order the IN Tokens have been received. The non-periodic Tx FIFO
  85599. + * is flushed, so it can be reloaded in the order seen in the IN Token
  85600. + * Queue.
  85601. + */
  85602. +int32_t dwc_otg_pcd_handle_ep_mismatch_intr(dwc_otg_pcd_t * pcd)
  85603. +{
  85604. + gintsts_data_t gintsts;
  85605. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  85606. + dctl_data_t dctl;
  85607. + gintmsk_data_t intr_mask = {.d32 = 0 };
  85608. +
  85609. + if (!core_if->en_multiple_tx_fifo && core_if->dma_enable) {
  85610. + core_if->start_predict = 1;
  85611. +
  85612. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, core_if);
  85613. +
  85614. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  85615. + if (!gintsts.b.ginnakeff) {
  85616. + /* Disable EP Mismatch interrupt */
  85617. + intr_mask.d32 = 0;
  85618. + intr_mask.b.epmismatch = 1;
  85619. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, intr_mask.d32, 0);
  85620. + /* Enable the Global IN NAK Effective Interrupt */
  85621. + intr_mask.d32 = 0;
  85622. + intr_mask.b.ginnakeff = 1;
  85623. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, intr_mask.d32);
  85624. + /* Set the global non-periodic IN NAK handshake */
  85625. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  85626. + dctl.b.sgnpinnak = 1;
  85627. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32);
  85628. + } else {
  85629. + DWC_PRINTF("gintsts.b.ginnakeff = 1! dctl.b.sgnpinnak not set\n");
  85630. + }
  85631. + /* Disabling of all EP's will be done in dwc_otg_pcd_handle_in_nak_effective()
  85632. + * handler after Global IN NAK Effective interrupt will be asserted */
  85633. + }
  85634. + /* Clear interrupt */
  85635. + gintsts.d32 = 0;
  85636. + gintsts.b.epmismatch = 1;
  85637. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  85638. +
  85639. + return 1;
  85640. +}
  85641. +
  85642. +/**
  85643. + * This interrupt is valid only in DMA mode. This interrupt indicates that the
  85644. + * core has stopped fetching data for IN endpoints due to the unavailability of
  85645. + * TxFIFO space or Request Queue space. This interrupt is used by the
  85646. + * application for an endpoint mismatch algorithm.
  85647. + *
  85648. + * @param pcd The PCD
  85649. + */
  85650. +int32_t dwc_otg_pcd_handle_ep_fetsusp_intr(dwc_otg_pcd_t * pcd)
  85651. +{
  85652. + gintsts_data_t gintsts;
  85653. + gintmsk_data_t gintmsk_data;
  85654. + dctl_data_t dctl;
  85655. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  85656. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, core_if);
  85657. +
  85658. + /* Clear the global non-periodic IN NAK handshake */
  85659. + dctl.d32 = 0;
  85660. + dctl.b.cgnpinnak = 1;
  85661. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  85662. +
  85663. + /* Mask GINTSTS.FETSUSP interrupt */
  85664. + gintmsk_data.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  85665. + gintmsk_data.b.fetsusp = 0;
  85666. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gintmsk_data.d32);
  85667. +
  85668. + /* Clear interrupt */
  85669. + gintsts.d32 = 0;
  85670. + gintsts.b.fetsusp = 1;
  85671. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  85672. +
  85673. + return 1;
  85674. +}
  85675. +/**
  85676. + * This funcion stalls EP0.
  85677. + */
  85678. +static inline void ep0_do_stall(dwc_otg_pcd_t * pcd, const int err_val)
  85679. +{
  85680. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  85681. + usb_device_request_t *ctrl = &pcd->setup_pkt->req;
  85682. + DWC_WARN("req %02x.%02x protocol STALL; err %d\n",
  85683. + ctrl->bmRequestType, ctrl->bRequest, err_val);
  85684. +
  85685. + ep0->dwc_ep.is_in = 1;
  85686. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd), &ep0->dwc_ep);
  85687. + pcd->ep0.stopped = 1;
  85688. + pcd->ep0state = EP0_IDLE;
  85689. + ep0_out_start(GET_CORE_IF(pcd), pcd);
  85690. +}
  85691. +
  85692. +/**
  85693. + * This functions delegates the setup command to the gadget driver.
  85694. + */
  85695. +static inline void do_gadget_setup(dwc_otg_pcd_t * pcd,
  85696. + usb_device_request_t * ctrl)
  85697. +{
  85698. + int ret = 0;
  85699. + DWC_SPINUNLOCK(pcd->lock);
  85700. + ret = pcd->fops->setup(pcd, (uint8_t *) ctrl);
  85701. + DWC_SPINLOCK(pcd->lock);
  85702. + if (ret < 0) {
  85703. + ep0_do_stall(pcd, ret);
  85704. + }
  85705. +
  85706. + /** @todo This is a g_file_storage gadget driver specific
  85707. + * workaround: a DELAYED_STATUS result from the fsg_setup
  85708. + * routine will result in the gadget queueing a EP0 IN status
  85709. + * phase for a two-stage control transfer. Exactly the same as
  85710. + * a SET_CONFIGURATION/SET_INTERFACE except that this is a class
  85711. + * specific request. Need a generic way to know when the gadget
  85712. + * driver will queue the status phase. Can we assume when we
  85713. + * call the gadget driver setup() function that it will always
  85714. + * queue and require the following flag? Need to look into
  85715. + * this.
  85716. + */
  85717. +
  85718. + if (ret == 256 + 999) {
  85719. + pcd->request_config = 1;
  85720. + }
  85721. +}
  85722. +
  85723. +#ifdef DWC_UTE_CFI
  85724. +/**
  85725. + * This functions delegates the CFI setup commands to the gadget driver.
  85726. + * This function will return a negative value to indicate a failure.
  85727. + */
  85728. +static inline int cfi_gadget_setup(dwc_otg_pcd_t * pcd,
  85729. + struct cfi_usb_ctrlrequest *ctrl_req)
  85730. +{
  85731. + int ret = 0;
  85732. +
  85733. + if (pcd->fops && pcd->fops->cfi_setup) {
  85734. + DWC_SPINUNLOCK(pcd->lock);
  85735. + ret = pcd->fops->cfi_setup(pcd, ctrl_req);
  85736. + DWC_SPINLOCK(pcd->lock);
  85737. + if (ret < 0) {
  85738. + ep0_do_stall(pcd, ret);
  85739. + return ret;
  85740. + }
  85741. + }
  85742. +
  85743. + return ret;
  85744. +}
  85745. +#endif
  85746. +
  85747. +/**
  85748. + * This function starts the Zero-Length Packet for the IN status phase
  85749. + * of a 2 stage control transfer.
  85750. + */
  85751. +static inline void do_setup_in_status_phase(dwc_otg_pcd_t * pcd)
  85752. +{
  85753. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  85754. + if (pcd->ep0state == EP0_STALL) {
  85755. + return;
  85756. + }
  85757. +
  85758. + pcd->ep0state = EP0_IN_STATUS_PHASE;
  85759. +
  85760. + /* Prepare for more SETUP Packets */
  85761. + DWC_DEBUGPL(DBG_PCD, "EP0 IN ZLP\n");
  85762. + if ((GET_CORE_IF(pcd)->snpsid >= OTG_CORE_REV_3_00a)
  85763. + && (pcd->core_if->dma_desc_enable)
  85764. + && (ep0->dwc_ep.xfer_count < ep0->dwc_ep.total_len)) {
  85765. + DWC_DEBUGPL(DBG_PCDV,
  85766. + "Data terminated wait next packet in out_desc_addr\n");
  85767. + pcd->backup_buf = phys_to_virt(ep0->dwc_ep.dma_addr);
  85768. + pcd->data_terminated = 1;
  85769. + }
  85770. + ep0->dwc_ep.xfer_len = 0;
  85771. + ep0->dwc_ep.xfer_count = 0;
  85772. + ep0->dwc_ep.is_in = 1;
  85773. + ep0->dwc_ep.dma_addr = pcd->setup_pkt_dma_handle;
  85774. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd), &ep0->dwc_ep);
  85775. +
  85776. + /* Prepare for more SETUP Packets */
  85777. + //ep0_out_start(GET_CORE_IF(pcd), pcd);
  85778. +}
  85779. +
  85780. +/**
  85781. + * This function starts the Zero-Length Packet for the OUT status phase
  85782. + * of a 2 stage control transfer.
  85783. + */
  85784. +static inline void do_setup_out_status_phase(dwc_otg_pcd_t * pcd)
  85785. +{
  85786. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  85787. + if (pcd->ep0state == EP0_STALL) {
  85788. + DWC_DEBUGPL(DBG_PCD, "EP0 STALLED\n");
  85789. + return;
  85790. + }
  85791. + pcd->ep0state = EP0_OUT_STATUS_PHASE;
  85792. +
  85793. + DWC_DEBUGPL(DBG_PCD, "EP0 OUT ZLP\n");
  85794. + ep0->dwc_ep.xfer_len = 0;
  85795. + ep0->dwc_ep.xfer_count = 0;
  85796. + ep0->dwc_ep.is_in = 0;
  85797. + ep0->dwc_ep.dma_addr = pcd->setup_pkt_dma_handle;
  85798. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd), &ep0->dwc_ep);
  85799. +
  85800. + /* Prepare for more SETUP Packets */
  85801. + if (GET_CORE_IF(pcd)->dma_enable == 0) {
  85802. + ep0_out_start(GET_CORE_IF(pcd), pcd);
  85803. + }
  85804. +}
  85805. +
  85806. +/**
  85807. + * Clear the EP halt (STALL) and if pending requests start the
  85808. + * transfer.
  85809. + */
  85810. +static inline void pcd_clear_halt(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * ep)
  85811. +{
  85812. + if (ep->dwc_ep.stall_clear_flag == 0)
  85813. + dwc_otg_ep_clear_stall(GET_CORE_IF(pcd), &ep->dwc_ep);
  85814. +
  85815. + /* Reactive the EP */
  85816. + dwc_otg_ep_activate(GET_CORE_IF(pcd), &ep->dwc_ep);
  85817. + if (ep->stopped) {
  85818. + ep->stopped = 0;
  85819. + /* If there is a request in the EP queue start it */
  85820. +
  85821. + /** @todo FIXME: this causes an EP mismatch in DMA mode.
  85822. + * epmismatch not yet implemented. */
  85823. +
  85824. + /*
  85825. + * Above fixme is solved by implmenting a tasklet to call the
  85826. + * start_next_request(), outside of interrupt context at some
  85827. + * time after the current time, after a clear-halt setup packet.
  85828. + * Still need to implement ep mismatch in the future if a gadget
  85829. + * ever uses more than one endpoint at once
  85830. + */
  85831. + ep->queue_sof = 1;
  85832. + DWC_TASK_SCHEDULE(pcd->start_xfer_tasklet);
  85833. + }
  85834. + /* Start Control Status Phase */
  85835. + do_setup_in_status_phase(pcd);
  85836. +}
  85837. +
  85838. +/**
  85839. + * This function is called when the SET_FEATURE TEST_MODE Setup packet
  85840. + * is sent from the host. The Device Control register is written with
  85841. + * the Test Mode bits set to the specified Test Mode. This is done as
  85842. + * a tasklet so that the "Status" phase of the control transfer
  85843. + * completes before transmitting the TEST packets.
  85844. + *
  85845. + * @todo This has not been tested since the tasklet struct was put
  85846. + * into the PCD struct!
  85847. + *
  85848. + */
  85849. +void do_test_mode(void *data)
  85850. +{
  85851. + dctl_data_t dctl;
  85852. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) data;
  85853. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  85854. + int test_mode = pcd->test_mode;
  85855. +
  85856. +// DWC_WARN("%s() has not been tested since being rewritten!\n", __func__);
  85857. +
  85858. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  85859. + switch (test_mode) {
  85860. + case 1: // TEST_J
  85861. + dctl.b.tstctl = 1;
  85862. + break;
  85863. +
  85864. + case 2: // TEST_K
  85865. + dctl.b.tstctl = 2;
  85866. + break;
  85867. +
  85868. + case 3: // TEST_SE0_NAK
  85869. + dctl.b.tstctl = 3;
  85870. + break;
  85871. +
  85872. + case 4: // TEST_PACKET
  85873. + dctl.b.tstctl = 4;
  85874. + break;
  85875. +
  85876. + case 5: // TEST_FORCE_ENABLE
  85877. + dctl.b.tstctl = 5;
  85878. + break;
  85879. + }
  85880. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32);
  85881. +}
  85882. +
  85883. +/**
  85884. + * This function process the GET_STATUS Setup Commands.
  85885. + */
  85886. +static inline void do_get_status(dwc_otg_pcd_t * pcd)
  85887. +{
  85888. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  85889. + dwc_otg_pcd_ep_t *ep;
  85890. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  85891. + uint16_t *status = pcd->status_buf;
  85892. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  85893. +
  85894. +#ifdef DEBUG_EP0
  85895. + DWC_DEBUGPL(DBG_PCD,
  85896. + "GET_STATUS %02x.%02x v%04x i%04x l%04x\n",
  85897. + ctrl.bmRequestType, ctrl.bRequest,
  85898. + UGETW(ctrl.wValue), UGETW(ctrl.wIndex),
  85899. + UGETW(ctrl.wLength));
  85900. +#endif
  85901. +
  85902. + switch (UT_GET_RECIPIENT(ctrl.bmRequestType)) {
  85903. + case UT_DEVICE:
  85904. + if(UGETW(ctrl.wIndex) == 0xF000) { /* OTG Status selector */
  85905. + DWC_PRINTF("wIndex - %d\n", UGETW(ctrl.wIndex));
  85906. + DWC_PRINTF("OTG VERSION - %d\n", core_if->otg_ver);
  85907. + DWC_PRINTF("OTG CAP - %d, %d\n",
  85908. + core_if->core_params->otg_cap,
  85909. + DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE);
  85910. + if (core_if->otg_ver == 1
  85911. + && core_if->core_params->otg_cap ==
  85912. + DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE) {
  85913. + uint8_t *otgsts = (uint8_t*)pcd->status_buf;
  85914. + *otgsts = (core_if->otg_sts & 0x1);
  85915. + pcd->ep0_pending = 1;
  85916. + ep0->dwc_ep.start_xfer_buff =
  85917. + (uint8_t *) otgsts;
  85918. + ep0->dwc_ep.xfer_buff = (uint8_t *) otgsts;
  85919. + ep0->dwc_ep.dma_addr =
  85920. + pcd->status_buf_dma_handle;
  85921. + ep0->dwc_ep.xfer_len = 1;
  85922. + ep0->dwc_ep.xfer_count = 0;
  85923. + ep0->dwc_ep.total_len = ep0->dwc_ep.xfer_len;
  85924. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd),
  85925. + &ep0->dwc_ep);
  85926. + return;
  85927. + } else {
  85928. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  85929. + return;
  85930. + }
  85931. + break;
  85932. + } else {
  85933. + *status = 0x1; /* Self powered */
  85934. + *status |= pcd->remote_wakeup_enable << 1;
  85935. + break;
  85936. + }
  85937. + case UT_INTERFACE:
  85938. + *status = 0;
  85939. + break;
  85940. +
  85941. + case UT_ENDPOINT:
  85942. + ep = get_ep_by_addr(pcd, UGETW(ctrl.wIndex));
  85943. + if (ep == 0 || UGETW(ctrl.wLength) > 2) {
  85944. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  85945. + return;
  85946. + }
  85947. + /** @todo check for EP stall */
  85948. + *status = ep->stopped;
  85949. + break;
  85950. + }
  85951. + pcd->ep0_pending = 1;
  85952. + ep0->dwc_ep.start_xfer_buff = (uint8_t *) status;
  85953. + ep0->dwc_ep.xfer_buff = (uint8_t *) status;
  85954. + ep0->dwc_ep.dma_addr = pcd->status_buf_dma_handle;
  85955. + ep0->dwc_ep.xfer_len = 2;
  85956. + ep0->dwc_ep.xfer_count = 0;
  85957. + ep0->dwc_ep.total_len = ep0->dwc_ep.xfer_len;
  85958. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd), &ep0->dwc_ep);
  85959. +}
  85960. +
  85961. +/**
  85962. + * This function process the SET_FEATURE Setup Commands.
  85963. + */
  85964. +static inline void do_set_feature(dwc_otg_pcd_t * pcd)
  85965. +{
  85966. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  85967. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  85968. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  85969. + dwc_otg_pcd_ep_t *ep = 0;
  85970. + int32_t otg_cap_param = core_if->core_params->otg_cap;
  85971. + gotgctl_data_t gotgctl = {.d32 = 0 };
  85972. +
  85973. + DWC_DEBUGPL(DBG_PCD, "SET_FEATURE:%02x.%02x v%04x i%04x l%04x\n",
  85974. + ctrl.bmRequestType, ctrl.bRequest,
  85975. + UGETW(ctrl.wValue), UGETW(ctrl.wIndex),
  85976. + UGETW(ctrl.wLength));
  85977. + DWC_DEBUGPL(DBG_PCD, "otg_cap=%d\n", otg_cap_param);
  85978. +
  85979. + switch (UT_GET_RECIPIENT(ctrl.bmRequestType)) {
  85980. + case UT_DEVICE:
  85981. + switch (UGETW(ctrl.wValue)) {
  85982. + case UF_DEVICE_REMOTE_WAKEUP:
  85983. + pcd->remote_wakeup_enable = 1;
  85984. + break;
  85985. +
  85986. + case UF_TEST_MODE:
  85987. + /* Setup the Test Mode tasklet to do the Test
  85988. + * Packet generation after the SETUP Status
  85989. + * phase has completed. */
  85990. +
  85991. + /** @todo This has not been tested since the
  85992. + * tasklet struct was put into the PCD
  85993. + * struct! */
  85994. + pcd->test_mode = UGETW(ctrl.wIndex) >> 8;
  85995. + DWC_TASK_SCHEDULE(pcd->test_mode_tasklet);
  85996. + break;
  85997. +
  85998. + case UF_DEVICE_B_HNP_ENABLE:
  85999. + DWC_DEBUGPL(DBG_PCDV,
  86000. + "SET_FEATURE: USB_DEVICE_B_HNP_ENABLE\n");
  86001. +
  86002. + /* dev may initiate HNP */
  86003. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE) {
  86004. + pcd->b_hnp_enable = 1;
  86005. + dwc_otg_pcd_update_otg(pcd, 0);
  86006. + DWC_DEBUGPL(DBG_PCD, "Request B HNP\n");
  86007. + /**@todo Is the gotgctl.devhnpen cleared
  86008. + * by a USB Reset? */
  86009. + gotgctl.b.devhnpen = 1;
  86010. + gotgctl.b.hnpreq = 1;
  86011. + DWC_WRITE_REG32(&global_regs->gotgctl,
  86012. + gotgctl.d32);
  86013. + } else {
  86014. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  86015. + return;
  86016. + }
  86017. + break;
  86018. +
  86019. + case UF_DEVICE_A_HNP_SUPPORT:
  86020. + /* RH port supports HNP */
  86021. + DWC_DEBUGPL(DBG_PCDV,
  86022. + "SET_FEATURE: USB_DEVICE_A_HNP_SUPPORT\n");
  86023. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE) {
  86024. + pcd->a_hnp_support = 1;
  86025. + dwc_otg_pcd_update_otg(pcd, 0);
  86026. + } else {
  86027. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  86028. + return;
  86029. + }
  86030. + break;
  86031. +
  86032. + case UF_DEVICE_A_ALT_HNP_SUPPORT:
  86033. + /* other RH port does */
  86034. + DWC_DEBUGPL(DBG_PCDV,
  86035. + "SET_FEATURE: USB_DEVICE_A_ALT_HNP_SUPPORT\n");
  86036. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE) {
  86037. + pcd->a_alt_hnp_support = 1;
  86038. + dwc_otg_pcd_update_otg(pcd, 0);
  86039. + } else {
  86040. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  86041. + return;
  86042. + }
  86043. + break;
  86044. +
  86045. + default:
  86046. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  86047. + return;
  86048. +
  86049. + }
  86050. + do_setup_in_status_phase(pcd);
  86051. + break;
  86052. +
  86053. + case UT_INTERFACE:
  86054. + do_gadget_setup(pcd, &ctrl);
  86055. + break;
  86056. +
  86057. + case UT_ENDPOINT:
  86058. + if (UGETW(ctrl.wValue) == UF_ENDPOINT_HALT) {
  86059. + ep = get_ep_by_addr(pcd, UGETW(ctrl.wIndex));
  86060. + if (ep == 0) {
  86061. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  86062. + return;
  86063. + }
  86064. + ep->stopped = 1;
  86065. + dwc_otg_ep_set_stall(core_if, &ep->dwc_ep);
  86066. + }
  86067. + do_setup_in_status_phase(pcd);
  86068. + break;
  86069. + }
  86070. +}
  86071. +
  86072. +/**
  86073. + * This function process the CLEAR_FEATURE Setup Commands.
  86074. + */
  86075. +static inline void do_clear_feature(dwc_otg_pcd_t * pcd)
  86076. +{
  86077. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  86078. + dwc_otg_pcd_ep_t *ep = 0;
  86079. +
  86080. + DWC_DEBUGPL(DBG_PCD,
  86081. + "CLEAR_FEATURE:%02x.%02x v%04x i%04x l%04x\n",
  86082. + ctrl.bmRequestType, ctrl.bRequest,
  86083. + UGETW(ctrl.wValue), UGETW(ctrl.wIndex),
  86084. + UGETW(ctrl.wLength));
  86085. +
  86086. + switch (UT_GET_RECIPIENT(ctrl.bmRequestType)) {
  86087. + case UT_DEVICE:
  86088. + switch (UGETW(ctrl.wValue)) {
  86089. + case UF_DEVICE_REMOTE_WAKEUP:
  86090. + pcd->remote_wakeup_enable = 0;
  86091. + break;
  86092. +
  86093. + case UF_TEST_MODE:
  86094. + /** @todo Add CLEAR_FEATURE for TEST modes. */
  86095. + break;
  86096. +
  86097. + default:
  86098. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  86099. + return;
  86100. + }
  86101. + do_setup_in_status_phase(pcd);
  86102. + break;
  86103. +
  86104. + case UT_ENDPOINT:
  86105. + ep = get_ep_by_addr(pcd, UGETW(ctrl.wIndex));
  86106. + if (ep == 0) {
  86107. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  86108. + return;
  86109. + }
  86110. +
  86111. + pcd_clear_halt(pcd, ep);
  86112. +
  86113. + break;
  86114. + }
  86115. +}
  86116. +
  86117. +/**
  86118. + * This function process the SET_ADDRESS Setup Commands.
  86119. + */
  86120. +static inline void do_set_address(dwc_otg_pcd_t * pcd)
  86121. +{
  86122. + dwc_otg_dev_if_t *dev_if = GET_CORE_IF(pcd)->dev_if;
  86123. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  86124. +
  86125. + if (ctrl.bmRequestType == UT_DEVICE) {
  86126. + dcfg_data_t dcfg = {.d32 = 0 };
  86127. +
  86128. +#ifdef DEBUG_EP0
  86129. +// DWC_DEBUGPL(DBG_PCDV, "SET_ADDRESS:%d\n", ctrl.wValue);
  86130. +#endif
  86131. + dcfg.b.devaddr = UGETW(ctrl.wValue);
  86132. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dcfg, 0, dcfg.d32);
  86133. + do_setup_in_status_phase(pcd);
  86134. + }
  86135. +}
  86136. +
  86137. +/**
  86138. + * This function processes SETUP commands. In Linux, the USB Command
  86139. + * processing is done in two places - the first being the PCD and the
  86140. + * second in the Gadget Driver (for example, the File-Backed Storage
  86141. + * Gadget Driver).
  86142. + *
  86143. + * <table>
  86144. + * <tr><td>Command </td><td>Driver </td><td>Description</td></tr>
  86145. + *
  86146. + * <tr><td>GET_STATUS </td><td>PCD </td><td>Command is processed as
  86147. + * defined in chapter 9 of the USB 2.0 Specification chapter 9
  86148. + * </td></tr>
  86149. + *
  86150. + * <tr><td>CLEAR_FEATURE </td><td>PCD </td><td>The Device and Endpoint
  86151. + * requests are the ENDPOINT_HALT feature is procesed, all others the
  86152. + * interface requests are ignored.</td></tr>
  86153. + *
  86154. + * <tr><td>SET_FEATURE </td><td>PCD </td><td>The Device and Endpoint
  86155. + * requests are processed by the PCD. Interface requests are passed
  86156. + * to the Gadget Driver.</td></tr>
  86157. + *
  86158. + * <tr><td>SET_ADDRESS </td><td>PCD </td><td>Program the DCFG reg,
  86159. + * with device address received </td></tr>
  86160. + *
  86161. + * <tr><td>GET_DESCRIPTOR </td><td>Gadget Driver </td><td>Return the
  86162. + * requested descriptor</td></tr>
  86163. + *
  86164. + * <tr><td>SET_DESCRIPTOR </td><td>Gadget Driver </td><td>Optional -
  86165. + * not implemented by any of the existing Gadget Drivers.</td></tr>
  86166. + *
  86167. + * <tr><td>SET_CONFIGURATION </td><td>Gadget Driver </td><td>Disable
  86168. + * all EPs and enable EPs for new configuration.</td></tr>
  86169. + *
  86170. + * <tr><td>GET_CONFIGURATION </td><td>Gadget Driver </td><td>Return
  86171. + * the current configuration</td></tr>
  86172. + *
  86173. + * <tr><td>SET_INTERFACE </td><td>Gadget Driver </td><td>Disable all
  86174. + * EPs and enable EPs for new configuration.</td></tr>
  86175. + *
  86176. + * <tr><td>GET_INTERFACE </td><td>Gadget Driver </td><td>Return the
  86177. + * current interface.</td></tr>
  86178. + *
  86179. + * <tr><td>SYNC_FRAME </td><td>PCD </td><td>Display debug
  86180. + * message.</td></tr>
  86181. + * </table>
  86182. + *
  86183. + * When the SETUP Phase Done interrupt occurs, the PCD SETUP commands are
  86184. + * processed by pcd_setup. Calling the Function Driver's setup function from
  86185. + * pcd_setup processes the gadget SETUP commands.
  86186. + */
  86187. +static inline void pcd_setup(dwc_otg_pcd_t * pcd)
  86188. +{
  86189. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  86190. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  86191. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  86192. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  86193. +
  86194. + deptsiz0_data_t doeptsize0 = {.d32 = 0 };
  86195. +
  86196. +#ifdef DWC_UTE_CFI
  86197. + int retval = 0;
  86198. + struct cfi_usb_ctrlrequest cfi_req;
  86199. +#endif
  86200. +
  86201. + doeptsize0.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[0]->doeptsiz);
  86202. +
  86203. + /** In BDMA more then 1 setup packet is not supported till 3.00a */
  86204. + if (core_if->dma_enable && core_if->dma_desc_enable == 0
  86205. + && (doeptsize0.b.supcnt < 2)
  86206. + && (core_if->snpsid < OTG_CORE_REV_2_94a)) {
  86207. + DWC_ERROR
  86208. + ("\n\n----------- CANNOT handle > 1 setup packet in DMA mode\n\n");
  86209. + }
  86210. + if ((core_if->snpsid >= OTG_CORE_REV_3_00a)
  86211. + && (core_if->dma_enable == 1) && (core_if->dma_desc_enable == 0)) {
  86212. + ctrl =
  86213. + (pcd->setup_pkt +
  86214. + (3 - doeptsize0.b.supcnt - 1 +
  86215. + ep0->dwc_ep.stp_rollover))->req;
  86216. + }
  86217. +#ifdef DEBUG_EP0
  86218. + DWC_DEBUGPL(DBG_PCD, "SETUP %02x.%02x v%04x i%04x l%04x\n",
  86219. + ctrl.bmRequestType, ctrl.bRequest,
  86220. + UGETW(ctrl.wValue), UGETW(ctrl.wIndex),
  86221. + UGETW(ctrl.wLength));
  86222. +#endif
  86223. +
  86224. + /* Clean up the request queue */
  86225. + dwc_otg_request_nuke(ep0);
  86226. + ep0->stopped = 0;
  86227. +
  86228. + if (ctrl.bmRequestType & UE_DIR_IN) {
  86229. + ep0->dwc_ep.is_in = 1;
  86230. + pcd->ep0state = EP0_IN_DATA_PHASE;
  86231. + } else {
  86232. + ep0->dwc_ep.is_in = 0;
  86233. + pcd->ep0state = EP0_OUT_DATA_PHASE;
  86234. + }
  86235. +
  86236. + if (UGETW(ctrl.wLength) == 0) {
  86237. + ep0->dwc_ep.is_in = 1;
  86238. + pcd->ep0state = EP0_IN_STATUS_PHASE;
  86239. + }
  86240. +
  86241. + if (UT_GET_TYPE(ctrl.bmRequestType) != UT_STANDARD) {
  86242. +
  86243. +#ifdef DWC_UTE_CFI
  86244. + DWC_MEMCPY(&cfi_req, &ctrl, sizeof(usb_device_request_t));
  86245. +
  86246. + //printk(KERN_ALERT "CFI: req_type=0x%02x; req=0x%02x\n",
  86247. + ctrl.bRequestType, ctrl.bRequest);
  86248. + if (UT_GET_TYPE(cfi_req.bRequestType) == UT_VENDOR) {
  86249. + if (cfi_req.bRequest > 0xB0 && cfi_req.bRequest < 0xBF) {
  86250. + retval = cfi_setup(pcd, &cfi_req);
  86251. + if (retval < 0) {
  86252. + ep0_do_stall(pcd, retval);
  86253. + pcd->ep0_pending = 0;
  86254. + return;
  86255. + }
  86256. +
  86257. + /* if need gadget setup then call it and check the retval */
  86258. + if (pcd->cfi->need_gadget_att) {
  86259. + retval =
  86260. + cfi_gadget_setup(pcd,
  86261. + &pcd->
  86262. + cfi->ctrl_req);
  86263. + if (retval < 0) {
  86264. + pcd->ep0_pending = 0;
  86265. + return;
  86266. + }
  86267. + }
  86268. +
  86269. + if (pcd->cfi->need_status_in_complete) {
  86270. + do_setup_in_status_phase(pcd);
  86271. + }
  86272. + return;
  86273. + }
  86274. + }
  86275. +#endif
  86276. +
  86277. + /* handle non-standard (class/vendor) requests in the gadget driver */
  86278. + do_gadget_setup(pcd, &ctrl);
  86279. + return;
  86280. + }
  86281. +
  86282. + /** @todo NGS: Handle bad setup packet? */
  86283. +
  86284. +///////////////////////////////////////////
  86285. +//// --- Standard Request handling --- ////
  86286. +
  86287. + switch (ctrl.bRequest) {
  86288. + case UR_GET_STATUS:
  86289. + do_get_status(pcd);
  86290. + break;
  86291. +
  86292. + case UR_CLEAR_FEATURE:
  86293. + do_clear_feature(pcd);
  86294. + break;
  86295. +
  86296. + case UR_SET_FEATURE:
  86297. + do_set_feature(pcd);
  86298. + break;
  86299. +
  86300. + case UR_SET_ADDRESS:
  86301. + do_set_address(pcd);
  86302. + break;
  86303. +
  86304. + case UR_SET_INTERFACE:
  86305. + case UR_SET_CONFIG:
  86306. +// _pcd->request_config = 1; /* Configuration changed */
  86307. + do_gadget_setup(pcd, &ctrl);
  86308. + break;
  86309. +
  86310. + case UR_SYNCH_FRAME:
  86311. + do_gadget_setup(pcd, &ctrl);
  86312. + break;
  86313. +
  86314. + default:
  86315. + /* Call the Gadget Driver's setup functions */
  86316. + do_gadget_setup(pcd, &ctrl);
  86317. + break;
  86318. + }
  86319. +}
  86320. +
  86321. +/**
  86322. + * This function completes the ep0 control transfer.
  86323. + */
  86324. +static int32_t ep0_complete_request(dwc_otg_pcd_ep_t * ep)
  86325. +{
  86326. + dwc_otg_core_if_t *core_if = GET_CORE_IF(ep->pcd);
  86327. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  86328. + dwc_otg_dev_in_ep_regs_t *in_ep_regs =
  86329. + dev_if->in_ep_regs[ep->dwc_ep.num];
  86330. +#ifdef DEBUG_EP0
  86331. + dwc_otg_dev_out_ep_regs_t *out_ep_regs =
  86332. + dev_if->out_ep_regs[ep->dwc_ep.num];
  86333. +#endif
  86334. + deptsiz0_data_t deptsiz;
  86335. + dev_dma_desc_sts_t desc_sts;
  86336. + dwc_otg_pcd_request_t *req;
  86337. + int is_last = 0;
  86338. + dwc_otg_pcd_t *pcd = ep->pcd;
  86339. +
  86340. +#ifdef DWC_UTE_CFI
  86341. + struct cfi_usb_ctrlrequest *ctrlreq;
  86342. + int retval = -DWC_E_NOT_SUPPORTED;
  86343. +#endif
  86344. +
  86345. + desc_sts.b.bytes = 0;
  86346. +
  86347. + if (pcd->ep0_pending && DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  86348. + if (ep->dwc_ep.is_in) {
  86349. +#ifdef DEBUG_EP0
  86350. + DWC_DEBUGPL(DBG_PCDV, "Do setup OUT status phase\n");
  86351. +#endif
  86352. + do_setup_out_status_phase(pcd);
  86353. + } else {
  86354. +#ifdef DEBUG_EP0
  86355. + DWC_DEBUGPL(DBG_PCDV, "Do setup IN status phase\n");
  86356. +#endif
  86357. +
  86358. +#ifdef DWC_UTE_CFI
  86359. + ctrlreq = &pcd->cfi->ctrl_req;
  86360. +
  86361. + if (UT_GET_TYPE(ctrlreq->bRequestType) == UT_VENDOR) {
  86362. + if (ctrlreq->bRequest > 0xB0
  86363. + && ctrlreq->bRequest < 0xBF) {
  86364. +
  86365. + /* Return if the PCD failed to handle the request */
  86366. + if ((retval =
  86367. + pcd->cfi->ops.
  86368. + ctrl_write_complete(pcd->cfi,
  86369. + pcd)) < 0) {
  86370. + CFI_INFO
  86371. + ("ERROR setting a new value in the PCD(%d)\n",
  86372. + retval);
  86373. + ep0_do_stall(pcd, retval);
  86374. + pcd->ep0_pending = 0;
  86375. + return 0;
  86376. + }
  86377. +
  86378. + /* If the gadget needs to be notified on the request */
  86379. + if (pcd->cfi->need_gadget_att == 1) {
  86380. + //retval = do_gadget_setup(pcd, &pcd->cfi->ctrl_req);
  86381. + retval =
  86382. + cfi_gadget_setup(pcd,
  86383. + &pcd->cfi->
  86384. + ctrl_req);
  86385. +
  86386. + /* Return from the function if the gadget failed to process
  86387. + * the request properly - this should never happen !!!
  86388. + */
  86389. + if (retval < 0) {
  86390. + CFI_INFO
  86391. + ("ERROR setting a new value in the gadget(%d)\n",
  86392. + retval);
  86393. + pcd->ep0_pending = 0;
  86394. + return 0;
  86395. + }
  86396. + }
  86397. +
  86398. + CFI_INFO("%s: RETVAL=%d\n", __func__,
  86399. + retval);
  86400. + /* If we hit here then the PCD and the gadget has properly
  86401. + * handled the request - so send the ZLP IN to the host.
  86402. + */
  86403. + /* @todo: MAS - decide whether we need to start the setup
  86404. + * stage based on the need_setup value of the cfi object
  86405. + */
  86406. + do_setup_in_status_phase(pcd);
  86407. + pcd->ep0_pending = 0;
  86408. + return 1;
  86409. + }
  86410. + }
  86411. +#endif
  86412. +
  86413. + do_setup_in_status_phase(pcd);
  86414. + }
  86415. + pcd->ep0_pending = 0;
  86416. + return 1;
  86417. + }
  86418. +
  86419. + if (DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  86420. + return 0;
  86421. + }
  86422. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  86423. +
  86424. + if (pcd->ep0state == EP0_OUT_STATUS_PHASE
  86425. + || pcd->ep0state == EP0_IN_STATUS_PHASE) {
  86426. + is_last = 1;
  86427. + } else if (ep->dwc_ep.is_in) {
  86428. + deptsiz.d32 = DWC_READ_REG32(&in_ep_regs->dieptsiz);
  86429. + if (core_if->dma_desc_enable != 0)
  86430. + desc_sts = dev_if->in_desc_addr->status;
  86431. +#ifdef DEBUG_EP0
  86432. + DWC_DEBUGPL(DBG_PCDV, "%d len=%d xfersize=%d pktcnt=%d\n",
  86433. + ep->dwc_ep.num, ep->dwc_ep.xfer_len,
  86434. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  86435. +#endif
  86436. +
  86437. + if (((core_if->dma_desc_enable == 0)
  86438. + && (deptsiz.b.xfersize == 0))
  86439. + || ((core_if->dma_desc_enable != 0)
  86440. + && (desc_sts.b.bytes == 0))) {
  86441. + req->actual = ep->dwc_ep.xfer_count;
  86442. + /* Is a Zero Len Packet needed? */
  86443. + if (req->sent_zlp) {
  86444. +#ifdef DEBUG_EP0
  86445. + DWC_DEBUGPL(DBG_PCD, "Setup Rx ZLP\n");
  86446. +#endif
  86447. + req->sent_zlp = 0;
  86448. + }
  86449. + do_setup_out_status_phase(pcd);
  86450. + }
  86451. + } else {
  86452. + /* ep0-OUT */
  86453. +#ifdef DEBUG_EP0
  86454. + deptsiz.d32 = DWC_READ_REG32(&out_ep_regs->doeptsiz);
  86455. + DWC_DEBUGPL(DBG_PCDV, "%d len=%d xsize=%d pktcnt=%d\n",
  86456. + ep->dwc_ep.num, ep->dwc_ep.xfer_len,
  86457. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  86458. +#endif
  86459. + req->actual = ep->dwc_ep.xfer_count;
  86460. +
  86461. + /* Is a Zero Len Packet needed? */
  86462. + if (req->sent_zlp) {
  86463. +#ifdef DEBUG_EP0
  86464. + DWC_DEBUGPL(DBG_PCDV, "Setup Tx ZLP\n");
  86465. +#endif
  86466. + req->sent_zlp = 0;
  86467. + }
  86468. + /* For older cores do setup in status phase in Slave/BDMA modes,
  86469. + * starting from 3.00 do that only in slave, and for DMA modes
  86470. + * just re-enable ep 0 OUT here*/
  86471. + if (core_if->dma_enable == 0
  86472. + || (core_if->dma_desc_enable == 0
  86473. + && core_if->snpsid <= OTG_CORE_REV_2_94a)) {
  86474. + do_setup_in_status_phase(pcd);
  86475. + } else if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  86476. + DWC_DEBUGPL(DBG_PCDV,
  86477. + "Enable out ep before in status phase\n");
  86478. + ep0_out_start(core_if, pcd);
  86479. + }
  86480. + }
  86481. +
  86482. + /* Complete the request */
  86483. + if (is_last) {
  86484. + dwc_otg_request_done(ep, req, 0);
  86485. + ep->dwc_ep.start_xfer_buff = 0;
  86486. + ep->dwc_ep.xfer_buff = 0;
  86487. + ep->dwc_ep.xfer_len = 0;
  86488. + return 1;
  86489. + }
  86490. + return 0;
  86491. +}
  86492. +
  86493. +#ifdef DWC_UTE_CFI
  86494. +/**
  86495. + * This function calculates traverses all the CFI DMA descriptors and
  86496. + * and accumulates the bytes that are left to be transfered.
  86497. + *
  86498. + * @return The total bytes left to transfered, or a negative value as failure
  86499. + */
  86500. +static inline int cfi_calc_desc_residue(dwc_otg_pcd_ep_t * ep)
  86501. +{
  86502. + int32_t ret = 0;
  86503. + int i;
  86504. + struct dwc_otg_dma_desc *ddesc = NULL;
  86505. + struct cfi_ep *cfiep;
  86506. +
  86507. + /* See if the pcd_ep has its respective cfi_ep mapped */
  86508. + cfiep = get_cfi_ep_by_pcd_ep(ep->pcd->cfi, ep);
  86509. + if (!cfiep) {
  86510. + CFI_INFO("%s: Failed to find ep\n", __func__);
  86511. + return -1;
  86512. + }
  86513. +
  86514. + ddesc = ep->dwc_ep.descs;
  86515. +
  86516. + for (i = 0; (i < cfiep->desc_count) && (i < MAX_DMA_DESCS_PER_EP); i++) {
  86517. +
  86518. +#if defined(PRINT_CFI_DMA_DESCS)
  86519. + print_desc(ddesc, ep->ep.name, i);
  86520. +#endif
  86521. + ret += ddesc->status.b.bytes;
  86522. + ddesc++;
  86523. + }
  86524. +
  86525. + if (ret)
  86526. + CFI_INFO("!!!!!!!!!! WARNING (%s) - residue=%d\n", __func__,
  86527. + ret);
  86528. +
  86529. + return ret;
  86530. +}
  86531. +#endif
  86532. +
  86533. +/**
  86534. + * This function completes the request for the EP. If there are
  86535. + * additional requests for the EP in the queue they will be started.
  86536. + */
  86537. +static void complete_ep(dwc_otg_pcd_ep_t * ep)
  86538. +{
  86539. + dwc_otg_core_if_t *core_if = GET_CORE_IF(ep->pcd);
  86540. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  86541. + dwc_otg_dev_in_ep_regs_t *in_ep_regs =
  86542. + dev_if->in_ep_regs[ep->dwc_ep.num];
  86543. + deptsiz_data_t deptsiz;
  86544. + dev_dma_desc_sts_t desc_sts;
  86545. + dwc_otg_pcd_request_t *req = 0;
  86546. + dwc_otg_dev_dma_desc_t *dma_desc;
  86547. + uint32_t byte_count = 0;
  86548. + int is_last = 0;
  86549. + int i;
  86550. +
  86551. + DWC_DEBUGPL(DBG_PCDV, "%s() %d-%s\n", __func__, ep->dwc_ep.num,
  86552. + (ep->dwc_ep.is_in ? "IN" : "OUT"));
  86553. +
  86554. + /* Get any pending requests */
  86555. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  86556. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  86557. + if (!req) {
  86558. + DWC_PRINTF("complete_ep 0x%p, req = NULL!\n", ep);
  86559. + return;
  86560. + }
  86561. + } else {
  86562. + DWC_PRINTF("complete_ep 0x%p, ep->queue empty!\n", ep);
  86563. + return;
  86564. + }
  86565. +
  86566. + DWC_DEBUGPL(DBG_PCD, "Requests %d\n", ep->pcd->request_pending);
  86567. +
  86568. + if (ep->dwc_ep.is_in) {
  86569. + deptsiz.d32 = DWC_READ_REG32(&in_ep_regs->dieptsiz);
  86570. +
  86571. + if (core_if->dma_enable) {
  86572. + if (core_if->dma_desc_enable == 0) {
  86573. + if (deptsiz.b.xfersize == 0
  86574. + && deptsiz.b.pktcnt == 0) {
  86575. + byte_count =
  86576. + ep->dwc_ep.xfer_len -
  86577. + ep->dwc_ep.xfer_count;
  86578. +
  86579. + ep->dwc_ep.xfer_buff += byte_count;
  86580. + ep->dwc_ep.dma_addr += byte_count;
  86581. + ep->dwc_ep.xfer_count += byte_count;
  86582. +
  86583. + DWC_DEBUGPL(DBG_PCDV,
  86584. + "%d-%s len=%d xfersize=%d pktcnt=%d\n",
  86585. + ep->dwc_ep.num,
  86586. + (ep->dwc_ep.
  86587. + is_in ? "IN" : "OUT"),
  86588. + ep->dwc_ep.xfer_len,
  86589. + deptsiz.b.xfersize,
  86590. + deptsiz.b.pktcnt);
  86591. +
  86592. + if (ep->dwc_ep.xfer_len <
  86593. + ep->dwc_ep.total_len) {
  86594. + dwc_otg_ep_start_transfer
  86595. + (core_if, &ep->dwc_ep);
  86596. + } else if (ep->dwc_ep.sent_zlp) {
  86597. + /*
  86598. + * This fragment of code should initiate 0
  86599. + * length transfer in case if it is queued
  86600. + * a transfer with size divisible to EPs max
  86601. + * packet size and with usb_request zero field
  86602. + * is set, which means that after data is transfered,
  86603. + * it is also should be transfered
  86604. + * a 0 length packet at the end. For Slave and
  86605. + * Buffer DMA modes in this case SW has
  86606. + * to initiate 2 transfers one with transfer size,
  86607. + * and the second with 0 size. For Descriptor
  86608. + * DMA mode SW is able to initiate a transfer,
  86609. + * which will handle all the packets including
  86610. + * the last 0 length.
  86611. + */
  86612. + ep->dwc_ep.sent_zlp = 0;
  86613. + dwc_otg_ep_start_zl_transfer
  86614. + (core_if, &ep->dwc_ep);
  86615. + } else {
  86616. + is_last = 1;
  86617. + }
  86618. + } else {
  86619. + if (ep->dwc_ep.type ==
  86620. + DWC_OTG_EP_TYPE_ISOC) {
  86621. + req->actual = 0;
  86622. + dwc_otg_request_done(ep, req, 0);
  86623. +
  86624. + ep->dwc_ep.start_xfer_buff = 0;
  86625. + ep->dwc_ep.xfer_buff = 0;
  86626. + ep->dwc_ep.xfer_len = 0;
  86627. +
  86628. + /* If there is a request in the queue start it. */
  86629. + start_next_request(ep);
  86630. + } else
  86631. + DWC_WARN
  86632. + ("Incomplete transfer (%d - %s [siz=%d pkt=%d])\n",
  86633. + ep->dwc_ep.num,
  86634. + (ep->dwc_ep.is_in ? "IN" : "OUT"),
  86635. + deptsiz.b.xfersize,
  86636. + deptsiz.b.pktcnt);
  86637. + }
  86638. + } else {
  86639. + dma_desc = ep->dwc_ep.desc_addr;
  86640. + byte_count = 0;
  86641. + ep->dwc_ep.sent_zlp = 0;
  86642. +
  86643. +#ifdef DWC_UTE_CFI
  86644. + CFI_INFO("%s: BUFFER_MODE=%d\n", __func__,
  86645. + ep->dwc_ep.buff_mode);
  86646. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  86647. + int residue;
  86648. +
  86649. + residue = cfi_calc_desc_residue(ep);
  86650. + if (residue < 0)
  86651. + return;
  86652. +
  86653. + byte_count = residue;
  86654. + } else {
  86655. +#endif
  86656. + for (i = 0; i < ep->dwc_ep.desc_cnt;
  86657. + ++i) {
  86658. + desc_sts = dma_desc->status;
  86659. + byte_count += desc_sts.b.bytes;
  86660. + dma_desc++;
  86661. + }
  86662. +#ifdef DWC_UTE_CFI
  86663. + }
  86664. +#endif
  86665. + if (byte_count == 0) {
  86666. + ep->dwc_ep.xfer_count =
  86667. + ep->dwc_ep.total_len;
  86668. + is_last = 1;
  86669. + } else {
  86670. + DWC_WARN("Incomplete transfer\n");
  86671. + }
  86672. + }
  86673. + } else {
  86674. + if (deptsiz.b.xfersize == 0 && deptsiz.b.pktcnt == 0) {
  86675. + DWC_DEBUGPL(DBG_PCDV,
  86676. + "%d-%s len=%d xfersize=%d pktcnt=%d\n",
  86677. + ep->dwc_ep.num,
  86678. + ep->dwc_ep.is_in ? "IN" : "OUT",
  86679. + ep->dwc_ep.xfer_len,
  86680. + deptsiz.b.xfersize,
  86681. + deptsiz.b.pktcnt);
  86682. +
  86683. + /* Check if the whole transfer was completed,
  86684. + * if no, setup transfer for next portion of data
  86685. + */
  86686. + if (ep->dwc_ep.xfer_len < ep->dwc_ep.total_len) {
  86687. + dwc_otg_ep_start_transfer(core_if,
  86688. + &ep->dwc_ep);
  86689. + } else if (ep->dwc_ep.sent_zlp) {
  86690. + /*
  86691. + * This fragment of code should initiate 0
  86692. + * length trasfer in case if it is queued
  86693. + * a trasfer with size divisible to EPs max
  86694. + * packet size and with usb_request zero field
  86695. + * is set, which means that after data is transfered,
  86696. + * it is also should be transfered
  86697. + * a 0 length packet at the end. For Slave and
  86698. + * Buffer DMA modes in this case SW has
  86699. + * to initiate 2 transfers one with transfer size,
  86700. + * and the second with 0 size. For Desriptor
  86701. + * DMA mode SW is able to initiate a transfer,
  86702. + * which will handle all the packets including
  86703. + * the last 0 legth.
  86704. + */
  86705. + ep->dwc_ep.sent_zlp = 0;
  86706. + dwc_otg_ep_start_zl_transfer(core_if,
  86707. + &ep->dwc_ep);
  86708. + } else {
  86709. + is_last = 1;
  86710. + }
  86711. + } else {
  86712. + DWC_WARN
  86713. + ("Incomplete transfer (%d-%s [siz=%d pkt=%d])\n",
  86714. + ep->dwc_ep.num,
  86715. + (ep->dwc_ep.is_in ? "IN" : "OUT"),
  86716. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  86717. + }
  86718. + }
  86719. + } else {
  86720. + dwc_otg_dev_out_ep_regs_t *out_ep_regs =
  86721. + dev_if->out_ep_regs[ep->dwc_ep.num];
  86722. + desc_sts.d32 = 0;
  86723. + if (core_if->dma_enable) {
  86724. + if (core_if->dma_desc_enable) {
  86725. + dma_desc = ep->dwc_ep.desc_addr;
  86726. + byte_count = 0;
  86727. + ep->dwc_ep.sent_zlp = 0;
  86728. +
  86729. +#ifdef DWC_UTE_CFI
  86730. + CFI_INFO("%s: BUFFER_MODE=%d\n", __func__,
  86731. + ep->dwc_ep.buff_mode);
  86732. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  86733. + int residue;
  86734. + residue = cfi_calc_desc_residue(ep);
  86735. + if (residue < 0)
  86736. + return;
  86737. + byte_count = residue;
  86738. + } else {
  86739. +#endif
  86740. +
  86741. + for (i = 0; i < ep->dwc_ep.desc_cnt;
  86742. + ++i) {
  86743. + desc_sts = dma_desc->status;
  86744. + byte_count += desc_sts.b.bytes;
  86745. + dma_desc++;
  86746. + }
  86747. +
  86748. +#ifdef DWC_UTE_CFI
  86749. + }
  86750. +#endif
  86751. + /* Checking for interrupt Out transfers with not
  86752. + * dword aligned mps sizes
  86753. + */
  86754. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_INTR &&
  86755. + (ep->dwc_ep.maxpacket%4)) {
  86756. + ep->dwc_ep.xfer_count =
  86757. + ep->dwc_ep.total_len - byte_count;
  86758. + if ((ep->dwc_ep.xfer_len %
  86759. + ep->dwc_ep.maxpacket)
  86760. + && (ep->dwc_ep.xfer_len /
  86761. + ep->dwc_ep.maxpacket <
  86762. + MAX_DMA_DESC_CNT))
  86763. + ep->dwc_ep.xfer_len -=
  86764. + (ep->dwc_ep.desc_cnt -
  86765. + 1) * ep->dwc_ep.maxpacket +
  86766. + ep->dwc_ep.xfer_len %
  86767. + ep->dwc_ep.maxpacket;
  86768. + else
  86769. + ep->dwc_ep.xfer_len -=
  86770. + ep->dwc_ep.desc_cnt *
  86771. + ep->dwc_ep.maxpacket;
  86772. + if (ep->dwc_ep.xfer_len > 0) {
  86773. + dwc_otg_ep_start_transfer
  86774. + (core_if, &ep->dwc_ep);
  86775. + } else {
  86776. + is_last = 1;
  86777. + }
  86778. + } else {
  86779. + ep->dwc_ep.xfer_count =
  86780. + ep->dwc_ep.total_len - byte_count +
  86781. + ((4 -
  86782. + (ep->dwc_ep.
  86783. + total_len & 0x3)) & 0x3);
  86784. + is_last = 1;
  86785. + }
  86786. + } else {
  86787. + deptsiz.d32 = 0;
  86788. + deptsiz.d32 =
  86789. + DWC_READ_REG32(&out_ep_regs->doeptsiz);
  86790. +
  86791. + byte_count = (ep->dwc_ep.xfer_len -
  86792. + ep->dwc_ep.xfer_count -
  86793. + deptsiz.b.xfersize);
  86794. + ep->dwc_ep.xfer_buff += byte_count;
  86795. + ep->dwc_ep.dma_addr += byte_count;
  86796. + ep->dwc_ep.xfer_count += byte_count;
  86797. +
  86798. + /* Check if the whole transfer was completed,
  86799. + * if no, setup transfer for next portion of data
  86800. + */
  86801. + if (ep->dwc_ep.xfer_len < ep->dwc_ep.total_len) {
  86802. + dwc_otg_ep_start_transfer(core_if,
  86803. + &ep->dwc_ep);
  86804. + } else if (ep->dwc_ep.sent_zlp) {
  86805. + /*
  86806. + * This fragment of code should initiate 0
  86807. + * length trasfer in case if it is queued
  86808. + * a trasfer with size divisible to EPs max
  86809. + * packet size and with usb_request zero field
  86810. + * is set, which means that after data is transfered,
  86811. + * it is also should be transfered
  86812. + * a 0 length packet at the end. For Slave and
  86813. + * Buffer DMA modes in this case SW has
  86814. + * to initiate 2 transfers one with transfer size,
  86815. + * and the second with 0 size. For Desriptor
  86816. + * DMA mode SW is able to initiate a transfer,
  86817. + * which will handle all the packets including
  86818. + * the last 0 legth.
  86819. + */
  86820. + ep->dwc_ep.sent_zlp = 0;
  86821. + dwc_otg_ep_start_zl_transfer(core_if,
  86822. + &ep->dwc_ep);
  86823. + } else {
  86824. + is_last = 1;
  86825. + }
  86826. + }
  86827. + } else {
  86828. + /* Check if the whole transfer was completed,
  86829. + * if no, setup transfer for next portion of data
  86830. + */
  86831. + if (ep->dwc_ep.xfer_len < ep->dwc_ep.total_len) {
  86832. + dwc_otg_ep_start_transfer(core_if, &ep->dwc_ep);
  86833. + } else if (ep->dwc_ep.sent_zlp) {
  86834. + /*
  86835. + * This fragment of code should initiate 0
  86836. + * length transfer in case if it is queued
  86837. + * a transfer with size divisible to EPs max
  86838. + * packet size and with usb_request zero field
  86839. + * is set, which means that after data is transfered,
  86840. + * it is also should be transfered
  86841. + * a 0 length packet at the end. For Slave and
  86842. + * Buffer DMA modes in this case SW has
  86843. + * to initiate 2 transfers one with transfer size,
  86844. + * and the second with 0 size. For Descriptor
  86845. + * DMA mode SW is able to initiate a transfer,
  86846. + * which will handle all the packets including
  86847. + * the last 0 length.
  86848. + */
  86849. + ep->dwc_ep.sent_zlp = 0;
  86850. + dwc_otg_ep_start_zl_transfer(core_if,
  86851. + &ep->dwc_ep);
  86852. + } else {
  86853. + is_last = 1;
  86854. + }
  86855. + }
  86856. +
  86857. + DWC_DEBUGPL(DBG_PCDV,
  86858. + "addr %p, %d-%s len=%d cnt=%d xsize=%d pktcnt=%d\n",
  86859. + &out_ep_regs->doeptsiz, ep->dwc_ep.num,
  86860. + ep->dwc_ep.is_in ? "IN" : "OUT",
  86861. + ep->dwc_ep.xfer_len, ep->dwc_ep.xfer_count,
  86862. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  86863. + }
  86864. +
  86865. + /* Complete the request */
  86866. + if (is_last) {
  86867. +#ifdef DWC_UTE_CFI
  86868. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  86869. + req->actual = ep->dwc_ep.cfi_req_len - byte_count;
  86870. + } else {
  86871. +#endif
  86872. + req->actual = ep->dwc_ep.xfer_count;
  86873. +#ifdef DWC_UTE_CFI
  86874. + }
  86875. +#endif
  86876. + if (req->dw_align_buf) {
  86877. + if (!ep->dwc_ep.is_in) {
  86878. + dwc_memcpy(req->buf, req->dw_align_buf, req->length);
  86879. + }
  86880. + DWC_DMA_FREE(req->length, req->dw_align_buf,
  86881. + req->dw_align_buf_dma);
  86882. + }
  86883. +
  86884. + dwc_otg_request_done(ep, req, 0);
  86885. +
  86886. + ep->dwc_ep.start_xfer_buff = 0;
  86887. + ep->dwc_ep.xfer_buff = 0;
  86888. + ep->dwc_ep.xfer_len = 0;
  86889. +
  86890. + /* If there is a request in the queue start it. */
  86891. + start_next_request(ep);
  86892. + }
  86893. +}
  86894. +
  86895. +#ifdef DWC_EN_ISOC
  86896. +
  86897. +/**
  86898. + * This function BNA interrupt for Isochronous EPs
  86899. + *
  86900. + */
  86901. +static void dwc_otg_pcd_handle_iso_bna(dwc_otg_pcd_ep_t * ep)
  86902. +{
  86903. + dwc_ep_t *dwc_ep = &ep->dwc_ep;
  86904. + volatile uint32_t *addr;
  86905. + depctl_data_t depctl = {.d32 = 0 };
  86906. + dwc_otg_pcd_t *pcd = ep->pcd;
  86907. + dwc_otg_dev_dma_desc_t *dma_desc;
  86908. + int i;
  86909. +
  86910. + dma_desc =
  86911. + dwc_ep->iso_desc_addr + dwc_ep->desc_cnt * (dwc_ep->proc_buf_num);
  86912. +
  86913. + if (dwc_ep->is_in) {
  86914. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  86915. + for (i = 0; i < dwc_ep->desc_cnt; ++i, ++dma_desc) {
  86916. + sts.d32 = dma_desc->status.d32;
  86917. + sts.b_iso_in.bs = BS_HOST_READY;
  86918. + dma_desc->status.d32 = sts.d32;
  86919. + }
  86920. + } else {
  86921. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  86922. + for (i = 0; i < dwc_ep->desc_cnt; ++i, ++dma_desc) {
  86923. + sts.d32 = dma_desc->status.d32;
  86924. + sts.b_iso_out.bs = BS_HOST_READY;
  86925. + dma_desc->status.d32 = sts.d32;
  86926. + }
  86927. + }
  86928. +
  86929. + if (dwc_ep->is_in == 0) {
  86930. + addr =
  86931. + &GET_CORE_IF(pcd)->dev_if->out_ep_regs[dwc_ep->
  86932. + num]->doepctl;
  86933. + } else {
  86934. + addr =
  86935. + &GET_CORE_IF(pcd)->dev_if->in_ep_regs[dwc_ep->num]->diepctl;
  86936. + }
  86937. + depctl.b.epena = 1;
  86938. + DWC_MODIFY_REG32(addr, depctl.d32, depctl.d32);
  86939. +}
  86940. +
  86941. +/**
  86942. + * This function sets latest iso packet information(non-PTI mode)
  86943. + *
  86944. + * @param core_if Programming view of DWC_otg controller.
  86945. + * @param ep The EP to start the transfer on.
  86946. + *
  86947. + */
  86948. +void set_current_pkt_info(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  86949. +{
  86950. + deptsiz_data_t deptsiz = {.d32 = 0 };
  86951. + dma_addr_t dma_addr;
  86952. + uint32_t offset;
  86953. +
  86954. + if (ep->proc_buf_num)
  86955. + dma_addr = ep->dma_addr1;
  86956. + else
  86957. + dma_addr = ep->dma_addr0;
  86958. +
  86959. + if (ep->is_in) {
  86960. + deptsiz.d32 =
  86961. + DWC_READ_REG32(&core_if->dev_if->
  86962. + in_ep_regs[ep->num]->dieptsiz);
  86963. + offset = ep->data_per_frame;
  86964. + } else {
  86965. + deptsiz.d32 =
  86966. + DWC_READ_REG32(&core_if->dev_if->
  86967. + out_ep_regs[ep->num]->doeptsiz);
  86968. + offset =
  86969. + ep->data_per_frame +
  86970. + (0x4 & (0x4 - (ep->data_per_frame & 0x3)));
  86971. + }
  86972. +
  86973. + if (!deptsiz.b.xfersize) {
  86974. + ep->pkt_info[ep->cur_pkt].length = ep->data_per_frame;
  86975. + ep->pkt_info[ep->cur_pkt].offset =
  86976. + ep->cur_pkt_dma_addr - dma_addr;
  86977. + ep->pkt_info[ep->cur_pkt].status = 0;
  86978. + } else {
  86979. + ep->pkt_info[ep->cur_pkt].length = ep->data_per_frame;
  86980. + ep->pkt_info[ep->cur_pkt].offset =
  86981. + ep->cur_pkt_dma_addr - dma_addr;
  86982. + ep->pkt_info[ep->cur_pkt].status = -DWC_E_NO_DATA;
  86983. + }
  86984. + ep->cur_pkt_addr += offset;
  86985. + ep->cur_pkt_dma_addr += offset;
  86986. + ep->cur_pkt++;
  86987. +}
  86988. +
  86989. +/**
  86990. + * This function sets latest iso packet information(DDMA mode)
  86991. + *
  86992. + * @param core_if Programming view of DWC_otg controller.
  86993. + * @param dwc_ep The EP to start the transfer on.
  86994. + *
  86995. + */
  86996. +static void set_ddma_iso_pkts_info(dwc_otg_core_if_t * core_if,
  86997. + dwc_ep_t * dwc_ep)
  86998. +{
  86999. + dwc_otg_dev_dma_desc_t *dma_desc;
  87000. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  87001. + iso_pkt_info_t *iso_packet;
  87002. + uint32_t data_per_desc;
  87003. + uint32_t offset;
  87004. + int i, j;
  87005. +
  87006. + iso_packet = dwc_ep->pkt_info;
  87007. +
  87008. + /** Reinit closed DMA Descriptors*/
  87009. + /** ISO OUT EP */
  87010. + if (dwc_ep->is_in == 0) {
  87011. + dma_desc =
  87012. + dwc_ep->iso_desc_addr +
  87013. + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
  87014. + offset = 0;
  87015. +
  87016. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  87017. + i += dwc_ep->pkt_per_frm) {
  87018. + for (j = 0; j < dwc_ep->pkt_per_frm; ++j) {
  87019. + data_per_desc =
  87020. + ((j + 1) * dwc_ep->maxpacket >
  87021. + dwc_ep->
  87022. + data_per_frame) ? dwc_ep->data_per_frame -
  87023. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  87024. + data_per_desc +=
  87025. + (data_per_desc % 4) ? (4 -
  87026. + data_per_desc %
  87027. + 4) : 0;
  87028. +
  87029. + sts.d32 = dma_desc->status.d32;
  87030. +
  87031. + /* Write status in iso_packet_decsriptor */
  87032. + iso_packet->status =
  87033. + sts.b_iso_out.rxsts +
  87034. + (sts.b_iso_out.bs ^ BS_DMA_DONE);
  87035. + if (iso_packet->status) {
  87036. + iso_packet->status = -DWC_E_NO_DATA;
  87037. + }
  87038. +
  87039. + /* Received data length */
  87040. + if (!sts.b_iso_out.rxbytes) {
  87041. + iso_packet->length =
  87042. + data_per_desc -
  87043. + sts.b_iso_out.rxbytes;
  87044. + } else {
  87045. + iso_packet->length =
  87046. + data_per_desc -
  87047. + sts.b_iso_out.rxbytes + (4 -
  87048. + dwc_ep->data_per_frame
  87049. + % 4);
  87050. + }
  87051. +
  87052. + iso_packet->offset = offset;
  87053. +
  87054. + offset += data_per_desc;
  87055. + dma_desc++;
  87056. + iso_packet++;
  87057. + }
  87058. + }
  87059. +
  87060. + for (j = 0; j < dwc_ep->pkt_per_frm - 1; ++j) {
  87061. + data_per_desc =
  87062. + ((j + 1) * dwc_ep->maxpacket >
  87063. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  87064. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  87065. + data_per_desc +=
  87066. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  87067. +
  87068. + sts.d32 = dma_desc->status.d32;
  87069. +
  87070. + /* Write status in iso_packet_decsriptor */
  87071. + iso_packet->status =
  87072. + sts.b_iso_out.rxsts +
  87073. + (sts.b_iso_out.bs ^ BS_DMA_DONE);
  87074. + if (iso_packet->status) {
  87075. + iso_packet->status = -DWC_E_NO_DATA;
  87076. + }
  87077. +
  87078. + /* Received data length */
  87079. + iso_packet->length =
  87080. + dwc_ep->data_per_frame - sts.b_iso_out.rxbytes;
  87081. +
  87082. + iso_packet->offset = offset;
  87083. +
  87084. + offset += data_per_desc;
  87085. + iso_packet++;
  87086. + dma_desc++;
  87087. + }
  87088. +
  87089. + sts.d32 = dma_desc->status.d32;
  87090. +
  87091. + /* Write status in iso_packet_decsriptor */
  87092. + iso_packet->status =
  87093. + sts.b_iso_out.rxsts + (sts.b_iso_out.bs ^ BS_DMA_DONE);
  87094. + if (iso_packet->status) {
  87095. + iso_packet->status = -DWC_E_NO_DATA;
  87096. + }
  87097. + /* Received data length */
  87098. + if (!sts.b_iso_out.rxbytes) {
  87099. + iso_packet->length =
  87100. + dwc_ep->data_per_frame - sts.b_iso_out.rxbytes;
  87101. + } else {
  87102. + iso_packet->length =
  87103. + dwc_ep->data_per_frame - sts.b_iso_out.rxbytes +
  87104. + (4 - dwc_ep->data_per_frame % 4);
  87105. + }
  87106. +
  87107. + iso_packet->offset = offset;
  87108. + } else {
  87109. +/** ISO IN EP */
  87110. +
  87111. + dma_desc =
  87112. + dwc_ep->iso_desc_addr +
  87113. + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
  87114. +
  87115. + for (i = 0; i < dwc_ep->desc_cnt - 1; i++) {
  87116. + sts.d32 = dma_desc->status.d32;
  87117. +
  87118. + /* Write status in iso packet descriptor */
  87119. + iso_packet->status =
  87120. + sts.b_iso_in.txsts +
  87121. + (sts.b_iso_in.bs ^ BS_DMA_DONE);
  87122. + if (iso_packet->status != 0) {
  87123. + iso_packet->status = -DWC_E_NO_DATA;
  87124. +
  87125. + }
  87126. + /* Bytes has been transfered */
  87127. + iso_packet->length =
  87128. + dwc_ep->data_per_frame - sts.b_iso_in.txbytes;
  87129. +
  87130. + dma_desc++;
  87131. + iso_packet++;
  87132. + }
  87133. +
  87134. + sts.d32 = dma_desc->status.d32;
  87135. + while (sts.b_iso_in.bs == BS_DMA_BUSY) {
  87136. + sts.d32 = dma_desc->status.d32;
  87137. + }
  87138. +
  87139. + /* Write status in iso packet descriptor ??? do be done with ERROR codes */
  87140. + iso_packet->status =
  87141. + sts.b_iso_in.txsts + (sts.b_iso_in.bs ^ BS_DMA_DONE);
  87142. + if (iso_packet->status != 0) {
  87143. + iso_packet->status = -DWC_E_NO_DATA;
  87144. + }
  87145. +
  87146. + /* Bytes has been transfered */
  87147. + iso_packet->length =
  87148. + dwc_ep->data_per_frame - sts.b_iso_in.txbytes;
  87149. + }
  87150. +}
  87151. +
  87152. +/**
  87153. + * This function reinitialize DMA Descriptors for Isochronous transfer
  87154. + *
  87155. + * @param core_if Programming view of DWC_otg controller.
  87156. + * @param dwc_ep The EP to start the transfer on.
  87157. + *
  87158. + */
  87159. +static void reinit_ddma_iso_xfer(dwc_otg_core_if_t * core_if, dwc_ep_t * dwc_ep)
  87160. +{
  87161. + int i, j;
  87162. + dwc_otg_dev_dma_desc_t *dma_desc;
  87163. + dma_addr_t dma_ad;
  87164. + volatile uint32_t *addr;
  87165. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  87166. + uint32_t data_per_desc;
  87167. +
  87168. + if (dwc_ep->is_in == 0) {
  87169. + addr = &core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl;
  87170. + } else {
  87171. + addr = &core_if->dev_if->in_ep_regs[dwc_ep->num]->diepctl;
  87172. + }
  87173. +
  87174. + if (dwc_ep->proc_buf_num == 0) {
  87175. + /** Buffer 0 descriptors setup */
  87176. + dma_ad = dwc_ep->dma_addr0;
  87177. + } else {
  87178. + /** Buffer 1 descriptors setup */
  87179. + dma_ad = dwc_ep->dma_addr1;
  87180. + }
  87181. +
  87182. + /** Reinit closed DMA Descriptors*/
  87183. + /** ISO OUT EP */
  87184. + if (dwc_ep->is_in == 0) {
  87185. + dma_desc =
  87186. + dwc_ep->iso_desc_addr +
  87187. + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
  87188. +
  87189. + sts.b_iso_out.bs = BS_HOST_READY;
  87190. + sts.b_iso_out.rxsts = 0;
  87191. + sts.b_iso_out.l = 0;
  87192. + sts.b_iso_out.sp = 0;
  87193. + sts.b_iso_out.ioc = 0;
  87194. + sts.b_iso_out.pid = 0;
  87195. + sts.b_iso_out.framenum = 0;
  87196. +
  87197. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  87198. + i += dwc_ep->pkt_per_frm) {
  87199. + for (j = 0; j < dwc_ep->pkt_per_frm; ++j) {
  87200. + data_per_desc =
  87201. + ((j + 1) * dwc_ep->maxpacket >
  87202. + dwc_ep->
  87203. + data_per_frame) ? dwc_ep->data_per_frame -
  87204. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  87205. + data_per_desc +=
  87206. + (data_per_desc % 4) ? (4 -
  87207. + data_per_desc %
  87208. + 4) : 0;
  87209. + sts.b_iso_out.rxbytes = data_per_desc;
  87210. + dma_desc->buf = dma_ad;
  87211. + dma_desc->status.d32 = sts.d32;
  87212. +
  87213. + dma_ad += data_per_desc;
  87214. + dma_desc++;
  87215. + }
  87216. + }
  87217. +
  87218. + for (j = 0; j < dwc_ep->pkt_per_frm - 1; ++j) {
  87219. +
  87220. + data_per_desc =
  87221. + ((j + 1) * dwc_ep->maxpacket >
  87222. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  87223. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  87224. + data_per_desc +=
  87225. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  87226. + sts.b_iso_out.rxbytes = data_per_desc;
  87227. +
  87228. + dma_desc->buf = dma_ad;
  87229. + dma_desc->status.d32 = sts.d32;
  87230. +
  87231. + dma_desc++;
  87232. + dma_ad += data_per_desc;
  87233. + }
  87234. +
  87235. + sts.b_iso_out.ioc = 1;
  87236. + sts.b_iso_out.l = dwc_ep->proc_buf_num;
  87237. +
  87238. + data_per_desc =
  87239. + ((j + 1) * dwc_ep->maxpacket >
  87240. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  87241. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  87242. + data_per_desc +=
  87243. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  87244. + sts.b_iso_out.rxbytes = data_per_desc;
  87245. +
  87246. + dma_desc->buf = dma_ad;
  87247. + dma_desc->status.d32 = sts.d32;
  87248. + } else {
  87249. +/** ISO IN EP */
  87250. +
  87251. + dma_desc =
  87252. + dwc_ep->iso_desc_addr +
  87253. + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
  87254. +
  87255. + sts.b_iso_in.bs = BS_HOST_READY;
  87256. + sts.b_iso_in.txsts = 0;
  87257. + sts.b_iso_in.sp = 0;
  87258. + sts.b_iso_in.ioc = 0;
  87259. + sts.b_iso_in.pid = dwc_ep->pkt_per_frm;
  87260. + sts.b_iso_in.framenum = dwc_ep->next_frame;
  87261. + sts.b_iso_in.txbytes = dwc_ep->data_per_frame;
  87262. + sts.b_iso_in.l = 0;
  87263. +
  87264. + for (i = 0; i < dwc_ep->desc_cnt - 1; i++) {
  87265. + dma_desc->buf = dma_ad;
  87266. + dma_desc->status.d32 = sts.d32;
  87267. +
  87268. + sts.b_iso_in.framenum += dwc_ep->bInterval;
  87269. + dma_ad += dwc_ep->data_per_frame;
  87270. + dma_desc++;
  87271. + }
  87272. +
  87273. + sts.b_iso_in.ioc = 1;
  87274. + sts.b_iso_in.l = dwc_ep->proc_buf_num;
  87275. +
  87276. + dma_desc->buf = dma_ad;
  87277. + dma_desc->status.d32 = sts.d32;
  87278. +
  87279. + dwc_ep->next_frame =
  87280. + sts.b_iso_in.framenum + dwc_ep->bInterval * 1;
  87281. + }
  87282. + dwc_ep->proc_buf_num = (dwc_ep->proc_buf_num ^ 1) & 0x1;
  87283. +}
  87284. +
  87285. +/**
  87286. + * This function is to handle Iso EP transfer complete interrupt
  87287. + * in case Iso out packet was dropped
  87288. + *
  87289. + * @param core_if Programming view of DWC_otg controller.
  87290. + * @param dwc_ep The EP for wihich transfer complete was asserted
  87291. + *
  87292. + */
  87293. +static uint32_t handle_iso_out_pkt_dropped(dwc_otg_core_if_t * core_if,
  87294. + dwc_ep_t * dwc_ep)
  87295. +{
  87296. + uint32_t dma_addr;
  87297. + uint32_t drp_pkt;
  87298. + uint32_t drp_pkt_cnt;
  87299. + deptsiz_data_t deptsiz = {.d32 = 0 };
  87300. + depctl_data_t depctl = {.d32 = 0 };
  87301. + int i;
  87302. +
  87303. + deptsiz.d32 =
  87304. + DWC_READ_REG32(&core_if->dev_if->
  87305. + out_ep_regs[dwc_ep->num]->doeptsiz);
  87306. +
  87307. + drp_pkt = dwc_ep->pkt_cnt - deptsiz.b.pktcnt;
  87308. + drp_pkt_cnt = dwc_ep->pkt_per_frm - (drp_pkt % dwc_ep->pkt_per_frm);
  87309. +
  87310. + /* Setting dropped packets status */
  87311. + for (i = 0; i < drp_pkt_cnt; ++i) {
  87312. + dwc_ep->pkt_info[drp_pkt].status = -DWC_E_NO_DATA;
  87313. + drp_pkt++;
  87314. + deptsiz.b.pktcnt--;
  87315. + }
  87316. +
  87317. + if (deptsiz.b.pktcnt > 0) {
  87318. + deptsiz.b.xfersize =
  87319. + dwc_ep->xfer_len - (dwc_ep->pkt_cnt -
  87320. + deptsiz.b.pktcnt) * dwc_ep->maxpacket;
  87321. + } else {
  87322. + deptsiz.b.xfersize = 0;
  87323. + deptsiz.b.pktcnt = 0;
  87324. + }
  87325. +
  87326. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doeptsiz,
  87327. + deptsiz.d32);
  87328. +
  87329. + if (deptsiz.b.pktcnt > 0) {
  87330. + if (dwc_ep->proc_buf_num) {
  87331. + dma_addr =
  87332. + dwc_ep->dma_addr1 + dwc_ep->xfer_len -
  87333. + deptsiz.b.xfersize;
  87334. + } else {
  87335. + dma_addr =
  87336. + dwc_ep->dma_addr0 + dwc_ep->xfer_len -
  87337. + deptsiz.b.xfersize;;
  87338. + }
  87339. +
  87340. + DWC_WRITE_REG32(&core_if->dev_if->
  87341. + out_ep_regs[dwc_ep->num]->doepdma, dma_addr);
  87342. +
  87343. + /** Re-enable endpoint, clear nak */
  87344. + depctl.d32 = 0;
  87345. + depctl.b.epena = 1;
  87346. + depctl.b.cnak = 1;
  87347. +
  87348. + DWC_MODIFY_REG32(&core_if->dev_if->
  87349. + out_ep_regs[dwc_ep->num]->doepctl, depctl.d32,
  87350. + depctl.d32);
  87351. + return 0;
  87352. + } else {
  87353. + return 1;
  87354. + }
  87355. +}
  87356. +
  87357. +/**
  87358. + * This function sets iso packets information(PTI mode)
  87359. + *
  87360. + * @param core_if Programming view of DWC_otg controller.
  87361. + * @param ep The EP to start the transfer on.
  87362. + *
  87363. + */
  87364. +static uint32_t set_iso_pkts_info(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  87365. +{
  87366. + int i, j;
  87367. + dma_addr_t dma_ad;
  87368. + iso_pkt_info_t *packet_info = ep->pkt_info;
  87369. + uint32_t offset;
  87370. + uint32_t frame_data;
  87371. + deptsiz_data_t deptsiz;
  87372. +
  87373. + if (ep->proc_buf_num == 0) {
  87374. + /** Buffer 0 descriptors setup */
  87375. + dma_ad = ep->dma_addr0;
  87376. + } else {
  87377. + /** Buffer 1 descriptors setup */
  87378. + dma_ad = ep->dma_addr1;
  87379. + }
  87380. +
  87381. + if (ep->is_in) {
  87382. + deptsiz.d32 =
  87383. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  87384. + dieptsiz);
  87385. + } else {
  87386. + deptsiz.d32 =
  87387. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[ep->num]->
  87388. + doeptsiz);
  87389. + }
  87390. +
  87391. + if (!deptsiz.b.xfersize) {
  87392. + offset = 0;
  87393. + for (i = 0; i < ep->pkt_cnt; i += ep->pkt_per_frm) {
  87394. + frame_data = ep->data_per_frame;
  87395. + for (j = 0; j < ep->pkt_per_frm; ++j) {
  87396. +
  87397. + /* Packet status - is not set as initially
  87398. + * it is set to 0 and if packet was sent
  87399. + successfully, status field will remain 0*/
  87400. +
  87401. + /* Bytes has been transfered */
  87402. + packet_info->length =
  87403. + (ep->maxpacket <
  87404. + frame_data) ? ep->maxpacket : frame_data;
  87405. +
  87406. + /* Received packet offset */
  87407. + packet_info->offset = offset;
  87408. + offset += packet_info->length;
  87409. + frame_data -= packet_info->length;
  87410. +
  87411. + packet_info++;
  87412. + }
  87413. + }
  87414. + return 1;
  87415. + } else {
  87416. + /* This is a workaround for in case of Transfer Complete with
  87417. + * PktDrpSts interrupts merging - in this case Transfer complete
  87418. + * interrupt for Isoc Out Endpoint is asserted without PktDrpSts
  87419. + * set and with DOEPTSIZ register non zero. Investigations showed,
  87420. + * that this happens when Out packet is dropped, but because of
  87421. + * interrupts merging during first interrupt handling PktDrpSts
  87422. + * bit is cleared and for next merged interrupts it is not reset.
  87423. + * In this case SW hadles the interrupt as if PktDrpSts bit is set.
  87424. + */
  87425. + if (ep->is_in) {
  87426. + return 1;
  87427. + } else {
  87428. + return handle_iso_out_pkt_dropped(core_if, ep);
  87429. + }
  87430. + }
  87431. +}
  87432. +
  87433. +/**
  87434. + * This function is to handle Iso EP transfer complete interrupt
  87435. + *
  87436. + * @param pcd The PCD
  87437. + * @param ep The EP for which transfer complete was asserted
  87438. + *
  87439. + */
  87440. +static void complete_iso_ep(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * ep)
  87441. +{
  87442. + dwc_otg_core_if_t *core_if = GET_CORE_IF(ep->pcd);
  87443. + dwc_ep_t *dwc_ep = &ep->dwc_ep;
  87444. + uint8_t is_last = 0;
  87445. +
  87446. + if (ep->dwc_ep.next_frame == 0xffffffff) {
  87447. + DWC_WARN("Next frame is not set!\n");
  87448. + return;
  87449. + }
  87450. +
  87451. + if (core_if->dma_enable) {
  87452. + if (core_if->dma_desc_enable) {
  87453. + set_ddma_iso_pkts_info(core_if, dwc_ep);
  87454. + reinit_ddma_iso_xfer(core_if, dwc_ep);
  87455. + is_last = 1;
  87456. + } else {
  87457. + if (core_if->pti_enh_enable) {
  87458. + if (set_iso_pkts_info(core_if, dwc_ep)) {
  87459. + dwc_ep->proc_buf_num =
  87460. + (dwc_ep->proc_buf_num ^ 1) & 0x1;
  87461. + dwc_otg_iso_ep_start_buf_transfer
  87462. + (core_if, dwc_ep);
  87463. + is_last = 1;
  87464. + }
  87465. + } else {
  87466. + set_current_pkt_info(core_if, dwc_ep);
  87467. + if (dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
  87468. + is_last = 1;
  87469. + dwc_ep->cur_pkt = 0;
  87470. + dwc_ep->proc_buf_num =
  87471. + (dwc_ep->proc_buf_num ^ 1) & 0x1;
  87472. + if (dwc_ep->proc_buf_num) {
  87473. + dwc_ep->cur_pkt_addr =
  87474. + dwc_ep->xfer_buff1;
  87475. + dwc_ep->cur_pkt_dma_addr =
  87476. + dwc_ep->dma_addr1;
  87477. + } else {
  87478. + dwc_ep->cur_pkt_addr =
  87479. + dwc_ep->xfer_buff0;
  87480. + dwc_ep->cur_pkt_dma_addr =
  87481. + dwc_ep->dma_addr0;
  87482. + }
  87483. +
  87484. + }
  87485. + dwc_otg_iso_ep_start_frm_transfer(core_if,
  87486. + dwc_ep);
  87487. + }
  87488. + }
  87489. + } else {
  87490. + set_current_pkt_info(core_if, dwc_ep);
  87491. + if (dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
  87492. + is_last = 1;
  87493. + dwc_ep->cur_pkt = 0;
  87494. + dwc_ep->proc_buf_num = (dwc_ep->proc_buf_num ^ 1) & 0x1;
  87495. + if (dwc_ep->proc_buf_num) {
  87496. + dwc_ep->cur_pkt_addr = dwc_ep->xfer_buff1;
  87497. + dwc_ep->cur_pkt_dma_addr = dwc_ep->dma_addr1;
  87498. + } else {
  87499. + dwc_ep->cur_pkt_addr = dwc_ep->xfer_buff0;
  87500. + dwc_ep->cur_pkt_dma_addr = dwc_ep->dma_addr0;
  87501. + }
  87502. +
  87503. + }
  87504. + dwc_otg_iso_ep_start_frm_transfer(core_if, dwc_ep);
  87505. + }
  87506. + if (is_last)
  87507. + dwc_otg_iso_buffer_done(pcd, ep, ep->iso_req_handle);
  87508. +}
  87509. +#endif /* DWC_EN_ISOC */
  87510. +
  87511. +/**
  87512. + * This function handle BNA interrupt for Non Isochronous EPs
  87513. + *
  87514. + */
  87515. +static void dwc_otg_pcd_handle_noniso_bna(dwc_otg_pcd_ep_t * ep)
  87516. +{
  87517. + dwc_ep_t *dwc_ep = &ep->dwc_ep;
  87518. + volatile uint32_t *addr;
  87519. + depctl_data_t depctl = {.d32 = 0 };
  87520. + dwc_otg_pcd_t *pcd = ep->pcd;
  87521. + dwc_otg_dev_dma_desc_t *dma_desc;
  87522. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  87523. + dwc_otg_core_if_t *core_if = ep->pcd->core_if;
  87524. + int i, start;
  87525. +
  87526. + if (!dwc_ep->desc_cnt)
  87527. + DWC_WARN("Ep%d %s Descriptor count = %d \n", dwc_ep->num,
  87528. + (dwc_ep->is_in ? "IN" : "OUT"), dwc_ep->desc_cnt);
  87529. +
  87530. + if (core_if->core_params->cont_on_bna && !dwc_ep->is_in
  87531. + && dwc_ep->type != DWC_OTG_EP_TYPE_CONTROL) {
  87532. + uint32_t doepdma;
  87533. + dwc_otg_dev_out_ep_regs_t *out_regs =
  87534. + core_if->dev_if->out_ep_regs[dwc_ep->num];
  87535. + doepdma = DWC_READ_REG32(&(out_regs->doepdma));
  87536. + start = (doepdma - dwc_ep->dma_desc_addr)/sizeof(dwc_otg_dev_dma_desc_t);
  87537. + dma_desc = &(dwc_ep->desc_addr[start]);
  87538. + } else {
  87539. + start = 0;
  87540. + dma_desc = dwc_ep->desc_addr;
  87541. + }
  87542. +
  87543. +
  87544. + for (i = start; i < dwc_ep->desc_cnt; ++i, ++dma_desc) {
  87545. + sts.d32 = dma_desc->status.d32;
  87546. + sts.b.bs = BS_HOST_READY;
  87547. + dma_desc->status.d32 = sts.d32;
  87548. + }
  87549. +
  87550. + if (dwc_ep->is_in == 0) {
  87551. + addr =
  87552. + &GET_CORE_IF(pcd)->dev_if->out_ep_regs[dwc_ep->num]->
  87553. + doepctl;
  87554. + } else {
  87555. + addr =
  87556. + &GET_CORE_IF(pcd)->dev_if->in_ep_regs[dwc_ep->num]->diepctl;
  87557. + }
  87558. + depctl.b.epena = 1;
  87559. + depctl.b.cnak = 1;
  87560. + DWC_MODIFY_REG32(addr, 0, depctl.d32);
  87561. +}
  87562. +
  87563. +/**
  87564. + * This function handles EP0 Control transfers.
  87565. + *
  87566. + * The state of the control transfers are tracked in
  87567. + * <code>ep0state</code>.
  87568. + */
  87569. +static void handle_ep0(dwc_otg_pcd_t * pcd)
  87570. +{
  87571. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  87572. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  87573. + dev_dma_desc_sts_t desc_sts;
  87574. + deptsiz0_data_t deptsiz;
  87575. + uint32_t byte_count;
  87576. +
  87577. +#ifdef DEBUG_EP0
  87578. + DWC_DEBUGPL(DBG_PCDV, "%s()\n", __func__);
  87579. + print_ep0_state(pcd);
  87580. +#endif
  87581. +
  87582. +// DWC_PRINTF("HANDLE EP0\n");
  87583. +
  87584. + switch (pcd->ep0state) {
  87585. + case EP0_DISCONNECT:
  87586. + break;
  87587. +
  87588. + case EP0_IDLE:
  87589. + pcd->request_config = 0;
  87590. +
  87591. + pcd_setup(pcd);
  87592. + break;
  87593. +
  87594. + case EP0_IN_DATA_PHASE:
  87595. +#ifdef DEBUG_EP0
  87596. + DWC_DEBUGPL(DBG_PCD, "DATA_IN EP%d-%s: type=%d, mps=%d\n",
  87597. + ep0->dwc_ep.num, (ep0->dwc_ep.is_in ? "IN" : "OUT"),
  87598. + ep0->dwc_ep.type, ep0->dwc_ep.maxpacket);
  87599. +#endif
  87600. +
  87601. + if (core_if->dma_enable != 0) {
  87602. + /*
  87603. + * For EP0 we can only program 1 packet at a time so we
  87604. + * need to do the make calculations after each complete.
  87605. + * Call write_packet to make the calculations, as in
  87606. + * slave mode, and use those values to determine if we
  87607. + * can complete.
  87608. + */
  87609. + if (core_if->dma_desc_enable == 0) {
  87610. + deptsiz.d32 =
  87611. + DWC_READ_REG32(&core_if->
  87612. + dev_if->in_ep_regs[0]->
  87613. + dieptsiz);
  87614. + byte_count =
  87615. + ep0->dwc_ep.xfer_len - deptsiz.b.xfersize;
  87616. + } else {
  87617. + desc_sts =
  87618. + core_if->dev_if->in_desc_addr->status;
  87619. + byte_count =
  87620. + ep0->dwc_ep.xfer_len - desc_sts.b.bytes;
  87621. + }
  87622. + ep0->dwc_ep.xfer_count += byte_count;
  87623. + ep0->dwc_ep.xfer_buff += byte_count;
  87624. + ep0->dwc_ep.dma_addr += byte_count;
  87625. + }
  87626. + if (ep0->dwc_ep.xfer_count < ep0->dwc_ep.total_len) {
  87627. + dwc_otg_ep0_continue_transfer(GET_CORE_IF(pcd),
  87628. + &ep0->dwc_ep);
  87629. + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER\n");
  87630. + } else if (ep0->dwc_ep.sent_zlp) {
  87631. + dwc_otg_ep0_continue_transfer(GET_CORE_IF(pcd),
  87632. + &ep0->dwc_ep);
  87633. + ep0->dwc_ep.sent_zlp = 0;
  87634. + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER sent zlp\n");
  87635. + } else {
  87636. + ep0_complete_request(ep0);
  87637. + DWC_DEBUGPL(DBG_PCD, "COMPLETE TRANSFER\n");
  87638. + }
  87639. + break;
  87640. + case EP0_OUT_DATA_PHASE:
  87641. +#ifdef DEBUG_EP0
  87642. + DWC_DEBUGPL(DBG_PCD, "DATA_OUT EP%d-%s: type=%d, mps=%d\n",
  87643. + ep0->dwc_ep.num, (ep0->dwc_ep.is_in ? "IN" : "OUT"),
  87644. + ep0->dwc_ep.type, ep0->dwc_ep.maxpacket);
  87645. +#endif
  87646. + if (core_if->dma_enable != 0) {
  87647. + if (core_if->dma_desc_enable == 0) {
  87648. + deptsiz.d32 =
  87649. + DWC_READ_REG32(&core_if->
  87650. + dev_if->out_ep_regs[0]->
  87651. + doeptsiz);
  87652. + byte_count =
  87653. + ep0->dwc_ep.maxpacket - deptsiz.b.xfersize;
  87654. + } else {
  87655. + desc_sts =
  87656. + core_if->dev_if->out_desc_addr->status;
  87657. + byte_count =
  87658. + ep0->dwc_ep.maxpacket - desc_sts.b.bytes;
  87659. + }
  87660. + ep0->dwc_ep.xfer_count += byte_count;
  87661. + ep0->dwc_ep.xfer_buff += byte_count;
  87662. + ep0->dwc_ep.dma_addr += byte_count;
  87663. + }
  87664. + if (ep0->dwc_ep.xfer_count < ep0->dwc_ep.total_len) {
  87665. + dwc_otg_ep0_continue_transfer(GET_CORE_IF(pcd),
  87666. + &ep0->dwc_ep);
  87667. + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER\n");
  87668. + } else if (ep0->dwc_ep.sent_zlp) {
  87669. + dwc_otg_ep0_continue_transfer(GET_CORE_IF(pcd),
  87670. + &ep0->dwc_ep);
  87671. + ep0->dwc_ep.sent_zlp = 0;
  87672. + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER sent zlp\n");
  87673. + } else {
  87674. + ep0_complete_request(ep0);
  87675. + DWC_DEBUGPL(DBG_PCD, "COMPLETE TRANSFER\n");
  87676. + }
  87677. + break;
  87678. +
  87679. + case EP0_IN_STATUS_PHASE:
  87680. + case EP0_OUT_STATUS_PHASE:
  87681. + DWC_DEBUGPL(DBG_PCD, "CASE: EP0_STATUS\n");
  87682. + ep0_complete_request(ep0);
  87683. + pcd->ep0state = EP0_IDLE;
  87684. + ep0->stopped = 1;
  87685. + ep0->dwc_ep.is_in = 0; /* OUT for next SETUP */
  87686. +
  87687. + /* Prepare for more SETUP Packets */
  87688. + if (core_if->dma_enable) {
  87689. + ep0_out_start(core_if, pcd);
  87690. + }
  87691. + break;
  87692. +
  87693. + case EP0_STALL:
  87694. + DWC_ERROR("EP0 STALLed, should not get here pcd_setup()\n");
  87695. + break;
  87696. + }
  87697. +#ifdef DEBUG_EP0
  87698. + print_ep0_state(pcd);
  87699. +#endif
  87700. +}
  87701. +
  87702. +/**
  87703. + * Restart transfer
  87704. + */
  87705. +static void restart_transfer(dwc_otg_pcd_t * pcd, const uint32_t epnum)
  87706. +{
  87707. + dwc_otg_core_if_t *core_if;
  87708. + dwc_otg_dev_if_t *dev_if;
  87709. + deptsiz_data_t dieptsiz = {.d32 = 0 };
  87710. + dwc_otg_pcd_ep_t *ep;
  87711. +
  87712. + ep = get_in_ep(pcd, epnum);
  87713. +
  87714. +#ifdef DWC_EN_ISOC
  87715. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  87716. + return;
  87717. + }
  87718. +#endif /* DWC_EN_ISOC */
  87719. +
  87720. + core_if = GET_CORE_IF(pcd);
  87721. + dev_if = core_if->dev_if;
  87722. +
  87723. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dieptsiz);
  87724. +
  87725. + DWC_DEBUGPL(DBG_PCD, "xfer_buff=%p xfer_count=%0x xfer_len=%0x"
  87726. + " stopped=%d\n", ep->dwc_ep.xfer_buff,
  87727. + ep->dwc_ep.xfer_count, ep->dwc_ep.xfer_len, ep->stopped);
  87728. + /*
  87729. + * If xfersize is 0 and pktcnt in not 0, resend the last packet.
  87730. + */
  87731. + if (dieptsiz.b.pktcnt && dieptsiz.b.xfersize == 0 &&
  87732. + ep->dwc_ep.start_xfer_buff != 0) {
  87733. + if (ep->dwc_ep.total_len <= ep->dwc_ep.maxpacket) {
  87734. + ep->dwc_ep.xfer_count = 0;
  87735. + ep->dwc_ep.xfer_buff = ep->dwc_ep.start_xfer_buff;
  87736. + ep->dwc_ep.xfer_len = ep->dwc_ep.xfer_count;
  87737. + } else {
  87738. + ep->dwc_ep.xfer_count -= ep->dwc_ep.maxpacket;
  87739. + /* convert packet size to dwords. */
  87740. + ep->dwc_ep.xfer_buff -= ep->dwc_ep.maxpacket;
  87741. + ep->dwc_ep.xfer_len = ep->dwc_ep.xfer_count;
  87742. + }
  87743. + ep->stopped = 0;
  87744. + DWC_DEBUGPL(DBG_PCD, "xfer_buff=%p xfer_count=%0x "
  87745. + "xfer_len=%0x stopped=%d\n",
  87746. + ep->dwc_ep.xfer_buff,
  87747. + ep->dwc_ep.xfer_count, ep->dwc_ep.xfer_len,
  87748. + ep->stopped);
  87749. + if (epnum == 0) {
  87750. + dwc_otg_ep0_start_transfer(core_if, &ep->dwc_ep);
  87751. + } else {
  87752. + dwc_otg_ep_start_transfer(core_if, &ep->dwc_ep);
  87753. + }
  87754. + }
  87755. +}
  87756. +
  87757. +/*
  87758. + * This function create new nextep sequnce based on Learn Queue.
  87759. + *
  87760. + * @param core_if Programming view of DWC_otg controller
  87761. + */
  87762. +void predict_nextep_seq( dwc_otg_core_if_t * core_if)
  87763. +{
  87764. + dwc_otg_device_global_regs_t *dev_global_regs =
  87765. + core_if->dev_if->dev_global_regs;
  87766. + const uint32_t TOKEN_Q_DEPTH = core_if->hwcfg2.b.dev_token_q_depth;
  87767. + /* Number of Token Queue Registers */
  87768. + const int DTKNQ_REG_CNT = (TOKEN_Q_DEPTH + 7) / 8;
  87769. + dtknq1_data_t dtknqr1;
  87770. + uint32_t in_tkn_epnums[4];
  87771. + uint8_t seqnum[MAX_EPS_CHANNELS];
  87772. + uint8_t intkn_seq[TOKEN_Q_DEPTH];
  87773. + grstctl_t resetctl = {.d32 = 0 };
  87774. + uint8_t temp;
  87775. + int ndx = 0;
  87776. + int start = 0;
  87777. + int end = 0;
  87778. + int sort_done = 0;
  87779. + int i = 0;
  87780. + volatile uint32_t *addr = &dev_global_regs->dtknqr1;
  87781. +
  87782. +
  87783. + DWC_DEBUGPL(DBG_PCD,"dev_token_q_depth=%d\n",TOKEN_Q_DEPTH);
  87784. +
  87785. + /* Read the DTKNQ Registers */
  87786. + for (i = 0; i < DTKNQ_REG_CNT; i++) {
  87787. + in_tkn_epnums[i] = DWC_READ_REG32(addr);
  87788. + DWC_DEBUGPL(DBG_PCDV, "DTKNQR%d=0x%08x\n", i + 1,
  87789. + in_tkn_epnums[i]);
  87790. + if (addr == &dev_global_regs->dvbusdis) {
  87791. + addr = &dev_global_regs->dtknqr3_dthrctl;
  87792. + } else {
  87793. + ++addr;
  87794. + }
  87795. +
  87796. + }
  87797. +
  87798. + /* Copy the DTKNQR1 data to the bit field. */
  87799. + dtknqr1.d32 = in_tkn_epnums[0];
  87800. + if (dtknqr1.b.wrap_bit) {
  87801. + ndx = dtknqr1.b.intknwptr;
  87802. + end = ndx -1;
  87803. + if (end < 0)
  87804. + end = TOKEN_Q_DEPTH -1;
  87805. + } else {
  87806. + ndx = 0;
  87807. + end = dtknqr1.b.intknwptr -1;
  87808. + if (end < 0)
  87809. + end = 0;
  87810. + }
  87811. + start = ndx;
  87812. +
  87813. + /* Fill seqnum[] by initial values: EP number + 31 */
  87814. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  87815. + seqnum[i] = i +31;
  87816. + }
  87817. +
  87818. + /* Fill intkn_seq[] from in_tkn_epnums[0] */
  87819. + for (i=0; i < 6; i++)
  87820. + intkn_seq[i] = (in_tkn_epnums[0] >> ((7-i) * 4)) & 0xf;
  87821. +
  87822. + if (TOKEN_Q_DEPTH > 6) {
  87823. + /* Fill intkn_seq[] from in_tkn_epnums[1] */
  87824. + for (i=6; i < 14; i++)
  87825. + intkn_seq[i] =
  87826. + (in_tkn_epnums[1] >> ((7 - (i - 6)) * 4)) & 0xf;
  87827. + }
  87828. +
  87829. + if (TOKEN_Q_DEPTH > 14) {
  87830. + /* Fill intkn_seq[] from in_tkn_epnums[1] */
  87831. + for (i=14; i < 22; i++)
  87832. + intkn_seq[i] =
  87833. + (in_tkn_epnums[2] >> ((7 - (i - 14)) * 4)) & 0xf;
  87834. + }
  87835. +
  87836. + if (TOKEN_Q_DEPTH > 22) {
  87837. + /* Fill intkn_seq[] from in_tkn_epnums[1] */
  87838. + for (i=22; i < 30; i++)
  87839. + intkn_seq[i] =
  87840. + (in_tkn_epnums[3] >> ((7 - (i - 22)) * 4)) & 0xf;
  87841. + }
  87842. +
  87843. + DWC_DEBUGPL(DBG_PCDV, "%s start=%d end=%d intkn_seq[]:\n", __func__,
  87844. + start, end);
  87845. + for (i=0; i<TOKEN_Q_DEPTH; i++)
  87846. + DWC_DEBUGPL(DBG_PCDV,"%d\n", intkn_seq[i]);
  87847. +
  87848. + /* Update seqnum based on intkn_seq[] */
  87849. + i = 0;
  87850. + do {
  87851. + seqnum[intkn_seq[ndx]] = i;
  87852. + ndx++;
  87853. + i++;
  87854. + if (ndx == TOKEN_Q_DEPTH)
  87855. + ndx = 0;
  87856. + } while ( i < TOKEN_Q_DEPTH );
  87857. +
  87858. + /* Mark non active EP's in seqnum[] by 0xff */
  87859. + for (i=0; i<=core_if->dev_if->num_in_eps; i++) {
  87860. + if (core_if->nextep_seq[i] == 0xff )
  87861. + seqnum[i] = 0xff;
  87862. + }
  87863. +
  87864. + /* Sort seqnum[] */
  87865. + sort_done = 0;
  87866. + while (!sort_done) {
  87867. + sort_done = 1;
  87868. + for (i=0; i<core_if->dev_if->num_in_eps; i++) {
  87869. + if (seqnum[i] > seqnum[i+1]) {
  87870. + temp = seqnum[i];
  87871. + seqnum[i] = seqnum[i+1];
  87872. + seqnum[i+1] = temp;
  87873. + sort_done = 0;
  87874. + }
  87875. + }
  87876. + }
  87877. +
  87878. + ndx = start + seqnum[0];
  87879. + if (ndx >= TOKEN_Q_DEPTH)
  87880. + ndx = ndx % TOKEN_Q_DEPTH;
  87881. + core_if->first_in_nextep_seq = intkn_seq[ndx];
  87882. +
  87883. + /* Update seqnum[] by EP numbers */
  87884. + for (i=0; i<=core_if->dev_if->num_in_eps; i++) {
  87885. + ndx = start + i;
  87886. + if (seqnum[i] < 31) {
  87887. + ndx = start + seqnum[i];
  87888. + if (ndx >= TOKEN_Q_DEPTH)
  87889. + ndx = ndx % TOKEN_Q_DEPTH;
  87890. + seqnum[i] = intkn_seq[ndx];
  87891. + } else {
  87892. + if (seqnum[i] < 0xff) {
  87893. + seqnum[i] = seqnum[i] - 31;
  87894. + } else {
  87895. + break;
  87896. + }
  87897. + }
  87898. + }
  87899. +
  87900. + /* Update nextep_seq[] based on seqnum[] */
  87901. + for (i=0; i<core_if->dev_if->num_in_eps; i++) {
  87902. + if (seqnum[i] != 0xff) {
  87903. + if (seqnum[i+1] != 0xff) {
  87904. + core_if->nextep_seq[seqnum[i]] = seqnum[i+1];
  87905. + } else {
  87906. + core_if->nextep_seq[seqnum[i]] = core_if->first_in_nextep_seq;
  87907. + break;
  87908. + }
  87909. + } else {
  87910. + break;
  87911. + }
  87912. + }
  87913. +
  87914. + DWC_DEBUGPL(DBG_PCDV, "%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  87915. + __func__, core_if->first_in_nextep_seq);
  87916. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  87917. + DWC_DEBUGPL(DBG_PCDV,"%2d\n", core_if->nextep_seq[i]);
  87918. + }
  87919. +
  87920. + /* Flush the Learning Queue */
  87921. + resetctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->grstctl);
  87922. + resetctl.b.intknqflsh = 1;
  87923. + DWC_WRITE_REG32(&core_if->core_global_regs->grstctl, resetctl.d32);
  87924. +
  87925. +
  87926. +}
  87927. +
  87928. +/**
  87929. + * handle the IN EP disable interrupt.
  87930. + */
  87931. +static inline void handle_in_ep_disable_intr(dwc_otg_pcd_t * pcd,
  87932. + const uint32_t epnum)
  87933. +{
  87934. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  87935. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  87936. + deptsiz_data_t dieptsiz = {.d32 = 0 };
  87937. + dctl_data_t dctl = {.d32 = 0 };
  87938. + dwc_otg_pcd_ep_t *ep;
  87939. + dwc_ep_t *dwc_ep;
  87940. + gintmsk_data_t gintmsk_data;
  87941. + depctl_data_t depctl;
  87942. + uint32_t diepdma;
  87943. + uint32_t remain_to_transfer = 0;
  87944. + uint8_t i;
  87945. + uint32_t xfer_size;
  87946. +
  87947. + ep = get_in_ep(pcd, epnum);
  87948. + dwc_ep = &ep->dwc_ep;
  87949. +
  87950. + if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  87951. + dwc_otg_flush_tx_fifo(core_if, dwc_ep->tx_fifo_num);
  87952. + complete_ep(ep);
  87953. + return;
  87954. + }
  87955. +
  87956. + DWC_DEBUGPL(DBG_PCD, "diepctl%d=%0x\n", epnum,
  87957. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->diepctl));
  87958. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dieptsiz);
  87959. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->diepctl);
  87960. +
  87961. + DWC_DEBUGPL(DBG_ANY, "pktcnt=%d size=%d\n",
  87962. + dieptsiz.b.pktcnt, dieptsiz.b.xfersize);
  87963. +
  87964. + if ((core_if->start_predict == 0) || (depctl.b.eptype & 1)) {
  87965. + if (ep->stopped) {
  87966. + if (core_if->en_multiple_tx_fifo)
  87967. + /* Flush the Tx FIFO */
  87968. + dwc_otg_flush_tx_fifo(core_if, dwc_ep->tx_fifo_num);
  87969. + /* Clear the Global IN NP NAK */
  87970. + dctl.d32 = 0;
  87971. + dctl.b.cgnpinnak = 1;
  87972. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  87973. + /* Restart the transaction */
  87974. + if (dieptsiz.b.pktcnt != 0 || dieptsiz.b.xfersize != 0) {
  87975. + restart_transfer(pcd, epnum);
  87976. + }
  87977. + } else {
  87978. + /* Restart the transaction */
  87979. + if (dieptsiz.b.pktcnt != 0 || dieptsiz.b.xfersize != 0) {
  87980. + restart_transfer(pcd, epnum);
  87981. + }
  87982. + DWC_DEBUGPL(DBG_ANY, "STOPPED!!!\n");
  87983. + }
  87984. + return;
  87985. + }
  87986. +
  87987. + if (core_if->start_predict > 2) { // NP IN EP
  87988. + core_if->start_predict--;
  87989. + return;
  87990. + }
  87991. +
  87992. + core_if->start_predict--;
  87993. +
  87994. + if (core_if->start_predict == 1) { // All NP IN Ep's disabled now
  87995. +
  87996. + predict_nextep_seq(core_if);
  87997. +
  87998. + /* Update all active IN EP's NextEP field based of nextep_seq[] */
  87999. + for ( i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  88000. + depctl.d32 =
  88001. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  88002. + if (core_if->nextep_seq[i] != 0xff) { // Active NP IN EP
  88003. + depctl.b.nextep = core_if->nextep_seq[i];
  88004. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepctl, depctl.d32);
  88005. + }
  88006. + }
  88007. + /* Flush Shared NP TxFIFO */
  88008. + dwc_otg_flush_tx_fifo(core_if, 0);
  88009. + /* Rewind buffers */
  88010. + if (!core_if->dma_desc_enable) {
  88011. + i = core_if->first_in_nextep_seq;
  88012. + do {
  88013. + ep = get_in_ep(pcd, i);
  88014. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->dieptsiz);
  88015. + xfer_size = ep->dwc_ep.total_len - ep->dwc_ep.xfer_count;
  88016. + if (xfer_size > ep->dwc_ep.maxxfer)
  88017. + xfer_size = ep->dwc_ep.maxxfer;
  88018. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  88019. + if (dieptsiz.b.pktcnt != 0) {
  88020. + if (xfer_size == 0) {
  88021. + remain_to_transfer = 0;
  88022. + } else {
  88023. + if ((xfer_size % ep->dwc_ep.maxpacket) == 0) {
  88024. + remain_to_transfer =
  88025. + dieptsiz.b.pktcnt * ep->dwc_ep.maxpacket;
  88026. + } else {
  88027. + remain_to_transfer = ((dieptsiz.b.pktcnt -1) * ep->dwc_ep.maxpacket)
  88028. + + (xfer_size % ep->dwc_ep.maxpacket);
  88029. + }
  88030. + }
  88031. + diepdma = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepdma);
  88032. + dieptsiz.b.xfersize = remain_to_transfer;
  88033. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->dieptsiz, dieptsiz.d32);
  88034. + diepdma = ep->dwc_ep.dma_addr + (xfer_size - remain_to_transfer);
  88035. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepdma, diepdma);
  88036. + }
  88037. + i = core_if->nextep_seq[i];
  88038. + } while (i != core_if->first_in_nextep_seq);
  88039. + } else { // dma_desc_enable
  88040. + DWC_PRINTF("%s Learning Queue not supported in DDMA\n", __func__);
  88041. + }
  88042. +
  88043. + /* Restart transfers in predicted sequences */
  88044. + i = core_if->first_in_nextep_seq;
  88045. + do {
  88046. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->dieptsiz);
  88047. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  88048. + if (dieptsiz.b.pktcnt != 0) {
  88049. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  88050. + depctl.b.epena = 1;
  88051. + depctl.b.cnak = 1;
  88052. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepctl, depctl.d32);
  88053. + }
  88054. + i = core_if->nextep_seq[i];
  88055. + } while (i != core_if->first_in_nextep_seq);
  88056. +
  88057. + /* Clear the global non-periodic IN NAK handshake */
  88058. + dctl.d32 = 0;
  88059. + dctl.b.cgnpinnak = 1;
  88060. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  88061. +
  88062. + /* Unmask EP Mismatch interrupt */
  88063. + gintmsk_data.d32 = 0;
  88064. + gintmsk_data.b.epmismatch = 1;
  88065. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, gintmsk_data.d32);
  88066. +
  88067. + core_if->start_predict = 0;
  88068. +
  88069. + }
  88070. +}
  88071. +
  88072. +/**
  88073. + * Handler for the IN EP timeout handshake interrupt.
  88074. + */
  88075. +static inline void handle_in_ep_timeout_intr(dwc_otg_pcd_t * pcd,
  88076. + const uint32_t epnum)
  88077. +{
  88078. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  88079. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  88080. +
  88081. +#ifdef DEBUG
  88082. + deptsiz_data_t dieptsiz = {.d32 = 0 };
  88083. + uint32_t num = 0;
  88084. +#endif
  88085. + dctl_data_t dctl = {.d32 = 0 };
  88086. + dwc_otg_pcd_ep_t *ep;
  88087. +
  88088. + gintmsk_data_t intr_mask = {.d32 = 0 };
  88089. +
  88090. + ep = get_in_ep(pcd, epnum);
  88091. +
  88092. + /* Disable the NP Tx Fifo Empty Interrrupt */
  88093. + if (!core_if->dma_enable) {
  88094. + intr_mask.b.nptxfempty = 1;
  88095. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk,
  88096. + intr_mask.d32, 0);
  88097. + }
  88098. + /** @todo NGS Check EP type.
  88099. + * Implement for Periodic EPs */
  88100. + /*
  88101. + * Non-periodic EP
  88102. + */
  88103. + /* Enable the Global IN NAK Effective Interrupt */
  88104. + intr_mask.b.ginnakeff = 1;
  88105. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, intr_mask.d32);
  88106. +
  88107. + /* Set Global IN NAK */
  88108. + dctl.b.sgnpinnak = 1;
  88109. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  88110. +
  88111. + ep->stopped = 1;
  88112. +
  88113. +#ifdef DEBUG
  88114. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[num]->dieptsiz);
  88115. + DWC_DEBUGPL(DBG_ANY, "pktcnt=%d size=%d\n",
  88116. + dieptsiz.b.pktcnt, dieptsiz.b.xfersize);
  88117. +#endif
  88118. +
  88119. +#ifdef DISABLE_PERIODIC_EP
  88120. + /*
  88121. + * Set the NAK bit for this EP to
  88122. + * start the disable process.
  88123. + */
  88124. + diepctl.d32 = 0;
  88125. + diepctl.b.snak = 1;
  88126. + DWC_MODIFY_REG32(&dev_if->in_ep_regs[num]->diepctl, diepctl.d32,
  88127. + diepctl.d32);
  88128. + ep->disabling = 1;
  88129. + ep->stopped = 1;
  88130. +#endif
  88131. +}
  88132. +
  88133. +/**
  88134. + * Handler for the IN EP NAK interrupt.
  88135. + */
  88136. +static inline int32_t handle_in_ep_nak_intr(dwc_otg_pcd_t * pcd,
  88137. + const uint32_t epnum)
  88138. +{
  88139. + /** @todo implement ISR */
  88140. + dwc_otg_core_if_t *core_if;
  88141. + diepmsk_data_t intr_mask = {.d32 = 0 };
  88142. +
  88143. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n", "IN EP NAK");
  88144. + core_if = GET_CORE_IF(pcd);
  88145. + intr_mask.b.nak = 1;
  88146. +
  88147. + if (core_if->multiproc_int_enable) {
  88148. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  88149. + diepeachintmsk[epnum], intr_mask.d32, 0);
  88150. + } else {
  88151. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->diepmsk,
  88152. + intr_mask.d32, 0);
  88153. + }
  88154. +
  88155. + return 1;
  88156. +}
  88157. +
  88158. +/**
  88159. + * Handler for the OUT EP Babble interrupt.
  88160. + */
  88161. +static inline int32_t handle_out_ep_babble_intr(dwc_otg_pcd_t * pcd,
  88162. + const uint32_t epnum)
  88163. +{
  88164. + /** @todo implement ISR */
  88165. + dwc_otg_core_if_t *core_if;
  88166. + doepmsk_data_t intr_mask = {.d32 = 0 };
  88167. +
  88168. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n",
  88169. + "OUT EP Babble");
  88170. + core_if = GET_CORE_IF(pcd);
  88171. + intr_mask.b.babble = 1;
  88172. +
  88173. + if (core_if->multiproc_int_enable) {
  88174. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  88175. + doepeachintmsk[epnum], intr_mask.d32, 0);
  88176. + } else {
  88177. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->doepmsk,
  88178. + intr_mask.d32, 0);
  88179. + }
  88180. +
  88181. + return 1;
  88182. +}
  88183. +
  88184. +/**
  88185. + * Handler for the OUT EP NAK interrupt.
  88186. + */
  88187. +static inline int32_t handle_out_ep_nak_intr(dwc_otg_pcd_t * pcd,
  88188. + const uint32_t epnum)
  88189. +{
  88190. + /** @todo implement ISR */
  88191. + dwc_otg_core_if_t *core_if;
  88192. + doepmsk_data_t intr_mask = {.d32 = 0 };
  88193. +
  88194. + DWC_DEBUGPL(DBG_ANY, "INTERRUPT Handler not implemented for %s\n", "OUT EP NAK");
  88195. + core_if = GET_CORE_IF(pcd);
  88196. + intr_mask.b.nak = 1;
  88197. +
  88198. + if (core_if->multiproc_int_enable) {
  88199. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  88200. + doepeachintmsk[epnum], intr_mask.d32, 0);
  88201. + } else {
  88202. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->doepmsk,
  88203. + intr_mask.d32, 0);
  88204. + }
  88205. +
  88206. + return 1;
  88207. +}
  88208. +
  88209. +/**
  88210. + * Handler for the OUT EP NYET interrupt.
  88211. + */
  88212. +static inline int32_t handle_out_ep_nyet_intr(dwc_otg_pcd_t * pcd,
  88213. + const uint32_t epnum)
  88214. +{
  88215. + /** @todo implement ISR */
  88216. + dwc_otg_core_if_t *core_if;
  88217. + doepmsk_data_t intr_mask = {.d32 = 0 };
  88218. +
  88219. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n", "OUT EP NYET");
  88220. + core_if = GET_CORE_IF(pcd);
  88221. + intr_mask.b.nyet = 1;
  88222. +
  88223. + if (core_if->multiproc_int_enable) {
  88224. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  88225. + doepeachintmsk[epnum], intr_mask.d32, 0);
  88226. + } else {
  88227. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->doepmsk,
  88228. + intr_mask.d32, 0);
  88229. + }
  88230. +
  88231. + return 1;
  88232. +}
  88233. +
  88234. +/**
  88235. + * This interrupt indicates that an IN EP has a pending Interrupt.
  88236. + * The sequence for handling the IN EP interrupt is shown below:
  88237. + * -# Read the Device All Endpoint Interrupt register
  88238. + * -# Repeat the following for each IN EP interrupt bit set (from
  88239. + * LSB to MSB).
  88240. + * -# Read the Device Endpoint Interrupt (DIEPINTn) register
  88241. + * -# If "Transfer Complete" call the request complete function
  88242. + * -# If "Endpoint Disabled" complete the EP disable procedure.
  88243. + * -# If "AHB Error Interrupt" log error
  88244. + * -# If "Time-out Handshake" log error
  88245. + * -# If "IN Token Received when TxFIFO Empty" write packet to Tx
  88246. + * FIFO.
  88247. + * -# If "IN Token EP Mismatch" (disable, this is handled by EP
  88248. + * Mismatch Interrupt)
  88249. + */
  88250. +static int32_t dwc_otg_pcd_handle_in_ep_intr(dwc_otg_pcd_t * pcd)
  88251. +{
  88252. +#define CLEAR_IN_EP_INTR(__core_if,__epnum,__intr) \
  88253. +do { \
  88254. + diepint_data_t diepint = {.d32=0}; \
  88255. + diepint.b.__intr = 1; \
  88256. + DWC_WRITE_REG32(&__core_if->dev_if->in_ep_regs[__epnum]->diepint, \
  88257. + diepint.d32); \
  88258. +} while (0)
  88259. +
  88260. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  88261. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  88262. + diepint_data_t diepint = {.d32 = 0 };
  88263. + depctl_data_t depctl = {.d32 = 0 };
  88264. + uint32_t ep_intr;
  88265. + uint32_t epnum = 0;
  88266. + dwc_otg_pcd_ep_t *ep;
  88267. + dwc_ep_t *dwc_ep;
  88268. + gintmsk_data_t intr_mask = {.d32 = 0 };
  88269. +
  88270. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, pcd);
  88271. +
  88272. + /* Read in the device interrupt bits */
  88273. + ep_intr = dwc_otg_read_dev_all_in_ep_intr(core_if);
  88274. +
  88275. + /* Service the Device IN interrupts for each endpoint */
  88276. + while (ep_intr) {
  88277. + if (ep_intr & 0x1) {
  88278. + uint32_t empty_msk;
  88279. + /* Get EP pointer */
  88280. + ep = get_in_ep(pcd, epnum);
  88281. + dwc_ep = &ep->dwc_ep;
  88282. +
  88283. + depctl.d32 =
  88284. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->diepctl);
  88285. + empty_msk =
  88286. + DWC_READ_REG32(&dev_if->
  88287. + dev_global_regs->dtknqr4_fifoemptymsk);
  88288. +
  88289. + DWC_DEBUGPL(DBG_PCDV,
  88290. + "IN EP INTERRUPT - %d\nepmty_msk - %8x diepctl - %8x\n",
  88291. + epnum, empty_msk, depctl.d32);
  88292. +
  88293. + DWC_DEBUGPL(DBG_PCD,
  88294. + "EP%d-%s: type=%d, mps=%d\n",
  88295. + dwc_ep->num, (dwc_ep->is_in ? "IN" : "OUT"),
  88296. + dwc_ep->type, dwc_ep->maxpacket);
  88297. +
  88298. + diepint.d32 =
  88299. + dwc_otg_read_dev_in_ep_intr(core_if, dwc_ep);
  88300. +
  88301. + DWC_DEBUGPL(DBG_PCDV,
  88302. + "EP %d Interrupt Register - 0x%x\n", epnum,
  88303. + diepint.d32);
  88304. + /* Transfer complete */
  88305. + if (diepint.b.xfercompl) {
  88306. + /* Disable the NP Tx FIFO Empty
  88307. + * Interrupt */
  88308. + if (core_if->en_multiple_tx_fifo == 0) {
  88309. + intr_mask.b.nptxfempty = 1;
  88310. + DWC_MODIFY_REG32
  88311. + (&core_if->core_global_regs->gintmsk,
  88312. + intr_mask.d32, 0);
  88313. + } else {
  88314. + /* Disable the Tx FIFO Empty Interrupt for this EP */
  88315. + uint32_t fifoemptymsk =
  88316. + 0x1 << dwc_ep->num;
  88317. + DWC_MODIFY_REG32(&core_if->
  88318. + dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  88319. + fifoemptymsk, 0);
  88320. + }
  88321. + /* Clear the bit in DIEPINTn for this interrupt */
  88322. + CLEAR_IN_EP_INTR(core_if, epnum, xfercompl);
  88323. +
  88324. + /* Complete the transfer */
  88325. + if (epnum == 0) {
  88326. + handle_ep0(pcd);
  88327. + }
  88328. +#ifdef DWC_EN_ISOC
  88329. + else if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  88330. + if (!ep->stopped)
  88331. + complete_iso_ep(pcd, ep);
  88332. + }
  88333. +#endif /* DWC_EN_ISOC */
  88334. +#ifdef DWC_UTE_PER_IO
  88335. + else if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  88336. + if (!ep->stopped)
  88337. + complete_xiso_ep(ep);
  88338. + }
  88339. +#endif /* DWC_UTE_PER_IO */
  88340. + else {
  88341. + if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC &&
  88342. + dwc_ep->bInterval > 1) {
  88343. + dwc_ep->frame_num += dwc_ep->bInterval;
  88344. + if (dwc_ep->frame_num > 0x3FFF)
  88345. + {
  88346. + dwc_ep->frm_overrun = 1;
  88347. + dwc_ep->frame_num &= 0x3FFF;
  88348. + } else
  88349. + dwc_ep->frm_overrun = 0;
  88350. + }
  88351. + complete_ep(ep);
  88352. + if(diepint.b.nak)
  88353. + CLEAR_IN_EP_INTR(core_if, epnum, nak);
  88354. + }
  88355. + }
  88356. + /* Endpoint disable */
  88357. + if (diepint.b.epdisabled) {
  88358. + DWC_DEBUGPL(DBG_ANY, "EP%d IN disabled\n",
  88359. + epnum);
  88360. + handle_in_ep_disable_intr(pcd, epnum);
  88361. +
  88362. + /* Clear the bit in DIEPINTn for this interrupt */
  88363. + CLEAR_IN_EP_INTR(core_if, epnum, epdisabled);
  88364. + }
  88365. + /* AHB Error */
  88366. + if (diepint.b.ahberr) {
  88367. + DWC_ERROR("EP%d IN AHB Error\n", epnum);
  88368. + /* Clear the bit in DIEPINTn for this interrupt */
  88369. + CLEAR_IN_EP_INTR(core_if, epnum, ahberr);
  88370. + }
  88371. + /* TimeOUT Handshake (non-ISOC IN EPs) */
  88372. + if (diepint.b.timeout) {
  88373. + DWC_ERROR("EP%d IN Time-out\n", epnum);
  88374. + handle_in_ep_timeout_intr(pcd, epnum);
  88375. +
  88376. + CLEAR_IN_EP_INTR(core_if, epnum, timeout);
  88377. + }
  88378. + /** IN Token received with TxF Empty */
  88379. + if (diepint.b.intktxfemp) {
  88380. + DWC_DEBUGPL(DBG_ANY,
  88381. + "EP%d IN TKN TxFifo Empty\n",
  88382. + epnum);
  88383. + if (!ep->stopped && epnum != 0) {
  88384. +
  88385. + diepmsk_data_t diepmsk = {.d32 = 0 };
  88386. + diepmsk.b.intktxfemp = 1;
  88387. +
  88388. + if (core_if->multiproc_int_enable) {
  88389. + DWC_MODIFY_REG32
  88390. + (&dev_if->dev_global_regs->diepeachintmsk
  88391. + [epnum], diepmsk.d32, 0);
  88392. + } else {
  88393. + DWC_MODIFY_REG32
  88394. + (&dev_if->dev_global_regs->diepmsk,
  88395. + diepmsk.d32, 0);
  88396. + }
  88397. + } else if (core_if->dma_desc_enable
  88398. + && epnum == 0
  88399. + && pcd->ep0state ==
  88400. + EP0_OUT_STATUS_PHASE) {
  88401. + // EP0 IN set STALL
  88402. + depctl.d32 =
  88403. + DWC_READ_REG32(&dev_if->in_ep_regs
  88404. + [epnum]->diepctl);
  88405. +
  88406. + /* set the disable and stall bits */
  88407. + if (depctl.b.epena) {
  88408. + depctl.b.epdis = 1;
  88409. + }
  88410. + depctl.b.stall = 1;
  88411. + DWC_WRITE_REG32(&dev_if->in_ep_regs
  88412. + [epnum]->diepctl,
  88413. + depctl.d32);
  88414. + }
  88415. + CLEAR_IN_EP_INTR(core_if, epnum, intktxfemp);
  88416. + }
  88417. + /** IN Token Received with EP mismatch */
  88418. + if (diepint.b.intknepmis) {
  88419. + DWC_DEBUGPL(DBG_ANY,
  88420. + "EP%d IN TKN EP Mismatch\n", epnum);
  88421. + CLEAR_IN_EP_INTR(core_if, epnum, intknepmis);
  88422. + }
  88423. + /** IN Endpoint NAK Effective */
  88424. + if (diepint.b.inepnakeff) {
  88425. + DWC_DEBUGPL(DBG_ANY,
  88426. + "EP%d IN EP NAK Effective\n",
  88427. + epnum);
  88428. + /* Periodic EP */
  88429. + if (ep->disabling) {
  88430. + depctl.d32 = 0;
  88431. + depctl.b.snak = 1;
  88432. + depctl.b.epdis = 1;
  88433. + DWC_MODIFY_REG32(&dev_if->in_ep_regs
  88434. + [epnum]->diepctl,
  88435. + depctl.d32,
  88436. + depctl.d32);
  88437. + }
  88438. + CLEAR_IN_EP_INTR(core_if, epnum, inepnakeff);
  88439. +
  88440. + }
  88441. +
  88442. + /** IN EP Tx FIFO Empty Intr */
  88443. + if (diepint.b.emptyintr) {
  88444. + DWC_DEBUGPL(DBG_ANY,
  88445. + "EP%d Tx FIFO Empty Intr \n",
  88446. + epnum);
  88447. + write_empty_tx_fifo(pcd, epnum);
  88448. +
  88449. + CLEAR_IN_EP_INTR(core_if, epnum, emptyintr);
  88450. +
  88451. + }
  88452. +
  88453. + /** IN EP BNA Intr */
  88454. + if (diepint.b.bna) {
  88455. + CLEAR_IN_EP_INTR(core_if, epnum, bna);
  88456. + if (core_if->dma_desc_enable) {
  88457. +#ifdef DWC_EN_ISOC
  88458. + if (dwc_ep->type ==
  88459. + DWC_OTG_EP_TYPE_ISOC) {
  88460. + /*
  88461. + * This checking is performed to prevent first "false" BNA
  88462. + * handling occuring right after reconnect
  88463. + */
  88464. + if (dwc_ep->next_frame !=
  88465. + 0xffffffff)
  88466. + dwc_otg_pcd_handle_iso_bna(ep);
  88467. + } else
  88468. +#endif /* DWC_EN_ISOC */
  88469. + {
  88470. + dwc_otg_pcd_handle_noniso_bna(ep);
  88471. + }
  88472. + }
  88473. + }
  88474. + /* NAK Interrutp */
  88475. + if (diepint.b.nak) {
  88476. + DWC_DEBUGPL(DBG_ANY, "EP%d IN NAK Interrupt\n",
  88477. + epnum);
  88478. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  88479. + depctl_data_t depctl;
  88480. + if (ep->dwc_ep.frame_num == 0xFFFFFFFF) {
  88481. + ep->dwc_ep.frame_num = core_if->frame_num;
  88482. + if (ep->dwc_ep.bInterval > 1) {
  88483. + depctl.d32 = 0;
  88484. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->diepctl);
  88485. + if (ep->dwc_ep.frame_num & 0x1) {
  88486. + depctl.b.setd1pid = 1;
  88487. + depctl.b.setd0pid = 0;
  88488. + } else {
  88489. + depctl.b.setd0pid = 1;
  88490. + depctl.b.setd1pid = 0;
  88491. + }
  88492. + DWC_WRITE_REG32(&dev_if->in_ep_regs[epnum]->diepctl, depctl.d32);
  88493. + }
  88494. + start_next_request(ep);
  88495. + }
  88496. + ep->dwc_ep.frame_num += ep->dwc_ep.bInterval;
  88497. + if (dwc_ep->frame_num > 0x3FFF) {
  88498. + dwc_ep->frm_overrun = 1;
  88499. + dwc_ep->frame_num &= 0x3FFF;
  88500. + } else
  88501. + dwc_ep->frm_overrun = 0;
  88502. + }
  88503. +
  88504. + CLEAR_IN_EP_INTR(core_if, epnum, nak);
  88505. + }
  88506. + }
  88507. + epnum++;
  88508. + ep_intr >>= 1;
  88509. + }
  88510. +
  88511. + return 1;
  88512. +#undef CLEAR_IN_EP_INTR
  88513. +}
  88514. +
  88515. +/**
  88516. + * This interrupt indicates that an OUT EP has a pending Interrupt.
  88517. + * The sequence for handling the OUT EP interrupt is shown below:
  88518. + * -# Read the Device All Endpoint Interrupt register
  88519. + * -# Repeat the following for each OUT EP interrupt bit set (from
  88520. + * LSB to MSB).
  88521. + * -# Read the Device Endpoint Interrupt (DOEPINTn) register
  88522. + * -# If "Transfer Complete" call the request complete function
  88523. + * -# If "Endpoint Disabled" complete the EP disable procedure.
  88524. + * -# If "AHB Error Interrupt" log error
  88525. + * -# If "Setup Phase Done" process Setup Packet (See Standard USB
  88526. + * Command Processing)
  88527. + */
  88528. +static int32_t dwc_otg_pcd_handle_out_ep_intr(dwc_otg_pcd_t * pcd)
  88529. +{
  88530. +#define CLEAR_OUT_EP_INTR(__core_if,__epnum,__intr) \
  88531. +do { \
  88532. + doepint_data_t doepint = {.d32=0}; \
  88533. + doepint.b.__intr = 1; \
  88534. + DWC_WRITE_REG32(&__core_if->dev_if->out_ep_regs[__epnum]->doepint, \
  88535. + doepint.d32); \
  88536. +} while (0)
  88537. +
  88538. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  88539. + uint32_t ep_intr;
  88540. + doepint_data_t doepint = {.d32 = 0 };
  88541. + uint32_t epnum = 0;
  88542. + dwc_otg_pcd_ep_t *ep;
  88543. + dwc_ep_t *dwc_ep;
  88544. + dctl_data_t dctl = {.d32 = 0 };
  88545. + gintmsk_data_t gintmsk = {.d32 = 0 };
  88546. +
  88547. +
  88548. + DWC_DEBUGPL(DBG_PCDV, "%s()\n", __func__);
  88549. +
  88550. + /* Read in the device interrupt bits */
  88551. + ep_intr = dwc_otg_read_dev_all_out_ep_intr(core_if);
  88552. +
  88553. + while (ep_intr) {
  88554. + if (ep_intr & 0x1) {
  88555. + /* Get EP pointer */
  88556. + ep = get_out_ep(pcd, epnum);
  88557. + dwc_ep = &ep->dwc_ep;
  88558. +
  88559. +#ifdef VERBOSE
  88560. + DWC_DEBUGPL(DBG_PCDV,
  88561. + "EP%d-%s: type=%d, mps=%d\n",
  88562. + dwc_ep->num, (dwc_ep->is_in ? "IN" : "OUT"),
  88563. + dwc_ep->type, dwc_ep->maxpacket);
  88564. +#endif
  88565. + doepint.d32 =
  88566. + dwc_otg_read_dev_out_ep_intr(core_if, dwc_ep);
  88567. + /* Moved this interrupt upper due to core deffect of asserting
  88568. + * OUT EP 0 xfercompl along with stsphsrcvd in BDMA */
  88569. + if (doepint.b.stsphsercvd) {
  88570. + deptsiz0_data_t deptsiz;
  88571. + CLEAR_OUT_EP_INTR(core_if, epnum, stsphsercvd);
  88572. + deptsiz.d32 =
  88573. + DWC_READ_REG32(&core_if->dev_if->
  88574. + out_ep_regs[0]->doeptsiz);
  88575. + if (core_if->snpsid >= OTG_CORE_REV_3_00a
  88576. + && core_if->dma_enable
  88577. + && core_if->dma_desc_enable == 0
  88578. + && doepint.b.xfercompl
  88579. + && deptsiz.b.xfersize == 24) {
  88580. + CLEAR_OUT_EP_INTR(core_if, epnum,
  88581. + xfercompl);
  88582. + doepint.b.xfercompl = 0;
  88583. + ep0_out_start(core_if, pcd);
  88584. + }
  88585. + if ((core_if->dma_desc_enable) ||
  88586. + (core_if->dma_enable
  88587. + && core_if->snpsid >=
  88588. + OTG_CORE_REV_3_00a)) {
  88589. + do_setup_in_status_phase(pcd);
  88590. + }
  88591. + }
  88592. + /* Transfer complete */
  88593. + if (doepint.b.xfercompl) {
  88594. +
  88595. + if (epnum == 0) {
  88596. + /* Clear the bit in DOEPINTn for this interrupt */
  88597. + CLEAR_OUT_EP_INTR(core_if, epnum, xfercompl);
  88598. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  88599. + DWC_DEBUGPL(DBG_PCDV, "DOEPINT=%x doepint=%x\n",
  88600. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[0]->doepint),
  88601. + doepint.d32);
  88602. + DWC_DEBUGPL(DBG_PCDV, "DOEPCTL=%x \n",
  88603. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[0]->doepctl));
  88604. +
  88605. + if (core_if->snpsid >= OTG_CORE_REV_3_00a
  88606. + && core_if->dma_enable == 0) {
  88607. + doepint_data_t doepint;
  88608. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  88609. + out_ep_regs[0]->doepint);
  88610. + if (pcd->ep0state == EP0_IDLE && doepint.b.sr) {
  88611. + CLEAR_OUT_EP_INTR(core_if, epnum, sr);
  88612. + goto exit_xfercompl;
  88613. + }
  88614. + }
  88615. + /* In case of DDMA look at SR bit to go to the Data Stage */
  88616. + if (core_if->dma_desc_enable) {
  88617. + dev_dma_desc_sts_t status = {.d32 = 0};
  88618. + if (pcd->ep0state == EP0_IDLE) {
  88619. + status.d32 = core_if->dev_if->setup_desc_addr[core_if->
  88620. + dev_if->setup_desc_index]->status.d32;
  88621. + if(pcd->data_terminated) {
  88622. + pcd->data_terminated = 0;
  88623. + status.d32 = core_if->dev_if->out_desc_addr->status.d32;
  88624. + dwc_memcpy(&pcd->setup_pkt->req, pcd->backup_buf, 8);
  88625. + }
  88626. + if (status.b.sr) {
  88627. + if (doepint.b.setup) {
  88628. + DWC_DEBUGPL(DBG_PCDV, "DMA DESC EP0_IDLE SR=1 setup=1\n");
  88629. + /* Already started data stage, clear setup */
  88630. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  88631. + doepint.b.setup = 0;
  88632. + handle_ep0(pcd);
  88633. + /* Prepare for more setup packets */
  88634. + if (pcd->ep0state == EP0_IN_STATUS_PHASE ||
  88635. + pcd->ep0state == EP0_IN_DATA_PHASE) {
  88636. + ep0_out_start(core_if, pcd);
  88637. + }
  88638. +
  88639. + goto exit_xfercompl;
  88640. + } else {
  88641. + /* Prepare for more setup packets */
  88642. + DWC_DEBUGPL(DBG_PCDV,
  88643. + "EP0_IDLE SR=1 setup=0 new setup comes\n");
  88644. + ep0_out_start(core_if, pcd);
  88645. + }
  88646. + }
  88647. + } else {
  88648. + dwc_otg_pcd_request_t *req;
  88649. + dev_dma_desc_sts_t status = {.d32 = 0};
  88650. + diepint_data_t diepint0;
  88651. + diepint0.d32 = DWC_READ_REG32(&core_if->dev_if->
  88652. + in_ep_regs[0]->diepint);
  88653. +
  88654. + if (pcd->ep0state == EP0_STALL || pcd->ep0state == EP0_DISCONNECT) {
  88655. + DWC_ERROR("EP0 is stalled/disconnected\n");
  88656. + }
  88657. +
  88658. + /* Clear IN xfercompl if set */
  88659. + if (diepint0.b.xfercompl && (pcd->ep0state == EP0_IN_STATUS_PHASE
  88660. + || pcd->ep0state == EP0_IN_DATA_PHASE)) {
  88661. + DWC_WRITE_REG32(&core_if->dev_if->
  88662. + in_ep_regs[0]->diepint, diepint0.d32);
  88663. + }
  88664. +
  88665. + status.d32 = core_if->dev_if->setup_desc_addr[core_if->
  88666. + dev_if->setup_desc_index]->status.d32;
  88667. +
  88668. + if (ep->dwc_ep.xfer_count != ep->dwc_ep.total_len
  88669. + && (pcd->ep0state == EP0_OUT_DATA_PHASE))
  88670. + status.d32 = core_if->dev_if->out_desc_addr->status.d32;
  88671. + if (pcd->ep0state == EP0_OUT_STATUS_PHASE)
  88672. + status.d32 = core_if->dev_if->
  88673. + out_desc_addr->status.d32;
  88674. +
  88675. + if (status.b.sr) {
  88676. + if (DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  88677. + DWC_DEBUGPL(DBG_PCDV, "Request queue empty!!\n");
  88678. + } else {
  88679. + DWC_DEBUGPL(DBG_PCDV, "complete req!!\n");
  88680. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  88681. + if (ep->dwc_ep.xfer_count != ep->dwc_ep.total_len &&
  88682. + pcd->ep0state == EP0_OUT_DATA_PHASE) {
  88683. + /* Read arrived setup packet from req->buf */
  88684. + dwc_memcpy(&pcd->setup_pkt->req,
  88685. + req->buf + ep->dwc_ep.xfer_count, 8);
  88686. + }
  88687. + req->actual = ep->dwc_ep.xfer_count;
  88688. + dwc_otg_request_done(ep, req, -ECONNRESET);
  88689. + ep->dwc_ep.start_xfer_buff = 0;
  88690. + ep->dwc_ep.xfer_buff = 0;
  88691. + ep->dwc_ep.xfer_len = 0;
  88692. + }
  88693. + pcd->ep0state = EP0_IDLE;
  88694. + if (doepint.b.setup) {
  88695. + DWC_DEBUGPL(DBG_PCDV, "EP0_IDLE SR=1 setup=1\n");
  88696. + /* Data stage started, clear setup */
  88697. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  88698. + doepint.b.setup = 0;
  88699. + handle_ep0(pcd);
  88700. + /* Prepare for setup packets if ep0in was enabled*/
  88701. + if (pcd->ep0state == EP0_IN_STATUS_PHASE) {
  88702. + ep0_out_start(core_if, pcd);
  88703. + }
  88704. +
  88705. + goto exit_xfercompl;
  88706. + } else {
  88707. + /* Prepare for more setup packets */
  88708. + DWC_DEBUGPL(DBG_PCDV,
  88709. + "EP0_IDLE SR=1 setup=0 new setup comes 2\n");
  88710. + ep0_out_start(core_if, pcd);
  88711. + }
  88712. + }
  88713. + }
  88714. + }
  88715. + if (core_if->snpsid >= OTG_CORE_REV_2_94a && core_if->dma_enable
  88716. + && core_if->dma_desc_enable == 0) {
  88717. + doepint_data_t doepint_temp = {.d32 = 0};
  88718. + deptsiz0_data_t doeptsize0 = {.d32 = 0 };
  88719. + doepint_temp.d32 = DWC_READ_REG32(&core_if->dev_if->
  88720. + out_ep_regs[ep->dwc_ep.num]->doepint);
  88721. + doeptsize0.d32 = DWC_READ_REG32(&core_if->dev_if->
  88722. + out_ep_regs[ep->dwc_ep.num]->doeptsiz);
  88723. + if (pcd->ep0state == EP0_IDLE) {
  88724. + if (doepint_temp.b.sr) {
  88725. + CLEAR_OUT_EP_INTR(core_if, epnum, sr);
  88726. + }
  88727. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  88728. + out_ep_regs[0]->doepint);
  88729. + if (doeptsize0.b.supcnt == 3) {
  88730. + DWC_DEBUGPL(DBG_ANY, "Rolling over!!!!!!!\n");
  88731. + ep->dwc_ep.stp_rollover = 1;
  88732. + }
  88733. + if (doepint.b.setup) {
  88734. +retry:
  88735. + /* Already started data stage, clear setup */
  88736. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  88737. + doepint.b.setup = 0;
  88738. + handle_ep0(pcd);
  88739. + ep->dwc_ep.stp_rollover = 0;
  88740. + /* Prepare for more setup packets */
  88741. + if (pcd->ep0state == EP0_IN_STATUS_PHASE ||
  88742. + pcd->ep0state == EP0_IN_DATA_PHASE) {
  88743. + ep0_out_start(core_if, pcd);
  88744. + }
  88745. + goto exit_xfercompl;
  88746. + } else {
  88747. + /* Prepare for more setup packets */
  88748. + DWC_DEBUGPL(DBG_ANY,
  88749. + "EP0_IDLE SR=1 setup=0 new setup comes\n");
  88750. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  88751. + out_ep_regs[0]->doepint);
  88752. + if(doepint.b.setup)
  88753. + goto retry;
  88754. + ep0_out_start(core_if, pcd);
  88755. + }
  88756. + } else {
  88757. + dwc_otg_pcd_request_t *req;
  88758. + diepint_data_t diepint0 = {.d32 = 0};
  88759. + doepint_data_t doepint_temp = {.d32 = 0};
  88760. + depctl_data_t diepctl0;
  88761. + diepint0.d32 = DWC_READ_REG32(&core_if->dev_if->
  88762. + in_ep_regs[0]->diepint);
  88763. + diepctl0.d32 = DWC_READ_REG32(&core_if->dev_if->
  88764. + in_ep_regs[0]->diepctl);
  88765. +
  88766. + if (pcd->ep0state == EP0_IN_DATA_PHASE
  88767. + || pcd->ep0state == EP0_IN_STATUS_PHASE) {
  88768. + if (diepint0.b.xfercompl) {
  88769. + DWC_WRITE_REG32(&core_if->dev_if->
  88770. + in_ep_regs[0]->diepint, diepint0.d32);
  88771. + }
  88772. + if (diepctl0.b.epena) {
  88773. + diepint_data_t diepint = {.d32 = 0};
  88774. + diepctl0.b.snak = 1;
  88775. + DWC_WRITE_REG32(&core_if->dev_if->
  88776. + in_ep_regs[0]->diepctl, diepctl0.d32);
  88777. + do {
  88778. + dwc_udelay(10);
  88779. + diepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  88780. + in_ep_regs[0]->diepint);
  88781. + } while (!diepint.b.inepnakeff);
  88782. + diepint.b.inepnakeff = 1;
  88783. + DWC_WRITE_REG32(&core_if->dev_if->
  88784. + in_ep_regs[0]->diepint, diepint.d32);
  88785. + diepctl0.d32 = 0;
  88786. + diepctl0.b.epdis = 1;
  88787. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[0]->diepctl,
  88788. + diepctl0.d32);
  88789. + do {
  88790. + dwc_udelay(10);
  88791. + diepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  88792. + in_ep_regs[0]->diepint);
  88793. + } while (!diepint.b.epdisabled);
  88794. + diepint.b.epdisabled = 1;
  88795. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[0]->diepint,
  88796. + diepint.d32);
  88797. + }
  88798. + }
  88799. + doepint_temp.d32 = DWC_READ_REG32(&core_if->dev_if->
  88800. + out_ep_regs[ep->dwc_ep.num]->doepint);
  88801. + if (doepint_temp.b.sr) {
  88802. + CLEAR_OUT_EP_INTR(core_if, epnum, sr);
  88803. + if (DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  88804. + DWC_DEBUGPL(DBG_PCDV, "Request queue empty!!\n");
  88805. + } else {
  88806. + DWC_DEBUGPL(DBG_PCDV, "complete req!!\n");
  88807. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  88808. + if (ep->dwc_ep.xfer_count != ep->dwc_ep.total_len &&
  88809. + pcd->ep0state == EP0_OUT_DATA_PHASE) {
  88810. + /* Read arrived setup packet from req->buf */
  88811. + dwc_memcpy(&pcd->setup_pkt->req,
  88812. + req->buf + ep->dwc_ep.xfer_count, 8);
  88813. + }
  88814. + req->actual = ep->dwc_ep.xfer_count;
  88815. + dwc_otg_request_done(ep, req, -ECONNRESET);
  88816. + ep->dwc_ep.start_xfer_buff = 0;
  88817. + ep->dwc_ep.xfer_buff = 0;
  88818. + ep->dwc_ep.xfer_len = 0;
  88819. + }
  88820. + pcd->ep0state = EP0_IDLE;
  88821. + if (doepint.b.setup) {
  88822. + DWC_DEBUGPL(DBG_PCDV, "EP0_IDLE SR=1 setup=1\n");
  88823. + /* Data stage started, clear setup */
  88824. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  88825. + doepint.b.setup = 0;
  88826. + handle_ep0(pcd);
  88827. + /* Prepare for setup packets if ep0in was enabled*/
  88828. + if (pcd->ep0state == EP0_IN_STATUS_PHASE) {
  88829. + ep0_out_start(core_if, pcd);
  88830. + }
  88831. + goto exit_xfercompl;
  88832. + } else {
  88833. + /* Prepare for more setup packets */
  88834. + DWC_DEBUGPL(DBG_PCDV,
  88835. + "EP0_IDLE SR=1 setup=0 new setup comes 2\n");
  88836. + ep0_out_start(core_if, pcd);
  88837. + }
  88838. + }
  88839. + }
  88840. + }
  88841. + if (core_if->dma_enable == 0 || pcd->ep0state != EP0_IDLE)
  88842. + handle_ep0(pcd);
  88843. +exit_xfercompl:
  88844. + DWC_DEBUGPL(DBG_PCDV, "DOEPINT=%x doepint=%x\n",
  88845. + dwc_otg_read_dev_out_ep_intr(core_if, dwc_ep), doepint.d32);
  88846. + } else {
  88847. + if (core_if->dma_desc_enable == 0
  88848. + || pcd->ep0state != EP0_IDLE)
  88849. + handle_ep0(pcd);
  88850. + }
  88851. +#ifdef DWC_EN_ISOC
  88852. + } else if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  88853. + if (doepint.b.pktdrpsts == 0) {
  88854. + /* Clear the bit in DOEPINTn for this interrupt */
  88855. + CLEAR_OUT_EP_INTR(core_if,
  88856. + epnum,
  88857. + xfercompl);
  88858. + complete_iso_ep(pcd, ep);
  88859. + } else {
  88860. +
  88861. + doepint_data_t doepint = {.d32 = 0 };
  88862. + doepint.b.xfercompl = 1;
  88863. + doepint.b.pktdrpsts = 1;
  88864. + DWC_WRITE_REG32
  88865. + (&core_if->dev_if->out_ep_regs
  88866. + [epnum]->doepint,
  88867. + doepint.d32);
  88868. + if (handle_iso_out_pkt_dropped
  88869. + (core_if, dwc_ep)) {
  88870. + complete_iso_ep(pcd,
  88871. + ep);
  88872. + }
  88873. + }
  88874. +#endif /* DWC_EN_ISOC */
  88875. +#ifdef DWC_UTE_PER_IO
  88876. + } else if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  88877. + CLEAR_OUT_EP_INTR(core_if, epnum, xfercompl);
  88878. + if (!ep->stopped)
  88879. + complete_xiso_ep(ep);
  88880. +#endif /* DWC_UTE_PER_IO */
  88881. + } else {
  88882. + /* Clear the bit in DOEPINTn for this interrupt */
  88883. + CLEAR_OUT_EP_INTR(core_if, epnum,
  88884. + xfercompl);
  88885. +
  88886. + if (core_if->core_params->dev_out_nak) {
  88887. + DWC_TIMER_CANCEL(pcd->core_if->ep_xfer_timer[epnum]);
  88888. + pcd->core_if->ep_xfer_info[epnum].state = 0;
  88889. +#ifdef DEBUG
  88890. + print_memory_payload(pcd, dwc_ep);
  88891. +#endif
  88892. + }
  88893. + complete_ep(ep);
  88894. + }
  88895. +
  88896. + }
  88897. +
  88898. + /* Endpoint disable */
  88899. + if (doepint.b.epdisabled) {
  88900. +
  88901. + /* Clear the bit in DOEPINTn for this interrupt */
  88902. + CLEAR_OUT_EP_INTR(core_if, epnum, epdisabled);
  88903. + if (core_if->core_params->dev_out_nak) {
  88904. +#ifdef DEBUG
  88905. + print_memory_payload(pcd, dwc_ep);
  88906. +#endif
  88907. + /* In case of timeout condition */
  88908. + if (core_if->ep_xfer_info[epnum].state == 2) {
  88909. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->
  88910. + dev_global_regs->dctl);
  88911. + dctl.b.cgoutnak = 1;
  88912. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl,
  88913. + dctl.d32);
  88914. + /* Unmask goutnakeff interrupt which was masked
  88915. + * during handle nak out interrupt */
  88916. + gintmsk.b.goutnakeff = 1;
  88917. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk,
  88918. + 0, gintmsk.d32);
  88919. +
  88920. + complete_ep(ep);
  88921. + }
  88922. + }
  88923. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC)
  88924. + {
  88925. + dctl_data_t dctl;
  88926. + gintmsk_data_t intr_mask = {.d32 = 0};
  88927. + dwc_otg_pcd_request_t *req = 0;
  88928. +
  88929. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->
  88930. + dev_global_regs->dctl);
  88931. + dctl.b.cgoutnak = 1;
  88932. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl,
  88933. + dctl.d32);
  88934. +
  88935. + intr_mask.d32 = 0;
  88936. + intr_mask.b.incomplisoout = 1;
  88937. +
  88938. + /* Get any pending requests */
  88939. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  88940. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  88941. + if (!req) {
  88942. + DWC_PRINTF("complete_ep 0x%p, req = NULL!\n", ep);
  88943. + } else {
  88944. + dwc_otg_request_done(ep, req, 0);
  88945. + start_next_request(ep);
  88946. + }
  88947. + } else {
  88948. + DWC_PRINTF("complete_ep 0x%p, ep->queue empty!\n", ep);
  88949. + }
  88950. + }
  88951. + }
  88952. + /* AHB Error */
  88953. + if (doepint.b.ahberr) {
  88954. + DWC_ERROR("EP%d OUT AHB Error\n", epnum);
  88955. + DWC_ERROR("EP%d DEPDMA=0x%08x \n",
  88956. + epnum, core_if->dev_if->out_ep_regs[epnum]->doepdma);
  88957. + CLEAR_OUT_EP_INTR(core_if, epnum, ahberr);
  88958. + }
  88959. + /* Setup Phase Done (contorl EPs) */
  88960. + if (doepint.b.setup) {
  88961. +#ifdef DEBUG_EP0
  88962. + DWC_DEBUGPL(DBG_PCD, "EP%d SETUP Done\n", epnum);
  88963. +#endif
  88964. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  88965. +
  88966. + handle_ep0(pcd);
  88967. + }
  88968. +
  88969. + /** OUT EP BNA Intr */
  88970. + if (doepint.b.bna) {
  88971. + CLEAR_OUT_EP_INTR(core_if, epnum, bna);
  88972. + if (core_if->dma_desc_enable) {
  88973. +#ifdef DWC_EN_ISOC
  88974. + if (dwc_ep->type ==
  88975. + DWC_OTG_EP_TYPE_ISOC) {
  88976. + /*
  88977. + * This checking is performed to prevent first "false" BNA
  88978. + * handling occuring right after reconnect
  88979. + */
  88980. + if (dwc_ep->next_frame !=
  88981. + 0xffffffff)
  88982. + dwc_otg_pcd_handle_iso_bna(ep);
  88983. + } else
  88984. +#endif /* DWC_EN_ISOC */
  88985. + {
  88986. + dwc_otg_pcd_handle_noniso_bna(ep);
  88987. + }
  88988. + }
  88989. + }
  88990. + /* Babble Interrupt */
  88991. + if (doepint.b.babble) {
  88992. + DWC_DEBUGPL(DBG_ANY, "EP%d OUT Babble\n",
  88993. + epnum);
  88994. + handle_out_ep_babble_intr(pcd, epnum);
  88995. +
  88996. + CLEAR_OUT_EP_INTR(core_if, epnum, babble);
  88997. + }
  88998. + if (doepint.b.outtknepdis) {
  88999. + DWC_DEBUGPL(DBG_ANY, "EP%d OUT Token received when EP is \
  89000. + disabled\n",epnum);
  89001. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  89002. + doepmsk_data_t doepmsk = {.d32 = 0};
  89003. + ep->dwc_ep.frame_num = core_if->frame_num;
  89004. + if (ep->dwc_ep.bInterval > 1) {
  89005. + depctl_data_t depctl;
  89006. + depctl.d32 = DWC_READ_REG32(&core_if->dev_if->
  89007. + out_ep_regs[epnum]->doepctl);
  89008. + if (ep->dwc_ep.frame_num & 0x1) {
  89009. + depctl.b.setd1pid = 1;
  89010. + depctl.b.setd0pid = 0;
  89011. + } else {
  89012. + depctl.b.setd0pid = 1;
  89013. + depctl.b.setd1pid = 0;
  89014. + }
  89015. + DWC_WRITE_REG32(&core_if->dev_if->
  89016. + out_ep_regs[epnum]->doepctl, depctl.d32);
  89017. + }
  89018. + start_next_request(ep);
  89019. + doepmsk.b.outtknepdis = 1;
  89020. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->doepmsk,
  89021. + doepmsk.d32, 0);
  89022. + }
  89023. + CLEAR_OUT_EP_INTR(core_if, epnum, outtknepdis);
  89024. + }
  89025. +
  89026. + /* NAK Interrutp */
  89027. + if (doepint.b.nak) {
  89028. + DWC_DEBUGPL(DBG_ANY, "EP%d OUT NAK\n", epnum);
  89029. + handle_out_ep_nak_intr(pcd, epnum);
  89030. +
  89031. + CLEAR_OUT_EP_INTR(core_if, epnum, nak);
  89032. + }
  89033. + /* NYET Interrutp */
  89034. + if (doepint.b.nyet) {
  89035. + DWC_DEBUGPL(DBG_ANY, "EP%d OUT NYET\n", epnum);
  89036. + handle_out_ep_nyet_intr(pcd, epnum);
  89037. +
  89038. + CLEAR_OUT_EP_INTR(core_if, epnum, nyet);
  89039. + }
  89040. + }
  89041. +
  89042. + epnum++;
  89043. + ep_intr >>= 1;
  89044. + }
  89045. +
  89046. + return 1;
  89047. +
  89048. +#undef CLEAR_OUT_EP_INTR
  89049. +}
  89050. +static int drop_transfer(uint32_t trgt_fr, uint32_t curr_fr, uint8_t frm_overrun)
  89051. +{
  89052. + int retval = 0;
  89053. + if(!frm_overrun && curr_fr >= trgt_fr)
  89054. + retval = 1;
  89055. + else if (frm_overrun
  89056. + && (curr_fr >= trgt_fr && ((curr_fr - trgt_fr) < 0x3FFF / 2)))
  89057. + retval = 1;
  89058. + return retval;
  89059. +}
  89060. +/**
  89061. + * Incomplete ISO IN Transfer Interrupt.
  89062. + * This interrupt indicates one of the following conditions occurred
  89063. + * while transmitting an ISOC transaction.
  89064. + * - Corrupted IN Token for ISOC EP.
  89065. + * - Packet not complete in FIFO.
  89066. + * The follow actions will be taken:
  89067. + * -# Determine the EP
  89068. + * -# Set incomplete flag in dwc_ep structure
  89069. + * -# Disable EP; when "Endpoint Disabled" interrupt is received
  89070. + * Flush FIFO
  89071. + */
  89072. +int32_t dwc_otg_pcd_handle_incomplete_isoc_in_intr(dwc_otg_pcd_t * pcd)
  89073. +{
  89074. + gintsts_data_t gintsts;
  89075. +
  89076. +#ifdef DWC_EN_ISOC
  89077. + dwc_otg_dev_if_t *dev_if;
  89078. + deptsiz_data_t deptsiz = {.d32 = 0 };
  89079. + depctl_data_t depctl = {.d32 = 0 };
  89080. + dsts_data_t dsts = {.d32 = 0 };
  89081. + dwc_ep_t *dwc_ep;
  89082. + int i;
  89083. +
  89084. + dev_if = GET_CORE_IF(pcd)->dev_if;
  89085. +
  89086. + for (i = 1; i <= dev_if->num_in_eps; ++i) {
  89087. + dwc_ep = &pcd->in_ep[i].dwc_ep;
  89088. + if (dwc_ep->active && dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  89089. + deptsiz.d32 =
  89090. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->dieptsiz);
  89091. + depctl.d32 =
  89092. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  89093. +
  89094. + if (depctl.b.epdis && deptsiz.d32) {
  89095. + set_current_pkt_info(GET_CORE_IF(pcd), dwc_ep);
  89096. + if (dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
  89097. + dwc_ep->cur_pkt = 0;
  89098. + dwc_ep->proc_buf_num =
  89099. + (dwc_ep->proc_buf_num ^ 1) & 0x1;
  89100. +
  89101. + if (dwc_ep->proc_buf_num) {
  89102. + dwc_ep->cur_pkt_addr =
  89103. + dwc_ep->xfer_buff1;
  89104. + dwc_ep->cur_pkt_dma_addr =
  89105. + dwc_ep->dma_addr1;
  89106. + } else {
  89107. + dwc_ep->cur_pkt_addr =
  89108. + dwc_ep->xfer_buff0;
  89109. + dwc_ep->cur_pkt_dma_addr =
  89110. + dwc_ep->dma_addr0;
  89111. + }
  89112. +
  89113. + }
  89114. +
  89115. + dsts.d32 =
  89116. + DWC_READ_REG32(&GET_CORE_IF(pcd)->dev_if->
  89117. + dev_global_regs->dsts);
  89118. + dwc_ep->next_frame = dsts.b.soffn;
  89119. +
  89120. + dwc_otg_iso_ep_start_frm_transfer(GET_CORE_IF
  89121. + (pcd),
  89122. + dwc_ep);
  89123. + }
  89124. + }
  89125. + }
  89126. +
  89127. +#else
  89128. + depctl_data_t depctl = {.d32 = 0 };
  89129. + dwc_ep_t *dwc_ep;
  89130. + dwc_otg_dev_if_t *dev_if;
  89131. + int i;
  89132. + dev_if = GET_CORE_IF(pcd)->dev_if;
  89133. +
  89134. + DWC_DEBUGPL(DBG_PCD,"Incomplete ISO IN \n");
  89135. +
  89136. + for (i = 1; i <= dev_if->num_in_eps; ++i) {
  89137. + dwc_ep = &pcd->in_ep[i-1].dwc_ep;
  89138. + depctl.d32 =
  89139. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  89140. + if (depctl.b.epena && dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  89141. + if (drop_transfer(dwc_ep->frame_num, GET_CORE_IF(pcd)->frame_num,
  89142. + dwc_ep->frm_overrun))
  89143. + {
  89144. + depctl.d32 =
  89145. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  89146. + depctl.b.snak = 1;
  89147. + depctl.b.epdis = 1;
  89148. + DWC_MODIFY_REG32(&dev_if->in_ep_regs[i]->diepctl, depctl.d32, depctl.d32);
  89149. + }
  89150. + }
  89151. + }
  89152. +
  89153. + /*intr_mask.b.incomplisoin = 1;
  89154. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  89155. + intr_mask.d32, 0); */
  89156. +#endif //DWC_EN_ISOC
  89157. +
  89158. + /* Clear interrupt */
  89159. + gintsts.d32 = 0;
  89160. + gintsts.b.incomplisoin = 1;
  89161. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  89162. + gintsts.d32);
  89163. +
  89164. + return 1;
  89165. +}
  89166. +
  89167. +/**
  89168. + * Incomplete ISO OUT Transfer Interrupt.
  89169. + *
  89170. + * This interrupt indicates that the core has dropped an ISO OUT
  89171. + * packet. The following conditions can be the cause:
  89172. + * - FIFO Full, the entire packet would not fit in the FIFO.
  89173. + * - CRC Error
  89174. + * - Corrupted Token
  89175. + * The follow actions will be taken:
  89176. + * -# Determine the EP
  89177. + * -# Set incomplete flag in dwc_ep structure
  89178. + * -# Read any data from the FIFO
  89179. + * -# Disable EP. When "Endpoint Disabled" interrupt is received
  89180. + * re-enable EP.
  89181. + */
  89182. +int32_t dwc_otg_pcd_handle_incomplete_isoc_out_intr(dwc_otg_pcd_t * pcd)
  89183. +{
  89184. +
  89185. + gintsts_data_t gintsts;
  89186. +
  89187. +#ifdef DWC_EN_ISOC
  89188. + dwc_otg_dev_if_t *dev_if;
  89189. + deptsiz_data_t deptsiz = {.d32 = 0 };
  89190. + depctl_data_t depctl = {.d32 = 0 };
  89191. + dsts_data_t dsts = {.d32 = 0 };
  89192. + dwc_ep_t *dwc_ep;
  89193. + int i;
  89194. +
  89195. + dev_if = GET_CORE_IF(pcd)->dev_if;
  89196. +
  89197. + for (i = 1; i <= dev_if->num_out_eps; ++i) {
  89198. + dwc_ep = &pcd->in_ep[i].dwc_ep;
  89199. + if (pcd->out_ep[i].dwc_ep.active &&
  89200. + pcd->out_ep[i].dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  89201. + deptsiz.d32 =
  89202. + DWC_READ_REG32(&dev_if->out_ep_regs[i]->doeptsiz);
  89203. + depctl.d32 =
  89204. + DWC_READ_REG32(&dev_if->out_ep_regs[i]->doepctl);
  89205. +
  89206. + if (depctl.b.epdis && deptsiz.d32) {
  89207. + set_current_pkt_info(GET_CORE_IF(pcd),
  89208. + &pcd->out_ep[i].dwc_ep);
  89209. + if (dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
  89210. + dwc_ep->cur_pkt = 0;
  89211. + dwc_ep->proc_buf_num =
  89212. + (dwc_ep->proc_buf_num ^ 1) & 0x1;
  89213. +
  89214. + if (dwc_ep->proc_buf_num) {
  89215. + dwc_ep->cur_pkt_addr =
  89216. + dwc_ep->xfer_buff1;
  89217. + dwc_ep->cur_pkt_dma_addr =
  89218. + dwc_ep->dma_addr1;
  89219. + } else {
  89220. + dwc_ep->cur_pkt_addr =
  89221. + dwc_ep->xfer_buff0;
  89222. + dwc_ep->cur_pkt_dma_addr =
  89223. + dwc_ep->dma_addr0;
  89224. + }
  89225. +
  89226. + }
  89227. +
  89228. + dsts.d32 =
  89229. + DWC_READ_REG32(&GET_CORE_IF(pcd)->dev_if->
  89230. + dev_global_regs->dsts);
  89231. + dwc_ep->next_frame = dsts.b.soffn;
  89232. +
  89233. + dwc_otg_iso_ep_start_frm_transfer(GET_CORE_IF
  89234. + (pcd),
  89235. + dwc_ep);
  89236. + }
  89237. + }
  89238. + }
  89239. +#else
  89240. + /** @todo implement ISR */
  89241. + gintmsk_data_t intr_mask = {.d32 = 0 };
  89242. + dwc_otg_core_if_t *core_if;
  89243. + deptsiz_data_t deptsiz = {.d32 = 0 };
  89244. + depctl_data_t depctl = {.d32 = 0 };
  89245. + dctl_data_t dctl = {.d32 = 0 };
  89246. + dwc_ep_t *dwc_ep = NULL;
  89247. + int i;
  89248. + core_if = GET_CORE_IF(pcd);
  89249. +
  89250. + for (i = 0; i < core_if->dev_if->num_out_eps; ++i) {
  89251. + dwc_ep = &pcd->out_ep[i].dwc_ep;
  89252. + depctl.d32 =
  89253. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl);
  89254. + if (depctl.b.epena && depctl.b.dpid == (core_if->frame_num & 0x1)) {
  89255. + core_if->dev_if->isoc_ep = dwc_ep;
  89256. + deptsiz.d32 =
  89257. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doeptsiz);
  89258. + break;
  89259. + }
  89260. + }
  89261. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  89262. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  89263. + intr_mask.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  89264. +
  89265. + if (!intr_mask.b.goutnakeff) {
  89266. + /* Unmask it */
  89267. + intr_mask.b.goutnakeff = 1;
  89268. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, intr_mask.d32);
  89269. + }
  89270. + if (!gintsts.b.goutnakeff) {
  89271. + dctl.b.sgoutnak = 1;
  89272. + }
  89273. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32);
  89274. +
  89275. + depctl.d32 = DWC_READ_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl);
  89276. + if (depctl.b.epena) {
  89277. + depctl.b.epdis = 1;
  89278. + depctl.b.snak = 1;
  89279. + }
  89280. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl, depctl.d32);
  89281. +
  89282. + intr_mask.d32 = 0;
  89283. + intr_mask.b.incomplisoout = 1;
  89284. +
  89285. +#endif /* DWC_EN_ISOC */
  89286. +
  89287. + /* Clear interrupt */
  89288. + gintsts.d32 = 0;
  89289. + gintsts.b.incomplisoout = 1;
  89290. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  89291. + gintsts.d32);
  89292. +
  89293. + return 1;
  89294. +}
  89295. +
  89296. +/**
  89297. + * This function handles the Global IN NAK Effective interrupt.
  89298. + *
  89299. + */
  89300. +int32_t dwc_otg_pcd_handle_in_nak_effective(dwc_otg_pcd_t * pcd)
  89301. +{
  89302. + dwc_otg_dev_if_t *dev_if = GET_CORE_IF(pcd)->dev_if;
  89303. + depctl_data_t diepctl = {.d32 = 0 };
  89304. + gintmsk_data_t intr_mask = {.d32 = 0 };
  89305. + gintsts_data_t gintsts;
  89306. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  89307. + int i;
  89308. +
  89309. + DWC_DEBUGPL(DBG_PCD, "Global IN NAK Effective\n");
  89310. +
  89311. + /* Disable all active IN EPs */
  89312. + for (i = 0; i <= dev_if->num_in_eps; i++) {
  89313. + diepctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  89314. + if (!(diepctl.b.eptype & 1) && diepctl.b.epena) {
  89315. + if (core_if->start_predict > 0)
  89316. + core_if->start_predict++;
  89317. + diepctl.b.epdis = 1;
  89318. + diepctl.b.snak = 1;
  89319. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepctl, diepctl.d32);
  89320. + }
  89321. + }
  89322. +
  89323. +
  89324. + /* Disable the Global IN NAK Effective Interrupt */
  89325. + intr_mask.b.ginnakeff = 1;
  89326. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  89327. + intr_mask.d32, 0);
  89328. +
  89329. + /* Clear interrupt */
  89330. + gintsts.d32 = 0;
  89331. + gintsts.b.ginnakeff = 1;
  89332. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  89333. + gintsts.d32);
  89334. +
  89335. + return 1;
  89336. +}
  89337. +
  89338. +/**
  89339. + * OUT NAK Effective.
  89340. + *
  89341. + */
  89342. +int32_t dwc_otg_pcd_handle_out_nak_effective(dwc_otg_pcd_t * pcd)
  89343. +{
  89344. + dwc_otg_dev_if_t *dev_if = GET_CORE_IF(pcd)->dev_if;
  89345. + gintmsk_data_t intr_mask = {.d32 = 0 };
  89346. + gintsts_data_t gintsts;
  89347. + depctl_data_t doepctl;
  89348. + int i;
  89349. +
  89350. + /* Disable the Global OUT NAK Effective Interrupt */
  89351. + intr_mask.b.goutnakeff = 1;
  89352. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  89353. + intr_mask.d32, 0);
  89354. +
  89355. + /* If DEV OUT NAK enabled*/
  89356. + if (pcd->core_if->core_params->dev_out_nak) {
  89357. + /* Run over all out endpoints to determine the ep number on
  89358. + * which the timeout has happened
  89359. + */
  89360. + for (i = 0; i <= dev_if->num_out_eps; i++) {
  89361. + if ( pcd->core_if->ep_xfer_info[i].state == 2 )
  89362. + break;
  89363. + }
  89364. + if (i > dev_if->num_out_eps) {
  89365. + dctl_data_t dctl;
  89366. + dctl.d32 =
  89367. + DWC_READ_REG32(&dev_if->dev_global_regs->dctl);
  89368. + dctl.b.cgoutnak = 1;
  89369. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dctl,
  89370. + dctl.d32);
  89371. + goto out;
  89372. + }
  89373. +
  89374. + /* Disable the endpoint */
  89375. + doepctl.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[i]->doepctl);
  89376. + if (doepctl.b.epena) {
  89377. + doepctl.b.epdis = 1;
  89378. + doepctl.b.snak = 1;
  89379. + }
  89380. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepctl, doepctl.d32);
  89381. + return 1;
  89382. + }
  89383. + /* We come here from Incomplete ISO OUT handler */
  89384. + if (dev_if->isoc_ep) {
  89385. + dwc_ep_t *dwc_ep = (dwc_ep_t *)dev_if->isoc_ep;
  89386. + uint32_t epnum = dwc_ep->num;
  89387. + doepint_data_t doepint;
  89388. + doepint.d32 =
  89389. + DWC_READ_REG32(&dev_if->out_ep_regs[dwc_ep->num]->doepint);
  89390. + dev_if->isoc_ep = NULL;
  89391. + doepctl.d32 =
  89392. + DWC_READ_REG32(&dev_if->out_ep_regs[epnum]->doepctl);
  89393. + DWC_PRINTF("Before disable DOEPCTL = %08x\n", doepctl.d32);
  89394. + if (doepctl.b.epena) {
  89395. + doepctl.b.epdis = 1;
  89396. + doepctl.b.snak = 1;
  89397. + }
  89398. + DWC_WRITE_REG32(&dev_if->out_ep_regs[epnum]->doepctl,
  89399. + doepctl.d32);
  89400. + return 1;
  89401. + } else
  89402. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n",
  89403. + "Global OUT NAK Effective\n");
  89404. +
  89405. +out:
  89406. + /* Clear interrupt */
  89407. + gintsts.d32 = 0;
  89408. + gintsts.b.goutnakeff = 1;
  89409. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  89410. + gintsts.d32);
  89411. +
  89412. + return 1;
  89413. +}
  89414. +
  89415. +/**
  89416. + * PCD interrupt handler.
  89417. + *
  89418. + * The PCD handles the device interrupts. Many conditions can cause a
  89419. + * device interrupt. When an interrupt occurs, the device interrupt
  89420. + * service routine determines the cause of the interrupt and
  89421. + * dispatches handling to the appropriate function. These interrupt
  89422. + * handling functions are described below.
  89423. + *
  89424. + * All interrupt registers are processed from LSB to MSB.
  89425. + *
  89426. + */
  89427. +int32_t dwc_otg_pcd_handle_intr(dwc_otg_pcd_t * pcd)
  89428. +{
  89429. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  89430. +#ifdef VERBOSE
  89431. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  89432. +#endif
  89433. + gintsts_data_t gintr_status;
  89434. + int32_t retval = 0;
  89435. +
  89436. + /* Exit from ISR if core is hibernated */
  89437. + if (core_if->hibernation_suspend == 1) {
  89438. + return retval;
  89439. + }
  89440. +#ifdef VERBOSE
  89441. + DWC_DEBUGPL(DBG_ANY, "%s() gintsts=%08x gintmsk=%08x\n",
  89442. + __func__,
  89443. + DWC_READ_REG32(&global_regs->gintsts),
  89444. + DWC_READ_REG32(&global_regs->gintmsk));
  89445. +#endif
  89446. +
  89447. + if (dwc_otg_is_device_mode(core_if)) {
  89448. + DWC_SPINLOCK(pcd->lock);
  89449. +#ifdef VERBOSE
  89450. + DWC_DEBUGPL(DBG_PCDV, "%s() gintsts=%08x gintmsk=%08x\n",
  89451. + __func__,
  89452. + DWC_READ_REG32(&global_regs->gintsts),
  89453. + DWC_READ_REG32(&global_regs->gintmsk));
  89454. +#endif
  89455. +
  89456. + gintr_status.d32 = dwc_otg_read_core_intr(core_if);
  89457. +
  89458. + DWC_DEBUGPL(DBG_PCDV, "%s: gintsts&gintmsk=%08x\n",
  89459. + __func__, gintr_status.d32);
  89460. +
  89461. + if (gintr_status.b.sofintr) {
  89462. + retval |= dwc_otg_pcd_handle_sof_intr(pcd);
  89463. + }
  89464. + if (gintr_status.b.rxstsqlvl) {
  89465. + retval |=
  89466. + dwc_otg_pcd_handle_rx_status_q_level_intr(pcd);
  89467. + }
  89468. + if (gintr_status.b.nptxfempty) {
  89469. + retval |= dwc_otg_pcd_handle_np_tx_fifo_empty_intr(pcd);
  89470. + }
  89471. + if (gintr_status.b.goutnakeff) {
  89472. + retval |= dwc_otg_pcd_handle_out_nak_effective(pcd);
  89473. + }
  89474. + if (gintr_status.b.i2cintr) {
  89475. + retval |= dwc_otg_pcd_handle_i2c_intr(pcd);
  89476. + }
  89477. + if (gintr_status.b.erlysuspend) {
  89478. + retval |= dwc_otg_pcd_handle_early_suspend_intr(pcd);
  89479. + }
  89480. + if (gintr_status.b.usbreset) {
  89481. + retval |= dwc_otg_pcd_handle_usb_reset_intr(pcd);
  89482. + }
  89483. + if (gintr_status.b.enumdone) {
  89484. + retval |= dwc_otg_pcd_handle_enum_done_intr(pcd);
  89485. + }
  89486. + if (gintr_status.b.isooutdrop) {
  89487. + retval |=
  89488. + dwc_otg_pcd_handle_isoc_out_packet_dropped_intr
  89489. + (pcd);
  89490. + }
  89491. + if (gintr_status.b.eopframe) {
  89492. + retval |=
  89493. + dwc_otg_pcd_handle_end_periodic_frame_intr(pcd);
  89494. + }
  89495. + if (gintr_status.b.inepint) {
  89496. + if (!core_if->multiproc_int_enable) {
  89497. + retval |= dwc_otg_pcd_handle_in_ep_intr(pcd);
  89498. + }
  89499. + }
  89500. + if (gintr_status.b.outepintr) {
  89501. + if (!core_if->multiproc_int_enable) {
  89502. + retval |= dwc_otg_pcd_handle_out_ep_intr(pcd);
  89503. + }
  89504. + }
  89505. + if (gintr_status.b.epmismatch) {
  89506. + retval |= dwc_otg_pcd_handle_ep_mismatch_intr(pcd);
  89507. + }
  89508. + if (gintr_status.b.fetsusp) {
  89509. + retval |= dwc_otg_pcd_handle_ep_fetsusp_intr(pcd);
  89510. + }
  89511. + if (gintr_status.b.ginnakeff) {
  89512. + retval |= dwc_otg_pcd_handle_in_nak_effective(pcd);
  89513. + }
  89514. + if (gintr_status.b.incomplisoin) {
  89515. + retval |=
  89516. + dwc_otg_pcd_handle_incomplete_isoc_in_intr(pcd);
  89517. + }
  89518. + if (gintr_status.b.incomplisoout) {
  89519. + retval |=
  89520. + dwc_otg_pcd_handle_incomplete_isoc_out_intr(pcd);
  89521. + }
  89522. +
  89523. + /* In MPI mode Device Endpoints interrupts are asserted
  89524. + * without setting outepintr and inepint bits set, so these
  89525. + * Interrupt handlers are called without checking these bit-fields
  89526. + */
  89527. + if (core_if->multiproc_int_enable) {
  89528. + retval |= dwc_otg_pcd_handle_in_ep_intr(pcd);
  89529. + retval |= dwc_otg_pcd_handle_out_ep_intr(pcd);
  89530. + }
  89531. +#ifdef VERBOSE
  89532. + DWC_DEBUGPL(DBG_PCDV, "%s() gintsts=%0x\n", __func__,
  89533. + DWC_READ_REG32(&global_regs->gintsts));
  89534. +#endif
  89535. + DWC_SPINUNLOCK(pcd->lock);
  89536. + }
  89537. + return retval;
  89538. +}
  89539. +
  89540. +#endif /* DWC_HOST_ONLY */
  89541. diff -Nur linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c
  89542. --- linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c 1970-01-01 01:00:00.000000000 +0100
  89543. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c 2014-04-24 15:37:13.314990533 +0200
  89544. @@ -0,0 +1,1358 @@
  89545. + /* ==========================================================================
  89546. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd_linux.c $
  89547. + * $Revision: #21 $
  89548. + * $Date: 2012/08/10 $
  89549. + * $Change: 2047372 $
  89550. + *
  89551. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  89552. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  89553. + * otherwise expressly agreed to in writing between Synopsys and you.
  89554. + *
  89555. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  89556. + * any End User Software License Agreement or Agreement for Licensed Product
  89557. + * with Synopsys or any supplement thereto. You are permitted to use and
  89558. + * redistribute this Software in source and binary forms, with or without
  89559. + * modification, provided that redistributions of source code must retain this
  89560. + * notice. You may not view, use, disclose, copy or distribute this file or
  89561. + * any information contained herein except pursuant to this license grant from
  89562. + * Synopsys. If you do not agree with this notice, including the disclaimer
  89563. + * below, then you are not authorized to use the Software.
  89564. + *
  89565. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  89566. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  89567. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  89568. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  89569. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  89570. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  89571. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  89572. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  89573. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  89574. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  89575. + * DAMAGE.
  89576. + * ========================================================================== */
  89577. +#ifndef DWC_HOST_ONLY
  89578. +
  89579. +/** @file
  89580. + * This file implements the Peripheral Controller Driver.
  89581. + *
  89582. + * The Peripheral Controller Driver (PCD) is responsible for
  89583. + * translating requests from the Function Driver into the appropriate
  89584. + * actions on the DWC_otg controller. It isolates the Function Driver
  89585. + * from the specifics of the controller by providing an API to the
  89586. + * Function Driver.
  89587. + *
  89588. + * The Peripheral Controller Driver for Linux will implement the
  89589. + * Gadget API, so that the existing Gadget drivers can be used.
  89590. + * (Gadget Driver is the Linux terminology for a Function Driver.)
  89591. + *
  89592. + * The Linux Gadget API is defined in the header file
  89593. + * <code><linux/usb_gadget.h></code>. The USB EP operations API is
  89594. + * defined in the structure <code>usb_ep_ops</code> and the USB
  89595. + * Controller API is defined in the structure
  89596. + * <code>usb_gadget_ops</code>.
  89597. + *
  89598. + */
  89599. +
  89600. +#include "dwc_otg_os_dep.h"
  89601. +#include "dwc_otg_pcd_if.h"
  89602. +#include "dwc_otg_pcd.h"
  89603. +#include "dwc_otg_driver.h"
  89604. +#include "dwc_otg_dbg.h"
  89605. +
  89606. +static struct gadget_wrapper {
  89607. + dwc_otg_pcd_t *pcd;
  89608. +
  89609. + struct usb_gadget gadget;
  89610. + struct usb_gadget_driver *driver;
  89611. +
  89612. + struct usb_ep ep0;
  89613. + struct usb_ep in_ep[16];
  89614. + struct usb_ep out_ep[16];
  89615. +
  89616. +} *gadget_wrapper;
  89617. +
  89618. +/* Display the contents of the buffer */
  89619. +extern void dump_msg(const u8 * buf, unsigned int length);
  89620. +/**
  89621. + * Get the dwc_otg_pcd_ep_t* from usb_ep* pointer - NULL in case
  89622. + * if the endpoint is not found
  89623. + */
  89624. +static struct dwc_otg_pcd_ep *ep_from_handle(dwc_otg_pcd_t * pcd, void *handle)
  89625. +{
  89626. + int i;
  89627. + if (pcd->ep0.priv == handle) {
  89628. + return &pcd->ep0;
  89629. + }
  89630. +
  89631. + for (i = 0; i < MAX_EPS_CHANNELS - 1; i++) {
  89632. + if (pcd->in_ep[i].priv == handle)
  89633. + return &pcd->in_ep[i];
  89634. + if (pcd->out_ep[i].priv == handle)
  89635. + return &pcd->out_ep[i];
  89636. + }
  89637. +
  89638. + return NULL;
  89639. +}
  89640. +
  89641. +/* USB Endpoint Operations */
  89642. +/*
  89643. + * The following sections briefly describe the behavior of the Gadget
  89644. + * API endpoint operations implemented in the DWC_otg driver
  89645. + * software. Detailed descriptions of the generic behavior of each of
  89646. + * these functions can be found in the Linux header file
  89647. + * include/linux/usb_gadget.h.
  89648. + *
  89649. + * The Gadget API provides wrapper functions for each of the function
  89650. + * pointers defined in usb_ep_ops. The Gadget Driver calls the wrapper
  89651. + * function, which then calls the underlying PCD function. The
  89652. + * following sections are named according to the wrapper
  89653. + * functions. Within each section, the corresponding DWC_otg PCD
  89654. + * function name is specified.
  89655. + *
  89656. + */
  89657. +
  89658. +/**
  89659. + * This function is called by the Gadget Driver for each EP to be
  89660. + * configured for the current configuration (SET_CONFIGURATION).
  89661. + *
  89662. + * This function initializes the dwc_otg_ep_t data structure, and then
  89663. + * calls dwc_otg_ep_activate.
  89664. + */
  89665. +static int ep_enable(struct usb_ep *usb_ep,
  89666. + const struct usb_endpoint_descriptor *ep_desc)
  89667. +{
  89668. + int retval;
  89669. +
  89670. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%p)\n", __func__, usb_ep, ep_desc);
  89671. +
  89672. + if (!usb_ep || !ep_desc || ep_desc->bDescriptorType != USB_DT_ENDPOINT) {
  89673. + DWC_WARN("%s, bad ep or descriptor\n", __func__);
  89674. + return -EINVAL;
  89675. + }
  89676. + if (usb_ep == &gadget_wrapper->ep0) {
  89677. + DWC_WARN("%s, bad ep(0)\n", __func__);
  89678. + return -EINVAL;
  89679. + }
  89680. +
  89681. + /* Check FIFO size? */
  89682. + if (!ep_desc->wMaxPacketSize) {
  89683. + DWC_WARN("%s, bad %s maxpacket\n", __func__, usb_ep->name);
  89684. + return -ERANGE;
  89685. + }
  89686. +
  89687. + if (!gadget_wrapper->driver ||
  89688. + gadget_wrapper->gadget.speed == USB_SPEED_UNKNOWN) {
  89689. + DWC_WARN("%s, bogus device state\n", __func__);
  89690. + return -ESHUTDOWN;
  89691. + }
  89692. +
  89693. + /* Delete after check - MAS */
  89694. +#if 0
  89695. + nat = (uint32_t) ep_desc->wMaxPacketSize;
  89696. + printk(KERN_ALERT "%s: nat (before) =%d\n", __func__, nat);
  89697. + nat = (nat >> 11) & 0x03;
  89698. + printk(KERN_ALERT "%s: nat (after) =%d\n", __func__, nat);
  89699. +#endif
  89700. + retval = dwc_otg_pcd_ep_enable(gadget_wrapper->pcd,
  89701. + (const uint8_t *)ep_desc,
  89702. + (void *)usb_ep);
  89703. + if (retval) {
  89704. + DWC_WARN("dwc_otg_pcd_ep_enable failed\n");
  89705. + return -EINVAL;
  89706. + }
  89707. +
  89708. + usb_ep->maxpacket = le16_to_cpu(ep_desc->wMaxPacketSize);
  89709. +
  89710. + return 0;
  89711. +}
  89712. +
  89713. +/**
  89714. + * This function is called when an EP is disabled due to disconnect or
  89715. + * change in configuration. Any pending requests will terminate with a
  89716. + * status of -ESHUTDOWN.
  89717. + *
  89718. + * This function modifies the dwc_otg_ep_t data structure for this EP,
  89719. + * and then calls dwc_otg_ep_deactivate.
  89720. + */
  89721. +static int ep_disable(struct usb_ep *usb_ep)
  89722. +{
  89723. + int retval;
  89724. +
  89725. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, usb_ep);
  89726. + if (!usb_ep) {
  89727. + DWC_DEBUGPL(DBG_PCD, "%s, %s not enabled\n", __func__,
  89728. + usb_ep ? usb_ep->name : NULL);
  89729. + return -EINVAL;
  89730. + }
  89731. +
  89732. + retval = dwc_otg_pcd_ep_disable(gadget_wrapper->pcd, usb_ep);
  89733. + if (retval) {
  89734. + retval = -EINVAL;
  89735. + }
  89736. +
  89737. + return retval;
  89738. +}
  89739. +
  89740. +/**
  89741. + * This function allocates a request object to use with the specified
  89742. + * endpoint.
  89743. + *
  89744. + * @param ep The endpoint to be used with with the request
  89745. + * @param gfp_flags the GFP_* flags to use.
  89746. + */
  89747. +static struct usb_request *dwc_otg_pcd_alloc_request(struct usb_ep *ep,
  89748. + gfp_t gfp_flags)
  89749. +{
  89750. + struct usb_request *usb_req;
  89751. +
  89752. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%d)\n", __func__, ep, gfp_flags);
  89753. + if (0 == ep) {
  89754. + DWC_WARN("%s() %s\n", __func__, "Invalid EP!\n");
  89755. + return 0;
  89756. + }
  89757. + usb_req = kmalloc(sizeof(*usb_req), gfp_flags);
  89758. + if (0 == usb_req) {
  89759. + DWC_WARN("%s() %s\n", __func__, "request allocation failed!\n");
  89760. + return 0;
  89761. + }
  89762. + memset(usb_req, 0, sizeof(*usb_req));
  89763. + usb_req->dma = DWC_DMA_ADDR_INVALID;
  89764. +
  89765. + return usb_req;
  89766. +}
  89767. +
  89768. +/**
  89769. + * This function frees a request object.
  89770. + *
  89771. + * @param ep The endpoint associated with the request
  89772. + * @param req The request being freed
  89773. + */
  89774. +static void dwc_otg_pcd_free_request(struct usb_ep *ep, struct usb_request *req)
  89775. +{
  89776. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%p)\n", __func__, ep, req);
  89777. +
  89778. + if (0 == ep || 0 == req) {
  89779. + DWC_WARN("%s() %s\n", __func__,
  89780. + "Invalid ep or req argument!\n");
  89781. + return;
  89782. + }
  89783. +
  89784. + kfree(req);
  89785. +}
  89786. +
  89787. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  89788. +/**
  89789. + * This function allocates an I/O buffer to be used for a transfer
  89790. + * to/from the specified endpoint.
  89791. + *
  89792. + * @param usb_ep The endpoint to be used with with the request
  89793. + * @param bytes The desired number of bytes for the buffer
  89794. + * @param dma Pointer to the buffer's DMA address; must be valid
  89795. + * @param gfp_flags the GFP_* flags to use.
  89796. + * @return address of a new buffer or null is buffer could not be allocated.
  89797. + */
  89798. +static void *dwc_otg_pcd_alloc_buffer(struct usb_ep *usb_ep, unsigned bytes,
  89799. + dma_addr_t * dma, gfp_t gfp_flags)
  89800. +{
  89801. + void *buf;
  89802. + dwc_otg_pcd_t *pcd = 0;
  89803. +
  89804. + pcd = gadget_wrapper->pcd;
  89805. +
  89806. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%d,%p,%0x)\n", __func__, usb_ep, bytes,
  89807. + dma, gfp_flags);
  89808. +
  89809. + /* Check dword alignment */
  89810. + if ((bytes & 0x3UL) != 0) {
  89811. + DWC_WARN("%s() Buffer size is not a multiple of"
  89812. + "DWORD size (%d)", __func__, bytes);
  89813. + }
  89814. +
  89815. + buf = dma_alloc_coherent(NULL, bytes, dma, gfp_flags);
  89816. +
  89817. + /* Check dword alignment */
  89818. + if (((int)buf & 0x3UL) != 0) {
  89819. + DWC_WARN("%s() Buffer is not DWORD aligned (%p)",
  89820. + __func__, buf);
  89821. + }
  89822. +
  89823. + return buf;
  89824. +}
  89825. +
  89826. +/**
  89827. + * This function frees an I/O buffer that was allocated by alloc_buffer.
  89828. + *
  89829. + * @param usb_ep the endpoint associated with the buffer
  89830. + * @param buf address of the buffer
  89831. + * @param dma The buffer's DMA address
  89832. + * @param bytes The number of bytes of the buffer
  89833. + */
  89834. +static void dwc_otg_pcd_free_buffer(struct usb_ep *usb_ep, void *buf,
  89835. + dma_addr_t dma, unsigned bytes)
  89836. +{
  89837. + dwc_otg_pcd_t *pcd = 0;
  89838. +
  89839. + pcd = gadget_wrapper->pcd;
  89840. +
  89841. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%0x,%d)\n", __func__, buf, dma, bytes);
  89842. +
  89843. + dma_free_coherent(NULL, bytes, buf, dma);
  89844. +}
  89845. +#endif
  89846. +
  89847. +/**
  89848. + * This function is used to submit an I/O Request to an EP.
  89849. + *
  89850. + * - When the request completes the request's completion callback
  89851. + * is called to return the request to the driver.
  89852. + * - An EP, except control EPs, may have multiple requests
  89853. + * pending.
  89854. + * - Once submitted the request cannot be examined or modified.
  89855. + * - Each request is turned into one or more packets.
  89856. + * - A BULK EP can queue any amount of data; the transfer is
  89857. + * packetized.
  89858. + * - Zero length Packets are specified with the request 'zero'
  89859. + * flag.
  89860. + */
  89861. +static int ep_queue(struct usb_ep *usb_ep, struct usb_request *usb_req,
  89862. + gfp_t gfp_flags)
  89863. +{
  89864. + dwc_otg_pcd_t *pcd;
  89865. + struct dwc_otg_pcd_ep *ep = NULL;
  89866. + int retval = 0, is_isoc_ep = 0;
  89867. + dma_addr_t dma_addr = DWC_DMA_ADDR_INVALID;
  89868. +
  89869. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%p,%d)\n",
  89870. + __func__, usb_ep, usb_req, gfp_flags);
  89871. +
  89872. + if (!usb_req || !usb_req->complete || !usb_req->buf) {
  89873. + DWC_WARN("bad params\n");
  89874. + return -EINVAL;
  89875. + }
  89876. +
  89877. + if (!usb_ep) {
  89878. + DWC_WARN("bad ep\n");
  89879. + return -EINVAL;
  89880. + }
  89881. +
  89882. + pcd = gadget_wrapper->pcd;
  89883. + if (!gadget_wrapper->driver ||
  89884. + gadget_wrapper->gadget.speed == USB_SPEED_UNKNOWN) {
  89885. + DWC_DEBUGPL(DBG_PCDV, "gadget.speed=%d\n",
  89886. + gadget_wrapper->gadget.speed);
  89887. + DWC_WARN("bogus device state\n");
  89888. + return -ESHUTDOWN;
  89889. + }
  89890. +
  89891. + DWC_DEBUGPL(DBG_PCD, "%s queue req %p, len %d buf %p\n",
  89892. + usb_ep->name, usb_req, usb_req->length, usb_req->buf);
  89893. +
  89894. + usb_req->status = -EINPROGRESS;
  89895. + usb_req->actual = 0;
  89896. +
  89897. + ep = ep_from_handle(pcd, usb_ep);
  89898. + if (ep == NULL)
  89899. + is_isoc_ep = 0;
  89900. + else
  89901. + is_isoc_ep = (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) ? 1 : 0;
  89902. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  89903. + dma_addr = usb_req->dma;
  89904. +#else
  89905. + if (GET_CORE_IF(pcd)->dma_enable) {
  89906. + dwc_otg_device_t *otg_dev = gadget_wrapper->pcd->otg_dev;
  89907. + struct device *dev = NULL;
  89908. +
  89909. + if (otg_dev != NULL)
  89910. + dev = DWC_OTG_OS_GETDEV(otg_dev->os_dep);
  89911. +
  89912. + if (usb_req->length != 0 &&
  89913. + usb_req->dma == DWC_DMA_ADDR_INVALID) {
  89914. + dma_addr = dma_map_single(dev, usb_req->buf,
  89915. + usb_req->length,
  89916. + ep->dwc_ep.is_in ?
  89917. + DMA_TO_DEVICE:
  89918. + DMA_FROM_DEVICE);
  89919. + }
  89920. + }
  89921. +#endif
  89922. +
  89923. +#ifdef DWC_UTE_PER_IO
  89924. + if (is_isoc_ep == 1) {
  89925. + retval = dwc_otg_pcd_xiso_ep_queue(pcd, usb_ep, usb_req->buf, dma_addr,
  89926. + usb_req->length, usb_req->zero, usb_req,
  89927. + gfp_flags == GFP_ATOMIC ? 1 : 0, &usb_req->ext_req);
  89928. + if (retval)
  89929. + return -EINVAL;
  89930. +
  89931. + return 0;
  89932. + }
  89933. +#endif
  89934. + retval = dwc_otg_pcd_ep_queue(pcd, usb_ep, usb_req->buf, dma_addr,
  89935. + usb_req->length, usb_req->zero, usb_req,
  89936. + gfp_flags == GFP_ATOMIC ? 1 : 0);
  89937. + if (retval) {
  89938. + return -EINVAL;
  89939. + }
  89940. +
  89941. + return 0;
  89942. +}
  89943. +
  89944. +/**
  89945. + * This function cancels an I/O request from an EP.
  89946. + */
  89947. +static int ep_dequeue(struct usb_ep *usb_ep, struct usb_request *usb_req)
  89948. +{
  89949. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%p)\n", __func__, usb_ep, usb_req);
  89950. +
  89951. + if (!usb_ep || !usb_req) {
  89952. + DWC_WARN("bad argument\n");
  89953. + return -EINVAL;
  89954. + }
  89955. + if (!gadget_wrapper->driver ||
  89956. + gadget_wrapper->gadget.speed == USB_SPEED_UNKNOWN) {
  89957. + DWC_WARN("bogus device state\n");
  89958. + return -ESHUTDOWN;
  89959. + }
  89960. + if (dwc_otg_pcd_ep_dequeue(gadget_wrapper->pcd, usb_ep, usb_req)) {
  89961. + return -EINVAL;
  89962. + }
  89963. +
  89964. + return 0;
  89965. +}
  89966. +
  89967. +/**
  89968. + * usb_ep_set_halt stalls an endpoint.
  89969. + *
  89970. + * usb_ep_clear_halt clears an endpoint halt and resets its data
  89971. + * toggle.
  89972. + *
  89973. + * Both of these functions are implemented with the same underlying
  89974. + * function. The behavior depends on the value argument.
  89975. + *
  89976. + * @param[in] usb_ep the Endpoint to halt or clear halt.
  89977. + * @param[in] value
  89978. + * - 0 means clear_halt.
  89979. + * - 1 means set_halt,
  89980. + * - 2 means clear stall lock flag.
  89981. + * - 3 means set stall lock flag.
  89982. + */
  89983. +static int ep_halt(struct usb_ep *usb_ep, int value)
  89984. +{
  89985. + int retval = 0;
  89986. +
  89987. + DWC_DEBUGPL(DBG_PCD, "HALT %s %d\n", usb_ep->name, value);
  89988. +
  89989. + if (!usb_ep) {
  89990. + DWC_WARN("bad ep\n");
  89991. + return -EINVAL;
  89992. + }
  89993. +
  89994. + retval = dwc_otg_pcd_ep_halt(gadget_wrapper->pcd, usb_ep, value);
  89995. + if (retval == -DWC_E_AGAIN) {
  89996. + return -EAGAIN;
  89997. + } else if (retval) {
  89998. + retval = -EINVAL;
  89999. + }
  90000. +
  90001. + return retval;
  90002. +}
  90003. +
  90004. +//#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30))
  90005. +#if 0
  90006. +/**
  90007. + * ep_wedge: sets the halt feature and ignores clear requests
  90008. + *
  90009. + * @usb_ep: the endpoint being wedged
  90010. + *
  90011. + * Use this to stall an endpoint and ignore CLEAR_FEATURE(HALT_ENDPOINT)
  90012. + * requests. If the gadget driver clears the halt status, it will
  90013. + * automatically unwedge the endpoint.
  90014. + *
  90015. + * Returns zero on success, else negative errno. *
  90016. + * Check usb_ep_set_wedge() at "usb_gadget.h" for details
  90017. + */
  90018. +static int ep_wedge(struct usb_ep *usb_ep)
  90019. +{
  90020. + int retval = 0;
  90021. +
  90022. + DWC_DEBUGPL(DBG_PCD, "WEDGE %s\n", usb_ep->name);
  90023. +
  90024. + if (!usb_ep) {
  90025. + DWC_WARN("bad ep\n");
  90026. + return -EINVAL;
  90027. + }
  90028. +
  90029. + retval = dwc_otg_pcd_ep_wedge(gadget_wrapper->pcd, usb_ep);
  90030. + if (retval == -DWC_E_AGAIN) {
  90031. + retval = -EAGAIN;
  90032. + } else if (retval) {
  90033. + retval = -EINVAL;
  90034. + }
  90035. +
  90036. + return retval;
  90037. +}
  90038. +#endif
  90039. +
  90040. +#ifdef DWC_EN_ISOC
  90041. +/**
  90042. + * This function is used to submit an ISOC Transfer Request to an EP.
  90043. + *
  90044. + * - Every time a sync period completes the request's completion callback
  90045. + * is called to provide data to the gadget driver.
  90046. + * - Once submitted the request cannot be modified.
  90047. + * - Each request is turned into periodic data packets untill ISO
  90048. + * Transfer is stopped..
  90049. + */
  90050. +static int iso_ep_start(struct usb_ep *usb_ep, struct usb_iso_request *req,
  90051. + gfp_t gfp_flags)
  90052. +{
  90053. + int retval = 0;
  90054. +
  90055. + if (!req || !req->process_buffer || !req->buf0 || !req->buf1) {
  90056. + DWC_WARN("bad params\n");
  90057. + return -EINVAL;
  90058. + }
  90059. +
  90060. + if (!usb_ep) {
  90061. + DWC_PRINTF("bad params\n");
  90062. + return -EINVAL;
  90063. + }
  90064. +
  90065. + req->status = -EINPROGRESS;
  90066. +
  90067. + retval =
  90068. + dwc_otg_pcd_iso_ep_start(gadget_wrapper->pcd, usb_ep, req->buf0,
  90069. + req->buf1, req->dma0, req->dma1,
  90070. + req->sync_frame, req->data_pattern_frame,
  90071. + req->data_per_frame,
  90072. + req->
  90073. + flags & USB_REQ_ISO_ASAP ? -1 :
  90074. + req->start_frame, req->buf_proc_intrvl,
  90075. + req, gfp_flags == GFP_ATOMIC ? 1 : 0);
  90076. +
  90077. + if (retval) {
  90078. + return -EINVAL;
  90079. + }
  90080. +
  90081. + return retval;
  90082. +}
  90083. +
  90084. +/**
  90085. + * This function stops ISO EP Periodic Data Transfer.
  90086. + */
  90087. +static int iso_ep_stop(struct usb_ep *usb_ep, struct usb_iso_request *req)
  90088. +{
  90089. + int retval = 0;
  90090. + if (!usb_ep) {
  90091. + DWC_WARN("bad ep\n");
  90092. + }
  90093. +
  90094. + if (!gadget_wrapper->driver ||
  90095. + gadget_wrapper->gadget.speed == USB_SPEED_UNKNOWN) {
  90096. + DWC_DEBUGPL(DBG_PCDV, "gadget.speed=%d\n",
  90097. + gadget_wrapper->gadget.speed);
  90098. + DWC_WARN("bogus device state\n");
  90099. + }
  90100. +
  90101. + dwc_otg_pcd_iso_ep_stop(gadget_wrapper->pcd, usb_ep, req);
  90102. + if (retval) {
  90103. + retval = -EINVAL;
  90104. + }
  90105. +
  90106. + return retval;
  90107. +}
  90108. +
  90109. +static struct usb_iso_request *alloc_iso_request(struct usb_ep *ep,
  90110. + int packets, gfp_t gfp_flags)
  90111. +{
  90112. + struct usb_iso_request *pReq = NULL;
  90113. + uint32_t req_size;
  90114. +
  90115. + req_size = sizeof(struct usb_iso_request);
  90116. + req_size +=
  90117. + (2 * packets * (sizeof(struct usb_gadget_iso_packet_descriptor)));
  90118. +
  90119. + pReq = kmalloc(req_size, gfp_flags);
  90120. + if (!pReq) {
  90121. + DWC_WARN("Can't allocate Iso Request\n");
  90122. + return 0;
  90123. + }
  90124. + pReq->iso_packet_desc0 = (void *)(pReq + 1);
  90125. +
  90126. + pReq->iso_packet_desc1 = pReq->iso_packet_desc0 + packets;
  90127. +
  90128. + return pReq;
  90129. +}
  90130. +
  90131. +static void free_iso_request(struct usb_ep *ep, struct usb_iso_request *req)
  90132. +{
  90133. + kfree(req);
  90134. +}
  90135. +
  90136. +static struct usb_isoc_ep_ops dwc_otg_pcd_ep_ops = {
  90137. + .ep_ops = {
  90138. + .enable = ep_enable,
  90139. + .disable = ep_disable,
  90140. +
  90141. + .alloc_request = dwc_otg_pcd_alloc_request,
  90142. + .free_request = dwc_otg_pcd_free_request,
  90143. +
  90144. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  90145. + .alloc_buffer = dwc_otg_pcd_alloc_buffer,
  90146. + .free_buffer = dwc_otg_pcd_free_buffer,
  90147. +#endif
  90148. +
  90149. + .queue = ep_queue,
  90150. + .dequeue = ep_dequeue,
  90151. +
  90152. + .set_halt = ep_halt,
  90153. + .fifo_status = 0,
  90154. + .fifo_flush = 0,
  90155. + },
  90156. + .iso_ep_start = iso_ep_start,
  90157. + .iso_ep_stop = iso_ep_stop,
  90158. + .alloc_iso_request = alloc_iso_request,
  90159. + .free_iso_request = free_iso_request,
  90160. +};
  90161. +
  90162. +#else
  90163. +
  90164. + int (*enable) (struct usb_ep *ep,
  90165. + const struct usb_endpoint_descriptor *desc);
  90166. + int (*disable) (struct usb_ep *ep);
  90167. +
  90168. + struct usb_request *(*alloc_request) (struct usb_ep *ep,
  90169. + gfp_t gfp_flags);
  90170. + void (*free_request) (struct usb_ep *ep, struct usb_request *req);
  90171. +
  90172. + int (*queue) (struct usb_ep *ep, struct usb_request *req,
  90173. + gfp_t gfp_flags);
  90174. + int (*dequeue) (struct usb_ep *ep, struct usb_request *req);
  90175. +
  90176. + int (*set_halt) (struct usb_ep *ep, int value);
  90177. + int (*set_wedge) (struct usb_ep *ep);
  90178. +
  90179. + int (*fifo_status) (struct usb_ep *ep);
  90180. + void (*fifo_flush) (struct usb_ep *ep);
  90181. +static struct usb_ep_ops dwc_otg_pcd_ep_ops = {
  90182. + .enable = ep_enable,
  90183. + .disable = ep_disable,
  90184. +
  90185. + .alloc_request = dwc_otg_pcd_alloc_request,
  90186. + .free_request = dwc_otg_pcd_free_request,
  90187. +
  90188. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  90189. + .alloc_buffer = dwc_otg_pcd_alloc_buffer,
  90190. + .free_buffer = dwc_otg_pcd_free_buffer,
  90191. +#else
  90192. + /* .set_wedge = ep_wedge, */
  90193. + .set_wedge = NULL, /* uses set_halt instead */
  90194. +#endif
  90195. +
  90196. + .queue = ep_queue,
  90197. + .dequeue = ep_dequeue,
  90198. +
  90199. + .set_halt = ep_halt,
  90200. + .fifo_status = 0,
  90201. + .fifo_flush = 0,
  90202. +
  90203. +};
  90204. +
  90205. +#endif /* _EN_ISOC_ */
  90206. +/* Gadget Operations */
  90207. +/**
  90208. + * The following gadget operations will be implemented in the DWC_otg
  90209. + * PCD. Functions in the API that are not described below are not
  90210. + * implemented.
  90211. + *
  90212. + * The Gadget API provides wrapper functions for each of the function
  90213. + * pointers defined in usb_gadget_ops. The Gadget Driver calls the
  90214. + * wrapper function, which then calls the underlying PCD function. The
  90215. + * following sections are named according to the wrapper functions
  90216. + * (except for ioctl, which doesn't have a wrapper function). Within
  90217. + * each section, the corresponding DWC_otg PCD function name is
  90218. + * specified.
  90219. + *
  90220. + */
  90221. +
  90222. +/**
  90223. + *Gets the USB Frame number of the last SOF.
  90224. + */
  90225. +static int get_frame_number(struct usb_gadget *gadget)
  90226. +{
  90227. + struct gadget_wrapper *d;
  90228. +
  90229. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, gadget);
  90230. +
  90231. + if (gadget == 0) {
  90232. + return -ENODEV;
  90233. + }
  90234. +
  90235. + d = container_of(gadget, struct gadget_wrapper, gadget);
  90236. + return dwc_otg_pcd_get_frame_number(d->pcd);
  90237. +}
  90238. +
  90239. +#ifdef CONFIG_USB_DWC_OTG_LPM
  90240. +static int test_lpm_enabled(struct usb_gadget *gadget)
  90241. +{
  90242. + struct gadget_wrapper *d;
  90243. +
  90244. + d = container_of(gadget, struct gadget_wrapper, gadget);
  90245. +
  90246. + return dwc_otg_pcd_is_lpm_enabled(d->pcd);
  90247. +}
  90248. +#endif
  90249. +
  90250. +/**
  90251. + * Initiates Session Request Protocol (SRP) to wakeup the host if no
  90252. + * session is in progress. If a session is already in progress, but
  90253. + * the device is suspended, remote wakeup signaling is started.
  90254. + *
  90255. + */
  90256. +static int wakeup(struct usb_gadget *gadget)
  90257. +{
  90258. + struct gadget_wrapper *d;
  90259. +
  90260. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, gadget);
  90261. +
  90262. + if (gadget == 0) {
  90263. + return -ENODEV;
  90264. + } else {
  90265. + d = container_of(gadget, struct gadget_wrapper, gadget);
  90266. + }
  90267. + dwc_otg_pcd_wakeup(d->pcd);
  90268. + return 0;
  90269. +}
  90270. +
  90271. +static const struct usb_gadget_ops dwc_otg_pcd_ops = {
  90272. + .get_frame = get_frame_number,
  90273. + .wakeup = wakeup,
  90274. +#ifdef CONFIG_USB_DWC_OTG_LPM
  90275. + .lpm_support = test_lpm_enabled,
  90276. +#endif
  90277. + // current versions must always be self-powered
  90278. +};
  90279. +
  90280. +static int _setup(dwc_otg_pcd_t * pcd, uint8_t * bytes)
  90281. +{
  90282. + int retval = -DWC_E_NOT_SUPPORTED;
  90283. + if (gadget_wrapper->driver && gadget_wrapper->driver->setup) {
  90284. + retval = gadget_wrapper->driver->setup(&gadget_wrapper->gadget,
  90285. + (struct usb_ctrlrequest
  90286. + *)bytes);
  90287. + }
  90288. +
  90289. + if (retval == -ENOTSUPP) {
  90290. + retval = -DWC_E_NOT_SUPPORTED;
  90291. + } else if (retval < 0) {
  90292. + retval = -DWC_E_INVALID;
  90293. + }
  90294. +
  90295. + return retval;
  90296. +}
  90297. +
  90298. +#ifdef DWC_EN_ISOC
  90299. +static int _isoc_complete(dwc_otg_pcd_t * pcd, void *ep_handle,
  90300. + void *req_handle, int proc_buf_num)
  90301. +{
  90302. + int i, packet_count;
  90303. + struct usb_gadget_iso_packet_descriptor *iso_packet = 0;
  90304. + struct usb_iso_request *iso_req = req_handle;
  90305. +
  90306. + if (proc_buf_num) {
  90307. + iso_packet = iso_req->iso_packet_desc1;
  90308. + } else {
  90309. + iso_packet = iso_req->iso_packet_desc0;
  90310. + }
  90311. + packet_count =
  90312. + dwc_otg_pcd_get_iso_packet_count(pcd, ep_handle, req_handle);
  90313. + for (i = 0; i < packet_count; ++i) {
  90314. + int status;
  90315. + int actual;
  90316. + int offset;
  90317. + dwc_otg_pcd_get_iso_packet_params(pcd, ep_handle, req_handle,
  90318. + i, &status, &actual, &offset);
  90319. + switch (status) {
  90320. + case -DWC_E_NO_DATA:
  90321. + status = -ENODATA;
  90322. + break;
  90323. + default:
  90324. + if (status) {
  90325. + DWC_PRINTF("unknown status in isoc packet\n");
  90326. + }
  90327. +
  90328. + }
  90329. + iso_packet[i].status = status;
  90330. + iso_packet[i].offset = offset;
  90331. + iso_packet[i].actual_length = actual;
  90332. + }
  90333. +
  90334. + iso_req->status = 0;
  90335. + iso_req->process_buffer(ep_handle, iso_req);
  90336. +
  90337. + return 0;
  90338. +}
  90339. +#endif /* DWC_EN_ISOC */
  90340. +
  90341. +#ifdef DWC_UTE_PER_IO
  90342. +/**
  90343. + * Copy the contents of the extended request to the Linux usb_request's
  90344. + * extended part and call the gadget's completion.
  90345. + *
  90346. + * @param pcd Pointer to the pcd structure
  90347. + * @param ep_handle Void pointer to the usb_ep structure
  90348. + * @param req_handle Void pointer to the usb_request structure
  90349. + * @param status Request status returned from the portable logic
  90350. + * @param ereq_port Void pointer to the extended request structure
  90351. + * created in the the portable part that contains the
  90352. + * results of the processed iso packets.
  90353. + */
  90354. +static int _xisoc_complete(dwc_otg_pcd_t * pcd, void *ep_handle,
  90355. + void *req_handle, int32_t status, void *ereq_port)
  90356. +{
  90357. + struct dwc_ute_iso_req_ext *ereqorg = NULL;
  90358. + struct dwc_iso_xreq_port *ereqport = NULL;
  90359. + struct dwc_ute_iso_packet_descriptor *desc_org = NULL;
  90360. + int i;
  90361. + struct usb_request *req;
  90362. + //struct dwc_ute_iso_packet_descriptor *
  90363. + //int status = 0;
  90364. +
  90365. + req = (struct usb_request *)req_handle;
  90366. + ereqorg = &req->ext_req;
  90367. + ereqport = (struct dwc_iso_xreq_port *)ereq_port;
  90368. + desc_org = ereqorg->per_io_frame_descs;
  90369. +
  90370. + if (req && req->complete) {
  90371. + /* Copy the request data from the portable logic to our request */
  90372. + for (i = 0; i < ereqport->pio_pkt_count; i++) {
  90373. + desc_org[i].actual_length =
  90374. + ereqport->per_io_frame_descs[i].actual_length;
  90375. + desc_org[i].status =
  90376. + ereqport->per_io_frame_descs[i].status;
  90377. + }
  90378. +
  90379. + switch (status) {
  90380. + case -DWC_E_SHUTDOWN:
  90381. + req->status = -ESHUTDOWN;
  90382. + break;
  90383. + case -DWC_E_RESTART:
  90384. + req->status = -ECONNRESET;
  90385. + break;
  90386. + case -DWC_E_INVALID:
  90387. + req->status = -EINVAL;
  90388. + break;
  90389. + case -DWC_E_TIMEOUT:
  90390. + req->status = -ETIMEDOUT;
  90391. + break;
  90392. + default:
  90393. + req->status = status;
  90394. + }
  90395. +
  90396. + /* And call the gadget's completion */
  90397. + req->complete(ep_handle, req);
  90398. + }
  90399. +
  90400. + return 0;
  90401. +}
  90402. +#endif /* DWC_UTE_PER_IO */
  90403. +
  90404. +static int _complete(dwc_otg_pcd_t * pcd, void *ep_handle,
  90405. + void *req_handle, int32_t status, uint32_t actual)
  90406. +{
  90407. + struct usb_request *req = (struct usb_request *)req_handle;
  90408. +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,27)
  90409. + struct dwc_otg_pcd_ep *ep = NULL;
  90410. +#endif
  90411. +
  90412. + if (req && req->complete) {
  90413. + switch (status) {
  90414. + case -DWC_E_SHUTDOWN:
  90415. + req->status = -ESHUTDOWN;
  90416. + break;
  90417. + case -DWC_E_RESTART:
  90418. + req->status = -ECONNRESET;
  90419. + break;
  90420. + case -DWC_E_INVALID:
  90421. + req->status = -EINVAL;
  90422. + break;
  90423. + case -DWC_E_TIMEOUT:
  90424. + req->status = -ETIMEDOUT;
  90425. + break;
  90426. + default:
  90427. + req->status = status;
  90428. +
  90429. + }
  90430. +
  90431. + req->actual = actual;
  90432. + DWC_SPINUNLOCK(pcd->lock);
  90433. + req->complete(ep_handle, req);
  90434. + DWC_SPINLOCK(pcd->lock);
  90435. + }
  90436. +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,27)
  90437. + ep = ep_from_handle(pcd, ep_handle);
  90438. + if (GET_CORE_IF(pcd)->dma_enable) {
  90439. + if (req->length != 0) {
  90440. + dwc_otg_device_t *otg_dev = gadget_wrapper->pcd->otg_dev;
  90441. + struct device *dev = NULL;
  90442. +
  90443. + if (otg_dev != NULL)
  90444. + dev = DWC_OTG_OS_GETDEV(otg_dev->os_dep);
  90445. +
  90446. + dma_unmap_single(dev, req->dma, req->length,
  90447. + ep->dwc_ep.is_in ?
  90448. + DMA_TO_DEVICE: DMA_FROM_DEVICE);
  90449. + }
  90450. + }
  90451. +#endif
  90452. +
  90453. + return 0;
  90454. +}
  90455. +
  90456. +static int _connect(dwc_otg_pcd_t * pcd, int speed)
  90457. +{
  90458. + gadget_wrapper->gadget.speed = speed;
  90459. + return 0;
  90460. +}
  90461. +
  90462. +static int _disconnect(dwc_otg_pcd_t * pcd)
  90463. +{
  90464. + if (gadget_wrapper->driver && gadget_wrapper->driver->disconnect) {
  90465. + gadget_wrapper->driver->disconnect(&gadget_wrapper->gadget);
  90466. + }
  90467. + return 0;
  90468. +}
  90469. +
  90470. +static int _resume(dwc_otg_pcd_t * pcd)
  90471. +{
  90472. + if (gadget_wrapper->driver && gadget_wrapper->driver->resume) {
  90473. + gadget_wrapper->driver->resume(&gadget_wrapper->gadget);
  90474. + }
  90475. +
  90476. + return 0;
  90477. +}
  90478. +
  90479. +static int _suspend(dwc_otg_pcd_t * pcd)
  90480. +{
  90481. + if (gadget_wrapper->driver && gadget_wrapper->driver->suspend) {
  90482. + gadget_wrapper->driver->suspend(&gadget_wrapper->gadget);
  90483. + }
  90484. + return 0;
  90485. +}
  90486. +
  90487. +/**
  90488. + * This function updates the otg values in the gadget structure.
  90489. + */
  90490. +static int _hnp_changed(dwc_otg_pcd_t * pcd)
  90491. +{
  90492. +
  90493. + if (!gadget_wrapper->gadget.is_otg)
  90494. + return 0;
  90495. +
  90496. + gadget_wrapper->gadget.b_hnp_enable = get_b_hnp_enable(pcd);
  90497. + gadget_wrapper->gadget.a_hnp_support = get_a_hnp_support(pcd);
  90498. + gadget_wrapper->gadget.a_alt_hnp_support = get_a_alt_hnp_support(pcd);
  90499. + return 0;
  90500. +}
  90501. +
  90502. +static int _reset(dwc_otg_pcd_t * pcd)
  90503. +{
  90504. + return 0;
  90505. +}
  90506. +
  90507. +#ifdef DWC_UTE_CFI
  90508. +static int _cfi_setup(dwc_otg_pcd_t * pcd, void *cfi_req)
  90509. +{
  90510. + int retval = -DWC_E_INVALID;
  90511. + if (gadget_wrapper->driver->cfi_feature_setup) {
  90512. + retval =
  90513. + gadget_wrapper->driver->
  90514. + cfi_feature_setup(&gadget_wrapper->gadget,
  90515. + (struct cfi_usb_ctrlrequest *)cfi_req);
  90516. + }
  90517. +
  90518. + return retval;
  90519. +}
  90520. +#endif
  90521. +
  90522. +static const struct dwc_otg_pcd_function_ops fops = {
  90523. + .complete = _complete,
  90524. +#ifdef DWC_EN_ISOC
  90525. + .isoc_complete = _isoc_complete,
  90526. +#endif
  90527. + .setup = _setup,
  90528. + .disconnect = _disconnect,
  90529. + .connect = _connect,
  90530. + .resume = _resume,
  90531. + .suspend = _suspend,
  90532. + .hnp_changed = _hnp_changed,
  90533. + .reset = _reset,
  90534. +#ifdef DWC_UTE_CFI
  90535. + .cfi_setup = _cfi_setup,
  90536. +#endif
  90537. +#ifdef DWC_UTE_PER_IO
  90538. + .xisoc_complete = _xisoc_complete,
  90539. +#endif
  90540. +};
  90541. +
  90542. +/**
  90543. + * This function is the top level PCD interrupt handler.
  90544. + */
  90545. +static irqreturn_t dwc_otg_pcd_irq(int irq, void *dev)
  90546. +{
  90547. + dwc_otg_pcd_t *pcd = dev;
  90548. + int32_t retval = IRQ_NONE;
  90549. +
  90550. + retval = dwc_otg_pcd_handle_intr(pcd);
  90551. + if (retval != 0) {
  90552. + S3C2410X_CLEAR_EINTPEND();
  90553. + }
  90554. + return IRQ_RETVAL(retval);
  90555. +}
  90556. +
  90557. +/**
  90558. + * This function initialized the usb_ep structures to there default
  90559. + * state.
  90560. + *
  90561. + * @param d Pointer on gadget_wrapper.
  90562. + */
  90563. +void gadget_add_eps(struct gadget_wrapper *d)
  90564. +{
  90565. + static const char *names[] = {
  90566. +
  90567. + "ep0",
  90568. + "ep1in",
  90569. + "ep2in",
  90570. + "ep3in",
  90571. + "ep4in",
  90572. + "ep5in",
  90573. + "ep6in",
  90574. + "ep7in",
  90575. + "ep8in",
  90576. + "ep9in",
  90577. + "ep10in",
  90578. + "ep11in",
  90579. + "ep12in",
  90580. + "ep13in",
  90581. + "ep14in",
  90582. + "ep15in",
  90583. + "ep1out",
  90584. + "ep2out",
  90585. + "ep3out",
  90586. + "ep4out",
  90587. + "ep5out",
  90588. + "ep6out",
  90589. + "ep7out",
  90590. + "ep8out",
  90591. + "ep9out",
  90592. + "ep10out",
  90593. + "ep11out",
  90594. + "ep12out",
  90595. + "ep13out",
  90596. + "ep14out",
  90597. + "ep15out"
  90598. + };
  90599. +
  90600. + int i;
  90601. + struct usb_ep *ep;
  90602. + int8_t dev_endpoints;
  90603. +
  90604. + DWC_DEBUGPL(DBG_PCDV, "%s\n", __func__);
  90605. +
  90606. + INIT_LIST_HEAD(&d->gadget.ep_list);
  90607. + d->gadget.ep0 = &d->ep0;
  90608. + d->gadget.speed = USB_SPEED_UNKNOWN;
  90609. +
  90610. + INIT_LIST_HEAD(&d->gadget.ep0->ep_list);
  90611. +
  90612. + /**
  90613. + * Initialize the EP0 structure.
  90614. + */
  90615. + ep = &d->ep0;
  90616. +
  90617. + /* Init the usb_ep structure. */
  90618. + ep->name = names[0];
  90619. + ep->ops = (struct usb_ep_ops *)&dwc_otg_pcd_ep_ops;
  90620. +
  90621. + /**
  90622. + * @todo NGS: What should the max packet size be set to
  90623. + * here? Before EP type is set?
  90624. + */
  90625. + ep->maxpacket = MAX_PACKET_SIZE;
  90626. + dwc_otg_pcd_ep_enable(d->pcd, NULL, ep);
  90627. +
  90628. + list_add_tail(&ep->ep_list, &d->gadget.ep_list);
  90629. +
  90630. + /**
  90631. + * Initialize the EP structures.
  90632. + */
  90633. + dev_endpoints = d->pcd->core_if->dev_if->num_in_eps;
  90634. +
  90635. + for (i = 0; i < dev_endpoints; i++) {
  90636. + ep = &d->in_ep[i];
  90637. +
  90638. + /* Init the usb_ep structure. */
  90639. + ep->name = names[d->pcd->in_ep[i].dwc_ep.num];
  90640. + ep->ops = (struct usb_ep_ops *)&dwc_otg_pcd_ep_ops;
  90641. +
  90642. + /**
  90643. + * @todo NGS: What should the max packet size be set to
  90644. + * here? Before EP type is set?
  90645. + */
  90646. + ep->maxpacket = MAX_PACKET_SIZE;
  90647. + list_add_tail(&ep->ep_list, &d->gadget.ep_list);
  90648. + }
  90649. +
  90650. + dev_endpoints = d->pcd->core_if->dev_if->num_out_eps;
  90651. +
  90652. + for (i = 0; i < dev_endpoints; i++) {
  90653. + ep = &d->out_ep[i];
  90654. +
  90655. + /* Init the usb_ep structure. */
  90656. + ep->name = names[15 + d->pcd->out_ep[i].dwc_ep.num];
  90657. + ep->ops = (struct usb_ep_ops *)&dwc_otg_pcd_ep_ops;
  90658. +
  90659. + /**
  90660. + * @todo NGS: What should the max packet size be set to
  90661. + * here? Before EP type is set?
  90662. + */
  90663. + ep->maxpacket = MAX_PACKET_SIZE;
  90664. +
  90665. + list_add_tail(&ep->ep_list, &d->gadget.ep_list);
  90666. + }
  90667. +
  90668. + /* remove ep0 from the list. There is a ep0 pointer. */
  90669. + list_del_init(&d->ep0.ep_list);
  90670. +
  90671. + d->ep0.maxpacket = MAX_EP0_SIZE;
  90672. +}
  90673. +
  90674. +/**
  90675. + * This function releases the Gadget device.
  90676. + * required by device_unregister().
  90677. + *
  90678. + * @todo Should this do something? Should it free the PCD?
  90679. + */
  90680. +static void dwc_otg_pcd_gadget_release(struct device *dev)
  90681. +{
  90682. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, dev);
  90683. +}
  90684. +
  90685. +static struct gadget_wrapper *alloc_wrapper(dwc_bus_dev_t *_dev)
  90686. +{
  90687. + static char pcd_name[] = "dwc_otg_pcd";
  90688. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  90689. + struct gadget_wrapper *d;
  90690. + int retval;
  90691. +
  90692. + d = DWC_ALLOC(sizeof(*d));
  90693. + if (d == NULL) {
  90694. + return NULL;
  90695. + }
  90696. +
  90697. + memset(d, 0, sizeof(*d));
  90698. +
  90699. + d->gadget.name = pcd_name;
  90700. + d->pcd = otg_dev->pcd;
  90701. +
  90702. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
  90703. + strcpy(d->gadget.dev.bus_id, "gadget");
  90704. +#else
  90705. + dev_set_name(&d->gadget.dev, "%s", "gadget");
  90706. +#endif
  90707. +
  90708. + d->gadget.dev.parent = &_dev->dev;
  90709. + d->gadget.dev.release = dwc_otg_pcd_gadget_release;
  90710. + d->gadget.ops = &dwc_otg_pcd_ops;
  90711. + d->gadget.max_speed = dwc_otg_pcd_is_dualspeed(otg_dev->pcd) ? USB_SPEED_HIGH:USB_SPEED_FULL;
  90712. + d->gadget.is_otg = dwc_otg_pcd_is_otg(otg_dev->pcd);
  90713. +
  90714. + d->driver = 0;
  90715. + /* Register the gadget device */
  90716. + retval = device_register(&d->gadget.dev);
  90717. + if (retval != 0) {
  90718. + DWC_ERROR("device_register failed\n");
  90719. + DWC_FREE(d);
  90720. + return NULL;
  90721. + }
  90722. +
  90723. + return d;
  90724. +}
  90725. +
  90726. +static void free_wrapper(struct gadget_wrapper *d)
  90727. +{
  90728. + if (d->driver) {
  90729. + /* should have been done already by driver model core */
  90730. + DWC_WARN("driver '%s' is still registered\n",
  90731. + d->driver->driver.name);
  90732. + usb_gadget_unregister_driver(d->driver);
  90733. + }
  90734. +
  90735. + device_unregister(&d->gadget.dev);
  90736. + DWC_FREE(d);
  90737. +}
  90738. +
  90739. +/**
  90740. + * This function initialized the PCD portion of the driver.
  90741. + *
  90742. + */
  90743. +int pcd_init(dwc_bus_dev_t *_dev)
  90744. +{
  90745. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  90746. + int retval = 0;
  90747. +
  90748. + DWC_DEBUGPL(DBG_PCDV, "%s(%p) otg_dev=%p\n", __func__, _dev, otg_dev);
  90749. +
  90750. + otg_dev->pcd = dwc_otg_pcd_init(otg_dev->core_if);
  90751. +
  90752. + if (!otg_dev->pcd) {
  90753. + DWC_ERROR("dwc_otg_pcd_init failed\n");
  90754. + return -ENOMEM;
  90755. + }
  90756. +
  90757. + otg_dev->pcd->otg_dev = otg_dev;
  90758. + gadget_wrapper = alloc_wrapper(_dev);
  90759. +
  90760. + /*
  90761. + * Initialize EP structures
  90762. + */
  90763. + gadget_add_eps(gadget_wrapper);
  90764. + /*
  90765. + * Setup interupt handler
  90766. + */
  90767. +#ifdef PLATFORM_INTERFACE
  90768. + DWC_DEBUGPL(DBG_ANY, "registering handler for irq%d\n",
  90769. + platform_get_irq(_dev, 0));
  90770. + retval = request_irq(platform_get_irq(_dev, 0), dwc_otg_pcd_irq,
  90771. + IRQF_SHARED, gadget_wrapper->gadget.name,
  90772. + otg_dev->pcd);
  90773. + if (retval != 0) {
  90774. + DWC_ERROR("request of irq%d failed\n",
  90775. + platform_get_irq(_dev, 0));
  90776. + free_wrapper(gadget_wrapper);
  90777. + return -EBUSY;
  90778. + }
  90779. +#else
  90780. + DWC_DEBUGPL(DBG_ANY, "registering handler for irq%d\n",
  90781. + _dev->irq);
  90782. + retval = request_irq(_dev->irq, dwc_otg_pcd_irq,
  90783. + IRQF_SHARED | IRQF_DISABLED,
  90784. + gadget_wrapper->gadget.name, otg_dev->pcd);
  90785. + if (retval != 0) {
  90786. + DWC_ERROR("request of irq%d failed\n", _dev->irq);
  90787. + free_wrapper(gadget_wrapper);
  90788. + return -EBUSY;
  90789. + }
  90790. +#endif
  90791. +
  90792. + dwc_otg_pcd_start(gadget_wrapper->pcd, &fops);
  90793. +
  90794. + return retval;
  90795. +}
  90796. +
  90797. +/**
  90798. + * Cleanup the PCD.
  90799. + */
  90800. +void pcd_remove(dwc_bus_dev_t *_dev)
  90801. +{
  90802. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  90803. + dwc_otg_pcd_t *pcd = otg_dev->pcd;
  90804. +
  90805. + DWC_DEBUGPL(DBG_PCDV, "%s(%p) otg_dev %p\n", __func__, _dev, otg_dev);
  90806. +
  90807. + /*
  90808. + * Free the IRQ
  90809. + */
  90810. +#ifdef PLATFORM_INTERFACE
  90811. + free_irq(platform_get_irq(_dev, 0), pcd);
  90812. +#else
  90813. + free_irq(_dev->irq, pcd);
  90814. +#endif
  90815. + dwc_otg_pcd_remove(otg_dev->pcd);
  90816. + free_wrapper(gadget_wrapper);
  90817. + otg_dev->pcd = 0;
  90818. +}
  90819. +
  90820. +/**
  90821. + * This function registers a gadget driver with the PCD.
  90822. + *
  90823. + * When a driver is successfully registered, it will receive control
  90824. + * requests including set_configuration(), which enables non-control
  90825. + * requests. then usb traffic follows until a disconnect is reported.
  90826. + * then a host may connect again, or the driver might get unbound.
  90827. + *
  90828. + * @param driver The driver being registered
  90829. + * @param bind The bind function of gadget driver
  90830. + */
  90831. +
  90832. +int usb_gadget_probe_driver(struct usb_gadget_driver *driver)
  90833. +{
  90834. + int retval;
  90835. +
  90836. + DWC_DEBUGPL(DBG_PCD, "registering gadget driver '%s'\n",
  90837. + driver->driver.name);
  90838. +
  90839. + if (!driver || driver->max_speed == USB_SPEED_UNKNOWN ||
  90840. + !driver->bind ||
  90841. + !driver->unbind || !driver->disconnect || !driver->setup) {
  90842. + DWC_DEBUGPL(DBG_PCDV, "EINVAL\n");
  90843. + return -EINVAL;
  90844. + }
  90845. + if (gadget_wrapper == 0) {
  90846. + DWC_DEBUGPL(DBG_PCDV, "ENODEV\n");
  90847. + return -ENODEV;
  90848. + }
  90849. + if (gadget_wrapper->driver != 0) {
  90850. + DWC_DEBUGPL(DBG_PCDV, "EBUSY (%p)\n", gadget_wrapper->driver);
  90851. + return -EBUSY;
  90852. + }
  90853. +
  90854. + /* hook up the driver */
  90855. + gadget_wrapper->driver = driver;
  90856. + gadget_wrapper->gadget.dev.driver = &driver->driver;
  90857. +
  90858. + DWC_DEBUGPL(DBG_PCD, "bind to driver %s\n", driver->driver.name);
  90859. + retval = driver->bind(&gadget_wrapper->gadget, gadget_wrapper->driver);
  90860. + if (retval) {
  90861. + DWC_ERROR("bind to driver %s --> error %d\n",
  90862. + driver->driver.name, retval);
  90863. + gadget_wrapper->driver = 0;
  90864. + gadget_wrapper->gadget.dev.driver = 0;
  90865. + return retval;
  90866. + }
  90867. + DWC_DEBUGPL(DBG_ANY, "registered gadget driver '%s'\n",
  90868. + driver->driver.name);
  90869. + return 0;
  90870. +}
  90871. +EXPORT_SYMBOL(usb_gadget_probe_driver);
  90872. +
  90873. +/**
  90874. + * This function unregisters a gadget driver
  90875. + *
  90876. + * @param driver The driver being unregistered
  90877. + */
  90878. +int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
  90879. +{
  90880. + //DWC_DEBUGPL(DBG_PCDV,"%s(%p)\n", __func__, _driver);
  90881. +
  90882. + if (gadget_wrapper == 0) {
  90883. + DWC_DEBUGPL(DBG_ANY, "%s Return(%d): s_pcd==0\n", __func__,
  90884. + -ENODEV);
  90885. + return -ENODEV;
  90886. + }
  90887. + if (driver == 0 || driver != gadget_wrapper->driver) {
  90888. + DWC_DEBUGPL(DBG_ANY, "%s Return(%d): driver?\n", __func__,
  90889. + -EINVAL);
  90890. + return -EINVAL;
  90891. + }
  90892. +
  90893. + driver->unbind(&gadget_wrapper->gadget);
  90894. + gadget_wrapper->driver = 0;
  90895. +
  90896. + DWC_DEBUGPL(DBG_ANY, "unregistered driver '%s'\n", driver->driver.name);
  90897. + return 0;
  90898. +}
  90899. +
  90900. +EXPORT_SYMBOL(usb_gadget_unregister_driver);
  90901. +
  90902. +#endif /* DWC_HOST_ONLY */
  90903. diff -Nur linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_regs.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_regs.h
  90904. --- linux-3.13.11/drivers/usb/host/dwc_otg/dwc_otg_regs.h 1970-01-01 01:00:00.000000000 +0100
  90905. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_regs.h 2014-04-24 15:37:13.318990576 +0200
  90906. @@ -0,0 +1,2550 @@
  90907. +/* ==========================================================================
  90908. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_regs.h $
  90909. + * $Revision: #98 $
  90910. + * $Date: 2012/08/10 $
  90911. + * $Change: 2047372 $
  90912. + *
  90913. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  90914. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  90915. + * otherwise expressly agreed to in writing between Synopsys and you.
  90916. + *
  90917. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  90918. + * any End User Software License Agreement or Agreement for Licensed Product
  90919. + * with Synopsys or any supplement thereto. You are permitted to use and
  90920. + * redistribute this Software in source and binary forms, with or without
  90921. + * modification, provided that redistributions of source code must retain this
  90922. + * notice. You may not view, use, disclose, copy or distribute this file or
  90923. + * any information contained herein except pursuant to this license grant from
  90924. + * Synopsys. If you do not agree with this notice, including the disclaimer
  90925. + * below, then you are not authorized to use the Software.
  90926. + *
  90927. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  90928. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  90929. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  90930. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  90931. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  90932. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  90933. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  90934. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  90935. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  90936. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  90937. + * DAMAGE.
  90938. + * ========================================================================== */
  90939. +
  90940. +#ifndef __DWC_OTG_REGS_H__
  90941. +#define __DWC_OTG_REGS_H__
  90942. +
  90943. +#include "dwc_otg_core_if.h"
  90944. +
  90945. +/**
  90946. + * @file
  90947. + *
  90948. + * This file contains the data structures for accessing the DWC_otg core registers.
  90949. + *
  90950. + * The application interfaces with the HS OTG core by reading from and
  90951. + * writing to the Control and Status Register (CSR) space through the
  90952. + * AHB Slave interface. These registers are 32 bits wide, and the
  90953. + * addresses are 32-bit-block aligned.
  90954. + * CSRs are classified as follows:
  90955. + * - Core Global Registers
  90956. + * - Device Mode Registers
  90957. + * - Device Global Registers
  90958. + * - Device Endpoint Specific Registers
  90959. + * - Host Mode Registers
  90960. + * - Host Global Registers
  90961. + * - Host Port CSRs
  90962. + * - Host Channel Specific Registers
  90963. + *
  90964. + * Only the Core Global registers can be accessed in both Device and
  90965. + * Host modes. When the HS OTG core is operating in one mode, either
  90966. + * Device or Host, the application must not access registers from the
  90967. + * other mode. When the core switches from one mode to another, the
  90968. + * registers in the new mode of operation must be reprogrammed as they
  90969. + * would be after a power-on reset.
  90970. + */
  90971. +
  90972. +/****************************************************************************/
  90973. +/** DWC_otg Core registers .
  90974. + * The dwc_otg_core_global_regs structure defines the size
  90975. + * and relative field offsets for the Core Global registers.
  90976. + */
  90977. +typedef struct dwc_otg_core_global_regs {
  90978. + /** OTG Control and Status Register. <i>Offset: 000h</i> */
  90979. + volatile uint32_t gotgctl;
  90980. + /** OTG Interrupt Register. <i>Offset: 004h</i> */
  90981. + volatile uint32_t gotgint;
  90982. + /**Core AHB Configuration Register. <i>Offset: 008h</i> */
  90983. + volatile uint32_t gahbcfg;
  90984. +
  90985. +#define DWC_GLBINTRMASK 0x0001
  90986. +#define DWC_DMAENABLE 0x0020
  90987. +#define DWC_NPTXEMPTYLVL_EMPTY 0x0080
  90988. +#define DWC_NPTXEMPTYLVL_HALFEMPTY 0x0000
  90989. +#define DWC_PTXEMPTYLVL_EMPTY 0x0100
  90990. +#define DWC_PTXEMPTYLVL_HALFEMPTY 0x0000
  90991. +
  90992. + /**Core USB Configuration Register. <i>Offset: 00Ch</i> */
  90993. + volatile uint32_t gusbcfg;
  90994. + /**Core Reset Register. <i>Offset: 010h</i> */
  90995. + volatile uint32_t grstctl;
  90996. + /**Core Interrupt Register. <i>Offset: 014h</i> */
  90997. + volatile uint32_t gintsts;
  90998. + /**Core Interrupt Mask Register. <i>Offset: 018h</i> */
  90999. + volatile uint32_t gintmsk;
  91000. + /**Receive Status Queue Read Register (Read Only). <i>Offset: 01Ch</i> */
  91001. + volatile uint32_t grxstsr;
  91002. + /**Receive Status Queue Read & POP Register (Read Only). <i>Offset: 020h</i>*/
  91003. + volatile uint32_t grxstsp;
  91004. + /**Receive FIFO Size Register. <i>Offset: 024h</i> */
  91005. + volatile uint32_t grxfsiz;
  91006. + /**Non Periodic Transmit FIFO Size Register. <i>Offset: 028h</i> */
  91007. + volatile uint32_t gnptxfsiz;
  91008. + /**Non Periodic Transmit FIFO/Queue Status Register (Read
  91009. + * Only). <i>Offset: 02Ch</i> */
  91010. + volatile uint32_t gnptxsts;
  91011. + /**I2C Access Register. <i>Offset: 030h</i> */
  91012. + volatile uint32_t gi2cctl;
  91013. + /**PHY Vendor Control Register. <i>Offset: 034h</i> */
  91014. + volatile uint32_t gpvndctl;
  91015. + /**General Purpose Input/Output Register. <i>Offset: 038h</i> */
  91016. + volatile uint32_t ggpio;
  91017. + /**User ID Register. <i>Offset: 03Ch</i> */
  91018. + volatile uint32_t guid;
  91019. + /**Synopsys ID Register (Read Only). <i>Offset: 040h</i> */
  91020. + volatile uint32_t gsnpsid;
  91021. + /**User HW Config1 Register (Read Only). <i>Offset: 044h</i> */
  91022. + volatile uint32_t ghwcfg1;
  91023. + /**User HW Config2 Register (Read Only). <i>Offset: 048h</i> */
  91024. + volatile uint32_t ghwcfg2;
  91025. +#define DWC_SLAVE_ONLY_ARCH 0
  91026. +#define DWC_EXT_DMA_ARCH 1
  91027. +#define DWC_INT_DMA_ARCH 2
  91028. +
  91029. +#define DWC_MODE_HNP_SRP_CAPABLE 0
  91030. +#define DWC_MODE_SRP_ONLY_CAPABLE 1
  91031. +#define DWC_MODE_NO_HNP_SRP_CAPABLE 2
  91032. +#define DWC_MODE_SRP_CAPABLE_DEVICE 3
  91033. +#define DWC_MODE_NO_SRP_CAPABLE_DEVICE 4
  91034. +#define DWC_MODE_SRP_CAPABLE_HOST 5
  91035. +#define DWC_MODE_NO_SRP_CAPABLE_HOST 6
  91036. +
  91037. + /**User HW Config3 Register (Read Only). <i>Offset: 04Ch</i> */
  91038. + volatile uint32_t ghwcfg3;
  91039. + /**User HW Config4 Register (Read Only). <i>Offset: 050h</i>*/
  91040. + volatile uint32_t ghwcfg4;
  91041. + /** Core LPM Configuration register <i>Offset: 054h</i>*/
  91042. + volatile uint32_t glpmcfg;
  91043. + /** Global PowerDn Register <i>Offset: 058h</i> */
  91044. + volatile uint32_t gpwrdn;
  91045. + /** Global DFIFO SW Config Register <i>Offset: 05Ch</i> */
  91046. + volatile uint32_t gdfifocfg;
  91047. + /** ADP Control Register <i>Offset: 060h</i> */
  91048. + volatile uint32_t adpctl;
  91049. + /** Reserved <i>Offset: 064h-0FFh</i> */
  91050. + volatile uint32_t reserved39[39];
  91051. + /** Host Periodic Transmit FIFO Size Register. <i>Offset: 100h</i> */
  91052. + volatile uint32_t hptxfsiz;
  91053. + /** Device Periodic Transmit FIFO#n Register if dedicated fifos are disabled,
  91054. + otherwise Device Transmit FIFO#n Register.
  91055. + * <i>Offset: 104h + (FIFO_Number-1)*04h, 1 <= FIFO Number <= 15 (1<=n<=15).</i> */
  91056. + volatile uint32_t dtxfsiz[15];
  91057. +} dwc_otg_core_global_regs_t;
  91058. +
  91059. +/**
  91060. + * This union represents the bit fields of the Core OTG Control
  91061. + * and Status Register (GOTGCTL). Set the bits using the bit
  91062. + * fields then write the <i>d32</i> value to the register.
  91063. + */
  91064. +typedef union gotgctl_data {
  91065. + /** raw register data */
  91066. + uint32_t d32;
  91067. + /** register bits */
  91068. + struct {
  91069. + unsigned sesreqscs:1;
  91070. + unsigned sesreq:1;
  91071. + unsigned vbvalidoven:1;
  91072. + unsigned vbvalidovval:1;
  91073. + unsigned avalidoven:1;
  91074. + unsigned avalidovval:1;
  91075. + unsigned bvalidoven:1;
  91076. + unsigned bvalidovval:1;
  91077. + unsigned hstnegscs:1;
  91078. + unsigned hnpreq:1;
  91079. + unsigned hstsethnpen:1;
  91080. + unsigned devhnpen:1;
  91081. + unsigned reserved12_15:4;
  91082. + unsigned conidsts:1;
  91083. + unsigned dbnctime:1;
  91084. + unsigned asesvld:1;
  91085. + unsigned bsesvld:1;
  91086. + unsigned otgver:1;
  91087. + unsigned reserved1:1;
  91088. + unsigned multvalidbc:5;
  91089. + unsigned chirpen:1;
  91090. + unsigned reserved28_31:4;
  91091. + } b;
  91092. +} gotgctl_data_t;
  91093. +
  91094. +/**
  91095. + * This union represents the bit fields of the Core OTG Interrupt Register
  91096. + * (GOTGINT). Set/clear the bits using the bit fields then write the <i>d32</i>
  91097. + * value to the register.
  91098. + */
  91099. +typedef union gotgint_data {
  91100. + /** raw register data */
  91101. + uint32_t d32;
  91102. + /** register bits */
  91103. + struct {
  91104. + /** Current Mode */
  91105. + unsigned reserved0_1:2;
  91106. +
  91107. + /** Session End Detected */
  91108. + unsigned sesenddet:1;
  91109. +
  91110. + unsigned reserved3_7:5;
  91111. +
  91112. + /** Session Request Success Status Change */
  91113. + unsigned sesreqsucstschng:1;
  91114. + /** Host Negotiation Success Status Change */
  91115. + unsigned hstnegsucstschng:1;
  91116. +
  91117. + unsigned reserved10_16:7;
  91118. +
  91119. + /** Host Negotiation Detected */
  91120. + unsigned hstnegdet:1;
  91121. + /** A-Device Timeout Change */
  91122. + unsigned adevtoutchng:1;
  91123. + /** Debounce Done */
  91124. + unsigned debdone:1;
  91125. + /** Multi-Valued input changed */
  91126. + unsigned mvic:1;
  91127. +
  91128. + unsigned reserved31_21:11;
  91129. +
  91130. + } b;
  91131. +} gotgint_data_t;
  91132. +
  91133. +/**
  91134. + * This union represents the bit fields of the Core AHB Configuration
  91135. + * Register (GAHBCFG). Set/clear the bits using the bit fields then
  91136. + * write the <i>d32</i> value to the register.
  91137. + */
  91138. +typedef union gahbcfg_data {
  91139. + /** raw register data */
  91140. + uint32_t d32;
  91141. + /** register bits */
  91142. + struct {
  91143. + unsigned glblintrmsk:1;
  91144. +#define DWC_GAHBCFG_GLBINT_ENABLE 1
  91145. +
  91146. + unsigned hburstlen:4;
  91147. +#define DWC_GAHBCFG_INT_DMA_BURST_SINGLE 0
  91148. +#define DWC_GAHBCFG_INT_DMA_BURST_INCR 1
  91149. +#define DWC_GAHBCFG_INT_DMA_BURST_INCR4 3
  91150. +#define DWC_GAHBCFG_INT_DMA_BURST_INCR8 5
  91151. +#define DWC_GAHBCFG_INT_DMA_BURST_INCR16 7
  91152. +
  91153. + unsigned dmaenable:1;
  91154. +#define DWC_GAHBCFG_DMAENABLE 1
  91155. + unsigned reserved:1;
  91156. + unsigned nptxfemplvl_txfemplvl:1;
  91157. + unsigned ptxfemplvl:1;
  91158. +#define DWC_GAHBCFG_TXFEMPTYLVL_EMPTY 1
  91159. +#define DWC_GAHBCFG_TXFEMPTYLVL_HALFEMPTY 0
  91160. + unsigned reserved9_20:12;
  91161. + unsigned remmemsupp:1;
  91162. + unsigned notialldmawrit:1;
  91163. + unsigned ahbsingle:1;
  91164. + unsigned reserved24_31:8;
  91165. + } b;
  91166. +} gahbcfg_data_t;
  91167. +
  91168. +/**
  91169. + * This union represents the bit fields of the Core USB Configuration
  91170. + * Register (GUSBCFG). Set the bits using the bit fields then write
  91171. + * the <i>d32</i> value to the register.
  91172. + */
  91173. +typedef union gusbcfg_data {
  91174. + /** raw register data */
  91175. + uint32_t d32;
  91176. + /** register bits */
  91177. + struct {
  91178. + unsigned toutcal:3;
  91179. + unsigned phyif:1;
  91180. + unsigned ulpi_utmi_sel:1;
  91181. + unsigned fsintf:1;
  91182. + unsigned physel:1;
  91183. + unsigned ddrsel:1;
  91184. + unsigned srpcap:1;
  91185. + unsigned hnpcap:1;
  91186. + unsigned usbtrdtim:4;
  91187. + unsigned reserved1:1;
  91188. + unsigned phylpwrclksel:1;
  91189. + unsigned otgutmifssel:1;
  91190. + unsigned ulpi_fsls:1;
  91191. + unsigned ulpi_auto_res:1;
  91192. + unsigned ulpi_clk_sus_m:1;
  91193. + unsigned ulpi_ext_vbus_drv:1;
  91194. + unsigned ulpi_int_vbus_indicator:1;
  91195. + unsigned term_sel_dl_pulse:1;
  91196. + unsigned indicator_complement:1;
  91197. + unsigned indicator_pass_through:1;
  91198. + unsigned ulpi_int_prot_dis:1;
  91199. + unsigned ic_usb_cap:1;
  91200. + unsigned ic_traffic_pull_remove:1;
  91201. + unsigned tx_end_delay:1;
  91202. + unsigned force_host_mode:1;
  91203. + unsigned force_dev_mode:1;
  91204. + unsigned reserved31:1;
  91205. + } b;
  91206. +} gusbcfg_data_t;
  91207. +
  91208. +/**
  91209. + * This union represents the bit fields of the Core Reset Register
  91210. + * (GRSTCTL). Set/clear the bits using the bit fields then write the
  91211. + * <i>d32</i> value to the register.
  91212. + */
  91213. +typedef union grstctl_data {
  91214. + /** raw register data */
  91215. + uint32_t d32;
  91216. + /** register bits */
  91217. + struct {
  91218. + /** Core Soft Reset (CSftRst) (Device and Host)
  91219. + *
  91220. + * The application can flush the control logic in the
  91221. + * entire core using this bit. This bit resets the
  91222. + * pipelines in the AHB Clock domain as well as the
  91223. + * PHY Clock domain.
  91224. + *
  91225. + * The state machines are reset to an IDLE state, the
  91226. + * control bits in the CSRs are cleared, all the
  91227. + * transmit FIFOs and the receive FIFO are flushed.
  91228. + *
  91229. + * The status mask bits that control the generation of
  91230. + * the interrupt, are cleared, to clear the
  91231. + * interrupt. The interrupt status bits are not
  91232. + * cleared, so the application can get the status of
  91233. + * any events that occurred in the core after it has
  91234. + * set this bit.
  91235. + *
  91236. + * Any transactions on the AHB are terminated as soon
  91237. + * as possible following the protocol. Any
  91238. + * transactions on the USB are terminated immediately.
  91239. + *
  91240. + * The configuration settings in the CSRs are
  91241. + * unchanged, so the software doesn't have to
  91242. + * reprogram these registers (Device
  91243. + * Configuration/Host Configuration/Core System
  91244. + * Configuration/Core PHY Configuration).
  91245. + *
  91246. + * The application can write to this bit, any time it
  91247. + * wants to reset the core. This is a self clearing
  91248. + * bit and the core clears this bit after all the
  91249. + * necessary logic is reset in the core, which may
  91250. + * take several clocks, depending on the current state
  91251. + * of the core.
  91252. + */
  91253. + unsigned csftrst:1;
  91254. + /** Hclk Soft Reset
  91255. + *
  91256. + * The application uses this bit to reset the control logic in
  91257. + * the AHB clock domain. Only AHB clock domain pipelines are
  91258. + * reset.
  91259. + */
  91260. + unsigned hsftrst:1;
  91261. + /** Host Frame Counter Reset (Host Only)<br>
  91262. + *
  91263. + * The application can reset the (micro)frame number
  91264. + * counter inside the core, using this bit. When the
  91265. + * (micro)frame counter is reset, the subsequent SOF
  91266. + * sent out by the core, will have a (micro)frame
  91267. + * number of 0.
  91268. + */
  91269. + unsigned hstfrm:1;
  91270. + /** In Token Sequence Learning Queue Flush
  91271. + * (INTknQFlsh) (Device Only)
  91272. + */
  91273. + unsigned intknqflsh:1;
  91274. + /** RxFIFO Flush (RxFFlsh) (Device and Host)
  91275. + *
  91276. + * The application can flush the entire Receive FIFO
  91277. + * using this bit. The application must first
  91278. + * ensure that the core is not in the middle of a
  91279. + * transaction. The application should write into
  91280. + * this bit, only after making sure that neither the
  91281. + * DMA engine is reading from the RxFIFO nor the MAC
  91282. + * is writing the data in to the FIFO. The
  91283. + * application should wait until the bit is cleared
  91284. + * before performing any other operations. This bit
  91285. + * will takes 8 clocks (slowest of PHY or AHB clock)
  91286. + * to clear.
  91287. + */
  91288. + unsigned rxfflsh:1;
  91289. + /** TxFIFO Flush (TxFFlsh) (Device and Host).
  91290. + *
  91291. + * This bit is used to selectively flush a single or
  91292. + * all transmit FIFOs. The application must first
  91293. + * ensure that the core is not in the middle of a
  91294. + * transaction. The application should write into
  91295. + * this bit, only after making sure that neither the
  91296. + * DMA engine is writing into the TxFIFO nor the MAC
  91297. + * is reading the data out of the FIFO. The
  91298. + * application should wait until the core clears this
  91299. + * bit, before performing any operations. This bit
  91300. + * will takes 8 clocks (slowest of PHY or AHB clock)
  91301. + * to clear.
  91302. + */
  91303. + unsigned txfflsh:1;
  91304. +
  91305. + /** TxFIFO Number (TxFNum) (Device and Host).
  91306. + *
  91307. + * This is the FIFO number which needs to be flushed,
  91308. + * using the TxFIFO Flush bit. This field should not
  91309. + * be changed until the TxFIFO Flush bit is cleared by
  91310. + * the core.
  91311. + * - 0x0 : Non Periodic TxFIFO Flush
  91312. + * - 0x1 : Periodic TxFIFO #1 Flush in device mode
  91313. + * or Periodic TxFIFO in host mode
  91314. + * - 0x2 : Periodic TxFIFO #2 Flush in device mode.
  91315. + * - ...
  91316. + * - 0xF : Periodic TxFIFO #15 Flush in device mode
  91317. + * - 0x10: Flush all the Transmit NonPeriodic and
  91318. + * Transmit Periodic FIFOs in the core
  91319. + */
  91320. + unsigned txfnum:5;
  91321. + /** Reserved */
  91322. + unsigned reserved11_29:19;
  91323. + /** DMA Request Signal. Indicated DMA request is in
  91324. + * probress. Used for debug purpose. */
  91325. + unsigned dmareq:1;
  91326. + /** AHB Master Idle. Indicates the AHB Master State
  91327. + * Machine is in IDLE condition. */
  91328. + unsigned ahbidle:1;
  91329. + } b;
  91330. +} grstctl_t;
  91331. +
  91332. +/**
  91333. + * This union represents the bit fields of the Core Interrupt Mask
  91334. + * Register (GINTMSK). Set/clear the bits using the bit fields then
  91335. + * write the <i>d32</i> value to the register.
  91336. + */
  91337. +typedef union gintmsk_data {
  91338. + /** raw register data */
  91339. + uint32_t d32;
  91340. + /** register bits */
  91341. + struct {
  91342. + unsigned reserved0:1;
  91343. + unsigned modemismatch:1;
  91344. + unsigned otgintr:1;
  91345. + unsigned sofintr:1;
  91346. + unsigned rxstsqlvl:1;
  91347. + unsigned nptxfempty:1;
  91348. + unsigned ginnakeff:1;
  91349. + unsigned goutnakeff:1;
  91350. + unsigned ulpickint:1;
  91351. + unsigned i2cintr:1;
  91352. + unsigned erlysuspend:1;
  91353. + unsigned usbsuspend:1;
  91354. + unsigned usbreset:1;
  91355. + unsigned enumdone:1;
  91356. + unsigned isooutdrop:1;
  91357. + unsigned eopframe:1;
  91358. + unsigned restoredone:1;
  91359. + unsigned epmismatch:1;
  91360. + unsigned inepintr:1;
  91361. + unsigned outepintr:1;
  91362. + unsigned incomplisoin:1;
  91363. + unsigned incomplisoout:1;
  91364. + unsigned fetsusp:1;
  91365. + unsigned resetdet:1;
  91366. + unsigned portintr:1;
  91367. + unsigned hcintr:1;
  91368. + unsigned ptxfempty:1;
  91369. + unsigned lpmtranrcvd:1;
  91370. + unsigned conidstschng:1;
  91371. + unsigned disconnect:1;
  91372. + unsigned sessreqintr:1;
  91373. + unsigned wkupintr:1;
  91374. + } b;
  91375. +} gintmsk_data_t;
  91376. +/**
  91377. + * This union represents the bit fields of the Core Interrupt Register
  91378. + * (GINTSTS). Set/clear the bits using the bit fields then write the
  91379. + * <i>d32</i> value to the register.
  91380. + */
  91381. +typedef union gintsts_data {
  91382. + /** raw register data */
  91383. + uint32_t d32;
  91384. +#define DWC_SOF_INTR_MASK 0x0008
  91385. + /** register bits */
  91386. + struct {
  91387. +#define DWC_HOST_MODE 1
  91388. + unsigned curmode:1;
  91389. + unsigned modemismatch:1;
  91390. + unsigned otgintr:1;
  91391. + unsigned sofintr:1;
  91392. + unsigned rxstsqlvl:1;
  91393. + unsigned nptxfempty:1;
  91394. + unsigned ginnakeff:1;
  91395. + unsigned goutnakeff:1;
  91396. + unsigned ulpickint:1;
  91397. + unsigned i2cintr:1;
  91398. + unsigned erlysuspend:1;
  91399. + unsigned usbsuspend:1;
  91400. + unsigned usbreset:1;
  91401. + unsigned enumdone:1;
  91402. + unsigned isooutdrop:1;
  91403. + unsigned eopframe:1;
  91404. + unsigned restoredone:1;
  91405. + unsigned epmismatch:1;
  91406. + unsigned inepint:1;
  91407. + unsigned outepintr:1;
  91408. + unsigned incomplisoin:1;
  91409. + unsigned incomplisoout:1;
  91410. + unsigned fetsusp:1;
  91411. + unsigned resetdet:1;
  91412. + unsigned portintr:1;
  91413. + unsigned hcintr:1;
  91414. + unsigned ptxfempty:1;
  91415. + unsigned lpmtranrcvd:1;
  91416. + unsigned conidstschng:1;
  91417. + unsigned disconnect:1;
  91418. + unsigned sessreqintr:1;
  91419. + unsigned wkupintr:1;
  91420. + } b;
  91421. +} gintsts_data_t;
  91422. +
  91423. +/**
  91424. + * This union represents the bit fields in the Device Receive Status Read and
  91425. + * Pop Registers (GRXSTSR, GRXSTSP) Read the register into the <i>d32</i>
  91426. + * element then read out the bits using the <i>b</i>it elements.
  91427. + */
  91428. +typedef union device_grxsts_data {
  91429. + /** raw register data */
  91430. + uint32_t d32;
  91431. + /** register bits */
  91432. + struct {
  91433. + unsigned epnum:4;
  91434. + unsigned bcnt:11;
  91435. + unsigned dpid:2;
  91436. +
  91437. +#define DWC_STS_DATA_UPDT 0x2 // OUT Data Packet
  91438. +#define DWC_STS_XFER_COMP 0x3 // OUT Data Transfer Complete
  91439. +
  91440. +#define DWC_DSTS_GOUT_NAK 0x1 // Global OUT NAK
  91441. +#define DWC_DSTS_SETUP_COMP 0x4 // Setup Phase Complete
  91442. +#define DWC_DSTS_SETUP_UPDT 0x6 // SETUP Packet
  91443. + unsigned pktsts:4;
  91444. + unsigned fn:4;
  91445. + unsigned reserved25_31:7;
  91446. + } b;
  91447. +} device_grxsts_data_t;
  91448. +
  91449. +/**
  91450. + * This union represents the bit fields in the Host Receive Status Read and
  91451. + * Pop Registers (GRXSTSR, GRXSTSP) Read the register into the <i>d32</i>
  91452. + * element then read out the bits using the <i>b</i>it elements.
  91453. + */
  91454. +typedef union host_grxsts_data {
  91455. + /** raw register data */
  91456. + uint32_t d32;
  91457. + /** register bits */
  91458. + struct {
  91459. + unsigned chnum:4;
  91460. + unsigned bcnt:11;
  91461. + unsigned dpid:2;
  91462. +
  91463. + unsigned pktsts:4;
  91464. +#define DWC_GRXSTS_PKTSTS_IN 0x2
  91465. +#define DWC_GRXSTS_PKTSTS_IN_XFER_COMP 0x3
  91466. +#define DWC_GRXSTS_PKTSTS_DATA_TOGGLE_ERR 0x5
  91467. +#define DWC_GRXSTS_PKTSTS_CH_HALTED 0x7
  91468. +
  91469. + unsigned reserved21_31:11;
  91470. + } b;
  91471. +} host_grxsts_data_t;
  91472. +
  91473. +/**
  91474. + * This union represents the bit fields in the FIFO Size Registers (HPTXFSIZ,
  91475. + * GNPTXFSIZ, DPTXFSIZn, DIEPTXFn). Read the register into the <i>d32</i> element
  91476. + * then read out the bits using the <i>b</i>it elements.
  91477. + */
  91478. +typedef union fifosize_data {
  91479. + /** raw register data */
  91480. + uint32_t d32;
  91481. + /** register bits */
  91482. + struct {
  91483. + unsigned startaddr:16;
  91484. + unsigned depth:16;
  91485. + } b;
  91486. +} fifosize_data_t;
  91487. +
  91488. +/**
  91489. + * This union represents the bit fields in the Non-Periodic Transmit
  91490. + * FIFO/Queue Status Register (GNPTXSTS). Read the register into the
  91491. + * <i>d32</i> element then read out the bits using the <i>b</i>it
  91492. + * elements.
  91493. + */
  91494. +typedef union gnptxsts_data {
  91495. + /** raw register data */
  91496. + uint32_t d32;
  91497. + /** register bits */
  91498. + struct {
  91499. + unsigned nptxfspcavail:16;
  91500. + unsigned nptxqspcavail:8;
  91501. + /** Top of the Non-Periodic Transmit Request Queue
  91502. + * - bit 24 - Terminate (Last entry for the selected
  91503. + * channel/EP)
  91504. + * - bits 26:25 - Token Type
  91505. + * - 2'b00 - IN/OUT
  91506. + * - 2'b01 - Zero Length OUT
  91507. + * - 2'b10 - PING/Complete Split
  91508. + * - 2'b11 - Channel Halt
  91509. + * - bits 30:27 - Channel/EP Number
  91510. + */
  91511. + unsigned nptxqtop_terminate:1;
  91512. + unsigned nptxqtop_token:2;
  91513. + unsigned nptxqtop_chnep:4;
  91514. + unsigned reserved:1;
  91515. + } b;
  91516. +} gnptxsts_data_t;
  91517. +
  91518. +/**
  91519. + * This union represents the bit fields in the Transmit
  91520. + * FIFO Status Register (DTXFSTS). Read the register into the
  91521. + * <i>d32</i> element then read out the bits using the <i>b</i>it
  91522. + * elements.
  91523. + */
  91524. +typedef union dtxfsts_data {
  91525. + /** raw register data */
  91526. + uint32_t d32;
  91527. + /** register bits */
  91528. + struct {
  91529. + unsigned txfspcavail:16;
  91530. + unsigned reserved:16;
  91531. + } b;
  91532. +} dtxfsts_data_t;
  91533. +
  91534. +/**
  91535. + * This union represents the bit fields in the I2C Control Register
  91536. + * (I2CCTL). Read the register into the <i>d32</i> element then read out the
  91537. + * bits using the <i>b</i>it elements.
  91538. + */
  91539. +typedef union gi2cctl_data {
  91540. + /** raw register data */
  91541. + uint32_t d32;
  91542. + /** register bits */
  91543. + struct {
  91544. + unsigned rwdata:8;
  91545. + unsigned regaddr:8;
  91546. + unsigned addr:7;
  91547. + unsigned i2cen:1;
  91548. + unsigned ack:1;
  91549. + unsigned i2csuspctl:1;
  91550. + unsigned i2cdevaddr:2;
  91551. + unsigned i2cdatse0:1;
  91552. + unsigned reserved:1;
  91553. + unsigned rw:1;
  91554. + unsigned bsydne:1;
  91555. + } b;
  91556. +} gi2cctl_data_t;
  91557. +
  91558. +/**
  91559. + * This union represents the bit fields in the PHY Vendor Control Register
  91560. + * (GPVNDCTL). Read the register into the <i>d32</i> element then read out the
  91561. + * bits using the <i>b</i>it elements.
  91562. + */
  91563. +typedef union gpvndctl_data {
  91564. + /** raw register data */
  91565. + uint32_t d32;
  91566. + /** register bits */
  91567. + struct {
  91568. + unsigned regdata:8;
  91569. + unsigned vctrl:8;
  91570. + unsigned regaddr16_21:6;
  91571. + unsigned regwr:1;
  91572. + unsigned reserved23_24:2;
  91573. + unsigned newregreq:1;
  91574. + unsigned vstsbsy:1;
  91575. + unsigned vstsdone:1;
  91576. + unsigned reserved28_30:3;
  91577. + unsigned disulpidrvr:1;
  91578. + } b;
  91579. +} gpvndctl_data_t;
  91580. +
  91581. +/**
  91582. + * This union represents the bit fields in the General Purpose
  91583. + * Input/Output Register (GGPIO).
  91584. + * Read the register into the <i>d32</i> element then read out the
  91585. + * bits using the <i>b</i>it elements.
  91586. + */
  91587. +typedef union ggpio_data {
  91588. + /** raw register data */
  91589. + uint32_t d32;
  91590. + /** register bits */
  91591. + struct {
  91592. + unsigned gpi:16;
  91593. + unsigned gpo:16;
  91594. + } b;
  91595. +} ggpio_data_t;
  91596. +
  91597. +/**
  91598. + * This union represents the bit fields in the User ID Register
  91599. + * (GUID). Read the register into the <i>d32</i> element then read out the
  91600. + * bits using the <i>b</i>it elements.
  91601. + */
  91602. +typedef union guid_data {
  91603. + /** raw register data */
  91604. + uint32_t d32;
  91605. + /** register bits */
  91606. + struct {
  91607. + unsigned rwdata:32;
  91608. + } b;
  91609. +} guid_data_t;
  91610. +
  91611. +/**
  91612. + * This union represents the bit fields in the Synopsys ID Register
  91613. + * (GSNPSID). Read the register into the <i>d32</i> element then read out the
  91614. + * bits using the <i>b</i>it elements.
  91615. + */
  91616. +typedef union gsnpsid_data {
  91617. + /** raw register data */
  91618. + uint32_t d32;
  91619. + /** register bits */
  91620. + struct {
  91621. + unsigned rwdata:32;
  91622. + } b;
  91623. +} gsnpsid_data_t;
  91624. +
  91625. +/**
  91626. + * This union represents the bit fields in the User HW Config1
  91627. + * Register. Read the register into the <i>d32</i> element then read
  91628. + * out the bits using the <i>b</i>it elements.
  91629. + */
  91630. +typedef union hwcfg1_data {
  91631. + /** raw register data */
  91632. + uint32_t d32;
  91633. + /** register bits */
  91634. + struct {
  91635. + unsigned ep_dir0:2;
  91636. + unsigned ep_dir1:2;
  91637. + unsigned ep_dir2:2;
  91638. + unsigned ep_dir3:2;
  91639. + unsigned ep_dir4:2;
  91640. + unsigned ep_dir5:2;
  91641. + unsigned ep_dir6:2;
  91642. + unsigned ep_dir7:2;
  91643. + unsigned ep_dir8:2;
  91644. + unsigned ep_dir9:2;
  91645. + unsigned ep_dir10:2;
  91646. + unsigned ep_dir11:2;
  91647. + unsigned ep_dir12:2;
  91648. + unsigned ep_dir13:2;
  91649. + unsigned ep_dir14:2;
  91650. + unsigned ep_dir15:2;
  91651. + } b;
  91652. +} hwcfg1_data_t;
  91653. +
  91654. +/**
  91655. + * This union represents the bit fields in the User HW Config2
  91656. + * Register. Read the register into the <i>d32</i> element then read
  91657. + * out the bits using the <i>b</i>it elements.
  91658. + */
  91659. +typedef union hwcfg2_data {
  91660. + /** raw register data */
  91661. + uint32_t d32;
  91662. + /** register bits */
  91663. + struct {
  91664. + /* GHWCFG2 */
  91665. + unsigned op_mode:3;
  91666. +#define DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG 0
  91667. +#define DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG 1
  91668. +#define DWC_HWCFG2_OP_MODE_NO_HNP_SRP_CAPABLE_OTG 2
  91669. +#define DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE 3
  91670. +#define DWC_HWCFG2_OP_MODE_NO_SRP_CAPABLE_DEVICE 4
  91671. +#define DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST 5
  91672. +#define DWC_HWCFG2_OP_MODE_NO_SRP_CAPABLE_HOST 6
  91673. +
  91674. + unsigned architecture:2;
  91675. + unsigned point2point:1;
  91676. + unsigned hs_phy_type:2;
  91677. +#define DWC_HWCFG2_HS_PHY_TYPE_NOT_SUPPORTED 0
  91678. +#define DWC_HWCFG2_HS_PHY_TYPE_UTMI 1
  91679. +#define DWC_HWCFG2_HS_PHY_TYPE_ULPI 2
  91680. +#define DWC_HWCFG2_HS_PHY_TYPE_UTMI_ULPI 3
  91681. +
  91682. + unsigned fs_phy_type:2;
  91683. + unsigned num_dev_ep:4;
  91684. + unsigned num_host_chan:4;
  91685. + unsigned perio_ep_supported:1;
  91686. + unsigned dynamic_fifo:1;
  91687. + unsigned multi_proc_int:1;
  91688. + unsigned reserved21:1;
  91689. + unsigned nonperio_tx_q_depth:2;
  91690. + unsigned host_perio_tx_q_depth:2;
  91691. + unsigned dev_token_q_depth:5;
  91692. + unsigned otg_enable_ic_usb:1;
  91693. + } b;
  91694. +} hwcfg2_data_t;
  91695. +
  91696. +/**
  91697. + * This union represents the bit fields in the User HW Config3
  91698. + * Register. Read the register into the <i>d32</i> element then read
  91699. + * out the bits using the <i>b</i>it elements.
  91700. + */
  91701. +typedef union hwcfg3_data {
  91702. + /** raw register data */
  91703. + uint32_t d32;
  91704. + /** register bits */
  91705. + struct {
  91706. + /* GHWCFG3 */
  91707. + unsigned xfer_size_cntr_width:4;
  91708. + unsigned packet_size_cntr_width:3;
  91709. + unsigned otg_func:1;
  91710. + unsigned i2c:1;
  91711. + unsigned vendor_ctrl_if:1;
  91712. + unsigned optional_features:1;
  91713. + unsigned synch_reset_type:1;
  91714. + unsigned adp_supp:1;
  91715. + unsigned otg_enable_hsic:1;
  91716. + unsigned bc_support:1;
  91717. + unsigned otg_lpm_en:1;
  91718. + unsigned dfifo_depth:16;
  91719. + } b;
  91720. +} hwcfg3_data_t;
  91721. +
  91722. +/**
  91723. + * This union represents the bit fields in the User HW Config4
  91724. + * Register. Read the register into the <i>d32</i> element then read
  91725. + * out the bits using the <i>b</i>it elements.
  91726. + */
  91727. +typedef union hwcfg4_data {
  91728. + /** raw register data */
  91729. + uint32_t d32;
  91730. + /** register bits */
  91731. + struct {
  91732. + unsigned num_dev_perio_in_ep:4;
  91733. + unsigned power_optimiz:1;
  91734. + unsigned min_ahb_freq:1;
  91735. + unsigned hiber:1;
  91736. + unsigned xhiber:1;
  91737. + unsigned reserved:6;
  91738. + unsigned utmi_phy_data_width:2;
  91739. + unsigned num_dev_mode_ctrl_ep:4;
  91740. + unsigned iddig_filt_en:1;
  91741. + unsigned vbus_valid_filt_en:1;
  91742. + unsigned a_valid_filt_en:1;
  91743. + unsigned b_valid_filt_en:1;
  91744. + unsigned session_end_filt_en:1;
  91745. + unsigned ded_fifo_en:1;
  91746. + unsigned num_in_eps:4;
  91747. + unsigned desc_dma:1;
  91748. + unsigned desc_dma_dyn:1;
  91749. + } b;
  91750. +} hwcfg4_data_t;
  91751. +
  91752. +/**
  91753. + * This union represents the bit fields of the Core LPM Configuration
  91754. + * Register (GLPMCFG). Set the bits using bit fields then write
  91755. + * the <i>d32</i> value to the register.
  91756. + */
  91757. +typedef union glpmctl_data {
  91758. + /** raw register data */
  91759. + uint32_t d32;
  91760. + /** register bits */
  91761. + struct {
  91762. + /** LPM-Capable (LPMCap) (Device and Host)
  91763. + * The application uses this bit to control
  91764. + * the DWC_otg core LPM capabilities.
  91765. + */
  91766. + unsigned lpm_cap_en:1;
  91767. + /** LPM response programmed by application (AppL1Res) (Device)
  91768. + * Handshake response to LPM token pre-programmed
  91769. + * by device application software.
  91770. + */
  91771. + unsigned appl_resp:1;
  91772. + /** Host Initiated Resume Duration (HIRD) (Device and Host)
  91773. + * In Host mode this field indicates the value of HIRD
  91774. + * to be sent in an LPM transaction.
  91775. + * In Device mode this field is updated with the
  91776. + * Received LPM Token HIRD bmAttribute
  91777. + * when an ACK/NYET/STALL response is sent
  91778. + * to an LPM transaction.
  91779. + */
  91780. + unsigned hird:4;
  91781. + /** RemoteWakeEnable (bRemoteWake) (Device and Host)
  91782. + * In Host mode this bit indicates the value of remote
  91783. + * wake up to be sent in wIndex field of LPM transaction.
  91784. + * In Device mode this field is updated with the
  91785. + * Received LPM Token bRemoteWake bmAttribute
  91786. + * when an ACK/NYET/STALL response is sent
  91787. + * to an LPM transaction.
  91788. + */
  91789. + unsigned rem_wkup_en:1;
  91790. + /** Enable utmi_sleep_n (EnblSlpM) (Device and Host)
  91791. + * The application uses this bit to control
  91792. + * the utmi_sleep_n assertion to the PHY when in L1 state.
  91793. + */
  91794. + unsigned en_utmi_sleep:1;
  91795. + /** HIRD Threshold (HIRD_Thres) (Device and Host)
  91796. + */
  91797. + unsigned hird_thres:5;
  91798. + /** LPM Response (CoreL1Res) (Device and Host)
  91799. + * In Host mode this bit contains handsake response to
  91800. + * LPM transaction.
  91801. + * In Device mode the response of the core to
  91802. + * LPM transaction received is reflected in these two bits.
  91803. + - 0x0 : ERROR (No handshake response)
  91804. + - 0x1 : STALL
  91805. + - 0x2 : NYET
  91806. + - 0x3 : ACK
  91807. + */
  91808. + unsigned lpm_resp:2;
  91809. + /** Port Sleep Status (SlpSts) (Device and Host)
  91810. + * This bit is set as long as a Sleep condition
  91811. + * is present on the USB bus.
  91812. + */
  91813. + unsigned prt_sleep_sts:1;
  91814. + /** Sleep State Resume OK (L1ResumeOK) (Device and Host)
  91815. + * Indicates that the application or host
  91816. + * can start resume from Sleep state.
  91817. + */
  91818. + unsigned sleep_state_resumeok:1;
  91819. + /** LPM channel Index (LPM_Chnl_Indx) (Host)
  91820. + * The channel number on which the LPM transaction
  91821. + * has to be applied while sending
  91822. + * an LPM transaction to the local device.
  91823. + */
  91824. + unsigned lpm_chan_index:4;
  91825. + /** LPM Retry Count (LPM_Retry_Cnt) (Host)
  91826. + * Number host retries that would be performed
  91827. + * if the device response was not valid response.
  91828. + */
  91829. + unsigned retry_count:3;
  91830. + /** Send LPM Transaction (SndLPM) (Host)
  91831. + * When set by application software,
  91832. + * an LPM transaction containing two tokens
  91833. + * is sent.
  91834. + */
  91835. + unsigned send_lpm:1;
  91836. + /** LPM Retry status (LPM_RetryCnt_Sts) (Host)
  91837. + * Number of LPM Host Retries still remaining
  91838. + * to be transmitted for the current LPM sequence
  91839. + */
  91840. + unsigned retry_count_sts:3;
  91841. + unsigned reserved28_29:2;
  91842. + /** In host mode once this bit is set, the host
  91843. + * configures to drive the HSIC Idle state on the bus.
  91844. + * It then waits for the device to initiate the Connect sequence.
  91845. + * In device mode once this bit is set, the device waits for
  91846. + * the HSIC Idle line state on the bus. Upon receving the Idle
  91847. + * line state, it initiates the HSIC Connect sequence.
  91848. + */
  91849. + unsigned hsic_connect:1;
  91850. + /** This bit overrides and functionally inverts
  91851. + * the if_select_hsic input port signal.
  91852. + */
  91853. + unsigned inv_sel_hsic:1;
  91854. + } b;
  91855. +} glpmcfg_data_t;
  91856. +
  91857. +/**
  91858. + * This union represents the bit fields of the Core ADP Timer, Control and
  91859. + * Status Register (ADPTIMCTLSTS). Set the bits using bit fields then write
  91860. + * the <i>d32</i> value to the register.
  91861. + */
  91862. +typedef union adpctl_data {
  91863. + /** raw register data */
  91864. + uint32_t d32;
  91865. + /** register bits */
  91866. + struct {
  91867. + /** Probe Discharge (PRB_DSCHG)
  91868. + * These bits set the times for TADP_DSCHG.
  91869. + * These bits are defined as follows:
  91870. + * 2'b00 - 4 msec
  91871. + * 2'b01 - 8 msec
  91872. + * 2'b10 - 16 msec
  91873. + * 2'b11 - 32 msec
  91874. + */
  91875. + unsigned prb_dschg:2;
  91876. + /** Probe Delta (PRB_DELTA)
  91877. + * These bits set the resolution for RTIM value.
  91878. + * The bits are defined in units of 32 kHz clock cycles as follows:
  91879. + * 2'b00 - 1 cycles
  91880. + * 2'b01 - 2 cycles
  91881. + * 2'b10 - 3 cycles
  91882. + * 2'b11 - 4 cycles
  91883. + * For example if this value is chosen to 2'b01, it means that RTIM
  91884. + * increments for every 3(three) 32Khz clock cycles.
  91885. + */
  91886. + unsigned prb_delta:2;
  91887. + /** Probe Period (PRB_PER)
  91888. + * These bits sets the TADP_PRD as shown in Figure 4 as follows:
  91889. + * 2'b00 - 0.625 to 0.925 sec (typical 0.775 sec)
  91890. + * 2'b01 - 1.25 to 1.85 sec (typical 1.55 sec)
  91891. + * 2'b10 - 1.9 to 2.6 sec (typical 2.275 sec)
  91892. + * 2'b11 - Reserved
  91893. + */
  91894. + unsigned prb_per:2;
  91895. + /** These bits capture the latest time it took for VBUS to ramp from
  91896. + * VADP_SINK to VADP_PRB.
  91897. + * 0x000 - 1 cycles
  91898. + * 0x001 - 2 cycles
  91899. + * 0x002 - 3 cycles
  91900. + * etc
  91901. + * 0x7FF - 2048 cycles
  91902. + * A time of 1024 cycles at 32 kHz corresponds to a time of 32 msec.
  91903. + */
  91904. + unsigned rtim:11;
  91905. + /** Enable Probe (EnaPrb)
  91906. + * When programmed to 1'b1, the core performs a probe operation.
  91907. + * This bit is valid only if OTG_Ver = 1'b1.
  91908. + */
  91909. + unsigned enaprb:1;
  91910. + /** Enable Sense (EnaSns)
  91911. + * When programmed to 1'b1, the core performs a Sense operation.
  91912. + * This bit is valid only if OTG_Ver = 1'b1.
  91913. + */
  91914. + unsigned enasns:1;
  91915. + /** ADP Reset (ADPRes)
  91916. + * When set, ADP controller is reset.
  91917. + * This bit is valid only if OTG_Ver = 1'b1.
  91918. + */
  91919. + unsigned adpres:1;
  91920. + /** ADP Enable (ADPEn)
  91921. + * When set, the core performs either ADP probing or sensing
  91922. + * based on EnaPrb or EnaSns.
  91923. + * This bit is valid only if OTG_Ver = 1'b1.
  91924. + */
  91925. + unsigned adpen:1;
  91926. + /** ADP Probe Interrupt (ADP_PRB_INT)
  91927. + * When this bit is set, it means that the VBUS
  91928. + * voltage is greater than VADP_PRB or VADP_PRB is reached.
  91929. + * This bit is valid only if OTG_Ver = 1'b1.
  91930. + */
  91931. + unsigned adp_prb_int:1;
  91932. + /**
  91933. + * ADP Sense Interrupt (ADP_SNS_INT)
  91934. + * When this bit is set, it means that the VBUS voltage is greater than
  91935. + * VADP_SNS value or VADP_SNS is reached.
  91936. + * This bit is valid only if OTG_Ver = 1'b1.
  91937. + */
  91938. + unsigned adp_sns_int:1;
  91939. + /** ADP Tomeout Interrupt (ADP_TMOUT_INT)
  91940. + * This bit is relevant only for an ADP probe.
  91941. + * When this bit is set, it means that the ramp time has
  91942. + * completed ie ADPCTL.RTIM has reached its terminal value
  91943. + * of 0x7FF. This is a debug feature that allows software
  91944. + * to read the ramp time after each cycle.
  91945. + * This bit is valid only if OTG_Ver = 1'b1.
  91946. + */
  91947. + unsigned adp_tmout_int:1;
  91948. + /** ADP Probe Interrupt Mask (ADP_PRB_INT_MSK)
  91949. + * When this bit is set, it unmasks the interrupt due to ADP_PRB_INT.
  91950. + * This bit is valid only if OTG_Ver = 1'b1.
  91951. + */
  91952. + unsigned adp_prb_int_msk:1;
  91953. + /** ADP Sense Interrupt Mask (ADP_SNS_INT_MSK)
  91954. + * When this bit is set, it unmasks the interrupt due to ADP_SNS_INT.
  91955. + * This bit is valid only if OTG_Ver = 1'b1.
  91956. + */
  91957. + unsigned adp_sns_int_msk:1;
  91958. + /** ADP Timoeout Interrupt Mask (ADP_TMOUT_MSK)
  91959. + * When this bit is set, it unmasks the interrupt due to ADP_TMOUT_INT.
  91960. + * This bit is valid only if OTG_Ver = 1'b1.
  91961. + */
  91962. + unsigned adp_tmout_int_msk:1;
  91963. + /** Access Request
  91964. + * 2'b00 - Read/Write Valid (updated by the core)
  91965. + * 2'b01 - Read
  91966. + * 2'b00 - Write
  91967. + * 2'b00 - Reserved
  91968. + */
  91969. + unsigned ar:2;
  91970. + /** Reserved */
  91971. + unsigned reserved29_31:3;
  91972. + } b;
  91973. +} adpctl_data_t;
  91974. +
  91975. +////////////////////////////////////////////
  91976. +// Device Registers
  91977. +/**
  91978. + * Device Global Registers. <i>Offsets 800h-BFFh</i>
  91979. + *
  91980. + * The following structures define the size and relative field offsets
  91981. + * for the Device Mode Registers.
  91982. + *
  91983. + * <i>These registers are visible only in Device mode and must not be
  91984. + * accessed in Host mode, as the results are unknown.</i>
  91985. + */
  91986. +typedef struct dwc_otg_dev_global_regs {
  91987. + /** Device Configuration Register. <i>Offset 800h</i> */
  91988. + volatile uint32_t dcfg;
  91989. + /** Device Control Register. <i>Offset: 804h</i> */
  91990. + volatile uint32_t dctl;
  91991. + /** Device Status Register (Read Only). <i>Offset: 808h</i> */
  91992. + volatile uint32_t dsts;
  91993. + /** Reserved. <i>Offset: 80Ch</i> */
  91994. + uint32_t unused;
  91995. + /** Device IN Endpoint Common Interrupt Mask
  91996. + * Register. <i>Offset: 810h</i> */
  91997. + volatile uint32_t diepmsk;
  91998. + /** Device OUT Endpoint Common Interrupt Mask
  91999. + * Register. <i>Offset: 814h</i> */
  92000. + volatile uint32_t doepmsk;
  92001. + /** Device All Endpoints Interrupt Register. <i>Offset: 818h</i> */
  92002. + volatile uint32_t daint;
  92003. + /** Device All Endpoints Interrupt Mask Register. <i>Offset:
  92004. + * 81Ch</i> */
  92005. + volatile uint32_t daintmsk;
  92006. + /** Device IN Token Queue Read Register-1 (Read Only).
  92007. + * <i>Offset: 820h</i> */
  92008. + volatile uint32_t dtknqr1;
  92009. + /** Device IN Token Queue Read Register-2 (Read Only).
  92010. + * <i>Offset: 824h</i> */
  92011. + volatile uint32_t dtknqr2;
  92012. + /** Device VBUS discharge Register. <i>Offset: 828h</i> */
  92013. + volatile uint32_t dvbusdis;
  92014. + /** Device VBUS Pulse Register. <i>Offset: 82Ch</i> */
  92015. + volatile uint32_t dvbuspulse;
  92016. + /** Device IN Token Queue Read Register-3 (Read Only). /
  92017. + * Device Thresholding control register (Read/Write)
  92018. + * <i>Offset: 830h</i> */
  92019. + volatile uint32_t dtknqr3_dthrctl;
  92020. + /** Device IN Token Queue Read Register-4 (Read Only). /
  92021. + * Device IN EPs empty Inr. Mask Register (Read/Write)
  92022. + * <i>Offset: 834h</i> */
  92023. + volatile uint32_t dtknqr4_fifoemptymsk;
  92024. + /** Device Each Endpoint Interrupt Register (Read Only). /
  92025. + * <i>Offset: 838h</i> */
  92026. + volatile uint32_t deachint;
  92027. + /** Device Each Endpoint Interrupt mask Register (Read/Write). /
  92028. + * <i>Offset: 83Ch</i> */
  92029. + volatile uint32_t deachintmsk;
  92030. + /** Device Each In Endpoint Interrupt mask Register (Read/Write). /
  92031. + * <i>Offset: 840h</i> */
  92032. + volatile uint32_t diepeachintmsk[MAX_EPS_CHANNELS];
  92033. + /** Device Each Out Endpoint Interrupt mask Register (Read/Write). /
  92034. + * <i>Offset: 880h</i> */
  92035. + volatile uint32_t doepeachintmsk[MAX_EPS_CHANNELS];
  92036. +} dwc_otg_device_global_regs_t;
  92037. +
  92038. +/**
  92039. + * This union represents the bit fields in the Device Configuration
  92040. + * Register. Read the register into the <i>d32</i> member then
  92041. + * set/clear the bits using the <i>b</i>it elements. Write the
  92042. + * <i>d32</i> member to the dcfg register.
  92043. + */
  92044. +typedef union dcfg_data {
  92045. + /** raw register data */
  92046. + uint32_t d32;
  92047. + /** register bits */
  92048. + struct {
  92049. + /** Device Speed */
  92050. + unsigned devspd:2;
  92051. + /** Non Zero Length Status OUT Handshake */
  92052. + unsigned nzstsouthshk:1;
  92053. +#define DWC_DCFG_SEND_STALL 1
  92054. +
  92055. + unsigned ena32khzs:1;
  92056. + /** Device Addresses */
  92057. + unsigned devaddr:7;
  92058. + /** Periodic Frame Interval */
  92059. + unsigned perfrint:2;
  92060. +#define DWC_DCFG_FRAME_INTERVAL_80 0
  92061. +#define DWC_DCFG_FRAME_INTERVAL_85 1
  92062. +#define DWC_DCFG_FRAME_INTERVAL_90 2
  92063. +#define DWC_DCFG_FRAME_INTERVAL_95 3
  92064. +
  92065. + /** Enable Device OUT NAK for bulk in DDMA mode */
  92066. + unsigned endevoutnak:1;
  92067. +
  92068. + unsigned reserved14_17:4;
  92069. + /** In Endpoint Mis-match count */
  92070. + unsigned epmscnt:5;
  92071. + /** Enable Descriptor DMA in Device mode */
  92072. + unsigned descdma:1;
  92073. + unsigned perschintvl:2;
  92074. + unsigned resvalid:6;
  92075. + } b;
  92076. +} dcfg_data_t;
  92077. +
  92078. +/**
  92079. + * This union represents the bit fields in the Device Control
  92080. + * Register. Read the register into the <i>d32</i> member then
  92081. + * set/clear the bits using the <i>b</i>it elements.
  92082. + */
  92083. +typedef union dctl_data {
  92084. + /** raw register data */
  92085. + uint32_t d32;
  92086. + /** register bits */
  92087. + struct {
  92088. + /** Remote Wakeup */
  92089. + unsigned rmtwkupsig:1;
  92090. + /** Soft Disconnect */
  92091. + unsigned sftdiscon:1;
  92092. + /** Global Non-Periodic IN NAK Status */
  92093. + unsigned gnpinnaksts:1;
  92094. + /** Global OUT NAK Status */
  92095. + unsigned goutnaksts:1;
  92096. + /** Test Control */
  92097. + unsigned tstctl:3;
  92098. + /** Set Global Non-Periodic IN NAK */
  92099. + unsigned sgnpinnak:1;
  92100. + /** Clear Global Non-Periodic IN NAK */
  92101. + unsigned cgnpinnak:1;
  92102. + /** Set Global OUT NAK */
  92103. + unsigned sgoutnak:1;
  92104. + /** Clear Global OUT NAK */
  92105. + unsigned cgoutnak:1;
  92106. + /** Power-On Programming Done */
  92107. + unsigned pwronprgdone:1;
  92108. + /** Reserved */
  92109. + unsigned reserved:1;
  92110. + /** Global Multi Count */
  92111. + unsigned gmc:2;
  92112. + /** Ignore Frame Number for ISOC EPs */
  92113. + unsigned ifrmnum:1;
  92114. + /** NAK on Babble */
  92115. + unsigned nakonbble:1;
  92116. + /** Enable Continue on BNA */
  92117. + unsigned encontonbna:1;
  92118. +
  92119. + unsigned reserved18_31:14;
  92120. + } b;
  92121. +} dctl_data_t;
  92122. +
  92123. +/**
  92124. + * This union represents the bit fields in the Device Status
  92125. + * Register. Read the register into the <i>d32</i> member then
  92126. + * set/clear the bits using the <i>b</i>it elements.
  92127. + */
  92128. +typedef union dsts_data {
  92129. + /** raw register data */
  92130. + uint32_t d32;
  92131. + /** register bits */
  92132. + struct {
  92133. + /** Suspend Status */
  92134. + unsigned suspsts:1;
  92135. + /** Enumerated Speed */
  92136. + unsigned enumspd:2;
  92137. +#define DWC_DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ 0
  92138. +#define DWC_DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ 1
  92139. +#define DWC_DSTS_ENUMSPD_LS_PHY_6MHZ 2
  92140. +#define DWC_DSTS_ENUMSPD_FS_PHY_48MHZ 3
  92141. + /** Erratic Error */
  92142. + unsigned errticerr:1;
  92143. + unsigned reserved4_7:4;
  92144. + /** Frame or Microframe Number of the received SOF */
  92145. + unsigned soffn:14;
  92146. + unsigned reserved22_31:10;
  92147. + } b;
  92148. +} dsts_data_t;
  92149. +
  92150. +/**
  92151. + * This union represents the bit fields in the Device IN EP Interrupt
  92152. + * Register and the Device IN EP Common Mask Register.
  92153. + *
  92154. + * - Read the register into the <i>d32</i> member then set/clear the
  92155. + * bits using the <i>b</i>it elements.
  92156. + */
  92157. +typedef union diepint_data {
  92158. + /** raw register data */
  92159. + uint32_t d32;
  92160. + /** register bits */
  92161. + struct {
  92162. + /** Transfer complete mask */
  92163. + unsigned xfercompl:1;
  92164. + /** Endpoint disable mask */
  92165. + unsigned epdisabled:1;
  92166. + /** AHB Error mask */
  92167. + unsigned ahberr:1;
  92168. + /** TimeOUT Handshake mask (non-ISOC EPs) */
  92169. + unsigned timeout:1;
  92170. + /** IN Token received with TxF Empty mask */
  92171. + unsigned intktxfemp:1;
  92172. + /** IN Token Received with EP mismatch mask */
  92173. + unsigned intknepmis:1;
  92174. + /** IN Endpoint NAK Effective mask */
  92175. + unsigned inepnakeff:1;
  92176. + /** Reserved */
  92177. + unsigned emptyintr:1;
  92178. +
  92179. + unsigned txfifoundrn:1;
  92180. +
  92181. + /** BNA Interrupt mask */
  92182. + unsigned bna:1;
  92183. +
  92184. + unsigned reserved10_12:3;
  92185. + /** BNA Interrupt mask */
  92186. + unsigned nak:1;
  92187. +
  92188. + unsigned reserved14_31:18;
  92189. + } b;
  92190. +} diepint_data_t;
  92191. +
  92192. +/**
  92193. + * This union represents the bit fields in the Device IN EP
  92194. + * Common/Dedicated Interrupt Mask Register.
  92195. + */
  92196. +typedef union diepint_data diepmsk_data_t;
  92197. +
  92198. +/**
  92199. + * This union represents the bit fields in the Device OUT EP Interrupt
  92200. + * Registerand Device OUT EP Common Interrupt Mask Register.
  92201. + *
  92202. + * - Read the register into the <i>d32</i> member then set/clear the
  92203. + * bits using the <i>b</i>it elements.
  92204. + */
  92205. +typedef union doepint_data {
  92206. + /** raw register data */
  92207. + uint32_t d32;
  92208. + /** register bits */
  92209. + struct {
  92210. + /** Transfer complete */
  92211. + unsigned xfercompl:1;
  92212. + /** Endpoint disable */
  92213. + unsigned epdisabled:1;
  92214. + /** AHB Error */
  92215. + unsigned ahberr:1;
  92216. + /** Setup Phase Done (contorl EPs) */
  92217. + unsigned setup:1;
  92218. + /** OUT Token Received when Endpoint Disabled */
  92219. + unsigned outtknepdis:1;
  92220. +
  92221. + unsigned stsphsercvd:1;
  92222. + /** Back-to-Back SETUP Packets Received */
  92223. + unsigned back2backsetup:1;
  92224. +
  92225. + unsigned reserved7:1;
  92226. + /** OUT packet Error */
  92227. + unsigned outpkterr:1;
  92228. + /** BNA Interrupt */
  92229. + unsigned bna:1;
  92230. +
  92231. + unsigned reserved10:1;
  92232. + /** Packet Drop Status */
  92233. + unsigned pktdrpsts:1;
  92234. + /** Babble Interrupt */
  92235. + unsigned babble:1;
  92236. + /** NAK Interrupt */
  92237. + unsigned nak:1;
  92238. + /** NYET Interrupt */
  92239. + unsigned nyet:1;
  92240. + /** Bit indicating setup packet received */
  92241. + unsigned sr:1;
  92242. +
  92243. + unsigned reserved16_31:16;
  92244. + } b;
  92245. +} doepint_data_t;
  92246. +
  92247. +/**
  92248. + * This union represents the bit fields in the Device OUT EP
  92249. + * Common/Dedicated Interrupt Mask Register.
  92250. + */
  92251. +typedef union doepint_data doepmsk_data_t;
  92252. +
  92253. +/**
  92254. + * This union represents the bit fields in the Device All EP Interrupt
  92255. + * and Mask Registers.
  92256. + * - Read the register into the <i>d32</i> member then set/clear the
  92257. + * bits using the <i>b</i>it elements.
  92258. + */
  92259. +typedef union daint_data {
  92260. + /** raw register data */
  92261. + uint32_t d32;
  92262. + /** register bits */
  92263. + struct {
  92264. + /** IN Endpoint bits */
  92265. + unsigned in:16;
  92266. + /** OUT Endpoint bits */
  92267. + unsigned out:16;
  92268. + } ep;
  92269. + struct {
  92270. + /** IN Endpoint bits */
  92271. + unsigned inep0:1;
  92272. + unsigned inep1:1;
  92273. + unsigned inep2:1;
  92274. + unsigned inep3:1;
  92275. + unsigned inep4:1;
  92276. + unsigned inep5:1;
  92277. + unsigned inep6:1;
  92278. + unsigned inep7:1;
  92279. + unsigned inep8:1;
  92280. + unsigned inep9:1;
  92281. + unsigned inep10:1;
  92282. + unsigned inep11:1;
  92283. + unsigned inep12:1;
  92284. + unsigned inep13:1;
  92285. + unsigned inep14:1;
  92286. + unsigned inep15:1;
  92287. + /** OUT Endpoint bits */
  92288. + unsigned outep0:1;
  92289. + unsigned outep1:1;
  92290. + unsigned outep2:1;
  92291. + unsigned outep3:1;
  92292. + unsigned outep4:1;
  92293. + unsigned outep5:1;
  92294. + unsigned outep6:1;
  92295. + unsigned outep7:1;
  92296. + unsigned outep8:1;
  92297. + unsigned outep9:1;
  92298. + unsigned outep10:1;
  92299. + unsigned outep11:1;
  92300. + unsigned outep12:1;
  92301. + unsigned outep13:1;
  92302. + unsigned outep14:1;
  92303. + unsigned outep15:1;
  92304. + } b;
  92305. +} daint_data_t;
  92306. +
  92307. +/**
  92308. + * This union represents the bit fields in the Device IN Token Queue
  92309. + * Read Registers.
  92310. + * - Read the register into the <i>d32</i> member.
  92311. + * - READ-ONLY Register
  92312. + */
  92313. +typedef union dtknq1_data {
  92314. + /** raw register data */
  92315. + uint32_t d32;
  92316. + /** register bits */
  92317. + struct {
  92318. + /** In Token Queue Write Pointer */
  92319. + unsigned intknwptr:5;
  92320. + /** Reserved */
  92321. + unsigned reserved05_06:2;
  92322. + /** write pointer has wrapped. */
  92323. + unsigned wrap_bit:1;
  92324. + /** EP Numbers of IN Tokens 0 ... 4 */
  92325. + unsigned epnums0_5:24;
  92326. + } b;
  92327. +} dtknq1_data_t;
  92328. +
  92329. +/**
  92330. + * This union represents Threshold control Register
  92331. + * - Read and write the register into the <i>d32</i> member.
  92332. + * - READ-WRITABLE Register
  92333. + */
  92334. +typedef union dthrctl_data {
  92335. + /** raw register data */
  92336. + uint32_t d32;
  92337. + /** register bits */
  92338. + struct {
  92339. + /** non ISO Tx Thr. Enable */
  92340. + unsigned non_iso_thr_en:1;
  92341. + /** ISO Tx Thr. Enable */
  92342. + unsigned iso_thr_en:1;
  92343. + /** Tx Thr. Length */
  92344. + unsigned tx_thr_len:9;
  92345. + /** AHB Threshold ratio */
  92346. + unsigned ahb_thr_ratio:2;
  92347. + /** Reserved */
  92348. + unsigned reserved13_15:3;
  92349. + /** Rx Thr. Enable */
  92350. + unsigned rx_thr_en:1;
  92351. + /** Rx Thr. Length */
  92352. + unsigned rx_thr_len:9;
  92353. + unsigned reserved26:1;
  92354. + /** Arbiter Parking Enable*/
  92355. + unsigned arbprken:1;
  92356. + /** Reserved */
  92357. + unsigned reserved28_31:4;
  92358. + } b;
  92359. +} dthrctl_data_t;
  92360. +
  92361. +/**
  92362. + * Device Logical IN Endpoint-Specific Registers. <i>Offsets
  92363. + * 900h-AFCh</i>
  92364. + *
  92365. + * There will be one set of endpoint registers per logical endpoint
  92366. + * implemented.
  92367. + *
  92368. + * <i>These registers are visible only in Device mode and must not be
  92369. + * accessed in Host mode, as the results are unknown.</i>
  92370. + */
  92371. +typedef struct dwc_otg_dev_in_ep_regs {
  92372. + /** Device IN Endpoint Control Register. <i>Offset:900h +
  92373. + * (ep_num * 20h) + 00h</i> */
  92374. + volatile uint32_t diepctl;
  92375. + /** Reserved. <i>Offset:900h + (ep_num * 20h) + 04h</i> */
  92376. + uint32_t reserved04;
  92377. + /** Device IN Endpoint Interrupt Register. <i>Offset:900h +
  92378. + * (ep_num * 20h) + 08h</i> */
  92379. + volatile uint32_t diepint;
  92380. + /** Reserved. <i>Offset:900h + (ep_num * 20h) + 0Ch</i> */
  92381. + uint32_t reserved0C;
  92382. + /** Device IN Endpoint Transfer Size
  92383. + * Register. <i>Offset:900h + (ep_num * 20h) + 10h</i> */
  92384. + volatile uint32_t dieptsiz;
  92385. + /** Device IN Endpoint DMA Address Register. <i>Offset:900h +
  92386. + * (ep_num * 20h) + 14h</i> */
  92387. + volatile uint32_t diepdma;
  92388. + /** Device IN Endpoint Transmit FIFO Status Register. <i>Offset:900h +
  92389. + * (ep_num * 20h) + 18h</i> */
  92390. + volatile uint32_t dtxfsts;
  92391. + /** Device IN Endpoint DMA Buffer Register. <i>Offset:900h +
  92392. + * (ep_num * 20h) + 1Ch</i> */
  92393. + volatile uint32_t diepdmab;
  92394. +} dwc_otg_dev_in_ep_regs_t;
  92395. +
  92396. +/**
  92397. + * Device Logical OUT Endpoint-Specific Registers. <i>Offsets:
  92398. + * B00h-CFCh</i>
  92399. + *
  92400. + * There will be one set of endpoint registers per logical endpoint
  92401. + * implemented.
  92402. + *
  92403. + * <i>These registers are visible only in Device mode and must not be
  92404. + * accessed in Host mode, as the results are unknown.</i>
  92405. + */
  92406. +typedef struct dwc_otg_dev_out_ep_regs {
  92407. + /** Device OUT Endpoint Control Register. <i>Offset:B00h +
  92408. + * (ep_num * 20h) + 00h</i> */
  92409. + volatile uint32_t doepctl;
  92410. + /** Reserved. <i>Offset:B00h + (ep_num * 20h) + 04h</i> */
  92411. + uint32_t reserved04;
  92412. + /** Device OUT Endpoint Interrupt Register. <i>Offset:B00h +
  92413. + * (ep_num * 20h) + 08h</i> */
  92414. + volatile uint32_t doepint;
  92415. + /** Reserved. <i>Offset:B00h + (ep_num * 20h) + 0Ch</i> */
  92416. + uint32_t reserved0C;
  92417. + /** Device OUT Endpoint Transfer Size Register. <i>Offset:
  92418. + * B00h + (ep_num * 20h) + 10h</i> */
  92419. + volatile uint32_t doeptsiz;
  92420. + /** Device OUT Endpoint DMA Address Register. <i>Offset:B00h
  92421. + * + (ep_num * 20h) + 14h</i> */
  92422. + volatile uint32_t doepdma;
  92423. + /** Reserved. <i>Offset:B00h + * (ep_num * 20h) + 18h</i> */
  92424. + uint32_t unused;
  92425. + /** Device OUT Endpoint DMA Buffer Register. <i>Offset:B00h
  92426. + * + (ep_num * 20h) + 1Ch</i> */
  92427. + uint32_t doepdmab;
  92428. +} dwc_otg_dev_out_ep_regs_t;
  92429. +
  92430. +/**
  92431. + * This union represents the bit fields in the Device EP Control
  92432. + * Register. Read the register into the <i>d32</i> member then
  92433. + * set/clear the bits using the <i>b</i>it elements.
  92434. + */
  92435. +typedef union depctl_data {
  92436. + /** raw register data */
  92437. + uint32_t d32;
  92438. + /** register bits */
  92439. + struct {
  92440. + /** Maximum Packet Size
  92441. + * IN/OUT EPn
  92442. + * IN/OUT EP0 - 2 bits
  92443. + * 2'b00: 64 Bytes
  92444. + * 2'b01: 32
  92445. + * 2'b10: 16
  92446. + * 2'b11: 8 */
  92447. + unsigned mps:11;
  92448. +#define DWC_DEP0CTL_MPS_64 0
  92449. +#define DWC_DEP0CTL_MPS_32 1
  92450. +#define DWC_DEP0CTL_MPS_16 2
  92451. +#define DWC_DEP0CTL_MPS_8 3
  92452. +
  92453. + /** Next Endpoint
  92454. + * IN EPn/IN EP0
  92455. + * OUT EPn/OUT EP0 - reserved */
  92456. + unsigned nextep:4;
  92457. +
  92458. + /** USB Active Endpoint */
  92459. + unsigned usbactep:1;
  92460. +
  92461. + /** Endpoint DPID (INTR/Bulk IN and OUT endpoints)
  92462. + * This field contains the PID of the packet going to
  92463. + * be received or transmitted on this endpoint. The
  92464. + * application should program the PID of the first
  92465. + * packet going to be received or transmitted on this
  92466. + * endpoint , after the endpoint is
  92467. + * activated. Application use the SetD1PID and
  92468. + * SetD0PID fields of this register to program either
  92469. + * D0 or D1 PID.
  92470. + *
  92471. + * The encoding for this field is
  92472. + * - 0: D0
  92473. + * - 1: D1
  92474. + */
  92475. + unsigned dpid:1;
  92476. +
  92477. + /** NAK Status */
  92478. + unsigned naksts:1;
  92479. +
  92480. + /** Endpoint Type
  92481. + * 2'b00: Control
  92482. + * 2'b01: Isochronous
  92483. + * 2'b10: Bulk
  92484. + * 2'b11: Interrupt */
  92485. + unsigned eptype:2;
  92486. +
  92487. + /** Snoop Mode
  92488. + * OUT EPn/OUT EP0
  92489. + * IN EPn/IN EP0 - reserved */
  92490. + unsigned snp:1;
  92491. +
  92492. + /** Stall Handshake */
  92493. + unsigned stall:1;
  92494. +
  92495. + /** Tx Fifo Number
  92496. + * IN EPn/IN EP0
  92497. + * OUT EPn/OUT EP0 - reserved */
  92498. + unsigned txfnum:4;
  92499. +
  92500. + /** Clear NAK */
  92501. + unsigned cnak:1;
  92502. + /** Set NAK */
  92503. + unsigned snak:1;
  92504. + /** Set DATA0 PID (INTR/Bulk IN and OUT endpoints)
  92505. + * Writing to this field sets the Endpoint DPID (DPID)
  92506. + * field in this register to DATA0. Set Even
  92507. + * (micro)frame (SetEvenFr) (ISO IN and OUT Endpoints)
  92508. + * Writing to this field sets the Even/Odd
  92509. + * (micro)frame (EO_FrNum) field to even (micro)
  92510. + * frame.
  92511. + */
  92512. + unsigned setd0pid:1;
  92513. + /** Set DATA1 PID (INTR/Bulk IN and OUT endpoints)
  92514. + * Writing to this field sets the Endpoint DPID (DPID)
  92515. + * field in this register to DATA1 Set Odd
  92516. + * (micro)frame (SetOddFr) (ISO IN and OUT Endpoints)
  92517. + * Writing to this field sets the Even/Odd
  92518. + * (micro)frame (EO_FrNum) field to odd (micro) frame.
  92519. + */
  92520. + unsigned setd1pid:1;
  92521. +
  92522. + /** Endpoint Disable */
  92523. + unsigned epdis:1;
  92524. + /** Endpoint Enable */
  92525. + unsigned epena:1;
  92526. + } b;
  92527. +} depctl_data_t;
  92528. +
  92529. +/**
  92530. + * This union represents the bit fields in the Device EP Transfer
  92531. + * Size Register. Read the register into the <i>d32</i> member then
  92532. + * set/clear the bits using the <i>b</i>it elements.
  92533. + */
  92534. +typedef union deptsiz_data {
  92535. + /** raw register data */
  92536. + uint32_t d32;
  92537. + /** register bits */
  92538. + struct {
  92539. + /** Transfer size */
  92540. + unsigned xfersize:19;
  92541. +/** Max packet count for EP (pow(2,10)-1) */
  92542. +#define MAX_PKT_CNT 1023
  92543. + /** Packet Count */
  92544. + unsigned pktcnt:10;
  92545. + /** Multi Count - Periodic IN endpoints */
  92546. + unsigned mc:2;
  92547. + unsigned reserved:1;
  92548. + } b;
  92549. +} deptsiz_data_t;
  92550. +
  92551. +/**
  92552. + * This union represents the bit fields in the Device EP 0 Transfer
  92553. + * Size Register. Read the register into the <i>d32</i> member then
  92554. + * set/clear the bits using the <i>b</i>it elements.
  92555. + */
  92556. +typedef union deptsiz0_data {
  92557. + /** raw register data */
  92558. + uint32_t d32;
  92559. + /** register bits */
  92560. + struct {
  92561. + /** Transfer size */
  92562. + unsigned xfersize:7;
  92563. + /** Reserved */
  92564. + unsigned reserved7_18:12;
  92565. + /** Packet Count */
  92566. + unsigned pktcnt:2;
  92567. + /** Reserved */
  92568. + unsigned reserved21_28:8;
  92569. + /**Setup Packet Count (DOEPTSIZ0 Only) */
  92570. + unsigned supcnt:2;
  92571. + unsigned reserved31;
  92572. + } b;
  92573. +} deptsiz0_data_t;
  92574. +
  92575. +/////////////////////////////////////////////////
  92576. +// DMA Descriptor Specific Structures
  92577. +//
  92578. +
  92579. +/** Buffer status definitions */
  92580. +
  92581. +#define BS_HOST_READY 0x0
  92582. +#define BS_DMA_BUSY 0x1
  92583. +#define BS_DMA_DONE 0x2
  92584. +#define BS_HOST_BUSY 0x3
  92585. +
  92586. +/** Receive/Transmit status definitions */
  92587. +
  92588. +#define RTS_SUCCESS 0x0
  92589. +#define RTS_BUFFLUSH 0x1
  92590. +#define RTS_RESERVED 0x2
  92591. +#define RTS_BUFERR 0x3
  92592. +
  92593. +/**
  92594. + * This union represents the bit fields in the DMA Descriptor
  92595. + * status quadlet. Read the quadlet into the <i>d32</i> member then
  92596. + * set/clear the bits using the <i>b</i>it, <i>b_iso_out</i> and
  92597. + * <i>b_iso_in</i> elements.
  92598. + */
  92599. +typedef union dev_dma_desc_sts {
  92600. + /** raw register data */
  92601. + uint32_t d32;
  92602. + /** quadlet bits */
  92603. + struct {
  92604. + /** Received number of bytes */
  92605. + unsigned bytes:16;
  92606. + /** NAK bit - only for OUT EPs */
  92607. + unsigned nak:1;
  92608. + unsigned reserved17_22:6;
  92609. + /** Multiple Transfer - only for OUT EPs */
  92610. + unsigned mtrf:1;
  92611. + /** Setup Packet received - only for OUT EPs */
  92612. + unsigned sr:1;
  92613. + /** Interrupt On Complete */
  92614. + unsigned ioc:1;
  92615. + /** Short Packet */
  92616. + unsigned sp:1;
  92617. + /** Last */
  92618. + unsigned l:1;
  92619. + /** Receive Status */
  92620. + unsigned sts:2;
  92621. + /** Buffer Status */
  92622. + unsigned bs:2;
  92623. + } b;
  92624. +
  92625. +//#ifdef DWC_EN_ISOC
  92626. + /** iso out quadlet bits */
  92627. + struct {
  92628. + /** Received number of bytes */
  92629. + unsigned rxbytes:11;
  92630. +
  92631. + unsigned reserved11:1;
  92632. + /** Frame Number */
  92633. + unsigned framenum:11;
  92634. + /** Received ISO Data PID */
  92635. + unsigned pid:2;
  92636. + /** Interrupt On Complete */
  92637. + unsigned ioc:1;
  92638. + /** Short Packet */
  92639. + unsigned sp:1;
  92640. + /** Last */
  92641. + unsigned l:1;
  92642. + /** Receive Status */
  92643. + unsigned rxsts:2;
  92644. + /** Buffer Status */
  92645. + unsigned bs:2;
  92646. + } b_iso_out;
  92647. +
  92648. + /** iso in quadlet bits */
  92649. + struct {
  92650. + /** Transmited number of bytes */
  92651. + unsigned txbytes:12;
  92652. + /** Frame Number */
  92653. + unsigned framenum:11;
  92654. + /** Transmited ISO Data PID */
  92655. + unsigned pid:2;
  92656. + /** Interrupt On Complete */
  92657. + unsigned ioc:1;
  92658. + /** Short Packet */
  92659. + unsigned sp:1;
  92660. + /** Last */
  92661. + unsigned l:1;
  92662. + /** Transmit Status */
  92663. + unsigned txsts:2;
  92664. + /** Buffer Status */
  92665. + unsigned bs:2;
  92666. + } b_iso_in;
  92667. +//#endif /* DWC_EN_ISOC */
  92668. +} dev_dma_desc_sts_t;
  92669. +
  92670. +/**
  92671. + * DMA Descriptor structure
  92672. + *
  92673. + * DMA Descriptor structure contains two quadlets:
  92674. + * Status quadlet and Data buffer pointer.
  92675. + */
  92676. +typedef struct dwc_otg_dev_dma_desc {
  92677. + /** DMA Descriptor status quadlet */
  92678. + dev_dma_desc_sts_t status;
  92679. + /** DMA Descriptor data buffer pointer */
  92680. + uint32_t buf;
  92681. +} dwc_otg_dev_dma_desc_t;
  92682. +
  92683. +/**
  92684. + * The dwc_otg_dev_if structure contains information needed to manage
  92685. + * the DWC_otg controller acting in device mode. It represents the
  92686. + * programming view of the device-specific aspects of the controller.
  92687. + */
  92688. +typedef struct dwc_otg_dev_if {
  92689. + /** Pointer to device Global registers.
  92690. + * Device Global Registers starting at offset 800h
  92691. + */
  92692. + dwc_otg_device_global_regs_t *dev_global_regs;
  92693. +#define DWC_DEV_GLOBAL_REG_OFFSET 0x800
  92694. +
  92695. + /**
  92696. + * Device Logical IN Endpoint-Specific Registers 900h-AFCh
  92697. + */
  92698. + dwc_otg_dev_in_ep_regs_t *in_ep_regs[MAX_EPS_CHANNELS];
  92699. +#define DWC_DEV_IN_EP_REG_OFFSET 0x900
  92700. +#define DWC_EP_REG_OFFSET 0x20
  92701. +
  92702. + /** Device Logical OUT Endpoint-Specific Registers B00h-CFCh */
  92703. + dwc_otg_dev_out_ep_regs_t *out_ep_regs[MAX_EPS_CHANNELS];
  92704. +#define DWC_DEV_OUT_EP_REG_OFFSET 0xB00
  92705. +
  92706. + /* Device configuration information */
  92707. + uint8_t speed; /**< Device Speed 0: Unknown, 1: LS, 2:FS, 3: HS */
  92708. + uint8_t num_in_eps; /**< Number # of Tx EP range: 0-15 exept ep0 */
  92709. + uint8_t num_out_eps; /**< Number # of Rx EP range: 0-15 exept ep 0*/
  92710. +
  92711. + /** Size of periodic FIFOs (Bytes) */
  92712. + uint16_t perio_tx_fifo_size[MAX_PERIO_FIFOS];
  92713. +
  92714. + /** Size of Tx FIFOs (Bytes) */
  92715. + uint16_t tx_fifo_size[MAX_TX_FIFOS];
  92716. +
  92717. + /** Thresholding enable flags and length varaiables **/
  92718. + uint16_t rx_thr_en;
  92719. + uint16_t iso_tx_thr_en;
  92720. + uint16_t non_iso_tx_thr_en;
  92721. +
  92722. + uint16_t rx_thr_length;
  92723. + uint16_t tx_thr_length;
  92724. +
  92725. + /**
  92726. + * Pointers to the DMA Descriptors for EP0 Control
  92727. + * transfers (virtual and physical)
  92728. + */
  92729. +
  92730. + /** 2 descriptors for SETUP packets */
  92731. + dwc_dma_t dma_setup_desc_addr[2];
  92732. + dwc_otg_dev_dma_desc_t *setup_desc_addr[2];
  92733. +
  92734. + /** Pointer to Descriptor with latest SETUP packet */
  92735. + dwc_otg_dev_dma_desc_t *psetup;
  92736. +
  92737. + /** Index of current SETUP handler descriptor */
  92738. + uint32_t setup_desc_index;
  92739. +
  92740. + /** Descriptor for Data In or Status In phases */
  92741. + dwc_dma_t dma_in_desc_addr;
  92742. + dwc_otg_dev_dma_desc_t *in_desc_addr;
  92743. +
  92744. + /** Descriptor for Data Out or Status Out phases */
  92745. + dwc_dma_t dma_out_desc_addr;
  92746. + dwc_otg_dev_dma_desc_t *out_desc_addr;
  92747. +
  92748. + /** Setup Packet Detected - if set clear NAK when queueing */
  92749. + uint32_t spd;
  92750. + /** Isoc ep pointer on which incomplete happens */
  92751. + void *isoc_ep;
  92752. +
  92753. +} dwc_otg_dev_if_t;
  92754. +
  92755. +/////////////////////////////////////////////////
  92756. +// Host Mode Register Structures
  92757. +//
  92758. +/**
  92759. + * The Host Global Registers structure defines the size and relative
  92760. + * field offsets for the Host Mode Global Registers. Host Global
  92761. + * Registers offsets 400h-7FFh.
  92762. +*/
  92763. +typedef struct dwc_otg_host_global_regs {
  92764. + /** Host Configuration Register. <i>Offset: 400h</i> */
  92765. + volatile uint32_t hcfg;
  92766. + /** Host Frame Interval Register. <i>Offset: 404h</i> */
  92767. + volatile uint32_t hfir;
  92768. + /** Host Frame Number / Frame Remaining Register. <i>Offset: 408h</i> */
  92769. + volatile uint32_t hfnum;
  92770. + /** Reserved. <i>Offset: 40Ch</i> */
  92771. + uint32_t reserved40C;
  92772. + /** Host Periodic Transmit FIFO/ Queue Status Register. <i>Offset: 410h</i> */
  92773. + volatile uint32_t hptxsts;
  92774. + /** Host All Channels Interrupt Register. <i>Offset: 414h</i> */
  92775. + volatile uint32_t haint;
  92776. + /** Host All Channels Interrupt Mask Register. <i>Offset: 418h</i> */
  92777. + volatile uint32_t haintmsk;
  92778. + /** Host Frame List Base Address Register . <i>Offset: 41Ch</i> */
  92779. + volatile uint32_t hflbaddr;
  92780. +} dwc_otg_host_global_regs_t;
  92781. +
  92782. +/**
  92783. + * This union represents the bit fields in the Host Configuration Register.
  92784. + * Read the register into the <i>d32</i> member then set/clear the bits using
  92785. + * the <i>b</i>it elements. Write the <i>d32</i> member to the hcfg register.
  92786. + */
  92787. +typedef union hcfg_data {
  92788. + /** raw register data */
  92789. + uint32_t d32;
  92790. +
  92791. + /** register bits */
  92792. + struct {
  92793. + /** FS/LS Phy Clock Select */
  92794. + unsigned fslspclksel:2;
  92795. +#define DWC_HCFG_30_60_MHZ 0
  92796. +#define DWC_HCFG_48_MHZ 1
  92797. +#define DWC_HCFG_6_MHZ 2
  92798. +
  92799. + /** FS/LS Only Support */
  92800. + unsigned fslssupp:1;
  92801. + unsigned reserved3_6:4;
  92802. + /** Enable 32-KHz Suspend Mode */
  92803. + unsigned ena32khzs:1;
  92804. + /** Resume Validation Periiod */
  92805. + unsigned resvalid:8;
  92806. + unsigned reserved16_22:7;
  92807. + /** Enable Scatter/gather DMA in Host mode */
  92808. + unsigned descdma:1;
  92809. + /** Frame List Entries */
  92810. + unsigned frlisten:2;
  92811. + /** Enable Periodic Scheduling */
  92812. + unsigned perschedena:1;
  92813. + unsigned reserved27_30:4;
  92814. + unsigned modechtimen:1;
  92815. + } b;
  92816. +} hcfg_data_t;
  92817. +
  92818. +/**
  92819. + * This union represents the bit fields in the Host Frame Remaing/Number
  92820. + * Register.
  92821. + */
  92822. +typedef union hfir_data {
  92823. + /** raw register data */
  92824. + uint32_t d32;
  92825. +
  92826. + /** register bits */
  92827. + struct {
  92828. + unsigned frint:16;
  92829. + unsigned hfirrldctrl:1;
  92830. + unsigned reserved:15;
  92831. + } b;
  92832. +} hfir_data_t;
  92833. +
  92834. +/**
  92835. + * This union represents the bit fields in the Host Frame Remaing/Number
  92836. + * Register.
  92837. + */
  92838. +typedef union hfnum_data {
  92839. + /** raw register data */
  92840. + uint32_t d32;
  92841. +
  92842. + /** register bits */
  92843. + struct {
  92844. + unsigned frnum:16;
  92845. +#define DWC_HFNUM_MAX_FRNUM 0x3FFF
  92846. + unsigned frrem:16;
  92847. + } b;
  92848. +} hfnum_data_t;
  92849. +
  92850. +typedef union hptxsts_data {
  92851. + /** raw register data */
  92852. + uint32_t d32;
  92853. +
  92854. + /** register bits */
  92855. + struct {
  92856. + unsigned ptxfspcavail:16;
  92857. + unsigned ptxqspcavail:8;
  92858. + /** Top of the Periodic Transmit Request Queue
  92859. + * - bit 24 - Terminate (last entry for the selected channel)
  92860. + * - bits 26:25 - Token Type
  92861. + * - 2'b00 - Zero length
  92862. + * - 2'b01 - Ping
  92863. + * - 2'b10 - Disable
  92864. + * - bits 30:27 - Channel Number
  92865. + * - bit 31 - Odd/even microframe
  92866. + */
  92867. + unsigned ptxqtop_terminate:1;
  92868. + unsigned ptxqtop_token:2;
  92869. + unsigned ptxqtop_chnum:4;
  92870. + unsigned ptxqtop_odd:1;
  92871. + } b;
  92872. +} hptxsts_data_t;
  92873. +
  92874. +/**
  92875. + * This union represents the bit fields in the Host Port Control and Status
  92876. + * Register. Read the register into the <i>d32</i> member then set/clear the
  92877. + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
  92878. + * hprt0 register.
  92879. + */
  92880. +typedef union hprt0_data {
  92881. + /** raw register data */
  92882. + uint32_t d32;
  92883. + /** register bits */
  92884. + struct {
  92885. + unsigned prtconnsts:1;
  92886. + unsigned prtconndet:1;
  92887. + unsigned prtena:1;
  92888. + unsigned prtenchng:1;
  92889. + unsigned prtovrcurract:1;
  92890. + unsigned prtovrcurrchng:1;
  92891. + unsigned prtres:1;
  92892. + unsigned prtsusp:1;
  92893. + unsigned prtrst:1;
  92894. + unsigned reserved9:1;
  92895. + unsigned prtlnsts:2;
  92896. + unsigned prtpwr:1;
  92897. + unsigned prttstctl:4;
  92898. + unsigned prtspd:2;
  92899. +#define DWC_HPRT0_PRTSPD_HIGH_SPEED 0
  92900. +#define DWC_HPRT0_PRTSPD_FULL_SPEED 1
  92901. +#define DWC_HPRT0_PRTSPD_LOW_SPEED 2
  92902. + unsigned reserved19_31:13;
  92903. + } b;
  92904. +} hprt0_data_t;
  92905. +
  92906. +/**
  92907. + * This union represents the bit fields in the Host All Interrupt
  92908. + * Register.
  92909. + */
  92910. +typedef union haint_data {
  92911. + /** raw register data */
  92912. + uint32_t d32;
  92913. + /** register bits */
  92914. + struct {
  92915. + unsigned ch0:1;
  92916. + unsigned ch1:1;
  92917. + unsigned ch2:1;
  92918. + unsigned ch3:1;
  92919. + unsigned ch4:1;
  92920. + unsigned ch5:1;
  92921. + unsigned ch6:1;
  92922. + unsigned ch7:1;
  92923. + unsigned ch8:1;
  92924. + unsigned ch9:1;
  92925. + unsigned ch10:1;
  92926. + unsigned ch11:1;
  92927. + unsigned ch12:1;
  92928. + unsigned ch13:1;
  92929. + unsigned ch14:1;
  92930. + unsigned ch15:1;
  92931. + unsigned reserved:16;
  92932. + } b;
  92933. +
  92934. + struct {
  92935. + unsigned chint:16;
  92936. + unsigned reserved:16;
  92937. + } b2;
  92938. +} haint_data_t;
  92939. +
  92940. +/**
  92941. + * This union represents the bit fields in the Host All Interrupt
  92942. + * Register.
  92943. + */
  92944. +typedef union haintmsk_data {
  92945. + /** raw register data */
  92946. + uint32_t d32;
  92947. + /** register bits */
  92948. + struct {
  92949. + unsigned ch0:1;
  92950. + unsigned ch1:1;
  92951. + unsigned ch2:1;
  92952. + unsigned ch3:1;
  92953. + unsigned ch4:1;
  92954. + unsigned ch5:1;
  92955. + unsigned ch6:1;
  92956. + unsigned ch7:1;
  92957. + unsigned ch8:1;
  92958. + unsigned ch9:1;
  92959. + unsigned ch10:1;
  92960. + unsigned ch11:1;
  92961. + unsigned ch12:1;
  92962. + unsigned ch13:1;
  92963. + unsigned ch14:1;
  92964. + unsigned ch15:1;
  92965. + unsigned reserved:16;
  92966. + } b;
  92967. +
  92968. + struct {
  92969. + unsigned chint:16;
  92970. + unsigned reserved:16;
  92971. + } b2;
  92972. +} haintmsk_data_t;
  92973. +
  92974. +/**
  92975. + * Host Channel Specific Registers. <i>500h-5FCh</i>
  92976. + */
  92977. +typedef struct dwc_otg_hc_regs {
  92978. + /** Host Channel 0 Characteristic Register. <i>Offset: 500h + (chan_num * 20h) + 00h</i> */
  92979. + volatile uint32_t hcchar;
  92980. + /** Host Channel 0 Split Control Register. <i>Offset: 500h + (chan_num * 20h) + 04h</i> */
  92981. + volatile uint32_t hcsplt;
  92982. + /** Host Channel 0 Interrupt Register. <i>Offset: 500h + (chan_num * 20h) + 08h</i> */
  92983. + volatile uint32_t hcint;
  92984. + /** Host Channel 0 Interrupt Mask Register. <i>Offset: 500h + (chan_num * 20h) + 0Ch</i> */
  92985. + volatile uint32_t hcintmsk;
  92986. + /** Host Channel 0 Transfer Size Register. <i>Offset: 500h + (chan_num * 20h) + 10h</i> */
  92987. + volatile uint32_t hctsiz;
  92988. + /** Host Channel 0 DMA Address Register. <i>Offset: 500h + (chan_num * 20h) + 14h</i> */
  92989. + volatile uint32_t hcdma;
  92990. + volatile uint32_t reserved;
  92991. + /** Host Channel 0 DMA Buffer Address Register. <i>Offset: 500h + (chan_num * 20h) + 1Ch</i> */
  92992. + volatile uint32_t hcdmab;
  92993. +} dwc_otg_hc_regs_t;
  92994. +
  92995. +/**
  92996. + * This union represents the bit fields in the Host Channel Characteristics
  92997. + * Register. Read the register into the <i>d32</i> member then set/clear the
  92998. + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
  92999. + * hcchar register.
  93000. + */
  93001. +typedef union hcchar_data {
  93002. + /** raw register data */
  93003. + uint32_t d32;
  93004. +
  93005. + /** register bits */
  93006. + struct {
  93007. + /** Maximum packet size in bytes */
  93008. + unsigned mps:11;
  93009. +
  93010. + /** Endpoint number */
  93011. + unsigned epnum:4;
  93012. +
  93013. + /** 0: OUT, 1: IN */
  93014. + unsigned epdir:1;
  93015. +
  93016. + unsigned reserved:1;
  93017. +
  93018. + /** 0: Full/high speed device, 1: Low speed device */
  93019. + unsigned lspddev:1;
  93020. +
  93021. + /** 0: Control, 1: Isoc, 2: Bulk, 3: Intr */
  93022. + unsigned eptype:2;
  93023. +
  93024. + /** Packets per frame for periodic transfers. 0 is reserved. */
  93025. + unsigned multicnt:2;
  93026. +
  93027. + /** Device address */
  93028. + unsigned devaddr:7;
  93029. +
  93030. + /**
  93031. + * Frame to transmit periodic transaction.
  93032. + * 0: even, 1: odd
  93033. + */
  93034. + unsigned oddfrm:1;
  93035. +
  93036. + /** Channel disable */
  93037. + unsigned chdis:1;
  93038. +
  93039. + /** Channel enable */
  93040. + unsigned chen:1;
  93041. + } b;
  93042. +} hcchar_data_t;
  93043. +
  93044. +typedef union hcsplt_data {
  93045. + /** raw register data */
  93046. + uint32_t d32;
  93047. +
  93048. + /** register bits */
  93049. + struct {
  93050. + /** Port Address */
  93051. + unsigned prtaddr:7;
  93052. +
  93053. + /** Hub Address */
  93054. + unsigned hubaddr:7;
  93055. +
  93056. + /** Transaction Position */
  93057. + unsigned xactpos:2;
  93058. +#define DWC_HCSPLIT_XACTPOS_MID 0
  93059. +#define DWC_HCSPLIT_XACTPOS_END 1
  93060. +#define DWC_HCSPLIT_XACTPOS_BEGIN 2
  93061. +#define DWC_HCSPLIT_XACTPOS_ALL 3
  93062. +
  93063. + /** Do Complete Split */
  93064. + unsigned compsplt:1;
  93065. +
  93066. + /** Reserved */
  93067. + unsigned reserved:14;
  93068. +
  93069. + /** Split Enble */
  93070. + unsigned spltena:1;
  93071. + } b;
  93072. +} hcsplt_data_t;
  93073. +
  93074. +/**
  93075. + * This union represents the bit fields in the Host All Interrupt
  93076. + * Register.
  93077. + */
  93078. +typedef union hcint_data {
  93079. + /** raw register data */
  93080. + uint32_t d32;
  93081. + /** register bits */
  93082. + struct {
  93083. + /** Transfer Complete */
  93084. + unsigned xfercomp:1;
  93085. + /** Channel Halted */
  93086. + unsigned chhltd:1;
  93087. + /** AHB Error */
  93088. + unsigned ahberr:1;
  93089. + /** STALL Response Received */
  93090. + unsigned stall:1;
  93091. + /** NAK Response Received */
  93092. + unsigned nak:1;
  93093. + /** ACK Response Received */
  93094. + unsigned ack:1;
  93095. + /** NYET Response Received */
  93096. + unsigned nyet:1;
  93097. + /** Transaction Err */
  93098. + unsigned xacterr:1;
  93099. + /** Babble Error */
  93100. + unsigned bblerr:1;
  93101. + /** Frame Overrun */
  93102. + unsigned frmovrun:1;
  93103. + /** Data Toggle Error */
  93104. + unsigned datatglerr:1;
  93105. + /** Buffer Not Available (only for DDMA mode) */
  93106. + unsigned bna:1;
  93107. + /** Exessive transaction error (only for DDMA mode) */
  93108. + unsigned xcs_xact:1;
  93109. + /** Frame List Rollover interrupt */
  93110. + unsigned frm_list_roll:1;
  93111. + /** Reserved */
  93112. + unsigned reserved14_31:18;
  93113. + } b;
  93114. +} hcint_data_t;
  93115. +
  93116. +/**
  93117. + * This union represents the bit fields in the Host Channel Interrupt Mask
  93118. + * Register. Read the register into the <i>d32</i> member then set/clear the
  93119. + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
  93120. + * hcintmsk register.
  93121. + */
  93122. +typedef union hcintmsk_data {
  93123. + /** raw register data */
  93124. + uint32_t d32;
  93125. +
  93126. + /** register bits */
  93127. + struct {
  93128. + unsigned xfercompl:1;
  93129. + unsigned chhltd:1;
  93130. + unsigned ahberr:1;
  93131. + unsigned stall:1;
  93132. + unsigned nak:1;
  93133. + unsigned ack:1;
  93134. + unsigned nyet:1;
  93135. + unsigned xacterr:1;
  93136. + unsigned bblerr:1;
  93137. + unsigned frmovrun:1;
  93138. + unsigned datatglerr:1;
  93139. + unsigned bna:1;
  93140. + unsigned xcs_xact:1;
  93141. + unsigned frm_list_roll:1;
  93142. + unsigned reserved14_31:18;
  93143. + } b;
  93144. +} hcintmsk_data_t;
  93145. +
  93146. +/**
  93147. + * This union represents the bit fields in the Host Channel Transfer Size
  93148. + * Register. Read the register into the <i>d32</i> member then set/clear the
  93149. + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
  93150. + * hcchar register.
  93151. + */
  93152. +
  93153. +typedef union hctsiz_data {
  93154. + /** raw register data */
  93155. + uint32_t d32;
  93156. +
  93157. + /** register bits */
  93158. + struct {
  93159. + /** Total transfer size in bytes */
  93160. + unsigned xfersize:19;
  93161. +
  93162. + /** Data packets to transfer */
  93163. + unsigned pktcnt:10;
  93164. +
  93165. + /**
  93166. + * Packet ID for next data packet
  93167. + * 0: DATA0
  93168. + * 1: DATA2
  93169. + * 2: DATA1
  93170. + * 3: MDATA (non-Control), SETUP (Control)
  93171. + */
  93172. + unsigned pid:2;
  93173. +#define DWC_HCTSIZ_DATA0 0
  93174. +#define DWC_HCTSIZ_DATA1 2
  93175. +#define DWC_HCTSIZ_DATA2 1
  93176. +#define DWC_HCTSIZ_MDATA 3
  93177. +#define DWC_HCTSIZ_SETUP 3
  93178. +
  93179. + /** Do PING protocol when 1 */
  93180. + unsigned dopng:1;
  93181. + } b;
  93182. +
  93183. + /** register bits */
  93184. + struct {
  93185. + /** Scheduling information */
  93186. + unsigned schinfo:8;
  93187. +
  93188. + /** Number of transfer descriptors.
  93189. + * Max value:
  93190. + * 64 in general,
  93191. + * 256 only for HS isochronous endpoint.
  93192. + */
  93193. + unsigned ntd:8;
  93194. +
  93195. + /** Data packets to transfer */
  93196. + unsigned reserved16_28:13;
  93197. +
  93198. + /**
  93199. + * Packet ID for next data packet
  93200. + * 0: DATA0
  93201. + * 1: DATA2
  93202. + * 2: DATA1
  93203. + * 3: MDATA (non-Control)
  93204. + */
  93205. + unsigned pid:2;
  93206. +
  93207. + /** Do PING protocol when 1 */
  93208. + unsigned dopng:1;
  93209. + } b_ddma;
  93210. +} hctsiz_data_t;
  93211. +
  93212. +/**
  93213. + * This union represents the bit fields in the Host DMA Address
  93214. + * Register used in Descriptor DMA mode.
  93215. + */
  93216. +typedef union hcdma_data {
  93217. + /** raw register data */
  93218. + uint32_t d32;
  93219. + /** register bits */
  93220. + struct {
  93221. + unsigned reserved0_2:3;
  93222. + /** Current Transfer Descriptor. Not used for ISOC */
  93223. + unsigned ctd:8;
  93224. + /** Start Address of Descriptor List */
  93225. + unsigned dma_addr:21;
  93226. + } b;
  93227. +} hcdma_data_t;
  93228. +
  93229. +/**
  93230. + * This union represents the bit fields in the DMA Descriptor
  93231. + * status quadlet for host mode. Read the quadlet into the <i>d32</i> member then
  93232. + * set/clear the bits using the <i>b</i>it elements.
  93233. + */
  93234. +typedef union host_dma_desc_sts {
  93235. + /** raw register data */
  93236. + uint32_t d32;
  93237. + /** quadlet bits */
  93238. +
  93239. + /* for non-isochronous */
  93240. + struct {
  93241. + /** Number of bytes */
  93242. + unsigned n_bytes:17;
  93243. + /** QTD offset to jump when Short Packet received - only for IN EPs */
  93244. + unsigned qtd_offset:6;
  93245. + /**
  93246. + * Set to request the core to jump to alternate QTD if
  93247. + * Short Packet received - only for IN EPs
  93248. + */
  93249. + unsigned a_qtd:1;
  93250. + /**
  93251. + * Setup Packet bit. When set indicates that buffer contains
  93252. + * setup packet.
  93253. + */
  93254. + unsigned sup:1;
  93255. + /** Interrupt On Complete */
  93256. + unsigned ioc:1;
  93257. + /** End of List */
  93258. + unsigned eol:1;
  93259. + unsigned reserved27:1;
  93260. + /** Rx/Tx Status */
  93261. + unsigned sts:2;
  93262. +#define DMA_DESC_STS_PKTERR 1
  93263. + unsigned reserved30:1;
  93264. + /** Active Bit */
  93265. + unsigned a:1;
  93266. + } b;
  93267. + /* for isochronous */
  93268. + struct {
  93269. + /** Number of bytes */
  93270. + unsigned n_bytes:12;
  93271. + unsigned reserved12_24:13;
  93272. + /** Interrupt On Complete */
  93273. + unsigned ioc:1;
  93274. + unsigned reserved26_27:2;
  93275. + /** Rx/Tx Status */
  93276. + unsigned sts:2;
  93277. + unsigned reserved30:1;
  93278. + /** Active Bit */
  93279. + unsigned a:1;
  93280. + } b_isoc;
  93281. +} host_dma_desc_sts_t;
  93282. +
  93283. +#define MAX_DMA_DESC_SIZE 131071
  93284. +#define MAX_DMA_DESC_NUM_GENERIC 64
  93285. +#define MAX_DMA_DESC_NUM_HS_ISOC 256
  93286. +#define MAX_FRLIST_EN_NUM 64
  93287. +/**
  93288. + * Host-mode DMA Descriptor structure
  93289. + *
  93290. + * DMA Descriptor structure contains two quadlets:
  93291. + * Status quadlet and Data buffer pointer.
  93292. + */
  93293. +typedef struct dwc_otg_host_dma_desc {
  93294. + /** DMA Descriptor status quadlet */
  93295. + host_dma_desc_sts_t status;
  93296. + /** DMA Descriptor data buffer pointer */
  93297. + uint32_t buf;
  93298. +} dwc_otg_host_dma_desc_t;
  93299. +
  93300. +/** OTG Host Interface Structure.
  93301. + *
  93302. + * The OTG Host Interface Structure structure contains information
  93303. + * needed to manage the DWC_otg controller acting in host mode. It
  93304. + * represents the programming view of the host-specific aspects of the
  93305. + * controller.
  93306. + */
  93307. +typedef struct dwc_otg_host_if {
  93308. + /** Host Global Registers starting at offset 400h.*/
  93309. + dwc_otg_host_global_regs_t *host_global_regs;
  93310. +#define DWC_OTG_HOST_GLOBAL_REG_OFFSET 0x400
  93311. +
  93312. + /** Host Port 0 Control and Status Register */
  93313. + volatile uint32_t *hprt0;
  93314. +#define DWC_OTG_HOST_PORT_REGS_OFFSET 0x440
  93315. +
  93316. + /** Host Channel Specific Registers at offsets 500h-5FCh. */
  93317. + dwc_otg_hc_regs_t *hc_regs[MAX_EPS_CHANNELS];
  93318. +#define DWC_OTG_HOST_CHAN_REGS_OFFSET 0x500
  93319. +#define DWC_OTG_CHAN_REGS_OFFSET 0x20
  93320. +
  93321. + /* Host configuration information */
  93322. + /** Number of Host Channels (range: 1-16) */
  93323. + uint8_t num_host_channels;
  93324. + /** Periodic EPs supported (0: no, 1: yes) */
  93325. + uint8_t perio_eps_supported;
  93326. + /** Periodic Tx FIFO Size (Only 1 host periodic Tx FIFO) */
  93327. + uint16_t perio_tx_fifo_size;
  93328. +
  93329. +} dwc_otg_host_if_t;
  93330. +
  93331. +/**
  93332. + * This union represents the bit fields in the Power and Clock Gating Control
  93333. + * Register. Read the register into the <i>d32</i> member then set/clear the
  93334. + * bits using the <i>b</i>it elements.
  93335. + */
  93336. +typedef union pcgcctl_data {
  93337. + /** raw register data */
  93338. + uint32_t d32;
  93339. +
  93340. + /** register bits */
  93341. + struct {
  93342. + /** Stop Pclk */
  93343. + unsigned stoppclk:1;
  93344. + /** Gate Hclk */
  93345. + unsigned gatehclk:1;
  93346. + /** Power Clamp */
  93347. + unsigned pwrclmp:1;
  93348. + /** Reset Power Down Modules */
  93349. + unsigned rstpdwnmodule:1;
  93350. + /** Reserved */
  93351. + unsigned reserved:1;
  93352. + /** Enable Sleep Clock Gating (Enbl_L1Gating) */
  93353. + unsigned enbl_sleep_gating:1;
  93354. + /** PHY In Sleep (PhySleep) */
  93355. + unsigned phy_in_sleep:1;
  93356. + /** Deep Sleep*/
  93357. + unsigned deep_sleep:1;
  93358. + unsigned resetaftsusp:1;
  93359. + unsigned restoremode:1;
  93360. + unsigned enbl_extnd_hiber:1;
  93361. + unsigned extnd_hiber_pwrclmp:1;
  93362. + unsigned extnd_hiber_switch:1;
  93363. + unsigned ess_reg_restored:1;
  93364. + unsigned prt_clk_sel:2;
  93365. + unsigned port_power:1;
  93366. + unsigned max_xcvrselect:2;
  93367. + unsigned max_termsel:1;
  93368. + unsigned mac_dev_addr:7;
  93369. + unsigned p2hd_dev_enum_spd:2;
  93370. + unsigned p2hd_prt_spd:2;
  93371. + unsigned if_dev_mode:1;
  93372. + } b;
  93373. +} pcgcctl_data_t;
  93374. +
  93375. +/**
  93376. + * This union represents the bit fields in the Global Data FIFO Software
  93377. + * Configuration Register. Read the register into the <i>d32</i> member then
  93378. + * set/clear the bits using the <i>b</i>it elements.
  93379. + */
  93380. +typedef union gdfifocfg_data {
  93381. + /* raw register data */
  93382. + uint32_t d32;
  93383. + /** register bits */
  93384. + struct {
  93385. + /** OTG Data FIFO depth */
  93386. + unsigned gdfifocfg:16;
  93387. + /** Start address of EP info controller */
  93388. + unsigned epinfobase:16;
  93389. + } b;
  93390. +} gdfifocfg_data_t;
  93391. +
  93392. +/**
  93393. + * This union represents the bit fields in the Global Power Down Register
  93394. + * Register. Read the register into the <i>d32</i> member then set/clear the
  93395. + * bits using the <i>b</i>it elements.
  93396. + */
  93397. +typedef union gpwrdn_data {
  93398. + /* raw register data */
  93399. + uint32_t d32;
  93400. +
  93401. + /** register bits */
  93402. + struct {
  93403. + /** PMU Interrupt Select */
  93404. + unsigned pmuintsel:1;
  93405. + /** PMU Active */
  93406. + unsigned pmuactv:1;
  93407. + /** Restore */
  93408. + unsigned restore:1;
  93409. + /** Power Down Clamp */
  93410. + unsigned pwrdnclmp:1;
  93411. + /** Power Down Reset */
  93412. + unsigned pwrdnrstn:1;
  93413. + /** Power Down Switch */
  93414. + unsigned pwrdnswtch:1;
  93415. + /** Disable VBUS */
  93416. + unsigned dis_vbus:1;
  93417. + /** Line State Change */
  93418. + unsigned lnstschng:1;
  93419. + /** Line state change mask */
  93420. + unsigned lnstchng_msk:1;
  93421. + /** Reset Detected */
  93422. + unsigned rst_det:1;
  93423. + /** Reset Detect mask */
  93424. + unsigned rst_det_msk:1;
  93425. + /** Disconnect Detected */
  93426. + unsigned disconn_det:1;
  93427. + /** Disconnect Detect mask */
  93428. + unsigned disconn_det_msk:1;
  93429. + /** Connect Detected*/
  93430. + unsigned connect_det:1;
  93431. + /** Connect Detected Mask*/
  93432. + unsigned connect_det_msk:1;
  93433. + /** SRP Detected */
  93434. + unsigned srp_det:1;
  93435. + /** SRP Detect mask */
  93436. + unsigned srp_det_msk:1;
  93437. + /** Status Change Interrupt */
  93438. + unsigned sts_chngint:1;
  93439. + /** Status Change Interrupt Mask */
  93440. + unsigned sts_chngint_msk:1;
  93441. + /** Line State */
  93442. + unsigned linestate:2;
  93443. + /** Indicates current mode(status of IDDIG signal) */
  93444. + unsigned idsts:1;
  93445. + /** B Session Valid signal status*/
  93446. + unsigned bsessvld:1;
  93447. + /** ADP Event Detected */
  93448. + unsigned adp_int:1;
  93449. + /** Multi Valued ID pin */
  93450. + unsigned mult_val_id_bc:5;
  93451. + /** Reserved 24_31 */
  93452. + unsigned reserved29_31:3;
  93453. + } b;
  93454. +} gpwrdn_data_t;
  93455. +
  93456. +#endif
  93457. diff -Nur linux-3.13.11/drivers/usb/host/dwc_otg/Makefile linux-rpi/drivers/usb/host/dwc_otg/Makefile
  93458. --- linux-3.13.11/drivers/usb/host/dwc_otg/Makefile 1970-01-01 01:00:00.000000000 +0100
  93459. +++ linux-rpi/drivers/usb/host/dwc_otg/Makefile 2014-04-24 15:37:13.306990445 +0200
  93460. @@ -0,0 +1,82 @@
  93461. +#
  93462. +# Makefile for DWC_otg Highspeed USB controller driver
  93463. +#
  93464. +
  93465. +ifneq ($(KERNELRELEASE),)
  93466. +
  93467. +# Use the BUS_INTERFACE variable to compile the software for either
  93468. +# PCI(PCI_INTERFACE) or LM(LM_INTERFACE) bus.
  93469. +ifeq ($(BUS_INTERFACE),)
  93470. +# BUS_INTERFACE = -DPCI_INTERFACE
  93471. +# BUS_INTERFACE = -DLM_INTERFACE
  93472. + BUS_INTERFACE = -DPLATFORM_INTERFACE
  93473. +endif
  93474. +
  93475. +#ccflags-y += -DDEBUG
  93476. +#ccflags-y += -DDWC_OTG_DEBUGLEV=1 # reduce common debug msgs
  93477. +
  93478. +# Use one of the following flags to compile the software in host-only or
  93479. +# device-only mode.
  93480. +#ccflags-y += -DDWC_HOST_ONLY
  93481. +#ccflags-y += -DDWC_DEVICE_ONLY
  93482. +
  93483. +ccflags-y += -Dlinux -DDWC_HS_ELECT_TST
  93484. +#ccflags-y += -DDWC_EN_ISOC
  93485. +ccflags-y += -I$(obj)/../dwc_common_port
  93486. +#ccflags-y += -I$(PORTLIB)
  93487. +ccflags-y += -DDWC_LINUX
  93488. +ccflags-y += $(CFI)
  93489. +ccflags-y += $(BUS_INTERFACE)
  93490. +#ccflags-y += -DDWC_DEV_SRPCAP
  93491. +
  93492. +obj-$(CONFIG_USB_DWCOTG) += dwc_otg.o
  93493. +
  93494. +dwc_otg-objs := dwc_otg_driver.o dwc_otg_attr.o
  93495. +dwc_otg-objs += dwc_otg_cil.o dwc_otg_cil_intr.o
  93496. +dwc_otg-objs += dwc_otg_pcd_linux.o dwc_otg_pcd.o dwc_otg_pcd_intr.o
  93497. +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
  93498. +dwc_otg-objs += dwc_otg_adp.o
  93499. +dwc_otg-objs += dwc_otg_fiq_fsm.o
  93500. +dwc_otg-objs += dwc_otg_fiq_stub.o
  93501. +ifneq ($(CFI),)
  93502. +dwc_otg-objs += dwc_otg_cfi.o
  93503. +endif
  93504. +
  93505. +kernrelwd := $(subst ., ,$(KERNELRELEASE))
  93506. +kernrel3 := $(word 1,$(kernrelwd)).$(word 2,$(kernrelwd)).$(word 3,$(kernrelwd))
  93507. +
  93508. +ifneq ($(kernrel3),2.6.20)
  93509. +ccflags-y += $(CPPFLAGS)
  93510. +endif
  93511. +
  93512. +else
  93513. +
  93514. +PWD := $(shell pwd)
  93515. +PORTLIB := $(PWD)/../dwc_common_port
  93516. +
  93517. +# Command paths
  93518. +CTAGS := $(CTAGS)
  93519. +DOXYGEN := $(DOXYGEN)
  93520. +
  93521. +default: portlib
  93522. + $(MAKE) -C$(KDIR) M=$(PWD) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules
  93523. +
  93524. +install: default
  93525. + $(MAKE) -C$(KDIR) M=$(PORTLIB) modules_install
  93526. + $(MAKE) -C$(KDIR) M=$(PWD) modules_install
  93527. +
  93528. +portlib:
  93529. + $(MAKE) -C$(KDIR) M=$(PORTLIB) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules
  93530. + cp $(PORTLIB)/Module.symvers $(PWD)/
  93531. +
  93532. +docs: $(wildcard *.[hc]) doc/doxygen.cfg
  93533. + $(DOXYGEN) doc/doxygen.cfg
  93534. +
  93535. +tags: $(wildcard *.[hc])
  93536. + $(CTAGS) -e $(wildcard *.[hc]) $(wildcard linux/*.[hc]) $(wildcard $(KDIR)/include/linux/usb*.h)
  93537. +
  93538. +
  93539. +clean:
  93540. + rm -rf *.o *.ko .*cmd *.mod.c .tmp_versions Module.symvers
  93541. +
  93542. +endif
  93543. diff -Nur linux-3.13.11/drivers/usb/host/dwc_otg/test/dwc_otg_test.pm linux-rpi/drivers/usb/host/dwc_otg/test/dwc_otg_test.pm
  93544. --- linux-3.13.11/drivers/usb/host/dwc_otg/test/dwc_otg_test.pm 1970-01-01 01:00:00.000000000 +0100
  93545. +++ linux-rpi/drivers/usb/host/dwc_otg/test/dwc_otg_test.pm 2014-04-24 15:37:13.318990576 +0200
  93546. @@ -0,0 +1,337 @@
  93547. +package dwc_otg_test;
  93548. +
  93549. +use strict;
  93550. +use Exporter ();
  93551. +
  93552. +use vars qw(@ISA @EXPORT
  93553. +$sysfsdir $paramdir $errors $params
  93554. +);
  93555. +
  93556. +@ISA = qw(Exporter);
  93557. +
  93558. +#
  93559. +# Globals
  93560. +#
  93561. +$sysfsdir = "/sys/devices/lm0";
  93562. +$paramdir = "/sys/module/dwc_otg";
  93563. +$errors = 0;
  93564. +
  93565. +$params = [
  93566. + {
  93567. + NAME => "otg_cap",
  93568. + DEFAULT => 0,
  93569. + ENUM => [],
  93570. + LOW => 0,
  93571. + HIGH => 2
  93572. + },
  93573. + {
  93574. + NAME => "dma_enable",
  93575. + DEFAULT => 0,
  93576. + ENUM => [],
  93577. + LOW => 0,
  93578. + HIGH => 1
  93579. + },
  93580. + {
  93581. + NAME => "dma_burst_size",
  93582. + DEFAULT => 32,
  93583. + ENUM => [1, 4, 8, 16, 32, 64, 128, 256],
  93584. + LOW => 1,
  93585. + HIGH => 256
  93586. + },
  93587. + {
  93588. + NAME => "host_speed",
  93589. + DEFAULT => 0,
  93590. + ENUM => [],
  93591. + LOW => 0,
  93592. + HIGH => 1
  93593. + },
  93594. + {
  93595. + NAME => "host_support_fs_ls_low_power",
  93596. + DEFAULT => 0,
  93597. + ENUM => [],
  93598. + LOW => 0,
  93599. + HIGH => 1
  93600. + },
  93601. + {
  93602. + NAME => "host_ls_low_power_phy_clk",
  93603. + DEFAULT => 0,
  93604. + ENUM => [],
  93605. + LOW => 0,
  93606. + HIGH => 1
  93607. + },
  93608. + {
  93609. + NAME => "dev_speed",
  93610. + DEFAULT => 0,
  93611. + ENUM => [],
  93612. + LOW => 0,
  93613. + HIGH => 1
  93614. + },
  93615. + {
  93616. + NAME => "enable_dynamic_fifo",
  93617. + DEFAULT => 1,
  93618. + ENUM => [],
  93619. + LOW => 0,
  93620. + HIGH => 1
  93621. + },
  93622. + {
  93623. + NAME => "data_fifo_size",
  93624. + DEFAULT => 8192,
  93625. + ENUM => [],
  93626. + LOW => 32,
  93627. + HIGH => 32768
  93628. + },
  93629. + {
  93630. + NAME => "dev_rx_fifo_size",
  93631. + DEFAULT => 1064,
  93632. + ENUM => [],
  93633. + LOW => 16,
  93634. + HIGH => 32768
  93635. + },
  93636. + {
  93637. + NAME => "dev_nperio_tx_fifo_size",
  93638. + DEFAULT => 1024,
  93639. + ENUM => [],
  93640. + LOW => 16,
  93641. + HIGH => 32768
  93642. + },
  93643. + {
  93644. + NAME => "dev_perio_tx_fifo_size_1",
  93645. + DEFAULT => 256,
  93646. + ENUM => [],
  93647. + LOW => 4,
  93648. + HIGH => 768
  93649. + },
  93650. + {
  93651. + NAME => "dev_perio_tx_fifo_size_2",
  93652. + DEFAULT => 256,
  93653. + ENUM => [],
  93654. + LOW => 4,
  93655. + HIGH => 768
  93656. + },
  93657. + {
  93658. + NAME => "dev_perio_tx_fifo_size_3",
  93659. + DEFAULT => 256,
  93660. + ENUM => [],
  93661. + LOW => 4,
  93662. + HIGH => 768
  93663. + },
  93664. + {
  93665. + NAME => "dev_perio_tx_fifo_size_4",
  93666. + DEFAULT => 256,
  93667. + ENUM => [],
  93668. + LOW => 4,
  93669. + HIGH => 768
  93670. + },
  93671. + {
  93672. + NAME => "dev_perio_tx_fifo_size_5",
  93673. + DEFAULT => 256,
  93674. + ENUM => [],
  93675. + LOW => 4,
  93676. + HIGH => 768
  93677. + },
  93678. + {
  93679. + NAME => "dev_perio_tx_fifo_size_6",
  93680. + DEFAULT => 256,
  93681. + ENUM => [],
  93682. + LOW => 4,
  93683. + HIGH => 768
  93684. + },
  93685. + {
  93686. + NAME => "dev_perio_tx_fifo_size_7",
  93687. + DEFAULT => 256,
  93688. + ENUM => [],
  93689. + LOW => 4,
  93690. + HIGH => 768
  93691. + },
  93692. + {
  93693. + NAME => "dev_perio_tx_fifo_size_8",
  93694. + DEFAULT => 256,
  93695. + ENUM => [],
  93696. + LOW => 4,
  93697. + HIGH => 768
  93698. + },
  93699. + {
  93700. + NAME => "dev_perio_tx_fifo_size_9",
  93701. + DEFAULT => 256,
  93702. + ENUM => [],
  93703. + LOW => 4,
  93704. + HIGH => 768
  93705. + },
  93706. + {
  93707. + NAME => "dev_perio_tx_fifo_size_10",
  93708. + DEFAULT => 256,
  93709. + ENUM => [],
  93710. + LOW => 4,
  93711. + HIGH => 768
  93712. + },
  93713. + {
  93714. + NAME => "dev_perio_tx_fifo_size_11",
  93715. + DEFAULT => 256,
  93716. + ENUM => [],
  93717. + LOW => 4,
  93718. + HIGH => 768
  93719. + },
  93720. + {
  93721. + NAME => "dev_perio_tx_fifo_size_12",
  93722. + DEFAULT => 256,
  93723. + ENUM => [],
  93724. + LOW => 4,
  93725. + HIGH => 768
  93726. + },
  93727. + {
  93728. + NAME => "dev_perio_tx_fifo_size_13",
  93729. + DEFAULT => 256,
  93730. + ENUM => [],
  93731. + LOW => 4,
  93732. + HIGH => 768
  93733. + },
  93734. + {
  93735. + NAME => "dev_perio_tx_fifo_size_14",
  93736. + DEFAULT => 256,
  93737. + ENUM => [],
  93738. + LOW => 4,
  93739. + HIGH => 768
  93740. + },
  93741. + {
  93742. + NAME => "dev_perio_tx_fifo_size_15",
  93743. + DEFAULT => 256,
  93744. + ENUM => [],
  93745. + LOW => 4,
  93746. + HIGH => 768
  93747. + },
  93748. + {
  93749. + NAME => "host_rx_fifo_size",
  93750. + DEFAULT => 1024,
  93751. + ENUM => [],
  93752. + LOW => 16,
  93753. + HIGH => 32768
  93754. + },
  93755. + {
  93756. + NAME => "host_nperio_tx_fifo_size",
  93757. + DEFAULT => 1024,
  93758. + ENUM => [],
  93759. + LOW => 16,
  93760. + HIGH => 32768
  93761. + },
  93762. + {
  93763. + NAME => "host_perio_tx_fifo_size",
  93764. + DEFAULT => 1024,
  93765. + ENUM => [],
  93766. + LOW => 16,
  93767. + HIGH => 32768
  93768. + },
  93769. + {
  93770. + NAME => "max_transfer_size",
  93771. + DEFAULT => 65535,
  93772. + ENUM => [],
  93773. + LOW => 2047,
  93774. + HIGH => 65535
  93775. + },
  93776. + {
  93777. + NAME => "max_packet_count",
  93778. + DEFAULT => 511,
  93779. + ENUM => [],
  93780. + LOW => 15,
  93781. + HIGH => 511
  93782. + },
  93783. + {
  93784. + NAME => "host_channels",
  93785. + DEFAULT => 12,
  93786. + ENUM => [],
  93787. + LOW => 1,
  93788. + HIGH => 16
  93789. + },
  93790. + {
  93791. + NAME => "dev_endpoints",
  93792. + DEFAULT => 6,
  93793. + ENUM => [],
  93794. + LOW => 1,
  93795. + HIGH => 15
  93796. + },
  93797. + {
  93798. + NAME => "phy_type",
  93799. + DEFAULT => 1,
  93800. + ENUM => [],
  93801. + LOW => 0,
  93802. + HIGH => 2
  93803. + },
  93804. + {
  93805. + NAME => "phy_utmi_width",
  93806. + DEFAULT => 16,
  93807. + ENUM => [8, 16],
  93808. + LOW => 8,
  93809. + HIGH => 16
  93810. + },
  93811. + {
  93812. + NAME => "phy_ulpi_ddr",
  93813. + DEFAULT => 0,
  93814. + ENUM => [],
  93815. + LOW => 0,
  93816. + HIGH => 1
  93817. + },
  93818. + ];
  93819. +
  93820. +
  93821. +#
  93822. +#
  93823. +sub check_arch {
  93824. + $_ = `uname -m`;
  93825. + chomp;
  93826. + unless (m/armv4tl/) {
  93827. + warn "# \n# Can't execute on $_. Run on integrator platform.\n# \n";
  93828. + return 0;
  93829. + }
  93830. + return 1;
  93831. +}
  93832. +
  93833. +#
  93834. +#
  93835. +sub load_module {
  93836. + my $params = shift;
  93837. + print "\nRemoving Module\n";
  93838. + system "rmmod dwc_otg";
  93839. + print "Loading Module\n";
  93840. + if ($params ne "") {
  93841. + print "Module Parameters: $params\n";
  93842. + }
  93843. + if (system("modprobe dwc_otg $params")) {
  93844. + warn "Unable to load module\n";
  93845. + return 0;
  93846. + }
  93847. + return 1;
  93848. +}
  93849. +
  93850. +#
  93851. +#
  93852. +sub test_status {
  93853. + my $arg = shift;
  93854. +
  93855. + print "\n";
  93856. +
  93857. + if (defined $arg) {
  93858. + warn "WARNING: $arg\n";
  93859. + }
  93860. +
  93861. + if ($errors > 0) {
  93862. + warn "TEST FAILED with $errors errors\n";
  93863. + return 0;
  93864. + } else {
  93865. + print "TEST PASSED\n";
  93866. + return 0 if (defined $arg);
  93867. + }
  93868. + return 1;
  93869. +}
  93870. +
  93871. +#
  93872. +#
  93873. +@EXPORT = qw(
  93874. +$sysfsdir
  93875. +$paramdir
  93876. +$params
  93877. +$errors
  93878. +check_arch
  93879. +load_module
  93880. +test_status
  93881. +);
  93882. +
  93883. +1;
  93884. diff -Nur linux-3.13.11/drivers/usb/host/dwc_otg/test/Makefile linux-rpi/drivers/usb/host/dwc_otg/test/Makefile
  93885. --- linux-3.13.11/drivers/usb/host/dwc_otg/test/Makefile 1970-01-01 01:00:00.000000000 +0100
  93886. +++ linux-rpi/drivers/usb/host/dwc_otg/test/Makefile 2014-04-24 15:35:04.177565820 +0200
  93887. @@ -0,0 +1,16 @@
  93888. +
  93889. +PERL=/usr/bin/perl
  93890. +PL_TESTS=test_sysfs.pl test_mod_param.pl
  93891. +
  93892. +.PHONY : test
  93893. +test : perl_tests
  93894. +
  93895. +perl_tests :
  93896. + @echo
  93897. + @echo Running perl tests
  93898. + @for test in $(PL_TESTS); do \
  93899. + if $(PERL) ./$$test ; then \
  93900. + echo "=======> $$test, PASSED" ; \
  93901. + else echo "=======> $$test, FAILED" ; \
  93902. + fi \
  93903. + done
  93904. diff -Nur linux-3.13.11/drivers/usb/host/dwc_otg/test/test_mod_param.pl linux-rpi/drivers/usb/host/dwc_otg/test/test_mod_param.pl
  93905. --- linux-3.13.11/drivers/usb/host/dwc_otg/test/test_mod_param.pl 1970-01-01 01:00:00.000000000 +0100
  93906. +++ linux-rpi/drivers/usb/host/dwc_otg/test/test_mod_param.pl 2014-04-24 15:37:13.318990576 +0200
  93907. @@ -0,0 +1,133 @@
  93908. +#!/usr/bin/perl -w
  93909. +#
  93910. +# Run this program on the integrator.
  93911. +#
  93912. +# - Tests module parameter default values.
  93913. +# - Tests setting of valid module parameter values via modprobe.
  93914. +# - Tests invalid module parameter values.
  93915. +# -----------------------------------------------------------------------------
  93916. +use strict;
  93917. +use dwc_otg_test;
  93918. +
  93919. +check_arch() or die;
  93920. +
  93921. +#
  93922. +#
  93923. +sub test {
  93924. + my ($param,$expected) = @_;
  93925. + my $value = get($param);
  93926. +
  93927. + if ($value == $expected) {
  93928. + print "$param = $value, okay\n";
  93929. + }
  93930. +
  93931. + else {
  93932. + warn "ERROR: value of $param != $expected, $value\n";
  93933. + $errors ++;
  93934. + }
  93935. +}
  93936. +
  93937. +#
  93938. +#
  93939. +sub get {
  93940. + my $param = shift;
  93941. + my $tmp = `cat $paramdir/$param`;
  93942. + chomp $tmp;
  93943. + return $tmp;
  93944. +}
  93945. +
  93946. +#
  93947. +#
  93948. +sub test_main {
  93949. +
  93950. + print "\nTesting Module Parameters\n";
  93951. +
  93952. + load_module("") or die;
  93953. +
  93954. + # Test initial values
  93955. + print "\nTesting Default Values\n";
  93956. + foreach (@{$params}) {
  93957. + test ($_->{NAME}, $_->{DEFAULT});
  93958. + }
  93959. +
  93960. + # Test low value
  93961. + print "\nTesting Low Value\n";
  93962. + my $cmd_params = "";
  93963. + foreach (@{$params}) {
  93964. + $cmd_params = $cmd_params . "$_->{NAME}=$_->{LOW} ";
  93965. + }
  93966. + load_module($cmd_params) or die;
  93967. +
  93968. + foreach (@{$params}) {
  93969. + test ($_->{NAME}, $_->{LOW});
  93970. + }
  93971. +
  93972. + # Test high value
  93973. + print "\nTesting High Value\n";
  93974. + $cmd_params = "";
  93975. + foreach (@{$params}) {
  93976. + $cmd_params = $cmd_params . "$_->{NAME}=$_->{HIGH} ";
  93977. + }
  93978. + load_module($cmd_params) or die;
  93979. +
  93980. + foreach (@{$params}) {
  93981. + test ($_->{NAME}, $_->{HIGH});
  93982. + }
  93983. +
  93984. + # Test Enum
  93985. + print "\nTesting Enumerated\n";
  93986. + foreach (@{$params}) {
  93987. + if (defined $_->{ENUM}) {
  93988. + my $value;
  93989. + foreach $value (@{$_->{ENUM}}) {
  93990. + $cmd_params = "$_->{NAME}=$value";
  93991. + load_module($cmd_params) or die;
  93992. + test ($_->{NAME}, $value);
  93993. + }
  93994. + }
  93995. + }
  93996. +
  93997. + # Test Invalid Values
  93998. + print "\nTesting Invalid Values\n";
  93999. + $cmd_params = "";
  94000. + foreach (@{$params}) {
  94001. + $cmd_params = $cmd_params . sprintf "$_->{NAME}=%d ", $_->{LOW}-1;
  94002. + }
  94003. + load_module($cmd_params) or die;
  94004. +
  94005. + foreach (@{$params}) {
  94006. + test ($_->{NAME}, $_->{DEFAULT});
  94007. + }
  94008. +
  94009. + $cmd_params = "";
  94010. + foreach (@{$params}) {
  94011. + $cmd_params = $cmd_params . sprintf "$_->{NAME}=%d ", $_->{HIGH}+1;
  94012. + }
  94013. + load_module($cmd_params) or die;
  94014. +
  94015. + foreach (@{$params}) {
  94016. + test ($_->{NAME}, $_->{DEFAULT});
  94017. + }
  94018. +
  94019. + print "\nTesting Enumerated\n";
  94020. + foreach (@{$params}) {
  94021. + if (defined $_->{ENUM}) {
  94022. + my $value;
  94023. + foreach $value (@{$_->{ENUM}}) {
  94024. + $value = $value + 1;
  94025. + $cmd_params = "$_->{NAME}=$value";
  94026. + load_module($cmd_params) or die;
  94027. + test ($_->{NAME}, $_->{DEFAULT});
  94028. + $value = $value - 2;
  94029. + $cmd_params = "$_->{NAME}=$value";
  94030. + load_module($cmd_params) or die;
  94031. + test ($_->{NAME}, $_->{DEFAULT});
  94032. + }
  94033. + }
  94034. + }
  94035. +
  94036. + test_status() or die;
  94037. +}
  94038. +
  94039. +test_main();
  94040. +0;
  94041. diff -Nur linux-3.13.11/drivers/usb/host/dwc_otg/test/test_sysfs.pl linux-rpi/drivers/usb/host/dwc_otg/test/test_sysfs.pl
  94042. --- linux-3.13.11/drivers/usb/host/dwc_otg/test/test_sysfs.pl 1970-01-01 01:00:00.000000000 +0100
  94043. +++ linux-rpi/drivers/usb/host/dwc_otg/test/test_sysfs.pl 2014-04-24 15:37:13.318990576 +0200
  94044. @@ -0,0 +1,193 @@
  94045. +#!/usr/bin/perl -w
  94046. +#
  94047. +# Run this program on the integrator
  94048. +# - Tests select sysfs attributes.
  94049. +# - Todo ... test more attributes, hnp/srp, buspower/bussuspend, etc.
  94050. +# -----------------------------------------------------------------------------
  94051. +use strict;
  94052. +use dwc_otg_test;
  94053. +
  94054. +check_arch() or die;
  94055. +
  94056. +#
  94057. +#
  94058. +sub test {
  94059. + my ($attr,$expected) = @_;
  94060. + my $string = get($attr);
  94061. +
  94062. + if ($string eq $expected) {
  94063. + printf("$attr = $string, okay\n");
  94064. + }
  94065. + else {
  94066. + warn "ERROR: value of $attr != $expected, $string\n";
  94067. + $errors ++;
  94068. + }
  94069. +}
  94070. +
  94071. +#
  94072. +#
  94073. +sub set {
  94074. + my ($reg, $value) = @_;
  94075. + system "echo $value > $sysfsdir/$reg";
  94076. +}
  94077. +
  94078. +#
  94079. +#
  94080. +sub get {
  94081. + my $attr = shift;
  94082. + my $string = `cat $sysfsdir/$attr`;
  94083. + chomp $string;
  94084. + if ($string =~ m/\s\=\s/) {
  94085. + my $tmp;
  94086. + ($tmp, $string) = split /\s=\s/, $string;
  94087. + }
  94088. + return $string;
  94089. +}
  94090. +
  94091. +#
  94092. +#
  94093. +sub test_main {
  94094. + print("\nTesting Sysfs Attributes\n");
  94095. +
  94096. + load_module("") or die;
  94097. +
  94098. + # Test initial values of regoffset/regvalue/guid/gsnpsid
  94099. + print("\nTesting Default Values\n");
  94100. +
  94101. + test("regoffset", "0xffffffff");
  94102. + test("regvalue", "invalid offset");
  94103. + test("guid", "0x12345678"); # this will fail if it has been changed
  94104. + test("gsnpsid", "0x4f54200a");
  94105. +
  94106. + # Test operation of regoffset/regvalue
  94107. + print("\nTesting regoffset\n");
  94108. + set('regoffset', '5a5a5a5a');
  94109. + test("regoffset", "0xffffffff");
  94110. +
  94111. + set('regoffset', '0');
  94112. + test("regoffset", "0x00000000");
  94113. +
  94114. + set('regoffset', '40000');
  94115. + test("regoffset", "0x00000000");
  94116. +
  94117. + set('regoffset', '3ffff');
  94118. + test("regoffset", "0x0003ffff");
  94119. +
  94120. + set('regoffset', '1');
  94121. + test("regoffset", "0x00000001");
  94122. +
  94123. + print("\nTesting regvalue\n");
  94124. + set('regoffset', '3c');
  94125. + test("regvalue", "0x12345678");
  94126. + set('regvalue', '5a5a5a5a');
  94127. + test("regvalue", "0x5a5a5a5a");
  94128. + set('regvalue','a5a5a5a5');
  94129. + test("regvalue", "0xa5a5a5a5");
  94130. + set('guid','12345678');
  94131. +
  94132. + # Test HNP Capable
  94133. + print("\nTesting HNP Capable bit\n");
  94134. + set('hnpcapable', '1');
  94135. + test("hnpcapable", "0x1");
  94136. + set('hnpcapable','0');
  94137. + test("hnpcapable", "0x0");
  94138. +
  94139. + set('regoffset','0c');
  94140. +
  94141. + my $old = get('gusbcfg');
  94142. + print("setting hnpcapable\n");
  94143. + set('hnpcapable', '1');
  94144. + test("hnpcapable", "0x1");
  94145. + test('gusbcfg', sprintf "0x%08x", (oct ($old) | (1<<9)));
  94146. + test('regvalue', sprintf "0x%08x", (oct ($old) | (1<<9)));
  94147. +
  94148. + $old = get('gusbcfg');
  94149. + print("clearing hnpcapable\n");
  94150. + set('hnpcapable', '0');
  94151. + test("hnpcapable", "0x0");
  94152. + test ('gusbcfg', sprintf "0x%08x", oct ($old) & (~(1<<9)));
  94153. + test ('regvalue', sprintf "0x%08x", oct ($old) & (~(1<<9)));
  94154. +
  94155. + # Test SRP Capable
  94156. + print("\nTesting SRP Capable bit\n");
  94157. + set('srpcapable', '1');
  94158. + test("srpcapable", "0x1");
  94159. + set('srpcapable','0');
  94160. + test("srpcapable", "0x0");
  94161. +
  94162. + set('regoffset','0c');
  94163. +
  94164. + $old = get('gusbcfg');
  94165. + print("setting srpcapable\n");
  94166. + set('srpcapable', '1');
  94167. + test("srpcapable", "0x1");
  94168. + test('gusbcfg', sprintf "0x%08x", (oct ($old) | (1<<8)));
  94169. + test('regvalue', sprintf "0x%08x", (oct ($old) | (1<<8)));
  94170. +
  94171. + $old = get('gusbcfg');
  94172. + print("clearing srpcapable\n");
  94173. + set('srpcapable', '0');
  94174. + test("srpcapable", "0x0");
  94175. + test('gusbcfg', sprintf "0x%08x", oct ($old) & (~(1<<8)));
  94176. + test('regvalue', sprintf "0x%08x", oct ($old) & (~(1<<8)));
  94177. +
  94178. + # Test GGPIO
  94179. + print("\nTesting GGPIO\n");
  94180. + set('ggpio','5a5a5a5a');
  94181. + test('ggpio','0x5a5a0000');
  94182. + set('ggpio','a5a5a5a5');
  94183. + test('ggpio','0xa5a50000');
  94184. + set('ggpio','11110000');
  94185. + test('ggpio','0x11110000');
  94186. + set('ggpio','00001111');
  94187. + test('ggpio','0x00000000');
  94188. +
  94189. + # Test DEVSPEED
  94190. + print("\nTesting DEVSPEED\n");
  94191. + set('regoffset','800');
  94192. + $old = get('regvalue');
  94193. + set('devspeed','0');
  94194. + test('devspeed','0x0');
  94195. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3)));
  94196. + set('devspeed','1');
  94197. + test('devspeed','0x1');
  94198. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3) | 1));
  94199. + set('devspeed','2');
  94200. + test('devspeed','0x2');
  94201. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3) | 2));
  94202. + set('devspeed','3');
  94203. + test('devspeed','0x3');
  94204. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3) | 3));
  94205. + set('devspeed','4');
  94206. + test('devspeed','0x0');
  94207. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3)));
  94208. + set('devspeed','5');
  94209. + test('devspeed','0x1');
  94210. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3) | 1));
  94211. +
  94212. +
  94213. + # mode Returns the current mode:0 for device mode1 for host mode Read
  94214. + # hnp Initiate the Host Negotiation Protocol. Read returns the status. Read/Write
  94215. + # srp Initiate the Session Request Protocol. Read returns the status. Read/Write
  94216. + # buspower Get or Set the Power State of the bus (0 - Off or 1 - On) Read/Write
  94217. + # bussuspend Suspend the USB bus. Read/Write
  94218. + # busconnected Get the connection status of the bus Read
  94219. +
  94220. + # gotgctl Get or set the Core Control Status Register. Read/Write
  94221. + ## gusbcfg Get or set the Core USB Configuration Register Read/Write
  94222. + # grxfsiz Get or set the Receive FIFO Size Register Read/Write
  94223. + # gnptxfsiz Get or set the non-periodic Transmit Size Register Read/Write
  94224. + # gpvndctl Get or set the PHY Vendor Control Register Read/Write
  94225. + ## ggpio Get the value in the lower 16-bits of the General Purpose IO Register or Set the upper 16 bits. Read/Write
  94226. + ## guid Get or set the value of the User ID Register Read/Write
  94227. + ## gsnpsid Get the value of the Synopsys ID Regester Read
  94228. + ## devspeed Get or set the device speed setting in the DCFG register Read/Write
  94229. + # enumspeed Gets the device enumeration Speed. Read
  94230. + # hptxfsiz Get the value of the Host Periodic Transmit FIFO Read
  94231. + # hprt0 Get or Set the value in the Host Port Control and Status Register Read/Write
  94232. +
  94233. + test_status("TEST NYI") or die;
  94234. +}
  94235. +
  94236. +test_main();
  94237. +0;
  94238. diff -Nur linux-3.13.11/drivers/usb/host/Kconfig linux-rpi/drivers/usb/host/Kconfig
  94239. --- linux-3.13.11/drivers/usb/host/Kconfig 2014-04-23 01:49:33.000000000 +0200
  94240. +++ linux-rpi/drivers/usb/host/Kconfig 2014-04-24 15:37:13.306990445 +0200
  94241. @@ -689,6 +689,19 @@
  94242. To compile this driver a module, choose M here: the module
  94243. will be called "hwa-hc".
  94244. +config USB_DWCOTG
  94245. + tristate "Synopsis DWC host support"
  94246. + depends on USB
  94247. + help
  94248. + The Synopsis DWC controller is a dual-role
  94249. + host/peripheral/OTG ("On The Go") USB controllers.
  94250. +
  94251. + Enable this option to support this IP in host controller mode.
  94252. + If unsure, say N.
  94253. +
  94254. + To compile this driver as a module, choose M here: the
  94255. + modules built will be called dwc_otg and dwc_common_port.
  94256. +
  94257. config USB_IMX21_HCD
  94258. tristate "i.MX21 HCD support"
  94259. depends on ARM && ARCH_MXC
  94260. diff -Nur linux-3.13.11/drivers/usb/host/Makefile linux-rpi/drivers/usb/host/Makefile
  94261. --- linux-3.13.11/drivers/usb/host/Makefile 2014-04-23 01:49:33.000000000 +0200
  94262. +++ linux-rpi/drivers/usb/host/Makefile 2014-04-24 15:37:13.306990445 +0200
  94263. @@ -65,6 +65,8 @@
  94264. obj-$(CONFIG_USB_R8A66597_HCD) += r8a66597-hcd.o
  94265. obj-$(CONFIG_USB_ISP1760_HCD) += isp1760.o
  94266. obj-$(CONFIG_USB_HWA_HCD) += hwa-hc.o
  94267. +
  94268. +obj-$(CONFIG_USB_DWCOTG) += dwc_otg/ dwc_common_port/
  94269. obj-$(CONFIG_USB_IMX21_HCD) += imx21-hcd.o
  94270. obj-$(CONFIG_USB_FSL_MPH_DR_OF) += fsl-mph-dr-of.o
  94271. obj-$(CONFIG_USB_OCTEON2_COMMON) += octeon2-common.o
  94272. diff -Nur linux-3.13.11/drivers/usb/Makefile linux-rpi/drivers/usb/Makefile
  94273. --- linux-3.13.11/drivers/usb/Makefile 2014-04-23 01:49:33.000000000 +0200
  94274. +++ linux-rpi/drivers/usb/Makefile 2014-04-24 15:37:12.762984501 +0200
  94275. @@ -23,6 +23,7 @@
  94276. obj-$(CONFIG_USB_R8A66597_HCD) += host/
  94277. obj-$(CONFIG_USB_HWA_HCD) += host/
  94278. obj-$(CONFIG_USB_ISP1760_HCD) += host/
  94279. +obj-$(CONFIG_USB_DWCOTG) += host/
  94280. obj-$(CONFIG_USB_IMX21_HCD) += host/
  94281. obj-$(CONFIG_USB_FSL_MPH_DR_OF) += host/
  94282. obj-$(CONFIG_USB_FUSBH200_HCD) += host/
  94283. diff -Nur linux-3.13.11/drivers/video/bcm2708_fb.c linux-rpi/drivers/video/bcm2708_fb.c
  94284. --- linux-3.13.11/drivers/video/bcm2708_fb.c 1970-01-01 01:00:00.000000000 +0100
  94285. +++ linux-rpi/drivers/video/bcm2708_fb.c 2014-04-24 15:37:13.926997220 +0200
  94286. @@ -0,0 +1,762 @@
  94287. +/*
  94288. + * linux/drivers/video/bcm2708_fb.c
  94289. + *
  94290. + * Copyright (C) 2010 Broadcom
  94291. + *
  94292. + * This file is subject to the terms and conditions of the GNU General Public
  94293. + * License. See the file COPYING in the main directory of this archive
  94294. + * for more details.
  94295. + *
  94296. + * Broadcom simple framebuffer driver
  94297. + *
  94298. + * This file is derived from cirrusfb.c
  94299. + * Copyright 1999-2001 Jeff Garzik <jgarzik@pobox.com>
  94300. + *
  94301. + */
  94302. +#include <linux/module.h>
  94303. +#include <linux/kernel.h>
  94304. +#include <linux/errno.h>
  94305. +#include <linux/string.h>
  94306. +#include <linux/slab.h>
  94307. +#include <linux/mm.h>
  94308. +#include <linux/fb.h>
  94309. +#include <linux/init.h>
  94310. +#include <linux/interrupt.h>
  94311. +#include <linux/ioport.h>
  94312. +#include <linux/list.h>
  94313. +#include <linux/platform_device.h>
  94314. +#include <linux/clk.h>
  94315. +#include <linux/printk.h>
  94316. +#include <linux/console.h>
  94317. +#include <linux/debugfs.h>
  94318. +
  94319. +#include <mach/dma.h>
  94320. +#include <mach/platform.h>
  94321. +#include <mach/vcio.h>
  94322. +
  94323. +#include <asm/sizes.h>
  94324. +#include <linux/io.h>
  94325. +#include <linux/dma-mapping.h>
  94326. +
  94327. +#ifdef BCM2708_FB_DEBUG
  94328. +#define print_debug(fmt,...) pr_debug("%s:%s:%d: "fmt, MODULE_NAME, __func__, __LINE__, ##__VA_ARGS__)
  94329. +#else
  94330. +#define print_debug(fmt,...)
  94331. +#endif
  94332. +
  94333. +/* This is limited to 16 characters when displayed by X startup */
  94334. +static const char *bcm2708_name = "BCM2708 FB";
  94335. +
  94336. +#define DRIVER_NAME "bcm2708_fb"
  94337. +
  94338. +static int fbwidth = 800; /* module parameter */
  94339. +static int fbheight = 480; /* module parameter */
  94340. +static int fbdepth = 16; /* module parameter */
  94341. +static int fbswap = 0; /* module parameter */
  94342. +
  94343. +static u32 dma_busy_wait_threshold = 1<<15;
  94344. +module_param(dma_busy_wait_threshold, int, 0644);
  94345. +MODULE_PARM_DESC(dma_busy_wait_threshold, "Busy-wait for DMA completion below this area");
  94346. +
  94347. +/* this data structure describes each frame buffer device we find */
  94348. +
  94349. +struct fbinfo_s {
  94350. + u32 xres, yres, xres_virtual, yres_virtual;
  94351. + u32 pitch, bpp;
  94352. + u32 xoffset, yoffset;
  94353. + u32 base;
  94354. + u32 screen_size;
  94355. + u16 cmap[256];
  94356. +};
  94357. +
  94358. +struct bcm2708_fb_stats {
  94359. + struct debugfs_regset32 regset;
  94360. + u32 dma_copies;
  94361. + u32 dma_irqs;
  94362. +};
  94363. +
  94364. +struct bcm2708_fb {
  94365. + struct fb_info fb;
  94366. + struct platform_device *dev;
  94367. + struct fbinfo_s *info;
  94368. + dma_addr_t dma;
  94369. + u32 cmap[16];
  94370. + int dma_chan;
  94371. + int dma_irq;
  94372. + void __iomem *dma_chan_base;
  94373. + void *cb_base; /* DMA control blocks */
  94374. + dma_addr_t cb_handle;
  94375. + struct dentry *debugfs_dir;
  94376. + wait_queue_head_t dma_waitq;
  94377. + struct bcm2708_fb_stats stats;
  94378. +};
  94379. +
  94380. +#define to_bcm2708(info) container_of(info, struct bcm2708_fb, fb)
  94381. +
  94382. +static void bcm2708_fb_debugfs_deinit(struct bcm2708_fb *fb)
  94383. +{
  94384. + debugfs_remove_recursive(fb->debugfs_dir);
  94385. + fb->debugfs_dir = NULL;
  94386. +}
  94387. +
  94388. +static int bcm2708_fb_debugfs_init(struct bcm2708_fb *fb)
  94389. +{
  94390. + static struct debugfs_reg32 stats_registers[] = {
  94391. + {
  94392. + "dma_copies",
  94393. + offsetof(struct bcm2708_fb_stats, dma_copies)
  94394. + },
  94395. + {
  94396. + "dma_irqs",
  94397. + offsetof(struct bcm2708_fb_stats, dma_irqs)
  94398. + },
  94399. + };
  94400. +
  94401. + fb->debugfs_dir = debugfs_create_dir(DRIVER_NAME, NULL);
  94402. + if (!fb->debugfs_dir) {
  94403. + pr_warn("%s: could not create debugfs entry\n",
  94404. + __func__);
  94405. + return -EFAULT;
  94406. + }
  94407. +
  94408. + fb->stats.regset.regs = stats_registers;
  94409. + fb->stats.regset.nregs = ARRAY_SIZE(stats_registers);
  94410. + fb->stats.regset.base = &fb->stats;
  94411. +
  94412. + if (!debugfs_create_regset32(
  94413. + "stats", 0444, fb->debugfs_dir, &fb->stats.regset)) {
  94414. + pr_warn("%s: could not create statistics registers\n",
  94415. + __func__);
  94416. + goto fail;
  94417. + }
  94418. + return 0;
  94419. +
  94420. +fail:
  94421. + bcm2708_fb_debugfs_deinit(fb);
  94422. + return -EFAULT;
  94423. +}
  94424. +
  94425. +static int bcm2708_fb_set_bitfields(struct fb_var_screeninfo *var)
  94426. +{
  94427. + int ret = 0;
  94428. +
  94429. + memset(&var->transp, 0, sizeof(var->transp));
  94430. +
  94431. + var->red.msb_right = 0;
  94432. + var->green.msb_right = 0;
  94433. + var->blue.msb_right = 0;
  94434. +
  94435. + switch (var->bits_per_pixel) {
  94436. + case 1:
  94437. + case 2:
  94438. + case 4:
  94439. + case 8:
  94440. + var->red.length = var->bits_per_pixel;
  94441. + var->red.offset = 0;
  94442. + var->green.length = var->bits_per_pixel;
  94443. + var->green.offset = 0;
  94444. + var->blue.length = var->bits_per_pixel;
  94445. + var->blue.offset = 0;
  94446. + break;
  94447. + case 16:
  94448. + var->red.length = 5;
  94449. + var->blue.length = 5;
  94450. + /*
  94451. + * Green length can be 5 or 6 depending whether
  94452. + * we're operating in RGB555 or RGB565 mode.
  94453. + */
  94454. + if (var->green.length != 5 && var->green.length != 6)
  94455. + var->green.length = 6;
  94456. + break;
  94457. + case 24:
  94458. + var->red.length = 8;
  94459. + var->blue.length = 8;
  94460. + var->green.length = 8;
  94461. + break;
  94462. + case 32:
  94463. + var->red.length = 8;
  94464. + var->green.length = 8;
  94465. + var->blue.length = 8;
  94466. + var->transp.length = 8;
  94467. + break;
  94468. + default:
  94469. + ret = -EINVAL;
  94470. + break;
  94471. + }
  94472. +
  94473. + /*
  94474. + * >= 16bpp displays have separate colour component bitfields
  94475. + * encoded in the pixel data. Calculate their position from
  94476. + * the bitfield length defined above.
  94477. + */
  94478. + if (ret == 0 && var->bits_per_pixel >= 24 && fbswap) {
  94479. + var->blue.offset = 0;
  94480. + var->green.offset = var->blue.offset + var->blue.length;
  94481. + var->red.offset = var->green.offset + var->green.length;
  94482. + var->transp.offset = var->red.offset + var->red.length;
  94483. + } else if (ret == 0 && var->bits_per_pixel >= 24) {
  94484. + var->red.offset = 0;
  94485. + var->green.offset = var->red.offset + var->red.length;
  94486. + var->blue.offset = var->green.offset + var->green.length;
  94487. + var->transp.offset = var->blue.offset + var->blue.length;
  94488. + } else if (ret == 0 && var->bits_per_pixel >= 16) {
  94489. + var->blue.offset = 0;
  94490. + var->green.offset = var->blue.offset + var->blue.length;
  94491. + var->red.offset = var->green.offset + var->green.length;
  94492. + var->transp.offset = var->red.offset + var->red.length;
  94493. + }
  94494. +
  94495. + return ret;
  94496. +}
  94497. +
  94498. +static int bcm2708_fb_check_var(struct fb_var_screeninfo *var,
  94499. + struct fb_info *info)
  94500. +{
  94501. + /* info input, var output */
  94502. + int yres;
  94503. +
  94504. + /* info input, var output */
  94505. + print_debug("bcm2708_fb_check_var info(%p) %dx%d (%dx%d), %d, %d\n", info,
  94506. + info->var.xres, info->var.yres, info->var.xres_virtual,
  94507. + info->var.yres_virtual, (int)info->screen_size,
  94508. + info->var.bits_per_pixel);
  94509. + print_debug("bcm2708_fb_check_var var(%p) %dx%d (%dx%d), %d\n", var,
  94510. + var->xres, var->yres, var->xres_virtual, var->yres_virtual,
  94511. + var->bits_per_pixel);
  94512. +
  94513. + if (!var->bits_per_pixel)
  94514. + var->bits_per_pixel = 16;
  94515. +
  94516. + if (bcm2708_fb_set_bitfields(var) != 0) {
  94517. + pr_err("bcm2708_fb_check_var: invalid bits_per_pixel %d\n",
  94518. + var->bits_per_pixel);
  94519. + return -EINVAL;
  94520. + }
  94521. +
  94522. +
  94523. + if (var->xres_virtual < var->xres)
  94524. + var->xres_virtual = var->xres;
  94525. + /* use highest possible virtual resolution */
  94526. + if (var->yres_virtual == -1) {
  94527. + var->yres_virtual = 480;
  94528. +
  94529. + pr_err
  94530. + ("bcm2708_fb_check_var: virtual resolution set to maximum of %dx%d\n",
  94531. + var->xres_virtual, var->yres_virtual);
  94532. + }
  94533. + if (var->yres_virtual < var->yres)
  94534. + var->yres_virtual = var->yres;
  94535. +
  94536. + if (var->xoffset < 0)
  94537. + var->xoffset = 0;
  94538. + if (var->yoffset < 0)
  94539. + var->yoffset = 0;
  94540. +
  94541. + /* truncate xoffset and yoffset to maximum if too high */
  94542. + if (var->xoffset > var->xres_virtual - var->xres)
  94543. + var->xoffset = var->xres_virtual - var->xres - 1;
  94544. + if (var->yoffset > var->yres_virtual - var->yres)
  94545. + var->yoffset = var->yres_virtual - var->yres - 1;
  94546. +
  94547. + yres = var->yres;
  94548. + if (var->vmode & FB_VMODE_DOUBLE)
  94549. + yres *= 2;
  94550. + else if (var->vmode & FB_VMODE_INTERLACED)
  94551. + yres = (yres + 1) / 2;
  94552. +
  94553. + if (var->xres * yres > 1920 * 1200) {
  94554. + pr_err("bcm2708_fb_check_var: ERROR: Pixel size >= 1920x1200; "
  94555. + "special treatment required! (TODO)\n");
  94556. + return -EINVAL;
  94557. + }
  94558. +
  94559. + return 0;
  94560. +}
  94561. +
  94562. +static int bcm2708_fb_set_par(struct fb_info *info)
  94563. +{
  94564. + uint32_t val = 0;
  94565. + struct bcm2708_fb *fb = to_bcm2708(info);
  94566. + volatile struct fbinfo_s *fbinfo = fb->info;
  94567. + fbinfo->xres = info->var.xres;
  94568. + fbinfo->yres = info->var.yres;
  94569. + fbinfo->xres_virtual = info->var.xres_virtual;
  94570. + fbinfo->yres_virtual = info->var.yres_virtual;
  94571. + fbinfo->bpp = info->var.bits_per_pixel;
  94572. + fbinfo->xoffset = info->var.xoffset;
  94573. + fbinfo->yoffset = info->var.yoffset;
  94574. + fbinfo->base = 0; /* filled in by VC */
  94575. + fbinfo->pitch = 0; /* filled in by VC */
  94576. +
  94577. + print_debug("bcm2708_fb_set_par info(%p) %dx%d (%dx%d), %d, %d\n", info,
  94578. + info->var.xres, info->var.yres, info->var.xres_virtual,
  94579. + info->var.yres_virtual, (int)info->screen_size,
  94580. + info->var.bits_per_pixel);
  94581. +
  94582. + /* ensure last write to fbinfo is visible to GPU */
  94583. + wmb();
  94584. +
  94585. + /* inform vc about new framebuffer */
  94586. + bcm_mailbox_write(MBOX_CHAN_FB, fb->dma);
  94587. +
  94588. + /* TODO: replace fb driver with vchiq version */
  94589. + /* wait for response */
  94590. + bcm_mailbox_read(MBOX_CHAN_FB, &val);
  94591. +
  94592. + /* ensure GPU writes are visible to us */
  94593. + rmb();
  94594. +
  94595. + if (val == 0) {
  94596. + fb->fb.fix.line_length = fbinfo->pitch;
  94597. +
  94598. + if (info->var.bits_per_pixel <= 8)
  94599. + fb->fb.fix.visual = FB_VISUAL_PSEUDOCOLOR;
  94600. + else
  94601. + fb->fb.fix.visual = FB_VISUAL_TRUECOLOR;
  94602. +
  94603. + fb->fb.fix.smem_start = fbinfo->base;
  94604. + fb->fb.fix.smem_len = fbinfo->pitch * fbinfo->yres_virtual;
  94605. + fb->fb.screen_size = fbinfo->screen_size;
  94606. + if (fb->fb.screen_base)
  94607. + iounmap(fb->fb.screen_base);
  94608. + fb->fb.screen_base =
  94609. + (void *)ioremap_wc(fb->fb.fix.smem_start, fb->fb.screen_size);
  94610. + if (!fb->fb.screen_base) {
  94611. + /* the console may currently be locked */
  94612. + console_trylock();
  94613. + console_unlock();
  94614. +
  94615. + BUG(); /* what can we do here */
  94616. + }
  94617. + }
  94618. + print_debug
  94619. + ("BCM2708FB: start = %p,%p width=%d, height=%d, bpp=%d, pitch=%d size=%d success=%d\n",
  94620. + (void *)fb->fb.screen_base, (void *)fb->fb.fix.smem_start,
  94621. + fbinfo->xres, fbinfo->yres, fbinfo->bpp,
  94622. + fbinfo->pitch, (int)fb->fb.screen_size, val);
  94623. +
  94624. + return val;
  94625. +}
  94626. +
  94627. +static inline u32 convert_bitfield(int val, struct fb_bitfield *bf)
  94628. +{
  94629. + unsigned int mask = (1 << bf->length) - 1;
  94630. +
  94631. + return (val >> (16 - bf->length) & mask) << bf->offset;
  94632. +}
  94633. +
  94634. +
  94635. +static int bcm2708_fb_setcolreg(unsigned int regno, unsigned int red,
  94636. + unsigned int green, unsigned int blue,
  94637. + unsigned int transp, struct fb_info *info)
  94638. +{
  94639. + struct bcm2708_fb *fb = to_bcm2708(info);
  94640. +
  94641. + /*print_debug("BCM2708FB: setcolreg %d:(%02x,%02x,%02x,%02x) %x\n", regno, red, green, blue, transp, fb->fb.fix.visual);*/
  94642. + if (fb->fb.var.bits_per_pixel <= 8) {
  94643. + if (regno < 256) {
  94644. + /* blue [0:4], green [5:10], red [11:15] */
  94645. + fb->info->cmap[regno] = ((red >> (16-5)) & 0x1f) << 11 |
  94646. + ((green >> (16-6)) & 0x3f) << 5 |
  94647. + ((blue >> (16-5)) & 0x1f) << 0;
  94648. + }
  94649. + /* 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 */
  94650. + /* So just call it for what looks like the last colour in a list for now. */
  94651. + if (regno == 15 || regno == 255)
  94652. + bcm2708_fb_set_par(info);
  94653. + } else if (regno < 16) {
  94654. + fb->cmap[regno] = convert_bitfield(transp, &fb->fb.var.transp) |
  94655. + convert_bitfield(blue, &fb->fb.var.blue) |
  94656. + convert_bitfield(green, &fb->fb.var.green) |
  94657. + convert_bitfield(red, &fb->fb.var.red);
  94658. + }
  94659. + return regno > 255;
  94660. +}
  94661. +
  94662. +static int bcm2708_fb_blank(int blank_mode, struct fb_info *info)
  94663. +{
  94664. + /*print_debug("bcm2708_fb_blank\n"); */
  94665. + return -1;
  94666. +}
  94667. +
  94668. +static void bcm2708_fb_fillrect(struct fb_info *info,
  94669. + const struct fb_fillrect *rect)
  94670. +{
  94671. + /* (is called) print_debug("bcm2708_fb_fillrect\n"); */
  94672. + cfb_fillrect(info, rect);
  94673. +}
  94674. +
  94675. +/* A helper function for configuring dma control block */
  94676. +static void set_dma_cb(struct bcm2708_dma_cb *cb,
  94677. + int burst_size,
  94678. + dma_addr_t dst,
  94679. + int dst_stride,
  94680. + dma_addr_t src,
  94681. + int src_stride,
  94682. + int w,
  94683. + int h)
  94684. +{
  94685. + cb->info = BCM2708_DMA_BURST(burst_size) | BCM2708_DMA_S_WIDTH |
  94686. + BCM2708_DMA_S_INC | BCM2708_DMA_D_WIDTH |
  94687. + BCM2708_DMA_D_INC | BCM2708_DMA_TDMODE;
  94688. + cb->dst = dst;
  94689. + cb->src = src;
  94690. + /*
  94691. + * This is not really obvious from the DMA documentation,
  94692. + * but the top 16 bits must be programmmed to "height -1"
  94693. + * and not "height" in 2D mode.
  94694. + */
  94695. + cb->length = ((h - 1) << 16) | w;
  94696. + cb->stride = ((dst_stride - w) << 16) | (u16)(src_stride - w);
  94697. + cb->pad[0] = 0;
  94698. + cb->pad[1] = 0;
  94699. +}
  94700. +
  94701. +static void bcm2708_fb_copyarea(struct fb_info *info,
  94702. + const struct fb_copyarea *region)
  94703. +{
  94704. + struct bcm2708_fb *fb = to_bcm2708(info);
  94705. + struct bcm2708_dma_cb *cb = fb->cb_base;
  94706. + int bytes_per_pixel = (info->var.bits_per_pixel + 7) >> 3;
  94707. + /* Channel 0 supports larger bursts and is a bit faster */
  94708. + int burst_size = (fb->dma_chan == 0) ? 8 : 2;
  94709. + int pixels = region->width * region->height;
  94710. +
  94711. + /* Fallback to cfb_copyarea() if we don't like something */
  94712. + if (bytes_per_pixel > 4 ||
  94713. + info->var.xres * info->var.yres > 1920 * 1200 ||
  94714. + region->width <= 0 || region->width > info->var.xres ||
  94715. + region->height <= 0 || region->height > info->var.yres ||
  94716. + region->sx < 0 || region->sx >= info->var.xres ||
  94717. + region->sy < 0 || region->sy >= info->var.yres ||
  94718. + region->dx < 0 || region->dx >= info->var.xres ||
  94719. + region->dy < 0 || region->dy >= info->var.yres ||
  94720. + region->sx + region->width > info->var.xres ||
  94721. + region->dx + region->width > info->var.xres ||
  94722. + region->sy + region->height > info->var.yres ||
  94723. + region->dy + region->height > info->var.yres) {
  94724. + cfb_copyarea(info, region);
  94725. + return;
  94726. + }
  94727. +
  94728. + if (region->dy == region->sy && region->dx > region->sx) {
  94729. + /*
  94730. + * A difficult case of overlapped copy. Because DMA can't
  94731. + * copy individual scanlines in backwards direction, we need
  94732. + * two-pass processing. We do it by programming a chain of dma
  94733. + * control blocks in the first 16K part of the buffer and use
  94734. + * the remaining 48K as the intermediate temporary scratch
  94735. + * buffer. The buffer size is sufficient to handle up to
  94736. + * 1920x1200 resolution at 32bpp pixel depth.
  94737. + */
  94738. + int y;
  94739. + dma_addr_t control_block_pa = fb->cb_handle;
  94740. + dma_addr_t scratchbuf = fb->cb_handle + 16 * 1024;
  94741. + int scanline_size = bytes_per_pixel * region->width;
  94742. + int scanlines_per_cb = (64 * 1024 - 16 * 1024) / scanline_size;
  94743. +
  94744. + for (y = 0; y < region->height; y += scanlines_per_cb) {
  94745. + dma_addr_t src =
  94746. + fb->fb.fix.smem_start +
  94747. + bytes_per_pixel * region->sx +
  94748. + (region->sy + y) * fb->fb.fix.line_length;
  94749. + dma_addr_t dst =
  94750. + fb->fb.fix.smem_start +
  94751. + bytes_per_pixel * region->dx +
  94752. + (region->dy + y) * fb->fb.fix.line_length;
  94753. +
  94754. + if (region->height - y < scanlines_per_cb)
  94755. + scanlines_per_cb = region->height - y;
  94756. +
  94757. + set_dma_cb(cb, burst_size, scratchbuf, scanline_size,
  94758. + src, fb->fb.fix.line_length,
  94759. + scanline_size, scanlines_per_cb);
  94760. + control_block_pa += sizeof(struct bcm2708_dma_cb);
  94761. + cb->next = control_block_pa;
  94762. + cb++;
  94763. +
  94764. + set_dma_cb(cb, burst_size, dst, fb->fb.fix.line_length,
  94765. + scratchbuf, scanline_size,
  94766. + scanline_size, scanlines_per_cb);
  94767. + control_block_pa += sizeof(struct bcm2708_dma_cb);
  94768. + cb->next = control_block_pa;
  94769. + cb++;
  94770. + }
  94771. + /* move the pointer back to the last dma control block */
  94772. + cb--;
  94773. + } else {
  94774. + /* A single dma control block is enough. */
  94775. + int sy, dy, stride;
  94776. + if (region->dy <= region->sy) {
  94777. + /* processing from top to bottom */
  94778. + dy = region->dy;
  94779. + sy = region->sy;
  94780. + stride = fb->fb.fix.line_length;
  94781. + } else {
  94782. + /* processing from bottom to top */
  94783. + dy = region->dy + region->height - 1;
  94784. + sy = region->sy + region->height - 1;
  94785. + stride = -fb->fb.fix.line_length;
  94786. + }
  94787. + set_dma_cb(cb, burst_size,
  94788. + fb->fb.fix.smem_start + dy * fb->fb.fix.line_length +
  94789. + bytes_per_pixel * region->dx,
  94790. + stride,
  94791. + fb->fb.fix.smem_start + sy * fb->fb.fix.line_length +
  94792. + bytes_per_pixel * region->sx,
  94793. + stride,
  94794. + region->width * bytes_per_pixel,
  94795. + region->height);
  94796. + }
  94797. +
  94798. + /* end of dma control blocks chain */
  94799. + cb->next = 0;
  94800. +
  94801. +
  94802. + if (pixels < dma_busy_wait_threshold) {
  94803. + bcm_dma_start(fb->dma_chan_base, fb->cb_handle);
  94804. + bcm_dma_wait_idle(fb->dma_chan_base);
  94805. + } else {
  94806. + void __iomem *dma_chan = fb->dma_chan_base;
  94807. + cb->info |= BCM2708_DMA_INT_EN;
  94808. + bcm_dma_start(fb->dma_chan_base, fb->cb_handle);
  94809. + while (bcm_dma_is_busy(dma_chan)) {
  94810. + wait_event_interruptible(
  94811. + fb->dma_waitq,
  94812. + !bcm_dma_is_busy(dma_chan));
  94813. + }
  94814. + fb->stats.dma_irqs++;
  94815. + }
  94816. + fb->stats.dma_copies++;
  94817. +}
  94818. +
  94819. +static void bcm2708_fb_imageblit(struct fb_info *info,
  94820. + const struct fb_image *image)
  94821. +{
  94822. + /* (is called) print_debug("bcm2708_fb_imageblit\n"); */
  94823. + cfb_imageblit(info, image);
  94824. +}
  94825. +
  94826. +static irqreturn_t bcm2708_fb_dma_irq(int irq, void *cxt)
  94827. +{
  94828. + struct bcm2708_fb *fb = cxt;
  94829. +
  94830. + /* FIXME: should read status register to check if this is
  94831. + * actually interrupting us or not, in case this interrupt
  94832. + * ever becomes shared amongst several DMA channels
  94833. + *
  94834. + * readl(dma_chan_base + BCM2708_DMA_CS) & BCM2708_DMA_IRQ;
  94835. + */
  94836. +
  94837. + /* acknowledge the interrupt */
  94838. + writel(BCM2708_DMA_INT, fb->dma_chan_base + BCM2708_DMA_CS);
  94839. +
  94840. + wake_up(&fb->dma_waitq);
  94841. + return IRQ_HANDLED;
  94842. +}
  94843. +
  94844. +static struct fb_ops bcm2708_fb_ops = {
  94845. + .owner = THIS_MODULE,
  94846. + .fb_check_var = bcm2708_fb_check_var,
  94847. + .fb_set_par = bcm2708_fb_set_par,
  94848. + .fb_setcolreg = bcm2708_fb_setcolreg,
  94849. + .fb_blank = bcm2708_fb_blank,
  94850. + .fb_fillrect = bcm2708_fb_fillrect,
  94851. + .fb_copyarea = bcm2708_fb_copyarea,
  94852. + .fb_imageblit = bcm2708_fb_imageblit,
  94853. +};
  94854. +
  94855. +static int bcm2708_fb_register(struct bcm2708_fb *fb)
  94856. +{
  94857. + int ret;
  94858. + dma_addr_t dma;
  94859. + void *mem;
  94860. +
  94861. + mem =
  94862. + dma_alloc_coherent(NULL, PAGE_ALIGN(sizeof(*fb->info)), &dma,
  94863. + GFP_KERNEL);
  94864. +
  94865. + if (NULL == mem) {
  94866. + pr_err(": unable to allocate fbinfo buffer\n");
  94867. + ret = -ENOMEM;
  94868. + } else {
  94869. + fb->info = (struct fbinfo_s *)mem;
  94870. + fb->dma = dma;
  94871. + }
  94872. + fb->fb.fbops = &bcm2708_fb_ops;
  94873. + fb->fb.flags = FBINFO_FLAG_DEFAULT | FBINFO_HWACCEL_COPYAREA;
  94874. + fb->fb.pseudo_palette = fb->cmap;
  94875. +
  94876. + strncpy(fb->fb.fix.id, bcm2708_name, sizeof(fb->fb.fix.id));
  94877. + fb->fb.fix.type = FB_TYPE_PACKED_PIXELS;
  94878. + fb->fb.fix.type_aux = 0;
  94879. + fb->fb.fix.xpanstep = 0;
  94880. + fb->fb.fix.ypanstep = 0;
  94881. + fb->fb.fix.ywrapstep = 0;
  94882. + fb->fb.fix.accel = FB_ACCEL_NONE;
  94883. +
  94884. + fb->fb.var.xres = fbwidth;
  94885. + fb->fb.var.yres = fbheight;
  94886. + fb->fb.var.xres_virtual = fbwidth;
  94887. + fb->fb.var.yres_virtual = fbheight;
  94888. + fb->fb.var.bits_per_pixel = fbdepth;
  94889. + fb->fb.var.vmode = FB_VMODE_NONINTERLACED;
  94890. + fb->fb.var.activate = FB_ACTIVATE_NOW;
  94891. + fb->fb.var.nonstd = 0;
  94892. + fb->fb.var.height = -1; /* height of picture in mm */
  94893. + fb->fb.var.width = -1; /* width of picture in mm */
  94894. + fb->fb.var.accel_flags = 0;
  94895. +
  94896. + fb->fb.monspecs.hfmin = 0;
  94897. + fb->fb.monspecs.hfmax = 100000;
  94898. + fb->fb.monspecs.vfmin = 0;
  94899. + fb->fb.monspecs.vfmax = 400;
  94900. + fb->fb.monspecs.dclkmin = 1000000;
  94901. + fb->fb.monspecs.dclkmax = 100000000;
  94902. +
  94903. + bcm2708_fb_set_bitfields(&fb->fb.var);
  94904. + init_waitqueue_head(&fb->dma_waitq);
  94905. +
  94906. + /*
  94907. + * Allocate colourmap.
  94908. + */
  94909. +
  94910. + fb_set_var(&fb->fb, &fb->fb.var);
  94911. +
  94912. + print_debug("BCM2708FB: registering framebuffer (%dx%d@%d) (%d)\n", fbwidth
  94913. + fbheight, fbdepth, fbswap);
  94914. +
  94915. + ret = register_framebuffer(&fb->fb);
  94916. + print_debug("BCM2708FB: register framebuffer (%d)\n", ret);
  94917. + if (ret == 0)
  94918. + goto out;
  94919. +
  94920. + print_debug("BCM2708FB: cannot register framebuffer (%d)\n", ret);
  94921. +out:
  94922. + return ret;
  94923. +}
  94924. +
  94925. +static int bcm2708_fb_probe(struct platform_device *dev)
  94926. +{
  94927. + struct bcm2708_fb *fb;
  94928. + int ret;
  94929. +
  94930. + fb = kzalloc(sizeof(struct bcm2708_fb), GFP_KERNEL);
  94931. + if (!fb) {
  94932. + dev_err(&dev->dev,
  94933. + "could not allocate new bcm2708_fb struct\n");
  94934. + ret = -ENOMEM;
  94935. + goto free_region;
  94936. + }
  94937. +
  94938. + bcm2708_fb_debugfs_init(fb);
  94939. +
  94940. + fb->cb_base = dma_alloc_writecombine(&dev->dev, SZ_64K,
  94941. + &fb->cb_handle, GFP_KERNEL);
  94942. + if (!fb->cb_base) {
  94943. + dev_err(&dev->dev, "cannot allocate DMA CBs\n");
  94944. + ret = -ENOMEM;
  94945. + goto free_fb;
  94946. + }
  94947. +
  94948. + pr_info("BCM2708FB: allocated DMA memory %08x\n",
  94949. + fb->cb_handle);
  94950. +
  94951. + ret = bcm_dma_chan_alloc(BCM_DMA_FEATURE_BULK,
  94952. + &fb->dma_chan_base, &fb->dma_irq);
  94953. + if (ret < 0) {
  94954. + dev_err(&dev->dev, "couldn't allocate a DMA channel\n");
  94955. + goto free_cb;
  94956. + }
  94957. + fb->dma_chan = ret;
  94958. +
  94959. + ret = request_irq(fb->dma_irq, bcm2708_fb_dma_irq,
  94960. + 0, "bcm2708_fb dma", fb);
  94961. + if (ret) {
  94962. + pr_err("%s: failed to request DMA irq\n", __func__);
  94963. + goto free_dma_chan;
  94964. + }
  94965. +
  94966. +
  94967. + pr_info("BCM2708FB: allocated DMA channel %d @ %p\n",
  94968. + fb->dma_chan, fb->dma_chan_base);
  94969. +
  94970. + fb->dev = dev;
  94971. +
  94972. + ret = bcm2708_fb_register(fb);
  94973. + if (ret == 0) {
  94974. + platform_set_drvdata(dev, fb);
  94975. + goto out;
  94976. + }
  94977. +
  94978. +free_dma_chan:
  94979. + bcm_dma_chan_free(fb->dma_chan);
  94980. +free_cb:
  94981. + dma_free_writecombine(&dev->dev, SZ_64K, fb->cb_base, fb->cb_handle);
  94982. +free_fb:
  94983. + kfree(fb);
  94984. +free_region:
  94985. + dev_err(&dev->dev, "probe failed, err %d\n", ret);
  94986. +out:
  94987. + return ret;
  94988. +}
  94989. +
  94990. +static int bcm2708_fb_remove(struct platform_device *dev)
  94991. +{
  94992. + struct bcm2708_fb *fb = platform_get_drvdata(dev);
  94993. +
  94994. + platform_set_drvdata(dev, NULL);
  94995. +
  94996. + if (fb->fb.screen_base)
  94997. + iounmap(fb->fb.screen_base);
  94998. + unregister_framebuffer(&fb->fb);
  94999. +
  95000. + dma_free_writecombine(&dev->dev, SZ_64K, fb->cb_base, fb->cb_handle);
  95001. + bcm_dma_chan_free(fb->dma_chan);
  95002. +
  95003. + dma_free_coherent(NULL, PAGE_ALIGN(sizeof(*fb->info)), (void *)fb->info,
  95004. + fb->dma);
  95005. + bcm2708_fb_debugfs_deinit(fb);
  95006. +
  95007. + free_irq(fb->dma_irq, fb);
  95008. +
  95009. + kfree(fb);
  95010. +
  95011. + return 0;
  95012. +}
  95013. +
  95014. +static struct platform_driver bcm2708_fb_driver = {
  95015. + .probe = bcm2708_fb_probe,
  95016. + .remove = bcm2708_fb_remove,
  95017. + .driver = {
  95018. + .name = DRIVER_NAME,
  95019. + .owner = THIS_MODULE,
  95020. + },
  95021. +};
  95022. +
  95023. +static int __init bcm2708_fb_init(void)
  95024. +{
  95025. + return platform_driver_register(&bcm2708_fb_driver);
  95026. +}
  95027. +
  95028. +module_init(bcm2708_fb_init);
  95029. +
  95030. +static void __exit bcm2708_fb_exit(void)
  95031. +{
  95032. + platform_driver_unregister(&bcm2708_fb_driver);
  95033. +}
  95034. +
  95035. +module_exit(bcm2708_fb_exit);
  95036. +
  95037. +module_param(fbwidth, int, 0644);
  95038. +module_param(fbheight, int, 0644);
  95039. +module_param(fbdepth, int, 0644);
  95040. +module_param(fbswap, int, 0644);
  95041. +
  95042. +MODULE_DESCRIPTION("BCM2708 framebuffer driver");
  95043. +MODULE_LICENSE("GPL");
  95044. +
  95045. +MODULE_PARM_DESC(fbwidth, "Width of ARM Framebuffer");
  95046. +MODULE_PARM_DESC(fbheight, "Height of ARM Framebuffer");
  95047. +MODULE_PARM_DESC(fbdepth, "Bit depth of ARM Framebuffer");
  95048. +MODULE_PARM_DESC(fbswap, "Swap order of red and blue in 24 and 32 bit modes");
  95049. diff -Nur linux-3.13.11/drivers/video/cfbimgblt.c linux-rpi/drivers/video/cfbimgblt.c
  95050. --- linux-3.13.11/drivers/video/cfbimgblt.c 2014-04-23 01:49:33.000000000 +0200
  95051. +++ linux-rpi/drivers/video/cfbimgblt.c 2014-04-24 15:37:13.938997351 +0200
  95052. @@ -28,6 +28,11 @@
  95053. *
  95054. * Also need to add code to deal with cards endians that are different than
  95055. * the native cpu endians. I also need to deal with MSB position in the word.
  95056. + * Modified by Harm Hanemaaijer (fgenfb@yahoo.com) 2013:
  95057. + * - Provide optimized versions of fast_imageblit for 16 and 32bpp that are
  95058. + * significantly faster than the previous implementation.
  95059. + * - Simplify the fast/slow_imageblit selection code, avoiding integer
  95060. + * divides.
  95061. */
  95062. #include <linux/module.h>
  95063. #include <linux/string.h>
  95064. @@ -262,6 +267,133 @@
  95065. }
  95066. }
  95067. +/*
  95068. + * Optimized fast_imageblit for bpp == 16. ppw = 2, bit_mask = 3 folded
  95069. + * into the code, main loop unrolled.
  95070. + */
  95071. +
  95072. +static inline void fast_imageblit16(const struct fb_image *image,
  95073. + struct fb_info *p, u8 __iomem * dst1,
  95074. + u32 fgcolor, u32 bgcolor)
  95075. +{
  95076. + u32 fgx = fgcolor, bgx = bgcolor;
  95077. + u32 spitch = (image->width + 7) / 8;
  95078. + u32 end_mask, eorx;
  95079. + const char *s = image->data, *src;
  95080. + u32 __iomem *dst;
  95081. + const u32 *tab = NULL;
  95082. + int i, j, k;
  95083. +
  95084. + tab = fb_be_math(p) ? cfb_tab16_be : cfb_tab16_le;
  95085. +
  95086. + fgx <<= 16;
  95087. + bgx <<= 16;
  95088. + fgx |= fgcolor;
  95089. + bgx |= bgcolor;
  95090. +
  95091. + eorx = fgx ^ bgx;
  95092. + k = image->width / 2;
  95093. +
  95094. + for (i = image->height; i--;) {
  95095. + dst = (u32 __iomem *) dst1;
  95096. + src = s;
  95097. +
  95098. + j = k;
  95099. + while (j >= 4) {
  95100. + u8 bits = *src;
  95101. + end_mask = tab[(bits >> 6) & 3];
  95102. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  95103. + end_mask = tab[(bits >> 4) & 3];
  95104. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  95105. + end_mask = tab[(bits >> 2) & 3];
  95106. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  95107. + end_mask = tab[bits & 3];
  95108. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  95109. + src++;
  95110. + j -= 4;
  95111. + }
  95112. + if (j != 0) {
  95113. + u8 bits = *src;
  95114. + end_mask = tab[(bits >> 6) & 3];
  95115. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  95116. + if (j >= 2) {
  95117. + end_mask = tab[(bits >> 4) & 3];
  95118. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  95119. + if (j == 3) {
  95120. + end_mask = tab[(bits >> 2) & 3];
  95121. + FB_WRITEL((end_mask & eorx) ^ bgx, dst);
  95122. + }
  95123. + }
  95124. + }
  95125. + dst1 += p->fix.line_length;
  95126. + s += spitch;
  95127. + }
  95128. +}
  95129. +
  95130. +/*
  95131. + * Optimized fast_imageblit for bpp == 32. ppw = 1, bit_mask = 1 folded
  95132. + * into the code, main loop unrolled.
  95133. + */
  95134. +
  95135. +static inline void fast_imageblit32(const struct fb_image *image,
  95136. + struct fb_info *p, u8 __iomem * dst1,
  95137. + u32 fgcolor, u32 bgcolor)
  95138. +{
  95139. + u32 fgx = fgcolor, bgx = bgcolor;
  95140. + u32 spitch = (image->width + 7) / 8;
  95141. + u32 end_mask, eorx;
  95142. + const char *s = image->data, *src;
  95143. + u32 __iomem *dst;
  95144. + const u32 *tab = NULL;
  95145. + int i, j, k;
  95146. +
  95147. + tab = cfb_tab32;
  95148. +
  95149. + eorx = fgx ^ bgx;
  95150. + k = image->width;
  95151. +
  95152. + for (i = image->height; i--;) {
  95153. + dst = (u32 __iomem *) dst1;
  95154. + src = s;
  95155. +
  95156. + j = k;
  95157. + while (j >= 8) {
  95158. + u8 bits = *src;
  95159. + end_mask = tab[(bits >> 7) & 1];
  95160. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  95161. + end_mask = tab[(bits >> 6) & 1];
  95162. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  95163. + end_mask = tab[(bits >> 5) & 1];
  95164. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  95165. + end_mask = tab[(bits >> 4) & 1];
  95166. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  95167. + end_mask = tab[(bits >> 3) & 1];
  95168. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  95169. + end_mask = tab[(bits >> 2) & 1];
  95170. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  95171. + end_mask = tab[(bits >> 1) & 1];
  95172. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  95173. + end_mask = tab[bits & 1];
  95174. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  95175. + src++;
  95176. + j -= 8;
  95177. + }
  95178. + if (j != 0) {
  95179. + u32 bits = (u32) * src;
  95180. + while (j > 1) {
  95181. + end_mask = tab[(bits >> 7) & 1];
  95182. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  95183. + bits <<= 1;
  95184. + j--;
  95185. + }
  95186. + end_mask = tab[(bits >> 7) & 1];
  95187. + FB_WRITEL((end_mask & eorx) ^ bgx, dst);
  95188. + }
  95189. + dst1 += p->fix.line_length;
  95190. + s += spitch;
  95191. + }
  95192. +}
  95193. +
  95194. void cfb_imageblit(struct fb_info *p, const struct fb_image *image)
  95195. {
  95196. u32 fgcolor, bgcolor, start_index, bitstart, pitch_index = 0;
  95197. @@ -294,11 +426,21 @@
  95198. bgcolor = image->bg_color;
  95199. }
  95200. - if (32 % bpp == 0 && !start_index && !pitch_index &&
  95201. - ((width & (32/bpp-1)) == 0) &&
  95202. - bpp >= 8 && bpp <= 32)
  95203. - fast_imageblit(image, p, dst1, fgcolor, bgcolor);
  95204. - else
  95205. + if (!start_index && !pitch_index) {
  95206. + if (bpp == 32)
  95207. + fast_imageblit32(image, p, dst1, fgcolor,
  95208. + bgcolor);
  95209. + else if (bpp == 16 && (width & 1) == 0)
  95210. + fast_imageblit16(image, p, dst1, fgcolor,
  95211. + bgcolor);
  95212. + else if (bpp == 8 && (width & 3) == 0)
  95213. + fast_imageblit(image, p, dst1, fgcolor,
  95214. + bgcolor);
  95215. + else
  95216. + slow_imageblit(image, p, dst1, fgcolor,
  95217. + bgcolor,
  95218. + start_index, pitch_index);
  95219. + } else
  95220. slow_imageblit(image, p, dst1, fgcolor, bgcolor,
  95221. start_index, pitch_index);
  95222. } else
  95223. diff -Nur linux-3.13.11/drivers/video/fbmem.c linux-rpi/drivers/video/fbmem.c
  95224. --- linux-3.13.11/drivers/video/fbmem.c 2014-04-23 01:49:33.000000000 +0200
  95225. +++ linux-rpi/drivers/video/fbmem.c 2014-04-24 15:37:14.010998138 +0200
  95226. @@ -1083,6 +1083,25 @@
  95227. }
  95228. EXPORT_SYMBOL(fb_blank);
  95229. +static int fb_copyarea_user(struct fb_info *info,
  95230. + struct fb_copyarea *copy)
  95231. +{
  95232. + int ret = 0;
  95233. + if (!lock_fb_info(info))
  95234. + return -ENODEV;
  95235. + if (copy->dx + copy->width > info->var.xres ||
  95236. + copy->sx + copy->width > info->var.xres ||
  95237. + copy->dy + copy->height > info->var.yres ||
  95238. + copy->sy + copy->height > info->var.yres) {
  95239. + ret = -EINVAL;
  95240. + goto out;
  95241. + }
  95242. + info->fbops->fb_copyarea(info, copy);
  95243. +out:
  95244. + unlock_fb_info(info);
  95245. + return ret;
  95246. +}
  95247. +
  95248. static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
  95249. unsigned long arg)
  95250. {
  95251. @@ -1093,6 +1112,7 @@
  95252. struct fb_cmap cmap_from;
  95253. struct fb_cmap_user cmap;
  95254. struct fb_event event;
  95255. + struct fb_copyarea copy;
  95256. void __user *argp = (void __user *)arg;
  95257. long ret = 0;
  95258. @@ -1210,6 +1230,15 @@
  95259. unlock_fb_info(info);
  95260. console_unlock();
  95261. break;
  95262. + case FBIOCOPYAREA:
  95263. + if (info->flags & FBINFO_HWACCEL_COPYAREA) {
  95264. + /* only provide this ioctl if it is accelerated */
  95265. + if (copy_from_user(&copy, argp, sizeof(copy)))
  95266. + return -EFAULT;
  95267. + ret = fb_copyarea_user(info, &copy);
  95268. + break;
  95269. + }
  95270. + /* fall through */
  95271. default:
  95272. if (!lock_fb_info(info))
  95273. return -ENODEV;
  95274. @@ -1364,6 +1393,7 @@
  95275. case FBIOPAN_DISPLAY:
  95276. case FBIOGET_CON2FBMAP:
  95277. case FBIOPUT_CON2FBMAP:
  95278. + case FBIOCOPYAREA:
  95279. arg = (unsigned long) compat_ptr(arg);
  95280. case FBIOBLANK:
  95281. ret = do_fb_ioctl(info, cmd, arg);
  95282. diff -Nur linux-3.13.11/drivers/video/Kconfig linux-rpi/drivers/video/Kconfig
  95283. --- linux-3.13.11/drivers/video/Kconfig 2014-04-23 01:49:33.000000000 +0200
  95284. +++ linux-rpi/drivers/video/Kconfig 2014-04-24 15:37:13.806995908 +0200
  95285. @@ -310,6 +310,20 @@
  95286. help
  95287. Support the Permedia2 FIFO disconnect feature.
  95288. +config FB_BCM2708
  95289. + tristate "BCM2708 framebuffer support"
  95290. + depends on FB && ARM
  95291. + select FB_CFB_FILLRECT
  95292. + select FB_CFB_COPYAREA
  95293. + select FB_CFB_IMAGEBLIT
  95294. + help
  95295. + This framebuffer device driver is for the BCM2708 framebuffer.
  95296. +
  95297. + If you want to compile this as a module (=code which can be
  95298. + inserted into and removed from the running kernel), say M
  95299. + here and read <file:Documentation/kbuild/modules.txt>. The module
  95300. + will be called bcm2708_fb.
  95301. +
  95302. config FB_ARMCLCD
  95303. tristate "ARM PrimeCell PL110 support"
  95304. depends on FB && ARM && ARM_AMBA
  95305. diff -Nur linux-3.13.11/drivers/video/logo/logo_linux_clut224.ppm linux-rpi/drivers/video/logo/logo_linux_clut224.ppm
  95306. --- linux-3.13.11/drivers/video/logo/logo_linux_clut224.ppm 2014-04-23 01:49:33.000000000 +0200
  95307. +++ linux-rpi/drivers/video/logo/logo_linux_clut224.ppm 2014-04-24 15:35:04.285567024 +0200
  95308. @@ -1,1604 +1,883 @@
  95309. P3
  95310. -# Standard 224-color Linux logo
  95311. -80 80
  95312. +63 80
  95313. 255
  95314. - 0 0 0 0 0 0 0 0 0 0 0 0
  95315. - 0 0 0 0 0 0 0 0 0 0 0 0
  95316. - 0 0 0 0 0 0 0 0 0 0 0 0
  95317. - 0 0 0 0 0 0 0 0 0 0 0 0
  95318. - 0 0 0 0 0 0 0 0 0 0 0 0
  95319. - 0 0 0 0 0 0 0 0 0 0 0 0
  95320. - 0 0 0 0 0 0 0 0 0 0 0 0
  95321. - 0 0 0 0 0 0 0 0 0 0 0 0
  95322. - 0 0 0 0 0 0 0 0 0 0 0 0
  95323. - 6 6 6 6 6 6 10 10 10 10 10 10
  95324. - 10 10 10 6 6 6 6 6 6 6 6 6
  95325. - 0 0 0 0 0 0 0 0 0 0 0 0
  95326. - 0 0 0 0 0 0 0 0 0 0 0 0
  95327. - 0 0 0 0 0 0 0 0 0 0 0 0
  95328. - 0 0 0 0 0 0 0 0 0 0 0 0
  95329. - 0 0 0 0 0 0 0 0 0 0 0 0
  95330. - 0 0 0 0 0 0 0 0 0 0 0 0
  95331. - 0 0 0 0 0 0 0 0 0 0 0 0
  95332. - 0 0 0 0 0 0 0 0 0 0 0 0
  95333. - 0 0 0 0 0 0 0 0 0 0 0 0
  95334. - 0 0 0 0 0 0 0 0 0 0 0 0
  95335. - 0 0 0 0 0 0 0 0 0 0 0 0
  95336. - 0 0 0 0 0 0 0 0 0 0 0 0
  95337. - 0 0 0 0 0 0 0 0 0 0 0 0
  95338. - 0 0 0 0 0 0 0 0 0 0 0 0
  95339. - 0 0 0 0 0 0 0 0 0 0 0 0
  95340. - 0 0 0 0 0 0 0 0 0 0 0 0
  95341. - 0 0 0 0 0 0 0 0 0 0 0 0
  95342. - 0 0 0 6 6 6 10 10 10 14 14 14
  95343. - 22 22 22 26 26 26 30 30 30 34 34 34
  95344. - 30 30 30 30 30 30 26 26 26 18 18 18
  95345. - 14 14 14 10 10 10 6 6 6 0 0 0
  95346. - 0 0 0 0 0 0 0 0 0 0 0 0
  95347. - 0 0 0 0 0 0 0 0 0 0 0 0
  95348. - 0 0 0 0 0 0 0 0 0 0 0 0
  95349. - 0 0 0 0 0 0 0 0 0 0 0 0
  95350. - 0 0 0 0 0 0 0 0 0 0 0 0
  95351. - 0 0 0 0 0 0 0 0 0 0 0 0
  95352. - 0 0 0 0 0 0 0 0 0 0 0 0
  95353. - 0 0 0 0 0 0 0 0 0 0 0 0
  95354. - 0 0 0 0 0 0 0 0 0 0 0 0
  95355. - 0 0 0 0 0 1 0 0 1 0 0 0
  95356. - 0 0 0 0 0 0 0 0 0 0 0 0
  95357. - 0 0 0 0 0 0 0 0 0 0 0 0
  95358. - 0 0 0 0 0 0 0 0 0 0 0 0
  95359. - 0 0 0 0 0 0 0 0 0 0 0 0
  95360. - 0 0 0 0 0 0 0 0 0 0 0 0
  95361. - 0 0 0 0 0 0 0 0 0 0 0 0
  95362. - 6 6 6 14 14 14 26 26 26 42 42 42
  95363. - 54 54 54 66 66 66 78 78 78 78 78 78
  95364. - 78 78 78 74 74 74 66 66 66 54 54 54
  95365. - 42 42 42 26 26 26 18 18 18 10 10 10
  95366. - 6 6 6 0 0 0 0 0 0 0 0 0
  95367. - 0 0 0 0 0 0 0 0 0 0 0 0
  95368. - 0 0 0 0 0 0 0 0 0 0 0 0
  95369. - 0 0 0 0 0 0 0 0 0 0 0 0
  95370. - 0 0 0 0 0 0 0 0 0 0 0 0
  95371. - 0 0 0 0 0 0 0 0 0 0 0 0
  95372. - 0 0 0 0 0 0 0 0 0 0 0 0
  95373. - 0 0 0 0 0 0 0 0 0 0 0 0
  95374. - 0 0 0 0 0 0 0 0 0 0 0 0
  95375. - 0 0 1 0 0 0 0 0 0 0 0 0
  95376. - 0 0 0 0 0 0 0 0 0 0 0 0
  95377. - 0 0 0 0 0 0 0 0 0 0 0 0
  95378. - 0 0 0 0 0 0 0 0 0 0 0 0
  95379. - 0 0 0 0 0 0 0 0 0 0 0 0
  95380. - 0 0 0 0 0 0 0 0 0 0 0 0
  95381. - 0 0 0 0 0 0 0 0 0 10 10 10
  95382. - 22 22 22 42 42 42 66 66 66 86 86 86
  95383. - 66 66 66 38 38 38 38 38 38 22 22 22
  95384. - 26 26 26 34 34 34 54 54 54 66 66 66
  95385. - 86 86 86 70 70 70 46 46 46 26 26 26
  95386. - 14 14 14 6 6 6 0 0 0 0 0 0
  95387. - 0 0 0 0 0 0 0 0 0 0 0 0
  95388. - 0 0 0 0 0 0 0 0 0 0 0 0
  95389. - 0 0 0 0 0 0 0 0 0 0 0 0
  95390. - 0 0 0 0 0 0 0 0 0 0 0 0
  95391. - 0 0 0 0 0 0 0 0 0 0 0 0
  95392. - 0 0 0 0 0 0 0 0 0 0 0 0
  95393. - 0 0 0 0 0 0 0 0 0 0 0 0
  95394. - 0 0 0 0 0 0 0 0 0 0 0 0
  95395. - 0 0 1 0 0 1 0 0 1 0 0 0
  95396. - 0 0 0 0 0 0 0 0 0 0 0 0
  95397. - 0 0 0 0 0 0 0 0 0 0 0 0
  95398. - 0 0 0 0 0 0 0 0 0 0 0 0
  95399. - 0 0 0 0 0 0 0 0 0 0 0 0
  95400. - 0 0 0 0 0 0 0 0 0 0 0 0
  95401. - 0 0 0 0 0 0 10 10 10 26 26 26
  95402. - 50 50 50 82 82 82 58 58 58 6 6 6
  95403. - 2 2 6 2 2 6 2 2 6 2 2 6
  95404. - 2 2 6 2 2 6 2 2 6 2 2 6
  95405. - 6 6 6 54 54 54 86 86 86 66 66 66
  95406. - 38 38 38 18 18 18 6 6 6 0 0 0
  95407. - 0 0 0 0 0 0 0 0 0 0 0 0
  95408. - 0 0 0 0 0 0 0 0 0 0 0 0
  95409. - 0 0 0 0 0 0 0 0 0 0 0 0
  95410. - 0 0 0 0 0 0 0 0 0 0 0 0
  95411. - 0 0 0 0 0 0 0 0 0 0 0 0
  95412. - 0 0 0 0 0 0 0 0 0 0 0 0
  95413. - 0 0 0 0 0 0 0 0 0 0 0 0
  95414. - 0 0 0 0 0 0 0 0 0 0 0 0
  95415. - 0 0 0 0 0 0 0 0 0 0 0 0
  95416. - 0 0 0 0 0 0 0 0 0 0 0 0
  95417. - 0 0 0 0 0 0 0 0 0 0 0 0
  95418. - 0 0 0 0 0 0 0 0 0 0 0 0
  95419. - 0 0 0 0 0 0 0 0 0 0 0 0
  95420. - 0 0 0 0 0 0 0 0 0 0 0 0
  95421. - 0 0 0 6 6 6 22 22 22 50 50 50
  95422. - 78 78 78 34 34 34 2 2 6 2 2 6
  95423. - 2 2 6 2 2 6 2 2 6 2 2 6
  95424. - 2 2 6 2 2 6 2 2 6 2 2 6
  95425. - 2 2 6 2 2 6 6 6 6 70 70 70
  95426. - 78 78 78 46 46 46 22 22 22 6 6 6
  95427. - 0 0 0 0 0 0 0 0 0 0 0 0
  95428. - 0 0 0 0 0 0 0 0 0 0 0 0
  95429. - 0 0 0 0 0 0 0 0 0 0 0 0
  95430. - 0 0 0 0 0 0 0 0 0 0 0 0
  95431. - 0 0 0 0 0 0 0 0 0 0 0 0
  95432. - 0 0 0 0 0 0 0 0 0 0 0 0
  95433. - 0 0 0 0 0 0 0 0 0 0 0 0
  95434. - 0 0 0 0 0 0 0 0 0 0 0 0
  95435. - 0 0 1 0 0 1 0 0 1 0 0 0
  95436. - 0 0 0 0 0 0 0 0 0 0 0 0
  95437. - 0 0 0 0 0 0 0 0 0 0 0 0
  95438. - 0 0 0 0 0 0 0 0 0 0 0 0
  95439. - 0 0 0 0 0 0 0 0 0 0 0 0
  95440. - 0 0 0 0 0 0 0 0 0 0 0 0
  95441. - 6 6 6 18 18 18 42 42 42 82 82 82
  95442. - 26 26 26 2 2 6 2 2 6 2 2 6
  95443. - 2 2 6 2 2 6 2 2 6 2 2 6
  95444. - 2 2 6 2 2 6 2 2 6 14 14 14
  95445. - 46 46 46 34 34 34 6 6 6 2 2 6
  95446. - 42 42 42 78 78 78 42 42 42 18 18 18
  95447. - 6 6 6 0 0 0 0 0 0 0 0 0
  95448. - 0 0 0 0 0 0 0 0 0 0 0 0
  95449. - 0 0 0 0 0 0 0 0 0 0 0 0
  95450. - 0 0 0 0 0 0 0 0 0 0 0 0
  95451. - 0 0 0 0 0 0 0 0 0 0 0 0
  95452. - 0 0 0 0 0 0 0 0 0 0 0 0
  95453. - 0 0 0 0 0 0 0 0 0 0 0 0
  95454. - 0 0 0 0 0 0 0 0 0 0 0 0
  95455. - 0 0 1 0 0 0 0 0 1 0 0 0
  95456. - 0 0 0 0 0 0 0 0 0 0 0 0
  95457. - 0 0 0 0 0 0 0 0 0 0 0 0
  95458. - 0 0 0 0 0 0 0 0 0 0 0 0
  95459. - 0 0 0 0 0 0 0 0 0 0 0 0
  95460. - 0 0 0 0 0 0 0 0 0 0 0 0
  95461. - 10 10 10 30 30 30 66 66 66 58 58 58
  95462. - 2 2 6 2 2 6 2 2 6 2 2 6
  95463. - 2 2 6 2 2 6 2 2 6 2 2 6
  95464. - 2 2 6 2 2 6 2 2 6 26 26 26
  95465. - 86 86 86 101 101 101 46 46 46 10 10 10
  95466. - 2 2 6 58 58 58 70 70 70 34 34 34
  95467. - 10 10 10 0 0 0 0 0 0 0 0 0
  95468. - 0 0 0 0 0 0 0 0 0 0 0 0
  95469. - 0 0 0 0 0 0 0 0 0 0 0 0
  95470. - 0 0 0 0 0 0 0 0 0 0 0 0
  95471. - 0 0 0 0 0 0 0 0 0 0 0 0
  95472. - 0 0 0 0 0 0 0 0 0 0 0 0
  95473. - 0 0 0 0 0 0 0 0 0 0 0 0
  95474. - 0 0 0 0 0 0 0 0 0 0 0 0
  95475. - 0 0 1 0 0 1 0 0 1 0 0 0
  95476. - 0 0 0 0 0 0 0 0 0 0 0 0
  95477. - 0 0 0 0 0 0 0 0 0 0 0 0
  95478. - 0 0 0 0 0 0 0 0 0 0 0 0
  95479. - 0 0 0 0 0 0 0 0 0 0 0 0
  95480. - 0 0 0 0 0 0 0 0 0 0 0 0
  95481. - 14 14 14 42 42 42 86 86 86 10 10 10
  95482. - 2 2 6 2 2 6 2 2 6 2 2 6
  95483. - 2 2 6 2 2 6 2 2 6 2 2 6
  95484. - 2 2 6 2 2 6 2 2 6 30 30 30
  95485. - 94 94 94 94 94 94 58 58 58 26 26 26
  95486. - 2 2 6 6 6 6 78 78 78 54 54 54
  95487. - 22 22 22 6 6 6 0 0 0 0 0 0
  95488. - 0 0 0 0 0 0 0 0 0 0 0 0
  95489. - 0 0 0 0 0 0 0 0 0 0 0 0
  95490. - 0 0 0 0 0 0 0 0 0 0 0 0
  95491. - 0 0 0 0 0 0 0 0 0 0 0 0
  95492. - 0 0 0 0 0 0 0 0 0 0 0 0
  95493. - 0 0 0 0 0 0 0 0 0 0 0 0
  95494. - 0 0 0 0 0 0 0 0 0 0 0 0
  95495. - 0 0 0 0 0 0 0 0 0 0 0 0
  95496. - 0 0 0 0 0 0 0 0 0 0 0 0
  95497. - 0 0 0 0 0 0 0 0 0 0 0 0
  95498. - 0 0 0 0 0 0 0 0 0 0 0 0
  95499. - 0 0 0 0 0 0 0 0 0 0 0 0
  95500. - 0 0 0 0 0 0 0 0 0 6 6 6
  95501. - 22 22 22 62 62 62 62 62 62 2 2 6
  95502. - 2 2 6 2 2 6 2 2 6 2 2 6
  95503. - 2 2 6 2 2 6 2 2 6 2 2 6
  95504. - 2 2 6 2 2 6 2 2 6 26 26 26
  95505. - 54 54 54 38 38 38 18 18 18 10 10 10
  95506. - 2 2 6 2 2 6 34 34 34 82 82 82
  95507. - 38 38 38 14 14 14 0 0 0 0 0 0
  95508. - 0 0 0 0 0 0 0 0 0 0 0 0
  95509. - 0 0 0 0 0 0 0 0 0 0 0 0
  95510. - 0 0 0 0 0 0 0 0 0 0 0 0
  95511. - 0 0 0 0 0 0 0 0 0 0 0 0
  95512. - 0 0 0 0 0 0 0 0 0 0 0 0
  95513. - 0 0 0 0 0 0 0 0 0 0 0 0
  95514. - 0 0 0 0 0 0 0 0 0 0 0 0
  95515. - 0 0 0 0 0 1 0 0 1 0 0 0
  95516. - 0 0 0 0 0 0 0 0 0 0 0 0
  95517. - 0 0 0 0 0 0 0 0 0 0 0 0
  95518. - 0 0 0 0 0 0 0 0 0 0 0 0
  95519. - 0 0 0 0 0 0 0 0 0 0 0 0
  95520. - 0 0 0 0 0 0 0 0 0 6 6 6
  95521. - 30 30 30 78 78 78 30 30 30 2 2 6
  95522. - 2 2 6 2 2 6 2 2 6 2 2 6
  95523. - 2 2 6 2 2 6 2 2 6 2 2 6
  95524. - 2 2 6 2 2 6 2 2 6 10 10 10
  95525. - 10 10 10 2 2 6 2 2 6 2 2 6
  95526. - 2 2 6 2 2 6 2 2 6 78 78 78
  95527. - 50 50 50 18 18 18 6 6 6 0 0 0
  95528. - 0 0 0 0 0 0 0 0 0 0 0 0
  95529. - 0 0 0 0 0 0 0 0 0 0 0 0
  95530. - 0 0 0 0 0 0 0 0 0 0 0 0
  95531. - 0 0 0 0 0 0 0 0 0 0 0 0
  95532. - 0 0 0 0 0 0 0 0 0 0 0 0
  95533. - 0 0 0 0 0 0 0 0 0 0 0 0
  95534. - 0 0 0 0 0 0 0 0 0 0 0 0
  95535. - 0 0 1 0 0 0 0 0 0 0 0 0
  95536. - 0 0 0 0 0 0 0 0 0 0 0 0
  95537. - 0 0 0 0 0 0 0 0 0 0 0 0
  95538. - 0 0 0 0 0 0 0 0 0 0 0 0
  95539. - 0 0 0 0 0 0 0 0 0 0 0 0
  95540. - 0 0 0 0 0 0 0 0 0 10 10 10
  95541. - 38 38 38 86 86 86 14 14 14 2 2 6
  95542. - 2 2 6 2 2 6 2 2 6 2 2 6
  95543. - 2 2 6 2 2 6 2 2 6 2 2 6
  95544. - 2 2 6 2 2 6 2 2 6 2 2 6
  95545. - 2 2 6 2 2 6 2 2 6 2 2 6
  95546. - 2 2 6 2 2 6 2 2 6 54 54 54
  95547. - 66 66 66 26 26 26 6 6 6 0 0 0
  95548. - 0 0 0 0 0 0 0 0 0 0 0 0
  95549. - 0 0 0 0 0 0 0 0 0 0 0 0
  95550. - 0 0 0 0 0 0 0 0 0 0 0 0
  95551. - 0 0 0 0 0 0 0 0 0 0 0 0
  95552. - 0 0 0 0 0 0 0 0 0 0 0 0
  95553. - 0 0 0 0 0 0 0 0 0 0 0 0
  95554. - 0 0 0 0 0 0 0 0 0 0 0 0
  95555. - 0 0 0 0 0 1 0 0 1 0 0 0
  95556. - 0 0 0 0 0 0 0 0 0 0 0 0
  95557. - 0 0 0 0 0 0 0 0 0 0 0 0
  95558. - 0 0 0 0 0 0 0 0 0 0 0 0
  95559. - 0 0 0 0 0 0 0 0 0 0 0 0
  95560. - 0 0 0 0 0 0 0 0 0 14 14 14
  95561. - 42 42 42 82 82 82 2 2 6 2 2 6
  95562. - 2 2 6 6 6 6 10 10 10 2 2 6
  95563. - 2 2 6 2 2 6 2 2 6 2 2 6
  95564. - 2 2 6 2 2 6 2 2 6 6 6 6
  95565. - 14 14 14 10 10 10 2 2 6 2 2 6
  95566. - 2 2 6 2 2 6 2 2 6 18 18 18
  95567. - 82 82 82 34 34 34 10 10 10 0 0 0
  95568. - 0 0 0 0 0 0 0 0 0 0 0 0
  95569. - 0 0 0 0 0 0 0 0 0 0 0 0
  95570. - 0 0 0 0 0 0 0 0 0 0 0 0
  95571. - 0 0 0 0 0 0 0 0 0 0 0 0
  95572. - 0 0 0 0 0 0 0 0 0 0 0 0
  95573. - 0 0 0 0 0 0 0 0 0 0 0 0
  95574. - 0 0 0 0 0 0 0 0 0 0 0 0
  95575. - 0 0 1 0 0 0 0 0 0 0 0 0
  95576. - 0 0 0 0 0 0 0 0 0 0 0 0
  95577. - 0 0 0 0 0 0 0 0 0 0 0 0
  95578. - 0 0 0 0 0 0 0 0 0 0 0 0
  95579. - 0 0 0 0 0 0 0 0 0 0 0 0
  95580. - 0 0 0 0 0 0 0 0 0 14 14 14
  95581. - 46 46 46 86 86 86 2 2 6 2 2 6
  95582. - 6 6 6 6 6 6 22 22 22 34 34 34
  95583. - 6 6 6 2 2 6 2 2 6 2 2 6
  95584. - 2 2 6 2 2 6 18 18 18 34 34 34
  95585. - 10 10 10 50 50 50 22 22 22 2 2 6
  95586. - 2 2 6 2 2 6 2 2 6 10 10 10
  95587. - 86 86 86 42 42 42 14 14 14 0 0 0
  95588. - 0 0 0 0 0 0 0 0 0 0 0 0
  95589. - 0 0 0 0 0 0 0 0 0 0 0 0
  95590. - 0 0 0 0 0 0 0 0 0 0 0 0
  95591. - 0 0 0 0 0 0 0 0 0 0 0 0
  95592. - 0 0 0 0 0 0 0 0 0 0 0 0
  95593. - 0 0 0 0 0 0 0 0 0 0 0 0
  95594. - 0 0 0 0 0 0 0 0 0 0 0 0
  95595. - 0 0 1 0 0 1 0 0 1 0 0 0
  95596. - 0 0 0 0 0 0 0 0 0 0 0 0
  95597. - 0 0 0 0 0 0 0 0 0 0 0 0
  95598. - 0 0 0 0 0 0 0 0 0 0 0 0
  95599. - 0 0 0 0 0 0 0 0 0 0 0 0
  95600. - 0 0 0 0 0 0 0 0 0 14 14 14
  95601. - 46 46 46 86 86 86 2 2 6 2 2 6
  95602. - 38 38 38 116 116 116 94 94 94 22 22 22
  95603. - 22 22 22 2 2 6 2 2 6 2 2 6
  95604. - 14 14 14 86 86 86 138 138 138 162 162 162
  95605. -154 154 154 38 38 38 26 26 26 6 6 6
  95606. - 2 2 6 2 2 6 2 2 6 2 2 6
  95607. - 86 86 86 46 46 46 14 14 14 0 0 0
  95608. - 0 0 0 0 0 0 0 0 0 0 0 0
  95609. - 0 0 0 0 0 0 0 0 0 0 0 0
  95610. - 0 0 0 0 0 0 0 0 0 0 0 0
  95611. - 0 0 0 0 0 0 0 0 0 0 0 0
  95612. - 0 0 0 0 0 0 0 0 0 0 0 0
  95613. - 0 0 0 0 0 0 0 0 0 0 0 0
  95614. - 0 0 0 0 0 0 0 0 0 0 0 0
  95615. - 0 0 0 0 0 0 0 0 0 0 0 0
  95616. - 0 0 0 0 0 0 0 0 0 0 0 0
  95617. - 0 0 0 0 0 0 0 0 0 0 0 0
  95618. - 0 0 0 0 0 0 0 0 0 0 0 0
  95619. - 0 0 0 0 0 0 0 0 0 0 0 0
  95620. - 0 0 0 0 0 0 0 0 0 14 14 14
  95621. - 46 46 46 86 86 86 2 2 6 14 14 14
  95622. -134 134 134 198 198 198 195 195 195 116 116 116
  95623. - 10 10 10 2 2 6 2 2 6 6 6 6
  95624. -101 98 89 187 187 187 210 210 210 218 218 218
  95625. -214 214 214 134 134 134 14 14 14 6 6 6
  95626. - 2 2 6 2 2 6 2 2 6 2 2 6
  95627. - 86 86 86 50 50 50 18 18 18 6 6 6
  95628. - 0 0 0 0 0 0 0 0 0 0 0 0
  95629. - 0 0 0 0 0 0 0 0 0 0 0 0
  95630. - 0 0 0 0 0 0 0 0 0 0 0 0
  95631. - 0 0 0 0 0 0 0 0 0 0 0 0
  95632. - 0 0 0 0 0 0 0 0 0 0 0 0
  95633. - 0 0 0 0 0 0 0 0 0 0 0 0
  95634. - 0 0 0 0 0 0 0 0 1 0 0 0
  95635. - 0 0 1 0 0 1 0 0 1 0 0 0
  95636. - 0 0 0 0 0 0 0 0 0 0 0 0
  95637. - 0 0 0 0 0 0 0 0 0 0 0 0
  95638. - 0 0 0 0 0 0 0 0 0 0 0 0
  95639. - 0 0 0 0 0 0 0 0 0 0 0 0
  95640. - 0 0 0 0 0 0 0 0 0 14 14 14
  95641. - 46 46 46 86 86 86 2 2 6 54 54 54
  95642. -218 218 218 195 195 195 226 226 226 246 246 246
  95643. - 58 58 58 2 2 6 2 2 6 30 30 30
  95644. -210 210 210 253 253 253 174 174 174 123 123 123
  95645. -221 221 221 234 234 234 74 74 74 2 2 6
  95646. - 2 2 6 2 2 6 2 2 6 2 2 6
  95647. - 70 70 70 58 58 58 22 22 22 6 6 6
  95648. - 0 0 0 0 0 0 0 0 0 0 0 0
  95649. - 0 0 0 0 0 0 0 0 0 0 0 0
  95650. - 0 0 0 0 0 0 0 0 0 0 0 0
  95651. - 0 0 0 0 0 0 0 0 0 0 0 0
  95652. - 0 0 0 0 0 0 0 0 0 0 0 0
  95653. - 0 0 0 0 0 0 0 0 0 0 0 0
  95654. - 0 0 0 0 0 0 0 0 0 0 0 0
  95655. - 0 0 0 0 0 0 0 0 0 0 0 0
  95656. - 0 0 0 0 0 0 0 0 0 0 0 0
  95657. - 0 0 0 0 0 0 0 0 0 0 0 0
  95658. - 0 0 0 0 0 0 0 0 0 0 0 0
  95659. - 0 0 0 0 0 0 0 0 0 0 0 0
  95660. - 0 0 0 0 0 0 0 0 0 14 14 14
  95661. - 46 46 46 82 82 82 2 2 6 106 106 106
  95662. -170 170 170 26 26 26 86 86 86 226 226 226
  95663. -123 123 123 10 10 10 14 14 14 46 46 46
  95664. -231 231 231 190 190 190 6 6 6 70 70 70
  95665. - 90 90 90 238 238 238 158 158 158 2 2 6
  95666. - 2 2 6 2 2 6 2 2 6 2 2 6
  95667. - 70 70 70 58 58 58 22 22 22 6 6 6
  95668. - 0 0 0 0 0 0 0 0 0 0 0 0
  95669. - 0 0 0 0 0 0 0 0 0 0 0 0
  95670. - 0 0 0 0 0 0 0 0 0 0 0 0
  95671. - 0 0 0 0 0 0 0 0 0 0 0 0
  95672. - 0 0 0 0 0 0 0 0 0 0 0 0
  95673. - 0 0 0 0 0 0 0 0 0 0 0 0
  95674. - 0 0 0 0 0 0 0 0 1 0 0 0
  95675. - 0 0 1 0 0 1 0 0 1 0 0 0
  95676. - 0 0 0 0 0 0 0 0 0 0 0 0
  95677. - 0 0 0 0 0 0 0 0 0 0 0 0
  95678. - 0 0 0 0 0 0 0 0 0 0 0 0
  95679. - 0 0 0 0 0 0 0 0 0 0 0 0
  95680. - 0 0 0 0 0 0 0 0 0 14 14 14
  95681. - 42 42 42 86 86 86 6 6 6 116 116 116
  95682. -106 106 106 6 6 6 70 70 70 149 149 149
  95683. -128 128 128 18 18 18 38 38 38 54 54 54
  95684. -221 221 221 106 106 106 2 2 6 14 14 14
  95685. - 46 46 46 190 190 190 198 198 198 2 2 6
  95686. - 2 2 6 2 2 6 2 2 6 2 2 6
  95687. - 74 74 74 62 62 62 22 22 22 6 6 6
  95688. - 0 0 0 0 0 0 0 0 0 0 0 0
  95689. - 0 0 0 0 0 0 0 0 0 0 0 0
  95690. - 0 0 0 0 0 0 0 0 0 0 0 0
  95691. - 0 0 0 0 0 0 0 0 0 0 0 0
  95692. - 0 0 0 0 0 0 0 0 0 0 0 0
  95693. - 0 0 0 0 0 0 0 0 0 0 0 0
  95694. - 0 0 0 0 0 0 0 0 1 0 0 0
  95695. - 0 0 1 0 0 0 0 0 1 0 0 0
  95696. - 0 0 0 0 0 0 0 0 0 0 0 0
  95697. - 0 0 0 0 0 0 0 0 0 0 0 0
  95698. - 0 0 0 0 0 0 0 0 0 0 0 0
  95699. - 0 0 0 0 0 0 0 0 0 0 0 0
  95700. - 0 0 0 0 0 0 0 0 0 14 14 14
  95701. - 42 42 42 94 94 94 14 14 14 101 101 101
  95702. -128 128 128 2 2 6 18 18 18 116 116 116
  95703. -118 98 46 121 92 8 121 92 8 98 78 10
  95704. -162 162 162 106 106 106 2 2 6 2 2 6
  95705. - 2 2 6 195 195 195 195 195 195 6 6 6
  95706. - 2 2 6 2 2 6 2 2 6 2 2 6
  95707. - 74 74 74 62 62 62 22 22 22 6 6 6
  95708. - 0 0 0 0 0 0 0 0 0 0 0 0
  95709. - 0 0 0 0 0 0 0 0 0 0 0 0
  95710. - 0 0 0 0 0 0 0 0 0 0 0 0
  95711. - 0 0 0 0 0 0 0 0 0 0 0 0
  95712. - 0 0 0 0 0 0 0 0 0 0 0 0
  95713. - 0 0 0 0 0 0 0 0 0 0 0 0
  95714. - 0 0 0 0 0 0 0 0 1 0 0 1
  95715. - 0 0 1 0 0 0 0 0 1 0 0 0
  95716. - 0 0 0 0 0 0 0 0 0 0 0 0
  95717. - 0 0 0 0 0 0 0 0 0 0 0 0
  95718. - 0 0 0 0 0 0 0 0 0 0 0 0
  95719. - 0 0 0 0 0 0 0 0 0 0 0 0
  95720. - 0 0 0 0 0 0 0 0 0 10 10 10
  95721. - 38 38 38 90 90 90 14 14 14 58 58 58
  95722. -210 210 210 26 26 26 54 38 6 154 114 10
  95723. -226 170 11 236 186 11 225 175 15 184 144 12
  95724. -215 174 15 175 146 61 37 26 9 2 2 6
  95725. - 70 70 70 246 246 246 138 138 138 2 2 6
  95726. - 2 2 6 2 2 6 2 2 6 2 2 6
  95727. - 70 70 70 66 66 66 26 26 26 6 6 6
  95728. - 0 0 0 0 0 0 0 0 0 0 0 0
  95729. - 0 0 0 0 0 0 0 0 0 0 0 0
  95730. - 0 0 0 0 0 0 0 0 0 0 0 0
  95731. - 0 0 0 0 0 0 0 0 0 0 0 0
  95732. - 0 0 0 0 0 0 0 0 0 0 0 0
  95733. - 0 0 0 0 0 0 0 0 0 0 0 0
  95734. - 0 0 0 0 0 0 0 0 0 0 0 0
  95735. - 0 0 0 0 0 0 0 0 0 0 0 0
  95736. - 0 0 0 0 0 0 0 0 0 0 0 0
  95737. - 0 0 0 0 0 0 0 0 0 0 0 0
  95738. - 0 0 0 0 0 0 0 0 0 0 0 0
  95739. - 0 0 0 0 0 0 0 0 0 0 0 0
  95740. - 0 0 0 0 0 0 0 0 0 10 10 10
  95741. - 38 38 38 86 86 86 14 14 14 10 10 10
  95742. -195 195 195 188 164 115 192 133 9 225 175 15
  95743. -239 182 13 234 190 10 232 195 16 232 200 30
  95744. -245 207 45 241 208 19 232 195 16 184 144 12
  95745. -218 194 134 211 206 186 42 42 42 2 2 6
  95746. - 2 2 6 2 2 6 2 2 6 2 2 6
  95747. - 50 50 50 74 74 74 30 30 30 6 6 6
  95748. - 0 0 0 0 0 0 0 0 0 0 0 0
  95749. - 0 0 0 0 0 0 0 0 0 0 0 0
  95750. - 0 0 0 0 0 0 0 0 0 0 0 0
  95751. - 0 0 0 0 0 0 0 0 0 0 0 0
  95752. - 0 0 0 0 0 0 0 0 0 0 0 0
  95753. - 0 0 0 0 0 0 0 0 0 0 0 0
  95754. - 0 0 0 0 0 0 0 0 0 0 0 0
  95755. - 0 0 0 0 0 0 0 0 0 0 0 0
  95756. - 0 0 0 0 0 0 0 0 0 0 0 0
  95757. - 0 0 0 0 0 0 0 0 0 0 0 0
  95758. - 0 0 0 0 0 0 0 0 0 0 0 0
  95759. - 0 0 0 0 0 0 0 0 0 0 0 0
  95760. - 0 0 0 0 0 0 0 0 0 10 10 10
  95761. - 34 34 34 86 86 86 14 14 14 2 2 6
  95762. -121 87 25 192 133 9 219 162 10 239 182 13
  95763. -236 186 11 232 195 16 241 208 19 244 214 54
  95764. -246 218 60 246 218 38 246 215 20 241 208 19
  95765. -241 208 19 226 184 13 121 87 25 2 2 6
  95766. - 2 2 6 2 2 6 2 2 6 2 2 6
  95767. - 50 50 50 82 82 82 34 34 34 10 10 10
  95768. - 0 0 0 0 0 0 0 0 0 0 0 0
  95769. - 0 0 0 0 0 0 0 0 0 0 0 0
  95770. - 0 0 0 0 0 0 0 0 0 0 0 0
  95771. - 0 0 0 0 0 0 0 0 0 0 0 0
  95772. - 0 0 0 0 0 0 0 0 0 0 0 0
  95773. - 0 0 0 0 0 0 0 0 0 0 0 0
  95774. - 0 0 0 0 0 0 0 0 0 0 0 0
  95775. - 0 0 0 0 0 0 0 0 0 0 0 0
  95776. - 0 0 0 0 0 0 0 0 0 0 0 0
  95777. - 0 0 0 0 0 0 0 0 0 0 0 0
  95778. - 0 0 0 0 0 0 0 0 0 0 0 0
  95779. - 0 0 0 0 0 0 0 0 0 0 0 0
  95780. - 0 0 0 0 0 0 0 0 0 10 10 10
  95781. - 34 34 34 82 82 82 30 30 30 61 42 6
  95782. -180 123 7 206 145 10 230 174 11 239 182 13
  95783. -234 190 10 238 202 15 241 208 19 246 218 74
  95784. -246 218 38 246 215 20 246 215 20 246 215 20
  95785. -226 184 13 215 174 15 184 144 12 6 6 6
  95786. - 2 2 6 2 2 6 2 2 6 2 2 6
  95787. - 26 26 26 94 94 94 42 42 42 14 14 14
  95788. - 0 0 0 0 0 0 0 0 0 0 0 0
  95789. - 0 0 0 0 0 0 0 0 0 0 0 0
  95790. - 0 0 0 0 0 0 0 0 0 0 0 0
  95791. - 0 0 0 0 0 0 0 0 0 0 0 0
  95792. - 0 0 0 0 0 0 0 0 0 0 0 0
  95793. - 0 0 0 0 0 0 0 0 0 0 0 0
  95794. - 0 0 0 0 0 0 0 0 0 0 0 0
  95795. - 0 0 0 0 0 0 0 0 0 0 0 0
  95796. - 0 0 0 0 0 0 0 0 0 0 0 0
  95797. - 0 0 0 0 0 0 0 0 0 0 0 0
  95798. - 0 0 0 0 0 0 0 0 0 0 0 0
  95799. - 0 0 0 0 0 0 0 0 0 0 0 0
  95800. - 0 0 0 0 0 0 0 0 0 10 10 10
  95801. - 30 30 30 78 78 78 50 50 50 104 69 6
  95802. -192 133 9 216 158 10 236 178 12 236 186 11
  95803. -232 195 16 241 208 19 244 214 54 245 215 43
  95804. -246 215 20 246 215 20 241 208 19 198 155 10
  95805. -200 144 11 216 158 10 156 118 10 2 2 6
  95806. - 2 2 6 2 2 6 2 2 6 2 2 6
  95807. - 6 6 6 90 90 90 54 54 54 18 18 18
  95808. - 6 6 6 0 0 0 0 0 0 0 0 0
  95809. - 0 0 0 0 0 0 0 0 0 0 0 0
  95810. - 0 0 0 0 0 0 0 0 0 0 0 0
  95811. - 0 0 0 0 0 0 0 0 0 0 0 0
  95812. - 0 0 0 0 0 0 0 0 0 0 0 0
  95813. - 0 0 0 0 0 0 0 0 0 0 0 0
  95814. - 0 0 0 0 0 0 0 0 0 0 0 0
  95815. - 0 0 0 0 0 0 0 0 0 0 0 0
  95816. - 0 0 0 0 0 0 0 0 0 0 0 0
  95817. - 0 0 0 0 0 0 0 0 0 0 0 0
  95818. - 0 0 0 0 0 0 0 0 0 0 0 0
  95819. - 0 0 0 0 0 0 0 0 0 0 0 0
  95820. - 0 0 0 0 0 0 0 0 0 10 10 10
  95821. - 30 30 30 78 78 78 46 46 46 22 22 22
  95822. -137 92 6 210 162 10 239 182 13 238 190 10
  95823. -238 202 15 241 208 19 246 215 20 246 215 20
  95824. -241 208 19 203 166 17 185 133 11 210 150 10
  95825. -216 158 10 210 150 10 102 78 10 2 2 6
  95826. - 6 6 6 54 54 54 14 14 14 2 2 6
  95827. - 2 2 6 62 62 62 74 74 74 30 30 30
  95828. - 10 10 10 0 0 0 0 0 0 0 0 0
  95829. - 0 0 0 0 0 0 0 0 0 0 0 0
  95830. - 0 0 0 0 0 0 0 0 0 0 0 0
  95831. - 0 0 0 0 0 0 0 0 0 0 0 0
  95832. - 0 0 0 0 0 0 0 0 0 0 0 0
  95833. - 0 0 0 0 0 0 0 0 0 0 0 0
  95834. - 0 0 0 0 0 0 0 0 0 0 0 0
  95835. - 0 0 0 0 0 0 0 0 0 0 0 0
  95836. - 0 0 0 0 0 0 0 0 0 0 0 0
  95837. - 0 0 0 0 0 0 0 0 0 0 0 0
  95838. - 0 0 0 0 0 0 0 0 0 0 0 0
  95839. - 0 0 0 0 0 0 0 0 0 0 0 0
  95840. - 0 0 0 0 0 0 0 0 0 10 10 10
  95841. - 34 34 34 78 78 78 50 50 50 6 6 6
  95842. - 94 70 30 139 102 15 190 146 13 226 184 13
  95843. -232 200 30 232 195 16 215 174 15 190 146 13
  95844. -168 122 10 192 133 9 210 150 10 213 154 11
  95845. -202 150 34 182 157 106 101 98 89 2 2 6
  95846. - 2 2 6 78 78 78 116 116 116 58 58 58
  95847. - 2 2 6 22 22 22 90 90 90 46 46 46
  95848. - 18 18 18 6 6 6 0 0 0 0 0 0
  95849. - 0 0 0 0 0 0 0 0 0 0 0 0
  95850. - 0 0 0 0 0 0 0 0 0 0 0 0
  95851. - 0 0 0 0 0 0 0 0 0 0 0 0
  95852. - 0 0 0 0 0 0 0 0 0 0 0 0
  95853. - 0 0 0 0 0 0 0 0 0 0 0 0
  95854. - 0 0 0 0 0 0 0 0 0 0 0 0
  95855. - 0 0 0 0 0 0 0 0 0 0 0 0
  95856. - 0 0 0 0 0 0 0 0 0 0 0 0
  95857. - 0 0 0 0 0 0 0 0 0 0 0 0
  95858. - 0 0 0 0 0 0 0 0 0 0 0 0
  95859. - 0 0 0 0 0 0 0 0 0 0 0 0
  95860. - 0 0 0 0 0 0 0 0 0 10 10 10
  95861. - 38 38 38 86 86 86 50 50 50 6 6 6
  95862. -128 128 128 174 154 114 156 107 11 168 122 10
  95863. -198 155 10 184 144 12 197 138 11 200 144 11
  95864. -206 145 10 206 145 10 197 138 11 188 164 115
  95865. -195 195 195 198 198 198 174 174 174 14 14 14
  95866. - 2 2 6 22 22 22 116 116 116 116 116 116
  95867. - 22 22 22 2 2 6 74 74 74 70 70 70
  95868. - 30 30 30 10 10 10 0 0 0 0 0 0
  95869. - 0 0 0 0 0 0 0 0 0 0 0 0
  95870. - 0 0 0 0 0 0 0 0 0 0 0 0
  95871. - 0 0 0 0 0 0 0 0 0 0 0 0
  95872. - 0 0 0 0 0 0 0 0 0 0 0 0
  95873. - 0 0 0 0 0 0 0 0 0 0 0 0
  95874. - 0 0 0 0 0 0 0 0 0 0 0 0
  95875. - 0 0 0 0 0 0 0 0 0 0 0 0
  95876. - 0 0 0 0 0 0 0 0 0 0 0 0
  95877. - 0 0 0 0 0 0 0 0 0 0 0 0
  95878. - 0 0 0 0 0 0 0 0 0 0 0 0
  95879. - 0 0 0 0 0 0 0 0 0 0 0 0
  95880. - 0 0 0 0 0 0 6 6 6 18 18 18
  95881. - 50 50 50 101 101 101 26 26 26 10 10 10
  95882. -138 138 138 190 190 190 174 154 114 156 107 11
  95883. -197 138 11 200 144 11 197 138 11 192 133 9
  95884. -180 123 7 190 142 34 190 178 144 187 187 187
  95885. -202 202 202 221 221 221 214 214 214 66 66 66
  95886. - 2 2 6 2 2 6 50 50 50 62 62 62
  95887. - 6 6 6 2 2 6 10 10 10 90 90 90
  95888. - 50 50 50 18 18 18 6 6 6 0 0 0
  95889. - 0 0 0 0 0 0 0 0 0 0 0 0
  95890. - 0 0 0 0 0 0 0 0 0 0 0 0
  95891. - 0 0 0 0 0 0 0 0 0 0 0 0
  95892. - 0 0 0 0 0 0 0 0 0 0 0 0
  95893. - 0 0 0 0 0 0 0 0 0 0 0 0
  95894. - 0 0 0 0 0 0 0 0 0 0 0 0
  95895. - 0 0 0 0 0 0 0 0 0 0 0 0
  95896. - 0 0 0 0 0 0 0 0 0 0 0 0
  95897. - 0 0 0 0 0 0 0 0 0 0 0 0
  95898. - 0 0 0 0 0 0 0 0 0 0 0 0
  95899. - 0 0 0 0 0 0 0 0 0 0 0 0
  95900. - 0 0 0 0 0 0 10 10 10 34 34 34
  95901. - 74 74 74 74 74 74 2 2 6 6 6 6
  95902. -144 144 144 198 198 198 190 190 190 178 166 146
  95903. -154 121 60 156 107 11 156 107 11 168 124 44
  95904. -174 154 114 187 187 187 190 190 190 210 210 210
  95905. -246 246 246 253 253 253 253 253 253 182 182 182
  95906. - 6 6 6 2 2 6 2 2 6 2 2 6
  95907. - 2 2 6 2 2 6 2 2 6 62 62 62
  95908. - 74 74 74 34 34 34 14 14 14 0 0 0
  95909. - 0 0 0 0 0 0 0 0 0 0 0 0
  95910. - 0 0 0 0 0 0 0 0 0 0 0 0
  95911. - 0 0 0 0 0 0 0 0 0 0 0 0
  95912. - 0 0 0 0 0 0 0 0 0 0 0 0
  95913. - 0 0 0 0 0 0 0 0 0 0 0 0
  95914. - 0 0 0 0 0 0 0 0 0 0 0 0
  95915. - 0 0 0 0 0 0 0 0 0 0 0 0
  95916. - 0 0 0 0 0 0 0 0 0 0 0 0
  95917. - 0 0 0 0 0 0 0 0 0 0 0 0
  95918. - 0 0 0 0 0 0 0 0 0 0 0 0
  95919. - 0 0 0 0 0 0 0 0 0 0 0 0
  95920. - 0 0 0 10 10 10 22 22 22 54 54 54
  95921. - 94 94 94 18 18 18 2 2 6 46 46 46
  95922. -234 234 234 221 221 221 190 190 190 190 190 190
  95923. -190 190 190 187 187 187 187 187 187 190 190 190
  95924. -190 190 190 195 195 195 214 214 214 242 242 242
  95925. -253 253 253 253 253 253 253 253 253 253 253 253
  95926. - 82 82 82 2 2 6 2 2 6 2 2 6
  95927. - 2 2 6 2 2 6 2 2 6 14 14 14
  95928. - 86 86 86 54 54 54 22 22 22 6 6 6
  95929. - 0 0 0 0 0 0 0 0 0 0 0 0
  95930. - 0 0 0 0 0 0 0 0 0 0 0 0
  95931. - 0 0 0 0 0 0 0 0 0 0 0 0
  95932. - 0 0 0 0 0 0 0 0 0 0 0 0
  95933. - 0 0 0 0 0 0 0 0 0 0 0 0
  95934. - 0 0 0 0 0 0 0 0 0 0 0 0
  95935. - 0 0 0 0 0 0 0 0 0 0 0 0
  95936. - 0 0 0 0 0 0 0 0 0 0 0 0
  95937. - 0 0 0 0 0 0 0 0 0 0 0 0
  95938. - 0 0 0 0 0 0 0 0 0 0 0 0
  95939. - 0 0 0 0 0 0 0 0 0 0 0 0
  95940. - 6 6 6 18 18 18 46 46 46 90 90 90
  95941. - 46 46 46 18 18 18 6 6 6 182 182 182
  95942. -253 253 253 246 246 246 206 206 206 190 190 190
  95943. -190 190 190 190 190 190 190 190 190 190 190 190
  95944. -206 206 206 231 231 231 250 250 250 253 253 253
  95945. -253 253 253 253 253 253 253 253 253 253 253 253
  95946. -202 202 202 14 14 14 2 2 6 2 2 6
  95947. - 2 2 6 2 2 6 2 2 6 2 2 6
  95948. - 42 42 42 86 86 86 42 42 42 18 18 18
  95949. - 6 6 6 0 0 0 0 0 0 0 0 0
  95950. - 0 0 0 0 0 0 0 0 0 0 0 0
  95951. - 0 0 0 0 0 0 0 0 0 0 0 0
  95952. - 0 0 0 0 0 0 0 0 0 0 0 0
  95953. - 0 0 0 0 0 0 0 0 0 0 0 0
  95954. - 0 0 0 0 0 0 0 0 0 0 0 0
  95955. - 0 0 0 0 0 0 0 0 0 0 0 0
  95956. - 0 0 0 0 0 0 0 0 0 0 0 0
  95957. - 0 0 0 0 0 0 0 0 0 0 0 0
  95958. - 0 0 0 0 0 0 0 0 0 0 0 0
  95959. - 0 0 0 0 0 0 0 0 0 6 6 6
  95960. - 14 14 14 38 38 38 74 74 74 66 66 66
  95961. - 2 2 6 6 6 6 90 90 90 250 250 250
  95962. -253 253 253 253 253 253 238 238 238 198 198 198
  95963. -190 190 190 190 190 190 195 195 195 221 221 221
  95964. -246 246 246 253 253 253 253 253 253 253 253 253
  95965. -253 253 253 253 253 253 253 253 253 253 253 253
  95966. -253 253 253 82 82 82 2 2 6 2 2 6
  95967. - 2 2 6 2 2 6 2 2 6 2 2 6
  95968. - 2 2 6 78 78 78 70 70 70 34 34 34
  95969. - 14 14 14 6 6 6 0 0 0 0 0 0
  95970. - 0 0 0 0 0 0 0 0 0 0 0 0
  95971. - 0 0 0 0 0 0 0 0 0 0 0 0
  95972. - 0 0 0 0 0 0 0 0 0 0 0 0
  95973. - 0 0 0 0 0 0 0 0 0 0 0 0
  95974. - 0 0 0 0 0 0 0 0 0 0 0 0
  95975. - 0 0 0 0 0 0 0 0 0 0 0 0
  95976. - 0 0 0 0 0 0 0 0 0 0 0 0
  95977. - 0 0 0 0 0 0 0 0 0 0 0 0
  95978. - 0 0 0 0 0 0 0 0 0 0 0 0
  95979. - 0 0 0 0 0 0 0 0 0 14 14 14
  95980. - 34 34 34 66 66 66 78 78 78 6 6 6
  95981. - 2 2 6 18 18 18 218 218 218 253 253 253
  95982. -253 253 253 253 253 253 253 253 253 246 246 246
  95983. -226 226 226 231 231 231 246 246 246 253 253 253
  95984. -253 253 253 253 253 253 253 253 253 253 253 253
  95985. -253 253 253 253 253 253 253 253 253 253 253 253
  95986. -253 253 253 178 178 178 2 2 6 2 2 6
  95987. - 2 2 6 2 2 6 2 2 6 2 2 6
  95988. - 2 2 6 18 18 18 90 90 90 62 62 62
  95989. - 30 30 30 10 10 10 0 0 0 0 0 0
  95990. - 0 0 0 0 0 0 0 0 0 0 0 0
  95991. - 0 0 0 0 0 0 0 0 0 0 0 0
  95992. - 0 0 0 0 0 0 0 0 0 0 0 0
  95993. - 0 0 0 0 0 0 0 0 0 0 0 0
  95994. - 0 0 0 0 0 0 0 0 0 0 0 0
  95995. - 0 0 0 0 0 0 0 0 0 0 0 0
  95996. - 0 0 0 0 0 0 0 0 0 0 0 0
  95997. - 0 0 0 0 0 0 0 0 0 0 0 0
  95998. - 0 0 0 0 0 0 0 0 0 0 0 0
  95999. - 0 0 0 0 0 0 10 10 10 26 26 26
  96000. - 58 58 58 90 90 90 18 18 18 2 2 6
  96001. - 2 2 6 110 110 110 253 253 253 253 253 253
  96002. -253 253 253 253 253 253 253 253 253 253 253 253
  96003. -250 250 250 253 253 253 253 253 253 253 253 253
  96004. -253 253 253 253 253 253 253 253 253 253 253 253
  96005. -253 253 253 253 253 253 253 253 253 253 253 253
  96006. -253 253 253 231 231 231 18 18 18 2 2 6
  96007. - 2 2 6 2 2 6 2 2 6 2 2 6
  96008. - 2 2 6 2 2 6 18 18 18 94 94 94
  96009. - 54 54 54 26 26 26 10 10 10 0 0 0
  96010. - 0 0 0 0 0 0 0 0 0 0 0 0
  96011. - 0 0 0 0 0 0 0 0 0 0 0 0
  96012. - 0 0 0 0 0 0 0 0 0 0 0 0
  96013. - 0 0 0 0 0 0 0 0 0 0 0 0
  96014. - 0 0 0 0 0 0 0 0 0 0 0 0
  96015. - 0 0 0 0 0 0 0 0 0 0 0 0
  96016. - 0 0 0 0 0 0 0 0 0 0 0 0
  96017. - 0 0 0 0 0 0 0 0 0 0 0 0
  96018. - 0 0 0 0 0 0 0 0 0 0 0 0
  96019. - 0 0 0 6 6 6 22 22 22 50 50 50
  96020. - 90 90 90 26 26 26 2 2 6 2 2 6
  96021. - 14 14 14 195 195 195 250 250 250 253 253 253
  96022. -253 253 253 253 253 253 253 253 253 253 253 253
  96023. -253 253 253 253 253 253 253 253 253 253 253 253
  96024. -253 253 253 253 253 253 253 253 253 253 253 253
  96025. -253 253 253 253 253 253 253 253 253 253 253 253
  96026. -250 250 250 242 242 242 54 54 54 2 2 6
  96027. - 2 2 6 2 2 6 2 2 6 2 2 6
  96028. - 2 2 6 2 2 6 2 2 6 38 38 38
  96029. - 86 86 86 50 50 50 22 22 22 6 6 6
  96030. - 0 0 0 0 0 0 0 0 0 0 0 0
  96031. - 0 0 0 0 0 0 0 0 0 0 0 0
  96032. - 0 0 0 0 0 0 0 0 0 0 0 0
  96033. - 0 0 0 0 0 0 0 0 0 0 0 0
  96034. - 0 0 0 0 0 0 0 0 0 0 0 0
  96035. - 0 0 0 0 0 0 0 0 0 0 0 0
  96036. - 0 0 0 0 0 0 0 0 0 0 0 0
  96037. - 0 0 0 0 0 0 0 0 0 0 0 0
  96038. - 0 0 0 0 0 0 0 0 0 0 0 0
  96039. - 6 6 6 14 14 14 38 38 38 82 82 82
  96040. - 34 34 34 2 2 6 2 2 6 2 2 6
  96041. - 42 42 42 195 195 195 246 246 246 253 253 253
  96042. -253 253 253 253 253 253 253 253 253 250 250 250
  96043. -242 242 242 242 242 242 250 250 250 253 253 253
  96044. -253 253 253 253 253 253 253 253 253 253 253 253
  96045. -253 253 253 250 250 250 246 246 246 238 238 238
  96046. -226 226 226 231 231 231 101 101 101 6 6 6
  96047. - 2 2 6 2 2 6 2 2 6 2 2 6
  96048. - 2 2 6 2 2 6 2 2 6 2 2 6
  96049. - 38 38 38 82 82 82 42 42 42 14 14 14
  96050. - 6 6 6 0 0 0 0 0 0 0 0 0
  96051. - 0 0 0 0 0 0 0 0 0 0 0 0
  96052. - 0 0 0 0 0 0 0 0 0 0 0 0
  96053. - 0 0 0 0 0 0 0 0 0 0 0 0
  96054. - 0 0 0 0 0 0 0 0 0 0 0 0
  96055. - 0 0 0 0 0 0 0 0 0 0 0 0
  96056. - 0 0 0 0 0 0 0 0 0 0 0 0
  96057. - 0 0 0 0 0 0 0 0 0 0 0 0
  96058. - 0 0 0 0 0 0 0 0 0 0 0 0
  96059. - 10 10 10 26 26 26 62 62 62 66 66 66
  96060. - 2 2 6 2 2 6 2 2 6 6 6 6
  96061. - 70 70 70 170 170 170 206 206 206 234 234 234
  96062. -246 246 246 250 250 250 250 250 250 238 238 238
  96063. -226 226 226 231 231 231 238 238 238 250 250 250
  96064. -250 250 250 250 250 250 246 246 246 231 231 231
  96065. -214 214 214 206 206 206 202 202 202 202 202 202
  96066. -198 198 198 202 202 202 182 182 182 18 18 18
  96067. - 2 2 6 2 2 6 2 2 6 2 2 6
  96068. - 2 2 6 2 2 6 2 2 6 2 2 6
  96069. - 2 2 6 62 62 62 66 66 66 30 30 30
  96070. - 10 10 10 0 0 0 0 0 0 0 0 0
  96071. - 0 0 0 0 0 0 0 0 0 0 0 0
  96072. - 0 0 0 0 0 0 0 0 0 0 0 0
  96073. - 0 0 0 0 0 0 0 0 0 0 0 0
  96074. - 0 0 0 0 0 0 0 0 0 0 0 0
  96075. - 0 0 0 0 0 0 0 0 0 0 0 0
  96076. - 0 0 0 0 0 0 0 0 0 0 0 0
  96077. - 0 0 0 0 0 0 0 0 0 0 0 0
  96078. - 0 0 0 0 0 0 0 0 0 0 0 0
  96079. - 14 14 14 42 42 42 82 82 82 18 18 18
  96080. - 2 2 6 2 2 6 2 2 6 10 10 10
  96081. - 94 94 94 182 182 182 218 218 218 242 242 242
  96082. -250 250 250 253 253 253 253 253 253 250 250 250
  96083. -234 234 234 253 253 253 253 253 253 253 253 253
  96084. -253 253 253 253 253 253 253 253 253 246 246 246
  96085. -238 238 238 226 226 226 210 210 210 202 202 202
  96086. -195 195 195 195 195 195 210 210 210 158 158 158
  96087. - 6 6 6 14 14 14 50 50 50 14 14 14
  96088. - 2 2 6 2 2 6 2 2 6 2 2 6
  96089. - 2 2 6 6 6 6 86 86 86 46 46 46
  96090. - 18 18 18 6 6 6 0 0 0 0 0 0
  96091. - 0 0 0 0 0 0 0 0 0 0 0 0
  96092. - 0 0 0 0 0 0 0 0 0 0 0 0
  96093. - 0 0 0 0 0 0 0 0 0 0 0 0
  96094. - 0 0 0 0 0 0 0 0 0 0 0 0
  96095. - 0 0 0 0 0 0 0 0 0 0 0 0
  96096. - 0 0 0 0 0 0 0 0 0 0 0 0
  96097. - 0 0 0 0 0 0 0 0 0 0 0 0
  96098. - 0 0 0 0 0 0 0 0 0 6 6 6
  96099. - 22 22 22 54 54 54 70 70 70 2 2 6
  96100. - 2 2 6 10 10 10 2 2 6 22 22 22
  96101. -166 166 166 231 231 231 250 250 250 253 253 253
  96102. -253 253 253 253 253 253 253 253 253 250 250 250
  96103. -242 242 242 253 253 253 253 253 253 253 253 253
  96104. -253 253 253 253 253 253 253 253 253 253 253 253
  96105. -253 253 253 253 253 253 253 253 253 246 246 246
  96106. -231 231 231 206 206 206 198 198 198 226 226 226
  96107. - 94 94 94 2 2 6 6 6 6 38 38 38
  96108. - 30 30 30 2 2 6 2 2 6 2 2 6
  96109. - 2 2 6 2 2 6 62 62 62 66 66 66
  96110. - 26 26 26 10 10 10 0 0 0 0 0 0
  96111. - 0 0 0 0 0 0 0 0 0 0 0 0
  96112. - 0 0 0 0 0 0 0 0 0 0 0 0
  96113. - 0 0 0 0 0 0 0 0 0 0 0 0
  96114. - 0 0 0 0 0 0 0 0 0 0 0 0
  96115. - 0 0 0 0 0 0 0 0 0 0 0 0
  96116. - 0 0 0 0 0 0 0 0 0 0 0 0
  96117. - 0 0 0 0 0 0 0 0 0 0 0 0
  96118. - 0 0 0 0 0 0 0 0 0 10 10 10
  96119. - 30 30 30 74 74 74 50 50 50 2 2 6
  96120. - 26 26 26 26 26 26 2 2 6 106 106 106
  96121. -238 238 238 253 253 253 253 253 253 253 253 253
  96122. -253 253 253 253 253 253 253 253 253 253 253 253
  96123. -253 253 253 253 253 253 253 253 253 253 253 253
  96124. -253 253 253 253 253 253 253 253 253 253 253 253
  96125. -253 253 253 253 253 253 253 253 253 253 253 253
  96126. -253 253 253 246 246 246 218 218 218 202 202 202
  96127. -210 210 210 14 14 14 2 2 6 2 2 6
  96128. - 30 30 30 22 22 22 2 2 6 2 2 6
  96129. - 2 2 6 2 2 6 18 18 18 86 86 86
  96130. - 42 42 42 14 14 14 0 0 0 0 0 0
  96131. - 0 0 0 0 0 0 0 0 0 0 0 0
  96132. - 0 0 0 0 0 0 0 0 0 0 0 0
  96133. - 0 0 0 0 0 0 0 0 0 0 0 0
  96134. - 0 0 0 0 0 0 0 0 0 0 0 0
  96135. - 0 0 0 0 0 0 0 0 0 0 0 0
  96136. - 0 0 0 0 0 0 0 0 0 0 0 0
  96137. - 0 0 0 0 0 0 0 0 0 0 0 0
  96138. - 0 0 0 0 0 0 0 0 0 14 14 14
  96139. - 42 42 42 90 90 90 22 22 22 2 2 6
  96140. - 42 42 42 2 2 6 18 18 18 218 218 218
  96141. -253 253 253 253 253 253 253 253 253 253 253 253
  96142. -253 253 253 253 253 253 253 253 253 253 253 253
  96143. -253 253 253 253 253 253 253 253 253 253 253 253
  96144. -253 253 253 253 253 253 253 253 253 253 253 253
  96145. -253 253 253 253 253 253 253 253 253 253 253 253
  96146. -253 253 253 253 253 253 250 250 250 221 221 221
  96147. -218 218 218 101 101 101 2 2 6 14 14 14
  96148. - 18 18 18 38 38 38 10 10 10 2 2 6
  96149. - 2 2 6 2 2 6 2 2 6 78 78 78
  96150. - 58 58 58 22 22 22 6 6 6 0 0 0
  96151. - 0 0 0 0 0 0 0 0 0 0 0 0
  96152. - 0 0 0 0 0 0 0 0 0 0 0 0
  96153. - 0 0 0 0 0 0 0 0 0 0 0 0
  96154. - 0 0 0 0 0 0 0 0 0 0 0 0
  96155. - 0 0 0 0 0 0 0 0 0 0 0 0
  96156. - 0 0 0 0 0 0 0 0 0 0 0 0
  96157. - 0 0 0 0 0 0 0 0 0 0 0 0
  96158. - 0 0 0 0 0 0 6 6 6 18 18 18
  96159. - 54 54 54 82 82 82 2 2 6 26 26 26
  96160. - 22 22 22 2 2 6 123 123 123 253 253 253
  96161. -253 253 253 253 253 253 253 253 253 253 253 253
  96162. -253 253 253 253 253 253 253 253 253 253 253 253
  96163. -253 253 253 253 253 253 253 253 253 253 253 253
  96164. -253 253 253 253 253 253 253 253 253 253 253 253
  96165. -253 253 253 253 253 253 253 253 253 253 253 253
  96166. -253 253 253 253 253 253 253 253 253 250 250 250
  96167. -238 238 238 198 198 198 6 6 6 38 38 38
  96168. - 58 58 58 26 26 26 38 38 38 2 2 6
  96169. - 2 2 6 2 2 6 2 2 6 46 46 46
  96170. - 78 78 78 30 30 30 10 10 10 0 0 0
  96171. - 0 0 0 0 0 0 0 0 0 0 0 0
  96172. - 0 0 0 0 0 0 0 0 0 0 0 0
  96173. - 0 0 0 0 0 0 0 0 0 0 0 0
  96174. - 0 0 0 0 0 0 0 0 0 0 0 0
  96175. - 0 0 0 0 0 0 0 0 0 0 0 0
  96176. - 0 0 0 0 0 0 0 0 0 0 0 0
  96177. - 0 0 0 0 0 0 0 0 0 0 0 0
  96178. - 0 0 0 0 0 0 10 10 10 30 30 30
  96179. - 74 74 74 58 58 58 2 2 6 42 42 42
  96180. - 2 2 6 22 22 22 231 231 231 253 253 253
  96181. -253 253 253 253 253 253 253 253 253 253 253 253
  96182. -253 253 253 253 253 253 253 253 253 250 250 250
  96183. -253 253 253 253 253 253 253 253 253 253 253 253
  96184. -253 253 253 253 253 253 253 253 253 253 253 253
  96185. -253 253 253 253 253 253 253 253 253 253 253 253
  96186. -253 253 253 253 253 253 253 253 253 253 253 253
  96187. -253 253 253 246 246 246 46 46 46 38 38 38
  96188. - 42 42 42 14 14 14 38 38 38 14 14 14
  96189. - 2 2 6 2 2 6 2 2 6 6 6 6
  96190. - 86 86 86 46 46 46 14 14 14 0 0 0
  96191. - 0 0 0 0 0 0 0 0 0 0 0 0
  96192. - 0 0 0 0 0 0 0 0 0 0 0 0
  96193. - 0 0 0 0 0 0 0 0 0 0 0 0
  96194. - 0 0 0 0 0 0 0 0 0 0 0 0
  96195. - 0 0 0 0 0 0 0 0 0 0 0 0
  96196. - 0 0 0 0 0 0 0 0 0 0 0 0
  96197. - 0 0 0 0 0 0 0 0 0 0 0 0
  96198. - 0 0 0 6 6 6 14 14 14 42 42 42
  96199. - 90 90 90 18 18 18 18 18 18 26 26 26
  96200. - 2 2 6 116 116 116 253 253 253 253 253 253
  96201. -253 253 253 253 253 253 253 253 253 253 253 253
  96202. -253 253 253 253 253 253 250 250 250 238 238 238
  96203. -253 253 253 253 253 253 253 253 253 253 253 253
  96204. -253 253 253 253 253 253 253 253 253 253 253 253
  96205. -253 253 253 253 253 253 253 253 253 253 253 253
  96206. -253 253 253 253 253 253 253 253 253 253 253 253
  96207. -253 253 253 253 253 253 94 94 94 6 6 6
  96208. - 2 2 6 2 2 6 10 10 10 34 34 34
  96209. - 2 2 6 2 2 6 2 2 6 2 2 6
  96210. - 74 74 74 58 58 58 22 22 22 6 6 6
  96211. - 0 0 0 0 0 0 0 0 0 0 0 0
  96212. - 0 0 0 0 0 0 0 0 0 0 0 0
  96213. - 0 0 0 0 0 0 0 0 0 0 0 0
  96214. - 0 0 0 0 0 0 0 0 0 0 0 0
  96215. - 0 0 0 0 0 0 0 0 0 0 0 0
  96216. - 0 0 0 0 0 0 0 0 0 0 0 0
  96217. - 0 0 0 0 0 0 0 0 0 0 0 0
  96218. - 0 0 0 10 10 10 26 26 26 66 66 66
  96219. - 82 82 82 2 2 6 38 38 38 6 6 6
  96220. - 14 14 14 210 210 210 253 253 253 253 253 253
  96221. -253 253 253 253 253 253 253 253 253 253 253 253
  96222. -253 253 253 253 253 253 246 246 246 242 242 242
  96223. -253 253 253 253 253 253 253 253 253 253 253 253
  96224. -253 253 253 253 253 253 253 253 253 253 253 253
  96225. -253 253 253 253 253 253 253 253 253 253 253 253
  96226. -253 253 253 253 253 253 253 253 253 253 253 253
  96227. -253 253 253 253 253 253 144 144 144 2 2 6
  96228. - 2 2 6 2 2 6 2 2 6 46 46 46
  96229. - 2 2 6 2 2 6 2 2 6 2 2 6
  96230. - 42 42 42 74 74 74 30 30 30 10 10 10
  96231. - 0 0 0 0 0 0 0 0 0 0 0 0
  96232. - 0 0 0 0 0 0 0 0 0 0 0 0
  96233. - 0 0 0 0 0 0 0 0 0 0 0 0
  96234. - 0 0 0 0 0 0 0 0 0 0 0 0
  96235. - 0 0 0 0 0 0 0 0 0 0 0 0
  96236. - 0 0 0 0 0 0 0 0 0 0 0 0
  96237. - 0 0 0 0 0 0 0 0 0 0 0 0
  96238. - 6 6 6 14 14 14 42 42 42 90 90 90
  96239. - 26 26 26 6 6 6 42 42 42 2 2 6
  96240. - 74 74 74 250 250 250 253 253 253 253 253 253
  96241. -253 253 253 253 253 253 253 253 253 253 253 253
  96242. -253 253 253 253 253 253 242 242 242 242 242 242
  96243. -253 253 253 253 253 253 253 253 253 253 253 253
  96244. -253 253 253 253 253 253 253 253 253 253 253 253
  96245. -253 253 253 253 253 253 253 253 253 253 253 253
  96246. -253 253 253 253 253 253 253 253 253 253 253 253
  96247. -253 253 253 253 253 253 182 182 182 2 2 6
  96248. - 2 2 6 2 2 6 2 2 6 46 46 46
  96249. - 2 2 6 2 2 6 2 2 6 2 2 6
  96250. - 10 10 10 86 86 86 38 38 38 10 10 10
  96251. - 0 0 0 0 0 0 0 0 0 0 0 0
  96252. - 0 0 0 0 0 0 0 0 0 0 0 0
  96253. - 0 0 0 0 0 0 0 0 0 0 0 0
  96254. - 0 0 0 0 0 0 0 0 0 0 0 0
  96255. - 0 0 0 0 0 0 0 0 0 0 0 0
  96256. - 0 0 0 0 0 0 0 0 0 0 0 0
  96257. - 0 0 0 0 0 0 0 0 0 0 0 0
  96258. - 10 10 10 26 26 26 66 66 66 82 82 82
  96259. - 2 2 6 22 22 22 18 18 18 2 2 6
  96260. -149 149 149 253 253 253 253 253 253 253 253 253
  96261. -253 253 253 253 253 253 253 253 253 253 253 253
  96262. -253 253 253 253 253 253 234 234 234 242 242 242
  96263. -253 253 253 253 253 253 253 253 253 253 253 253
  96264. -253 253 253 253 253 253 253 253 253 253 253 253
  96265. -253 253 253 253 253 253 253 253 253 253 253 253
  96266. -253 253 253 253 253 253 253 253 253 253 253 253
  96267. -253 253 253 253 253 253 206 206 206 2 2 6
  96268. - 2 2 6 2 2 6 2 2 6 38 38 38
  96269. - 2 2 6 2 2 6 2 2 6 2 2 6
  96270. - 6 6 6 86 86 86 46 46 46 14 14 14
  96271. - 0 0 0 0 0 0 0 0 0 0 0 0
  96272. - 0 0 0 0 0 0 0 0 0 0 0 0
  96273. - 0 0 0 0 0 0 0 0 0 0 0 0
  96274. - 0 0 0 0 0 0 0 0 0 0 0 0
  96275. - 0 0 0 0 0 0 0 0 0 0 0 0
  96276. - 0 0 0 0 0 0 0 0 0 0 0 0
  96277. - 0 0 0 0 0 0 0 0 0 6 6 6
  96278. - 18 18 18 46 46 46 86 86 86 18 18 18
  96279. - 2 2 6 34 34 34 10 10 10 6 6 6
  96280. -210 210 210 253 253 253 253 253 253 253 253 253
  96281. -253 253 253 253 253 253 253 253 253 253 253 253
  96282. -253 253 253 253 253 253 234 234 234 242 242 242
  96283. -253 253 253 253 253 253 253 253 253 253 253 253
  96284. -253 253 253 253 253 253 253 253 253 253 253 253
  96285. -253 253 253 253 253 253 253 253 253 253 253 253
  96286. -253 253 253 253 253 253 253 253 253 253 253 253
  96287. -253 253 253 253 253 253 221 221 221 6 6 6
  96288. - 2 2 6 2 2 6 6 6 6 30 30 30
  96289. - 2 2 6 2 2 6 2 2 6 2 2 6
  96290. - 2 2 6 82 82 82 54 54 54 18 18 18
  96291. - 6 6 6 0 0 0 0 0 0 0 0 0
  96292. - 0 0 0 0 0 0 0 0 0 0 0 0
  96293. - 0 0 0 0 0 0 0 0 0 0 0 0
  96294. - 0 0 0 0 0 0 0 0 0 0 0 0
  96295. - 0 0 0 0 0 0 0 0 0 0 0 0
  96296. - 0 0 0 0 0 0 0 0 0 0 0 0
  96297. - 0 0 0 0 0 0 0 0 0 10 10 10
  96298. - 26 26 26 66 66 66 62 62 62 2 2 6
  96299. - 2 2 6 38 38 38 10 10 10 26 26 26
  96300. -238 238 238 253 253 253 253 253 253 253 253 253
  96301. -253 253 253 253 253 253 253 253 253 253 253 253
  96302. -253 253 253 253 253 253 231 231 231 238 238 238
  96303. -253 253 253 253 253 253 253 253 253 253 253 253
  96304. -253 253 253 253 253 253 253 253 253 253 253 253
  96305. -253 253 253 253 253 253 253 253 253 253 253 253
  96306. -253 253 253 253 253 253 253 253 253 253 253 253
  96307. -253 253 253 253 253 253 231 231 231 6 6 6
  96308. - 2 2 6 2 2 6 10 10 10 30 30 30
  96309. - 2 2 6 2 2 6 2 2 6 2 2 6
  96310. - 2 2 6 66 66 66 58 58 58 22 22 22
  96311. - 6 6 6 0 0 0 0 0 0 0 0 0
  96312. - 0 0 0 0 0 0 0 0 0 0 0 0
  96313. - 0 0 0 0 0 0 0 0 0 0 0 0
  96314. - 0 0 0 0 0 0 0 0 0 0 0 0
  96315. - 0 0 0 0 0 0 0 0 0 0 0 0
  96316. - 0 0 0 0 0 0 0 0 0 0 0 0
  96317. - 0 0 0 0 0 0 0 0 0 10 10 10
  96318. - 38 38 38 78 78 78 6 6 6 2 2 6
  96319. - 2 2 6 46 46 46 14 14 14 42 42 42
  96320. -246 246 246 253 253 253 253 253 253 253 253 253
  96321. -253 253 253 253 253 253 253 253 253 253 253 253
  96322. -253 253 253 253 253 253 231 231 231 242 242 242
  96323. -253 253 253 253 253 253 253 253 253 253 253 253
  96324. -253 253 253 253 253 253 253 253 253 253 253 253
  96325. -253 253 253 253 253 253 253 253 253 253 253 253
  96326. -253 253 253 253 253 253 253 253 253 253 253 253
  96327. -253 253 253 253 253 253 234 234 234 10 10 10
  96328. - 2 2 6 2 2 6 22 22 22 14 14 14
  96329. - 2 2 6 2 2 6 2 2 6 2 2 6
  96330. - 2 2 6 66 66 66 62 62 62 22 22 22
  96331. - 6 6 6 0 0 0 0 0 0 0 0 0
  96332. - 0 0 0 0 0 0 0 0 0 0 0 0
  96333. - 0 0 0 0 0 0 0 0 0 0 0 0
  96334. - 0 0 0 0 0 0 0 0 0 0 0 0
  96335. - 0 0 0 0 0 0 0 0 0 0 0 0
  96336. - 0 0 0 0 0 0 0 0 0 0 0 0
  96337. - 0 0 0 0 0 0 6 6 6 18 18 18
  96338. - 50 50 50 74 74 74 2 2 6 2 2 6
  96339. - 14 14 14 70 70 70 34 34 34 62 62 62
  96340. -250 250 250 253 253 253 253 253 253 253 253 253
  96341. -253 253 253 253 253 253 253 253 253 253 253 253
  96342. -253 253 253 253 253 253 231 231 231 246 246 246
  96343. -253 253 253 253 253 253 253 253 253 253 253 253
  96344. -253 253 253 253 253 253 253 253 253 253 253 253
  96345. -253 253 253 253 253 253 253 253 253 253 253 253
  96346. -253 253 253 253 253 253 253 253 253 253 253 253
  96347. -253 253 253 253 253 253 234 234 234 14 14 14
  96348. - 2 2 6 2 2 6 30 30 30 2 2 6
  96349. - 2 2 6 2 2 6 2 2 6 2 2 6
  96350. - 2 2 6 66 66 66 62 62 62 22 22 22
  96351. - 6 6 6 0 0 0 0 0 0 0 0 0
  96352. - 0 0 0 0 0 0 0 0 0 0 0 0
  96353. - 0 0 0 0 0 0 0 0 0 0 0 0
  96354. - 0 0 0 0 0 0 0 0 0 0 0 0
  96355. - 0 0 0 0 0 0 0 0 0 0 0 0
  96356. - 0 0 0 0 0 0 0 0 0 0 0 0
  96357. - 0 0 0 0 0 0 6 6 6 18 18 18
  96358. - 54 54 54 62 62 62 2 2 6 2 2 6
  96359. - 2 2 6 30 30 30 46 46 46 70 70 70
  96360. -250 250 250 253 253 253 253 253 253 253 253 253
  96361. -253 253 253 253 253 253 253 253 253 253 253 253
  96362. -253 253 253 253 253 253 231 231 231 246 246 246
  96363. -253 253 253 253 253 253 253 253 253 253 253 253
  96364. -253 253 253 253 253 253 253 253 253 253 253 253
  96365. -253 253 253 253 253 253 253 253 253 253 253 253
  96366. -253 253 253 253 253 253 253 253 253 253 253 253
  96367. -253 253 253 253 253 253 226 226 226 10 10 10
  96368. - 2 2 6 6 6 6 30 30 30 2 2 6
  96369. - 2 2 6 2 2 6 2 2 6 2 2 6
  96370. - 2 2 6 66 66 66 58 58 58 22 22 22
  96371. - 6 6 6 0 0 0 0 0 0 0 0 0
  96372. - 0 0 0 0 0 0 0 0 0 0 0 0
  96373. - 0 0 0 0 0 0 0 0 0 0 0 0
  96374. - 0 0 0 0 0 0 0 0 0 0 0 0
  96375. - 0 0 0 0 0 0 0 0 0 0 0 0
  96376. - 0 0 0 0 0 0 0 0 0 0 0 0
  96377. - 0 0 0 0 0 0 6 6 6 22 22 22
  96378. - 58 58 58 62 62 62 2 2 6 2 2 6
  96379. - 2 2 6 2 2 6 30 30 30 78 78 78
  96380. -250 250 250 253 253 253 253 253 253 253 253 253
  96381. -253 253 253 253 253 253 253 253 253 253 253 253
  96382. -253 253 253 253 253 253 231 231 231 246 246 246
  96383. -253 253 253 253 253 253 253 253 253 253 253 253
  96384. -253 253 253 253 253 253 253 253 253 253 253 253
  96385. -253 253 253 253 253 253 253 253 253 253 253 253
  96386. -253 253 253 253 253 253 253 253 253 253 253 253
  96387. -253 253 253 253 253 253 206 206 206 2 2 6
  96388. - 22 22 22 34 34 34 18 14 6 22 22 22
  96389. - 26 26 26 18 18 18 6 6 6 2 2 6
  96390. - 2 2 6 82 82 82 54 54 54 18 18 18
  96391. - 6 6 6 0 0 0 0 0 0 0 0 0
  96392. - 0 0 0 0 0 0 0 0 0 0 0 0
  96393. - 0 0 0 0 0 0 0 0 0 0 0 0
  96394. - 0 0 0 0 0 0 0 0 0 0 0 0
  96395. - 0 0 0 0 0 0 0 0 0 0 0 0
  96396. - 0 0 0 0 0 0 0 0 0 0 0 0
  96397. - 0 0 0 0 0 0 6 6 6 26 26 26
  96398. - 62 62 62 106 106 106 74 54 14 185 133 11
  96399. -210 162 10 121 92 8 6 6 6 62 62 62
  96400. -238 238 238 253 253 253 253 253 253 253 253 253
  96401. -253 253 253 253 253 253 253 253 253 253 253 253
  96402. -253 253 253 253 253 253 231 231 231 246 246 246
  96403. -253 253 253 253 253 253 253 253 253 253 253 253
  96404. -253 253 253 253 253 253 253 253 253 253 253 253
  96405. -253 253 253 253 253 253 253 253 253 253 253 253
  96406. -253 253 253 253 253 253 253 253 253 253 253 253
  96407. -253 253 253 253 253 253 158 158 158 18 18 18
  96408. - 14 14 14 2 2 6 2 2 6 2 2 6
  96409. - 6 6 6 18 18 18 66 66 66 38 38 38
  96410. - 6 6 6 94 94 94 50 50 50 18 18 18
  96411. - 6 6 6 0 0 0 0 0 0 0 0 0
  96412. - 0 0 0 0 0 0 0 0 0 0 0 0
  96413. - 0 0 0 0 0 0 0 0 0 0 0 0
  96414. - 0 0 0 0 0 0 0 0 0 0 0 0
  96415. - 0 0 0 0 0 0 0 0 0 0 0 0
  96416. - 0 0 0 0 0 0 0 0 0 6 6 6
  96417. - 10 10 10 10 10 10 18 18 18 38 38 38
  96418. - 78 78 78 142 134 106 216 158 10 242 186 14
  96419. -246 190 14 246 190 14 156 118 10 10 10 10
  96420. - 90 90 90 238 238 238 253 253 253 253 253 253
  96421. -253 253 253 253 253 253 253 253 253 253 253 253
  96422. -253 253 253 253 253 253 231 231 231 250 250 250
  96423. -253 253 253 253 253 253 253 253 253 253 253 253
  96424. -253 253 253 253 253 253 253 253 253 253 253 253
  96425. -253 253 253 253 253 253 253 253 253 253 253 253
  96426. -253 253 253 253 253 253 253 253 253 246 230 190
  96427. -238 204 91 238 204 91 181 142 44 37 26 9
  96428. - 2 2 6 2 2 6 2 2 6 2 2 6
  96429. - 2 2 6 2 2 6 38 38 38 46 46 46
  96430. - 26 26 26 106 106 106 54 54 54 18 18 18
  96431. - 6 6 6 0 0 0 0 0 0 0 0 0
  96432. - 0 0 0 0 0 0 0 0 0 0 0 0
  96433. - 0 0 0 0 0 0 0 0 0 0 0 0
  96434. - 0 0 0 0 0 0 0 0 0 0 0 0
  96435. - 0 0 0 0 0 0 0 0 0 0 0 0
  96436. - 0 0 0 6 6 6 14 14 14 22 22 22
  96437. - 30 30 30 38 38 38 50 50 50 70 70 70
  96438. -106 106 106 190 142 34 226 170 11 242 186 14
  96439. -246 190 14 246 190 14 246 190 14 154 114 10
  96440. - 6 6 6 74 74 74 226 226 226 253 253 253
  96441. -253 253 253 253 253 253 253 253 253 253 253 253
  96442. -253 253 253 253 253 253 231 231 231 250 250 250
  96443. -253 253 253 253 253 253 253 253 253 253 253 253
  96444. -253 253 253 253 253 253 253 253 253 253 253 253
  96445. -253 253 253 253 253 253 253 253 253 253 253 253
  96446. -253 253 253 253 253 253 253 253 253 228 184 62
  96447. -241 196 14 241 208 19 232 195 16 38 30 10
  96448. - 2 2 6 2 2 6 2 2 6 2 2 6
  96449. - 2 2 6 6 6 6 30 30 30 26 26 26
  96450. -203 166 17 154 142 90 66 66 66 26 26 26
  96451. - 6 6 6 0 0 0 0 0 0 0 0 0
  96452. - 0 0 0 0 0 0 0 0 0 0 0 0
  96453. - 0 0 0 0 0 0 0 0 0 0 0 0
  96454. - 0 0 0 0 0 0 0 0 0 0 0 0
  96455. - 0 0 0 0 0 0 0 0 0 0 0 0
  96456. - 6 6 6 18 18 18 38 38 38 58 58 58
  96457. - 78 78 78 86 86 86 101 101 101 123 123 123
  96458. -175 146 61 210 150 10 234 174 13 246 186 14
  96459. -246 190 14 246 190 14 246 190 14 238 190 10
  96460. -102 78 10 2 2 6 46 46 46 198 198 198
  96461. -253 253 253 253 253 253 253 253 253 253 253 253
  96462. -253 253 253 253 253 253 234 234 234 242 242 242
  96463. -253 253 253 253 253 253 253 253 253 253 253 253
  96464. -253 253 253 253 253 253 253 253 253 253 253 253
  96465. -253 253 253 253 253 253 253 253 253 253 253 253
  96466. -253 253 253 253 253 253 253 253 253 224 178 62
  96467. -242 186 14 241 196 14 210 166 10 22 18 6
  96468. - 2 2 6 2 2 6 2 2 6 2 2 6
  96469. - 2 2 6 2 2 6 6 6 6 121 92 8
  96470. -238 202 15 232 195 16 82 82 82 34 34 34
  96471. - 10 10 10 0 0 0 0 0 0 0 0 0
  96472. - 0 0 0 0 0 0 0 0 0 0 0 0
  96473. - 0 0 0 0 0 0 0 0 0 0 0 0
  96474. - 0 0 0 0 0 0 0 0 0 0 0 0
  96475. - 0 0 0 0 0 0 0 0 0 0 0 0
  96476. - 14 14 14 38 38 38 70 70 70 154 122 46
  96477. -190 142 34 200 144 11 197 138 11 197 138 11
  96478. -213 154 11 226 170 11 242 186 14 246 190 14
  96479. -246 190 14 246 190 14 246 190 14 246 190 14
  96480. -225 175 15 46 32 6 2 2 6 22 22 22
  96481. -158 158 158 250 250 250 253 253 253 253 253 253
  96482. -253 253 253 253 253 253 253 253 253 253 253 253
  96483. -253 253 253 253 253 253 253 253 253 253 253 253
  96484. -253 253 253 253 253 253 253 253 253 253 253 253
  96485. -253 253 253 253 253 253 253 253 253 253 253 253
  96486. -253 253 253 250 250 250 242 242 242 224 178 62
  96487. -239 182 13 236 186 11 213 154 11 46 32 6
  96488. - 2 2 6 2 2 6 2 2 6 2 2 6
  96489. - 2 2 6 2 2 6 61 42 6 225 175 15
  96490. -238 190 10 236 186 11 112 100 78 42 42 42
  96491. - 14 14 14 0 0 0 0 0 0 0 0 0
  96492. - 0 0 0 0 0 0 0 0 0 0 0 0
  96493. - 0 0 0 0 0 0 0 0 0 0 0 0
  96494. - 0 0 0 0 0 0 0 0 0 0 0 0
  96495. - 0 0 0 0 0 0 0 0 0 6 6 6
  96496. - 22 22 22 54 54 54 154 122 46 213 154 11
  96497. -226 170 11 230 174 11 226 170 11 226 170 11
  96498. -236 178 12 242 186 14 246 190 14 246 190 14
  96499. -246 190 14 246 190 14 246 190 14 246 190 14
  96500. -241 196 14 184 144 12 10 10 10 2 2 6
  96501. - 6 6 6 116 116 116 242 242 242 253 253 253
  96502. -253 253 253 253 253 253 253 253 253 253 253 253
  96503. -253 253 253 253 253 253 253 253 253 253 253 253
  96504. -253 253 253 253 253 253 253 253 253 253 253 253
  96505. -253 253 253 253 253 253 253 253 253 253 253 253
  96506. -253 253 253 231 231 231 198 198 198 214 170 54
  96507. -236 178 12 236 178 12 210 150 10 137 92 6
  96508. - 18 14 6 2 2 6 2 2 6 2 2 6
  96509. - 6 6 6 70 47 6 200 144 11 236 178 12
  96510. -239 182 13 239 182 13 124 112 88 58 58 58
  96511. - 22 22 22 6 6 6 0 0 0 0 0 0
  96512. - 0 0 0 0 0 0 0 0 0 0 0 0
  96513. - 0 0 0 0 0 0 0 0 0 0 0 0
  96514. - 0 0 0 0 0 0 0 0 0 0 0 0
  96515. - 0 0 0 0 0 0 0 0 0 10 10 10
  96516. - 30 30 30 70 70 70 180 133 36 226 170 11
  96517. -239 182 13 242 186 14 242 186 14 246 186 14
  96518. -246 190 14 246 190 14 246 190 14 246 190 14
  96519. -246 190 14 246 190 14 246 190 14 246 190 14
  96520. -246 190 14 232 195 16 98 70 6 2 2 6
  96521. - 2 2 6 2 2 6 66 66 66 221 221 221
  96522. -253 253 253 253 253 253 253 253 253 253 253 253
  96523. -253 253 253 253 253 253 253 253 253 253 253 253
  96524. -253 253 253 253 253 253 253 253 253 253 253 253
  96525. -253 253 253 253 253 253 253 253 253 253 253 253
  96526. -253 253 253 206 206 206 198 198 198 214 166 58
  96527. -230 174 11 230 174 11 216 158 10 192 133 9
  96528. -163 110 8 116 81 8 102 78 10 116 81 8
  96529. -167 114 7 197 138 11 226 170 11 239 182 13
  96530. -242 186 14 242 186 14 162 146 94 78 78 78
  96531. - 34 34 34 14 14 14 6 6 6 0 0 0
  96532. - 0 0 0 0 0 0 0 0 0 0 0 0
  96533. - 0 0 0 0 0 0 0 0 0 0 0 0
  96534. - 0 0 0 0 0 0 0 0 0 0 0 0
  96535. - 0 0 0 0 0 0 0 0 0 6 6 6
  96536. - 30 30 30 78 78 78 190 142 34 226 170 11
  96537. -239 182 13 246 190 14 246 190 14 246 190 14
  96538. -246 190 14 246 190 14 246 190 14 246 190 14
  96539. -246 190 14 246 190 14 246 190 14 246 190 14
  96540. -246 190 14 241 196 14 203 166 17 22 18 6
  96541. - 2 2 6 2 2 6 2 2 6 38 38 38
  96542. -218 218 218 253 253 253 253 253 253 253 253 253
  96543. -253 253 253 253 253 253 253 253 253 253 253 253
  96544. -253 253 253 253 253 253 253 253 253 253 253 253
  96545. -253 253 253 253 253 253 253 253 253 253 253 253
  96546. -250 250 250 206 206 206 198 198 198 202 162 69
  96547. -226 170 11 236 178 12 224 166 10 210 150 10
  96548. -200 144 11 197 138 11 192 133 9 197 138 11
  96549. -210 150 10 226 170 11 242 186 14 246 190 14
  96550. -246 190 14 246 186 14 225 175 15 124 112 88
  96551. - 62 62 62 30 30 30 14 14 14 6 6 6
  96552. - 0 0 0 0 0 0 0 0 0 0 0 0
  96553. - 0 0 0 0 0 0 0 0 0 0 0 0
  96554. - 0 0 0 0 0 0 0 0 0 0 0 0
  96555. - 0 0 0 0 0 0 0 0 0 10 10 10
  96556. - 30 30 30 78 78 78 174 135 50 224 166 10
  96557. -239 182 13 246 190 14 246 190 14 246 190 14
  96558. -246 190 14 246 190 14 246 190 14 246 190 14
  96559. -246 190 14 246 190 14 246 190 14 246 190 14
  96560. -246 190 14 246 190 14 241 196 14 139 102 15
  96561. - 2 2 6 2 2 6 2 2 6 2 2 6
  96562. - 78 78 78 250 250 250 253 253 253 253 253 253
  96563. -253 253 253 253 253 253 253 253 253 253 253 253
  96564. -253 253 253 253 253 253 253 253 253 253 253 253
  96565. -253 253 253 253 253 253 253 253 253 253 253 253
  96566. -250 250 250 214 214 214 198 198 198 190 150 46
  96567. -219 162 10 236 178 12 234 174 13 224 166 10
  96568. -216 158 10 213 154 11 213 154 11 216 158 10
  96569. -226 170 11 239 182 13 246 190 14 246 190 14
  96570. -246 190 14 246 190 14 242 186 14 206 162 42
  96571. -101 101 101 58 58 58 30 30 30 14 14 14
  96572. - 6 6 6 0 0 0 0 0 0 0 0 0
  96573. - 0 0 0 0 0 0 0 0 0 0 0 0
  96574. - 0 0 0 0 0 0 0 0 0 0 0 0
  96575. - 0 0 0 0 0 0 0 0 0 10 10 10
  96576. - 30 30 30 74 74 74 174 135 50 216 158 10
  96577. -236 178 12 246 190 14 246 190 14 246 190 14
  96578. -246 190 14 246 190 14 246 190 14 246 190 14
  96579. -246 190 14 246 190 14 246 190 14 246 190 14
  96580. -246 190 14 246 190 14 241 196 14 226 184 13
  96581. - 61 42 6 2 2 6 2 2 6 2 2 6
  96582. - 22 22 22 238 238 238 253 253 253 253 253 253
  96583. -253 253 253 253 253 253 253 253 253 253 253 253
  96584. -253 253 253 253 253 253 253 253 253 253 253 253
  96585. -253 253 253 253 253 253 253 253 253 253 253 253
  96586. -253 253 253 226 226 226 187 187 187 180 133 36
  96587. -216 158 10 236 178 12 239 182 13 236 178 12
  96588. -230 174 11 226 170 11 226 170 11 230 174 11
  96589. -236 178 12 242 186 14 246 190 14 246 190 14
  96590. -246 190 14 246 190 14 246 186 14 239 182 13
  96591. -206 162 42 106 106 106 66 66 66 34 34 34
  96592. - 14 14 14 6 6 6 0 0 0 0 0 0
  96593. - 0 0 0 0 0 0 0 0 0 0 0 0
  96594. - 0 0 0 0 0 0 0 0 0 0 0 0
  96595. - 0 0 0 0 0 0 0 0 0 6 6 6
  96596. - 26 26 26 70 70 70 163 133 67 213 154 11
  96597. -236 178 12 246 190 14 246 190 14 246 190 14
  96598. -246 190 14 246 190 14 246 190 14 246 190 14
  96599. -246 190 14 246 190 14 246 190 14 246 190 14
  96600. -246 190 14 246 190 14 246 190 14 241 196 14
  96601. -190 146 13 18 14 6 2 2 6 2 2 6
  96602. - 46 46 46 246 246 246 253 253 253 253 253 253
  96603. -253 253 253 253 253 253 253 253 253 253 253 253
  96604. -253 253 253 253 253 253 253 253 253 253 253 253
  96605. -253 253 253 253 253 253 253 253 253 253 253 253
  96606. -253 253 253 221 221 221 86 86 86 156 107 11
  96607. -216 158 10 236 178 12 242 186 14 246 186 14
  96608. -242 186 14 239 182 13 239 182 13 242 186 14
  96609. -242 186 14 246 186 14 246 190 14 246 190 14
  96610. -246 190 14 246 190 14 246 190 14 246 190 14
  96611. -242 186 14 225 175 15 142 122 72 66 66 66
  96612. - 30 30 30 10 10 10 0 0 0 0 0 0
  96613. - 0 0 0 0 0 0 0 0 0 0 0 0
  96614. - 0 0 0 0 0 0 0 0 0 0 0 0
  96615. - 0 0 0 0 0 0 0 0 0 6 6 6
  96616. - 26 26 26 70 70 70 163 133 67 210 150 10
  96617. -236 178 12 246 190 14 246 190 14 246 190 14
  96618. -246 190 14 246 190 14 246 190 14 246 190 14
  96619. -246 190 14 246 190 14 246 190 14 246 190 14
  96620. -246 190 14 246 190 14 246 190 14 246 190 14
  96621. -232 195 16 121 92 8 34 34 34 106 106 106
  96622. -221 221 221 253 253 253 253 253 253 253 253 253
  96623. -253 253 253 253 253 253 253 253 253 253 253 253
  96624. -253 253 253 253 253 253 253 253 253 253 253 253
  96625. -253 253 253 253 253 253 253 253 253 253 253 253
  96626. -242 242 242 82 82 82 18 14 6 163 110 8
  96627. -216 158 10 236 178 12 242 186 14 246 190 14
  96628. -246 190 14 246 190 14 246 190 14 246 190 14
  96629. -246 190 14 246 190 14 246 190 14 246 190 14
  96630. -246 190 14 246 190 14 246 190 14 246 190 14
  96631. -246 190 14 246 190 14 242 186 14 163 133 67
  96632. - 46 46 46 18 18 18 6 6 6 0 0 0
  96633. - 0 0 0 0 0 0 0 0 0 0 0 0
  96634. - 0 0 0 0 0 0 0 0 0 0 0 0
  96635. - 0 0 0 0 0 0 0 0 0 10 10 10
  96636. - 30 30 30 78 78 78 163 133 67 210 150 10
  96637. -236 178 12 246 186 14 246 190 14 246 190 14
  96638. -246 190 14 246 190 14 246 190 14 246 190 14
  96639. -246 190 14 246 190 14 246 190 14 246 190 14
  96640. -246 190 14 246 190 14 246 190 14 246 190 14
  96641. -241 196 14 215 174 15 190 178 144 253 253 253
  96642. -253 253 253 253 253 253 253 253 253 253 253 253
  96643. -253 253 253 253 253 253 253 253 253 253 253 253
  96644. -253 253 253 253 253 253 253 253 253 253 253 253
  96645. -253 253 253 253 253 253 253 253 253 218 218 218
  96646. - 58 58 58 2 2 6 22 18 6 167 114 7
  96647. -216 158 10 236 178 12 246 186 14 246 190 14
  96648. -246 190 14 246 190 14 246 190 14 246 190 14
  96649. -246 190 14 246 190 14 246 190 14 246 190 14
  96650. -246 190 14 246 190 14 246 190 14 246 190 14
  96651. -246 190 14 246 186 14 242 186 14 190 150 46
  96652. - 54 54 54 22 22 22 6 6 6 0 0 0
  96653. - 0 0 0 0 0 0 0 0 0 0 0 0
  96654. - 0 0 0 0 0 0 0 0 0 0 0 0
  96655. - 0 0 0 0 0 0 0 0 0 14 14 14
  96656. - 38 38 38 86 86 86 180 133 36 213 154 11
  96657. -236 178 12 246 186 14 246 190 14 246 190 14
  96658. -246 190 14 246 190 14 246 190 14 246 190 14
  96659. -246 190 14 246 190 14 246 190 14 246 190 14
  96660. -246 190 14 246 190 14 246 190 14 246 190 14
  96661. -246 190 14 232 195 16 190 146 13 214 214 214
  96662. -253 253 253 253 253 253 253 253 253 253 253 253
  96663. -253 253 253 253 253 253 253 253 253 253 253 253
  96664. -253 253 253 253 253 253 253 253 253 253 253 253
  96665. -253 253 253 250 250 250 170 170 170 26 26 26
  96666. - 2 2 6 2 2 6 37 26 9 163 110 8
  96667. -219 162 10 239 182 13 246 186 14 246 190 14
  96668. -246 190 14 246 190 14 246 190 14 246 190 14
  96669. -246 190 14 246 190 14 246 190 14 246 190 14
  96670. -246 190 14 246 190 14 246 190 14 246 190 14
  96671. -246 186 14 236 178 12 224 166 10 142 122 72
  96672. - 46 46 46 18 18 18 6 6 6 0 0 0
  96673. - 0 0 0 0 0 0 0 0 0 0 0 0
  96674. - 0 0 0 0 0 0 0 0 0 0 0 0
  96675. - 0 0 0 0 0 0 6 6 6 18 18 18
  96676. - 50 50 50 109 106 95 192 133 9 224 166 10
  96677. -242 186 14 246 190 14 246 190 14 246 190 14
  96678. -246 190 14 246 190 14 246 190 14 246 190 14
  96679. -246 190 14 246 190 14 246 190 14 246 190 14
  96680. -246 190 14 246 190 14 246 190 14 246 190 14
  96681. -242 186 14 226 184 13 210 162 10 142 110 46
  96682. -226 226 226 253 253 253 253 253 253 253 253 253
  96683. -253 253 253 253 253 253 253 253 253 253 253 253
  96684. -253 253 253 253 253 253 253 253 253 253 253 253
  96685. -198 198 198 66 66 66 2 2 6 2 2 6
  96686. - 2 2 6 2 2 6 50 34 6 156 107 11
  96687. -219 162 10 239 182 13 246 186 14 246 190 14
  96688. -246 190 14 246 190 14 246 190 14 246 190 14
  96689. -246 190 14 246 190 14 246 190 14 246 190 14
  96690. -246 190 14 246 190 14 246 190 14 242 186 14
  96691. -234 174 13 213 154 11 154 122 46 66 66 66
  96692. - 30 30 30 10 10 10 0 0 0 0 0 0
  96693. - 0 0 0 0 0 0 0 0 0 0 0 0
  96694. - 0 0 0 0 0 0 0 0 0 0 0 0
  96695. - 0 0 0 0 0 0 6 6 6 22 22 22
  96696. - 58 58 58 154 121 60 206 145 10 234 174 13
  96697. -242 186 14 246 186 14 246 190 14 246 190 14
  96698. -246 190 14 246 190 14 246 190 14 246 190 14
  96699. -246 190 14 246 190 14 246 190 14 246 190 14
  96700. -246 190 14 246 190 14 246 190 14 246 190 14
  96701. -246 186 14 236 178 12 210 162 10 163 110 8
  96702. - 61 42 6 138 138 138 218 218 218 250 250 250
  96703. -253 253 253 253 253 253 253 253 253 250 250 250
  96704. -242 242 242 210 210 210 144 144 144 66 66 66
  96705. - 6 6 6 2 2 6 2 2 6 2 2 6
  96706. - 2 2 6 2 2 6 61 42 6 163 110 8
  96707. -216 158 10 236 178 12 246 190 14 246 190 14
  96708. -246 190 14 246 190 14 246 190 14 246 190 14
  96709. -246 190 14 246 190 14 246 190 14 246 190 14
  96710. -246 190 14 239 182 13 230 174 11 216 158 10
  96711. -190 142 34 124 112 88 70 70 70 38 38 38
  96712. - 18 18 18 6 6 6 0 0 0 0 0 0
  96713. - 0 0 0 0 0 0 0 0 0 0 0 0
  96714. - 0 0 0 0 0 0 0 0 0 0 0 0
  96715. - 0 0 0 0 0 0 6 6 6 22 22 22
  96716. - 62 62 62 168 124 44 206 145 10 224 166 10
  96717. -236 178 12 239 182 13 242 186 14 242 186 14
  96718. -246 186 14 246 190 14 246 190 14 246 190 14
  96719. -246 190 14 246 190 14 246 190 14 246 190 14
  96720. -246 190 14 246 190 14 246 190 14 246 190 14
  96721. -246 190 14 236 178 12 216 158 10 175 118 6
  96722. - 80 54 7 2 2 6 6 6 6 30 30 30
  96723. - 54 54 54 62 62 62 50 50 50 38 38 38
  96724. - 14 14 14 2 2 6 2 2 6 2 2 6
  96725. - 2 2 6 2 2 6 2 2 6 2 2 6
  96726. - 2 2 6 6 6 6 80 54 7 167 114 7
  96727. -213 154 11 236 178 12 246 190 14 246 190 14
  96728. -246 190 14 246 190 14 246 190 14 246 190 14
  96729. -246 190 14 242 186 14 239 182 13 239 182 13
  96730. -230 174 11 210 150 10 174 135 50 124 112 88
  96731. - 82 82 82 54 54 54 34 34 34 18 18 18
  96732. - 6 6 6 0 0 0 0 0 0 0 0 0
  96733. - 0 0 0 0 0 0 0 0 0 0 0 0
  96734. - 0 0 0 0 0 0 0 0 0 0 0 0
  96735. - 0 0 0 0 0 0 6 6 6 18 18 18
  96736. - 50 50 50 158 118 36 192 133 9 200 144 11
  96737. -216 158 10 219 162 10 224 166 10 226 170 11
  96738. -230 174 11 236 178 12 239 182 13 239 182 13
  96739. -242 186 14 246 186 14 246 190 14 246 190 14
  96740. -246 190 14 246 190 14 246 190 14 246 190 14
  96741. -246 186 14 230 174 11 210 150 10 163 110 8
  96742. -104 69 6 10 10 10 2 2 6 2 2 6
  96743. - 2 2 6 2 2 6 2 2 6 2 2 6
  96744. - 2 2 6 2 2 6 2 2 6 2 2 6
  96745. - 2 2 6 2 2 6 2 2 6 2 2 6
  96746. - 2 2 6 6 6 6 91 60 6 167 114 7
  96747. -206 145 10 230 174 11 242 186 14 246 190 14
  96748. -246 190 14 246 190 14 246 186 14 242 186 14
  96749. -239 182 13 230 174 11 224 166 10 213 154 11
  96750. -180 133 36 124 112 88 86 86 86 58 58 58
  96751. - 38 38 38 22 22 22 10 10 10 6 6 6
  96752. - 0 0 0 0 0 0 0 0 0 0 0 0
  96753. - 0 0 0 0 0 0 0 0 0 0 0 0
  96754. - 0 0 0 0 0 0 0 0 0 0 0 0
  96755. - 0 0 0 0 0 0 0 0 0 14 14 14
  96756. - 34 34 34 70 70 70 138 110 50 158 118 36
  96757. -167 114 7 180 123 7 192 133 9 197 138 11
  96758. -200 144 11 206 145 10 213 154 11 219 162 10
  96759. -224 166 10 230 174 11 239 182 13 242 186 14
  96760. -246 186 14 246 186 14 246 186 14 246 186 14
  96761. -239 182 13 216 158 10 185 133 11 152 99 6
  96762. -104 69 6 18 14 6 2 2 6 2 2 6
  96763. - 2 2 6 2 2 6 2 2 6 2 2 6
  96764. - 2 2 6 2 2 6 2 2 6 2 2 6
  96765. - 2 2 6 2 2 6 2 2 6 2 2 6
  96766. - 2 2 6 6 6 6 80 54 7 152 99 6
  96767. -192 133 9 219 162 10 236 178 12 239 182 13
  96768. -246 186 14 242 186 14 239 182 13 236 178 12
  96769. -224 166 10 206 145 10 192 133 9 154 121 60
  96770. - 94 94 94 62 62 62 42 42 42 22 22 22
  96771. - 14 14 14 6 6 6 0 0 0 0 0 0
  96772. - 0 0 0 0 0 0 0 0 0 0 0 0
  96773. - 0 0 0 0 0 0 0 0 0 0 0 0
  96774. - 0 0 0 0 0 0 0 0 0 0 0 0
  96775. - 0 0 0 0 0 0 0 0 0 6 6 6
  96776. - 18 18 18 34 34 34 58 58 58 78 78 78
  96777. -101 98 89 124 112 88 142 110 46 156 107 11
  96778. -163 110 8 167 114 7 175 118 6 180 123 7
  96779. -185 133 11 197 138 11 210 150 10 219 162 10
  96780. -226 170 11 236 178 12 236 178 12 234 174 13
  96781. -219 162 10 197 138 11 163 110 8 130 83 6
  96782. - 91 60 6 10 10 10 2 2 6 2 2 6
  96783. - 18 18 18 38 38 38 38 38 38 38 38 38
  96784. - 38 38 38 38 38 38 38 38 38 38 38 38
  96785. - 38 38 38 38 38 38 26 26 26 2 2 6
  96786. - 2 2 6 6 6 6 70 47 6 137 92 6
  96787. -175 118 6 200 144 11 219 162 10 230 174 11
  96788. -234 174 13 230 174 11 219 162 10 210 150 10
  96789. -192 133 9 163 110 8 124 112 88 82 82 82
  96790. - 50 50 50 30 30 30 14 14 14 6 6 6
  96791. - 0 0 0 0 0 0 0 0 0 0 0 0
  96792. - 0 0 0 0 0 0 0 0 0 0 0 0
  96793. - 0 0 0 0 0 0 0 0 0 0 0 0
  96794. - 0 0 0 0 0 0 0 0 0 0 0 0
  96795. - 0 0 0 0 0 0 0 0 0 0 0 0
  96796. - 6 6 6 14 14 14 22 22 22 34 34 34
  96797. - 42 42 42 58 58 58 74 74 74 86 86 86
  96798. -101 98 89 122 102 70 130 98 46 121 87 25
  96799. -137 92 6 152 99 6 163 110 8 180 123 7
  96800. -185 133 11 197 138 11 206 145 10 200 144 11
  96801. -180 123 7 156 107 11 130 83 6 104 69 6
  96802. - 50 34 6 54 54 54 110 110 110 101 98 89
  96803. - 86 86 86 82 82 82 78 78 78 78 78 78
  96804. - 78 78 78 78 78 78 78 78 78 78 78 78
  96805. - 78 78 78 82 82 82 86 86 86 94 94 94
  96806. -106 106 106 101 101 101 86 66 34 124 80 6
  96807. -156 107 11 180 123 7 192 133 9 200 144 11
  96808. -206 145 10 200 144 11 192 133 9 175 118 6
  96809. -139 102 15 109 106 95 70 70 70 42 42 42
  96810. - 22 22 22 10 10 10 0 0 0 0 0 0
  96811. - 0 0 0 0 0 0 0 0 0 0 0 0
  96812. - 0 0 0 0 0 0 0 0 0 0 0 0
  96813. - 0 0 0 0 0 0 0 0 0 0 0 0
  96814. - 0 0 0 0 0 0 0 0 0 0 0 0
  96815. - 0 0 0 0 0 0 0 0 0 0 0 0
  96816. - 0 0 0 0 0 0 6 6 6 10 10 10
  96817. - 14 14 14 22 22 22 30 30 30 38 38 38
  96818. - 50 50 50 62 62 62 74 74 74 90 90 90
  96819. -101 98 89 112 100 78 121 87 25 124 80 6
  96820. -137 92 6 152 99 6 152 99 6 152 99 6
  96821. -138 86 6 124 80 6 98 70 6 86 66 30
  96822. -101 98 89 82 82 82 58 58 58 46 46 46
  96823. - 38 38 38 34 34 34 34 34 34 34 34 34
  96824. - 34 34 34 34 34 34 34 34 34 34 34 34
  96825. - 34 34 34 34 34 34 38 38 38 42 42 42
  96826. - 54 54 54 82 82 82 94 86 76 91 60 6
  96827. -134 86 6 156 107 11 167 114 7 175 118 6
  96828. -175 118 6 167 114 7 152 99 6 121 87 25
  96829. -101 98 89 62 62 62 34 34 34 18 18 18
  96830. - 6 6 6 0 0 0 0 0 0 0 0 0
  96831. - 0 0 0 0 0 0 0 0 0 0 0 0
  96832. - 0 0 0 0 0 0 0 0 0 0 0 0
  96833. - 0 0 0 0 0 0 0 0 0 0 0 0
  96834. - 0 0 0 0 0 0 0 0 0 0 0 0
  96835. - 0 0 0 0 0 0 0 0 0 0 0 0
  96836. - 0 0 0 0 0 0 0 0 0 0 0 0
  96837. - 0 0 0 6 6 6 6 6 6 10 10 10
  96838. - 18 18 18 22 22 22 30 30 30 42 42 42
  96839. - 50 50 50 66 66 66 86 86 86 101 98 89
  96840. -106 86 58 98 70 6 104 69 6 104 69 6
  96841. -104 69 6 91 60 6 82 62 34 90 90 90
  96842. - 62 62 62 38 38 38 22 22 22 14 14 14
  96843. - 10 10 10 10 10 10 10 10 10 10 10 10
  96844. - 10 10 10 10 10 10 6 6 6 10 10 10
  96845. - 10 10 10 10 10 10 10 10 10 14 14 14
  96846. - 22 22 22 42 42 42 70 70 70 89 81 66
  96847. - 80 54 7 104 69 6 124 80 6 137 92 6
  96848. -134 86 6 116 81 8 100 82 52 86 86 86
  96849. - 58 58 58 30 30 30 14 14 14 6 6 6
  96850. - 0 0 0 0 0 0 0 0 0 0 0 0
  96851. - 0 0 0 0 0 0 0 0 0 0 0 0
  96852. - 0 0 0 0 0 0 0 0 0 0 0 0
  96853. - 0 0 0 0 0 0 0 0 0 0 0 0
  96854. - 0 0 0 0 0 0 0 0 0 0 0 0
  96855. - 0 0 0 0 0 0 0 0 0 0 0 0
  96856. - 0 0 0 0 0 0 0 0 0 0 0 0
  96857. - 0 0 0 0 0 0 0 0 0 0 0 0
  96858. - 0 0 0 6 6 6 10 10 10 14 14 14
  96859. - 18 18 18 26 26 26 38 38 38 54 54 54
  96860. - 70 70 70 86 86 86 94 86 76 89 81 66
  96861. - 89 81 66 86 86 86 74 74 74 50 50 50
  96862. - 30 30 30 14 14 14 6 6 6 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. - 6 6 6 18 18 18 34 34 34 58 58 58
  96867. - 82 82 82 89 81 66 89 81 66 89 81 66
  96868. - 94 86 66 94 86 76 74 74 74 50 50 50
  96869. - 26 26 26 14 14 14 6 6 6 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 0 0 0
  96872. - 0 0 0 0 0 0 0 0 0 0 0 0
  96873. - 0 0 0 0 0 0 0 0 0 0 0 0
  96874. - 0 0 0 0 0 0 0 0 0 0 0 0
  96875. - 0 0 0 0 0 0 0 0 0 0 0 0
  96876. - 0 0 0 0 0 0 0 0 0 0 0 0
  96877. - 0 0 0 0 0 0 0 0 0 0 0 0
  96878. - 0 0 0 0 0 0 0 0 0 0 0 0
  96879. - 6 6 6 6 6 6 14 14 14 18 18 18
  96880. - 30 30 30 38 38 38 46 46 46 54 54 54
  96881. - 50 50 50 42 42 42 30 30 30 18 18 18
  96882. - 10 10 10 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 0 0 0 0
  96886. - 0 0 0 6 6 6 14 14 14 26 26 26
  96887. - 38 38 38 50 50 50 58 58 58 58 58 58
  96888. - 54 54 54 42 42 42 30 30 30 18 18 18
  96889. - 10 10 10 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 0 0 0
  96892. - 0 0 0 0 0 0 0 0 0 0 0 0
  96893. - 0 0 0 0 0 0 0 0 0 0 0 0
  96894. - 0 0 0 0 0 0 0 0 0 0 0 0
  96895. - 0 0 0 0 0 0 0 0 0 0 0 0
  96896. - 0 0 0 0 0 0 0 0 0 0 0 0
  96897. - 0 0 0 0 0 0 0 0 0 0 0 0
  96898. - 0 0 0 0 0 0 0 0 0 0 0 0
  96899. - 0 0 0 0 0 0 0 0 0 6 6 6
  96900. - 6 6 6 10 10 10 14 14 14 18 18 18
  96901. - 18 18 18 14 14 14 10 10 10 6 6 6
  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 6 6 6
  96907. - 14 14 14 18 18 18 22 22 22 22 22 22
  96908. - 18 18 18 14 14 14 10 10 10 6 6 6
  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 0 0 0
  96912. - 0 0 0 0 0 0 0 0 0 0 0 0
  96913. - 0 0 0 0 0 0 0 0 0 0 0 0
  96914. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96915. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96916. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96917. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96918. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96919. +0 0 0 0 0 0 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 0 0 0 0 0 0
  96921. +0 0 0 0 0 0 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 0 0 0 0 0 0
  96923. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96924. +0 0 0 0 0 0 0 0 0
  96925. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96926. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96927. +0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 1 0
  96928. +0 1 0 0 0 0 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 0 0 0 0 0 0
  96930. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96931. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96932. +0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0
  96933. +0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96934. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96935. +0 0 0 0 0 0 0 0 0
  96936. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96937. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0
  96938. +10 15 3 2 3 1 12 18 4 42 61 14 19 27 6 11 16 4
  96939. +38 55 13 10 15 3 3 4 1 10 15 3 0 0 0 0 0 0
  96940. +0 0 0 0 0 0 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 0 0 0 0 0 0
  96942. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 3 1
  96943. +12 18 4 1 1 0 23 34 8 31 45 11 10 15 3 32 47 11
  96944. +34 49 12 3 4 1 3 4 1 3 4 1 0 0 0 0 0 0
  96945. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96946. +0 0 0 0 0 0 0 0 0
  96947. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96948. +0 0 0 0 0 0 10 15 3 29 42 10 26 37 9 12 18 4
  96949. +55 80 19 81 118 28 55 80 19 92 132 31 106 153 36 69 100 23
  96950. +100 144 34 80 116 27 42 61 14 81 118 28 23 34 8 27 40 9
  96951. +15 21 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96952. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96953. +0 0 0 0 0 0 1 1 0 29 42 10 15 21 5 50 72 17
  96954. +74 107 25 45 64 15 102 148 35 80 116 27 84 121 28 111 160 38
  96955. +69 100 23 65 94 22 81 118 28 29 42 10 17 25 6 29 42 10
  96956. +23 34 8 2 3 1 0 0 0 0 0 0 0 0 0 0 0 0
  96957. +0 0 0 0 0 0 0 0 0
  96958. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 4 1
  96959. +15 21 5 15 21 5 34 49 12 101 146 34 111 161 38 97 141 33
  96960. +97 141 33 119 172 41 117 170 40 116 167 40 118 170 40 118 171 40
  96961. +117 169 40 118 170 40 111 160 38 118 170 40 96 138 32 89 128 30
  96962. +81 118 28 11 16 4 10 15 3 1 1 0 0 0 0 0 0 0
  96963. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96964. +3 4 1 3 4 1 34 49 12 101 146 34 79 115 27 111 160 38
  96965. +114 165 39 113 163 39 118 170 40 117 169 40 118 171 40 117 169 40
  96966. +116 167 40 119 172 41 113 163 39 92 132 31 105 151 36 113 163 39
  96967. +75 109 26 19 27 6 16 23 5 11 16 4 0 1 0 0 0 0
  96968. +0 0 0 0 0 0 0 0 0
  96969. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 15 3
  96970. +80 116 27 106 153 36 105 151 36 114 165 39 118 170 40 118 171 40
  96971. +118 171 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  96972. +117 169 40 117 169 40 117 170 40 117 169 40 118 170 40 118 170 40
  96973. +117 170 40 75 109 26 75 109 26 34 49 12 0 0 0 0 0 0
  96974. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 4 1
  96975. +64 92 22 65 94 22 100 144 34 118 171 40 118 170 40 117 169 40
  96976. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  96977. +117 169 40 117 169 40 117 169 40 118 171 41 118 170 40 117 169 40
  96978. +109 158 37 105 151 36 104 150 35 47 69 16 0 0 0 0 0 0
  96979. +0 0 0 0 0 0 0 0 0
  96980. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96981. +42 61 14 115 167 39 118 170 40 117 169 40 117 169 40 117 169 40
  96982. +117 170 40 117 170 40 117 169 40 117 169 40 117 169 40 117 169 40
  96983. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  96984. +117 169 40 117 169 40 118 170 40 96 138 32 17 25 6 0 0 0
  96985. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 47 69 16
  96986. +114 165 39 117 168 40 117 170 40 117 169 40 117 169 40 117 169 40
  96987. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  96988. +117 169 40 117 169 40 118 170 40 117 169 40 117 169 40 117 169 40
  96989. +117 170 40 119 172 41 96 138 32 12 18 4 0 0 0 0 0 0
  96990. +0 0 0 0 0 0 0 0 0
  96991. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 15 3
  96992. +32 47 11 105 151 36 118 170 40 117 169 40 117 169 40 116 168 40
  96993. +109 157 37 111 160 38 117 169 40 118 171 40 117 169 40 117 169 40
  96994. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  96995. +117 169 40 117 169 40 117 169 40 118 171 40 69 100 23 2 3 1
  96996. +0 0 0 0 0 0 0 0 0 0 0 0 19 27 6 101 146 34
  96997. +118 171 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  96998. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 170 40
  96999. +118 171 40 115 166 39 107 154 36 111 161 38 117 169 40 117 169 40
  97000. +117 169 40 118 171 40 75 109 26 19 27 6 2 3 1 0 0 0
  97001. +0 0 0 0 0 0 0 0 0
  97002. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 16 23 5
  97003. +89 128 30 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  97004. +111 160 38 92 132 31 79 115 27 96 138 32 115 166 39 119 171 41
  97005. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  97006. +117 169 40 117 169 40 117 169 40 118 170 40 109 157 37 26 37 9
  97007. +0 0 0 0 0 0 0 0 0 0 0 0 64 92 22 118 171 40
  97008. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  97009. +117 169 40 117 169 40 117 169 40 118 170 40 118 171 40 109 157 37
  97010. +89 128 30 81 118 28 100 144 34 115 166 39 117 169 40 117 169 40
  97011. +117 169 40 117 170 40 113 163 39 60 86 20 1 1 0 0 0 0
  97012. +0 0 0 0 0 0 0 0 0
  97013. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97014. +27 40 9 96 138 32 118 170 40 117 169 40 117 169 40 117 169 40
  97015. +117 170 40 117 169 40 101 146 34 67 96 23 55 80 19 84 121 28
  97016. +113 163 39 119 171 41 117 169 40 117 169 40 117 169 40 117 169 40
  97017. +117 169 40 117 169 40 117 169 40 117 169 40 119 171 41 65 94 22
  97018. +0 0 0 0 0 0 0 0 0 15 21 5 101 146 34 118 171 40
  97019. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  97020. +117 169 40 118 170 40 118 171 40 104 150 35 69 100 23 53 76 18
  97021. +81 118 28 111 160 38 118 170 40 117 169 40 117 169 40 117 169 40
  97022. +117 169 40 114 165 39 69 100 23 10 15 3 0 0 0 0 0 0
  97023. +0 0 0 0 0 0 0 0 0
  97024. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0
  97025. +31 45 11 77 111 26 117 169 40 117 169 40 117 169 40 117 169 40
  97026. +117 169 40 117 169 40 118 170 40 116 168 40 92 132 31 47 69 16
  97027. +38 55 13 81 118 28 113 163 39 119 171 41 117 169 40 117 169 40
  97028. +117 169 40 117 169 40 117 169 40 117 169 40 118 171 41 92 132 31
  97029. +10 15 3 0 0 0 0 0 0 36 52 12 115 166 39 117 169 40
  97030. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 118 170 40
  97031. +118 171 40 102 148 35 64 92 22 34 49 12 65 94 22 106 153 36
  97032. +118 171 40 117 170 40 117 169 40 117 169 40 117 169 40 117 169 40
  97033. +118 170 40 107 154 36 55 80 19 15 21 5 0 0 0 0 0 0
  97034. +0 0 0 0 0 0 0 0 0
  97035. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97036. +29 42 10 101 146 34 118 171 40 117 169 40 117 169 40 117 169 40
  97037. +117 169 40 117 169 40 117 169 40 117 169 40 118 171 40 113 163 39
  97038. +75 109 26 27 40 9 36 52 12 89 128 30 116 167 40 118 171 40
  97039. +117 169 40 117 169 40 117 169 40 117 169 40 118 170 40 104 150 35
  97040. +16 23 5 0 0 0 0 0 0 53 76 18 118 171 40 117 169 40
  97041. +117 169 40 117 169 40 117 169 40 117 169 40 119 171 41 109 157 37
  97042. +67 96 23 23 34 8 42 61 14 96 138 32 118 170 40 118 170 40
  97043. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  97044. +117 169 40 117 169 40 74 107 25 10 15 3 0 0 0 0 0 0
  97045. +0 0 0 0 0 0 0 0 0
  97046. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97047. +0 0 0 31 45 11 101 146 34 118 170 40 117 169 40 117 169 40
  97048. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  97049. +119 171 41 102 148 35 47 69 16 14 20 5 50 72 17 102 148 35
  97050. +118 171 40 117 169 40 117 169 40 117 169 40 118 170 40 102 148 35
  97051. +15 21 5 0 0 0 0 0 0 50 72 17 118 170 40 117 169 40
  97052. +117 169 40 117 169 40 118 170 40 116 167 40 84 121 28 27 40 9
  97053. +19 27 6 74 107 25 114 165 39 118 171 40 117 169 40 117 169 40
  97054. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  97055. +117 169 40 75 109 26 10 15 4 0 0 0 0 0 0 0 0 0
  97056. +0 0 0 0 0 0 0 0 0
  97057. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97058. +0 0 0 38 55 13 102 148 35 118 171 40 117 169 40 117 169 40
  97059. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  97060. +117 169 40 118 170 40 115 167 39 77 111 26 17 25 6 19 27 6
  97061. +77 111 26 115 166 39 118 170 40 117 169 40 119 172 41 81 118 28
  97062. +3 4 1 0 0 0 0 0 0 27 40 9 111 160 38 118 170 40
  97063. +117 169 40 118 171 40 105 151 36 50 72 17 10 15 3 38 55 13
  97064. +100 144 34 118 171 40 117 169 40 117 169 40 117 169 40 117 169 40
  97065. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  97066. +117 169 40 79 115 27 15 21 5 0 0 0 0 0 0 0 0 0
  97067. +0 0 0 0 0 0 0 0 0
  97068. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97069. +0 0 0 10 15 3 64 92 22 111 160 38 117 169 40 117 169 40
  97070. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  97071. +117 169 40 117 169 40 117 169 40 118 171 40 96 138 32 32 47 11
  97072. +3 4 1 50 72 17 107 154 36 120 173 41 105 151 36 31 45 11
  97073. +0 0 0 0 0 0 0 0 0 3 4 1 65 94 22 117 169 40
  97074. +118 170 40 89 128 30 26 37 9 3 4 1 60 86 20 111 161 38
  97075. +118 171 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  97076. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  97077. +97 141 33 36 52 12 1 1 0 0 0 0 0 0 0 0 0 0
  97078. +0 0 0 0 0 0 0 0 0
  97079. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97080. +0 0 0 0 0 0 14 20 5 75 109 26 117 168 40 117 169 40
  97081. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  97082. +117 169 40 117 169 40 117 169 40 117 169 40 118 171 40 107 154 36
  97083. +45 64 15 2 3 1 31 45 11 75 109 26 32 47 11 0 1 0
  97084. +0 0 0 0 0 0 0 0 0 0 0 0 10 15 3 55 80 19
  97085. +65 94 22 11 16 4 11 16 4 75 109 26 116 168 40 118 170 40
  97086. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  97087. +117 169 40 117 169 40 117 169 40 117 169 40 118 170 40 107 154 36
  97088. +47 69 16 3 4 1 0 0 0 0 0 0 0 0 0 0 0 0
  97089. +0 0 0 0 0 0 0 0 0
  97090. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97091. +0 0 0 0 0 0 12 18 4 69 100 23 111 161 38 118 171 40
  97092. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  97093. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 118 170 40
  97094. +111 160 38 50 72 17 2 3 1 2 3 1 0 0 0 0 0 0
  97095. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0
  97096. +1 1 0 12 18 4 81 118 28 118 170 40 117 169 40 117 169 40
  97097. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  97098. +117 169 40 117 169 40 117 169 40 117 170 40 118 171 40 101 146 34
  97099. +42 61 14 2 3 1 0 0 0 0 0 0 0 0 0 0 0 0
  97100. +0 0 0 0 0 0 0 0 0
  97101. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97102. +0 0 0 0 0 0 0 0 0 3 4 1 36 52 12 89 128 30
  97103. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  97104. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  97105. +118 171 41 101 146 34 14 20 5 0 0 0 0 0 0 0 0 0
  97106. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97107. +0 0 0 47 69 16 118 170 40 117 169 40 117 169 40 117 169 40
  97108. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  97109. +117 169 40 117 169 40 117 170 40 111 160 38 69 100 23 19 27 6
  97110. +0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97111. +0 0 0 0 0 0 0 0 0
  97112. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97113. +0 0 0 0 0 0 0 0 0 0 0 0 11 16 4 69 100 23
  97114. +115 167 39 119 172 41 117 169 40 117 169 40 117 169 40 117 169 40
  97115. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  97116. +119 172 41 75 109 26 3 4 1 0 0 0 0 0 0 0 0 0
  97117. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97118. +0 0 0 23 34 8 106 153 36 118 170 40 117 169 40 117 169 40
  97119. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  97120. +117 169 40 118 170 40 119 172 41 105 151 36 42 61 14 2 3 1
  97121. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97122. +0 0 0 0 0 0 0 0 0
  97123. +0 0 0 0 0 0 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 1 1 0 15 21 5
  97125. +45 64 15 80 116 27 114 165 39 118 170 40 117 169 40 117 169 40
  97126. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 119 172 41
  97127. +97 141 33 20 30 7 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 0 0 0 0 0 0
  97129. +0 0 0 1 1 0 53 76 18 114 165 39 118 171 40 117 169 40
  97130. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  97131. +118 171 40 104 150 35 64 92 22 31 45 11 10 15 3 0 0 0
  97132. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97133. +0 0 0 0 0 0 0 0 0
  97134. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97135. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97136. +0 0 0 36 52 12 97 141 33 109 158 37 113 163 39 116 168 40
  97137. +117 169 40 117 170 40 118 170 40 119 172 41 115 167 39 84 121 28
  97138. +23 34 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97139. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97140. +0 0 0 0 0 0 3 4 1 50 72 17 102 148 35 118 171 40
  97141. +119 171 41 118 170 40 117 169 40 117 169 40 115 166 39 111 161 38
  97142. +109 157 37 79 115 27 12 18 4 0 0 0 0 0 0 0 0 0
  97143. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97144. +0 0 0 0 0 0 0 0 0
  97145. +0 0 0 0 0 0 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 0 0 0 0 0 0
  97147. +0 0 0 3 4 1 15 21 5 23 34 8 45 64 15 106 153 36
  97148. +116 167 40 111 160 38 101 146 34 79 115 27 42 61 14 10 15 3
  97149. +0 0 0 0 0 0 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 0 0 0 0 0 0
  97151. +0 0 0 0 0 0 0 0 0 1 1 0 20 30 7 60 86 20
  97152. +89 128 30 106 153 36 113 163 39 117 169 40 84 121 28 29 42 10
  97153. +19 27 6 10 15 3 2 3 1 0 0 0 0 0 0 0 0 0
  97154. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97155. +0 0 0 0 0 0 0 0 0
  97156. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97157. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97158. +0 0 0 0 0 0 0 0 0 0 0 0 16 23 5 38 55 13
  97159. +36 52 12 26 37 9 12 18 4 2 3 1 0 0 0 0 0 0
  97160. +0 0 0 0 0 0 0 0 0 1 0 0 19 2 7 52 5 18
  97161. +78 7 27 88 8 31 81 7 29 56 5 19 25 2 9 3 0 1
  97162. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97163. +3 4 1 19 27 6 31 45 11 38 55 13 32 47 11 3 4 1
  97164. +0 0 0 0 0 0 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 0 0 0 0 0 0
  97166. +0 0 0 0 0 0 0 0 0
  97167. +0 0 0 0 0 0 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 0 0 0 0 0 0
  97169. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 1
  97170. +9 0 3 12 1 4 9 0 3 4 0 1 0 0 0 0 0 0
  97171. +0 0 0 0 0 0 28 3 10 99 9 35 156 14 55 182 16 64
  97172. +189 17 66 190 17 67 189 17 66 184 17 65 166 15 58 118 13 41
  97173. +45 4 16 3 0 1 0 0 0 0 0 0 0 0 0 0 0 0
  97174. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97175. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97176. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97177. +0 0 0 0 0 0 0 0 0
  97178. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97179. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97180. +0 0 0 0 0 0 11 1 4 52 5 18 101 9 35 134 12 47
  97181. +151 14 53 154 14 54 151 14 53 113 10 40 11 1 4 0 0 0
  97182. +3 0 1 67 6 24 159 14 56 190 17 67 190 17 67 188 17 66
  97183. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 191 17 67
  97184. +174 16 61 101 9 35 14 1 5 0 0 0 35 3 12 108 10 38
  97185. +122 11 43 122 11 43 112 10 39 87 8 30 50 5 17 13 1 5
  97186. +0 0 0 0 0 0 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 0 0 0 0 0 0
  97188. +0 0 0 0 0 0 0 0 0
  97189. +0 0 0 0 0 0 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 0 0 0 0 0 0
  97191. +3 0 1 56 5 19 141 13 49 182 16 64 191 17 67 191 17 67
  97192. +190 17 67 190 17 67 191 17 67 113 10 40 3 0 1 1 0 0
  97193. +79 7 28 180 16 63 190 17 67 188 17 66 188 17 66 188 17 66
  97194. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97195. +189 17 66 188 17 66 122 11 43 11 1 4 41 4 14 176 16 62
  97196. +191 17 67 191 17 67 191 17 67 190 17 67 181 16 63 146 13 51
  97197. +75 7 26 10 1 4 0 0 0 0 0 0 0 0 0 0 0 0
  97198. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97199. +0 0 0 0 0 0 0 0 0
  97200. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97201. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 1 2
  97202. +90 8 32 178 16 62 191 17 67 188 17 66 188 17 66 188 17 66
  97203. +188 17 66 190 17 67 141 13 49 22 2 8 0 0 0 41 4 14
  97204. +173 16 61 190 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  97205. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97206. +188 17 66 188 17 66 188 17 66 88 8 31 1 0 0 89 8 31
  97207. +185 17 65 189 17 66 188 17 66 188 17 66 189 17 66 191 17 67
  97208. +186 17 65 124 11 43 25 2 9 0 0 0 0 0 0 0 0 0
  97209. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97210. +0 0 0 0 0 0 0 0 0
  97211. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97212. +0 0 0 0 0 0 0 0 0 0 0 0 2 0 1 89 8 31
  97213. +184 17 65 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97214. +190 17 67 151 14 53 34 3 12 0 0 0 0 0 0 79 7 28
  97215. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97216. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97217. +188 17 66 188 17 66 191 17 67 146 13 51 9 1 3 7 1 2
  97218. +108 10 38 187 17 66 189 17 66 188 17 66 188 17 66 188 17 66
  97219. +188 17 66 190 17 67 141 13 49 22 2 8 0 0 0 0 0 0
  97220. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97221. +0 0 0 0 0 0 0 0 0
  97222. +0 0 0 0 0 0 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 52 5 18 176 16 62
  97224. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  97225. +151 14 53 38 3 13 0 0 0 0 0 0 0 0 0 50 5 17
  97226. +180 16 63 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97227. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97228. +188 17 66 188 17 66 191 17 67 141 13 49 7 1 3 0 0 0
  97229. +11 1 4 112 10 39 187 17 66 189 17 66 188 17 66 188 17 66
  97230. +188 17 66 188 17 66 190 17 67 113 10 40 5 0 2 0 0 0
  97231. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97232. +0 0 0 0 0 0 0 0 0
  97233. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97234. +0 0 0 0 0 0 0 0 0 7 1 3 132 12 46 191 17 67
  97235. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 146 13 51
  97236. +35 3 12 0 0 0 0 0 0 0 0 0 0 0 0 5 0 2
  97237. +101 9 35 185 17 65 190 17 67 188 17 66 188 17 66 188 17 66
  97238. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97239. +188 17 66 190 17 67 180 16 63 67 6 24 0 0 0 0 0 0
  97240. +0 0 0 11 1 4 108 10 38 186 17 65 189 17 66 188 17 66
  97241. +188 17 66 188 17 66 189 17 66 180 16 63 56 5 19 0 0 0
  97242. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97243. +0 0 0 0 0 0 0 0 0
  97244. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97245. +0 0 0 0 0 0 0 0 0 44 4 15 177 16 62 189 17 66
  97246. +188 17 66 188 17 66 189 17 66 189 17 66 134 12 47 28 3 10
  97247. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97248. +8 1 3 79 7 28 159 14 56 188 17 66 191 17 67 190 17 67
  97249. +189 17 66 189 17 66 189 17 66 189 17 66 190 17 67 191 17 67
  97250. +188 17 66 158 14 55 72 7 25 4 0 1 0 0 0 0 0 0
  97251. +0 0 0 0 0 0 8 1 3 95 9 33 182 16 64 189 17 67
  97252. +188 17 66 188 17 66 188 17 66 191 17 67 122 11 43 3 0 1
  97253. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97254. +0 0 0 0 0 0 0 0 0
  97255. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97256. +0 0 0 0 0 0 0 0 0 88 8 31 190 17 67 188 17 66
  97257. +188 17 66 189 17 66 185 17 65 113 10 40 18 2 6 0 0 0
  97258. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97259. +0 0 0 1 0 0 24 2 8 77 7 27 124 11 43 154 14 54
  97260. +168 15 59 173 16 61 173 16 61 168 15 59 154 14 54 124 11 43
  97261. +77 7 27 22 2 8 0 0 0 0 0 0 0 0 0 0 0 0
  97262. +0 0 0 0 0 0 0 0 0 5 0 2 77 7 27 173 16 61
  97263. +190 17 67 188 17 66 188 17 66 190 17 67 164 15 57 23 2 8
  97264. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97265. +0 0 0 0 0 0 0 0 0
  97266. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97267. +0 0 0 0 0 0 1 0 0 118 13 41 191 17 67 188 17 66
  97268. +190 17 67 174 16 61 87 8 30 8 1 3 0 0 0 0 0 0
  97269. +0 0 0 0 0 0 10 1 4 29 3 10 40 4 14 36 3 13
  97270. +18 2 6 2 0 1 0 0 0 0 0 0 3 0 1 14 1 5
  97271. +26 2 9 33 3 11 32 3 11 25 2 9 13 1 5 3 0 1
  97272. +0 0 0 14 1 5 56 5 19 95 9 33 109 10 38 101 9 35
  97273. +77 7 27 35 3 12 5 0 2 0 0 0 1 0 0 56 5 19
  97274. +156 14 55 190 17 67 188 17 66 188 17 66 182 16 64 50 5 17
  97275. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97276. +0 0 0 0 0 0 0 0 0
  97277. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97278. +0 0 0 0 0 0 5 0 2 134 12 47 191 17 67 189 17 66
  97279. +151 14 53 52 5 18 2 0 1 0 0 0 0 0 0 1 0 0
  97280. +28 3 10 90 8 32 146 13 51 170 15 60 178 16 62 174 16 61
  97281. +158 14 55 112 10 39 40 4 14 1 0 0 0 0 0 0 0 0
  97282. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 1
  97283. +56 5 19 146 13 51 183 17 64 191 17 67 191 17 67 191 17 67
  97284. +188 17 66 173 16 61 122 11 43 41 4 14 1 0 0 0 0 0
  97285. +30 3 10 124 11 43 185 17 65 190 17 67 187 17 66 67 6 24
  97286. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97287. +0 0 0 0 0 0 0 0 0
  97288. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97289. +0 0 0 0 0 0 6 1 2 134 12 47 168 15 59 99 9 35
  97290. +21 2 7 0 0 0 0 0 0 0 0 0 6 1 2 77 7 27
  97291. +162 15 57 190 17 67 191 17 67 189 17 66 189 17 66 189 17 66
  97292. +190 17 67 191 17 67 169 15 59 75 7 26 3 0 1 0 0 0
  97293. +0 0 0 0 0 0 0 0 0 0 0 0 2 0 1 79 7 28
  97294. +178 16 62 191 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  97295. +188 17 66 189 17 66 191 17 67 170 15 60 79 7 28 5 0 2
  97296. +0 0 0 10 1 3 78 7 27 159 14 56 188 17 66 75 7 26
  97297. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97298. +0 0 0 0 0 0 0 0 0
  97299. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97300. +0 0 0 0 0 0 1 0 0 35 3 12 29 3 10 2 0 1
  97301. +0 0 0 0 0 0 0 0 0 9 1 3 101 9 35 183 17 64
  97302. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97303. +188 17 66 188 17 66 190 17 67 178 16 63 67 6 23 0 0 0
  97304. +0 0 0 0 0 0 0 0 0 0 0 0 52 5 18 174 16 61
  97305. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97306. +188 17 66 188 17 66 188 17 66 190 17 67 182 16 64 89 8 31
  97307. +4 0 1 0 0 0 0 0 0 25 2 9 73 7 26 31 3 11
  97308. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97309. +0 0 0 0 0 0 0 0 0
  97310. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97311. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97312. +0 0 0 0 0 0 4 0 1 98 9 34 187 17 66 189 17 66
  97313. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97314. +188 17 66 188 17 66 188 17 66 190 17 67 158 14 55 25 2 9
  97315. +0 0 0 0 0 0 0 0 0 8 1 3 134 12 47 191 17 67
  97316. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97317. +188 17 66 188 17 66 188 17 66 188 17 66 189 17 66 180 16 63
  97318. +68 6 24 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97319. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97320. +0 0 0 0 0 0 0 0 0
  97321. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97322. +0 0 0 6 1 2 19 2 7 3 0 1 0 0 0 0 0 0
  97323. +0 0 0 0 0 0 65 6 23 180 16 63 189 17 66 188 17 66
  97324. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97325. +188 17 66 188 17 66 188 17 66 188 17 66 189 17 66 83 8 29
  97326. +0 0 0 0 0 0 0 0 0 41 4 14 177 16 62 189 17 66
  97327. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97328. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  97329. +159 14 56 28 3 10 0 0 0 0 0 0 0 0 0 23 2 8
  97330. +41 4 14 5 0 2 0 0 0 0 0 0 0 0 0 0 0 0
  97331. +0 0 0 0 0 0 0 0 0
  97332. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97333. +23 2 8 113 10 40 159 14 56 65 6 23 0 0 0 0 0 0
  97334. +0 0 0 16 1 6 146 13 51 191 17 67 188 17 66 188 17 66
  97335. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97336. +188 17 66 188 17 66 188 17 66 188 17 66 191 17 67 132 12 46
  97337. +5 0 2 0 0 0 0 0 0 77 7 27 189 17 66 188 17 66
  97338. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97339. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97340. +190 17 67 98 9 34 0 0 0 0 0 0 12 1 4 134 12 47
  97341. +178 16 63 108 10 38 16 1 6 0 0 0 0 0 0 0 0 0
  97342. +0 0 0 0 0 0 0 0 0
  97343. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 30 3 10
  97344. +141 13 49 190 17 67 191 17 67 134 12 47 6 1 2 0 0 0
  97345. +0 0 0 68 6 24 186 17 65 188 17 66 188 17 66 188 17 66
  97346. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97347. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 156 14 55
  97348. +14 1 5 0 0 0 0 0 0 98 9 34 191 17 67 188 17 66
  97349. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97350. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97351. +190 17 67 156 14 55 19 2 7 0 0 0 47 4 16 181 16 63
  97352. +190 17 67 189 17 66 126 14 44 17 2 6 0 0 0 0 0 0
  97353. +0 0 0 0 0 0 0 0 0
  97354. +0 0 0 0 0 0 0 0 0 0 0 0 16 1 6 134 12 47
  97355. +191 17 67 188 17 66 190 17 67 162 15 57 19 2 7 0 0 0
  97356. +3 0 1 123 11 43 191 17 67 188 17 66 188 17 66 188 17 66
  97357. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97358. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 163 15 57
  97359. +20 2 7 0 0 0 0 0 0 101 9 35 191 17 67 188 17 66
  97360. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97361. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97362. +188 17 66 182 16 64 52 5 18 0 0 0 73 7 26 188 17 66
  97363. +188 17 66 188 17 66 189 17 66 109 10 38 5 0 2 0 0 0
  97364. +0 0 0 0 0 0 0 0 0
  97365. +0 0 0 0 0 0 0 0 0 0 0 0 95 9 33 189 17 66
  97366. +188 17 66 188 17 66 189 17 66 171 15 60 29 3 10 0 0 0
  97367. +16 1 6 156 14 55 190 17 67 188 17 66 188 17 66 188 17 66
  97368. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97369. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 158 14 55
  97370. +17 2 6 0 0 0 0 0 0 85 8 30 190 17 67 188 17 66
  97371. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97372. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97373. +188 17 66 189 17 66 81 7 29 0 0 0 85 8 30 190 17 67
  97374. +188 17 66 188 17 66 189 17 66 180 16 63 56 5 19 0 0 0
  97375. +0 0 0 0 0 0 0 0 0
  97376. +0 0 0 0 0 0 0 0 0 25 2 9 162 15 57 190 17 67
  97377. +188 17 66 188 17 66 189 17 66 173 16 61 31 3 11 0 0 0
  97378. +30 3 10 171 15 60 189 17 66 188 17 66 188 17 66 188 17 66
  97379. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97380. +188 17 66 188 17 66 188 17 66 188 17 66 191 17 67 141 13 49
  97381. +7 1 2 0 0 0 0 0 0 56 5 19 183 17 64 188 17 66
  97382. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97383. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97384. +188 17 66 191 17 67 98 9 34 0 0 0 88 8 31 190 17 67
  97385. +188 17 66 188 17 66 188 17 66 191 17 67 124 11 43 5 0 2
  97386. +0 0 0 0 0 0 0 0 0
  97387. +0 0 0 0 0 0 0 0 0 68 6 24 187 17 66 188 17 66
  97388. +188 17 66 188 17 66 189 17 66 170 15 60 28 3 10 0 0 0
  97389. +34 3 12 174 16 61 189 17 66 188 17 66 188 17 66 188 17 66
  97390. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97391. +188 17 66 188 17 66 188 17 66 188 17 66 191 17 67 101 9 35
  97392. +0 0 0 0 0 0 0 0 0 21 2 7 159 14 56 190 17 67
  97393. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97394. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97395. +188 17 66 191 17 67 98 9 34 0 0 0 81 7 29 189 17 66
  97396. +188 17 66 188 17 66 188 17 66 189 17 66 168 15 59 28 3 10
  97397. +0 0 0 0 0 0 0 0 0
  97398. +0 0 0 0 0 0 0 0 0 109 10 38 191 17 67 188 17 66
  97399. +188 17 66 188 17 66 190 17 67 163 15 57 21 2 7 0 0 0
  97400. +26 2 9 168 15 59 189 17 66 188 17 66 188 17 66 188 17 66
  97401. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97402. +188 17 66 188 17 66 188 17 66 189 17 66 180 16 63 47 4 16
  97403. +0 0 0 0 0 0 0 0 0 0 0 0 108 10 38 190 17 67
  97404. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97405. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97406. +188 17 66 189 17 66 78 7 27 0 0 0 68 6 24 187 17 66
  97407. +188 17 66 188 17 66 188 17 66 188 17 66 183 17 64 56 5 19
  97408. +0 0 0 0 0 0 0 0 0
  97409. +0 0 0 0 0 0 3 0 1 131 12 46 191 17 67 188 17 66
  97410. +188 17 66 188 17 66 190 17 67 151 14 53 12 1 4 0 0 0
  97411. +11 1 4 146 13 51 190 17 67 188 17 66 188 17 66 188 17 66
  97412. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97413. +188 17 66 188 17 66 188 17 66 191 17 67 126 14 44 7 1 2
  97414. +0 0 0 0 0 0 0 0 0 0 0 0 32 3 11 164 15 58
  97415. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97416. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97417. +189 17 66 178 16 62 44 4 15 0 0 0 50 5 17 182 16 64
  97418. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 72 7 25
  97419. +0 0 0 0 0 0 0 0 0
  97420. +0 0 0 0 0 0 5 0 2 134 12 47 191 17 67 188 17 66
  97421. +188 17 66 188 17 66 191 17 67 131 12 46 3 0 1 0 0 0
  97422. +0 0 0 101 9 35 190 17 67 188 17 66 188 17 66 188 17 66
  97423. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97424. +188 17 66 188 17 66 190 17 67 170 15 60 44 4 15 0 0 0
  97425. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 77 7 27
  97426. +183 17 64 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97427. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97428. +191 17 67 134 12 47 9 1 3 0 0 0 31 3 11 171 15 60
  97429. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 72 7 25
  97430. +0 0 0 0 0 0 0 0 0
  97431. +0 0 0 0 0 0 2 0 1 124 11 43 191 17 67 188 17 66
  97432. +188 17 66 188 17 66 191 17 67 101 9 35 0 0 0 0 0 0
  97433. +0 0 0 35 3 12 168 15 59 190 17 67 188 17 66 188 17 66
  97434. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97435. +188 17 66 189 17 66 182 16 64 77 7 27 0 0 0 0 0 0
  97436. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 1 2
  97437. +99 9 35 185 17 65 189 17 66 188 17 66 188 17 66 188 17 66
  97438. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 189 17 66
  97439. +177 16 62 56 5 19 0 0 0 0 0 0 13 1 5 151 14 53
  97440. +190 17 67 188 17 66 188 17 66 188 17 66 185 17 65 56 5 19
  97441. +0 0 0 0 0 0 0 0 0
  97442. +0 0 0 0 0 0 0 0 0 99 9 35 191 17 67 188 17 66
  97443. +188 17 66 188 17 66 186 17 65 65 6 23 0 0 0 0 0 0
  97444. +0 0 0 0 0 0 79 7 28 182 16 64 190 17 67 188 17 66
  97445. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97446. +191 17 67 177 16 62 83 8 29 4 0 1 0 0 0 0 0 0
  97447. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97448. +8 1 3 89 8 31 175 16 62 191 17 67 189 17 66 188 17 66
  97449. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 181 16 63
  97450. +85 8 30 3 0 1 0 0 0 0 0 0 1 0 0 118 13 41
  97451. +191 17 67 188 17 66 188 17 66 189 17 66 173 16 61 34 3 12
  97452. +0 0 0 0 0 0 0 0 0
  97453. +0 0 0 0 0 0 0 0 0 56 5 19 183 17 64 188 17 66
  97454. +188 17 66 189 17 66 169 15 59 30 3 10 0 0 0 0 0 0
  97455. +0 0 0 0 0 0 5 0 2 83 8 29 173 16 61 191 17 67
  97456. +190 17 67 189 17 66 189 17 66 190 17 67 191 17 67 187 17 66
  97457. +151 14 53 56 5 19 3 0 1 0 0 0 16 1 6 50 5 17
  97458. +79 7 28 95 9 33 95 9 33 75 7 26 41 4 14 10 1 4
  97459. +0 0 0 2 0 1 50 5 17 132 12 46 178 16 62 190 17 67
  97460. +191 17 67 191 17 67 191 17 67 186 17 65 154 14 54 68 6 24
  97461. +4 0 1 0 0 0 0 0 0 0 0 0 0 0 0 72 7 25
  97462. +187 17 66 188 17 66 188 17 66 191 17 67 141 13 49 9 1 3
  97463. +0 0 0 0 0 0 0 0 0
  97464. +0 0 0 0 0 0 0 0 0 14 1 5 151 14 53 190 17 67
  97465. +188 17 66 191 17 67 131 12 46 5 0 2 0 0 0 0 0 0
  97466. +0 0 0 0 0 0 0 0 0 2 0 1 44 4 15 113 10 40
  97467. +156 14 55 173 16 61 174 16 61 164 15 58 134 12 47 77 7 27
  97468. +18 2 6 0 0 0 16 1 6 85 8 30 151 14 53 182 16 64
  97469. +189 17 66 191 17 67 190 17 67 188 17 66 177 16 62 141 13 49
  97470. +68 6 24 8 1 3 0 0 0 8 1 3 44 4 15 88 8 31
  97471. +113 10 40 122 11 43 108 10 38 67 6 24 20 2 7 0 0 0
  97472. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 28 3 10
  97473. +166 15 58 190 17 67 188 17 66 187 17 66 79 7 28 0 0 0
  97474. +0 0 0 0 0 0 0 0 0
  97475. +0 0 0 0 0 0 0 0 0 0 0 0 73 7 26 185 17 65
  97476. +189 17 66 184 17 65 65 6 23 0 0 0 0 0 0 0 0 0
  97477. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 1
  97478. +17 2 6 32 3 11 34 3 12 22 2 8 6 1 2 0 0 0
  97479. +0 0 0 38 3 13 141 13 49 188 17 66 190 17 67 188 17 66
  97480. +188 17 66 188 17 66 188 17 66 188 17 66 189 17 66 191 17 67
  97481. +184 17 65 122 11 43 21 2 7 0 0 0 0 0 0 0 0 0
  97482. +0 0 0 1 0 0 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 0 0 0 1 0 0
  97484. +108 10 38 191 17 67 191 17 67 141 13 49 16 1 6 0 0 0
  97485. +0 0 0 0 0 0 0 0 0
  97486. +0 0 0 0 0 0 0 0 0 0 0 0 8 1 3 112 10 39
  97487. +186 17 65 124 11 43 10 1 4 0 0 0 0 0 0 0 0 0
  97488. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97489. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97490. +36 3 13 156 14 55 191 17 67 188 17 66 188 17 66 188 17 66
  97491. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97492. +189 17 66 190 17 67 134 12 47 18 2 6 0 0 0 0 0 0
  97493. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97494. +0 0 0 7 1 2 41 4 14 75 7 26 66 5 23 19 2 7
  97495. +26 2 9 144 13 50 154 14 54 40 4 14 0 0 0 0 0 0
  97496. +0 0 0 0 0 0 0 0 0
  97497. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 13 1 5
  97498. +56 5 19 19 2 7 0 0 0 7 1 2 29 3 10 35 3 12
  97499. +19 2 7 2 0 1 0 0 0 0 0 0 0 0 0 0 0 0
  97500. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 13 1 5
  97501. +134 12 47 191 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  97502. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97503. +188 17 66 188 17 66 189 17 67 108 10 38 3 0 1 0 0 0
  97504. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
  97505. +40 4 14 124 11 43 177 16 62 188 17 66 187 17 66 144 13 50
  97506. +24 2 8 17 2 6 22 2 8 0 0 0 0 0 0 0 0 0
  97507. +0 0 0 0 0 0 0 0 0
  97508. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97509. +0 0 0 0 0 0 19 2 7 122 11 43 171 15 60 175 16 62
  97510. +159 14 56 112 10 39 40 4 14 2 0 1 0 0 0 0 0 0
  97511. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 72 7 25
  97512. +186 17 65 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97513. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97514. +188 17 66 188 17 66 189 17 66 174 16 61 41 4 14 0 0 0
  97515. +0 0 0 0 0 0 0 0 0 0 0 0 3 0 1 72 7 25
  97516. +168 15 59 191 17 67 189 17 66 188 17 66 188 17 66 190 17 67
  97517. +95 9 33 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97518. +0 0 0 0 0 0 0 0 0
  97519. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97520. +0 0 0 0 0 0 95 9 33 191 17 67 189 17 66 189 17 66
  97521. +190 17 67 191 17 67 171 15 60 90 8 32 12 1 4 0 0 0
  97522. +0 0 0 0 0 0 0 0 0 0 0 0 5 0 2 132 12 46
  97523. +191 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97524. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97525. +188 17 66 188 17 66 188 17 66 190 17 67 98 9 34 0 0 0
  97526. +0 0 0 0 0 0 0 0 0 5 0 2 88 8 31 180 16 63
  97527. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 191 17 67
  97528. +146 13 51 11 1 4 0 0 0 0 0 0 0 0 0 0 0 0
  97529. +0 0 0 0 0 0 0 0 0
  97530. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97531. +0 0 0 9 1 3 144 13 50 191 17 67 188 17 66 188 17 66
  97532. +188 17 66 188 17 66 189 17 66 187 17 66 123 11 43 20 2 7
  97533. +0 0 0 0 0 0 0 0 0 0 0 0 21 2 7 163 15 57
  97534. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97535. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97536. +188 17 66 188 17 66 188 17 66 191 17 67 134 12 47 5 0 2
  97537. +0 0 0 0 0 0 3 0 1 88 8 31 182 16 64 189 17 66
  97538. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 189 17 66
  97539. +171 15 60 31 3 11 0 0 0 0 0 0 0 0 0 0 0 0
  97540. +0 0 0 0 0 0 0 0 0
  97541. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97542. +0 0 0 20 2 7 162 15 57 190 17 67 188 17 66 188 17 66
  97543. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 132 12 46
  97544. +20 2 7 0 0 0 0 0 0 0 0 0 32 3 11 173 16 61
  97545. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97546. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97547. +188 17 66 188 17 66 188 17 66 190 17 67 151 14 53 12 1 4
  97548. +0 0 0 0 0 0 72 7 25 180 16 63 189 17 66 188 17 66
  97549. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97550. +181 16 63 47 4 16 0 0 0 0 0 0 0 0 0 0 0 0
  97551. +0 0 0 0 0 0 0 0 0
  97552. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97553. +0 0 0 21 2 7 163 15 57 190 17 67 188 17 66 188 17 66
  97554. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  97555. +122 11 43 9 1 3 0 0 0 0 0 0 30 3 10 171 15 60
  97556. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97557. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97558. +188 17 66 188 17 66 188 17 66 190 17 67 146 13 51 10 1 4
  97559. +0 0 0 38 3 13 166 15 58 190 17 67 188 17 66 188 17 66
  97560. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97561. +183 17 64 52 5 18 0 0 0 0 0 0 0 0 0 0 0 0
  97562. +0 0 0 0 0 0 0 0 0
  97563. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97564. +0 0 0 13 1 5 154 14 54 190 17 67 188 17 66 188 17 66
  97565. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97566. +186 17 65 79 7 28 0 0 0 0 0 0 14 1 5 156 14 54
  97567. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97568. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97569. +188 17 66 188 17 66 188 17 66 191 17 67 124 11 43 2 0 1
  97570. +5 0 2 122 11 43 191 17 67 188 17 66 188 17 66 188 17 66
  97571. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97572. +182 16 64 47 4 16 0 0 0 0 0 0 0 0 0 0 0 0
  97573. +0 0 0 0 0 0 0 0 0
  97574. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97575. +0 0 0 3 0 1 126 14 44 191 17 67 188 17 66 188 17 66
  97576. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97577. +190 17 67 158 14 55 23 2 8 0 0 0 1 0 0 113 10 40
  97578. +191 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97579. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97580. +188 17 66 188 17 66 188 17 66 188 17 66 78 7 27 0 0 0
  97581. +47 4 16 177 16 62 189 17 66 188 17 66 188 17 66 188 17 66
  97582. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 189 17 66
  97583. +173 16 61 34 3 12 0 0 0 0 0 0 0 0 0 0 0 0
  97584. +0 0 0 0 0 0 0 0 0
  97585. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97586. +0 0 0 0 0 0 85 8 30 189 17 66 188 17 66 188 17 66
  97587. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97588. +188 17 66 188 17 66 79 7 28 0 0 0 0 0 0 47 4 16
  97589. +175 16 62 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97590. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97591. +188 17 66 188 17 66 190 17 67 156 14 55 22 2 8 0 0 0
  97592. +109 10 38 191 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  97593. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  97594. +151 14 53 13 1 5 0 0 0 0 0 0 0 0 0 0 0 0
  97595. +0 0 0 0 0 0 0 0 0
  97596. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97597. +0 0 0 0 0 0 35 3 12 173 16 61 189 17 66 188 17 66
  97598. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97599. +188 17 66 191 17 67 134 12 47 7 1 2 0 0 0 3 0 1
  97600. +99 9 35 188 17 66 189 17 66 188 17 66 188 17 66 188 17 66
  97601. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97602. +188 17 66 189 17 66 181 16 63 68 6 24 0 0 0 18 2 6
  97603. +156 14 55 190 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  97604. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  97605. +101 9 35 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97606. +0 0 0 0 0 0 0 0 0
  97607. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97608. +0 0 0 0 0 0 3 0 1 118 13 41 191 17 67 188 17 66
  97609. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97610. +188 17 66 189 17 66 168 15 59 28 3 10 0 0 0 0 0 0
  97611. +12 1 4 113 10 40 187 17 66 189 17 67 188 17 66 188 17 66
  97612. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97613. +190 17 67 180 16 63 88 8 31 4 0 1 0 0 0 47 4 16
  97614. +180 16 63 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97615. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 168 15 59
  97616. +36 3 13 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97617. +0 0 0 0 0 0 0 0 0
  97618. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97619. +0 0 0 0 0 0 0 0 0 38 3 13 164 15 58 190 17 67
  97620. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97621. +188 17 66 188 17 66 182 16 64 50 5 17 0 0 0 0 0 0
  97622. +0 0 0 11 1 4 90 8 32 169 15 59 190 17 67 190 17 67
  97623. +189 17 66 189 17 66 189 17 66 189 17 66 191 17 67 189 17 66
  97624. +158 14 55 68 6 24 4 0 1 0 0 0 0 0 0 73 7 26
  97625. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97626. +188 17 66 188 17 66 188 17 66 189 17 66 185 17 65 83 8 29
  97627. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97628. +0 0 0 0 0 0 0 0 0
  97629. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97630. +0 0 0 0 0 0 0 0 0 0 0 0 65 6 23 174 16 61
  97631. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97632. +188 17 66 188 17 66 185 17 65 56 5 19 0 0 0 0 0 0
  97633. +0 0 0 0 0 0 2 0 1 35 3 12 99 9 35 146 13 51
  97634. +170 15 60 177 16 62 177 16 62 166 15 58 141 13 49 85 8 30
  97635. +24 2 8 0 0 0 0 0 0 0 0 0 0 0 0 85 8 30
  97636. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97637. +188 17 66 188 17 66 188 17 66 189 17 66 112 10 39 8 1 3
  97638. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97639. +0 0 0 0 0 0 0 0 0
  97640. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97641. +0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 68 6 24
  97642. +170 15 60 191 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  97643. +188 17 66 188 17 66 182 16 64 50 5 17 0 0 0 0 0 0
  97644. +0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 11 1 4
  97645. +28 3 10 40 4 14 38 3 13 25 2 9 8 1 3 0 0 0
  97646. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 78 7 27
  97647. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97648. +188 17 66 189 17 66 187 17 66 113 10 40 14 1 5 0 0 0
  97649. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97650. +0 0 0 0 0 0 0 0 0
  97651. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97652. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
  97653. +47 4 16 141 13 49 186 17 65 191 17 67 190 17 67 189 17 66
  97654. +189 17 66 191 17 67 156 14 55 20 2 7 0 0 0 0 0 0
  97655. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97656. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97657. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 44 4 15
  97658. +178 16 62 190 17 67 188 17 66 188 17 66 188 17 66 190 17 67
  97659. +191 17 67 173 16 61 90 8 32 10 1 4 0 0 0 0 0 0
  97660. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97661. +0 0 0 0 0 0 0 0 0
  97662. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97663. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97664. +0 0 0 14 1 5 68 6 24 131 12 46 162 15 57 174 16 61
  97665. +171 15 60 146 13 51 56 5 19 0 0 0 0 0 0 0 0 0
  97666. +0 0 0 0 0 0 0 0 0 3 0 1 14 1 5 29 3 10
  97667. +41 4 14 47 4 16 50 5 17 45 4 16 34 3 12 18 2 6
  97668. +5 0 2 0 0 0 0 0 0 0 0 0 0 0 0 5 0 2
  97669. +90 8 32 169 15 59 185 17 65 187 17 66 182 16 64 163 15 57
  97670. +113 10 40 41 4 14 2 0 1 0 0 0 0 0 0 0 0 0
  97671. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97672. +0 0 0 0 0 0 0 0 0
  97673. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97674. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97675. +0 0 0 0 0 0 0 0 0 5 0 2 21 2 7 34 3 12
  97676. +29 3 10 11 1 4 0 0 0 0 0 0 0 0 0 0 0 0
  97677. +3 0 1 32 3 11 79 7 28 124 11 43 154 14 54 171 15 60
  97678. +180 16 63 182 16 64 182 16 64 180 16 63 174 16 61 159 14 56
  97679. +132 12 46 88 8 31 34 3 12 3 0 1 0 0 0 0 0 0
  97680. +3 0 1 29 3 10 56 5 19 65 6 23 50 5 17 23 2 8
  97681. +3 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97682. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97683. +0 0 0 0 0 0 0 0 0
  97684. +0 0 0 0 0 0 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 0 0 0 0 0 0
  97686. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97687. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 25 2 9
  97688. +109 10 38 169 15 59 189 17 66 191 17 67 190 17 67 189 17 66
  97689. +189 17 66 188 17 66 188 17 66 188 17 66 189 17 66 190 17 67
  97690. +191 17 67 190 17 67 171 15 60 98 9 34 10 1 3 0 0 0
  97691. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97692. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97693. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97694. +0 0 0 0 0 0 0 0 0
  97695. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97696. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97697. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97698. +0 0 0 0 0 0 0 0 0 0 0 0 14 1 5 141 13 49
  97699. +191 17 67 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97700. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97701. +188 17 66 188 17 66 189 17 67 186 17 65 65 6 23 0 0 0
  97702. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97703. +0 0 0 0 0 0 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 0 0 0 0 0 0
  97705. +0 0 0 0 0 0 0 0 0
  97706. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97707. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97708. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97709. +0 0 0 0 0 0 0 0 0 0 0 0 23 2 8 166 15 58
  97710. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97711. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97712. +188 17 66 188 17 66 189 17 66 176 16 62 45 4 16 0 0 0
  97713. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97714. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97715. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97716. +0 0 0 0 0 0 0 0 0
  97717. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97718. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97719. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97720. +0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 83 8 29
  97721. +183 17 64 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97722. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97723. +188 17 66 189 17 66 185 17 65 95 9 33 3 0 1 0 0 0
  97724. +0 0 0 0 0 0 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 0 0 0 0 0 0
  97726. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97727. +0 0 0 0 0 0 0 0 0
  97728. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97729. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97730. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97731. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 0 2
  97732. +85 8 30 176 16 62 191 17 67 188 17 66 188 17 66 188 17 66
  97733. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97734. +191 17 67 180 16 63 95 9 33 7 1 3 0 0 0 0 0 0
  97735. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97736. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97737. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97738. +0 0 0 0 0 0 0 0 0
  97739. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97740. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97741. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97742. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97743. +2 0 1 52 5 18 141 13 49 185 17 65 191 17 67 189 17 67
  97744. +189 17 66 188 17 66 188 17 66 189 17 66 191 17 67 187 17 66
  97745. +146 13 51 56 5 19 4 0 1 0 0 0 0 0 0 0 0 0
  97746. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97747. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97748. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97749. +0 0 0 0 0 0 0 0 0
  97750. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97751. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97752. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97753. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97754. +0 0 0 0 0 0 14 1 5 68 6 24 131 12 46 166 15 58
  97755. +180 16 63 183 17 64 180 16 63 168 15 59 134 12 47 75 7 26
  97756. +17 2 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97757. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97758. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97759. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97760. +0 0 0 0 0 0 0 0 0
  97761. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97762. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97763. +0 0 0 0 0 0 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 0 0 0 0 0 0
  97765. +0 0 0 0 0 0 0 0 0 0 0 0 5 0 2 24 2 8
  97766. +44 4 15 52 5 18 45 4 16 26 2 9 6 1 2 0 0 0
  97767. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97768. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97769. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97770. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97771. +0 0 0 0 0 0 0 0 0
  97772. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97773. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97774. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97775. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97776. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97777. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97778. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97779. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97780. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97781. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97782. +0 0 0 0 0 0 0 0 0
  97783. +0 0 0 0 0 0 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 0 0 0 0 0 0
  97785. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97786. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97787. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97788. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97789. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97790. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97791. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97792. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97793. +0 0 0 0 0 0 0 0 0
  97794. diff -Nur linux-3.13.11/drivers/video/Makefile linux-rpi/drivers/video/Makefile
  97795. --- linux-3.13.11/drivers/video/Makefile 2014-04-23 01:49:33.000000000 +0200
  97796. +++ linux-rpi/drivers/video/Makefile 2014-04-24 15:35:04.249566623 +0200
  97797. @@ -100,6 +100,7 @@
  97798. obj-$(CONFIG_FB_VOODOO1) += sstfb.o
  97799. obj-$(CONFIG_FB_ARMCLCD) += amba-clcd.o
  97800. obj-$(CONFIG_FB_GOLDFISH) += goldfishfb.o
  97801. +obj-$(CONFIG_FB_BCM2708) += bcm2708_fb.o
  97802. obj-$(CONFIG_FB_68328) += 68328fb.o
  97803. obj-$(CONFIG_FB_GBE) += gbefb.o
  97804. obj-$(CONFIG_FB_CIRRUS) += cirrusfb.o
  97805. diff -Nur linux-3.13.11/drivers/w1/masters/w1-gpio.c linux-rpi/drivers/w1/masters/w1-gpio.c
  97806. --- linux-3.13.11/drivers/w1/masters/w1-gpio.c 2014-04-23 01:49:33.000000000 +0200
  97807. +++ linux-rpi/drivers/w1/masters/w1-gpio.c 2014-04-24 15:37:14.395002333 +0200
  97808. @@ -22,6 +22,9 @@
  97809. #include "../w1.h"
  97810. #include "../w1_int.h"
  97811. +static int w1_gpio_pullup = 0;
  97812. +module_param_named(pullup, w1_gpio_pullup, int, 0);
  97813. +
  97814. static void w1_gpio_write_bit_dir(void *data, u8 bit)
  97815. {
  97816. struct w1_gpio_platform_data *pdata = data;
  97817. @@ -46,6 +49,16 @@
  97818. return gpio_get_value(pdata->pin) ? 1 : 0;
  97819. }
  97820. +static void w1_gpio_bitbang_pullup(void *data, u8 on)
  97821. +{
  97822. + struct w1_gpio_platform_data *pdata = data;
  97823. +
  97824. + if (on)
  97825. + gpio_direction_output(pdata->pin, 1);
  97826. + else
  97827. + gpio_direction_input(pdata->pin);
  97828. +}
  97829. +
  97830. #if defined(CONFIG_OF)
  97831. static struct of_device_id w1_gpio_dt_ids[] = {
  97832. { .compatible = "w1-gpio" },
  97833. @@ -56,9 +69,8 @@
  97834. static int w1_gpio_probe_dt(struct platform_device *pdev)
  97835. {
  97836. - struct w1_gpio_platform_data *pdata = dev_get_platdata(&pdev->dev);
  97837. + struct w1_gpio_platform_data *pdata = pdev->dev.platform_data;
  97838. struct device_node *np = pdev->dev.of_node;
  97839. - int gpio;
  97840. pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
  97841. if (!pdata)
  97842. @@ -67,11 +79,7 @@
  97843. if (of_get_property(np, "linux,open-drain", NULL))
  97844. pdata->is_open_drain = 1;
  97845. - gpio = of_get_gpio(np, 0);
  97846. - if (gpio < 0)
  97847. - return gpio;
  97848. - pdata->pin = gpio;
  97849. -
  97850. + pdata->pin = of_get_gpio(np, 0);
  97851. pdata->ext_pullup_enable_pin = of_get_gpio(np, 1);
  97852. pdev->dev.platform_data = pdata;
  97853. @@ -92,34 +100,32 @@
  97854. }
  97855. }
  97856. - pdata = dev_get_platdata(&pdev->dev);
  97857. + pdata = pdev->dev.platform_data;
  97858. if (!pdata) {
  97859. dev_err(&pdev->dev, "No configuration data\n");
  97860. return -ENXIO;
  97861. }
  97862. - master = devm_kzalloc(&pdev->dev, sizeof(struct w1_bus_master),
  97863. - GFP_KERNEL);
  97864. + master = kzalloc(sizeof(struct w1_bus_master), GFP_KERNEL);
  97865. if (!master) {
  97866. dev_err(&pdev->dev, "Out of memory\n");
  97867. return -ENOMEM;
  97868. }
  97869. - err = devm_gpio_request(&pdev->dev, pdata->pin, "w1");
  97870. + err = gpio_request(pdata->pin, "w1");
  97871. if (err) {
  97872. dev_err(&pdev->dev, "gpio_request (pin) failed\n");
  97873. - return err;
  97874. + goto free_master;
  97875. }
  97876. if (gpio_is_valid(pdata->ext_pullup_enable_pin)) {
  97877. - err = devm_gpio_request_one(&pdev->dev,
  97878. - pdata->ext_pullup_enable_pin, GPIOF_INIT_LOW,
  97879. - "w1 pullup");
  97880. + err = gpio_request_one(pdata->ext_pullup_enable_pin,
  97881. + GPIOF_INIT_LOW, "w1 pullup");
  97882. if (err < 0) {
  97883. dev_err(&pdev->dev, "gpio_request_one "
  97884. "(ext_pullup_enable_pin) failed\n");
  97885. - return err;
  97886. + goto free_gpio;
  97887. }
  97888. }
  97889. @@ -134,10 +140,17 @@
  97890. master->write_bit = w1_gpio_write_bit_dir;
  97891. }
  97892. + if (w1_gpio_pullup)
  97893. + if (pdata->is_open_drain)
  97894. + printk(KERN_ERR "w1-gpio 'pullup' option "
  97895. + "doesn't work with open drain GPIO\n");
  97896. + else
  97897. + master->bitbang_pullup = w1_gpio_bitbang_pullup;
  97898. +
  97899. err = w1_add_master_device(master);
  97900. if (err) {
  97901. dev_err(&pdev->dev, "w1_add_master device failed\n");
  97902. - return err;
  97903. + goto free_gpio_ext_pu;
  97904. }
  97905. if (pdata->enable_external_pullup)
  97906. @@ -149,12 +162,22 @@
  97907. platform_set_drvdata(pdev, master);
  97908. return 0;
  97909. +
  97910. + free_gpio_ext_pu:
  97911. + if (gpio_is_valid(pdata->ext_pullup_enable_pin))
  97912. + gpio_free(pdata->ext_pullup_enable_pin);
  97913. + free_gpio:
  97914. + gpio_free(pdata->pin);
  97915. + free_master:
  97916. + kfree(master);
  97917. +
  97918. + return err;
  97919. }
  97920. static int w1_gpio_remove(struct platform_device *pdev)
  97921. {
  97922. struct w1_bus_master *master = platform_get_drvdata(pdev);
  97923. - struct w1_gpio_platform_data *pdata = dev_get_platdata(&pdev->dev);
  97924. + struct w1_gpio_platform_data *pdata = pdev->dev.platform_data;
  97925. if (pdata->enable_external_pullup)
  97926. pdata->enable_external_pullup(0);
  97927. @@ -163,6 +186,8 @@
  97928. gpio_set_value(pdata->ext_pullup_enable_pin, 0);
  97929. w1_remove_master_device(master);
  97930. + gpio_free(pdata->pin);
  97931. + kfree(master);
  97932. return 0;
  97933. }
  97934. @@ -171,7 +196,7 @@
  97935. static int w1_gpio_suspend(struct platform_device *pdev, pm_message_t state)
  97936. {
  97937. - struct w1_gpio_platform_data *pdata = dev_get_platdata(&pdev->dev);
  97938. + struct w1_gpio_platform_data *pdata = pdev->dev.platform_data;
  97939. if (pdata->enable_external_pullup)
  97940. pdata->enable_external_pullup(0);
  97941. @@ -181,7 +206,7 @@
  97942. static int w1_gpio_resume(struct platform_device *pdev)
  97943. {
  97944. - struct w1_gpio_platform_data *pdata = dev_get_platdata(&pdev->dev);
  97945. + struct w1_gpio_platform_data *pdata = pdev->dev.platform_data;
  97946. if (pdata->enable_external_pullup)
  97947. pdata->enable_external_pullup(1);
  97948. diff -Nur linux-3.13.11/drivers/w1/w1.h linux-rpi/drivers/w1/w1.h
  97949. --- linux-3.13.11/drivers/w1/w1.h 2014-04-23 01:49:33.000000000 +0200
  97950. +++ linux-rpi/drivers/w1/w1.h 2014-04-24 15:37:14.407002464 +0200
  97951. @@ -148,6 +148,12 @@
  97952. */
  97953. u8 (*set_pullup)(void *, int);
  97954. + /**
  97955. + * Turns the pullup on/off in bitbanging mode, takes an on/off argument.
  97956. + * @return -1=Error, 0=completed
  97957. + */
  97958. + void (*bitbang_pullup) (void *, u8);
  97959. +
  97960. /** Really nice hardware can handles the different types of ROM search
  97961. * w1_master* is passed to the slave found callback.
  97962. */
  97963. diff -Nur linux-3.13.11/drivers/w1/w1_int.c linux-rpi/drivers/w1/w1_int.c
  97964. --- linux-3.13.11/drivers/w1/w1_int.c 2014-04-23 01:49:33.000000000 +0200
  97965. +++ linux-rpi/drivers/w1/w1_int.c 2014-04-24 15:37:14.407002464 +0200
  97966. @@ -130,6 +130,20 @@
  97967. master->set_pullup = NULL;
  97968. }
  97969. + /* bitbanging hardware uses bitbang_pullup, other hardware uses set_pullup
  97970. + * and takes care of timing itself */
  97971. + if (!master->write_byte && !master->touch_bit && master->set_pullup) {
  97972. + printk(KERN_ERR "w1_add_master_device: set_pullup requires "
  97973. + "write_byte or touch_bit, disabling\n");
  97974. + master->set_pullup = NULL;
  97975. + }
  97976. +
  97977. + if (master->set_pullup && master->bitbang_pullup) {
  97978. + printk(KERN_ERR "w1_add_master_device: set_pullup should not "
  97979. + "be set when bitbang_pullup is used, disabling\n");
  97980. + master->set_pullup = NULL;
  97981. + }
  97982. +
  97983. /* Lock until the device is added (or not) to w1_masters. */
  97984. mutex_lock(&w1_mlock);
  97985. /* Search for the first available id (starting at 1). */
  97986. diff -Nur linux-3.13.11/drivers/w1/w1_io.c linux-rpi/drivers/w1/w1_io.c
  97987. --- linux-3.13.11/drivers/w1/w1_io.c 2014-04-23 01:49:33.000000000 +0200
  97988. +++ linux-rpi/drivers/w1/w1_io.c 2014-04-24 15:35:04.349567736 +0200
  97989. @@ -127,10 +127,22 @@
  97990. static void w1_post_write(struct w1_master *dev)
  97991. {
  97992. if (dev->pullup_duration) {
  97993. - if (dev->enable_pullup && dev->bus_master->set_pullup)
  97994. - dev->bus_master->set_pullup(dev->bus_master->data, 0);
  97995. - else
  97996. + if (dev->enable_pullup) {
  97997. + if (dev->bus_master->set_pullup) {
  97998. + dev->bus_master->set_pullup(dev->
  97999. + bus_master->data,
  98000. + 0);
  98001. + } else if (dev->bus_master->bitbang_pullup) {
  98002. + dev->bus_master->
  98003. + bitbang_pullup(dev->bus_master->data, 1);
  98004. msleep(dev->pullup_duration);
  98005. + dev->bus_master->
  98006. + bitbang_pullup(dev->bus_master->data, 0);
  98007. + }
  98008. + } else {
  98009. + msleep(dev->pullup_duration);
  98010. + }
  98011. +
  98012. dev->pullup_duration = 0;
  98013. }
  98014. }
  98015. diff -Nur linux-3.13.11/drivers/watchdog/bcm2708_wdog.c linux-rpi/drivers/watchdog/bcm2708_wdog.c
  98016. --- linux-3.13.11/drivers/watchdog/bcm2708_wdog.c 1970-01-01 01:00:00.000000000 +0100
  98017. +++ linux-rpi/drivers/watchdog/bcm2708_wdog.c 2014-04-24 15:37:14.419002595 +0200
  98018. @@ -0,0 +1,384 @@
  98019. +/*
  98020. + * Broadcom BCM2708 watchdog driver.
  98021. + *
  98022. + * (c) Copyright 2010 Broadcom Europe Ltd
  98023. + *
  98024. + * This program is free software; you can redistribute it and/or
  98025. + * modify it under the terms of the GNU General Public License
  98026. + * as published by the Free Software Foundation; either version
  98027. + * 2 of the License, or (at your option) any later version.
  98028. + *
  98029. + * BCM2708 watchdog driver. Loosely based on wdt driver.
  98030. + */
  98031. +
  98032. +#include <linux/interrupt.h>
  98033. +#include <linux/module.h>
  98034. +#include <linux/moduleparam.h>
  98035. +#include <linux/types.h>
  98036. +#include <linux/miscdevice.h>
  98037. +#include <linux/watchdog.h>
  98038. +#include <linux/fs.h>
  98039. +#include <linux/ioport.h>
  98040. +#include <linux/notifier.h>
  98041. +#include <linux/reboot.h>
  98042. +#include <linux/init.h>
  98043. +#include <linux/io.h>
  98044. +#include <linux/uaccess.h>
  98045. +#include <mach/platform.h>
  98046. +
  98047. +#include <asm/system.h>
  98048. +
  98049. +#define SECS_TO_WDOG_TICKS(x) ((x) << 16)
  98050. +#define WDOG_TICKS_TO_SECS(x) ((x) >> 16)
  98051. +
  98052. +static unsigned long wdog_is_open;
  98053. +static uint32_t wdog_ticks; /* Ticks to load into wdog timer */
  98054. +static char expect_close;
  98055. +
  98056. +/*
  98057. + * Module parameters
  98058. + */
  98059. +
  98060. +#define WD_TIMO 10 /* Default heartbeat = 60 seconds */
  98061. +static int heartbeat = WD_TIMO; /* Heartbeat in seconds */
  98062. +
  98063. +module_param(heartbeat, int, 0);
  98064. +MODULE_PARM_DESC(heartbeat,
  98065. + "Watchdog heartbeat in seconds. (0 < heartbeat < 65536, default="
  98066. + __MODULE_STRING(WD_TIMO) ")");
  98067. +
  98068. +static int nowayout = WATCHDOG_NOWAYOUT;
  98069. +module_param(nowayout, int, 0);
  98070. +MODULE_PARM_DESC(nowayout,
  98071. + "Watchdog cannot be stopped once started (default="
  98072. + __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
  98073. +
  98074. +static DEFINE_SPINLOCK(wdog_lock);
  98075. +
  98076. +/**
  98077. + * Start the watchdog driver.
  98078. + */
  98079. +
  98080. +static int wdog_start(unsigned long timeout)
  98081. +{
  98082. + uint32_t cur;
  98083. + unsigned long flags;
  98084. + spin_lock_irqsave(&wdog_lock, flags);
  98085. +
  98086. + /* enable the watchdog */
  98087. + iowrite32(PM_PASSWORD | (timeout & PM_WDOG_TIME_SET),
  98088. + __io_address(PM_WDOG));
  98089. + cur = ioread32(__io_address(PM_RSTC));
  98090. + iowrite32(PM_PASSWORD | (cur & PM_RSTC_WRCFG_CLR) |
  98091. + PM_RSTC_WRCFG_FULL_RESET, __io_address(PM_RSTC));
  98092. +
  98093. + spin_unlock_irqrestore(&wdog_lock, flags);
  98094. + return 0;
  98095. +}
  98096. +
  98097. +/**
  98098. + * Stop the watchdog driver.
  98099. + */
  98100. +
  98101. +static int wdog_stop(void)
  98102. +{
  98103. + iowrite32(PM_PASSWORD | PM_RSTC_RESET, __io_address(PM_RSTC));
  98104. + printk(KERN_INFO "watchdog stopped\n");
  98105. + return 0;
  98106. +}
  98107. +
  98108. +/**
  98109. + * Reload counter one with the watchdog heartbeat. We don't bother
  98110. + * reloading the cascade counter.
  98111. + */
  98112. +
  98113. +static void wdog_ping(void)
  98114. +{
  98115. + wdog_start(wdog_ticks);
  98116. +}
  98117. +
  98118. +/**
  98119. + * @t: the new heartbeat value that needs to be set.
  98120. + *
  98121. + * Set a new heartbeat value for the watchdog device. If the heartbeat
  98122. + * value is incorrect we keep the old value and return -EINVAL. If
  98123. + * successful we return 0.
  98124. + */
  98125. +
  98126. +static int wdog_set_heartbeat(int t)
  98127. +{
  98128. + if (t < 1 || t > WDOG_TICKS_TO_SECS(PM_WDOG_TIME_SET))
  98129. + return -EINVAL;
  98130. +
  98131. + heartbeat = t;
  98132. + wdog_ticks = SECS_TO_WDOG_TICKS(t);
  98133. + return 0;
  98134. +}
  98135. +
  98136. +/**
  98137. + * @file: file handle to the watchdog
  98138. + * @buf: buffer to write (unused as data does not matter here
  98139. + * @count: count of bytes
  98140. + * @ppos: pointer to the position to write. No seeks allowed
  98141. + *
  98142. + * A write to a watchdog device is defined as a keepalive signal.
  98143. + *
  98144. + * if 'nowayout' is set then normally a close() is ignored. But
  98145. + * if you write 'V' first then the close() will stop the timer.
  98146. + */
  98147. +
  98148. +static ssize_t wdog_write(struct file *file, const char __user *buf,
  98149. + size_t count, loff_t *ppos)
  98150. +{
  98151. + if (count) {
  98152. + if (!nowayout) {
  98153. + size_t i;
  98154. +
  98155. + /* In case it was set long ago */
  98156. + expect_close = 0;
  98157. +
  98158. + for (i = 0; i != count; i++) {
  98159. + char c;
  98160. + if (get_user(c, buf + i))
  98161. + return -EFAULT;
  98162. + if (c == 'V')
  98163. + expect_close = 42;
  98164. + }
  98165. + }
  98166. + wdog_ping();
  98167. + }
  98168. + return count;
  98169. +}
  98170. +
  98171. +static int wdog_get_status(void)
  98172. +{
  98173. + unsigned long flags;
  98174. + int status = 0;
  98175. + spin_lock_irqsave(&wdog_lock, flags);
  98176. + /* FIXME: readback reset reason */
  98177. + spin_unlock_irqrestore(&wdog_lock, flags);
  98178. + return status;
  98179. +}
  98180. +
  98181. +static uint32_t wdog_get_remaining(void)
  98182. +{
  98183. + uint32_t ret = ioread32(__io_address(PM_WDOG));
  98184. + return ret & PM_WDOG_TIME_SET;
  98185. +}
  98186. +
  98187. +/**
  98188. + * @file: file handle to the device
  98189. + * @cmd: watchdog command
  98190. + * @arg: argument pointer
  98191. + *
  98192. + * The watchdog API defines a common set of functions for all watchdogs
  98193. + * according to their available features. We only actually usefully support
  98194. + * querying capabilities and current status.
  98195. + */
  98196. +
  98197. +static long wdog_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  98198. +{
  98199. + void __user *argp = (void __user *)arg;
  98200. + int __user *p = argp;
  98201. + int new_heartbeat;
  98202. + int status;
  98203. + int options;
  98204. + uint32_t remaining;
  98205. +
  98206. + struct watchdog_info ident = {
  98207. + .options = WDIOF_SETTIMEOUT|
  98208. + WDIOF_MAGICCLOSE|
  98209. + WDIOF_KEEPALIVEPING,
  98210. + .firmware_version = 1,
  98211. + .identity = "BCM2708",
  98212. + };
  98213. +
  98214. + switch (cmd) {
  98215. + case WDIOC_GETSUPPORT:
  98216. + return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0;
  98217. + case WDIOC_GETSTATUS:
  98218. + status = wdog_get_status();
  98219. + return put_user(status, p);
  98220. + case WDIOC_GETBOOTSTATUS:
  98221. + return put_user(0, p);
  98222. + case WDIOC_KEEPALIVE:
  98223. + wdog_ping();
  98224. + return 0;
  98225. + case WDIOC_SETTIMEOUT:
  98226. + if (get_user(new_heartbeat, p))
  98227. + return -EFAULT;
  98228. + if (wdog_set_heartbeat(new_heartbeat))
  98229. + return -EINVAL;
  98230. + wdog_ping();
  98231. + /* Fall */
  98232. + case WDIOC_GETTIMEOUT:
  98233. + return put_user(heartbeat, p);
  98234. + case WDIOC_GETTIMELEFT:
  98235. + remaining = WDOG_TICKS_TO_SECS(wdog_get_remaining());
  98236. + return put_user(remaining, p);
  98237. + case WDIOC_SETOPTIONS:
  98238. + if (get_user(options, p))
  98239. + return -EFAULT;
  98240. + if (options & WDIOS_DISABLECARD)
  98241. + wdog_stop();
  98242. + if (options & WDIOS_ENABLECARD)
  98243. + wdog_start(wdog_ticks);
  98244. + return 0;
  98245. + default:
  98246. + return -ENOTTY;
  98247. + }
  98248. +}
  98249. +
  98250. +/**
  98251. + * @inode: inode of device
  98252. + * @file: file handle to device
  98253. + *
  98254. + * The watchdog device has been opened. The watchdog device is single
  98255. + * open and on opening we load the counters.
  98256. + */
  98257. +
  98258. +static int wdog_open(struct inode *inode, struct file *file)
  98259. +{
  98260. + if (test_and_set_bit(0, &wdog_is_open))
  98261. + return -EBUSY;
  98262. + /*
  98263. + * Activate
  98264. + */
  98265. + wdog_start(wdog_ticks);
  98266. + return nonseekable_open(inode, file);
  98267. +}
  98268. +
  98269. +/**
  98270. + * @inode: inode to board
  98271. + * @file: file handle to board
  98272. + *
  98273. + * The watchdog has a configurable API. There is a religious dispute
  98274. + * between people who want their watchdog to be able to shut down and
  98275. + * those who want to be sure if the watchdog manager dies the machine
  98276. + * reboots. In the former case we disable the counters, in the latter
  98277. + * case you have to open it again very soon.
  98278. + */
  98279. +
  98280. +static int wdog_release(struct inode *inode, struct file *file)
  98281. +{
  98282. + if (expect_close == 42) {
  98283. + wdog_stop();
  98284. + } else {
  98285. + printk(KERN_CRIT
  98286. + "wdt: WDT device closed unexpectedly. WDT will not stop!\n");
  98287. + wdog_ping();
  98288. + }
  98289. + clear_bit(0, &wdog_is_open);
  98290. + expect_close = 0;
  98291. + return 0;
  98292. +}
  98293. +
  98294. +/**
  98295. + * @this: our notifier block
  98296. + * @code: the event being reported
  98297. + * @unused: unused
  98298. + *
  98299. + * Our notifier is called on system shutdowns. Turn the watchdog
  98300. + * off so that it does not fire during the next reboot.
  98301. + */
  98302. +
  98303. +static int wdog_notify_sys(struct notifier_block *this, unsigned long code,
  98304. + void *unused)
  98305. +{
  98306. + if (code == SYS_DOWN || code == SYS_HALT)
  98307. + wdog_stop();
  98308. + return NOTIFY_DONE;
  98309. +}
  98310. +
  98311. +/*
  98312. + * Kernel Interfaces
  98313. + */
  98314. +
  98315. +
  98316. +static const struct file_operations wdog_fops = {
  98317. + .owner = THIS_MODULE,
  98318. + .llseek = no_llseek,
  98319. + .write = wdog_write,
  98320. + .unlocked_ioctl = wdog_ioctl,
  98321. + .open = wdog_open,
  98322. + .release = wdog_release,
  98323. +};
  98324. +
  98325. +static struct miscdevice wdog_miscdev = {
  98326. + .minor = WATCHDOG_MINOR,
  98327. + .name = "watchdog",
  98328. + .fops = &wdog_fops,
  98329. +};
  98330. +
  98331. +/*
  98332. + * The WDT card needs to learn about soft shutdowns in order to
  98333. + * turn the timebomb registers off.
  98334. + */
  98335. +
  98336. +static struct notifier_block wdog_notifier = {
  98337. + .notifier_call = wdog_notify_sys,
  98338. +};
  98339. +
  98340. +/**
  98341. + * cleanup_module:
  98342. + *
  98343. + * Unload the watchdog. You cannot do this with any file handles open.
  98344. + * If your watchdog is set to continue ticking on close and you unload
  98345. + * it, well it keeps ticking. We won't get the interrupt but the board
  98346. + * will not touch PC memory so all is fine. You just have to load a new
  98347. + * module in 60 seconds or reboot.
  98348. + */
  98349. +
  98350. +static void __exit wdog_exit(void)
  98351. +{
  98352. + misc_deregister(&wdog_miscdev);
  98353. + unregister_reboot_notifier(&wdog_notifier);
  98354. +}
  98355. +
  98356. +static int __init wdog_init(void)
  98357. +{
  98358. + int ret;
  98359. +
  98360. + /* Check that the heartbeat value is within it's range;
  98361. + if not reset to the default */
  98362. + if (wdog_set_heartbeat(heartbeat)) {
  98363. + wdog_set_heartbeat(WD_TIMO);
  98364. + printk(KERN_INFO "bcm2708_wdog: heartbeat value must be "
  98365. + "0 < heartbeat < %d, using %d\n",
  98366. + WDOG_TICKS_TO_SECS(PM_WDOG_TIME_SET),
  98367. + WD_TIMO);
  98368. + }
  98369. +
  98370. + ret = register_reboot_notifier(&wdog_notifier);
  98371. + if (ret) {
  98372. + printk(KERN_ERR
  98373. + "wdt: cannot register reboot notifier (err=%d)\n", ret);
  98374. + goto out_reboot;
  98375. + }
  98376. +
  98377. + ret = misc_register(&wdog_miscdev);
  98378. + if (ret) {
  98379. + printk(KERN_ERR
  98380. + "wdt: cannot register miscdev on minor=%d (err=%d)\n",
  98381. + WATCHDOG_MINOR, ret);
  98382. + goto out_misc;
  98383. + }
  98384. +
  98385. + printk(KERN_INFO "bcm2708 watchdog, heartbeat=%d sec (nowayout=%d)\n",
  98386. + heartbeat, nowayout);
  98387. + return 0;
  98388. +
  98389. +out_misc:
  98390. + unregister_reboot_notifier(&wdog_notifier);
  98391. +out_reboot:
  98392. + return ret;
  98393. +}
  98394. +
  98395. +module_init(wdog_init);
  98396. +module_exit(wdog_exit);
  98397. +
  98398. +MODULE_AUTHOR("Luke Diamand");
  98399. +MODULE_DESCRIPTION("Driver for BCM2708 watchdog");
  98400. +MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
  98401. +MODULE_ALIAS_MISCDEV(TEMP_MINOR);
  98402. +MODULE_LICENSE("GPL");
  98403. diff -Nur linux-3.13.11/drivers/watchdog/Kconfig linux-rpi/drivers/watchdog/Kconfig
  98404. --- linux-3.13.11/drivers/watchdog/Kconfig 2014-04-23 01:49:33.000000000 +0200
  98405. +++ linux-rpi/drivers/watchdog/Kconfig 2014-04-24 15:37:14.407002464 +0200
  98406. @@ -392,6 +392,12 @@
  98407. To compile this driver as a module, choose M here: the
  98408. module will be called retu_wdt.
  98409. +config BCM2708_WDT
  98410. + tristate "BCM2708 Watchdog"
  98411. + depends on ARCH_BCM2708
  98412. + help
  98413. + Enables BCM2708 watchdog support.
  98414. +
  98415. config MOXART_WDT
  98416. tristate "MOXART watchdog"
  98417. depends on ARCH_MOXART
  98418. diff -Nur linux-3.13.11/drivers/watchdog/Makefile linux-rpi/drivers/watchdog/Makefile
  98419. --- linux-3.13.11/drivers/watchdog/Makefile 2014-04-23 01:49:33.000000000 +0200
  98420. +++ linux-rpi/drivers/watchdog/Makefile 2014-04-24 15:37:14.407002464 +0200
  98421. @@ -54,6 +54,7 @@
  98422. obj-$(CONFIG_IMX2_WDT) += imx2_wdt.o
  98423. obj-$(CONFIG_UX500_WATCHDOG) += ux500_wdt.o
  98424. obj-$(CONFIG_RETU_WATCHDOG) += retu_wdt.o
  98425. +obj-$(CONFIG_BCM2708_WDT) += bcm2708_wdog.o
  98426. obj-$(CONFIG_BCM2835_WDT) += bcm2835_wdt.o
  98427. obj-$(CONFIG_MOXART_WDT) += moxart_wdt.o
  98428. obj-$(CONFIG_SIRFSOC_WATCHDOG) += sirfsoc_wdt.o
  98429. diff -Nur linux-3.13.11/fs/btrfs/disk-io.c linux-rpi/fs/btrfs/disk-io.c
  98430. --- linux-3.13.11/fs/btrfs/disk-io.c 2014-04-23 01:49:33.000000000 +0200
  98431. +++ linux-rpi/fs/btrfs/disk-io.c 2014-04-24 15:37:14.643005042 +0200
  98432. @@ -3238,8 +3238,6 @@
  98433. /* send down all the barriers */
  98434. head = &info->fs_devices->devices;
  98435. list_for_each_entry_rcu(dev, head, dev_list) {
  98436. - if (dev->missing)
  98437. - continue;
  98438. if (!dev->bdev) {
  98439. errors_send++;
  98440. continue;
  98441. @@ -3254,8 +3252,6 @@
  98442. /* wait for all the barriers */
  98443. list_for_each_entry_rcu(dev, head, dev_list) {
  98444. - if (dev->missing)
  98445. - continue;
  98446. if (!dev->bdev) {
  98447. errors_wait++;
  98448. continue;
  98449. diff -Nur linux-3.13.11/fs/btrfs/transaction.c linux-rpi/fs/btrfs/transaction.c
  98450. --- linux-3.13.11/fs/btrfs/transaction.c 2014-04-23 01:49:33.000000000 +0200
  98451. +++ linux-rpi/fs/btrfs/transaction.c 2014-04-24 15:37:14.747006178 +0200
  98452. @@ -685,8 +685,7 @@
  98453. int lock = (trans->type != TRANS_JOIN_NOLOCK);
  98454. int err = 0;
  98455. - if (trans->use_count > 1) {
  98456. - trans->use_count--;
  98457. + if (--trans->use_count) {
  98458. trans->block_rsv = trans->orig_rsv;
  98459. return 0;
  98460. }
  98461. @@ -734,10 +733,17 @@
  98462. }
  98463. if (lock && ACCESS_ONCE(cur_trans->state) == TRANS_STATE_BLOCKED) {
  98464. - if (throttle)
  98465. + if (throttle) {
  98466. + /*
  98467. + * We may race with somebody else here so end up having
  98468. + * to call end_transaction on ourselves again, so inc
  98469. + * our use_count.
  98470. + */
  98471. + trans->use_count++;
  98472. return btrfs_commit_transaction(trans, root);
  98473. - else
  98474. + } else {
  98475. wake_up_process(info->transaction_kthread);
  98476. + }
  98477. }
  98478. if (trans->type & __TRANS_FREEZABLE)
  98479. diff -Nur linux-3.13.11/fs/ext4/extents.c linux-rpi/fs/ext4/extents.c
  98480. --- linux-3.13.11/fs/ext4/extents.c 2014-04-23 01:49:33.000000000 +0200
  98481. +++ linux-rpi/fs/ext4/extents.c 2014-04-24 15:37:15.011009063 +0200
  98482. @@ -2585,27 +2585,6 @@
  98483. ex_ee_block = le32_to_cpu(ex->ee_block);
  98484. ex_ee_len = ext4_ext_get_actual_len(ex);
  98485. - /*
  98486. - * If we're starting with an extent other than the last one in the
  98487. - * node, we need to see if it shares a cluster with the extent to
  98488. - * the right (towards the end of the file). If its leftmost cluster
  98489. - * is this extent's rightmost cluster and it is not cluster aligned,
  98490. - * we'll mark it as a partial that is not to be deallocated.
  98491. - */
  98492. -
  98493. - if (ex != EXT_LAST_EXTENT(eh)) {
  98494. - ext4_fsblk_t current_pblk, right_pblk;
  98495. - long long current_cluster, right_cluster;
  98496. -
  98497. - current_pblk = ext4_ext_pblock(ex) + ex_ee_len - 1;
  98498. - current_cluster = (long long)EXT4_B2C(sbi, current_pblk);
  98499. - right_pblk = ext4_ext_pblock(ex + 1);
  98500. - right_cluster = (long long)EXT4_B2C(sbi, right_pblk);
  98501. - if (current_cluster == right_cluster &&
  98502. - EXT4_PBLK_COFF(sbi, right_pblk))
  98503. - *partial_cluster = -right_cluster;
  98504. - }
  98505. -
  98506. trace_ext4_ext_rm_leaf(inode, start, ex, *partial_cluster);
  98507. while (ex >= EXT_FIRST_EXTENT(eh) &&
  98508. @@ -2731,15 +2710,10 @@
  98509. err = ext4_ext_correct_indexes(handle, inode, path);
  98510. /*
  98511. - * If there's a partial cluster and at least one extent remains in
  98512. - * the leaf, free the partial cluster if it isn't shared with the
  98513. - * current extent. If there's a partial cluster and no extents
  98514. - * remain in the leaf, it can't be freed here. It can only be
  98515. - * freed when it's possible to determine if it's not shared with
  98516. - * any other extent - when the next leaf is processed or when space
  98517. - * removal is complete.
  98518. + * Free the partial cluster only if the current extent does not
  98519. + * reference it. Otherwise we might free used cluster.
  98520. */
  98521. - if (*partial_cluster > 0 && eh->eh_entries &&
  98522. + if (*partial_cluster > 0 &&
  98523. (EXT4_B2C(sbi, ext4_ext_pblock(ex) + ex_ee_len - 1) !=
  98524. *partial_cluster)) {
  98525. int flags = get_default_free_blocks_flags(inode);
  98526. @@ -4154,7 +4128,7 @@
  98527. struct ext4_extent newex, *ex, *ex2;
  98528. struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
  98529. ext4_fsblk_t newblock = 0;
  98530. - int free_on_err = 0, err = 0, depth, ret;
  98531. + int free_on_err = 0, err = 0, depth;
  98532. unsigned int allocated = 0, offset = 0;
  98533. unsigned int allocated_clusters = 0;
  98534. struct ext4_allocation_request ar;
  98535. @@ -4215,13 +4189,9 @@
  98536. if (!ext4_ext_is_uninitialized(ex))
  98537. goto out;
  98538. - ret = ext4_ext_handle_uninitialized_extents(
  98539. + allocated = ext4_ext_handle_uninitialized_extents(
  98540. handle, inode, map, path, flags,
  98541. allocated, newblock);
  98542. - if (ret < 0)
  98543. - err = ret;
  98544. - else
  98545. - allocated = ret;
  98546. goto out3;
  98547. }
  98548. }
  98549. diff -Nur linux-3.13.11/fs/fs-writeback.c linux-rpi/fs/fs-writeback.c
  98550. --- linux-3.13.11/fs/fs-writeback.c 2014-04-23 01:49:33.000000000 +0200
  98551. +++ linux-rpi/fs/fs-writeback.c 2014-04-24 15:37:15.107010111 +0200
  98552. @@ -89,29 +89,16 @@
  98553. #define CREATE_TRACE_POINTS
  98554. #include <trace/events/writeback.h>
  98555. -static void bdi_wakeup_thread(struct backing_dev_info *bdi)
  98556. -{
  98557. - spin_lock_bh(&bdi->wb_lock);
  98558. - if (test_bit(BDI_registered, &bdi->state))
  98559. - mod_delayed_work(bdi_wq, &bdi->wb.dwork, 0);
  98560. - spin_unlock_bh(&bdi->wb_lock);
  98561. -}
  98562. -
  98563. static void bdi_queue_work(struct backing_dev_info *bdi,
  98564. struct wb_writeback_work *work)
  98565. {
  98566. trace_writeback_queue(bdi, work);
  98567. spin_lock_bh(&bdi->wb_lock);
  98568. - if (!test_bit(BDI_registered, &bdi->state)) {
  98569. - if (work->done)
  98570. - complete(work->done);
  98571. - goto out_unlock;
  98572. - }
  98573. list_add_tail(&work->list, &bdi->work_list);
  98574. - mod_delayed_work(bdi_wq, &bdi->wb.dwork, 0);
  98575. -out_unlock:
  98576. spin_unlock_bh(&bdi->wb_lock);
  98577. +
  98578. + mod_delayed_work(bdi_wq, &bdi->wb.dwork, 0);
  98579. }
  98580. static void
  98581. @@ -127,7 +114,7 @@
  98582. work = kzalloc(sizeof(*work), GFP_ATOMIC);
  98583. if (!work) {
  98584. trace_writeback_nowork(bdi);
  98585. - bdi_wakeup_thread(bdi);
  98586. + mod_delayed_work(bdi_wq, &bdi->wb.dwork, 0);
  98587. return;
  98588. }
  98589. @@ -174,7 +161,7 @@
  98590. * writeback as soon as there is no other work to do.
  98591. */
  98592. trace_writeback_wake_background(bdi);
  98593. - bdi_wakeup_thread(bdi);
  98594. + mod_delayed_work(bdi_wq, &bdi->wb.dwork, 0);
  98595. }
  98596. /*
  98597. @@ -1030,7 +1017,7 @@
  98598. current->flags |= PF_SWAPWRITE;
  98599. if (likely(!current_is_workqueue_rescuer() ||
  98600. - !test_bit(BDI_registered, &bdi->state))) {
  98601. + list_empty(&bdi->bdi_list))) {
  98602. /*
  98603. * The normal path. Keep writing back @bdi until its
  98604. * work_list is empty. Note that this path is also taken
  98605. @@ -1052,10 +1039,10 @@
  98606. trace_writeback_pages_written(pages_written);
  98607. }
  98608. - if (!list_empty(&bdi->work_list))
  98609. - mod_delayed_work(bdi_wq, &wb->dwork, 0);
  98610. - else if (wb_has_dirty_io(wb) && dirty_writeback_interval)
  98611. - bdi_wakeup_thread_delayed(bdi);
  98612. + if (!list_empty(&bdi->work_list) ||
  98613. + (wb_has_dirty_io(wb) && dirty_writeback_interval))
  98614. + queue_delayed_work(bdi_wq, &wb->dwork,
  98615. + msecs_to_jiffies(dirty_writeback_interval * 10));
  98616. current->flags &= ~PF_SWAPWRITE;
  98617. }
  98618. diff -Nur linux-3.13.11/fs/jffs2/compr_rtime.c linux-rpi/fs/jffs2/compr_rtime.c
  98619. --- linux-3.13.11/fs/jffs2/compr_rtime.c 2014-04-23 01:49:33.000000000 +0200
  98620. +++ linux-rpi/fs/jffs2/compr_rtime.c 2014-04-24 15:35:04.533569786 +0200
  98621. @@ -33,7 +33,7 @@
  98622. unsigned char *cpage_out,
  98623. uint32_t *sourcelen, uint32_t *dstlen)
  98624. {
  98625. - unsigned short positions[256];
  98626. + short positions[256];
  98627. int outpos = 0;
  98628. int pos=0;
  98629. @@ -74,7 +74,7 @@
  98630. unsigned char *cpage_out,
  98631. uint32_t srclen, uint32_t destlen)
  98632. {
  98633. - unsigned short positions[256];
  98634. + short positions[256];
  98635. int outpos = 0;
  98636. int pos=0;
  98637. diff -Nur linux-3.13.11/fs/jffs2/nodelist.h linux-rpi/fs/jffs2/nodelist.h
  98638. --- linux-3.13.11/fs/jffs2/nodelist.h 2014-04-23 01:49:33.000000000 +0200
  98639. +++ linux-rpi/fs/jffs2/nodelist.h 2014-04-24 15:35:04.533569786 +0200
  98640. @@ -231,7 +231,7 @@
  98641. uint32_t version;
  98642. uint32_t data_crc;
  98643. uint32_t partial_crc;
  98644. - uint32_t csize;
  98645. + uint16_t csize;
  98646. uint16_t overlapped;
  98647. };
  98648. diff -Nur linux-3.13.11/fs/jffs2/nodemgmt.c linux-rpi/fs/jffs2/nodemgmt.c
  98649. --- linux-3.13.11/fs/jffs2/nodemgmt.c 2014-04-23 01:49:33.000000000 +0200
  98650. +++ linux-rpi/fs/jffs2/nodemgmt.c 2014-04-24 15:35:04.533569786 +0200
  98651. @@ -179,7 +179,6 @@
  98652. spin_unlock(&c->erase_completion_lock);
  98653. schedule();
  98654. - remove_wait_queue(&c->erase_wait, &wait);
  98655. } else
  98656. spin_unlock(&c->erase_completion_lock);
  98657. } else if (ret)
  98658. @@ -212,25 +211,20 @@
  98659. int jffs2_reserve_space_gc(struct jffs2_sb_info *c, uint32_t minsize,
  98660. uint32_t *len, uint32_t sumsize)
  98661. {
  98662. - int ret;
  98663. + int ret = -EAGAIN;
  98664. minsize = PAD(minsize);
  98665. jffs2_dbg(1, "%s(): Requested 0x%x bytes\n", __func__, minsize);
  98666. - while (true) {
  98667. - spin_lock(&c->erase_completion_lock);
  98668. + spin_lock(&c->erase_completion_lock);
  98669. + while(ret == -EAGAIN) {
  98670. ret = jffs2_do_reserve_space(c, minsize, len, sumsize);
  98671. if (ret) {
  98672. jffs2_dbg(1, "%s(): looping, ret is %d\n",
  98673. __func__, ret);
  98674. }
  98675. - spin_unlock(&c->erase_completion_lock);
  98676. -
  98677. - if (ret == -EAGAIN)
  98678. - cond_resched();
  98679. - else
  98680. - break;
  98681. }
  98682. + spin_unlock(&c->erase_completion_lock);
  98683. if (!ret)
  98684. ret = jffs2_prealloc_raw_node_refs(c, c->nextblock, 1);
  98685. diff -Nur linux-3.13.11/fs/xfs/xfs_da_btree.c linux-rpi/fs/xfs/xfs_da_btree.c
  98686. --- linux-3.13.11/fs/xfs/xfs_da_btree.c 2014-04-23 01:49:33.000000000 +0200
  98687. +++ linux-rpi/fs/xfs/xfs_da_btree.c 2014-04-24 15:37:15.827017976 +0200
  98688. @@ -1295,7 +1295,7 @@
  98689. node = blk->bp->b_addr;
  98690. dp->d_ops->node_hdr_from_disk(&nodehdr, node);
  98691. btree = dp->d_ops->node_tree_p(node);
  98692. - if (be32_to_cpu(btree[blk->index].hashval) == lasthash)
  98693. + if (be32_to_cpu(btree->hashval) == lasthash)
  98694. break;
  98695. blk->hashval = lasthash;
  98696. btree[blk->index].hashval = cpu_to_be32(lasthash);
  98697. diff -Nur linux-3.13.11/include/linux/backing-dev.h linux-rpi/include/linux/backing-dev.h
  98698. --- linux-3.13.11/include/linux/backing-dev.h 2014-04-23 01:49:33.000000000 +0200
  98699. +++ linux-rpi/include/linux/backing-dev.h 2014-04-24 15:37:16.919029902 +0200
  98700. @@ -95,7 +95,7 @@
  98701. unsigned int max_ratio, max_prop_frac;
  98702. struct bdi_writeback wb; /* default writeback info for this bdi */
  98703. - spinlock_t wb_lock; /* protects work_list & wb.dwork scheduling */
  98704. + spinlock_t wb_lock; /* protects work_list */
  98705. struct list_head work_list;
  98706. diff -Nur linux-3.13.11/include/linux/broadcom/vc_cma.h linux-rpi/include/linux/broadcom/vc_cma.h
  98707. --- linux-3.13.11/include/linux/broadcom/vc_cma.h 1970-01-01 01:00:00.000000000 +0100
  98708. +++ linux-rpi/include/linux/broadcom/vc_cma.h 2014-04-24 15:37:17.079031650 +0200
  98709. @@ -0,0 +1,29 @@
  98710. +/*****************************************************************************
  98711. +* Copyright 2012 Broadcom Corporation. All rights reserved.
  98712. +*
  98713. +* Unless you and Broadcom execute a separate written software license
  98714. +* agreement governing use of this software, this software is licensed to you
  98715. +* under the terms of the GNU General Public License version 2, available at
  98716. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  98717. +*
  98718. +* Notwithstanding the above, under no circumstances may you combine this
  98719. +* software in any way with any other Broadcom software provided under a
  98720. +* license other than the GPL, without Broadcom's express prior written
  98721. +* consent.
  98722. +*****************************************************************************/
  98723. +
  98724. +#if !defined( VC_CMA_H )
  98725. +#define VC_CMA_H
  98726. +
  98727. +#include <linux/ioctl.h>
  98728. +
  98729. +#define VC_CMA_IOC_MAGIC 0xc5
  98730. +
  98731. +#define VC_CMA_IOC_RESERVE _IO(VC_CMA_IOC_MAGIC, 0)
  98732. +
  98733. +#ifdef __KERNEL__
  98734. +extern void __init vc_cma_early_init(void);
  98735. +extern void __init vc_cma_reserve(void);
  98736. +#endif
  98737. +
  98738. +#endif /* VC_CMA_H */
  98739. diff -Nur linux-3.13.11/include/linux/mmc/host.h linux-rpi/include/linux/mmc/host.h
  98740. --- linux-3.13.11/include/linux/mmc/host.h 2014-04-23 01:49:33.000000000 +0200
  98741. +++ linux-rpi/include/linux/mmc/host.h 2014-04-24 15:37:17.251033528 +0200
  98742. @@ -282,6 +282,7 @@
  98743. MMC_CAP2_PACKED_WR)
  98744. #define MMC_CAP2_NO_PRESCAN_POWERUP (1 << 14) /* Don't power up before scan */
  98745. #define MMC_CAP2_SANITIZE (1 << 15) /* Support Sanitize */
  98746. +#define MMC_CAP2_FORCE_MULTIBLOCK (1 << 31) /* Always use multiblock transfers */
  98747. mmc_pm_flag_t pm_caps; /* supported pm features */
  98748. diff -Nur linux-3.13.11/include/linux/mmc/sdhci.h linux-rpi/include/linux/mmc/sdhci.h
  98749. --- linux-3.13.11/include/linux/mmc/sdhci.h 2014-04-23 01:49:33.000000000 +0200
  98750. +++ linux-rpi/include/linux/mmc/sdhci.h 2014-04-24 15:37:17.259033616 +0200
  98751. @@ -102,6 +102,7 @@
  98752. #define SDHCI_QUIRK2_BROKEN_HS200 (1<<6)
  98753. int irq; /* Device IRQ */
  98754. + int second_irq; /* Additional IRQ to disable/enable in low-latency mode */
  98755. void __iomem *ioaddr; /* Mapped address */
  98756. const struct sdhci_ops *ops; /* Low level hw interface */
  98757. @@ -133,6 +134,7 @@
  98758. #define SDHCI_SDIO_IRQ_ENABLED (1<<9) /* SDIO irq enabled */
  98759. #define SDHCI_SDR104_NEEDS_TUNING (1<<10) /* SDR104/HS200 needs tuning */
  98760. #define SDHCI_USING_RETUNING_TIMER (1<<11) /* Host is using a retuning timer for the card */
  98761. +#define SDHCI_USE_PLATDMA (1<<12) /* Host uses 3rd party DMA */
  98762. unsigned int version; /* SDHCI spec. version */
  98763. @@ -148,6 +150,7 @@
  98764. struct mmc_request *mrq; /* Current request */
  98765. struct mmc_command *cmd; /* Current command */
  98766. + int last_cmdop; /* Opcode of last cmd sent */
  98767. struct mmc_data *data; /* Current data request */
  98768. unsigned int data_early:1; /* Data finished before cmd */
  98769. diff -Nur linux-3.13.11/include/linux/tty.h linux-rpi/include/linux/tty.h
  98770. --- linux-3.13.11/include/linux/tty.h 2014-04-23 01:49:33.000000000 +0200
  98771. +++ linux-rpi/include/linux/tty.h 2014-04-24 15:37:17.855040124 +0200
  98772. @@ -202,7 +202,7 @@
  98773. wait_queue_head_t delta_msr_wait; /* Modem status change */
  98774. unsigned long flags; /* TTY flags ASY_*/
  98775. unsigned char console:1, /* port is a console */
  98776. - low_latency:1; /* optional: tune for latency */
  98777. + low_latency:1; /* direct buffer flush */
  98778. struct mutex mutex; /* Locking */
  98779. struct mutex buf_mutex; /* Buffer alloc lock */
  98780. unsigned char *xmit_buf; /* Optional buffer */
  98781. diff -Nur linux-3.13.11/include/uapi/linux/fb.h linux-rpi/include/uapi/linux/fb.h
  98782. --- linux-3.13.11/include/uapi/linux/fb.h 2014-04-23 01:49:33.000000000 +0200
  98783. +++ linux-rpi/include/uapi/linux/fb.h 2014-04-24 15:35:04.941574330 +0200
  98784. @@ -34,6 +34,11 @@
  98785. #define FBIOPUT_MODEINFO 0x4617
  98786. #define FBIOGET_DISPINFO 0x4618
  98787. #define FBIO_WAITFORVSYNC _IOW('F', 0x20, __u32)
  98788. +/*
  98789. + * HACK: use 'z' in order not to clash with any other ioctl numbers which might
  98790. + * be concurrently added to the mainline kernel
  98791. + */
  98792. +#define FBIOCOPYAREA _IOW('z', 0x21, struct fb_copyarea)
  98793. #define FB_TYPE_PACKED_PIXELS 0 /* Packed Pixels */
  98794. #define FB_TYPE_PLANES 1 /* Non interleaved planes */
  98795. diff -Nur linux-3.13.11/kernel/cgroup.c linux-rpi/kernel/cgroup.c
  98796. --- linux-3.13.11/kernel/cgroup.c 2014-04-23 01:49:33.000000000 +0200
  98797. +++ linux-rpi/kernel/cgroup.c 2014-04-24 15:37:18.955052135 +0200
  98798. @@ -5485,6 +5485,33 @@
  98799. }
  98800. __setup("cgroup_disable=", cgroup_disable);
  98801. +static int __init cgroup_enable(char *str)
  98802. +{
  98803. + struct cgroup_subsys *ss;
  98804. + char *token;
  98805. + int i;
  98806. +
  98807. + while ((token = strsep(&str, ",")) != NULL) {
  98808. + if (!*token)
  98809. + continue;
  98810. +
  98811. + /*
  98812. + * cgroup_disable, being at boot time, can't know about
  98813. + * module subsystems, so we don't worry about them.
  98814. + */
  98815. + for_each_builtin_subsys(ss, i) {
  98816. + if (!strcmp(token, ss->name)) {
  98817. + ss->disabled = 0;
  98818. + printk(KERN_INFO "Disabling %s control group"
  98819. + " subsystem\n", ss->name);
  98820. + break;
  98821. + }
  98822. + }
  98823. + }
  98824. + return 1;
  98825. +}
  98826. +__setup("cgroup_enable=", cgroup_enable);
  98827. +
  98828. /**
  98829. * css_from_dir - get corresponding css from the dentry of a cgroup dir
  98830. * @dentry: directory dentry of interest
  98831. diff -Nur linux-3.13.11/kernel/exit.c linux-rpi/kernel/exit.c
  98832. --- linux-3.13.11/kernel/exit.c 2014-04-23 01:49:33.000000000 +0200
  98833. +++ linux-rpi/kernel/exit.c 2014-04-24 15:37:18.959052178 +0200
  98834. @@ -559,6 +559,9 @@
  98835. struct list_head *dead)
  98836. {
  98837. list_move_tail(&p->sibling, &p->real_parent->children);
  98838. +
  98839. + if (p->exit_state == EXIT_DEAD)
  98840. + return;
  98841. /*
  98842. * If this is a threaded reparent there is no need to
  98843. * notify anyone anything has happened.
  98844. @@ -566,19 +569,9 @@
  98845. if (same_thread_group(p->real_parent, father))
  98846. return;
  98847. - /*
  98848. - * We don't want people slaying init.
  98849. - *
  98850. - * Note: we do this even if it is EXIT_DEAD, wait_task_zombie()
  98851. - * can change ->exit_state to EXIT_ZOMBIE. If this is the final
  98852. - * state, do_notify_parent() was already called and ->exit_signal
  98853. - * doesn't matter.
  98854. - */
  98855. + /* We don't want people slaying init. */
  98856. p->exit_signal = SIGCHLD;
  98857. - if (p->exit_state == EXIT_DEAD)
  98858. - return;
  98859. -
  98860. /* If it has exited notify the new parent about this child's death. */
  98861. if (!p->ptrace &&
  98862. p->exit_state == EXIT_ZOMBIE && thread_group_empty(p)) {
  98863. @@ -790,8 +783,6 @@
  98864. exit_shm(tsk);
  98865. exit_files(tsk);
  98866. exit_fs(tsk);
  98867. - if (group_dead)
  98868. - disassociate_ctty(1);
  98869. exit_task_namespaces(tsk);
  98870. exit_task_work(tsk);
  98871. check_stack_usage();
  98872. @@ -807,9 +798,13 @@
  98873. cgroup_exit(tsk, 1);
  98874. + if (group_dead)
  98875. + disassociate_ctty(1);
  98876. +
  98877. module_put(task_thread_info(tsk)->exec_domain->module);
  98878. proc_exit_connector(tsk);
  98879. +
  98880. /*
  98881. * FIXME: do that only when needed, using sched_exit tracepoint
  98882. */
  98883. diff -Nur linux-3.13.11/kernel/pid_namespace.c linux-rpi/kernel/pid_namespace.c
  98884. --- linux-3.13.11/kernel/pid_namespace.c 2014-04-23 01:49:33.000000000 +0200
  98885. +++ linux-rpi/kernel/pid_namespace.c 2014-04-24 15:37:18.971052309 +0200
  98886. @@ -318,9 +318,7 @@
  98887. struct pid_namespace *ns;
  98888. rcu_read_lock();
  98889. - ns = task_active_pid_ns(task);
  98890. - if (ns)
  98891. - get_pid_ns(ns);
  98892. + ns = get_pid_ns(task_active_pid_ns(task));
  98893. rcu_read_unlock();
  98894. return ns;
  98895. diff -Nur linux-3.13.11/kernel/user_namespace.c linux-rpi/kernel/user_namespace.c
  98896. --- linux-3.13.11/kernel/user_namespace.c 2014-04-23 01:49:33.000000000 +0200
  98897. +++ linux-rpi/kernel/user_namespace.c 2014-04-24 15:37:18.999052615 +0200
  98898. @@ -152,7 +152,7 @@
  98899. /* Find the matching extent */
  98900. extents = map->nr_extents;
  98901. - smp_rmb();
  98902. + smp_read_barrier_depends();
  98903. for (idx = 0; idx < extents; idx++) {
  98904. first = map->extent[idx].first;
  98905. last = first + map->extent[idx].count - 1;
  98906. @@ -176,7 +176,7 @@
  98907. /* Find the matching extent */
  98908. extents = map->nr_extents;
  98909. - smp_rmb();
  98910. + smp_read_barrier_depends();
  98911. for (idx = 0; idx < extents; idx++) {
  98912. first = map->extent[idx].first;
  98913. last = first + map->extent[idx].count - 1;
  98914. @@ -199,7 +199,7 @@
  98915. /* Find the matching extent */
  98916. extents = map->nr_extents;
  98917. - smp_rmb();
  98918. + smp_read_barrier_depends();
  98919. for (idx = 0; idx < extents; idx++) {
  98920. first = map->extent[idx].lower_first;
  98921. last = first + map->extent[idx].count - 1;
  98922. @@ -615,8 +615,9 @@
  98923. * were written before the count of the extents.
  98924. *
  98925. * To achieve this smp_wmb() is used on guarantee the write
  98926. - * order and smp_rmb() is guaranteed that we don't have crazy
  98927. - * architectures returning stale data.
  98928. + * order and smp_read_barrier_depends() is guaranteed that we
  98929. + * don't have crazy architectures returning stale data.
  98930. + *
  98931. */
  98932. mutex_lock(&id_map_mutex);
  98933. diff -Nur linux-3.13.11/mm/backing-dev.c linux-rpi/mm/backing-dev.c
  98934. --- linux-3.13.11/mm/backing-dev.c 2014-04-23 01:49:33.000000000 +0200
  98935. +++ linux-rpi/mm/backing-dev.c 2014-04-24 15:37:19.011052745 +0200
  98936. @@ -288,19 +288,13 @@
  98937. * Note, we wouldn't bother setting up the timer, but this function is on the
  98938. * fast-path (used by '__mark_inode_dirty()'), so we save few context switches
  98939. * by delaying the wake-up.
  98940. - *
  98941. - * We have to be careful not to postpone flush work if it is scheduled for
  98942. - * earlier. Thus we use queue_delayed_work().
  98943. */
  98944. void bdi_wakeup_thread_delayed(struct backing_dev_info *bdi)
  98945. {
  98946. unsigned long timeout;
  98947. timeout = msecs_to_jiffies(dirty_writeback_interval * 10);
  98948. - spin_lock_bh(&bdi->wb_lock);
  98949. - if (test_bit(BDI_registered, &bdi->state))
  98950. - queue_delayed_work(bdi_wq, &bdi->wb.dwork, timeout);
  98951. - spin_unlock_bh(&bdi->wb_lock);
  98952. + mod_delayed_work(bdi_wq, &bdi->wb.dwork, timeout);
  98953. }
  98954. /*
  98955. @@ -313,6 +307,9 @@
  98956. spin_unlock_bh(&bdi_lock);
  98957. synchronize_rcu_expedited();
  98958. +
  98959. + /* bdi_list is now unused, clear it to mark @bdi dying */
  98960. + INIT_LIST_HEAD(&bdi->bdi_list);
  98961. }
  98962. int bdi_register(struct backing_dev_info *bdi, struct device *parent,
  98963. @@ -363,11 +360,6 @@
  98964. */
  98965. bdi_remove_from_list(bdi);
  98966. - /* Make sure nobody queues further work */
  98967. - spin_lock_bh(&bdi->wb_lock);
  98968. - clear_bit(BDI_registered, &bdi->state);
  98969. - spin_unlock_bh(&bdi->wb_lock);
  98970. -
  98971. /*
  98972. * Drain work list and shutdown the delayed_work. At this point,
  98973. * @bdi->bdi_list is empty telling bdi_Writeback_workfn() that @bdi
  98974. diff -Nur linux-3.13.11/mm/memcontrol.c linux-rpi/mm/memcontrol.c
  98975. --- linux-3.13.11/mm/memcontrol.c 2014-04-23 01:49:33.000000000 +0200
  98976. +++ linux-rpi/mm/memcontrol.c 2014-04-24 15:37:19.019052833 +0200
  98977. @@ -7043,6 +7043,7 @@
  98978. .bind = mem_cgroup_bind,
  98979. .base_cftypes = mem_cgroup_files,
  98980. .early_init = 0,
  98981. + .disabled = 1,
  98982. };
  98983. #ifdef CONFIG_MEMCG_SWAP
  98984. diff -Nur linux-3.13.11/net/bluetooth/hci_event.c linux-rpi/net/bluetooth/hci_event.c
  98985. --- linux-3.13.11/net/bluetooth/hci_event.c 2014-04-23 01:49:33.000000000 +0200
  98986. +++ linux-rpi/net/bluetooth/hci_event.c 2014-04-24 15:37:19.067053357 +0200
  98987. @@ -3596,13 +3596,7 @@
  98988. hci_send_cmd(hdev, HCI_OP_LE_LTK_REPLY, sizeof(cp), &cp);
  98989. - /* Ref. Bluetooth Core SPEC pages 1975 and 2004. STK is a
  98990. - * temporary key used to encrypt a connection following
  98991. - * pairing. It is used during the Encrypted Session Setup to
  98992. - * distribute the keys. Later, security can be re-established
  98993. - * using a distributed LTK.
  98994. - */
  98995. - if (ltk->type == HCI_SMP_STK_SLAVE) {
  98996. + if (ltk->type & HCI_SMP_STK) {
  98997. list_del(&ltk->list);
  98998. kfree(ltk);
  98999. }
  99000. diff -Nur linux-3.13.11/security/integrity/ima/ima_fs.c linux-rpi/security/integrity/ima/ima_fs.c
  99001. --- linux-3.13.11/security/integrity/ima/ima_fs.c 2014-04-23 01:49:33.000000000 +0200
  99002. +++ linux-rpi/security/integrity/ima/ima_fs.c 2014-04-24 15:37:23.591102731 +0200
  99003. @@ -160,8 +160,6 @@
  99004. if (is_ima_template && strcmp(field->field_id, "d") == 0)
  99005. show = IMA_SHOW_BINARY_NO_FIELD_LEN;
  99006. - if (is_ima_template && strcmp(field->field_id, "n") == 0)
  99007. - show = IMA_SHOW_BINARY_OLD_STRING_FMT;
  99008. field->field_show(m, show, &e->template_data[i]);
  99009. }
  99010. return 0;
  99011. diff -Nur linux-3.13.11/security/integrity/ima/ima.h linux-rpi/security/integrity/ima/ima.h
  99012. --- linux-3.13.11/security/integrity/ima/ima.h 2014-04-23 01:49:33.000000000 +0200
  99013. +++ linux-rpi/security/integrity/ima/ima.h 2014-04-24 15:37:23.591102731 +0200
  99014. @@ -27,7 +27,7 @@
  99015. #include "../integrity.h"
  99016. enum ima_show_type { IMA_SHOW_BINARY, IMA_SHOW_BINARY_NO_FIELD_LEN,
  99017. - IMA_SHOW_BINARY_OLD_STRING_FMT, IMA_SHOW_ASCII };
  99018. + IMA_SHOW_ASCII };
  99019. enum tpm_pcrs { TPM_PCR0 = 0, TPM_PCR8 = 8 };
  99020. /* digest size for IMA, fits SHA1 or MD5 */
  99021. diff -Nur linux-3.13.11/security/integrity/ima/ima_template_lib.c linux-rpi/security/integrity/ima/ima_template_lib.c
  99022. --- linux-3.13.11/security/integrity/ima/ima_template_lib.c 2014-04-23 01:49:33.000000000 +0200
  99023. +++ linux-rpi/security/integrity/ima/ima_template_lib.c 2014-04-24 15:37:23.591102731 +0200
  99024. @@ -109,16 +109,13 @@
  99025. enum data_formats datafmt,
  99026. struct ima_field_data *field_data)
  99027. {
  99028. - u32 len = (show == IMA_SHOW_BINARY_OLD_STRING_FMT) ?
  99029. - strlen(field_data->data) : field_data->len;
  99030. -
  99031. if (show != IMA_SHOW_BINARY_NO_FIELD_LEN)
  99032. - ima_putc(m, &len, sizeof(len));
  99033. + ima_putc(m, &field_data->len, sizeof(u32));
  99034. - if (!len)
  99035. + if (!field_data->len)
  99036. return;
  99037. - ima_putc(m, field_data->data, len);
  99038. + ima_putc(m, field_data->data, field_data->len);
  99039. }
  99040. static void ima_show_template_field_data(struct seq_file *m,
  99041. @@ -132,7 +129,6 @@
  99042. break;
  99043. case IMA_SHOW_BINARY:
  99044. case IMA_SHOW_BINARY_NO_FIELD_LEN:
  99045. - case IMA_SHOW_BINARY_OLD_STRING_FMT:
  99046. ima_show_template_data_binary(m, show, datafmt, field_data);
  99047. break;
  99048. default:
  99049. diff -Nur linux-3.13.11/sound/arm/bcm2835.c linux-rpi/sound/arm/bcm2835.c
  99050. --- linux-3.13.11/sound/arm/bcm2835.c 1970-01-01 01:00:00.000000000 +0100
  99051. +++ linux-rpi/sound/arm/bcm2835.c 2014-04-24 15:37:23.599102818 +0200
  99052. @@ -0,0 +1,420 @@
  99053. +/*****************************************************************************
  99054. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  99055. +*
  99056. +* Unless you and Broadcom execute a separate written software license
  99057. +* agreement governing use of this software, this software is licensed to you
  99058. +* under the terms of the GNU General Public License version 2, available at
  99059. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  99060. +*
  99061. +* Notwithstanding the above, under no circumstances may you combine this
  99062. +* software in any way with any other Broadcom software provided under a
  99063. +* license other than the GPL, without Broadcom's express prior written
  99064. +* consent.
  99065. +*****************************************************************************/
  99066. +
  99067. +#include <linux/platform_device.h>
  99068. +
  99069. +#include <linux/init.h>
  99070. +#include <linux/slab.h>
  99071. +#include <linux/module.h>
  99072. +
  99073. +#include "bcm2835.h"
  99074. +
  99075. +/* module parameters (see "Module Parameters") */
  99076. +/* SNDRV_CARDS: maximum number of cards supported by this module */
  99077. +static int index[MAX_SUBSTREAMS] = {[0 ... (MAX_SUBSTREAMS - 1)] = -1 };
  99078. +static char *id[MAX_SUBSTREAMS] = {[0 ... (MAX_SUBSTREAMS - 1)] = NULL };
  99079. +static int enable[MAX_SUBSTREAMS] = {[0 ... (MAX_SUBSTREAMS - 1)] = 1 };
  99080. +
  99081. +/* HACKY global pointers needed for successive probes to work : ssp
  99082. + * But compared against the changes we will have to do in VC audio_ipc code
  99083. + * to export 8 audio_ipc devices as a single IPC device and then monitor all
  99084. + * four devices in a thread, this gets things done quickly and should be easier
  99085. + * to debug if we run into issues
  99086. + */
  99087. +
  99088. +static struct snd_card *g_card = NULL;
  99089. +static bcm2835_chip_t *g_chip = NULL;
  99090. +
  99091. +static int snd_bcm2835_free(bcm2835_chip_t * chip)
  99092. +{
  99093. + kfree(chip);
  99094. + return 0;
  99095. +}
  99096. +
  99097. +/* component-destructor
  99098. + * (see "Management of Cards and Components")
  99099. + */
  99100. +static int snd_bcm2835_dev_free(struct snd_device *device)
  99101. +{
  99102. + return snd_bcm2835_free(device->device_data);
  99103. +}
  99104. +
  99105. +/* chip-specific constructor
  99106. + * (see "Management of Cards and Components")
  99107. + */
  99108. +static int snd_bcm2835_create(struct snd_card *card,
  99109. + struct platform_device *pdev,
  99110. + bcm2835_chip_t ** rchip)
  99111. +{
  99112. + bcm2835_chip_t *chip;
  99113. + int err;
  99114. + static struct snd_device_ops ops = {
  99115. + .dev_free = snd_bcm2835_dev_free,
  99116. + };
  99117. +
  99118. + *rchip = NULL;
  99119. +
  99120. + chip = kzalloc(sizeof(*chip), GFP_KERNEL);
  99121. + if (chip == NULL)
  99122. + return -ENOMEM;
  99123. +
  99124. + chip->card = card;
  99125. +
  99126. + err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
  99127. + if (err < 0) {
  99128. + snd_bcm2835_free(chip);
  99129. + return err;
  99130. + }
  99131. +
  99132. + *rchip = chip;
  99133. + return 0;
  99134. +}
  99135. +
  99136. +static int snd_bcm2835_alsa_probe(struct platform_device *pdev)
  99137. +{
  99138. + static int dev;
  99139. + bcm2835_chip_t *chip;
  99140. + struct snd_card *card;
  99141. + int err;
  99142. +
  99143. + if (dev >= MAX_SUBSTREAMS)
  99144. + return -ENODEV;
  99145. +
  99146. + if (!enable[dev]) {
  99147. + dev++;
  99148. + return -ENOENT;
  99149. + }
  99150. +
  99151. + if (dev > 0)
  99152. + goto add_register_map;
  99153. +
  99154. + err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &g_card);
  99155. + if (err < 0)
  99156. + goto out;
  99157. +
  99158. + snd_card_set_dev(g_card, &pdev->dev);
  99159. + strcpy(g_card->driver, "bcm2835");
  99160. + strcpy(g_card->shortname, "bcm2835 ALSA");
  99161. + sprintf(g_card->longname, "%s", g_card->shortname);
  99162. +
  99163. + err = snd_bcm2835_create(g_card, pdev, &chip);
  99164. + if (err < 0) {
  99165. + dev_err(&pdev->dev, "Failed to create bcm2835 chip\n");
  99166. + goto out_bcm2835_create;
  99167. + }
  99168. +
  99169. + g_chip = chip;
  99170. + err = snd_bcm2835_new_pcm(chip);
  99171. + if (err < 0) {
  99172. + dev_err(&pdev->dev, "Failed to create new BCM2835 pcm device\n");
  99173. + goto out_bcm2835_new_pcm;
  99174. + }
  99175. +
  99176. + err = snd_bcm2835_new_spdif_pcm(chip);
  99177. + if (err < 0) {
  99178. + dev_err(&pdev->dev, "Failed to create new BCM2835 spdif pcm device\n");
  99179. + goto out_bcm2835_new_spdif;
  99180. + }
  99181. +
  99182. + err = snd_bcm2835_new_ctl(chip);
  99183. + if (err < 0) {
  99184. + dev_err(&pdev->dev, "Failed to create new BCM2835 ctl\n");
  99185. + goto out_bcm2835_new_ctl;
  99186. + }
  99187. +
  99188. +add_register_map:
  99189. + card = g_card;
  99190. + chip = g_chip;
  99191. +
  99192. + BUG_ON(!(card && chip));
  99193. +
  99194. + chip->avail_substreams |= (1 << dev);
  99195. + chip->pdev[dev] = pdev;
  99196. +
  99197. + if (dev == 0) {
  99198. + err = snd_card_register(card);
  99199. + if (err < 0) {
  99200. + dev_err(&pdev->dev,
  99201. + "Failed to register bcm2835 ALSA card \n");
  99202. + goto out_card_register;
  99203. + }
  99204. + platform_set_drvdata(pdev, card);
  99205. + audio_info("bcm2835 ALSA card created!\n");
  99206. + } else {
  99207. + audio_info("bcm2835 ALSA chip created!\n");
  99208. + platform_set_drvdata(pdev, (void *)dev);
  99209. + }
  99210. +
  99211. + dev++;
  99212. +
  99213. + return 0;
  99214. +
  99215. +out_card_register:
  99216. +out_bcm2835_new_ctl:
  99217. +out_bcm2835_new_spdif:
  99218. +out_bcm2835_new_pcm:
  99219. +out_bcm2835_create:
  99220. + BUG_ON(!g_card);
  99221. + if (snd_card_free(g_card))
  99222. + dev_err(&pdev->dev, "Failed to free Registered alsa card\n");
  99223. + g_card = NULL;
  99224. +out:
  99225. + dev = SNDRV_CARDS; /* stop more avail_substreams from being probed */
  99226. + dev_err(&pdev->dev, "BCM2835 ALSA Probe failed !!\n");
  99227. + return err;
  99228. +}
  99229. +
  99230. +static int snd_bcm2835_alsa_remove(struct platform_device *pdev)
  99231. +{
  99232. + uint32_t idx;
  99233. + void *drv_data;
  99234. +
  99235. + drv_data = platform_get_drvdata(pdev);
  99236. +
  99237. + if (drv_data == (void *)g_card) {
  99238. + /* This is the card device */
  99239. + snd_card_free((struct snd_card *)drv_data);
  99240. + g_card = NULL;
  99241. + g_chip = NULL;
  99242. + } else {
  99243. + idx = (uint32_t) drv_data;
  99244. + if (g_card != NULL) {
  99245. + BUG_ON(!g_chip);
  99246. + /* We pass chip device numbers in audio ipc devices
  99247. + * other than the one we registered our card with
  99248. + */
  99249. + idx = (uint32_t) drv_data;
  99250. + BUG_ON(!idx || idx > MAX_SUBSTREAMS);
  99251. + g_chip->avail_substreams &= ~(1 << idx);
  99252. + /* There should be atleast one substream registered
  99253. + * after we are done here, as it wil be removed when
  99254. + * the *remove* is called for the card device
  99255. + */
  99256. + BUG_ON(!g_chip->avail_substreams);
  99257. + }
  99258. + }
  99259. +
  99260. + platform_set_drvdata(pdev, NULL);
  99261. +
  99262. + return 0;
  99263. +}
  99264. +
  99265. +#ifdef CONFIG_PM
  99266. +static int snd_bcm2835_alsa_suspend(struct platform_device *pdev,
  99267. + pm_message_t state)
  99268. +{
  99269. + return 0;
  99270. +}
  99271. +
  99272. +static int snd_bcm2835_alsa_resume(struct platform_device *pdev)
  99273. +{
  99274. + return 0;
  99275. +}
  99276. +
  99277. +#endif
  99278. +
  99279. +static struct platform_driver bcm2835_alsa0_driver = {
  99280. + .probe = snd_bcm2835_alsa_probe,
  99281. + .remove = snd_bcm2835_alsa_remove,
  99282. +#ifdef CONFIG_PM
  99283. + .suspend = snd_bcm2835_alsa_suspend,
  99284. + .resume = snd_bcm2835_alsa_resume,
  99285. +#endif
  99286. + .driver = {
  99287. + .name = "bcm2835_AUD0",
  99288. + .owner = THIS_MODULE,
  99289. + },
  99290. +};
  99291. +
  99292. +static struct platform_driver bcm2835_alsa1_driver = {
  99293. + .probe = snd_bcm2835_alsa_probe,
  99294. + .remove = snd_bcm2835_alsa_remove,
  99295. +#ifdef CONFIG_PM
  99296. + .suspend = snd_bcm2835_alsa_suspend,
  99297. + .resume = snd_bcm2835_alsa_resume,
  99298. +#endif
  99299. + .driver = {
  99300. + .name = "bcm2835_AUD1",
  99301. + .owner = THIS_MODULE,
  99302. + },
  99303. +};
  99304. +
  99305. +static struct platform_driver bcm2835_alsa2_driver = {
  99306. + .probe = snd_bcm2835_alsa_probe,
  99307. + .remove = snd_bcm2835_alsa_remove,
  99308. +#ifdef CONFIG_PM
  99309. + .suspend = snd_bcm2835_alsa_suspend,
  99310. + .resume = snd_bcm2835_alsa_resume,
  99311. +#endif
  99312. + .driver = {
  99313. + .name = "bcm2835_AUD2",
  99314. + .owner = THIS_MODULE,
  99315. + },
  99316. +};
  99317. +
  99318. +static struct platform_driver bcm2835_alsa3_driver = {
  99319. + .probe = snd_bcm2835_alsa_probe,
  99320. + .remove = snd_bcm2835_alsa_remove,
  99321. +#ifdef CONFIG_PM
  99322. + .suspend = snd_bcm2835_alsa_suspend,
  99323. + .resume = snd_bcm2835_alsa_resume,
  99324. +#endif
  99325. + .driver = {
  99326. + .name = "bcm2835_AUD3",
  99327. + .owner = THIS_MODULE,
  99328. + },
  99329. +};
  99330. +
  99331. +static struct platform_driver bcm2835_alsa4_driver = {
  99332. + .probe = snd_bcm2835_alsa_probe,
  99333. + .remove = snd_bcm2835_alsa_remove,
  99334. +#ifdef CONFIG_PM
  99335. + .suspend = snd_bcm2835_alsa_suspend,
  99336. + .resume = snd_bcm2835_alsa_resume,
  99337. +#endif
  99338. + .driver = {
  99339. + .name = "bcm2835_AUD4",
  99340. + .owner = THIS_MODULE,
  99341. + },
  99342. +};
  99343. +
  99344. +static struct platform_driver bcm2835_alsa5_driver = {
  99345. + .probe = snd_bcm2835_alsa_probe,
  99346. + .remove = snd_bcm2835_alsa_remove,
  99347. +#ifdef CONFIG_PM
  99348. + .suspend = snd_bcm2835_alsa_suspend,
  99349. + .resume = snd_bcm2835_alsa_resume,
  99350. +#endif
  99351. + .driver = {
  99352. + .name = "bcm2835_AUD5",
  99353. + .owner = THIS_MODULE,
  99354. + },
  99355. +};
  99356. +
  99357. +static struct platform_driver bcm2835_alsa6_driver = {
  99358. + .probe = snd_bcm2835_alsa_probe,
  99359. + .remove = snd_bcm2835_alsa_remove,
  99360. +#ifdef CONFIG_PM
  99361. + .suspend = snd_bcm2835_alsa_suspend,
  99362. + .resume = snd_bcm2835_alsa_resume,
  99363. +#endif
  99364. + .driver = {
  99365. + .name = "bcm2835_AUD6",
  99366. + .owner = THIS_MODULE,
  99367. + },
  99368. +};
  99369. +
  99370. +static struct platform_driver bcm2835_alsa7_driver = {
  99371. + .probe = snd_bcm2835_alsa_probe,
  99372. + .remove = snd_bcm2835_alsa_remove,
  99373. +#ifdef CONFIG_PM
  99374. + .suspend = snd_bcm2835_alsa_suspend,
  99375. + .resume = snd_bcm2835_alsa_resume,
  99376. +#endif
  99377. + .driver = {
  99378. + .name = "bcm2835_AUD7",
  99379. + .owner = THIS_MODULE,
  99380. + },
  99381. +};
  99382. +
  99383. +static int bcm2835_alsa_device_init(void)
  99384. +{
  99385. + int err;
  99386. + err = platform_driver_register(&bcm2835_alsa0_driver);
  99387. + if (err) {
  99388. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  99389. + goto out;
  99390. + }
  99391. +
  99392. + err = platform_driver_register(&bcm2835_alsa1_driver);
  99393. + if (err) {
  99394. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  99395. + goto unregister_0;
  99396. + }
  99397. +
  99398. + err = platform_driver_register(&bcm2835_alsa2_driver);
  99399. + if (err) {
  99400. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  99401. + goto unregister_1;
  99402. + }
  99403. +
  99404. + err = platform_driver_register(&bcm2835_alsa3_driver);
  99405. + if (err) {
  99406. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  99407. + goto unregister_2;
  99408. + }
  99409. +
  99410. + err = platform_driver_register(&bcm2835_alsa4_driver);
  99411. + if (err) {
  99412. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  99413. + goto unregister_3;
  99414. + }
  99415. +
  99416. + err = platform_driver_register(&bcm2835_alsa5_driver);
  99417. + if (err) {
  99418. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  99419. + goto unregister_4;
  99420. + }
  99421. +
  99422. + err = platform_driver_register(&bcm2835_alsa6_driver);
  99423. + if (err) {
  99424. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  99425. + goto unregister_5;
  99426. + }
  99427. +
  99428. + err = platform_driver_register(&bcm2835_alsa7_driver);
  99429. + if (err) {
  99430. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  99431. + goto unregister_6;
  99432. + }
  99433. +
  99434. + return 0;
  99435. +
  99436. +unregister_6:
  99437. + platform_driver_unregister(&bcm2835_alsa6_driver);
  99438. +unregister_5:
  99439. + platform_driver_unregister(&bcm2835_alsa5_driver);
  99440. +unregister_4:
  99441. + platform_driver_unregister(&bcm2835_alsa4_driver);
  99442. +unregister_3:
  99443. + platform_driver_unregister(&bcm2835_alsa3_driver);
  99444. +unregister_2:
  99445. + platform_driver_unregister(&bcm2835_alsa2_driver);
  99446. +unregister_1:
  99447. + platform_driver_unregister(&bcm2835_alsa1_driver);
  99448. +unregister_0:
  99449. + platform_driver_unregister(&bcm2835_alsa0_driver);
  99450. +out:
  99451. + return err;
  99452. +}
  99453. +
  99454. +static void bcm2835_alsa_device_exit(void)
  99455. +{
  99456. + platform_driver_unregister(&bcm2835_alsa0_driver);
  99457. + platform_driver_unregister(&bcm2835_alsa1_driver);
  99458. + platform_driver_unregister(&bcm2835_alsa2_driver);
  99459. + platform_driver_unregister(&bcm2835_alsa3_driver);
  99460. + platform_driver_unregister(&bcm2835_alsa4_driver);
  99461. + platform_driver_unregister(&bcm2835_alsa5_driver);
  99462. + platform_driver_unregister(&bcm2835_alsa6_driver);
  99463. + platform_driver_unregister(&bcm2835_alsa7_driver);
  99464. +}
  99465. +
  99466. +late_initcall(bcm2835_alsa_device_init);
  99467. +module_exit(bcm2835_alsa_device_exit);
  99468. +
  99469. +MODULE_AUTHOR("Dom Cobley");
  99470. +MODULE_DESCRIPTION("Alsa driver for BCM2835 chip");
  99471. +MODULE_LICENSE("GPL");
  99472. +MODULE_ALIAS("platform:bcm2835_alsa");
  99473. diff -Nur linux-3.13.11/sound/arm/bcm2835-ctl.c linux-rpi/sound/arm/bcm2835-ctl.c
  99474. --- linux-3.13.11/sound/arm/bcm2835-ctl.c 1970-01-01 01:00:00.000000000 +0100
  99475. +++ linux-rpi/sound/arm/bcm2835-ctl.c 2014-04-24 15:37:23.599102818 +0200
  99476. @@ -0,0 +1,323 @@
  99477. +/*****************************************************************************
  99478. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  99479. +*
  99480. +* Unless you and Broadcom execute a separate written software license
  99481. +* agreement governing use of this software, this software is licensed to you
  99482. +* under the terms of the GNU General Public License version 2, available at
  99483. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  99484. +*
  99485. +* Notwithstanding the above, under no circumstances may you combine this
  99486. +* software in any way with any other Broadcom software provided under a
  99487. +* license other than the GPL, without Broadcom's express prior written
  99488. +* consent.
  99489. +*****************************************************************************/
  99490. +
  99491. +#include <linux/platform_device.h>
  99492. +#include <linux/init.h>
  99493. +#include <linux/io.h>
  99494. +#include <linux/jiffies.h>
  99495. +#include <linux/slab.h>
  99496. +#include <linux/time.h>
  99497. +#include <linux/wait.h>
  99498. +#include <linux/delay.h>
  99499. +#include <linux/moduleparam.h>
  99500. +#include <linux/sched.h>
  99501. +
  99502. +#include <sound/core.h>
  99503. +#include <sound/control.h>
  99504. +#include <sound/pcm.h>
  99505. +#include <sound/pcm_params.h>
  99506. +#include <sound/rawmidi.h>
  99507. +#include <sound/initval.h>
  99508. +#include <sound/tlv.h>
  99509. +#include <sound/asoundef.h>
  99510. +
  99511. +#include "bcm2835.h"
  99512. +
  99513. +/* volume maximum and minimum in terms of 0.01dB */
  99514. +#define CTRL_VOL_MAX 400
  99515. +#define CTRL_VOL_MIN -10239 /* originally -10240 */
  99516. +
  99517. +
  99518. +static int snd_bcm2835_ctl_info(struct snd_kcontrol *kcontrol,
  99519. + struct snd_ctl_elem_info *uinfo)
  99520. +{
  99521. + audio_info(" ... IN\n");
  99522. + if (kcontrol->private_value == PCM_PLAYBACK_VOLUME) {
  99523. + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  99524. + uinfo->count = 1;
  99525. + uinfo->value.integer.min = CTRL_VOL_MIN;
  99526. + uinfo->value.integer.max = CTRL_VOL_MAX; /* 2303 */
  99527. + } else if (kcontrol->private_value == PCM_PLAYBACK_MUTE) {
  99528. + uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  99529. + uinfo->count = 1;
  99530. + uinfo->value.integer.min = 0;
  99531. + uinfo->value.integer.max = 1;
  99532. + } else if (kcontrol->private_value == PCM_PLAYBACK_DEVICE) {
  99533. + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  99534. + uinfo->count = 1;
  99535. + uinfo->value.integer.min = 0;
  99536. + uinfo->value.integer.max = AUDIO_DEST_MAX-1;
  99537. + }
  99538. + audio_info(" ... OUT\n");
  99539. + return 0;
  99540. +}
  99541. +
  99542. +/* toggles mute on or off depending on the value of nmute, and returns
  99543. + * 1 if the mute value was changed, otherwise 0
  99544. + */
  99545. +static int toggle_mute(struct bcm2835_chip *chip, int nmute)
  99546. +{
  99547. + /* if settings are ok, just return 0 */
  99548. + if(chip->mute == nmute)
  99549. + return 0;
  99550. +
  99551. + /* if the sound is muted then we need to unmute */
  99552. + if(chip->mute == CTRL_VOL_MUTE)
  99553. + {
  99554. + chip->volume = chip->old_volume; /* copy the old volume back */
  99555. + audio_info("Unmuting, old_volume = %d, volume = %d ...\n", chip->old_volume, chip->volume);
  99556. + }
  99557. + else /* otherwise we mute */
  99558. + {
  99559. + chip->old_volume = chip->volume;
  99560. + chip->volume = 26214; /* set volume to minimum level AKA mute */
  99561. + audio_info("Muting, old_volume = %d, volume = %d ...\n", chip->old_volume, chip->volume);
  99562. + }
  99563. +
  99564. + chip->mute = nmute;
  99565. + return 1;
  99566. +}
  99567. +
  99568. +static int snd_bcm2835_ctl_get(struct snd_kcontrol *kcontrol,
  99569. + struct snd_ctl_elem_value *ucontrol)
  99570. +{
  99571. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  99572. +
  99573. + BUG_ON(!chip && !(chip->avail_substreams & AVAIL_SUBSTREAMS_MASK));
  99574. +
  99575. + if (kcontrol->private_value == PCM_PLAYBACK_VOLUME)
  99576. + ucontrol->value.integer.value[0] = chip2alsa(chip->volume);
  99577. + else if (kcontrol->private_value == PCM_PLAYBACK_MUTE)
  99578. + ucontrol->value.integer.value[0] = chip->mute;
  99579. + else if (kcontrol->private_value == PCM_PLAYBACK_DEVICE)
  99580. + ucontrol->value.integer.value[0] = chip->dest;
  99581. +
  99582. + return 0;
  99583. +}
  99584. +
  99585. +static int snd_bcm2835_ctl_put(struct snd_kcontrol *kcontrol,
  99586. + struct snd_ctl_elem_value *ucontrol)
  99587. +{
  99588. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  99589. + int changed = 0;
  99590. +
  99591. + if (kcontrol->private_value == PCM_PLAYBACK_VOLUME) {
  99592. + audio_info("Volume change attempted.. volume = %d new_volume = %d\n", chip->volume, (int)ucontrol->value.integer.value[0]);
  99593. + if (chip->mute == CTRL_VOL_MUTE) {
  99594. + /* changed = toggle_mute(chip, CTRL_VOL_UNMUTE); */
  99595. + return 1; /* should return 0 to signify no change but the mixer takes this as the opposite sign (no idea why) */
  99596. + }
  99597. + if (changed
  99598. + || (ucontrol->value.integer.value[0] != chip2alsa(chip->volume))) {
  99599. +
  99600. + chip->volume = alsa2chip(ucontrol->value.integer.value[0]);
  99601. + changed = 1;
  99602. + }
  99603. +
  99604. + } else if (kcontrol->private_value == PCM_PLAYBACK_MUTE) {
  99605. + /* Now implemented */
  99606. + audio_info(" Mute attempted\n");
  99607. + changed = toggle_mute(chip, ucontrol->value.integer.value[0]);
  99608. +
  99609. + } else if (kcontrol->private_value == PCM_PLAYBACK_DEVICE) {
  99610. + if (ucontrol->value.integer.value[0] != chip->dest) {
  99611. + chip->dest = ucontrol->value.integer.value[0];
  99612. + changed = 1;
  99613. + }
  99614. + }
  99615. +
  99616. + if (changed) {
  99617. + if (bcm2835_audio_set_ctls(chip))
  99618. + printk(KERN_ERR "Failed to set ALSA controls..\n");
  99619. + }
  99620. +
  99621. + return changed;
  99622. +}
  99623. +
  99624. +static DECLARE_TLV_DB_SCALE(snd_bcm2835_db_scale, CTRL_VOL_MIN, 1, 1);
  99625. +
  99626. +static struct snd_kcontrol_new snd_bcm2835_ctl[] = {
  99627. + {
  99628. + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  99629. + .name = "PCM Playback Volume",
  99630. + .index = 0,
  99631. + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ,
  99632. + .private_value = PCM_PLAYBACK_VOLUME,
  99633. + .info = snd_bcm2835_ctl_info,
  99634. + .get = snd_bcm2835_ctl_get,
  99635. + .put = snd_bcm2835_ctl_put,
  99636. + .count = 1,
  99637. + .tlv = {.p = snd_bcm2835_db_scale}
  99638. + },
  99639. + {
  99640. + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  99641. + .name = "PCM Playback Switch",
  99642. + .index = 0,
  99643. + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  99644. + .private_value = PCM_PLAYBACK_MUTE,
  99645. + .info = snd_bcm2835_ctl_info,
  99646. + .get = snd_bcm2835_ctl_get,
  99647. + .put = snd_bcm2835_ctl_put,
  99648. + .count = 1,
  99649. + },
  99650. + {
  99651. + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  99652. + .name = "PCM Playback Route",
  99653. + .index = 0,
  99654. + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  99655. + .private_value = PCM_PLAYBACK_DEVICE,
  99656. + .info = snd_bcm2835_ctl_info,
  99657. + .get = snd_bcm2835_ctl_get,
  99658. + .put = snd_bcm2835_ctl_put,
  99659. + .count = 1,
  99660. + },
  99661. +};
  99662. +
  99663. +static int snd_bcm2835_spdif_default_info(struct snd_kcontrol *kcontrol,
  99664. + struct snd_ctl_elem_info *uinfo)
  99665. +{
  99666. + uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  99667. + uinfo->count = 1;
  99668. + return 0;
  99669. +}
  99670. +
  99671. +static int snd_bcm2835_spdif_default_get(struct snd_kcontrol *kcontrol,
  99672. + struct snd_ctl_elem_value *ucontrol)
  99673. +{
  99674. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  99675. + int i;
  99676. +
  99677. + for (i = 0; i < 4; i++)
  99678. + ucontrol->value.iec958.status[i] =
  99679. + (chip->spdif_status >> (i * 8)) && 0xff;
  99680. +
  99681. + return 0;
  99682. +}
  99683. +
  99684. +static int snd_bcm2835_spdif_default_put(struct snd_kcontrol *kcontrol,
  99685. + struct snd_ctl_elem_value *ucontrol)
  99686. +{
  99687. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  99688. + unsigned int val = 0;
  99689. + int i, change;
  99690. +
  99691. + for (i = 0; i < 4; i++)
  99692. + val |= (unsigned int)ucontrol->value.iec958.status[i] << (i * 8);
  99693. +
  99694. + change = val != chip->spdif_status;
  99695. + chip->spdif_status = val;
  99696. +
  99697. + return change;
  99698. +}
  99699. +
  99700. +static int snd_bcm2835_spdif_mask_info(struct snd_kcontrol *kcontrol,
  99701. + struct snd_ctl_elem_info *uinfo)
  99702. +{
  99703. + uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  99704. + uinfo->count = 1;
  99705. + return 0;
  99706. +}
  99707. +
  99708. +static int snd_bcm2835_spdif_mask_get(struct snd_kcontrol *kcontrol,
  99709. + struct snd_ctl_elem_value *ucontrol)
  99710. +{
  99711. + /* bcm2835 supports only consumer mode and sets all other format flags
  99712. + * automatically. So the only thing left is signalling non-audio
  99713. + * content */
  99714. + ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO;
  99715. + return 0;
  99716. +}
  99717. +
  99718. +static int snd_bcm2835_spdif_stream_info(struct snd_kcontrol *kcontrol,
  99719. + struct snd_ctl_elem_info *uinfo)
  99720. +{
  99721. + uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  99722. + uinfo->count = 1;
  99723. + return 0;
  99724. +}
  99725. +
  99726. +static int snd_bcm2835_spdif_stream_get(struct snd_kcontrol *kcontrol,
  99727. + struct snd_ctl_elem_value *ucontrol)
  99728. +{
  99729. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  99730. + int i;
  99731. +
  99732. + for (i = 0; i < 4; i++)
  99733. + ucontrol->value.iec958.status[i] =
  99734. + (chip->spdif_status >> (i * 8)) & 0xff;
  99735. + return 0;
  99736. +}
  99737. +
  99738. +static int snd_bcm2835_spdif_stream_put(struct snd_kcontrol *kcontrol,
  99739. + struct snd_ctl_elem_value *ucontrol)
  99740. +{
  99741. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  99742. + unsigned int val = 0;
  99743. + int i, change;
  99744. +
  99745. + for (i = 0; i < 4; i++)
  99746. + val |= (unsigned int)ucontrol->value.iec958.status[i] << (i * 8);
  99747. + change = val != chip->spdif_status;
  99748. + chip->spdif_status = val;
  99749. +
  99750. + return change;
  99751. +}
  99752. +
  99753. +static struct snd_kcontrol_new snd_bcm2835_spdif[] = {
  99754. + {
  99755. + .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  99756. + .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
  99757. + .info = snd_bcm2835_spdif_default_info,
  99758. + .get = snd_bcm2835_spdif_default_get,
  99759. + .put = snd_bcm2835_spdif_default_put
  99760. + },
  99761. + {
  99762. + .access = SNDRV_CTL_ELEM_ACCESS_READ,
  99763. + .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  99764. + .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, CON_MASK),
  99765. + .info = snd_bcm2835_spdif_mask_info,
  99766. + .get = snd_bcm2835_spdif_mask_get,
  99767. + },
  99768. + {
  99769. + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
  99770. + SNDRV_CTL_ELEM_ACCESS_INACTIVE,
  99771. + .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  99772. + .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, PCM_STREAM),
  99773. + .info = snd_bcm2835_spdif_stream_info,
  99774. + .get = snd_bcm2835_spdif_stream_get,
  99775. + .put = snd_bcm2835_spdif_stream_put,
  99776. + },
  99777. +};
  99778. +
  99779. +int snd_bcm2835_new_ctl(bcm2835_chip_t * chip)
  99780. +{
  99781. + int err;
  99782. + unsigned int idx;
  99783. +
  99784. + strcpy(chip->card->mixername, "Broadcom Mixer");
  99785. + for (idx = 0; idx < ARRAY_SIZE(snd_bcm2835_ctl); idx++) {
  99786. + err =
  99787. + snd_ctl_add(chip->card,
  99788. + snd_ctl_new1(&snd_bcm2835_ctl[idx], chip));
  99789. + if (err < 0)
  99790. + return err;
  99791. + }
  99792. + for (idx = 0; idx < ARRAY_SIZE(snd_bcm2835_spdif); idx++) {
  99793. + err = snd_ctl_add(chip->card,
  99794. + snd_ctl_new1(&snd_bcm2835_spdif[idx], chip));
  99795. + if (err < 0)
  99796. + return err;
  99797. + }
  99798. + return 0;
  99799. +}
  99800. diff -Nur linux-3.13.11/sound/arm/bcm2835.h linux-rpi/sound/arm/bcm2835.h
  99801. --- linux-3.13.11/sound/arm/bcm2835.h 1970-01-01 01:00:00.000000000 +0100
  99802. +++ linux-rpi/sound/arm/bcm2835.h 2014-04-24 15:37:23.603102862 +0200
  99803. @@ -0,0 +1,166 @@
  99804. +/*****************************************************************************
  99805. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  99806. +*
  99807. +* Unless you and Broadcom execute a separate written software license
  99808. +* agreement governing use of this software, this software is licensed to you
  99809. +* under the terms of the GNU General Public License version 2, available at
  99810. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  99811. +*
  99812. +* Notwithstanding the above, under no circumstances may you combine this
  99813. +* software in any way with any other Broadcom software provided under a
  99814. +* license other than the GPL, without Broadcom's express prior written
  99815. +* consent.
  99816. +*****************************************************************************/
  99817. +
  99818. +#ifndef __SOUND_ARM_BCM2835_H
  99819. +#define __SOUND_ARM_BCM2835_H
  99820. +
  99821. +#include <linux/device.h>
  99822. +#include <linux/list.h>
  99823. +#include <linux/interrupt.h>
  99824. +#include <linux/wait.h>
  99825. +#include <sound/core.h>
  99826. +#include <sound/initval.h>
  99827. +#include <sound/pcm.h>
  99828. +#include <sound/pcm_params.h>
  99829. +#include <sound/pcm-indirect.h>
  99830. +#include <linux/workqueue.h>
  99831. +
  99832. +/*
  99833. +#define AUDIO_DEBUG_ENABLE
  99834. +#define AUDIO_VERBOSE_DEBUG_ENABLE
  99835. +*/
  99836. +
  99837. +/* Debug macros */
  99838. +
  99839. +#ifdef AUDIO_DEBUG_ENABLE
  99840. +#ifdef AUDIO_VERBOSE_DEBUG_ENABLE
  99841. +
  99842. +#define audio_debug(fmt, arg...) \
  99843. + printk(KERN_INFO"%s:%d " fmt, __func__, __LINE__, ##arg)
  99844. +
  99845. +#define audio_info(fmt, arg...) \
  99846. + printk(KERN_INFO"%s:%d " fmt, __func__, __LINE__, ##arg)
  99847. +
  99848. +#else
  99849. +
  99850. +#define audio_debug(fmt, arg...)
  99851. +
  99852. +#define audio_info(fmt, arg...)
  99853. +
  99854. +#endif /* AUDIO_VERBOSE_DEBUG_ENABLE */
  99855. +
  99856. +#else
  99857. +
  99858. +#define audio_debug(fmt, arg...)
  99859. +
  99860. +#define audio_info(fmt, arg...)
  99861. +
  99862. +#endif /* AUDIO_DEBUG_ENABLE */
  99863. +
  99864. +#define audio_error(fmt, arg...) \
  99865. + printk(KERN_ERR"%s:%d " fmt, __func__, __LINE__, ##arg)
  99866. +
  99867. +#define audio_warning(fmt, arg...) \
  99868. + printk(KERN_WARNING"%s:%d " fmt, __func__, __LINE__, ##arg)
  99869. +
  99870. +#define audio_alert(fmt, arg...) \
  99871. + printk(KERN_ALERT"%s:%d " fmt, __func__, __LINE__, ##arg)
  99872. +
  99873. +#define MAX_SUBSTREAMS (8)
  99874. +#define AVAIL_SUBSTREAMS_MASK (0xff)
  99875. +enum {
  99876. + CTRL_VOL_MUTE,
  99877. + CTRL_VOL_UNMUTE
  99878. +};
  99879. +
  99880. +/* macros for alsa2chip and chip2alsa, instead of functions */
  99881. +
  99882. +#define alsa2chip(vol) (uint)(-((vol << 8) / 100)) /* convert alsa to chip volume (defined as macro rather than function call) */
  99883. +#define chip2alsa(vol) -((vol * 100) >> 8) /* convert chip to alsa volume */
  99884. +
  99885. +/* Some constants for values .. */
  99886. +typedef enum {
  99887. + AUDIO_DEST_AUTO = 0,
  99888. + AUDIO_DEST_HEADPHONES = 1,
  99889. + AUDIO_DEST_HDMI = 2,
  99890. + AUDIO_DEST_MAX,
  99891. +} SND_BCM2835_ROUTE_T;
  99892. +
  99893. +typedef enum {
  99894. + PCM_PLAYBACK_VOLUME,
  99895. + PCM_PLAYBACK_MUTE,
  99896. + PCM_PLAYBACK_DEVICE,
  99897. +} SND_BCM2835_CTRL_T;
  99898. +
  99899. +/* definition of the chip-specific record */
  99900. +typedef struct bcm2835_chip {
  99901. + struct snd_card *card;
  99902. + struct snd_pcm *pcm;
  99903. + struct snd_pcm *pcm_spdif;
  99904. + /* Bitmat for valid reg_base and irq numbers */
  99905. + uint32_t avail_substreams;
  99906. + struct platform_device *pdev[MAX_SUBSTREAMS];
  99907. + struct bcm2835_alsa_stream *alsa_stream[MAX_SUBSTREAMS];
  99908. +
  99909. + int volume;
  99910. + int old_volume; /* stores the volume value whist muted */
  99911. + int dest;
  99912. + int mute;
  99913. +
  99914. + unsigned int opened;
  99915. + unsigned int spdif_status;
  99916. +} bcm2835_chip_t;
  99917. +
  99918. +typedef struct bcm2835_alsa_stream {
  99919. + bcm2835_chip_t *chip;
  99920. + struct snd_pcm_substream *substream;
  99921. + struct snd_pcm_indirect pcm_indirect;
  99922. +
  99923. + struct semaphore buffers_update_sem;
  99924. + struct semaphore control_sem;
  99925. + spinlock_t lock;
  99926. + volatile uint32_t control;
  99927. + volatile uint32_t status;
  99928. +
  99929. + int open;
  99930. + int running;
  99931. + int draining;
  99932. +
  99933. + int channels;
  99934. + int params_rate;
  99935. + int pcm_format_width;
  99936. +
  99937. + unsigned int pos;
  99938. + unsigned int buffer_size;
  99939. + unsigned int period_size;
  99940. +
  99941. + uint32_t enable_fifo_irq;
  99942. + irq_handler_t fifo_irq_handler;
  99943. +
  99944. + atomic_t retrieved;
  99945. + struct opaque_AUDIO_INSTANCE_T *instance;
  99946. + struct workqueue_struct *my_wq;
  99947. + int idx;
  99948. +} bcm2835_alsa_stream_t;
  99949. +
  99950. +int snd_bcm2835_new_ctl(bcm2835_chip_t * chip);
  99951. +int snd_bcm2835_new_pcm(bcm2835_chip_t * chip);
  99952. +int snd_bcm2835_new_spdif_pcm(bcm2835_chip_t * chip);
  99953. +
  99954. +int bcm2835_audio_open(bcm2835_alsa_stream_t * alsa_stream);
  99955. +int bcm2835_audio_close(bcm2835_alsa_stream_t * alsa_stream);
  99956. +int bcm2835_audio_set_params(bcm2835_alsa_stream_t * alsa_stream,
  99957. + uint32_t channels, uint32_t samplerate,
  99958. + uint32_t bps);
  99959. +int bcm2835_audio_setup(bcm2835_alsa_stream_t * alsa_stream);
  99960. +int bcm2835_audio_start(bcm2835_alsa_stream_t * alsa_stream);
  99961. +int bcm2835_audio_stop(bcm2835_alsa_stream_t * alsa_stream);
  99962. +int bcm2835_audio_set_ctls(bcm2835_chip_t * chip);
  99963. +int bcm2835_audio_write(bcm2835_alsa_stream_t * alsa_stream, uint32_t count,
  99964. + void *src);
  99965. +uint32_t bcm2835_audio_retrieve_buffers(bcm2835_alsa_stream_t * alsa_stream);
  99966. +void bcm2835_audio_flush_buffers(bcm2835_alsa_stream_t * alsa_stream);
  99967. +void bcm2835_audio_flush_playback_buffers(bcm2835_alsa_stream_t * alsa_stream);
  99968. +
  99969. +#endif /* __SOUND_ARM_BCM2835_H */
  99970. diff -Nur linux-3.13.11/sound/arm/bcm2835-pcm.c linux-rpi/sound/arm/bcm2835-pcm.c
  99971. --- linux-3.13.11/sound/arm/bcm2835-pcm.c 1970-01-01 01:00:00.000000000 +0100
  99972. +++ linux-rpi/sound/arm/bcm2835-pcm.c 2014-04-24 15:37:23.599102818 +0200
  99973. @@ -0,0 +1,518 @@
  99974. +/*****************************************************************************
  99975. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  99976. +*
  99977. +* Unless you and Broadcom execute a separate written software license
  99978. +* agreement governing use of this software, this software is licensed to you
  99979. +* under the terms of the GNU General Public License version 2, available at
  99980. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  99981. +*
  99982. +* Notwithstanding the above, under no circumstances may you combine this
  99983. +* software in any way with any other Broadcom software provided under a
  99984. +* license other than the GPL, without Broadcom's express prior written
  99985. +* consent.
  99986. +*****************************************************************************/
  99987. +
  99988. +#include <linux/interrupt.h>
  99989. +#include <linux/slab.h>
  99990. +
  99991. +#include <sound/asoundef.h>
  99992. +
  99993. +#include "bcm2835.h"
  99994. +
  99995. +/* hardware definition */
  99996. +static struct snd_pcm_hardware snd_bcm2835_playback_hw = {
  99997. + .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER |
  99998. + SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID),
  99999. + .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
  100000. + .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
  100001. + .rate_min = 8000,
  100002. + .rate_max = 48000,
  100003. + .channels_min = 1,
  100004. + .channels_max = 2,
  100005. + .buffer_bytes_max = 128 * 1024,
  100006. + .period_bytes_min = 1 * 1024,
  100007. + .period_bytes_max = 128 * 1024,
  100008. + .periods_min = 1,
  100009. + .periods_max = 128,
  100010. +};
  100011. +
  100012. +static struct snd_pcm_hardware snd_bcm2835_playback_spdif_hw = {
  100013. + .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER |
  100014. + SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID),
  100015. + .formats = SNDRV_PCM_FMTBIT_S16_LE,
  100016. + .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_44100 |
  100017. + SNDRV_PCM_RATE_48000,
  100018. + .rate_min = 44100,
  100019. + .rate_max = 48000,
  100020. + .channels_min = 2,
  100021. + .channels_max = 2,
  100022. + .buffer_bytes_max = 128 * 1024,
  100023. + .period_bytes_min = 1 * 1024,
  100024. + .period_bytes_max = 128 * 1024,
  100025. + .periods_min = 1,
  100026. + .periods_max = 128,
  100027. +};
  100028. +
  100029. +static void snd_bcm2835_playback_free(struct snd_pcm_runtime *runtime)
  100030. +{
  100031. + audio_info("Freeing up alsa stream here ..\n");
  100032. + if (runtime->private_data)
  100033. + kfree(runtime->private_data);
  100034. + runtime->private_data = NULL;
  100035. +}
  100036. +
  100037. +static irqreturn_t bcm2835_playback_fifo_irq(int irq, void *dev_id)
  100038. +{
  100039. + bcm2835_alsa_stream_t *alsa_stream = (bcm2835_alsa_stream_t *) dev_id;
  100040. + uint32_t consumed = 0;
  100041. + int new_period = 0;
  100042. +
  100043. + audio_info(" .. IN\n");
  100044. +
  100045. + audio_info("alsa_stream=%p substream=%p\n", alsa_stream,
  100046. + alsa_stream ? alsa_stream->substream : 0);
  100047. +
  100048. + if (alsa_stream->open)
  100049. + consumed = bcm2835_audio_retrieve_buffers(alsa_stream);
  100050. +
  100051. + /* We get called only if playback was triggered, So, the number of buffers we retrieve in
  100052. + * each iteration are the buffers that have been played out already
  100053. + */
  100054. +
  100055. + if (alsa_stream->period_size) {
  100056. + if ((alsa_stream->pos / alsa_stream->period_size) !=
  100057. + ((alsa_stream->pos + consumed) / alsa_stream->period_size))
  100058. + new_period = 1;
  100059. + }
  100060. + audio_debug("updating pos cur: %d + %d max:%d period_bytes:%d, hw_ptr: %d new_period:%d\n",
  100061. + alsa_stream->pos,
  100062. + consumed,
  100063. + alsa_stream->buffer_size,
  100064. + (int)(alsa_stream->period_size*alsa_stream->substream->runtime->periods),
  100065. + frames_to_bytes(alsa_stream->substream->runtime, alsa_stream->substream->runtime->status->hw_ptr),
  100066. + new_period);
  100067. + if (alsa_stream->buffer_size) {
  100068. + alsa_stream->pos += consumed &~ (1<<30);
  100069. + alsa_stream->pos %= alsa_stream->buffer_size;
  100070. + }
  100071. +
  100072. + if (alsa_stream->substream) {
  100073. + if (new_period)
  100074. + snd_pcm_period_elapsed(alsa_stream->substream);
  100075. + } else {
  100076. + audio_warning(" unexpected NULL substream\n");
  100077. + }
  100078. + audio_info(" .. OUT\n");
  100079. +
  100080. + return IRQ_HANDLED;
  100081. +}
  100082. +
  100083. +/* open callback */
  100084. +static int snd_bcm2835_playback_open_generic(
  100085. + struct snd_pcm_substream *substream, int spdif)
  100086. +{
  100087. + bcm2835_chip_t *chip = snd_pcm_substream_chip(substream);
  100088. + struct snd_pcm_runtime *runtime = substream->runtime;
  100089. + bcm2835_alsa_stream_t *alsa_stream;
  100090. + int idx;
  100091. + int err;
  100092. +
  100093. + audio_info(" .. IN (%d)\n", substream->number);
  100094. +
  100095. + audio_info("Alsa open (%d)\n", substream->number);
  100096. + idx = substream->number;
  100097. +
  100098. + if (spdif && chip->opened != 0)
  100099. + return -EBUSY;
  100100. + else if (!spdif && (chip->opened & (1 << idx)))
  100101. + return -EBUSY;
  100102. +
  100103. + if (idx > MAX_SUBSTREAMS) {
  100104. + audio_error
  100105. + ("substream(%d) device doesn't exist max(%d) substreams allowed\n",
  100106. + idx, MAX_SUBSTREAMS);
  100107. + err = -ENODEV;
  100108. + goto out;
  100109. + }
  100110. +
  100111. + /* Check if we are ready */
  100112. + if (!(chip->avail_substreams & (1 << idx))) {
  100113. + /* We are not ready yet */
  100114. + audio_error("substream(%d) device is not ready yet\n", idx);
  100115. + err = -EAGAIN;
  100116. + goto out;
  100117. + }
  100118. +
  100119. + alsa_stream = kzalloc(sizeof(bcm2835_alsa_stream_t), GFP_KERNEL);
  100120. + if (alsa_stream == NULL) {
  100121. + return -ENOMEM;
  100122. + }
  100123. +
  100124. + /* Initialise alsa_stream */
  100125. + alsa_stream->chip = chip;
  100126. + alsa_stream->substream = substream;
  100127. + alsa_stream->idx = idx;
  100128. +
  100129. + sema_init(&alsa_stream->buffers_update_sem, 0);
  100130. + sema_init(&alsa_stream->control_sem, 0);
  100131. + spin_lock_init(&alsa_stream->lock);
  100132. +
  100133. + /* Enabled in start trigger, called on each "fifo irq" after that */
  100134. + alsa_stream->enable_fifo_irq = 0;
  100135. + alsa_stream->fifo_irq_handler = bcm2835_playback_fifo_irq;
  100136. +
  100137. + runtime->private_data = alsa_stream;
  100138. + runtime->private_free = snd_bcm2835_playback_free;
  100139. + if (spdif) {
  100140. + runtime->hw = snd_bcm2835_playback_spdif_hw;
  100141. + } else {
  100142. + /* clear spdif status, as we are not in spdif mode */
  100143. + chip->spdif_status = 0;
  100144. + runtime->hw = snd_bcm2835_playback_hw;
  100145. + }
  100146. + /* minimum 16 bytes alignment (for vchiq bulk transfers) */
  100147. + snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
  100148. + 16);
  100149. +
  100150. + err = bcm2835_audio_open(alsa_stream);
  100151. + if (err != 0) {
  100152. + kfree(alsa_stream);
  100153. + return err;
  100154. + }
  100155. + chip->alsa_stream[idx] = alsa_stream;
  100156. +
  100157. + chip->opened |= (1 << idx);
  100158. + alsa_stream->open = 1;
  100159. + alsa_stream->draining = 1;
  100160. +
  100161. +out:
  100162. + audio_info(" .. OUT =%d\n", err);
  100163. +
  100164. + return err;
  100165. +}
  100166. +
  100167. +static int snd_bcm2835_playback_open(struct snd_pcm_substream *substream)
  100168. +{
  100169. + return snd_bcm2835_playback_open_generic(substream, 0);
  100170. +}
  100171. +
  100172. +static int snd_bcm2835_playback_spdif_open(struct snd_pcm_substream *substream)
  100173. +{
  100174. + return snd_bcm2835_playback_open_generic(substream, 1);
  100175. +}
  100176. +
  100177. +/* close callback */
  100178. +static int snd_bcm2835_playback_close(struct snd_pcm_substream *substream)
  100179. +{
  100180. + /* the hardware-specific codes will be here */
  100181. +
  100182. + struct snd_pcm_runtime *runtime = substream->runtime;
  100183. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  100184. + bcm2835_chip_t *chip = snd_pcm_substream_chip(substream);
  100185. +
  100186. + audio_info(" .. IN\n");
  100187. + audio_info("Alsa close\n");
  100188. +
  100189. + /*
  100190. + * Call stop if it's still running. This happens when app
  100191. + * is force killed and we don't get a stop trigger.
  100192. + */
  100193. + if (alsa_stream->running) {
  100194. + int err;
  100195. + err = bcm2835_audio_stop(alsa_stream);
  100196. + alsa_stream->running = 0;
  100197. + if (err != 0)
  100198. + audio_error(" Failed to STOP alsa device\n");
  100199. + }
  100200. +
  100201. + alsa_stream->period_size = 0;
  100202. + alsa_stream->buffer_size = 0;
  100203. +
  100204. + if (alsa_stream->open) {
  100205. + alsa_stream->open = 0;
  100206. + bcm2835_audio_close(alsa_stream);
  100207. + }
  100208. + if (alsa_stream->chip)
  100209. + alsa_stream->chip->alsa_stream[alsa_stream->idx] = NULL;
  100210. + /*
  100211. + * Do not free up alsa_stream here, it will be freed up by
  100212. + * runtime->private_free callback we registered in *_open above
  100213. + */
  100214. +
  100215. + chip->opened &= ~(1 << substream->number);
  100216. +
  100217. + audio_info(" .. OUT\n");
  100218. +
  100219. + return 0;
  100220. +}
  100221. +
  100222. +/* hw_params callback */
  100223. +static int snd_bcm2835_pcm_hw_params(struct snd_pcm_substream *substream,
  100224. + struct snd_pcm_hw_params *params)
  100225. +{
  100226. + struct snd_pcm_runtime *runtime = substream->runtime;
  100227. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  100228. + int err;
  100229. +
  100230. + audio_info(" .. IN\n");
  100231. +
  100232. + err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params));
  100233. + if (err < 0) {
  100234. + audio_error
  100235. + (" pcm_lib_malloc failed to allocated pages for buffers\n");
  100236. + return err;
  100237. + }
  100238. +
  100239. + alsa_stream->channels = params_channels(params);
  100240. + alsa_stream->params_rate = params_rate(params);
  100241. + alsa_stream->pcm_format_width = snd_pcm_format_width(params_format (params));
  100242. + audio_info(" .. OUT\n");
  100243. +
  100244. + return err;
  100245. +}
  100246. +
  100247. +/* hw_free callback */
  100248. +static int snd_bcm2835_pcm_hw_free(struct snd_pcm_substream *substream)
  100249. +{
  100250. + audio_info(" .. IN\n");
  100251. + return snd_pcm_lib_free_pages(substream);
  100252. +}
  100253. +
  100254. +/* prepare callback */
  100255. +static int snd_bcm2835_pcm_prepare(struct snd_pcm_substream *substream)
  100256. +{
  100257. + bcm2835_chip_t *chip = snd_pcm_substream_chip(substream);
  100258. + struct snd_pcm_runtime *runtime = substream->runtime;
  100259. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  100260. + int channels;
  100261. + int err;
  100262. +
  100263. + audio_info(" .. IN\n");
  100264. +
  100265. + /* notify the vchiq that it should enter spdif passthrough mode by
  100266. + * setting channels=0 (see
  100267. + * https://github.com/raspberrypi/linux/issues/528) */
  100268. + if (chip->spdif_status & IEC958_AES0_NONAUDIO)
  100269. + channels = 0;
  100270. + else
  100271. + channels = alsa_stream->channels;
  100272. +
  100273. + err = bcm2835_audio_set_params(alsa_stream, channels,
  100274. + alsa_stream->params_rate,
  100275. + alsa_stream->pcm_format_width);
  100276. + if (err < 0) {
  100277. + audio_error(" error setting hw params\n");
  100278. + }
  100279. +
  100280. + bcm2835_audio_setup(alsa_stream);
  100281. +
  100282. + /* in preparation of the stream, set the controls (volume level) of the stream */
  100283. + bcm2835_audio_set_ctls(alsa_stream->chip);
  100284. +
  100285. +
  100286. + memset(&alsa_stream->pcm_indirect, 0, sizeof(alsa_stream->pcm_indirect));
  100287. +
  100288. + alsa_stream->pcm_indirect.hw_buffer_size =
  100289. + alsa_stream->pcm_indirect.sw_buffer_size =
  100290. + snd_pcm_lib_buffer_bytes(substream);
  100291. +
  100292. + alsa_stream->buffer_size = snd_pcm_lib_buffer_bytes(substream);
  100293. + alsa_stream->period_size = snd_pcm_lib_period_bytes(substream);
  100294. + alsa_stream->pos = 0;
  100295. +
  100296. + audio_debug("buffer_size=%d, period_size=%d pos=%d frame_bits=%d\n",
  100297. + alsa_stream->buffer_size, alsa_stream->period_size,
  100298. + alsa_stream->pos, runtime->frame_bits);
  100299. +
  100300. + audio_info(" .. OUT\n");
  100301. + return 0;
  100302. +}
  100303. +
  100304. +static void snd_bcm2835_pcm_transfer(struct snd_pcm_substream *substream,
  100305. + struct snd_pcm_indirect *rec, size_t bytes)
  100306. +{
  100307. + struct snd_pcm_runtime *runtime = substream->runtime;
  100308. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  100309. + void *src = (void *)(substream->runtime->dma_area + rec->sw_data);
  100310. + int err;
  100311. +
  100312. + err = bcm2835_audio_write(alsa_stream, bytes, src);
  100313. + if (err)
  100314. + audio_error(" Failed to transfer to alsa device (%d)\n", err);
  100315. +
  100316. +}
  100317. +
  100318. +static int snd_bcm2835_pcm_ack(struct snd_pcm_substream *substream)
  100319. +{
  100320. + struct snd_pcm_runtime *runtime = substream->runtime;
  100321. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  100322. + struct snd_pcm_indirect *pcm_indirect = &alsa_stream->pcm_indirect;
  100323. +
  100324. + pcm_indirect->hw_queue_size = runtime->hw.buffer_bytes_max;
  100325. + snd_pcm_indirect_playback_transfer(substream, pcm_indirect,
  100326. + snd_bcm2835_pcm_transfer);
  100327. + return 0;
  100328. +}
  100329. +
  100330. +/* trigger callback */
  100331. +static int snd_bcm2835_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
  100332. +{
  100333. + struct snd_pcm_runtime *runtime = substream->runtime;
  100334. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  100335. + int err = 0;
  100336. +
  100337. + audio_info(" .. IN\n");
  100338. +
  100339. + switch (cmd) {
  100340. + case SNDRV_PCM_TRIGGER_START:
  100341. + audio_debug("bcm2835_AUDIO_TRIGGER_START running=%d\n",
  100342. + alsa_stream->running);
  100343. + if (!alsa_stream->running) {
  100344. + err = bcm2835_audio_start(alsa_stream);
  100345. + if (err == 0) {
  100346. + alsa_stream->pcm_indirect.hw_io =
  100347. + alsa_stream->pcm_indirect.hw_data =
  100348. + bytes_to_frames(runtime,
  100349. + alsa_stream->pos);
  100350. + substream->ops->ack(substream);
  100351. + alsa_stream->running = 1;
  100352. + alsa_stream->draining = 1;
  100353. + } else {
  100354. + audio_error(" Failed to START alsa device (%d)\n", err);
  100355. + }
  100356. + }
  100357. + break;
  100358. + case SNDRV_PCM_TRIGGER_STOP:
  100359. + audio_debug
  100360. + ("bcm2835_AUDIO_TRIGGER_STOP running=%d draining=%d\n",
  100361. + alsa_stream->running, runtime->status->state == SNDRV_PCM_STATE_DRAINING);
  100362. + if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
  100363. + audio_info("DRAINING\n");
  100364. + alsa_stream->draining = 1;
  100365. + } else {
  100366. + audio_info("DROPPING\n");
  100367. + alsa_stream->draining = 0;
  100368. + }
  100369. + if (alsa_stream->running) {
  100370. + err = bcm2835_audio_stop(alsa_stream);
  100371. + if (err != 0)
  100372. + audio_error(" Failed to STOP alsa device (%d)\n", err);
  100373. + alsa_stream->running = 0;
  100374. + }
  100375. + break;
  100376. + default:
  100377. + err = -EINVAL;
  100378. + }
  100379. +
  100380. + audio_info(" .. OUT\n");
  100381. + return err;
  100382. +}
  100383. +
  100384. +/* pointer callback */
  100385. +static snd_pcm_uframes_t
  100386. +snd_bcm2835_pcm_pointer(struct snd_pcm_substream *substream)
  100387. +{
  100388. + struct snd_pcm_runtime *runtime = substream->runtime;
  100389. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  100390. +
  100391. + audio_info(" .. IN\n");
  100392. +
  100393. + audio_debug("pcm_pointer... (%d) hwptr=%d appl=%d pos=%d\n", 0,
  100394. + frames_to_bytes(runtime, runtime->status->hw_ptr),
  100395. + frames_to_bytes(runtime, runtime->control->appl_ptr),
  100396. + alsa_stream->pos);
  100397. +
  100398. + audio_info(" .. OUT\n");
  100399. + return snd_pcm_indirect_playback_pointer(substream,
  100400. + &alsa_stream->pcm_indirect,
  100401. + alsa_stream->pos);
  100402. +}
  100403. +
  100404. +static int snd_bcm2835_pcm_lib_ioctl(struct snd_pcm_substream *substream,
  100405. + unsigned int cmd, void *arg)
  100406. +{
  100407. + int ret = snd_pcm_lib_ioctl(substream, cmd, arg);
  100408. + audio_info(" .. substream=%p, cmd=%d, arg=%p (%x) ret=%d\n", substream,
  100409. + cmd, arg, arg ? *(unsigned *)arg : 0, ret);
  100410. + return ret;
  100411. +}
  100412. +
  100413. +/* operators */
  100414. +static struct snd_pcm_ops snd_bcm2835_playback_ops = {
  100415. + .open = snd_bcm2835_playback_open,
  100416. + .close = snd_bcm2835_playback_close,
  100417. + .ioctl = snd_bcm2835_pcm_lib_ioctl,
  100418. + .hw_params = snd_bcm2835_pcm_hw_params,
  100419. + .hw_free = snd_bcm2835_pcm_hw_free,
  100420. + .prepare = snd_bcm2835_pcm_prepare,
  100421. + .trigger = snd_bcm2835_pcm_trigger,
  100422. + .pointer = snd_bcm2835_pcm_pointer,
  100423. + .ack = snd_bcm2835_pcm_ack,
  100424. +};
  100425. +
  100426. +static struct snd_pcm_ops snd_bcm2835_playback_spdif_ops = {
  100427. + .open = snd_bcm2835_playback_spdif_open,
  100428. + .close = snd_bcm2835_playback_close,
  100429. + .ioctl = snd_bcm2835_pcm_lib_ioctl,
  100430. + .hw_params = snd_bcm2835_pcm_hw_params,
  100431. + .hw_free = snd_bcm2835_pcm_hw_free,
  100432. + .prepare = snd_bcm2835_pcm_prepare,
  100433. + .trigger = snd_bcm2835_pcm_trigger,
  100434. + .pointer = snd_bcm2835_pcm_pointer,
  100435. + .ack = snd_bcm2835_pcm_ack,
  100436. +};
  100437. +
  100438. +/* create a pcm device */
  100439. +int snd_bcm2835_new_pcm(bcm2835_chip_t * chip)
  100440. +{
  100441. + struct snd_pcm *pcm;
  100442. + int err;
  100443. +
  100444. + audio_info(" .. IN\n");
  100445. + err =
  100446. + snd_pcm_new(chip->card, "bcm2835 ALSA", 0, MAX_SUBSTREAMS, 0, &pcm);
  100447. + if (err < 0)
  100448. + return err;
  100449. + pcm->private_data = chip;
  100450. + strcpy(pcm->name, "bcm2835 ALSA");
  100451. + chip->pcm = pcm;
  100452. + chip->dest = AUDIO_DEST_AUTO;
  100453. + chip->volume = alsa2chip(0);
  100454. + chip->mute = CTRL_VOL_UNMUTE; /*disable mute on startup */
  100455. + /* set operators */
  100456. + snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
  100457. + &snd_bcm2835_playback_ops);
  100458. +
  100459. + /* pre-allocation of buffers */
  100460. + /* NOTE: this may fail */
  100461. + snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
  100462. + snd_dma_continuous_data
  100463. + (GFP_KERNEL), 64 * 1024,
  100464. + 64 * 1024);
  100465. +
  100466. + audio_info(" .. OUT\n");
  100467. +
  100468. + return 0;
  100469. +}
  100470. +
  100471. +int snd_bcm2835_new_spdif_pcm(bcm2835_chip_t * chip)
  100472. +{
  100473. + struct snd_pcm *pcm;
  100474. + int err;
  100475. +
  100476. + err = snd_pcm_new(chip->card, "bcm2835 ALSA", 1, 1, 0, &pcm);
  100477. + if (err < 0)
  100478. + return err;
  100479. +
  100480. + pcm->private_data = chip;
  100481. + strcpy(pcm->name, "bcm2835 IEC958/HDMI");
  100482. + chip->pcm_spdif = pcm;
  100483. + snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
  100484. + &snd_bcm2835_playback_spdif_ops);
  100485. +
  100486. + snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
  100487. + snd_dma_continuous_data (GFP_KERNEL),
  100488. + 64 * 1024, 64 * 1024);
  100489. +
  100490. + return 0;
  100491. +}
  100492. diff -Nur linux-3.13.11/sound/arm/bcm2835-vchiq.c linux-rpi/sound/arm/bcm2835-vchiq.c
  100493. --- linux-3.13.11/sound/arm/bcm2835-vchiq.c 1970-01-01 01:00:00.000000000 +0100
  100494. +++ linux-rpi/sound/arm/bcm2835-vchiq.c 2014-04-24 15:37:23.599102818 +0200
  100495. @@ -0,0 +1,879 @@
  100496. +/*****************************************************************************
  100497. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  100498. +*
  100499. +* Unless you and Broadcom execute a separate written software license
  100500. +* agreement governing use of this software, this software is licensed to you
  100501. +* under the terms of the GNU General Public License version 2, available at
  100502. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  100503. +*
  100504. +* Notwithstanding the above, under no circumstances may you combine this
  100505. +* software in any way with any other Broadcom software provided under a
  100506. +* license other than the GPL, without Broadcom's express prior written
  100507. +* consent.
  100508. +*****************************************************************************/
  100509. +
  100510. +#include <linux/device.h>
  100511. +#include <sound/core.h>
  100512. +#include <sound/initval.h>
  100513. +#include <sound/pcm.h>
  100514. +#include <linux/io.h>
  100515. +#include <linux/interrupt.h>
  100516. +#include <linux/fs.h>
  100517. +#include <linux/file.h>
  100518. +#include <linux/mm.h>
  100519. +#include <linux/syscalls.h>
  100520. +#include <asm/uaccess.h>
  100521. +#include <linux/slab.h>
  100522. +#include <linux/delay.h>
  100523. +#include <linux/atomic.h>
  100524. +#include <linux/module.h>
  100525. +#include <linux/completion.h>
  100526. +
  100527. +#include "bcm2835.h"
  100528. +
  100529. +/* ---- Include Files -------------------------------------------------------- */
  100530. +
  100531. +#include "interface/vchi/vchi.h"
  100532. +#include "vc_vchi_audioserv_defs.h"
  100533. +
  100534. +/* ---- Private Constants and Types ------------------------------------------ */
  100535. +
  100536. +#define BCM2835_AUDIO_STOP 0
  100537. +#define BCM2835_AUDIO_START 1
  100538. +#define BCM2835_AUDIO_WRITE 2
  100539. +
  100540. +/* Logging macros (for remapping to other logging mechanisms, i.e., printf) */
  100541. +#ifdef AUDIO_DEBUG_ENABLE
  100542. + #define LOG_ERR( fmt, arg... ) pr_err( "%s:%d " fmt, __func__, __LINE__, ##arg)
  100543. + #define LOG_WARN( fmt, arg... ) pr_info( "%s:%d " fmt, __func__, __LINE__, ##arg)
  100544. + #define LOG_INFO( fmt, arg... ) pr_info( "%s:%d " fmt, __func__, __LINE__, ##arg)
  100545. + #define LOG_DBG( fmt, arg... ) pr_info( "%s:%d " fmt, __func__, __LINE__, ##arg)
  100546. +#else
  100547. + #define LOG_ERR( fmt, arg... ) pr_err( "%s:%d " fmt, __func__, __LINE__, ##arg)
  100548. + #define LOG_WARN( fmt, arg... )
  100549. + #define LOG_INFO( fmt, arg... )
  100550. + #define LOG_DBG( fmt, arg... )
  100551. +#endif
  100552. +
  100553. +typedef struct opaque_AUDIO_INSTANCE_T {
  100554. + uint32_t num_connections;
  100555. + VCHI_SERVICE_HANDLE_T vchi_handle[VCHI_MAX_NUM_CONNECTIONS];
  100556. + struct completion msg_avail_comp;
  100557. + struct mutex vchi_mutex;
  100558. + bcm2835_alsa_stream_t *alsa_stream;
  100559. + int32_t result;
  100560. + short peer_version;
  100561. +} AUDIO_INSTANCE_T;
  100562. +
  100563. +bool force_bulk = false;
  100564. +
  100565. +/* ---- Private Variables ---------------------------------------------------- */
  100566. +
  100567. +/* ---- Private Function Prototypes ------------------------------------------ */
  100568. +
  100569. +/* ---- Private Functions ---------------------------------------------------- */
  100570. +
  100571. +static int bcm2835_audio_stop_worker(bcm2835_alsa_stream_t * alsa_stream);
  100572. +static int bcm2835_audio_start_worker(bcm2835_alsa_stream_t * alsa_stream);
  100573. +static int bcm2835_audio_write_worker(bcm2835_alsa_stream_t *alsa_stream,
  100574. + uint32_t count, void *src);
  100575. +
  100576. +typedef struct {
  100577. + struct work_struct my_work;
  100578. + bcm2835_alsa_stream_t *alsa_stream;
  100579. + int cmd;
  100580. + void *src;
  100581. + uint32_t count;
  100582. +} my_work_t;
  100583. +
  100584. +static void my_wq_function(struct work_struct *work)
  100585. +{
  100586. + my_work_t *w = (my_work_t *) work;
  100587. + int ret = -9;
  100588. + LOG_DBG(" .. IN %p:%d\n", w->alsa_stream, w->cmd);
  100589. + switch (w->cmd) {
  100590. + case BCM2835_AUDIO_START:
  100591. + ret = bcm2835_audio_start_worker(w->alsa_stream);
  100592. + break;
  100593. + case BCM2835_AUDIO_STOP:
  100594. + ret = bcm2835_audio_stop_worker(w->alsa_stream);
  100595. + break;
  100596. + case BCM2835_AUDIO_WRITE:
  100597. + ret = bcm2835_audio_write_worker(w->alsa_stream, w->count,
  100598. + w->src);
  100599. + break;
  100600. + default:
  100601. + LOG_ERR(" Unexpected work: %p:%d\n", w->alsa_stream, w->cmd);
  100602. + break;
  100603. + }
  100604. + kfree((void *)work);
  100605. + LOG_DBG(" .. OUT %d\n", ret);
  100606. +}
  100607. +
  100608. +int bcm2835_audio_start(bcm2835_alsa_stream_t * alsa_stream)
  100609. +{
  100610. + int ret = -1;
  100611. + LOG_DBG(" .. IN\n");
  100612. + if (alsa_stream->my_wq) {
  100613. + my_work_t *work = kmalloc(sizeof(my_work_t), GFP_ATOMIC);
  100614. + /*--- Queue some work (item 1) ---*/
  100615. + if (work) {
  100616. + INIT_WORK((struct work_struct *)work, my_wq_function);
  100617. + work->alsa_stream = alsa_stream;
  100618. + work->cmd = BCM2835_AUDIO_START;
  100619. + if (queue_work
  100620. + (alsa_stream->my_wq, (struct work_struct *)work))
  100621. + ret = 0;
  100622. + } else
  100623. + LOG_ERR(" .. Error: NULL work kmalloc\n");
  100624. + }
  100625. + LOG_DBG(" .. OUT %d\n", ret);
  100626. + return ret;
  100627. +}
  100628. +
  100629. +int bcm2835_audio_stop(bcm2835_alsa_stream_t * alsa_stream)
  100630. +{
  100631. + int ret = -1;
  100632. + LOG_DBG(" .. IN\n");
  100633. + if (alsa_stream->my_wq) {
  100634. + my_work_t *work = kmalloc(sizeof(my_work_t), GFP_ATOMIC);
  100635. + /*--- Queue some work (item 1) ---*/
  100636. + if (work) {
  100637. + INIT_WORK((struct work_struct *)work, my_wq_function);
  100638. + work->alsa_stream = alsa_stream;
  100639. + work->cmd = BCM2835_AUDIO_STOP;
  100640. + if (queue_work
  100641. + (alsa_stream->my_wq, (struct work_struct *)work))
  100642. + ret = 0;
  100643. + } else
  100644. + LOG_ERR(" .. Error: NULL work kmalloc\n");
  100645. + }
  100646. + LOG_DBG(" .. OUT %d\n", ret);
  100647. + return ret;
  100648. +}
  100649. +
  100650. +int bcm2835_audio_write(bcm2835_alsa_stream_t *alsa_stream,
  100651. + uint32_t count, void *src)
  100652. +{
  100653. + int ret = -1;
  100654. + LOG_DBG(" .. IN\n");
  100655. + if (alsa_stream->my_wq) {
  100656. + my_work_t *work = kmalloc(sizeof(my_work_t), GFP_ATOMIC);
  100657. + /*--- Queue some work (item 1) ---*/
  100658. + if (work) {
  100659. + INIT_WORK((struct work_struct *)work, my_wq_function);
  100660. + work->alsa_stream = alsa_stream;
  100661. + work->cmd = BCM2835_AUDIO_WRITE;
  100662. + work->src = src;
  100663. + work->count = count;
  100664. + if (queue_work
  100665. + (alsa_stream->my_wq, (struct work_struct *)work))
  100666. + ret = 0;
  100667. + } else
  100668. + LOG_ERR(" .. Error: NULL work kmalloc\n");
  100669. + }
  100670. + LOG_DBG(" .. OUT %d\n", ret);
  100671. + return ret;
  100672. +}
  100673. +
  100674. +void my_workqueue_init(bcm2835_alsa_stream_t * alsa_stream)
  100675. +{
  100676. + alsa_stream->my_wq = alloc_workqueue("my_queue", WQ_HIGHPRI, 1);
  100677. + return;
  100678. +}
  100679. +
  100680. +void my_workqueue_quit(bcm2835_alsa_stream_t * alsa_stream)
  100681. +{
  100682. + if (alsa_stream->my_wq) {
  100683. + flush_workqueue(alsa_stream->my_wq);
  100684. + destroy_workqueue(alsa_stream->my_wq);
  100685. + alsa_stream->my_wq = NULL;
  100686. + }
  100687. + return;
  100688. +}
  100689. +
  100690. +static void audio_vchi_callback(void *param,
  100691. + const VCHI_CALLBACK_REASON_T reason,
  100692. + void *msg_handle)
  100693. +{
  100694. + AUDIO_INSTANCE_T *instance = (AUDIO_INSTANCE_T *) param;
  100695. + int32_t status;
  100696. + int32_t msg_len;
  100697. + VC_AUDIO_MSG_T m;
  100698. + bcm2835_alsa_stream_t *alsa_stream = 0;
  100699. + LOG_DBG(" .. IN instance=%p, param=%p, reason=%d, handle=%p\n",
  100700. + instance, param, reason, msg_handle);
  100701. +
  100702. + if (!instance || reason != VCHI_CALLBACK_MSG_AVAILABLE) {
  100703. + return;
  100704. + }
  100705. + alsa_stream = instance->alsa_stream;
  100706. + status = vchi_msg_dequeue(instance->vchi_handle[0],
  100707. + &m, sizeof m, &msg_len, VCHI_FLAGS_NONE);
  100708. + if (m.type == VC_AUDIO_MSG_TYPE_RESULT) {
  100709. + LOG_DBG
  100710. + (" .. instance=%p, m.type=VC_AUDIO_MSG_TYPE_RESULT, success=%d\n",
  100711. + instance, m.u.result.success);
  100712. + instance->result = m.u.result.success;
  100713. + complete(&instance->msg_avail_comp);
  100714. + } else if (m.type == VC_AUDIO_MSG_TYPE_COMPLETE) {
  100715. + irq_handler_t callback = (irq_handler_t) m.u.complete.callback;
  100716. + LOG_DBG
  100717. + (" .. instance=%p, m.type=VC_AUDIO_MSG_TYPE_COMPLETE, complete=%d\n",
  100718. + instance, m.u.complete.count);
  100719. + if (alsa_stream && callback) {
  100720. + atomic_add(m.u.complete.count, &alsa_stream->retrieved);
  100721. + callback(0, alsa_stream);
  100722. + } else {
  100723. + LOG_DBG(" .. unexpected alsa_stream=%p, callback=%p\n",
  100724. + alsa_stream, callback);
  100725. + }
  100726. + } else {
  100727. + LOG_DBG(" .. unexpected m.type=%d\n", m.type);
  100728. + }
  100729. + LOG_DBG(" .. OUT\n");
  100730. +}
  100731. +
  100732. +static AUDIO_INSTANCE_T *vc_vchi_audio_init(VCHI_INSTANCE_T vchi_instance,
  100733. + VCHI_CONNECTION_T **
  100734. + vchi_connections,
  100735. + uint32_t num_connections)
  100736. +{
  100737. + uint32_t i;
  100738. + AUDIO_INSTANCE_T *instance;
  100739. + int status;
  100740. +
  100741. + LOG_DBG("%s: start", __func__);
  100742. +
  100743. + if (num_connections > VCHI_MAX_NUM_CONNECTIONS) {
  100744. + LOG_ERR("%s: unsupported number of connections %u (max=%u)\n",
  100745. + __func__, num_connections, VCHI_MAX_NUM_CONNECTIONS);
  100746. +
  100747. + return NULL;
  100748. + }
  100749. + /* Allocate memory for this instance */
  100750. + instance = kmalloc(sizeof(*instance), GFP_KERNEL);
  100751. +
  100752. + memset(instance, 0, sizeof(*instance));
  100753. + instance->num_connections = num_connections;
  100754. +
  100755. + /* Create a lock for exclusive, serialized VCHI connection access */
  100756. + mutex_init(&instance->vchi_mutex);
  100757. + /* Open the VCHI service connections */
  100758. + for (i = 0; i < num_connections; i++) {
  100759. + SERVICE_CREATION_T params = {
  100760. + VCHI_VERSION_EX(VC_AUDIOSERV_VER, VC_AUDIOSERV_MIN_VER),
  100761. + VC_AUDIO_SERVER_NAME, // 4cc service code
  100762. + vchi_connections[i], // passed in fn pointers
  100763. + 0, // rx fifo size (unused)
  100764. + 0, // tx fifo size (unused)
  100765. + audio_vchi_callback, // service callback
  100766. + instance, // service callback parameter
  100767. + 1, //TODO: remove VCOS_FALSE, // unaligned bulk recieves
  100768. + 1, //TODO: remove VCOS_FALSE, // unaligned bulk transmits
  100769. + 0 // want crc check on bulk transfers
  100770. + };
  100771. +
  100772. + status = vchi_service_open(vchi_instance, &params,
  100773. + &instance->vchi_handle[i]);
  100774. + if (status) {
  100775. + LOG_ERR
  100776. + ("%s: failed to open VCHI service connection (status=%d)\n",
  100777. + __func__, status);
  100778. +
  100779. + goto err_close_services;
  100780. + }
  100781. + /* Finished with the service for now */
  100782. + vchi_service_release(instance->vchi_handle[i]);
  100783. + }
  100784. +
  100785. + return instance;
  100786. +
  100787. +err_close_services:
  100788. + for (i = 0; i < instance->num_connections; i++) {
  100789. + vchi_service_close(instance->vchi_handle[i]);
  100790. + }
  100791. +
  100792. + kfree(instance);
  100793. +
  100794. + return NULL;
  100795. +}
  100796. +
  100797. +static int32_t vc_vchi_audio_deinit(AUDIO_INSTANCE_T * instance)
  100798. +{
  100799. + uint32_t i;
  100800. +
  100801. + LOG_DBG(" .. IN\n");
  100802. +
  100803. + if (instance == NULL) {
  100804. + LOG_ERR("%s: invalid handle %p\n", __func__, instance);
  100805. +
  100806. + return -1;
  100807. + }
  100808. +
  100809. + LOG_DBG(" .. about to lock (%d)\n", instance->num_connections);
  100810. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  100811. + {
  100812. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  100813. + return -EINTR;
  100814. + }
  100815. +
  100816. + /* Close all VCHI service connections */
  100817. + for (i = 0; i < instance->num_connections; i++) {
  100818. + int32_t success;
  100819. + LOG_DBG(" .. %i:closing %p\n", i, instance->vchi_handle[i]);
  100820. + vchi_service_use(instance->vchi_handle[i]);
  100821. +
  100822. + success = vchi_service_close(instance->vchi_handle[i]);
  100823. + if (success != 0) {
  100824. + LOG_ERR
  100825. + ("%s: failed to close VCHI service connection (status=%d)\n",
  100826. + __func__, success);
  100827. + }
  100828. + }
  100829. +
  100830. + mutex_unlock(&instance->vchi_mutex);
  100831. +
  100832. + kfree(instance);
  100833. +
  100834. + LOG_DBG(" .. OUT\n");
  100835. +
  100836. + return 0;
  100837. +}
  100838. +
  100839. +static int bcm2835_audio_open_connection(bcm2835_alsa_stream_t * alsa_stream)
  100840. +{
  100841. + static VCHI_INSTANCE_T vchi_instance;
  100842. + static VCHI_CONNECTION_T *vchi_connection;
  100843. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  100844. + int ret;
  100845. + LOG_DBG(" .. IN\n");
  100846. +
  100847. + LOG_INFO("%s: start", __func__);
  100848. + //BUG_ON(instance);
  100849. + if (instance) {
  100850. + LOG_ERR("%s: VCHI instance already open (%p)\n",
  100851. + __func__, instance);
  100852. + instance->alsa_stream = alsa_stream;
  100853. + alsa_stream->instance = instance;
  100854. + ret = 0; // xxx todo -1;
  100855. + goto err_free_mem;
  100856. + }
  100857. +
  100858. + /* Initialize and create a VCHI connection */
  100859. + ret = vchi_initialise(&vchi_instance);
  100860. + if (ret != 0) {
  100861. + LOG_ERR("%s: failed to initialise VCHI instance (ret=%d)\n",
  100862. + __func__, ret);
  100863. +
  100864. + ret = -EIO;
  100865. + goto err_free_mem;
  100866. + }
  100867. + ret = vchi_connect(NULL, 0, vchi_instance);
  100868. + if (ret != 0) {
  100869. + LOG_ERR("%s: failed to connect VCHI instance (ret=%d)\n",
  100870. + __func__, ret);
  100871. +
  100872. + ret = -EIO;
  100873. + goto err_free_mem;
  100874. + }
  100875. +
  100876. + /* Initialize an instance of the audio service */
  100877. + instance = vc_vchi_audio_init(vchi_instance, &vchi_connection, 1);
  100878. +
  100879. + if (instance == NULL /*|| audio_handle != instance */ ) {
  100880. + LOG_ERR("%s: failed to initialize audio service\n", __func__);
  100881. +
  100882. + ret = -EPERM;
  100883. + goto err_free_mem;
  100884. + }
  100885. +
  100886. + instance->alsa_stream = alsa_stream;
  100887. + alsa_stream->instance = instance;
  100888. +
  100889. + LOG_DBG(" success !\n");
  100890. +err_free_mem:
  100891. + LOG_DBG(" .. OUT\n");
  100892. +
  100893. + return ret;
  100894. +}
  100895. +
  100896. +int bcm2835_audio_open(bcm2835_alsa_stream_t * alsa_stream)
  100897. +{
  100898. + AUDIO_INSTANCE_T *instance;
  100899. + VC_AUDIO_MSG_T m;
  100900. + int32_t success;
  100901. + int ret;
  100902. + LOG_DBG(" .. IN\n");
  100903. +
  100904. + my_workqueue_init(alsa_stream);
  100905. +
  100906. + ret = bcm2835_audio_open_connection(alsa_stream);
  100907. + if (ret != 0) {
  100908. + ret = -1;
  100909. + goto exit;
  100910. + }
  100911. + instance = alsa_stream->instance;
  100912. +
  100913. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  100914. + {
  100915. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  100916. + return -EINTR;
  100917. + }
  100918. + vchi_service_use(instance->vchi_handle[0]);
  100919. +
  100920. + m.type = VC_AUDIO_MSG_TYPE_OPEN;
  100921. +
  100922. + /* Send the message to the videocore */
  100923. + success = vchi_msg_queue(instance->vchi_handle[0],
  100924. + &m, sizeof m,
  100925. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  100926. +
  100927. + if (success != 0) {
  100928. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
  100929. + __func__, success);
  100930. +
  100931. + ret = -1;
  100932. + goto unlock;
  100933. + }
  100934. +
  100935. + ret = 0;
  100936. +
  100937. +unlock:
  100938. + vchi_service_release(instance->vchi_handle[0]);
  100939. + mutex_unlock(&instance->vchi_mutex);
  100940. +exit:
  100941. + LOG_DBG(" .. OUT\n");
  100942. + return ret;
  100943. +}
  100944. +
  100945. +static int bcm2835_audio_set_ctls_chan(bcm2835_alsa_stream_t * alsa_stream,
  100946. + bcm2835_chip_t * chip)
  100947. +{
  100948. + VC_AUDIO_MSG_T m;
  100949. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  100950. + int32_t success;
  100951. + int ret;
  100952. + LOG_DBG(" .. IN\n");
  100953. +
  100954. + LOG_INFO
  100955. + (" Setting ALSA dest(%d), volume(%d)\n", chip->dest, chip->volume);
  100956. +
  100957. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  100958. + {
  100959. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  100960. + return -EINTR;
  100961. + }
  100962. + vchi_service_use(instance->vchi_handle[0]);
  100963. +
  100964. + instance->result = -1;
  100965. +
  100966. + m.type = VC_AUDIO_MSG_TYPE_CONTROL;
  100967. + m.u.control.dest = chip->dest;
  100968. + m.u.control.volume = chip->volume;
  100969. +
  100970. + /* Create the message available completion */
  100971. + init_completion(&instance->msg_avail_comp);
  100972. +
  100973. + /* Send the message to the videocore */
  100974. + success = vchi_msg_queue(instance->vchi_handle[0],
  100975. + &m, sizeof m,
  100976. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  100977. +
  100978. + if (success != 0) {
  100979. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
  100980. + __func__, success);
  100981. +
  100982. + ret = -1;
  100983. + goto unlock;
  100984. + }
  100985. +
  100986. + /* We are expecting a reply from the videocore */
  100987. + ret = wait_for_completion_interruptible(&instance->msg_avail_comp);
  100988. + if (ret) {
  100989. + LOG_ERR("%s: failed on waiting for event (status=%d)\n",
  100990. + __func__, success);
  100991. + goto unlock;
  100992. + }
  100993. +
  100994. + if (instance->result != 0) {
  100995. + LOG_ERR("%s: result=%d\n", __func__, instance->result);
  100996. +
  100997. + ret = -1;
  100998. + goto unlock;
  100999. + }
  101000. +
  101001. + ret = 0;
  101002. +
  101003. +unlock:
  101004. + vchi_service_release(instance->vchi_handle[0]);
  101005. + mutex_unlock(&instance->vchi_mutex);
  101006. +
  101007. + LOG_DBG(" .. OUT\n");
  101008. + return ret;
  101009. +}
  101010. +
  101011. +int bcm2835_audio_set_ctls(bcm2835_chip_t * chip)
  101012. +{
  101013. + int i;
  101014. + int ret = 0;
  101015. + LOG_DBG(" .. IN\n");
  101016. +
  101017. + /* change ctls for all substreams */
  101018. + for (i = 0; i < MAX_SUBSTREAMS; i++) {
  101019. + if (chip->avail_substreams & (1 << i)) {
  101020. + if (!chip->alsa_stream[i])
  101021. + {
  101022. + LOG_DBG(" No ALSA stream available?! %i:%p (%x)\n", i, chip->alsa_stream[i], chip->avail_substreams);
  101023. + ret = 0;
  101024. + }
  101025. + else if (bcm2835_audio_set_ctls_chan /* returns 0 on success */
  101026. + (chip->alsa_stream[i], chip) != 0)
  101027. + {
  101028. + LOG_DBG("Couldn't set the controls for stream %d\n", i);
  101029. + ret = -1;
  101030. + }
  101031. + else LOG_DBG(" Controls set for stream %d\n", i);
  101032. + }
  101033. + }
  101034. + LOG_DBG(" .. OUT ret=%d\n", ret);
  101035. + return ret;
  101036. +}
  101037. +
  101038. +int bcm2835_audio_set_params(bcm2835_alsa_stream_t * alsa_stream,
  101039. + uint32_t channels, uint32_t samplerate,
  101040. + uint32_t bps)
  101041. +{
  101042. + VC_AUDIO_MSG_T m;
  101043. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  101044. + int32_t success;
  101045. + int ret;
  101046. + LOG_DBG(" .. IN\n");
  101047. +
  101048. + LOG_INFO
  101049. + (" Setting ALSA channels(%d), samplerate(%d), bits-per-sample(%d)\n",
  101050. + channels, samplerate, bps);
  101051. +
  101052. + /* resend ctls - alsa_stream may not have been open when first send */
  101053. + ret = bcm2835_audio_set_ctls_chan(alsa_stream, alsa_stream->chip);
  101054. + if (ret != 0) {
  101055. + LOG_ERR(" Alsa controls not supported\n");
  101056. + return -EINVAL;
  101057. + }
  101058. +
  101059. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  101060. + {
  101061. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  101062. + return -EINTR;
  101063. + }
  101064. + vchi_service_use(instance->vchi_handle[0]);
  101065. +
  101066. + instance->result = -1;
  101067. +
  101068. + m.type = VC_AUDIO_MSG_TYPE_CONFIG;
  101069. + m.u.config.channels = channels;
  101070. + m.u.config.samplerate = samplerate;
  101071. + m.u.config.bps = bps;
  101072. +
  101073. + /* Create the message available completion */
  101074. + init_completion(&instance->msg_avail_comp);
  101075. +
  101076. + /* Send the message to the videocore */
  101077. + success = vchi_msg_queue(instance->vchi_handle[0],
  101078. + &m, sizeof m,
  101079. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  101080. +
  101081. + if (success != 0) {
  101082. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
  101083. + __func__, success);
  101084. +
  101085. + ret = -1;
  101086. + goto unlock;
  101087. + }
  101088. +
  101089. + /* We are expecting a reply from the videocore */
  101090. + ret = wait_for_completion_interruptible(&instance->msg_avail_comp);
  101091. + if (ret) {
  101092. + LOG_ERR("%s: failed on waiting for event (status=%d)\n",
  101093. + __func__, success);
  101094. + goto unlock;
  101095. + }
  101096. +
  101097. + if (instance->result != 0) {
  101098. + LOG_ERR("%s: result=%d", __func__, instance->result);
  101099. +
  101100. + ret = -1;
  101101. + goto unlock;
  101102. + }
  101103. +
  101104. + ret = 0;
  101105. +
  101106. +unlock:
  101107. + vchi_service_release(instance->vchi_handle[0]);
  101108. + mutex_unlock(&instance->vchi_mutex);
  101109. +
  101110. + LOG_DBG(" .. OUT\n");
  101111. + return ret;
  101112. +}
  101113. +
  101114. +int bcm2835_audio_setup(bcm2835_alsa_stream_t * alsa_stream)
  101115. +{
  101116. + LOG_DBG(" .. IN\n");
  101117. +
  101118. + LOG_DBG(" .. OUT\n");
  101119. +
  101120. + return 0;
  101121. +}
  101122. +
  101123. +static int bcm2835_audio_start_worker(bcm2835_alsa_stream_t * alsa_stream)
  101124. +{
  101125. + VC_AUDIO_MSG_T m;
  101126. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  101127. + int32_t success;
  101128. + int ret;
  101129. + LOG_DBG(" .. IN\n");
  101130. +
  101131. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  101132. + {
  101133. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  101134. + return -EINTR;
  101135. + }
  101136. + vchi_service_use(instance->vchi_handle[0]);
  101137. +
  101138. + m.type = VC_AUDIO_MSG_TYPE_START;
  101139. +
  101140. + /* Send the message to the videocore */
  101141. + success = vchi_msg_queue(instance->vchi_handle[0],
  101142. + &m, sizeof m,
  101143. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  101144. +
  101145. + if (success != 0) {
  101146. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)",
  101147. + __func__, success);
  101148. +
  101149. + ret = -1;
  101150. + goto unlock;
  101151. + }
  101152. +
  101153. + ret = 0;
  101154. +
  101155. +unlock:
  101156. + vchi_service_release(instance->vchi_handle[0]);
  101157. + mutex_unlock(&instance->vchi_mutex);
  101158. + LOG_DBG(" .. OUT\n");
  101159. + return ret;
  101160. +}
  101161. +
  101162. +static int bcm2835_audio_stop_worker(bcm2835_alsa_stream_t * alsa_stream)
  101163. +{
  101164. + VC_AUDIO_MSG_T m;
  101165. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  101166. + int32_t success;
  101167. + int ret;
  101168. + LOG_DBG(" .. IN\n");
  101169. +
  101170. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  101171. + {
  101172. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  101173. + return -EINTR;
  101174. + }
  101175. + vchi_service_use(instance->vchi_handle[0]);
  101176. +
  101177. + m.type = VC_AUDIO_MSG_TYPE_STOP;
  101178. + m.u.stop.draining = alsa_stream->draining;
  101179. +
  101180. + /* Send the message to the videocore */
  101181. + success = vchi_msg_queue(instance->vchi_handle[0],
  101182. + &m, sizeof m,
  101183. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  101184. +
  101185. + if (success != 0) {
  101186. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)",
  101187. + __func__, success);
  101188. +
  101189. + ret = -1;
  101190. + goto unlock;
  101191. + }
  101192. +
  101193. + ret = 0;
  101194. +
  101195. +unlock:
  101196. + vchi_service_release(instance->vchi_handle[0]);
  101197. + mutex_unlock(&instance->vchi_mutex);
  101198. + LOG_DBG(" .. OUT\n");
  101199. + return ret;
  101200. +}
  101201. +
  101202. +int bcm2835_audio_close(bcm2835_alsa_stream_t * alsa_stream)
  101203. +{
  101204. + VC_AUDIO_MSG_T m;
  101205. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  101206. + int32_t success;
  101207. + int ret;
  101208. + LOG_DBG(" .. IN\n");
  101209. +
  101210. + my_workqueue_quit(alsa_stream);
  101211. +
  101212. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  101213. + {
  101214. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  101215. + return -EINTR;
  101216. + }
  101217. + vchi_service_use(instance->vchi_handle[0]);
  101218. +
  101219. + m.type = VC_AUDIO_MSG_TYPE_CLOSE;
  101220. +
  101221. + /* Create the message available completion */
  101222. + init_completion(&instance->msg_avail_comp);
  101223. +
  101224. + /* Send the message to the videocore */
  101225. + success = vchi_msg_queue(instance->vchi_handle[0],
  101226. + &m, sizeof m,
  101227. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  101228. +
  101229. + if (success != 0) {
  101230. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)",
  101231. + __func__, success);
  101232. + ret = -1;
  101233. + goto unlock;
  101234. + }
  101235. +
  101236. + ret = wait_for_completion_interruptible(&instance->msg_avail_comp);
  101237. + if (ret) {
  101238. + LOG_ERR("%s: failed on waiting for event (status=%d)",
  101239. + __func__, success);
  101240. + goto unlock;
  101241. + }
  101242. + if (instance->result != 0) {
  101243. + LOG_ERR("%s: failed result (status=%d)",
  101244. + __func__, instance->result);
  101245. +
  101246. + ret = -1;
  101247. + goto unlock;
  101248. + }
  101249. +
  101250. + ret = 0;
  101251. +
  101252. +unlock:
  101253. + vchi_service_release(instance->vchi_handle[0]);
  101254. + mutex_unlock(&instance->vchi_mutex);
  101255. +
  101256. + /* Stop the audio service */
  101257. + if (instance) {
  101258. + vc_vchi_audio_deinit(instance);
  101259. + alsa_stream->instance = NULL;
  101260. + }
  101261. + LOG_DBG(" .. OUT\n");
  101262. + return ret;
  101263. +}
  101264. +
  101265. +int bcm2835_audio_write_worker(bcm2835_alsa_stream_t *alsa_stream,
  101266. + uint32_t count, void *src)
  101267. +{
  101268. + VC_AUDIO_MSG_T m;
  101269. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  101270. + int32_t success;
  101271. + int ret;
  101272. +
  101273. + LOG_DBG(" .. IN\n");
  101274. +
  101275. + LOG_INFO(" Writing %d bytes from %p\n", count, src);
  101276. +
  101277. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  101278. + {
  101279. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  101280. + return -EINTR;
  101281. + }
  101282. + vchi_service_use(instance->vchi_handle[0]);
  101283. +
  101284. + if ( instance->peer_version==0 && vchi_get_peer_version(instance->vchi_handle[0], &instance->peer_version) == 0 ) {
  101285. + LOG_DBG("%s: client version %d connected\n", __func__, instance->peer_version);
  101286. + }
  101287. + m.type = VC_AUDIO_MSG_TYPE_WRITE;
  101288. + m.u.write.count = count;
  101289. + // old version uses bulk, new version uses control
  101290. + m.u.write.max_packet = instance->peer_version < 2 || force_bulk ? 0:4000;
  101291. + m.u.write.callback = alsa_stream->fifo_irq_handler;
  101292. + m.u.write.cookie = alsa_stream;
  101293. + m.u.write.silence = src == NULL;
  101294. +
  101295. + /* Send the message to the videocore */
  101296. + success = vchi_msg_queue(instance->vchi_handle[0],
  101297. + &m, sizeof m,
  101298. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  101299. +
  101300. + if (success != 0) {
  101301. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)",
  101302. + __func__, success);
  101303. +
  101304. + ret = -1;
  101305. + goto unlock;
  101306. + }
  101307. + if (!m.u.write.silence) {
  101308. + if (m.u.write.max_packet == 0) {
  101309. + /* Send the message to the videocore */
  101310. + success = vchi_bulk_queue_transmit(instance->vchi_handle[0],
  101311. + src, count,
  101312. + 0 *
  101313. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED
  101314. + +
  101315. + 1 *
  101316. + VCHI_FLAGS_BLOCK_UNTIL_DATA_READ,
  101317. + NULL);
  101318. + } else {
  101319. + while (count > 0) {
  101320. + int bytes = min((int)m.u.write.max_packet, (int)count);
  101321. + success = vchi_msg_queue(instance->vchi_handle[0],
  101322. + src, bytes,
  101323. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  101324. + src = (char *)src + bytes;
  101325. + count -= bytes;
  101326. + }
  101327. + }
  101328. + if (success != 0) {
  101329. + LOG_ERR
  101330. + ("%s: failed on vchi_bulk_queue_transmit (status=%d)",
  101331. + __func__, success);
  101332. +
  101333. + ret = -1;
  101334. + goto unlock;
  101335. + }
  101336. + }
  101337. + ret = 0;
  101338. +
  101339. +unlock:
  101340. + vchi_service_release(instance->vchi_handle[0]);
  101341. + mutex_unlock(&instance->vchi_mutex);
  101342. + LOG_DBG(" .. OUT\n");
  101343. + return ret;
  101344. +}
  101345. +
  101346. +/**
  101347. + * Returns all buffers from arm->vc
  101348. + */
  101349. +void bcm2835_audio_flush_buffers(bcm2835_alsa_stream_t * alsa_stream)
  101350. +{
  101351. + LOG_DBG(" .. IN\n");
  101352. + LOG_DBG(" .. OUT\n");
  101353. + return;
  101354. +}
  101355. +
  101356. +/**
  101357. + * Forces VC to flush(drop) its filled playback buffers and
  101358. + * return them the us. (VC->ARM)
  101359. + */
  101360. +void bcm2835_audio_flush_playback_buffers(bcm2835_alsa_stream_t * alsa_stream)
  101361. +{
  101362. + LOG_DBG(" .. IN\n");
  101363. + LOG_DBG(" .. OUT\n");
  101364. +}
  101365. +
  101366. +uint32_t bcm2835_audio_retrieve_buffers(bcm2835_alsa_stream_t * alsa_stream)
  101367. +{
  101368. + uint32_t count = atomic_read(&alsa_stream->retrieved);
  101369. + atomic_sub(count, &alsa_stream->retrieved);
  101370. + return count;
  101371. +}
  101372. +
  101373. +module_param(force_bulk, bool, 0444);
  101374. +MODULE_PARM_DESC(force_bulk, "Force use of vchiq bulk for audio");
  101375. diff -Nur linux-3.13.11/sound/arm/Kconfig linux-rpi/sound/arm/Kconfig
  101376. --- linux-3.13.11/sound/arm/Kconfig 2014-04-23 01:49:33.000000000 +0200
  101377. +++ linux-rpi/sound/arm/Kconfig 2014-04-24 15:35:05.357578964 +0200
  101378. @@ -39,5 +39,12 @@
  101379. Say Y or M if you want to support any AC97 codec attached to
  101380. the PXA2xx AC97 interface.
  101381. +config SND_BCM2835
  101382. + tristate "BCM2835 ALSA driver"
  101383. + depends on ARCH_BCM2708 && BCM2708_VCHIQ && SND
  101384. + select SND_PCM
  101385. + help
  101386. + Say Y or M if you want to support BCM2835 Alsa pcm card driver
  101387. +
  101388. endif # SND_ARM
  101389. diff -Nur linux-3.13.11/sound/arm/Makefile linux-rpi/sound/arm/Makefile
  101390. --- linux-3.13.11/sound/arm/Makefile 2014-04-23 01:49:33.000000000 +0200
  101391. +++ linux-rpi/sound/arm/Makefile 2014-04-24 15:37:23.599102818 +0200
  101392. @@ -14,3 +14,8 @@
  101393. obj-$(CONFIG_SND_PXA2XX_AC97) += snd-pxa2xx-ac97.o
  101394. snd-pxa2xx-ac97-objs := pxa2xx-ac97.o
  101395. +
  101396. +obj-$(CONFIG_SND_BCM2835) += snd-bcm2835.o
  101397. +snd-bcm2835-objs := bcm2835.o bcm2835-ctl.o bcm2835-pcm.o bcm2835-vchiq.o
  101398. +
  101399. +ccflags-y += -Idrivers/misc/vc04_services -Idrivers/misc/vc04_services/interface/vcos/linuxkernel -D__VCCOREVER__=0x04000000
  101400. diff -Nur linux-3.13.11/sound/arm/vc_vchi_audioserv_defs.h linux-rpi/sound/arm/vc_vchi_audioserv_defs.h
  101401. --- linux-3.13.11/sound/arm/vc_vchi_audioserv_defs.h 1970-01-01 01:00:00.000000000 +0100
  101402. +++ linux-rpi/sound/arm/vc_vchi_audioserv_defs.h 2014-04-24 15:35:05.365579053 +0200
  101403. @@ -0,0 +1,116 @@
  101404. +/*****************************************************************************
  101405. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  101406. +*
  101407. +* Unless you and Broadcom execute a separate written software license
  101408. +* agreement governing use of this software, this software is licensed to you
  101409. +* under the terms of the GNU General Public License version 2, available at
  101410. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  101411. +*
  101412. +* Notwithstanding the above, under no circumstances may you combine this
  101413. +* software in any way with any other Broadcom software provided under a
  101414. +* license other than the GPL, without Broadcom's express prior written
  101415. +* consent.
  101416. +*****************************************************************************/
  101417. +
  101418. +#ifndef _VC_AUDIO_DEFS_H_
  101419. +#define _VC_AUDIO_DEFS_H_
  101420. +
  101421. +#define VC_AUDIOSERV_MIN_VER 1
  101422. +#define VC_AUDIOSERV_VER 2
  101423. +
  101424. +// FourCC code used for VCHI connection
  101425. +#define VC_AUDIO_SERVER_NAME MAKE_FOURCC("AUDS")
  101426. +
  101427. +// Maximum message length
  101428. +#define VC_AUDIO_MAX_MSG_LEN (sizeof( VC_AUDIO_MSG_T ))
  101429. +
  101430. +// List of screens that are currently supported
  101431. +// All message types supported for HOST->VC direction
  101432. +typedef enum {
  101433. + VC_AUDIO_MSG_TYPE_RESULT, // Generic result
  101434. + VC_AUDIO_MSG_TYPE_COMPLETE, // Generic result
  101435. + VC_AUDIO_MSG_TYPE_CONFIG, // Configure audio
  101436. + VC_AUDIO_MSG_TYPE_CONTROL, // Configure audio
  101437. + VC_AUDIO_MSG_TYPE_OPEN, // Configure audio
  101438. + VC_AUDIO_MSG_TYPE_CLOSE, // Configure audio
  101439. + VC_AUDIO_MSG_TYPE_START, // Configure audio
  101440. + VC_AUDIO_MSG_TYPE_STOP, // Configure audio
  101441. + VC_AUDIO_MSG_TYPE_WRITE, // Configure audio
  101442. + VC_AUDIO_MSG_TYPE_MAX
  101443. +} VC_AUDIO_MSG_TYPE;
  101444. +
  101445. +// configure the audio
  101446. +typedef struct {
  101447. + uint32_t channels;
  101448. + uint32_t samplerate;
  101449. + uint32_t bps;
  101450. +
  101451. +} VC_AUDIO_CONFIG_T;
  101452. +
  101453. +typedef struct {
  101454. + uint32_t volume;
  101455. + uint32_t dest;
  101456. +
  101457. +} VC_AUDIO_CONTROL_T;
  101458. +
  101459. +// audio
  101460. +typedef struct {
  101461. + uint32_t dummy;
  101462. +
  101463. +} VC_AUDIO_OPEN_T;
  101464. +
  101465. +// audio
  101466. +typedef struct {
  101467. + uint32_t dummy;
  101468. +
  101469. +} VC_AUDIO_CLOSE_T;
  101470. +// audio
  101471. +typedef struct {
  101472. + uint32_t dummy;
  101473. +
  101474. +} VC_AUDIO_START_T;
  101475. +// audio
  101476. +typedef struct {
  101477. + uint32_t draining;
  101478. +
  101479. +} VC_AUDIO_STOP_T;
  101480. +
  101481. +// configure the write audio samples
  101482. +typedef struct {
  101483. + uint32_t count; // in bytes
  101484. + void *callback;
  101485. + void *cookie;
  101486. + uint16_t silence;
  101487. + uint16_t max_packet;
  101488. +} VC_AUDIO_WRITE_T;
  101489. +
  101490. +// Generic result for a request (VC->HOST)
  101491. +typedef struct {
  101492. + int32_t success; // Success value
  101493. +
  101494. +} VC_AUDIO_RESULT_T;
  101495. +
  101496. +// Generic result for a request (VC->HOST)
  101497. +typedef struct {
  101498. + int32_t count; // Success value
  101499. + void *callback;
  101500. + void *cookie;
  101501. +} VC_AUDIO_COMPLETE_T;
  101502. +
  101503. +// Message header for all messages in HOST->VC direction
  101504. +typedef struct {
  101505. + int32_t type; // Message type (VC_AUDIO_MSG_TYPE)
  101506. + union {
  101507. + VC_AUDIO_CONFIG_T config;
  101508. + VC_AUDIO_CONTROL_T control;
  101509. + VC_AUDIO_OPEN_T open;
  101510. + VC_AUDIO_CLOSE_T close;
  101511. + VC_AUDIO_START_T start;
  101512. + VC_AUDIO_STOP_T stop;
  101513. + VC_AUDIO_WRITE_T write;
  101514. + VC_AUDIO_RESULT_T result;
  101515. + VC_AUDIO_COMPLETE_T complete;
  101516. + } u;
  101517. +} VC_AUDIO_MSG_T;
  101518. +
  101519. +#endif // _VC_AUDIO_DEFS_H_
  101520. diff -Nur linux-3.13.11/sound/soc/bcm/bcm2708-i2s.c linux-rpi/sound/soc/bcm/bcm2708-i2s.c
  101521. --- linux-3.13.11/sound/soc/bcm/bcm2708-i2s.c 1970-01-01 01:00:00.000000000 +0100
  101522. +++ linux-rpi/sound/soc/bcm/bcm2708-i2s.c 2014-04-24 15:37:24.123108534 +0200
  101523. @@ -0,0 +1,945 @@
  101524. +/*
  101525. + * ALSA SoC I2S Audio Layer for Broadcom BCM2708 SoC
  101526. + *
  101527. + * Author: Florian Meier <florian.meier@koalo.de>
  101528. + * Copyright 2013
  101529. + *
  101530. + * Based on
  101531. + * Raspberry Pi PCM I2S ALSA Driver
  101532. + * Copyright (c) by Phil Poole 2013
  101533. + *
  101534. + * ALSA SoC I2S (McBSP) Audio Layer for TI DAVINCI processor
  101535. + * Vladimir Barinov, <vbarinov@embeddedalley.com>
  101536. + * Copyright (C) 2007 MontaVista Software, Inc., <source@mvista.com>
  101537. + *
  101538. + * OMAP ALSA SoC DAI driver using McBSP port
  101539. + * Copyright (C) 2008 Nokia Corporation
  101540. + * Contact: Jarkko Nikula <jarkko.nikula@bitmer.com>
  101541. + * Peter Ujfalusi <peter.ujfalusi@ti.com>
  101542. + *
  101543. + * Freescale SSI ALSA SoC Digital Audio Interface (DAI) driver
  101544. + * Author: Timur Tabi <timur@freescale.com>
  101545. + * Copyright 2007-2010 Freescale Semiconductor, Inc.
  101546. + *
  101547. + * This program is free software; you can redistribute it and/or
  101548. + * modify it under the terms of the GNU General Public License
  101549. + * version 2 as published by the Free Software Foundation.
  101550. + *
  101551. + * This program is distributed in the hope that it will be useful, but
  101552. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  101553. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  101554. + * General Public License for more details.
  101555. + */
  101556. +
  101557. +#include <linux/init.h>
  101558. +#include <linux/module.h>
  101559. +#include <linux/device.h>
  101560. +#include <linux/slab.h>
  101561. +#include <linux/delay.h>
  101562. +#include <linux/io.h>
  101563. +#include <linux/clk.h>
  101564. +
  101565. +#include <sound/core.h>
  101566. +#include <sound/pcm.h>
  101567. +#include <sound/pcm_params.h>
  101568. +#include <sound/initval.h>
  101569. +#include <sound/soc.h>
  101570. +#include <sound/dmaengine_pcm.h>
  101571. +
  101572. +/* Clock registers */
  101573. +#define BCM2708_CLK_PCMCTL_REG 0x00
  101574. +#define BCM2708_CLK_PCMDIV_REG 0x04
  101575. +
  101576. +/* Clock register settings */
  101577. +#define BCM2708_CLK_PASSWD (0x5a000000)
  101578. +#define BCM2708_CLK_PASSWD_MASK (0xff000000)
  101579. +#define BCM2708_CLK_MASH(v) ((v) << 9)
  101580. +#define BCM2708_CLK_FLIP BIT(8)
  101581. +#define BCM2708_CLK_BUSY BIT(7)
  101582. +#define BCM2708_CLK_KILL BIT(5)
  101583. +#define BCM2708_CLK_ENAB BIT(4)
  101584. +#define BCM2708_CLK_SRC(v) (v)
  101585. +
  101586. +#define BCM2708_CLK_SHIFT (12)
  101587. +#define BCM2708_CLK_DIVI(v) ((v) << BCM2708_CLK_SHIFT)
  101588. +#define BCM2708_CLK_DIVF(v) (v)
  101589. +#define BCM2708_CLK_DIVF_MASK (0xFFF)
  101590. +
  101591. +enum {
  101592. + BCM2708_CLK_MASH_0 = 0,
  101593. + BCM2708_CLK_MASH_1,
  101594. + BCM2708_CLK_MASH_2,
  101595. + BCM2708_CLK_MASH_3,
  101596. +};
  101597. +
  101598. +enum {
  101599. + BCM2708_CLK_SRC_GND = 0,
  101600. + BCM2708_CLK_SRC_OSC,
  101601. + BCM2708_CLK_SRC_DBG0,
  101602. + BCM2708_CLK_SRC_DBG1,
  101603. + BCM2708_CLK_SRC_PLLA,
  101604. + BCM2708_CLK_SRC_PLLC,
  101605. + BCM2708_CLK_SRC_PLLD,
  101606. + BCM2708_CLK_SRC_HDMI,
  101607. +};
  101608. +
  101609. +/* Most clocks are not useable (freq = 0) */
  101610. +static const unsigned int bcm2708_clk_freq[BCM2708_CLK_SRC_HDMI+1] = {
  101611. + [BCM2708_CLK_SRC_GND] = 0,
  101612. + [BCM2708_CLK_SRC_OSC] = 19200000,
  101613. + [BCM2708_CLK_SRC_DBG0] = 0,
  101614. + [BCM2708_CLK_SRC_DBG1] = 0,
  101615. + [BCM2708_CLK_SRC_PLLA] = 0,
  101616. + [BCM2708_CLK_SRC_PLLC] = 0,
  101617. + [BCM2708_CLK_SRC_PLLD] = 500000000,
  101618. + [BCM2708_CLK_SRC_HDMI] = 0,
  101619. +};
  101620. +
  101621. +/* I2S registers */
  101622. +#define BCM2708_I2S_CS_A_REG 0x00
  101623. +#define BCM2708_I2S_FIFO_A_REG 0x04
  101624. +#define BCM2708_I2S_MODE_A_REG 0x08
  101625. +#define BCM2708_I2S_RXC_A_REG 0x0c
  101626. +#define BCM2708_I2S_TXC_A_REG 0x10
  101627. +#define BCM2708_I2S_DREQ_A_REG 0x14
  101628. +#define BCM2708_I2S_INTEN_A_REG 0x18
  101629. +#define BCM2708_I2S_INTSTC_A_REG 0x1c
  101630. +#define BCM2708_I2S_GRAY_REG 0x20
  101631. +
  101632. +/* I2S register settings */
  101633. +#define BCM2708_I2S_STBY BIT(25)
  101634. +#define BCM2708_I2S_SYNC BIT(24)
  101635. +#define BCM2708_I2S_RXSEX BIT(23)
  101636. +#define BCM2708_I2S_RXF BIT(22)
  101637. +#define BCM2708_I2S_TXE BIT(21)
  101638. +#define BCM2708_I2S_RXD BIT(20)
  101639. +#define BCM2708_I2S_TXD BIT(19)
  101640. +#define BCM2708_I2S_RXR BIT(18)
  101641. +#define BCM2708_I2S_TXW BIT(17)
  101642. +#define BCM2708_I2S_CS_RXERR BIT(16)
  101643. +#define BCM2708_I2S_CS_TXERR BIT(15)
  101644. +#define BCM2708_I2S_RXSYNC BIT(14)
  101645. +#define BCM2708_I2S_TXSYNC BIT(13)
  101646. +#define BCM2708_I2S_DMAEN BIT(9)
  101647. +#define BCM2708_I2S_RXTHR(v) ((v) << 7)
  101648. +#define BCM2708_I2S_TXTHR(v) ((v) << 5)
  101649. +#define BCM2708_I2S_RXCLR BIT(4)
  101650. +#define BCM2708_I2S_TXCLR BIT(3)
  101651. +#define BCM2708_I2S_TXON BIT(2)
  101652. +#define BCM2708_I2S_RXON BIT(1)
  101653. +#define BCM2708_I2S_EN (1)
  101654. +
  101655. +#define BCM2708_I2S_CLKDIS BIT(28)
  101656. +#define BCM2708_I2S_PDMN BIT(27)
  101657. +#define BCM2708_I2S_PDME BIT(26)
  101658. +#define BCM2708_I2S_FRXP BIT(25)
  101659. +#define BCM2708_I2S_FTXP BIT(24)
  101660. +#define BCM2708_I2S_CLKM BIT(23)
  101661. +#define BCM2708_I2S_CLKI BIT(22)
  101662. +#define BCM2708_I2S_FSM BIT(21)
  101663. +#define BCM2708_I2S_FSI BIT(20)
  101664. +#define BCM2708_I2S_FLEN(v) ((v) << 10)
  101665. +#define BCM2708_I2S_FSLEN(v) (v)
  101666. +
  101667. +#define BCM2708_I2S_CHWEX BIT(15)
  101668. +#define BCM2708_I2S_CHEN BIT(14)
  101669. +#define BCM2708_I2S_CHPOS(v) ((v) << 4)
  101670. +#define BCM2708_I2S_CHWID(v) (v)
  101671. +#define BCM2708_I2S_CH1(v) ((v) << 16)
  101672. +#define BCM2708_I2S_CH2(v) (v)
  101673. +
  101674. +#define BCM2708_I2S_TX_PANIC(v) ((v) << 24)
  101675. +#define BCM2708_I2S_RX_PANIC(v) ((v) << 16)
  101676. +#define BCM2708_I2S_TX(v) ((v) << 8)
  101677. +#define BCM2708_I2S_RX(v) (v)
  101678. +
  101679. +#define BCM2708_I2S_INT_RXERR BIT(3)
  101680. +#define BCM2708_I2S_INT_TXERR BIT(2)
  101681. +#define BCM2708_I2S_INT_RXR BIT(1)
  101682. +#define BCM2708_I2S_INT_TXW BIT(0)
  101683. +
  101684. +/* I2S DMA interface */
  101685. +#define BCM2708_I2S_FIFO_PHYSICAL_ADDR 0x7E203004
  101686. +#define BCM2708_DMA_DREQ_PCM_TX 2
  101687. +#define BCM2708_DMA_DREQ_PCM_RX 3
  101688. +
  101689. +/* General device struct */
  101690. +struct bcm2708_i2s_dev {
  101691. + struct device *dev;
  101692. + struct snd_dmaengine_dai_dma_data dma_data[2];
  101693. + unsigned int fmt;
  101694. + unsigned int bclk_ratio;
  101695. +
  101696. + struct regmap *i2s_regmap;
  101697. + struct regmap *clk_regmap;
  101698. +};
  101699. +
  101700. +static void bcm2708_i2s_start_clock(struct bcm2708_i2s_dev *dev)
  101701. +{
  101702. + /* Start the clock if in master mode */
  101703. + unsigned int master = dev->fmt & SND_SOC_DAIFMT_MASTER_MASK;
  101704. +
  101705. + switch (master) {
  101706. + case SND_SOC_DAIFMT_CBS_CFS:
  101707. + case SND_SOC_DAIFMT_CBS_CFM:
  101708. + regmap_update_bits(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG,
  101709. + BCM2708_CLK_PASSWD_MASK | BCM2708_CLK_ENAB,
  101710. + BCM2708_CLK_PASSWD | BCM2708_CLK_ENAB);
  101711. + break;
  101712. + default:
  101713. + break;
  101714. + }
  101715. +}
  101716. +
  101717. +static void bcm2708_i2s_stop_clock(struct bcm2708_i2s_dev *dev)
  101718. +{
  101719. + uint32_t clkreg;
  101720. + int timeout = 1000;
  101721. +
  101722. + /* Stop clock */
  101723. + regmap_update_bits(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG,
  101724. + BCM2708_CLK_PASSWD_MASK | BCM2708_CLK_ENAB,
  101725. + BCM2708_CLK_PASSWD);
  101726. +
  101727. + /* Wait for the BUSY flag going down */
  101728. + while (--timeout) {
  101729. + regmap_read(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG, &clkreg);
  101730. + if (!(clkreg & BCM2708_CLK_BUSY))
  101731. + break;
  101732. + }
  101733. +
  101734. + if (!timeout) {
  101735. + /* KILL the clock */
  101736. + dev_err(dev->dev, "I2S clock didn't stop. Kill the clock!\n");
  101737. + regmap_update_bits(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG,
  101738. + BCM2708_CLK_KILL | BCM2708_CLK_PASSWD_MASK,
  101739. + BCM2708_CLK_KILL | BCM2708_CLK_PASSWD);
  101740. + }
  101741. +}
  101742. +
  101743. +static void bcm2708_i2s_clear_fifos(struct bcm2708_i2s_dev *dev,
  101744. + bool tx, bool rx)
  101745. +{
  101746. + int timeout = 1000;
  101747. + uint32_t syncval;
  101748. + uint32_t csreg;
  101749. + uint32_t i2s_active_state;
  101750. + uint32_t clkreg;
  101751. + uint32_t clk_active_state;
  101752. + uint32_t off;
  101753. + uint32_t clr;
  101754. +
  101755. + off = tx ? BCM2708_I2S_TXON : 0;
  101756. + off |= rx ? BCM2708_I2S_RXON : 0;
  101757. +
  101758. + clr = tx ? BCM2708_I2S_TXCLR : 0;
  101759. + clr |= rx ? BCM2708_I2S_RXCLR : 0;
  101760. +
  101761. + /* Backup the current state */
  101762. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &csreg);
  101763. + i2s_active_state = csreg & (BCM2708_I2S_RXON | BCM2708_I2S_TXON);
  101764. +
  101765. + regmap_read(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG, &clkreg);
  101766. + clk_active_state = clkreg & BCM2708_CLK_ENAB;
  101767. +
  101768. + /* Start clock if not running */
  101769. + if (!clk_active_state) {
  101770. + regmap_update_bits(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG,
  101771. + BCM2708_CLK_PASSWD_MASK | BCM2708_CLK_ENAB,
  101772. + BCM2708_CLK_PASSWD | BCM2708_CLK_ENAB);
  101773. + }
  101774. +
  101775. + /* Stop I2S module */
  101776. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, off, 0);
  101777. +
  101778. + /*
  101779. + * Clear the FIFOs
  101780. + * Requires at least 2 PCM clock cycles to take effect
  101781. + */
  101782. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, clr, clr);
  101783. +
  101784. + /* Wait for 2 PCM clock cycles */
  101785. +
  101786. + /*
  101787. + * Toggle the SYNC flag. After 2 PCM clock cycles it can be read back
  101788. + * FIXME: This does not seem to work for slave mode!
  101789. + */
  101790. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &syncval);
  101791. + syncval &= BCM2708_I2S_SYNC;
  101792. +
  101793. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  101794. + BCM2708_I2S_SYNC, ~syncval);
  101795. +
  101796. + /* Wait for the SYNC flag changing it's state */
  101797. + while (--timeout) {
  101798. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &csreg);
  101799. + if ((csreg & BCM2708_I2S_SYNC) != syncval)
  101800. + break;
  101801. + }
  101802. +
  101803. + if (!timeout)
  101804. + dev_err(dev->dev, "I2S SYNC error!\n");
  101805. +
  101806. + /* Stop clock if it was not running before */
  101807. + if (!clk_active_state)
  101808. + bcm2708_i2s_stop_clock(dev);
  101809. +
  101810. + /* Restore I2S state */
  101811. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  101812. + BCM2708_I2S_RXON | BCM2708_I2S_TXON, i2s_active_state);
  101813. +}
  101814. +
  101815. +static int bcm2708_i2s_set_dai_fmt(struct snd_soc_dai *dai,
  101816. + unsigned int fmt)
  101817. +{
  101818. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  101819. + dev->fmt = fmt;
  101820. + return 0;
  101821. +}
  101822. +
  101823. +static int bcm2708_i2s_set_dai_bclk_ratio(struct snd_soc_dai *dai,
  101824. + unsigned int ratio)
  101825. +{
  101826. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  101827. + dev->bclk_ratio = ratio;
  101828. + return 0;
  101829. +}
  101830. +
  101831. +static int bcm2708_i2s_hw_params(struct snd_pcm_substream *substream,
  101832. + struct snd_pcm_hw_params *params,
  101833. + struct snd_soc_dai *dai)
  101834. +{
  101835. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  101836. +
  101837. + unsigned int sampling_rate = params_rate(params);
  101838. + unsigned int data_length, data_delay, bclk_ratio;
  101839. + unsigned int ch1pos, ch2pos, mode, format;
  101840. + unsigned int mash = BCM2708_CLK_MASH_1;
  101841. + unsigned int divi, divf, target_frequency;
  101842. + int clk_src = -1;
  101843. + unsigned int master = dev->fmt & SND_SOC_DAIFMT_MASTER_MASK;
  101844. + bool bit_master = (master == SND_SOC_DAIFMT_CBS_CFS
  101845. + || master == SND_SOC_DAIFMT_CBS_CFM);
  101846. +
  101847. + bool frame_master = (master == SND_SOC_DAIFMT_CBS_CFS
  101848. + || master == SND_SOC_DAIFMT_CBM_CFS);
  101849. + uint32_t csreg;
  101850. +
  101851. + /*
  101852. + * If a stream is already enabled,
  101853. + * the registers are already set properly.
  101854. + */
  101855. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &csreg);
  101856. +
  101857. + if (csreg & (BCM2708_I2S_TXON | BCM2708_I2S_RXON))
  101858. + return 0;
  101859. +
  101860. + /*
  101861. + * Adjust the data length according to the format.
  101862. + * We prefill the half frame length with an integer
  101863. + * divider of 2400 as explained at the clock settings.
  101864. + * Maybe it is overwritten there, if the Integer mode
  101865. + * does not apply.
  101866. + */
  101867. + switch (params_format(params)) {
  101868. + case SNDRV_PCM_FORMAT_S16_LE:
  101869. + data_length = 16;
  101870. + bclk_ratio = 40;
  101871. + break;
  101872. + case SNDRV_PCM_FORMAT_S24_LE:
  101873. + data_length = 24;
  101874. + bclk_ratio = 40;
  101875. + break;
  101876. + case SNDRV_PCM_FORMAT_S32_LE:
  101877. + data_length = 32;
  101878. + bclk_ratio = 80;
  101879. + break;
  101880. + default:
  101881. + return -EINVAL;
  101882. + }
  101883. +
  101884. + /* If bclk_ratio already set, use that one. */
  101885. + if (dev->bclk_ratio)
  101886. + bclk_ratio = dev->bclk_ratio;
  101887. +
  101888. + /*
  101889. + * Clock Settings
  101890. + *
  101891. + * The target frequency of the bit clock is
  101892. + * sampling rate * frame length
  101893. + *
  101894. + * Integer mode:
  101895. + * Sampling rates that are multiples of 8000 kHz
  101896. + * can be driven by the oscillator of 19.2 MHz
  101897. + * with an integer divider as long as the frame length
  101898. + * is an integer divider of 19200000/8000=2400 as set up above.
  101899. + * This is no longer possible if the sampling rate
  101900. + * is too high (e.g. 192 kHz), because the oscillator is too slow.
  101901. + *
  101902. + * MASH mode:
  101903. + * For all other sampling rates, it is not possible to
  101904. + * have an integer divider. Approximate the clock
  101905. + * with the MASH module that induces a slight frequency
  101906. + * variance. To minimize that it is best to have the fastest
  101907. + * clock here. That is PLLD with 500 MHz.
  101908. + */
  101909. + target_frequency = sampling_rate * bclk_ratio;
  101910. + clk_src = BCM2708_CLK_SRC_OSC;
  101911. + mash = BCM2708_CLK_MASH_0;
  101912. +
  101913. + if (bcm2708_clk_freq[clk_src] % target_frequency == 0
  101914. + && bit_master && frame_master) {
  101915. + divi = bcm2708_clk_freq[clk_src] / target_frequency;
  101916. + divf = 0;
  101917. + } else {
  101918. + uint64_t dividend;
  101919. +
  101920. + if (!dev->bclk_ratio) {
  101921. + /*
  101922. + * Overwrite bclk_ratio, because the
  101923. + * above trick is not needed or can
  101924. + * not be used.
  101925. + */
  101926. + bclk_ratio = 2 * data_length;
  101927. + }
  101928. +
  101929. + target_frequency = sampling_rate * bclk_ratio;
  101930. +
  101931. + clk_src = BCM2708_CLK_SRC_PLLD;
  101932. + mash = BCM2708_CLK_MASH_1;
  101933. +
  101934. + dividend = bcm2708_clk_freq[clk_src];
  101935. + dividend <<= BCM2708_CLK_SHIFT;
  101936. + do_div(dividend, target_frequency);
  101937. + divi = dividend >> BCM2708_CLK_SHIFT;
  101938. + divf = dividend & BCM2708_CLK_DIVF_MASK;
  101939. + }
  101940. +
  101941. + /* Set clock divider */
  101942. + regmap_write(dev->clk_regmap, BCM2708_CLK_PCMDIV_REG, BCM2708_CLK_PASSWD
  101943. + | BCM2708_CLK_DIVI(divi)
  101944. + | BCM2708_CLK_DIVF(divf));
  101945. +
  101946. + /* Setup clock, but don't start it yet */
  101947. + regmap_write(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG, BCM2708_CLK_PASSWD
  101948. + | BCM2708_CLK_MASH(mash)
  101949. + | BCM2708_CLK_SRC(clk_src));
  101950. +
  101951. + /* Setup the frame format */
  101952. + format = BCM2708_I2S_CHEN;
  101953. +
  101954. + if (data_length >= 24)
  101955. + format |= BCM2708_I2S_CHWEX;
  101956. +
  101957. + format |= BCM2708_I2S_CHWID((data_length-8)&0xf);
  101958. +
  101959. + switch (dev->fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  101960. + case SND_SOC_DAIFMT_I2S:
  101961. + data_delay = 1;
  101962. + break;
  101963. + default:
  101964. + /*
  101965. + * TODO
  101966. + * Others are possible but are not implemented at the moment.
  101967. + */
  101968. + dev_err(dev->dev, "%s:bad format\n", __func__);
  101969. + return -EINVAL;
  101970. + }
  101971. +
  101972. + ch1pos = data_delay;
  101973. + ch2pos = bclk_ratio / 2 + data_delay;
  101974. +
  101975. + switch (params_channels(params)) {
  101976. + case 2:
  101977. + format = BCM2708_I2S_CH1(format) | BCM2708_I2S_CH2(format);
  101978. + format |= BCM2708_I2S_CH1(BCM2708_I2S_CHPOS(ch1pos));
  101979. + format |= BCM2708_I2S_CH2(BCM2708_I2S_CHPOS(ch2pos));
  101980. + break;
  101981. + default:
  101982. + return -EINVAL;
  101983. + }
  101984. +
  101985. + /*
  101986. + * Set format for both streams.
  101987. + * We cannot set another frame length
  101988. + * (and therefore word length) anyway,
  101989. + * so the format will be the same.
  101990. + */
  101991. + regmap_write(dev->i2s_regmap, BCM2708_I2S_RXC_A_REG, format);
  101992. + regmap_write(dev->i2s_regmap, BCM2708_I2S_TXC_A_REG, format);
  101993. +
  101994. + /* Setup the I2S mode */
  101995. + mode = 0;
  101996. +
  101997. + if (data_length <= 16) {
  101998. + /*
  101999. + * Use frame packed mode (2 channels per 32 bit word)
  102000. + * We cannot set another frame length in the second stream
  102001. + * (and therefore word length) anyway,
  102002. + * so the format will be the same.
  102003. + */
  102004. + mode |= BCM2708_I2S_FTXP | BCM2708_I2S_FRXP;
  102005. + }
  102006. +
  102007. + mode |= BCM2708_I2S_FLEN(bclk_ratio - 1);
  102008. + mode |= BCM2708_I2S_FSLEN(bclk_ratio / 2);
  102009. +
  102010. + /* Master or slave? */
  102011. + switch (dev->fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  102012. + case SND_SOC_DAIFMT_CBS_CFS:
  102013. + /* CPU is master */
  102014. + break;
  102015. + case SND_SOC_DAIFMT_CBM_CFS:
  102016. + /*
  102017. + * CODEC is bit clock master
  102018. + * CPU is frame master
  102019. + */
  102020. + mode |= BCM2708_I2S_CLKM;
  102021. + break;
  102022. + case SND_SOC_DAIFMT_CBS_CFM:
  102023. + /*
  102024. + * CODEC is frame master
  102025. + * CPU is bit clock master
  102026. + */
  102027. + mode |= BCM2708_I2S_FSM;
  102028. + break;
  102029. + case SND_SOC_DAIFMT_CBM_CFM:
  102030. + /* CODEC is master */
  102031. + mode |= BCM2708_I2S_CLKM;
  102032. + mode |= BCM2708_I2S_FSM;
  102033. + break;
  102034. + default:
  102035. + dev_err(dev->dev, "%s:bad master\n", __func__);
  102036. + return -EINVAL;
  102037. + }
  102038. +
  102039. + /*
  102040. + * Invert clocks?
  102041. + *
  102042. + * The BCM approach seems to be inverted to the classical I2S approach.
  102043. + */
  102044. + switch (dev->fmt & SND_SOC_DAIFMT_INV_MASK) {
  102045. + case SND_SOC_DAIFMT_NB_NF:
  102046. + /* None. Therefore, both for BCM */
  102047. + mode |= BCM2708_I2S_CLKI;
  102048. + mode |= BCM2708_I2S_FSI;
  102049. + break;
  102050. + case SND_SOC_DAIFMT_IB_IF:
  102051. + /* Both. Therefore, none for BCM */
  102052. + break;
  102053. + case SND_SOC_DAIFMT_NB_IF:
  102054. + /*
  102055. + * Invert only frame sync. Therefore,
  102056. + * invert only bit clock for BCM
  102057. + */
  102058. + mode |= BCM2708_I2S_CLKI;
  102059. + break;
  102060. + case SND_SOC_DAIFMT_IB_NF:
  102061. + /*
  102062. + * Invert only bit clock. Therefore,
  102063. + * invert only frame sync for BCM
  102064. + */
  102065. + mode |= BCM2708_I2S_FSI;
  102066. + break;
  102067. + default:
  102068. + return -EINVAL;
  102069. + }
  102070. +
  102071. + regmap_write(dev->i2s_regmap, BCM2708_I2S_MODE_A_REG, mode);
  102072. +
  102073. + /* Setup the DMA parameters */
  102074. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  102075. + BCM2708_I2S_RXTHR(1)
  102076. + | BCM2708_I2S_TXTHR(1)
  102077. + | BCM2708_I2S_DMAEN, 0xffffffff);
  102078. +
  102079. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_DREQ_A_REG,
  102080. + BCM2708_I2S_TX_PANIC(0x10)
  102081. + | BCM2708_I2S_RX_PANIC(0x30)
  102082. + | BCM2708_I2S_TX(0x30)
  102083. + | BCM2708_I2S_RX(0x20), 0xffffffff);
  102084. +
  102085. + /* Clear FIFOs */
  102086. + bcm2708_i2s_clear_fifos(dev, true, true);
  102087. +
  102088. + return 0;
  102089. +}
  102090. +
  102091. +static int bcm2708_i2s_prepare(struct snd_pcm_substream *substream,
  102092. + struct snd_soc_dai *dai)
  102093. +{
  102094. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  102095. + uint32_t cs_reg;
  102096. +
  102097. + bcm2708_i2s_start_clock(dev);
  102098. +
  102099. + /*
  102100. + * Clear both FIFOs if the one that should be started
  102101. + * is not empty at the moment. This should only happen
  102102. + * after overrun. Otherwise, hw_params would have cleared
  102103. + * the FIFO.
  102104. + */
  102105. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &cs_reg);
  102106. +
  102107. + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK
  102108. + && !(cs_reg & BCM2708_I2S_TXE))
  102109. + bcm2708_i2s_clear_fifos(dev, true, false);
  102110. + else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE
  102111. + && (cs_reg & BCM2708_I2S_RXD))
  102112. + bcm2708_i2s_clear_fifos(dev, false, true);
  102113. +
  102114. + return 0;
  102115. +}
  102116. +
  102117. +static void bcm2708_i2s_stop(struct bcm2708_i2s_dev *dev,
  102118. + struct snd_pcm_substream *substream,
  102119. + struct snd_soc_dai *dai)
  102120. +{
  102121. + uint32_t mask;
  102122. +
  102123. + if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
  102124. + mask = BCM2708_I2S_RXON;
  102125. + else
  102126. + mask = BCM2708_I2S_TXON;
  102127. +
  102128. + regmap_update_bits(dev->i2s_regmap,
  102129. + BCM2708_I2S_CS_A_REG, mask, 0);
  102130. +
  102131. + /* Stop also the clock when not SND_SOC_DAIFMT_CONT */
  102132. + if (!dai->active && !(dev->fmt & SND_SOC_DAIFMT_CONT))
  102133. + bcm2708_i2s_stop_clock(dev);
  102134. +}
  102135. +
  102136. +static int bcm2708_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
  102137. + struct snd_soc_dai *dai)
  102138. +{
  102139. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  102140. + uint32_t mask;
  102141. +
  102142. + switch (cmd) {
  102143. + case SNDRV_PCM_TRIGGER_START:
  102144. + case SNDRV_PCM_TRIGGER_RESUME:
  102145. + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  102146. + bcm2708_i2s_start_clock(dev);
  102147. +
  102148. + if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
  102149. + mask = BCM2708_I2S_RXON;
  102150. + else
  102151. + mask = BCM2708_I2S_TXON;
  102152. +
  102153. + regmap_update_bits(dev->i2s_regmap,
  102154. + BCM2708_I2S_CS_A_REG, mask, mask);
  102155. + break;
  102156. +
  102157. + case SNDRV_PCM_TRIGGER_STOP:
  102158. + case SNDRV_PCM_TRIGGER_SUSPEND:
  102159. + case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  102160. + bcm2708_i2s_stop(dev, substream, dai);
  102161. + break;
  102162. + default:
  102163. + return -EINVAL;
  102164. + }
  102165. +
  102166. + return 0;
  102167. +}
  102168. +
  102169. +static int bcm2708_i2s_startup(struct snd_pcm_substream *substream,
  102170. + struct snd_soc_dai *dai)
  102171. +{
  102172. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  102173. +
  102174. + if (dai->active)
  102175. + return 0;
  102176. +
  102177. + /* Should this still be running stop it */
  102178. + bcm2708_i2s_stop_clock(dev);
  102179. +
  102180. + /* Enable PCM block */
  102181. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  102182. + BCM2708_I2S_EN, BCM2708_I2S_EN);
  102183. +
  102184. + /*
  102185. + * Disable STBY.
  102186. + * Requires at least 4 PCM clock cycles to take effect.
  102187. + */
  102188. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  102189. + BCM2708_I2S_STBY, BCM2708_I2S_STBY);
  102190. +
  102191. + return 0;
  102192. +}
  102193. +
  102194. +static void bcm2708_i2s_shutdown(struct snd_pcm_substream *substream,
  102195. + struct snd_soc_dai *dai)
  102196. +{
  102197. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  102198. +
  102199. + bcm2708_i2s_stop(dev, substream, dai);
  102200. +
  102201. + /* If both streams are stopped, disable module and clock */
  102202. + if (dai->active)
  102203. + return;
  102204. +
  102205. + /* Disable the module */
  102206. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  102207. + BCM2708_I2S_EN, 0);
  102208. +
  102209. + /*
  102210. + * Stopping clock is necessary, because stop does
  102211. + * not stop the clock when SND_SOC_DAIFMT_CONT
  102212. + */
  102213. + bcm2708_i2s_stop_clock(dev);
  102214. +}
  102215. +
  102216. +static const struct snd_soc_dai_ops bcm2708_i2s_dai_ops = {
  102217. + .startup = bcm2708_i2s_startup,
  102218. + .shutdown = bcm2708_i2s_shutdown,
  102219. + .prepare = bcm2708_i2s_prepare,
  102220. + .trigger = bcm2708_i2s_trigger,
  102221. + .hw_params = bcm2708_i2s_hw_params,
  102222. + .set_fmt = bcm2708_i2s_set_dai_fmt,
  102223. + .set_bclk_ratio = bcm2708_i2s_set_dai_bclk_ratio
  102224. +};
  102225. +
  102226. +static int bcm2708_i2s_dai_probe(struct snd_soc_dai *dai)
  102227. +{
  102228. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  102229. +
  102230. + dai->playback_dma_data = &dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK];
  102231. + dai->capture_dma_data = &dev->dma_data[SNDRV_PCM_STREAM_CAPTURE];
  102232. +
  102233. + return 0;
  102234. +}
  102235. +
  102236. +static struct snd_soc_dai_driver bcm2708_i2s_dai = {
  102237. + .name = "bcm2708-i2s",
  102238. + .probe = bcm2708_i2s_dai_probe,
  102239. + .playback = {
  102240. + .channels_min = 2,
  102241. + .channels_max = 2,
  102242. + .rates = SNDRV_PCM_RATE_8000_192000,
  102243. + .formats = SNDRV_PCM_FMTBIT_S16_LE
  102244. + // | SNDRV_PCM_FMTBIT_S24_LE : disable for now, it causes white noise with xbmc
  102245. + | SNDRV_PCM_FMTBIT_S32_LE
  102246. + },
  102247. + .capture = {
  102248. + .channels_min = 2,
  102249. + .channels_max = 2,
  102250. + .rates = SNDRV_PCM_RATE_8000_192000,
  102251. + .formats = SNDRV_PCM_FMTBIT_S16_LE
  102252. + | SNDRV_PCM_FMTBIT_S24_LE
  102253. + | SNDRV_PCM_FMTBIT_S32_LE
  102254. + },
  102255. + .ops = &bcm2708_i2s_dai_ops,
  102256. + .symmetric_rates = 1
  102257. +};
  102258. +
  102259. +static bool bcm2708_i2s_volatile_reg(struct device *dev, unsigned int reg)
  102260. +{
  102261. + switch (reg) {
  102262. + case BCM2708_I2S_CS_A_REG:
  102263. + case BCM2708_I2S_FIFO_A_REG:
  102264. + case BCM2708_I2S_INTSTC_A_REG:
  102265. + case BCM2708_I2S_GRAY_REG:
  102266. + return true;
  102267. + default:
  102268. + return false;
  102269. + };
  102270. +}
  102271. +
  102272. +static bool bcm2708_i2s_precious_reg(struct device *dev, unsigned int reg)
  102273. +{
  102274. + switch (reg) {
  102275. + case BCM2708_I2S_FIFO_A_REG:
  102276. + return true;
  102277. + default:
  102278. + return false;
  102279. + };
  102280. +}
  102281. +
  102282. +static bool bcm2708_clk_volatile_reg(struct device *dev, unsigned int reg)
  102283. +{
  102284. + switch (reg) {
  102285. + case BCM2708_CLK_PCMCTL_REG:
  102286. + return true;
  102287. + default:
  102288. + return false;
  102289. + };
  102290. +}
  102291. +
  102292. +static const struct regmap_config bcm2708_regmap_config[] = {
  102293. + {
  102294. + .reg_bits = 32,
  102295. + .reg_stride = 4,
  102296. + .val_bits = 32,
  102297. + .max_register = BCM2708_I2S_GRAY_REG,
  102298. + .precious_reg = bcm2708_i2s_precious_reg,
  102299. + .volatile_reg = bcm2708_i2s_volatile_reg,
  102300. + .cache_type = REGCACHE_RBTREE,
  102301. + },
  102302. + {
  102303. + .reg_bits = 32,
  102304. + .reg_stride = 4,
  102305. + .val_bits = 32,
  102306. + .max_register = BCM2708_CLK_PCMDIV_REG,
  102307. + .volatile_reg = bcm2708_clk_volatile_reg,
  102308. + .cache_type = REGCACHE_RBTREE,
  102309. + },
  102310. +};
  102311. +
  102312. +static const struct snd_soc_component_driver bcm2708_i2s_component = {
  102313. + .name = "bcm2708-i2s-comp",
  102314. +};
  102315. +
  102316. +
  102317. +static void bcm2708_i2s_setup_gpio(void)
  102318. +{
  102319. + /*
  102320. + * This is the common way to handle the GPIO pins for
  102321. + * the Raspberry Pi.
  102322. + * TODO Better way would be to handle
  102323. + * this in the device tree!
  102324. + */
  102325. +#define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3))
  102326. +#define SET_GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3))
  102327. +
  102328. + unsigned int *gpio;
  102329. + int pin;
  102330. + gpio = ioremap(GPIO_BASE, SZ_16K);
  102331. +
  102332. + /* SPI is on GPIO 7..11 */
  102333. + for (pin = 28; pin <= 31; pin++) {
  102334. + INP_GPIO(pin); /* set mode to GPIO input first */
  102335. + SET_GPIO_ALT(pin, 2); /* set mode to ALT 0 */
  102336. + }
  102337. +#undef INP_GPIO
  102338. +#undef SET_GPIO_ALT
  102339. +}
  102340. +
  102341. +static const struct snd_pcm_hardware bcm2708_pcm_hardware = {
  102342. + .info = SNDRV_PCM_INFO_INTERLEAVED |
  102343. + SNDRV_PCM_INFO_JOINT_DUPLEX,
  102344. + .formats = SNDRV_PCM_FMTBIT_S16_LE |
  102345. + SNDRV_PCM_FMTBIT_S24_LE |
  102346. + SNDRV_PCM_FMTBIT_S32_LE,
  102347. + .period_bytes_min = 32,
  102348. + .period_bytes_max = 64 * PAGE_SIZE,
  102349. + .periods_min = 2,
  102350. + .periods_max = 255,
  102351. + .buffer_bytes_max = 128 * PAGE_SIZE,
  102352. +};
  102353. +
  102354. +static const struct snd_dmaengine_pcm_config bcm2708_dmaengine_pcm_config = {
  102355. + .prepare_slave_config = snd_dmaengine_pcm_prepare_slave_config,
  102356. + .pcm_hardware = &bcm2708_pcm_hardware,
  102357. + .prealloc_buffer_size = 256 * PAGE_SIZE,
  102358. +};
  102359. +
  102360. +
  102361. +static int bcm2708_i2s_probe(struct platform_device *pdev)
  102362. +{
  102363. + struct bcm2708_i2s_dev *dev;
  102364. + int i;
  102365. + int ret;
  102366. + struct regmap *regmap[2];
  102367. + struct resource *mem[2];
  102368. +
  102369. + /* Request both ioareas */
  102370. + for (i = 0; i <= 1; i++) {
  102371. + void __iomem *base;
  102372. +
  102373. + mem[i] = platform_get_resource(pdev, IORESOURCE_MEM, i);
  102374. + base = devm_ioremap_resource(&pdev->dev, mem[i]);
  102375. + if (IS_ERR(base))
  102376. + return PTR_ERR(base);
  102377. +
  102378. + regmap[i] = devm_regmap_init_mmio(&pdev->dev, base,
  102379. + &bcm2708_regmap_config[i]);
  102380. + if (IS_ERR(regmap[i])) {
  102381. + dev_err(&pdev->dev, "I2S probe: regmap init failed\n");
  102382. + return PTR_ERR(regmap[i]);
  102383. + }
  102384. + }
  102385. +
  102386. + dev = devm_kzalloc(&pdev->dev, sizeof(*dev),
  102387. + GFP_KERNEL);
  102388. + if (IS_ERR(dev))
  102389. + return PTR_ERR(dev);
  102390. +
  102391. + bcm2708_i2s_setup_gpio();
  102392. +
  102393. + dev->i2s_regmap = regmap[0];
  102394. + dev->clk_regmap = regmap[1];
  102395. +
  102396. + /* Set the DMA address */
  102397. + dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].addr =
  102398. + (dma_addr_t)BCM2708_I2S_FIFO_PHYSICAL_ADDR;
  102399. +
  102400. + dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].addr =
  102401. + (dma_addr_t)BCM2708_I2S_FIFO_PHYSICAL_ADDR;
  102402. +
  102403. + /* Set the DREQ */
  102404. + dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].slave_id =
  102405. + BCM2708_DMA_DREQ_PCM_TX;
  102406. + dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].slave_id =
  102407. + BCM2708_DMA_DREQ_PCM_RX;
  102408. +
  102409. + /* Set the bus width */
  102410. + dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].addr_width =
  102411. + DMA_SLAVE_BUSWIDTH_4_BYTES;
  102412. + dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].addr_width =
  102413. + DMA_SLAVE_BUSWIDTH_4_BYTES;
  102414. +
  102415. + /* Set burst */
  102416. + dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].maxburst = 2;
  102417. + dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].maxburst = 2;
  102418. +
  102419. + /* BCLK ratio - use default */
  102420. + dev->bclk_ratio = 0;
  102421. +
  102422. + /* Store the pdev */
  102423. + dev->dev = &pdev->dev;
  102424. + dev_set_drvdata(&pdev->dev, dev);
  102425. +
  102426. + ret = snd_soc_register_component(&pdev->dev,
  102427. + &bcm2708_i2s_component, &bcm2708_i2s_dai, 1);
  102428. +
  102429. + if (ret) {
  102430. + dev_err(&pdev->dev, "Could not register DAI: %d\n", ret);
  102431. + ret = -ENOMEM;
  102432. + return ret;
  102433. + }
  102434. +
  102435. + ret = snd_dmaengine_pcm_register(&pdev->dev,
  102436. + &bcm2708_dmaengine_pcm_config,
  102437. + SND_DMAENGINE_PCM_FLAG_COMPAT);
  102438. + if (ret) {
  102439. + dev_err(&pdev->dev, "Could not register PCM: %d\n", ret);
  102440. + snd_soc_unregister_component(&pdev->dev);
  102441. + return ret;
  102442. + }
  102443. +
  102444. + return 0;
  102445. +}
  102446. +
  102447. +static int bcm2708_i2s_remove(struct platform_device *pdev)
  102448. +{
  102449. + snd_dmaengine_pcm_unregister(&pdev->dev);
  102450. + snd_soc_unregister_component(&pdev->dev);
  102451. + return 0;
  102452. +}
  102453. +
  102454. +static struct platform_driver bcm2708_i2s_driver = {
  102455. + .probe = bcm2708_i2s_probe,
  102456. + .remove = bcm2708_i2s_remove,
  102457. + .driver = {
  102458. + .name = "bcm2708-i2s",
  102459. + .owner = THIS_MODULE,
  102460. + },
  102461. +};
  102462. +
  102463. +module_platform_driver(bcm2708_i2s_driver);
  102464. +
  102465. +MODULE_ALIAS("platform:bcm2708-i2s");
  102466. +MODULE_DESCRIPTION("BCM2708 I2S interface");
  102467. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  102468. +MODULE_LICENSE("GPL v2");
  102469. diff -Nur linux-3.13.11/sound/soc/bcm/hifiberry_dac.c linux-rpi/sound/soc/bcm/hifiberry_dac.c
  102470. --- linux-3.13.11/sound/soc/bcm/hifiberry_dac.c 1970-01-01 01:00:00.000000000 +0100
  102471. +++ linux-rpi/sound/soc/bcm/hifiberry_dac.c 2014-04-24 15:35:05.481580345 +0200
  102472. @@ -0,0 +1,100 @@
  102473. +/*
  102474. + * ASoC Driver for HifiBerry DAC
  102475. + *
  102476. + * Author: Florian Meier <florian.meier@koalo.de>
  102477. + * Copyright 2013
  102478. + *
  102479. + * This program is free software; you can redistribute it and/or
  102480. + * modify it under the terms of the GNU General Public License
  102481. + * version 2 as published by the Free Software Foundation.
  102482. + *
  102483. + * This program is distributed in the hope that it will be useful, but
  102484. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  102485. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  102486. + * General Public License for more details.
  102487. + */
  102488. +
  102489. +#include <linux/module.h>
  102490. +#include <linux/platform_device.h>
  102491. +
  102492. +#include <sound/core.h>
  102493. +#include <sound/pcm.h>
  102494. +#include <sound/pcm_params.h>
  102495. +#include <sound/soc.h>
  102496. +#include <sound/jack.h>
  102497. +
  102498. +static int snd_rpi_hifiberry_dac_init(struct snd_soc_pcm_runtime *rtd)
  102499. +{
  102500. + return 0;
  102501. +}
  102502. +
  102503. +static int snd_rpi_hifiberry_dac_hw_params(struct snd_pcm_substream *substream,
  102504. + struct snd_pcm_hw_params *params)
  102505. +{
  102506. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  102507. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  102508. +
  102509. + unsigned int sample_bits =
  102510. + snd_pcm_format_physical_width(params_format(params));
  102511. +
  102512. + return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
  102513. +}
  102514. +
  102515. +/* machine stream operations */
  102516. +static struct snd_soc_ops snd_rpi_hifiberry_dac_ops = {
  102517. + .hw_params = snd_rpi_hifiberry_dac_hw_params,
  102518. +};
  102519. +
  102520. +static struct snd_soc_dai_link snd_rpi_hifiberry_dac_dai[] = {
  102521. +{
  102522. + .name = "HifiBerry DAC",
  102523. + .stream_name = "HifiBerry DAC HiFi",
  102524. + .cpu_dai_name = "bcm2708-i2s.0",
  102525. + .codec_dai_name = "pcm5102a-hifi",
  102526. + .platform_name = "bcm2708-i2s.0",
  102527. + .codec_name = "pcm5102a-codec",
  102528. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  102529. + SND_SOC_DAIFMT_CBS_CFS,
  102530. + .ops = &snd_rpi_hifiberry_dac_ops,
  102531. + .init = snd_rpi_hifiberry_dac_init,
  102532. +},
  102533. +};
  102534. +
  102535. +/* audio machine driver */
  102536. +static struct snd_soc_card snd_rpi_hifiberry_dac = {
  102537. + .name = "snd_rpi_hifiberry_dac",
  102538. + .dai_link = snd_rpi_hifiberry_dac_dai,
  102539. + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_dac_dai),
  102540. +};
  102541. +
  102542. +static int snd_rpi_hifiberry_dac_probe(struct platform_device *pdev)
  102543. +{
  102544. + int ret = 0;
  102545. +
  102546. + snd_rpi_hifiberry_dac.dev = &pdev->dev;
  102547. + ret = snd_soc_register_card(&snd_rpi_hifiberry_dac);
  102548. + if (ret)
  102549. + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
  102550. +
  102551. + return ret;
  102552. +}
  102553. +
  102554. +static int snd_rpi_hifiberry_dac_remove(struct platform_device *pdev)
  102555. +{
  102556. + return snd_soc_unregister_card(&snd_rpi_hifiberry_dac);
  102557. +}
  102558. +
  102559. +static struct platform_driver snd_rpi_hifiberry_dac_driver = {
  102560. + .driver = {
  102561. + .name = "snd-hifiberry-dac",
  102562. + .owner = THIS_MODULE,
  102563. + },
  102564. + .probe = snd_rpi_hifiberry_dac_probe,
  102565. + .remove = snd_rpi_hifiberry_dac_remove,
  102566. +};
  102567. +
  102568. +module_platform_driver(snd_rpi_hifiberry_dac_driver);
  102569. +
  102570. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  102571. +MODULE_DESCRIPTION("ASoC Driver for HifiBerry DAC");
  102572. +MODULE_LICENSE("GPL v2");
  102573. diff -Nur linux-3.13.11/sound/soc/bcm/hifiberry_digi.c linux-rpi/sound/soc/bcm/hifiberry_digi.c
  102574. --- linux-3.13.11/sound/soc/bcm/hifiberry_digi.c 1970-01-01 01:00:00.000000000 +0100
  102575. +++ linux-rpi/sound/soc/bcm/hifiberry_digi.c 2014-04-24 15:37:24.123108534 +0200
  102576. @@ -0,0 +1,153 @@
  102577. +/*
  102578. + * ASoC Driver for HifiBerry Digi
  102579. + *
  102580. + * Author: Daniel Matuschek <info@crazy-audio.com>
  102581. + * based on the HifiBerry DAC driver by Florian Meier <florian.meier@koalo.de>
  102582. + * Copyright 2013
  102583. + *
  102584. + * This program is free software; you can redistribute it and/or
  102585. + * modify it under the terms of the GNU General Public License
  102586. + * version 2 as published by the Free Software Foundation.
  102587. + *
  102588. + * This program is distributed in the hope that it will be useful, but
  102589. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  102590. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  102591. + * General Public License for more details.
  102592. + */
  102593. +
  102594. +#include <linux/module.h>
  102595. +#include <linux/platform_device.h>
  102596. +
  102597. +#include <sound/core.h>
  102598. +#include <sound/pcm.h>
  102599. +#include <sound/pcm_params.h>
  102600. +#include <sound/soc.h>
  102601. +#include <sound/jack.h>
  102602. +
  102603. +#include "../codecs/wm8804.h"
  102604. +
  102605. +static int samplerate=44100;
  102606. +
  102607. +static int snd_rpi_hifiberry_digi_init(struct snd_soc_pcm_runtime *rtd)
  102608. +{
  102609. + struct snd_soc_codec *codec = rtd->codec;
  102610. +
  102611. + /* enable TX output */
  102612. + snd_soc_update_bits(codec, WM8804_PWRDN, 0x4, 0x0);
  102613. +
  102614. + return 0;
  102615. +}
  102616. +
  102617. +static int snd_rpi_hifiberry_digi_hw_params(struct snd_pcm_substream *substream,
  102618. + struct snd_pcm_hw_params *params)
  102619. +{
  102620. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  102621. + struct snd_soc_dai *codec_dai = rtd->codec_dai;
  102622. + struct snd_soc_codec *codec = rtd->codec;
  102623. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  102624. +
  102625. + int sysclk = 27000000; /* This is fixed on this board */
  102626. +
  102627. + long mclk_freq=0;
  102628. + int mclk_div=1;
  102629. +
  102630. + int ret;
  102631. +
  102632. + samplerate = params_rate(params);
  102633. +
  102634. + switch (samplerate) {
  102635. + case 44100:
  102636. + case 48000:
  102637. + case 88200:
  102638. + case 96000:
  102639. + mclk_freq=samplerate*256;
  102640. + mclk_div=WM8804_MCLKDIV_256FS;
  102641. + break;
  102642. + case 176400:
  102643. + case 192000:
  102644. + mclk_freq=samplerate*128;
  102645. + mclk_div=WM8804_MCLKDIV_128FS;
  102646. + break;
  102647. + default:
  102648. + dev_err(substream->pcm->dev,
  102649. + "Failed to set WM8804 SYSCLK, unsupported samplerate\n");
  102650. + }
  102651. +
  102652. + snd_soc_dai_set_clkdiv(codec_dai, WM8804_MCLK_DIV, mclk_div);
  102653. + snd_soc_dai_set_pll(codec_dai, 0, 0, sysclk, mclk_freq);
  102654. +
  102655. + ret = snd_soc_dai_set_sysclk(codec_dai, WM8804_TX_CLKSRC_PLL,
  102656. + sysclk, SND_SOC_CLOCK_OUT);
  102657. + if (ret < 0) {
  102658. + dev_err(substream->pcm->dev,
  102659. + "Failed to set WM8804 SYSCLK: %d\n", ret);
  102660. + return ret;
  102661. + }
  102662. +
  102663. + /* Enable TX output */
  102664. + snd_soc_update_bits(codec, WM8804_PWRDN, 0x4, 0x0);
  102665. +
  102666. + /* Power on */
  102667. + snd_soc_update_bits(codec, WM8804_PWRDN, 0x9, 0);
  102668. +
  102669. + return snd_soc_dai_set_bclk_ratio(cpu_dai,64);
  102670. +}
  102671. +
  102672. +/* machine stream operations */
  102673. +static struct snd_soc_ops snd_rpi_hifiberry_digi_ops = {
  102674. + .hw_params = snd_rpi_hifiberry_digi_hw_params,
  102675. +};
  102676. +
  102677. +static struct snd_soc_dai_link snd_rpi_hifiberry_digi_dai[] = {
  102678. +{
  102679. + .name = "HifiBerry Digi",
  102680. + .stream_name = "HifiBerry Digi HiFi",
  102681. + .cpu_dai_name = "bcm2708-i2s.0",
  102682. + .codec_dai_name = "wm8804-spdif",
  102683. + .platform_name = "bcm2708-i2s.0",
  102684. + .codec_name = "wm8804.1-003b",
  102685. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  102686. + SND_SOC_DAIFMT_CBM_CFM,
  102687. + .ops = &snd_rpi_hifiberry_digi_ops,
  102688. + .init = snd_rpi_hifiberry_digi_init,
  102689. +},
  102690. +};
  102691. +
  102692. +/* audio machine driver */
  102693. +static struct snd_soc_card snd_rpi_hifiberry_digi = {
  102694. + .name = "snd_rpi_hifiberry_digi",
  102695. + .dai_link = snd_rpi_hifiberry_digi_dai,
  102696. + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_digi_dai),
  102697. +};
  102698. +
  102699. +static int snd_rpi_hifiberry_digi_probe(struct platform_device *pdev)
  102700. +{
  102701. + int ret = 0;
  102702. +
  102703. + snd_rpi_hifiberry_digi.dev = &pdev->dev;
  102704. + ret = snd_soc_register_card(&snd_rpi_hifiberry_digi);
  102705. + if (ret)
  102706. + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
  102707. +
  102708. + return ret;
  102709. +}
  102710. +
  102711. +static int snd_rpi_hifiberry_digi_remove(struct platform_device *pdev)
  102712. +{
  102713. + return snd_soc_unregister_card(&snd_rpi_hifiberry_digi);
  102714. +}
  102715. +
  102716. +static struct platform_driver snd_rpi_hifiberry_digi_driver = {
  102717. + .driver = {
  102718. + .name = "snd-hifiberry-digi",
  102719. + .owner = THIS_MODULE,
  102720. + },
  102721. + .probe = snd_rpi_hifiberry_digi_probe,
  102722. + .remove = snd_rpi_hifiberry_digi_remove,
  102723. +};
  102724. +
  102725. +module_platform_driver(snd_rpi_hifiberry_digi_driver);
  102726. +
  102727. +MODULE_AUTHOR("Daniel Matuschek <info@crazy-audio.com>");
  102728. +MODULE_DESCRIPTION("ASoC Driver for HifiBerry Digi");
  102729. +MODULE_LICENSE("GPL v2");
  102730. diff -Nur linux-3.13.11/sound/soc/bcm/iqaudio-dac.c linux-rpi/sound/soc/bcm/iqaudio-dac.c
  102731. --- linux-3.13.11/sound/soc/bcm/iqaudio-dac.c 1970-01-01 01:00:00.000000000 +0100
  102732. +++ linux-rpi/sound/soc/bcm/iqaudio-dac.c 2014-04-24 15:37:24.123108534 +0200
  102733. @@ -0,0 +1,111 @@
  102734. +/*
  102735. + * ASoC Driver for IQaudIO DAC
  102736. + *
  102737. + * Author: Florian Meier <florian.meier@koalo.de>
  102738. + * Copyright 2013
  102739. + *
  102740. + * This program is free software; you can redistribute it and/or
  102741. + * modify it under the terms of the GNU General Public License
  102742. + * version 2 as published by the Free Software Foundation.
  102743. + *
  102744. + * This program is distributed in the hope that it will be useful, but
  102745. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  102746. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  102747. + * General Public License for more details.
  102748. + */
  102749. +
  102750. +#include <linux/module.h>
  102751. +#include <linux/platform_device.h>
  102752. +
  102753. +#include <sound/core.h>
  102754. +#include <sound/pcm.h>
  102755. +#include <sound/pcm_params.h>
  102756. +#include <sound/soc.h>
  102757. +#include <sound/jack.h>
  102758. +
  102759. +static int snd_rpi_iqaudio_dac_init(struct snd_soc_pcm_runtime *rtd)
  102760. +{
  102761. +// NOT USED struct snd_soc_codec *codec = rtd->codec;
  102762. +
  102763. + return 0;
  102764. +}
  102765. +
  102766. +static int snd_rpi_iqaudio_dac_hw_params(struct snd_pcm_substream *substream,
  102767. + struct snd_pcm_hw_params *params)
  102768. +{
  102769. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  102770. +// NOT USED struct snd_soc_dai *codec_dai = rtd->codec_dai;
  102771. +// NOT USED struct snd_soc_codec *codec = rtd->codec;
  102772. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  102773. +
  102774. + unsigned int sample_bits =
  102775. + snd_pcm_format_physical_width(params_format(params));
  102776. +
  102777. + return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
  102778. +}
  102779. +
  102780. +/* machine stream operations */
  102781. +static struct snd_soc_ops snd_rpi_iqaudio_dac_ops = {
  102782. + .hw_params = snd_rpi_iqaudio_dac_hw_params,
  102783. +};
  102784. +
  102785. +static struct snd_soc_dai_link snd_rpi_iqaudio_dac_dai[] = {
  102786. +{
  102787. + .name = "IQaudIO DAC",
  102788. + .stream_name = "IQaudIO DAC HiFi",
  102789. + .cpu_dai_name = "bcm2708-i2s.0",
  102790. + .codec_dai_name = "pcm512x-hifi",
  102791. + .platform_name = "bcm2708-i2s.0",
  102792. + .codec_name = "pcm512x.1-004c",
  102793. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  102794. + SND_SOC_DAIFMT_CBS_CFS,
  102795. + .ops = &snd_rpi_iqaudio_dac_ops,
  102796. + .init = snd_rpi_iqaudio_dac_init,
  102797. +},
  102798. +};
  102799. +
  102800. +/* audio machine driver */
  102801. +static struct snd_soc_card snd_rpi_iqaudio_dac = {
  102802. + .name = "snd_rpi_iqaudio_dac",
  102803. + .dai_link = snd_rpi_iqaudio_dac_dai,
  102804. + .num_links = ARRAY_SIZE(snd_rpi_iqaudio_dac_dai),
  102805. +};
  102806. +
  102807. +static int snd_rpi_iqaudio_dac_probe(struct platform_device *pdev)
  102808. +{
  102809. + int ret = 0;
  102810. +
  102811. + snd_rpi_iqaudio_dac.dev = &pdev->dev;
  102812. + ret = snd_soc_register_card(&snd_rpi_iqaudio_dac);
  102813. + if (ret)
  102814. + dev_err(&pdev->dev,
  102815. + "snd_soc_register_card() failed: %d\n", ret);
  102816. +
  102817. + return ret;
  102818. +}
  102819. +
  102820. +static int snd_rpi_iqaudio_dac_remove(struct platform_device *pdev)
  102821. +{
  102822. + return snd_soc_unregister_card(&snd_rpi_iqaudio_dac);
  102823. +}
  102824. +
  102825. +static const struct of_device_id iqaudio_of_match[] = {
  102826. + { .compatible = "iqaudio,iqaudio-dac", },
  102827. + {},
  102828. +};
  102829. +
  102830. +static struct platform_driver snd_rpi_iqaudio_dac_driver = {
  102831. + .driver = {
  102832. + .name = "snd-rpi-iqaudio-dac",
  102833. + .owner = THIS_MODULE,
  102834. + .of_match_table = iqaudio_of_match,
  102835. + },
  102836. + .probe = snd_rpi_iqaudio_dac_probe,
  102837. + .remove = snd_rpi_iqaudio_dac_remove,
  102838. +};
  102839. +
  102840. +module_platform_driver(snd_rpi_iqaudio_dac_driver);
  102841. +
  102842. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  102843. +MODULE_DESCRIPTION("ASoC Driver for IQAudio DAC");
  102844. +MODULE_LICENSE("GPL v2");
  102845. diff -Nur linux-3.13.11/sound/soc/bcm/Kconfig linux-rpi/sound/soc/bcm/Kconfig
  102846. --- linux-3.13.11/sound/soc/bcm/Kconfig 1970-01-01 01:00:00.000000000 +0100
  102847. +++ linux-rpi/sound/soc/bcm/Kconfig 2014-04-24 15:35:05.481580345 +0200
  102848. @@ -0,0 +1,38 @@
  102849. +config SND_BCM2708_SOC_I2S
  102850. + tristate "SoC Audio support for the Broadcom BCM2708 I2S module"
  102851. + depends on MACH_BCM2708
  102852. + select REGMAP_MMIO
  102853. + select SND_SOC_DMAENGINE_PCM
  102854. + select SND_SOC_GENERIC_DMAENGINE_PCM
  102855. + help
  102856. + Say Y or M if you want to add support for codecs attached to
  102857. + the BCM2708 I2S interface. You will also need
  102858. + to select the audio interfaces to support below.
  102859. +
  102860. +config SND_BCM2708_SOC_HIFIBERRY_DAC
  102861. + tristate "Support for HifiBerry DAC"
  102862. + depends on SND_BCM2708_SOC_I2S
  102863. + select SND_SOC_PCM5102A
  102864. + help
  102865. + Say Y or M if you want to add support for HifiBerry DAC.
  102866. +
  102867. +config SND_BCM2708_SOC_HIFIBERRY_DIGI
  102868. + tristate "Support for HifiBerry Digi"
  102869. + depends on SND_BCM2708_SOC_I2S
  102870. + select SND_SOC_WM8804
  102871. + help
  102872. + Say Y or M if you want to add support for HifiBerry Digi S/PDIF output board.
  102873. +
  102874. +config SND_BCM2708_SOC_RPI_DAC
  102875. + tristate "Support for RPi-DAC"
  102876. + depends on SND_BCM2708_SOC_I2S
  102877. + select SND_SOC_PCM1794A
  102878. + help
  102879. + Say Y or M if you want to add support for RPi-DAC.
  102880. +
  102881. +config SND_BCM2708_SOC_IQAUDIO_DAC
  102882. + tristate "Support for IQaudIO-DAC"
  102883. + depends on SND_BCM2708_SOC_I2S
  102884. + select SND_SOC_PCM512x
  102885. + help
  102886. + Say Y or M if you want to add support for IQaudIO-DAC.
  102887. diff -Nur linux-3.13.11/sound/soc/bcm/Makefile linux-rpi/sound/soc/bcm/Makefile
  102888. --- linux-3.13.11/sound/soc/bcm/Makefile 1970-01-01 01:00:00.000000000 +0100
  102889. +++ linux-rpi/sound/soc/bcm/Makefile 2014-04-24 15:37:24.123108534 +0200
  102890. @@ -0,0 +1,15 @@
  102891. +# BCM2708 Platform Support
  102892. +snd-soc-bcm2708-i2s-objs := bcm2708-i2s.o
  102893. +
  102894. +obj-$(CONFIG_SND_BCM2708_SOC_I2S) += snd-soc-bcm2708-i2s.o
  102895. +
  102896. +# BCM2708 Machine Support
  102897. +snd-soc-hifiberry-dac-objs := hifiberry_dac.o
  102898. +snd-soc-hifiberry-digi-objs := hifiberry_digi.o
  102899. +snd-soc-rpi-dac-objs := rpi-dac.o
  102900. +snd-soc-iqaudio-dac-objs := iqaudio-dac.o
  102901. +
  102902. +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
  102903. +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) += snd-soc-hifiberry-digi.o
  102904. +obj-$(CONFIG_SND_BCM2708_SOC_RPI_DAC) += snd-soc-rpi-dac.o
  102905. +obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) += snd-soc-iqaudio-dac.o
  102906. diff -Nur linux-3.13.11/sound/soc/bcm/rpi-dac.c linux-rpi/sound/soc/bcm/rpi-dac.c
  102907. --- linux-3.13.11/sound/soc/bcm/rpi-dac.c 1970-01-01 01:00:00.000000000 +0100
  102908. +++ linux-rpi/sound/soc/bcm/rpi-dac.c 2014-04-24 15:35:05.481580345 +0200
  102909. @@ -0,0 +1,97 @@
  102910. +/*
  102911. + * ASoC Driver for RPi-DAC.
  102912. + *
  102913. + * Author: Florian Meier <florian.meier@koalo.de>
  102914. + * Copyright 2013
  102915. + *
  102916. + * This program is free software; you can redistribute it and/or
  102917. + * modify it under the terms of the GNU General Public License
  102918. + * version 2 as published by the Free Software Foundation.
  102919. + *
  102920. + * This program is distributed in the hope that it will be useful, but
  102921. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  102922. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  102923. + * General Public License for more details.
  102924. + */
  102925. +
  102926. +#include <linux/module.h>
  102927. +#include <linux/platform_device.h>
  102928. +
  102929. +#include <sound/core.h>
  102930. +#include <sound/pcm.h>
  102931. +#include <sound/pcm_params.h>
  102932. +#include <sound/soc.h>
  102933. +#include <sound/jack.h>
  102934. +
  102935. +static int snd_rpi_rpi_dac_init(struct snd_soc_pcm_runtime *rtd)
  102936. +{
  102937. + return 0;
  102938. +}
  102939. +
  102940. +static int snd_rpi_rpi_dac_hw_params(struct snd_pcm_substream *substream,
  102941. + struct snd_pcm_hw_params *params)
  102942. +{
  102943. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  102944. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  102945. +
  102946. + return snd_soc_dai_set_bclk_ratio(cpu_dai, 32*2);
  102947. +}
  102948. +
  102949. +/* machine stream operations */
  102950. +static struct snd_soc_ops snd_rpi_rpi_dac_ops = {
  102951. + .hw_params = snd_rpi_rpi_dac_hw_params,
  102952. +};
  102953. +
  102954. +static struct snd_soc_dai_link snd_rpi_rpi_dac_dai[] = {
  102955. +{
  102956. + .name = "HifiBerry Mini",
  102957. + .stream_name = "HifiBerry Mini HiFi",
  102958. + .cpu_dai_name = "bcm2708-i2s.0",
  102959. + .codec_dai_name = "pcm1794a-hifi",
  102960. + .platform_name = "bcm2708-i2s.0",
  102961. + .codec_name = "pcm1794a-codec",
  102962. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  102963. + SND_SOC_DAIFMT_CBS_CFS,
  102964. + .ops = &snd_rpi_rpi_dac_ops,
  102965. + .init = snd_rpi_rpi_dac_init,
  102966. +},
  102967. +};
  102968. +
  102969. +/* audio machine driver */
  102970. +static struct snd_soc_card snd_rpi_rpi_dac = {
  102971. + .name = "snd_rpi_rpi_dac",
  102972. + .dai_link = snd_rpi_rpi_dac_dai,
  102973. + .num_links = ARRAY_SIZE(snd_rpi_rpi_dac_dai),
  102974. +};
  102975. +
  102976. +static int snd_rpi_rpi_dac_probe(struct platform_device *pdev)
  102977. +{
  102978. + int ret = 0;
  102979. +
  102980. + snd_rpi_rpi_dac.dev = &pdev->dev;
  102981. + ret = snd_soc_register_card(&snd_rpi_rpi_dac);
  102982. + if (ret)
  102983. + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
  102984. +
  102985. + return ret;
  102986. +}
  102987. +
  102988. +static int snd_rpi_rpi_dac_remove(struct platform_device *pdev)
  102989. +{
  102990. + return snd_soc_unregister_card(&snd_rpi_rpi_dac);
  102991. +}
  102992. +
  102993. +static struct platform_driver snd_rpi_rpi_dac_driver = {
  102994. + .driver = {
  102995. + .name = "snd-rpi-dac",
  102996. + .owner = THIS_MODULE,
  102997. + },
  102998. + .probe = snd_rpi_rpi_dac_probe,
  102999. + .remove = snd_rpi_rpi_dac_remove,
  103000. +};
  103001. +
  103002. +module_platform_driver(snd_rpi_rpi_dac_driver);
  103003. +
  103004. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  103005. +MODULE_DESCRIPTION("ASoC Driver for RPi-DAC");
  103006. +MODULE_LICENSE("GPL v2");
  103007. diff -Nur linux-3.13.11/sound/soc/codecs/Kconfig linux-rpi/sound/soc/codecs/Kconfig
  103008. --- linux-3.13.11/sound/soc/codecs/Kconfig 2014-04-23 01:49:33.000000000 +0200
  103009. +++ linux-rpi/sound/soc/codecs/Kconfig 2014-04-24 15:37:24.127108578 +0200
  103010. @@ -59,6 +59,9 @@
  103011. select SND_SOC_PCM1681 if I2C
  103012. select SND_SOC_PCM1792A if SPI_MASTER
  103013. select SND_SOC_PCM3008
  103014. + select SND_SOC_PCM1794A
  103015. + select SND_SOC_PCM5102A
  103016. + select SND_SOC_PCM512x if SND_SOC_I2C_AND_SPI
  103017. select SND_SOC_RT5631 if I2C
  103018. select SND_SOC_RT5640 if I2C
  103019. select SND_SOC_SGTL5000 if I2C
  103020. @@ -311,6 +314,15 @@
  103021. config SND_SOC_PCM3008
  103022. tristate
  103023. +config SND_SOC_PCM1794A
  103024. + tristate
  103025. +
  103026. +config SND_SOC_PCM5102A
  103027. + tristate
  103028. +
  103029. +config SND_SOC_PCM512x
  103030. + tristate
  103031. +
  103032. config SND_SOC_RT5631
  103033. tristate
  103034. diff -Nur linux-3.13.11/sound/soc/codecs/Makefile linux-rpi/sound/soc/codecs/Makefile
  103035. --- linux-3.13.11/sound/soc/codecs/Makefile 2014-04-23 01:49:33.000000000 +0200
  103036. +++ linux-rpi/sound/soc/codecs/Makefile 2014-04-24 15:37:24.127108578 +0200
  103037. @@ -46,6 +46,9 @@
  103038. snd-soc-pcm1681-objs := pcm1681.o
  103039. snd-soc-pcm1792a-codec-objs := pcm1792a.o
  103040. snd-soc-pcm3008-objs := pcm3008.o
  103041. +snd-soc-pcm1794a-objs := pcm1794a.o
  103042. +snd-soc-pcm5102a-objs := pcm5102a.o
  103043. +snd-soc-pcm512x-objs := pcm512x.o
  103044. snd-soc-rt5631-objs := rt5631.o
  103045. snd-soc-rt5640-objs := rt5640.o
  103046. snd-soc-sgtl5000-objs := sgtl5000.o
  103047. @@ -179,6 +182,9 @@
  103048. obj-$(CONFIG_SND_SOC_PCM1681) += snd-soc-pcm1681.o
  103049. obj-$(CONFIG_SND_SOC_PCM1792A) += snd-soc-pcm1792a-codec.o
  103050. obj-$(CONFIG_SND_SOC_PCM3008) += snd-soc-pcm3008.o
  103051. +obj-$(CONFIG_SND_SOC_PCM1794A) += snd-soc-pcm1794a.o
  103052. +obj-$(CONFIG_SND_SOC_PCM5102A) += snd-soc-pcm5102a.o
  103053. +obj-$(CONFIG_SND_SOC_PCM512x) += snd-soc-pcm512x.o
  103054. obj-$(CONFIG_SND_SOC_RT5631) += snd-soc-rt5631.o
  103055. obj-$(CONFIG_SND_SOC_RT5640) += snd-soc-rt5640.o
  103056. obj-$(CONFIG_SND_SOC_SGTL5000) += snd-soc-sgtl5000.o
  103057. diff -Nur linux-3.13.11/sound/soc/codecs/pcm1794a.c linux-rpi/sound/soc/codecs/pcm1794a.c
  103058. --- linux-3.13.11/sound/soc/codecs/pcm1794a.c 1970-01-01 01:00:00.000000000 +0100
  103059. +++ linux-rpi/sound/soc/codecs/pcm1794a.c 2014-04-24 15:35:05.493580478 +0200
  103060. @@ -0,0 +1,62 @@
  103061. +/*
  103062. + * Driver for the PCM1794A codec
  103063. + *
  103064. + * Author: Florian Meier <florian.meier@koalo.de>
  103065. + * Copyright 2013
  103066. + *
  103067. + * This program is free software; you can redistribute it and/or
  103068. + * modify it under the terms of the GNU General Public License
  103069. + * version 2 as published by the Free Software Foundation.
  103070. + *
  103071. + * This program is distributed in the hope that it will be useful, but
  103072. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  103073. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  103074. + * General Public License for more details.
  103075. + */
  103076. +
  103077. +
  103078. +#include <linux/init.h>
  103079. +#include <linux/module.h>
  103080. +#include <linux/platform_device.h>
  103081. +
  103082. +#include <sound/soc.h>
  103083. +
  103084. +static struct snd_soc_dai_driver pcm1794a_dai = {
  103085. + .name = "pcm1794a-hifi",
  103086. + .playback = {
  103087. + .channels_min = 2,
  103088. + .channels_max = 2,
  103089. + .rates = SNDRV_PCM_RATE_8000_192000,
  103090. + .formats = SNDRV_PCM_FMTBIT_S16_LE |
  103091. + SNDRV_PCM_FMTBIT_S24_LE
  103092. + },
  103093. +};
  103094. +
  103095. +static struct snd_soc_codec_driver soc_codec_dev_pcm1794a;
  103096. +
  103097. +static int pcm1794a_probe(struct platform_device *pdev)
  103098. +{
  103099. + return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_pcm1794a,
  103100. + &pcm1794a_dai, 1);
  103101. +}
  103102. +
  103103. +static int pcm1794a_remove(struct platform_device *pdev)
  103104. +{
  103105. + snd_soc_unregister_codec(&pdev->dev);
  103106. + return 0;
  103107. +}
  103108. +
  103109. +static struct platform_driver pcm1794a_codec_driver = {
  103110. + .probe = pcm1794a_probe,
  103111. + .remove = pcm1794a_remove,
  103112. + .driver = {
  103113. + .name = "pcm1794a-codec",
  103114. + .owner = THIS_MODULE,
  103115. + },
  103116. +};
  103117. +
  103118. +module_platform_driver(pcm1794a_codec_driver);
  103119. +
  103120. +MODULE_DESCRIPTION("ASoC PCM1794A codec driver");
  103121. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  103122. +MODULE_LICENSE("GPL v2");
  103123. diff -Nur linux-3.13.11/sound/soc/codecs/pcm5102a.c linux-rpi/sound/soc/codecs/pcm5102a.c
  103124. --- linux-3.13.11/sound/soc/codecs/pcm5102a.c 1970-01-01 01:00:00.000000000 +0100
  103125. +++ linux-rpi/sound/soc/codecs/pcm5102a.c 2014-04-24 15:35:05.493580478 +0200
  103126. @@ -0,0 +1,63 @@
  103127. +/*
  103128. + * Driver for the PCM5102A codec
  103129. + *
  103130. + * Author: Florian Meier <florian.meier@koalo.de>
  103131. + * Copyright 2013
  103132. + *
  103133. + * This program is free software; you can redistribute it and/or
  103134. + * modify it under the terms of the GNU General Public License
  103135. + * version 2 as published by the Free Software Foundation.
  103136. + *
  103137. + * This program is distributed in the hope that it will be useful, but
  103138. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  103139. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  103140. + * General Public License for more details.
  103141. + */
  103142. +
  103143. +
  103144. +#include <linux/init.h>
  103145. +#include <linux/module.h>
  103146. +#include <linux/platform_device.h>
  103147. +
  103148. +#include <sound/soc.h>
  103149. +
  103150. +static struct snd_soc_dai_driver pcm5102a_dai = {
  103151. + .name = "pcm5102a-hifi",
  103152. + .playback = {
  103153. + .channels_min = 2,
  103154. + .channels_max = 2,
  103155. + .rates = SNDRV_PCM_RATE_8000_192000,
  103156. + .formats = SNDRV_PCM_FMTBIT_S16_LE |
  103157. + // SNDRV_PCM_FMTBIT_S24_LE | : disable for now, it causes white noise with xbmc
  103158. + SNDRV_PCM_FMTBIT_S32_LE
  103159. + },
  103160. +};
  103161. +
  103162. +static struct snd_soc_codec_driver soc_codec_dev_pcm5102a;
  103163. +
  103164. +static int pcm5102a_probe(struct platform_device *pdev)
  103165. +{
  103166. + return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_pcm5102a,
  103167. + &pcm5102a_dai, 1);
  103168. +}
  103169. +
  103170. +static int pcm5102a_remove(struct platform_device *pdev)
  103171. +{
  103172. + snd_soc_unregister_codec(&pdev->dev);
  103173. + return 0;
  103174. +}
  103175. +
  103176. +static struct platform_driver pcm5102a_codec_driver = {
  103177. + .probe = pcm5102a_probe,
  103178. + .remove = pcm5102a_remove,
  103179. + .driver = {
  103180. + .name = "pcm5102a-codec",
  103181. + .owner = THIS_MODULE,
  103182. + },
  103183. +};
  103184. +
  103185. +module_platform_driver(pcm5102a_codec_driver);
  103186. +
  103187. +MODULE_DESCRIPTION("ASoC PCM5102A codec driver");
  103188. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  103189. +MODULE_LICENSE("GPL v2");
  103190. diff -Nur linux-3.13.11/sound/soc/codecs/pcm512x.c linux-rpi/sound/soc/codecs/pcm512x.c
  103191. --- linux-3.13.11/sound/soc/codecs/pcm512x.c 1970-01-01 01:00:00.000000000 +0100
  103192. +++ linux-rpi/sound/soc/codecs/pcm512x.c 2014-04-24 15:37:24.143108753 +0200
  103193. @@ -0,0 +1,678 @@
  103194. +/*
  103195. + * Driver for the PCM512x CODECs
  103196. + *
  103197. + * Author: Mark Brown <broonie@linaro.org>
  103198. + * Copyright 2014 Linaro Ltd
  103199. + *
  103200. + * This program is free software; you can redistribute it and/or
  103201. + * modify it under the terms of the GNU General Public License
  103202. + * version 2 as published by the Free Software Foundation.
  103203. + *
  103204. + * This program is distributed in the hope that it will be useful, but
  103205. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  103206. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  103207. + * General Public License for more details.
  103208. + */
  103209. +
  103210. +
  103211. +#include <linux/init.h>
  103212. +#include <linux/module.h>
  103213. +#include <linux/clk.h>
  103214. +#include <linux/i2c.h>
  103215. +#include <linux/pm_runtime.h>
  103216. +#include <linux/regmap.h>
  103217. +#include <linux/regulator/consumer.h>
  103218. +#include <linux/spi/spi.h>
  103219. +#include <sound/soc.h>
  103220. +#include <sound/soc-dapm.h>
  103221. +#include <sound/tlv.h>
  103222. +
  103223. +#include "pcm512x.h"
  103224. +
  103225. +#define PCM512x_NUM_SUPPLIES 3
  103226. +static const char *pcm512x_supply_names[PCM512x_NUM_SUPPLIES] = {
  103227. + "AVDD",
  103228. + "DVDD",
  103229. + "CPVDD",
  103230. +};
  103231. +
  103232. +struct pcm512x_priv {
  103233. + struct regmap *regmap;
  103234. + struct clk *sclk;
  103235. + struct regulator_bulk_data supplies[PCM512x_NUM_SUPPLIES];
  103236. + struct notifier_block supply_nb[PCM512x_NUM_SUPPLIES];
  103237. +};
  103238. +
  103239. +/*
  103240. + * We can't use the same notifier block for more than one supply and
  103241. + * there's no way I can see to get from a callback to the caller
  103242. + * except container_of().
  103243. + */
  103244. +#define PCM512x_REGULATOR_EVENT(n) \
  103245. +static int pcm512x_regulator_event_##n(struct notifier_block *nb, \
  103246. + unsigned long event, void *data) \
  103247. +{ \
  103248. + struct pcm512x_priv *pcm512x = container_of(nb, struct pcm512x_priv, \
  103249. + supply_nb[n]); \
  103250. + if (event & REGULATOR_EVENT_DISABLE) { \
  103251. + regcache_mark_dirty(pcm512x->regmap); \
  103252. + regcache_cache_only(pcm512x->regmap, true); \
  103253. + } \
  103254. + return 0; \
  103255. +}
  103256. +
  103257. +PCM512x_REGULATOR_EVENT(0)
  103258. +PCM512x_REGULATOR_EVENT(1)
  103259. +PCM512x_REGULATOR_EVENT(2)
  103260. +
  103261. +static const struct reg_default pcm512x_reg_defaults[] = {
  103262. + { PCM512x_RESET, 0x00 },
  103263. + { PCM512x_POWER, 0x00 },
  103264. + { PCM512x_MUTE, 0x00 },
  103265. + { PCM512x_DSP, 0x00 },
  103266. + { PCM512x_PLL_REF, 0x00 },
  103267. + { PCM512x_DAC_ROUTING, 0x11 },
  103268. + { PCM512x_DSP_PROGRAM, 0x01 },
  103269. + { PCM512x_CLKDET, 0x00 },
  103270. + { PCM512x_AUTO_MUTE, 0x00 },
  103271. + { PCM512x_ERROR_DETECT, 0x00 },
  103272. + { PCM512x_DIGITAL_VOLUME_1, 0x00 },
  103273. + { PCM512x_DIGITAL_VOLUME_2, 0x30 },
  103274. + { PCM512x_DIGITAL_VOLUME_3, 0x30 },
  103275. + { PCM512x_DIGITAL_MUTE_1, 0x22 },
  103276. + { PCM512x_DIGITAL_MUTE_2, 0x00 },
  103277. + { PCM512x_DIGITAL_MUTE_3, 0x07 },
  103278. +};
  103279. +
  103280. +static bool pcm512x_readable(struct device *dev, unsigned int reg)
  103281. +{
  103282. + switch (reg) {
  103283. + case PCM512x_RESET:
  103284. + case PCM512x_POWER:
  103285. + case PCM512x_MUTE:
  103286. + case PCM512x_PLL_EN:
  103287. + case PCM512x_SPI_MISO_FUNCTION:
  103288. + case PCM512x_DSP:
  103289. + case PCM512x_GPIO_EN:
  103290. + case PCM512x_BCLK_LRCLK_CFG:
  103291. + case PCM512x_DSP_GPIO_INPUT:
  103292. + case PCM512x_MASTER_MODE:
  103293. + case PCM512x_PLL_REF:
  103294. + case PCM512x_PLL_COEFF_0:
  103295. + case PCM512x_PLL_COEFF_1:
  103296. + case PCM512x_PLL_COEFF_2:
  103297. + case PCM512x_PLL_COEFF_3:
  103298. + case PCM512x_PLL_COEFF_4:
  103299. + case PCM512x_DSP_CLKDIV:
  103300. + case PCM512x_DAC_CLKDIV:
  103301. + case PCM512x_NCP_CLKDIV:
  103302. + case PCM512x_OSR_CLKDIV:
  103303. + case PCM512x_MASTER_CLKDIV_1:
  103304. + case PCM512x_MASTER_CLKDIV_2:
  103305. + case PCM512x_FS_SPEED_MODE:
  103306. + case PCM512x_IDAC_1:
  103307. + case PCM512x_IDAC_2:
  103308. + case PCM512x_ERROR_DETECT:
  103309. + case PCM512x_I2S_1:
  103310. + case PCM512x_I2S_2:
  103311. + case PCM512x_DAC_ROUTING:
  103312. + case PCM512x_DSP_PROGRAM:
  103313. + case PCM512x_CLKDET:
  103314. + case PCM512x_AUTO_MUTE:
  103315. + case PCM512x_DIGITAL_VOLUME_1:
  103316. + case PCM512x_DIGITAL_VOLUME_2:
  103317. + case PCM512x_DIGITAL_VOLUME_3:
  103318. + case PCM512x_DIGITAL_MUTE_1:
  103319. + case PCM512x_DIGITAL_MUTE_2:
  103320. + case PCM512x_DIGITAL_MUTE_3:
  103321. + case PCM512x_GPIO_OUTPUT_1:
  103322. + case PCM512x_GPIO_OUTPUT_2:
  103323. + case PCM512x_GPIO_OUTPUT_3:
  103324. + case PCM512x_GPIO_OUTPUT_4:
  103325. + case PCM512x_GPIO_OUTPUT_5:
  103326. + case PCM512x_GPIO_OUTPUT_6:
  103327. + case PCM512x_GPIO_CONTROL_1:
  103328. + case PCM512x_GPIO_CONTROL_2:
  103329. + case PCM512x_OVERFLOW:
  103330. + case PCM512x_RATE_DET_1:
  103331. + case PCM512x_RATE_DET_2:
  103332. + case PCM512x_RATE_DET_3:
  103333. + case PCM512x_RATE_DET_4:
  103334. + case PCM512x_ANALOG_MUTE_DET:
  103335. + case PCM512x_GPIN:
  103336. + case PCM512x_DIGITAL_MUTE_DET:
  103337. + return true;
  103338. + default:
  103339. + return false;
  103340. + }
  103341. +}
  103342. +
  103343. +static bool pcm512x_volatile(struct device *dev, unsigned int reg)
  103344. +{
  103345. + switch (reg) {
  103346. + case PCM512x_PLL_EN:
  103347. + case PCM512x_OVERFLOW:
  103348. + case PCM512x_RATE_DET_1:
  103349. + case PCM512x_RATE_DET_2:
  103350. + case PCM512x_RATE_DET_3:
  103351. + case PCM512x_RATE_DET_4:
  103352. + case PCM512x_ANALOG_MUTE_DET:
  103353. + case PCM512x_GPIN:
  103354. + case PCM512x_DIGITAL_MUTE_DET:
  103355. + return true;
  103356. + default:
  103357. + return false;
  103358. + }
  103359. +}
  103360. +
  103361. +static const DECLARE_TLV_DB_SCALE(digital_tlv, -10350, 50, 1);
  103362. +
  103363. +static const char *pcm512x_dsp_program_texts[] = {
  103364. + "FIR interpolation with de-emphasis",
  103365. + "Low latency IIR with de-emphasis",
  103366. + "High attenuation with de-emphasis",
  103367. + "Ringing-less low latency FIR",
  103368. +};
  103369. +
  103370. +static const unsigned int pcm512x_dsp_program_values[] = {
  103371. + 1,
  103372. + 2,
  103373. + 3,
  103374. + 5,
  103375. + 7,
  103376. +};
  103377. +
  103378. +static const SOC_VALUE_ENUM_SINGLE_DECL(pcm512x_dsp_program,
  103379. + PCM512x_DSP_PROGRAM, 0, 0x1f,
  103380. + pcm512x_dsp_program_texts,
  103381. + pcm512x_dsp_program_values);
  103382. +
  103383. +static const char *pcm512x_clk_missing_text[] = {
  103384. + "1s", "2s", "3s", "4s", "5s", "6s", "7s", "8s"
  103385. +};
  103386. +
  103387. +static const struct soc_enum pcm512x_clk_missing =
  103388. + SOC_ENUM_SINGLE(PCM512x_CLKDET, 0, 7, pcm512x_clk_missing_text);
  103389. +
  103390. +static const char *pcm512x_autom_text[] = {
  103391. + "21ms", "106ms", "213ms", "533ms", "1.07s", "2.13s", "5.33s", "10.66s"
  103392. +};
  103393. +
  103394. +static const struct soc_enum pcm512x_autom_l =
  103395. + SOC_ENUM_SINGLE(PCM512x_AUTO_MUTE, PCM512x_ATML_SHIFT, 7,
  103396. + pcm512x_autom_text);
  103397. +
  103398. +static const struct soc_enum pcm512x_autom_r =
  103399. + SOC_ENUM_SINGLE(PCM512x_AUTO_MUTE, PCM512x_ATMR_SHIFT, 7,
  103400. + pcm512x_autom_text);
  103401. +
  103402. +static const char *pcm512x_ramp_rate_text[] = {
  103403. + "1 sample/update", "2 samples/update", "4 samples/update",
  103404. + "Immediate"
  103405. +};
  103406. +
  103407. +static const struct soc_enum pcm512x_vndf =
  103408. + SOC_ENUM_SINGLE(PCM512x_DIGITAL_MUTE_1, PCM512x_VNDF_SHIFT, 4,
  103409. + pcm512x_ramp_rate_text);
  103410. +
  103411. +static const struct soc_enum pcm512x_vnuf =
  103412. + SOC_ENUM_SINGLE(PCM512x_DIGITAL_MUTE_1, PCM512x_VNUF_SHIFT, 4,
  103413. + pcm512x_ramp_rate_text);
  103414. +
  103415. +static const struct soc_enum pcm512x_vedf =
  103416. + SOC_ENUM_SINGLE(PCM512x_DIGITAL_MUTE_2, PCM512x_VEDF_SHIFT, 4,
  103417. + pcm512x_ramp_rate_text);
  103418. +
  103419. +static const char *pcm512x_ramp_step_text[] = {
  103420. + "4dB/step", "2dB/step", "1dB/step", "0.5dB/step"
  103421. +};
  103422. +
  103423. +static const struct soc_enum pcm512x_vnds =
  103424. + SOC_ENUM_SINGLE(PCM512x_DIGITAL_MUTE_1, PCM512x_VNDS_SHIFT, 4,
  103425. + pcm512x_ramp_step_text);
  103426. +
  103427. +static const struct soc_enum pcm512x_vnus =
  103428. + SOC_ENUM_SINGLE(PCM512x_DIGITAL_MUTE_1, PCM512x_VNUS_SHIFT, 4,
  103429. + pcm512x_ramp_step_text);
  103430. +
  103431. +static const struct soc_enum pcm512x_veds =
  103432. + SOC_ENUM_SINGLE(PCM512x_DIGITAL_MUTE_2, PCM512x_VEDS_SHIFT, 4,
  103433. + pcm512x_ramp_step_text);
  103434. +
  103435. +/* Don't let the DAC go into clipping by limiting the alsa volume control range */
  103436. +static const struct snd_kcontrol_new pcm512x_controls[] = {
  103437. +SOC_DOUBLE_R_RANGE_TLV("Playback Digital Volume", PCM512x_DIGITAL_VOLUME_2,
  103438. + PCM512x_DIGITAL_VOLUME_3, 0, 40, 255, 1, digital_tlv),
  103439. +SOC_DOUBLE("Playback Digital Switch", PCM512x_MUTE, PCM512x_RQML_SHIFT,
  103440. + PCM512x_RQMR_SHIFT, 1, 1),
  103441. +
  103442. +SOC_SINGLE("Deemphasis Switch", PCM512x_DSP, PCM512x_DEMP_SHIFT, 1, 1),
  103443. +SOC_VALUE_ENUM("DSP Program", pcm512x_dsp_program),
  103444. +
  103445. +SOC_ENUM("Clock Missing Period", pcm512x_clk_missing),
  103446. +SOC_ENUM("Auto Mute Time Left", pcm512x_autom_l),
  103447. +SOC_ENUM("Auto Mute Time Right", pcm512x_autom_r),
  103448. +SOC_SINGLE("Auto Mute Mono Switch", PCM512x_DIGITAL_MUTE_3,
  103449. + PCM512x_ACTL_SHIFT, 1, 0),
  103450. +SOC_DOUBLE("Auto Mute Switch", PCM512x_DIGITAL_MUTE_3, PCM512x_AMLE_SHIFT,
  103451. + PCM512x_AMLR_SHIFT, 1, 0),
  103452. +
  103453. +SOC_ENUM("Volume Ramp Down Rate", pcm512x_vndf),
  103454. +SOC_ENUM("Volume Ramp Down Step", pcm512x_vnds),
  103455. +SOC_ENUM("Volume Ramp Up Rate", pcm512x_vnuf),
  103456. +SOC_ENUM("Volume Ramp Up Step", pcm512x_vnus),
  103457. +SOC_ENUM("Volume Ramp Down Emergency Rate", pcm512x_vedf),
  103458. +SOC_ENUM("Volume Ramp Down Emergency Step", pcm512x_veds),
  103459. +};
  103460. +
  103461. +static const struct snd_soc_dapm_widget pcm512x_dapm_widgets[] = {
  103462. +SND_SOC_DAPM_DAC("DACL", NULL, SND_SOC_NOPM, 0, 0),
  103463. +SND_SOC_DAPM_DAC("DACR", NULL, SND_SOC_NOPM, 0, 0),
  103464. +
  103465. +SND_SOC_DAPM_OUTPUT("OUTL"),
  103466. +SND_SOC_DAPM_OUTPUT("OUTR"),
  103467. +};
  103468. +
  103469. +static const struct snd_soc_dapm_route pcm512x_dapm_routes[] = {
  103470. + { "DACL", NULL, "Playback" },
  103471. + { "DACR", NULL, "Playback" },
  103472. +
  103473. + { "OUTL", NULL, "DACL" },
  103474. + { "OUTR", NULL, "DACR" },
  103475. +};
  103476. +
  103477. +static int pcm512x_set_bias_level(struct snd_soc_codec *codec,
  103478. + enum snd_soc_bias_level level)
  103479. +{
  103480. + struct pcm512x_priv *pcm512x = dev_get_drvdata(codec->dev);
  103481. + int ret;
  103482. +
  103483. + switch (level) {
  103484. + case SND_SOC_BIAS_ON:
  103485. + case SND_SOC_BIAS_PREPARE:
  103486. + break;
  103487. +
  103488. + case SND_SOC_BIAS_STANDBY:
  103489. + ret = regmap_update_bits(pcm512x->regmap, PCM512x_POWER,
  103490. + PCM512x_RQST, 0);
  103491. + if (ret != 0) {
  103492. + dev_err(codec->dev, "Failed to remove standby: %d\n",
  103493. + ret);
  103494. + return ret;
  103495. + }
  103496. + break;
  103497. +
  103498. + case SND_SOC_BIAS_OFF:
  103499. + ret = regmap_update_bits(pcm512x->regmap, PCM512x_POWER,
  103500. + PCM512x_RQST, PCM512x_RQST);
  103501. + if (ret != 0) {
  103502. + dev_err(codec->dev, "Failed to request standby: %d\n",
  103503. + ret);
  103504. + return ret;
  103505. + }
  103506. + break;
  103507. + }
  103508. +
  103509. + codec->dapm.bias_level = level;
  103510. +
  103511. + return 0;
  103512. +}
  103513. +
  103514. +static struct snd_soc_dai_driver pcm512x_dai = {
  103515. + .name = "pcm512x-hifi",
  103516. + .playback = {
  103517. + .stream_name = "Playback",
  103518. + .channels_min = 2,
  103519. + .channels_max = 2,
  103520. + .rates = SNDRV_PCM_RATE_8000_192000,
  103521. + .formats = SNDRV_PCM_FMTBIT_S16_LE |
  103522. + SNDRV_PCM_FMTBIT_S24_LE |
  103523. + SNDRV_PCM_FMTBIT_S32_LE
  103524. + },
  103525. +};
  103526. +
  103527. +static struct snd_soc_codec_driver pcm512x_codec_driver = {
  103528. + .set_bias_level = pcm512x_set_bias_level,
  103529. + .idle_bias_off = true,
  103530. +
  103531. + .controls = pcm512x_controls,
  103532. + .num_controls = ARRAY_SIZE(pcm512x_controls),
  103533. + .dapm_widgets = pcm512x_dapm_widgets,
  103534. + .num_dapm_widgets = ARRAY_SIZE(pcm512x_dapm_widgets),
  103535. + .dapm_routes = pcm512x_dapm_routes,
  103536. + .num_dapm_routes = ARRAY_SIZE(pcm512x_dapm_routes),
  103537. +};
  103538. +
  103539. +static const struct regmap_config pcm512x_regmap = {
  103540. + .reg_bits = 8,
  103541. + .val_bits = 8,
  103542. +
  103543. + .readable_reg = pcm512x_readable,
  103544. + .volatile_reg = pcm512x_volatile,
  103545. +
  103546. + .max_register = PCM512x_MAX_REGISTER,
  103547. + .reg_defaults = pcm512x_reg_defaults,
  103548. + .num_reg_defaults = ARRAY_SIZE(pcm512x_reg_defaults),
  103549. + .cache_type = REGCACHE_RBTREE,
  103550. +};
  103551. +
  103552. +static const struct of_device_id pcm512x_of_match[] = {
  103553. + { .compatible = "ti,pcm5121", },
  103554. + { .compatible = "ti,pcm5122", },
  103555. + { }
  103556. +};
  103557. +MODULE_DEVICE_TABLE(of, pcm512x_of_match);
  103558. +
  103559. +static int pcm512x_probe(struct device *dev, struct regmap *regmap)
  103560. +{
  103561. + struct pcm512x_priv *pcm512x;
  103562. + int i, ret;
  103563. +
  103564. + pcm512x = devm_kzalloc(dev, sizeof(struct pcm512x_priv), GFP_KERNEL);
  103565. + if (!pcm512x)
  103566. + return -ENOMEM;
  103567. +
  103568. + dev_set_drvdata(dev, pcm512x);
  103569. + pcm512x->regmap = regmap;
  103570. +
  103571. + for (i = 0; i < ARRAY_SIZE(pcm512x->supplies); i++)
  103572. + pcm512x->supplies[i].supply = pcm512x_supply_names[i];
  103573. +
  103574. + ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(pcm512x->supplies),
  103575. + pcm512x->supplies);
  103576. + if (ret != 0) {
  103577. + dev_err(dev, "Failed to get supplies: %d\n", ret);
  103578. + return ret;
  103579. + }
  103580. +
  103581. + pcm512x->supply_nb[0].notifier_call = pcm512x_regulator_event_0;
  103582. + pcm512x->supply_nb[1].notifier_call = pcm512x_regulator_event_1;
  103583. + pcm512x->supply_nb[2].notifier_call = pcm512x_regulator_event_2;
  103584. +
  103585. + for (i = 0; i < ARRAY_SIZE(pcm512x->supplies); i++) {
  103586. + ret = regulator_register_notifier(pcm512x->supplies[i].consumer,
  103587. + &pcm512x->supply_nb[i]);
  103588. + if (ret != 0) {
  103589. + dev_err(dev,
  103590. + "Failed to register regulator notifier: %d\n",
  103591. + ret);
  103592. + }
  103593. + }
  103594. +
  103595. + ret = regulator_bulk_enable(ARRAY_SIZE(pcm512x->supplies),
  103596. + pcm512x->supplies);
  103597. + if (ret != 0) {
  103598. + dev_err(dev, "Failed to enable supplies: %d\n", ret);
  103599. + return ret;
  103600. + }
  103601. +
  103602. + /* Reset the device, verifying I/O in the process for I2C */
  103603. + ret = regmap_write(regmap, PCM512x_RESET,
  103604. + PCM512x_RSTM | PCM512x_RSTR);
  103605. + if (ret != 0) {
  103606. + dev_err(dev, "Failed to reset device: %d\n", ret);
  103607. + goto err;
  103608. + }
  103609. +
  103610. + ret = regmap_write(regmap, PCM512x_RESET, 0);
  103611. + if (ret != 0) {
  103612. + dev_err(dev, "Failed to reset device: %d\n", ret);
  103613. + goto err;
  103614. + }
  103615. +
  103616. + pcm512x->sclk = devm_clk_get(dev, NULL);
  103617. + if (IS_ERR(pcm512x->sclk)) {
  103618. + if (PTR_ERR(pcm512x->sclk) == -EPROBE_DEFER)
  103619. + return -EPROBE_DEFER;
  103620. +
  103621. + dev_info(dev, "No SCLK, using BCLK: %ld\n",
  103622. + PTR_ERR(pcm512x->sclk));
  103623. +
  103624. + /* Disable reporting of missing SCLK as an error */
  103625. + regmap_update_bits(regmap, PCM512x_ERROR_DETECT,
  103626. + PCM512x_IDCH, PCM512x_IDCH);
  103627. +
  103628. + /* Switch PLL input to BCLK */
  103629. + regmap_update_bits(regmap, PCM512x_PLL_REF,
  103630. + PCM512x_SREF, PCM512x_SREF);
  103631. + } else {
  103632. + ret = clk_prepare_enable(pcm512x->sclk);
  103633. + if (ret != 0) {
  103634. + dev_err(dev, "Failed to enable SCLK: %d\n", ret);
  103635. + return ret;
  103636. + }
  103637. + }
  103638. +
  103639. + /* Default to standby mode */
  103640. + ret = regmap_update_bits(pcm512x->regmap, PCM512x_POWER,
  103641. + PCM512x_RQST, PCM512x_RQST);
  103642. + if (ret != 0) {
  103643. + dev_err(dev, "Failed to request standby: %d\n",
  103644. + ret);
  103645. + goto err_clk;
  103646. + }
  103647. +
  103648. + pm_runtime_set_active(dev);
  103649. + pm_runtime_enable(dev);
  103650. + pm_runtime_idle(dev);
  103651. +
  103652. + ret = snd_soc_register_codec(dev, &pcm512x_codec_driver,
  103653. + &pcm512x_dai, 1);
  103654. + if (ret != 0) {
  103655. + dev_err(dev, "Failed to register CODEC: %d\n", ret);
  103656. + goto err_pm;
  103657. + }
  103658. +
  103659. + dev_info(dev, "Completed initialisation - pcm512x_probe");
  103660. +
  103661. + return 0;
  103662. +
  103663. +err_pm:
  103664. + pm_runtime_disable(dev);
  103665. +err_clk:
  103666. + if (!IS_ERR(pcm512x->sclk))
  103667. + clk_disable_unprepare(pcm512x->sclk);
  103668. +err:
  103669. + regulator_bulk_disable(ARRAY_SIZE(pcm512x->supplies),
  103670. + pcm512x->supplies);
  103671. + return ret;
  103672. +}
  103673. +
  103674. +static void pcm512x_remove(struct device *dev)
  103675. +{
  103676. + struct pcm512x_priv *pcm512x = dev_get_drvdata(dev);
  103677. +
  103678. + snd_soc_unregister_codec(dev);
  103679. + pm_runtime_disable(dev);
  103680. + if (!IS_ERR(pcm512x->sclk))
  103681. + clk_disable_unprepare(pcm512x->sclk);
  103682. + regulator_bulk_disable(ARRAY_SIZE(pcm512x->supplies),
  103683. + pcm512x->supplies);
  103684. +}
  103685. +
  103686. +/* TODO
  103687. +static int pcm512x_suspend(struct device *dev)
  103688. +{
  103689. + struct pcm512x_priv *pcm512x = dev_get_drvdata(dev);
  103690. + int ret;
  103691. +
  103692. + ret = regmap_update_bits(pcm512x->regmap, PCM512x_POWER,
  103693. + PCM512x_RQPD, PCM512x_RQPD);
  103694. + if (ret != 0) {
  103695. + dev_err(dev, "Failed to request power down: %d\n", ret);
  103696. + return ret;
  103697. + }
  103698. +
  103699. + ret = regulator_bulk_disable(ARRAY_SIZE(pcm512x->supplies),
  103700. + pcm512x->supplies);
  103701. + if (ret != 0) {
  103702. + dev_err(dev, "Failed to disable supplies: %d\n", ret);
  103703. + return ret;
  103704. + }
  103705. +
  103706. + if (!IS_ERR(pcm512x->sclk))
  103707. + clk_disable_unprepare(pcm512x->sclk);
  103708. +
  103709. + return 0;
  103710. +}
  103711. +
  103712. +static int pcm512x_resume(struct device *dev)
  103713. +{
  103714. + struct pcm512x_priv *pcm512x = dev_get_drvdata(dev);
  103715. + int ret;
  103716. +
  103717. + if (!IS_ERR(pcm512x->sclk)) {
  103718. + ret = clk_prepare_enable(pcm512x->sclk);
  103719. + if (ret != 0) {
  103720. + dev_err(dev, "Failed to enable SCLK: %d\n", ret);
  103721. + return ret;
  103722. + }
  103723. + }
  103724. +
  103725. + ret = regulator_bulk_enable(ARRAY_SIZE(pcm512x->supplies),
  103726. + pcm512x->supplies);
  103727. + if (ret != 0) {
  103728. + dev_err(dev, "Failed to enable supplies: %d\n", ret);
  103729. + return ret;
  103730. + }
  103731. +
  103732. + regcache_cache_only(pcm512x->regmap, false);
  103733. + ret = regcache_sync(pcm512x->regmap);
  103734. + if (ret != 0) {
  103735. + dev_err(dev, "Failed to sync cache: %d\n", ret);
  103736. + return ret;
  103737. + }
  103738. +
  103739. + ret = regmap_update_bits(pcm512x->regmap, PCM512x_POWER,
  103740. + PCM512x_RQPD, 0);
  103741. + if (ret != 0) {
  103742. + dev_err(dev, "Failed to remove power down: %d\n", ret);
  103743. + return ret;
  103744. + }
  103745. +
  103746. + return 0;
  103747. +}
  103748. +
  103749. +// END OF PCM512x_suspend and resume calls TODO
  103750. +*/
  103751. +
  103752. +static const struct dev_pm_ops pcm512x_pm_ops = {
  103753. + SET_RUNTIME_PM_OPS(pcm512x_suspend, pcm512x_resume, NULL)
  103754. +};
  103755. +
  103756. +#if IS_ENABLED(CONFIG_I2C)
  103757. +static int pcm512x_i2c_probe(struct i2c_client *i2c,
  103758. + const struct i2c_device_id *id)
  103759. +{
  103760. + struct regmap *regmap;
  103761. +
  103762. + regmap = devm_regmap_init_i2c(i2c, &pcm512x_regmap);
  103763. + if (IS_ERR(regmap))
  103764. + return PTR_ERR(regmap);
  103765. +
  103766. + return pcm512x_probe(&i2c->dev, regmap);
  103767. +}
  103768. +
  103769. +static int pcm512x_i2c_remove(struct i2c_client *i2c)
  103770. +{
  103771. + pcm512x_remove(&i2c->dev);
  103772. + return 0;
  103773. +}
  103774. +
  103775. +static const struct i2c_device_id pcm512x_i2c_id[] = {
  103776. + { "pcm5121", },
  103777. + { "pcm5122", },
  103778. + { }
  103779. +};
  103780. +MODULE_DEVICE_TABLE(i2c, pcm512x_i2c_id);
  103781. +
  103782. +static struct i2c_driver pcm512x_i2c_driver = {
  103783. + .probe = pcm512x_i2c_probe,
  103784. + .remove = pcm512x_i2c_remove,
  103785. + .id_table = pcm512x_i2c_id,
  103786. + .driver = {
  103787. + .name = "pcm512x",
  103788. + .owner = THIS_MODULE,
  103789. + .of_match_table = pcm512x_of_match,
  103790. + .pm = &pcm512x_pm_ops,
  103791. + },
  103792. +};
  103793. +#endif
  103794. +
  103795. +#if defined(CONFIG_SPI_MASTER)
  103796. +static int pcm512x_spi_probe(struct spi_device *spi)
  103797. +{
  103798. + struct regmap *regmap;
  103799. + int ret;
  103800. +
  103801. + regmap = devm_regmap_init_spi(spi, &pcm512x_regmap);
  103802. + if (IS_ERR(regmap)) {
  103803. + ret = PTR_ERR(regmap);
  103804. + return ret;
  103805. + }
  103806. +
  103807. + return pcm512x_probe(&spi->dev, regmap);
  103808. +}
  103809. +
  103810. +static int pcm512x_spi_remove(struct spi_device *spi)
  103811. +{
  103812. + pcm512x_remove(&spi->dev);
  103813. + return 0;
  103814. +}
  103815. +
  103816. +static const struct spi_device_id pcm512x_spi_id[] = {
  103817. + { "pcm5121", },
  103818. + { "pcm5122", },
  103819. + { },
  103820. +};
  103821. +MODULE_DEVICE_TABLE(spi, pcm512x_spi_id);
  103822. +
  103823. +static struct spi_driver pcm512x_spi_driver = {
  103824. + .probe = pcm512x_spi_probe,
  103825. + .remove = pcm512x_spi_remove,
  103826. + .id_table = pcm512x_spi_id,
  103827. + .driver = {
  103828. + .name = "pcm512x",
  103829. + .owner = THIS_MODULE,
  103830. + .of_match_table = pcm512x_of_match,
  103831. + .pm = &pcm512x_pm_ops,
  103832. + },
  103833. +};
  103834. +#endif
  103835. +
  103836. +static int __init pcm512x_modinit(void)
  103837. +{
  103838. + int ret = 0;
  103839. +
  103840. +#if IS_ENABLED(CONFIG_I2C)
  103841. + ret = i2c_add_driver(&pcm512x_i2c_driver);
  103842. + if (ret) {
  103843. + printk(KERN_ERR "Failed to register pcm512x I2C driver: %d\n",
  103844. + ret);
  103845. + }
  103846. +#endif
  103847. +#if defined(CONFIG_SPI_MASTER)
  103848. + ret = spi_register_driver(&pcm512x_spi_driver);
  103849. + if (ret != 0) {
  103850. + printk(KERN_ERR "Failed to register pcm512x SPI driver: %d\n",
  103851. + ret);
  103852. + }
  103853. +#endif
  103854. + return ret;
  103855. +}
  103856. +module_init(pcm512x_modinit);
  103857. +
  103858. +static void __exit pcm512x_exit(void)
  103859. +{
  103860. +#if IS_ENABLED(CONFIG_I2C)
  103861. + i2c_del_driver(&pcm512x_i2c_driver);
  103862. +#endif
  103863. +#if defined(CONFIG_SPI_MASTER)
  103864. + spi_unregister_driver(&pcm512x_spi_driver);
  103865. +#endif
  103866. +}
  103867. +module_exit(pcm512x_exit);
  103868. +
  103869. +MODULE_DESCRIPTION("ASoC PCM512x codec driver");
  103870. +MODULE_AUTHOR("Mark Brown <broonie@linaro.org>");
  103871. +MODULE_LICENSE("GPL v2");
  103872. diff -Nur linux-3.13.11/sound/soc/codecs/pcm512x.h linux-rpi/sound/soc/codecs/pcm512x.h
  103873. --- linux-3.13.11/sound/soc/codecs/pcm512x.h 1970-01-01 01:00:00.000000000 +0100
  103874. +++ linux-rpi/sound/soc/codecs/pcm512x.h 2014-04-24 15:35:05.493580478 +0200
  103875. @@ -0,0 +1,142 @@
  103876. +/*
  103877. + * Driver for the PCM512x CODECs
  103878. + *
  103879. + * Author: Mark Brown <broonie@linaro.org>
  103880. + * Copyright 2014 Linaro Ltd
  103881. + *
  103882. + * This program is free software; you can redistribute it and/or
  103883. + * modify it under the terms of the GNU General Public License
  103884. + * version 2 as published by the Free Software Foundation.
  103885. + *
  103886. + * This program is distributed in the hope that it will be useful, but
  103887. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  103888. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  103889. + * General Public License for more details.
  103890. + */
  103891. +
  103892. +#ifndef _SND_SOC_PCM512X
  103893. +#define _SND_SOC_PCM512X
  103894. +
  103895. +#define PCM512x_PAGE_0_BASE 0
  103896. +
  103897. +#define PCM512x_PAGE 0
  103898. +
  103899. +#define PCM512x_RESET (PCM512x_PAGE_0_BASE + 1)
  103900. +#define PCM512x_POWER (PCM512x_PAGE_0_BASE + 2)
  103901. +#define PCM512x_MUTE (PCM512x_PAGE_0_BASE + 3)
  103902. +#define PCM512x_PLL_EN (PCM512x_PAGE_0_BASE + 4)
  103903. +#define PCM512x_SPI_MISO_FUNCTION (PCM512x_PAGE_0_BASE + 6)
  103904. +#define PCM512x_DSP (PCM512x_PAGE_0_BASE + 7)
  103905. +#define PCM512x_GPIO_EN (PCM512x_PAGE_0_BASE + 8)
  103906. +#define PCM512x_BCLK_LRCLK_CFG (PCM512x_PAGE_0_BASE + 9)
  103907. +#define PCM512x_DSP_GPIO_INPUT (PCM512x_PAGE_0_BASE + 10)
  103908. +#define PCM512x_MASTER_MODE (PCM512x_PAGE_0_BASE + 12)
  103909. +#define PCM512x_PLL_REF (PCM512x_PAGE_0_BASE + 13)
  103910. +#define PCM512x_PLL_COEFF_0 (PCM512x_PAGE_0_BASE + 20)
  103911. +#define PCM512x_PLL_COEFF_1 (PCM512x_PAGE_0_BASE + 21)
  103912. +#define PCM512x_PLL_COEFF_2 (PCM512x_PAGE_0_BASE + 22)
  103913. +#define PCM512x_PLL_COEFF_3 (PCM512x_PAGE_0_BASE + 23)
  103914. +#define PCM512x_PLL_COEFF_4 (PCM512x_PAGE_0_BASE + 24)
  103915. +#define PCM512x_DSP_CLKDIV (PCM512x_PAGE_0_BASE + 27)
  103916. +#define PCM512x_DAC_CLKDIV (PCM512x_PAGE_0_BASE + 28)
  103917. +#define PCM512x_NCP_CLKDIV (PCM512x_PAGE_0_BASE + 29)
  103918. +#define PCM512x_OSR_CLKDIV (PCM512x_PAGE_0_BASE + 30)
  103919. +#define PCM512x_MASTER_CLKDIV_1 (PCM512x_PAGE_0_BASE + 32)
  103920. +#define PCM512x_MASTER_CLKDIV_2 (PCM512x_PAGE_0_BASE + 33)
  103921. +#define PCM512x_FS_SPEED_MODE (PCM512x_PAGE_0_BASE + 34)
  103922. +#define PCM512x_IDAC_1 (PCM512x_PAGE_0_BASE + 35)
  103923. +#define PCM512x_IDAC_2 (PCM512x_PAGE_0_BASE + 36)
  103924. +#define PCM512x_ERROR_DETECT (PCM512x_PAGE_0_BASE + 37)
  103925. +#define PCM512x_I2S_1 (PCM512x_PAGE_0_BASE + 40)
  103926. +#define PCM512x_I2S_2 (PCM512x_PAGE_0_BASE + 41)
  103927. +#define PCM512x_DAC_ROUTING (PCM512x_PAGE_0_BASE + 42)
  103928. +#define PCM512x_DSP_PROGRAM (PCM512x_PAGE_0_BASE + 43)
  103929. +#define PCM512x_CLKDET (PCM512x_PAGE_0_BASE + 44)
  103930. +#define PCM512x_AUTO_MUTE (PCM512x_PAGE_0_BASE + 59)
  103931. +#define PCM512x_DIGITAL_VOLUME_1 (PCM512x_PAGE_0_BASE + 60)
  103932. +#define PCM512x_DIGITAL_VOLUME_2 (PCM512x_PAGE_0_BASE + 61)
  103933. +#define PCM512x_DIGITAL_VOLUME_3 (PCM512x_PAGE_0_BASE + 62)
  103934. +#define PCM512x_DIGITAL_MUTE_1 (PCM512x_PAGE_0_BASE + 63)
  103935. +#define PCM512x_DIGITAL_MUTE_2 (PCM512x_PAGE_0_BASE + 64)
  103936. +#define PCM512x_DIGITAL_MUTE_3 (PCM512x_PAGE_0_BASE + 65)
  103937. +#define PCM512x_GPIO_OUTPUT_1 (PCM512x_PAGE_0_BASE + 80)
  103938. +#define PCM512x_GPIO_OUTPUT_2 (PCM512x_PAGE_0_BASE + 81)
  103939. +#define PCM512x_GPIO_OUTPUT_3 (PCM512x_PAGE_0_BASE + 82)
  103940. +#define PCM512x_GPIO_OUTPUT_4 (PCM512x_PAGE_0_BASE + 83)
  103941. +#define PCM512x_GPIO_OUTPUT_5 (PCM512x_PAGE_0_BASE + 84)
  103942. +#define PCM512x_GPIO_OUTPUT_6 (PCM512x_PAGE_0_BASE + 85)
  103943. +#define PCM512x_GPIO_CONTROL_1 (PCM512x_PAGE_0_BASE + 86)
  103944. +#define PCM512x_GPIO_CONTROL_2 (PCM512x_PAGE_0_BASE + 87)
  103945. +#define PCM512x_OVERFLOW (PCM512x_PAGE_0_BASE + 90)
  103946. +#define PCM512x_RATE_DET_1 (PCM512x_PAGE_0_BASE + 91)
  103947. +#define PCM512x_RATE_DET_2 (PCM512x_PAGE_0_BASE + 92)
  103948. +#define PCM512x_RATE_DET_3 (PCM512x_PAGE_0_BASE + 93)
  103949. +#define PCM512x_RATE_DET_4 (PCM512x_PAGE_0_BASE + 94)
  103950. +#define PCM512x_ANALOG_MUTE_DET (PCM512x_PAGE_0_BASE + 108)
  103951. +#define PCM512x_GPIN (PCM512x_PAGE_0_BASE + 119)
  103952. +#define PCM512x_DIGITAL_MUTE_DET (PCM512x_PAGE_0_BASE + 120)
  103953. +
  103954. +#define PCM512x_MAX_REGISTER (PCM512x_PAGE_0_BASE + 120)
  103955. +
  103956. +/* Page 0, Register 1 - reset */
  103957. +#define PCM512x_RSTR (1 << 0)
  103958. +#define PCM512x_RSTM (1 << 4)
  103959. +
  103960. +/* Page 0, Register 2 - power */
  103961. +#define PCM512x_RQPD (1 << 0)
  103962. +#define PCM512x_RQPD_SHIFT 0
  103963. +#define PCM512x_RQST (1 << 4)
  103964. +#define PCM512x_RQST_SHIFT 4
  103965. +
  103966. +/* Page 0, Register 3 - mute */
  103967. +#define PCM512x_RQMR_SHIFT 0
  103968. +#define PCM512x_RQML_SHIFT 4
  103969. +
  103970. +/* Page 0, Register 4 - PLL */
  103971. +#define PCM512x_PLCE (1 << 0)
  103972. +#define PCM512x_RLCE_SHIFT 0
  103973. +#define PCM512x_PLCK (1 << 4)
  103974. +#define PCM512x_PLCK_SHIFT 4
  103975. +
  103976. +/* Page 0, Register 7 - DSP */
  103977. +#define PCM512x_SDSL (1 << 0)
  103978. +#define PCM512x_SDSL_SHIFT 0
  103979. +#define PCM512x_DEMP (1 << 4)
  103980. +#define PCM512x_DEMP_SHIFT 4
  103981. +
  103982. +/* Page 0, Register 13 - PLL reference */
  103983. +#define PCM512x_SREF (1 << 4)
  103984. +
  103985. +/* Page 0, Register 37 - Error detection */
  103986. +#define PCM512x_IPLK (1 << 0)
  103987. +#define PCM512x_DCAS (1 << 1)
  103988. +#define PCM512x_IDCM (1 << 2)
  103989. +#define PCM512x_IDCH (1 << 3)
  103990. +#define PCM512x_IDSK (1 << 4)
  103991. +#define PCM512x_IDBK (1 << 5)
  103992. +#define PCM512x_IDFS (1 << 6)
  103993. +
  103994. +/* Page 0, Register 42 - DAC routing */
  103995. +#define PCM512x_AUPR_SHIFT 0
  103996. +#define PCM512x_AUPL_SHIFT 4
  103997. +
  103998. +/* Page 0, Register 59 - auto mute */
  103999. +#define PCM512x_ATMR_SHIFT 0
  104000. +#define PCM512x_ATML_SHIFT 4
  104001. +
  104002. +/* Page 0, Register 63 - ramp rates */
  104003. +#define PCM512x_VNDF_SHIFT 6
  104004. +#define PCM512x_VNDS_SHIFT 4
  104005. +#define PCM512x_VNUF_SHIFT 2
  104006. +#define PCM512x_VNUS_SHIFT 0
  104007. +
  104008. +/* Page 0, Register 64 - emergency ramp rates */
  104009. +#define PCM512x_VEDF_SHIFT 6
  104010. +#define PCM512x_VEDS_SHIFT 4
  104011. +
  104012. +/* Page 0, Register 65 - Digital mute enables */
  104013. +#define PCM512x_ACTL_SHIFT 2
  104014. +#define PCM512x_AMLE_SHIFT 1
  104015. +#define PCM512x_AMLR_SHIFT 0
  104016. +
  104017. +#endif
  104018. diff -Nur linux-3.13.11/sound/soc/codecs/wm8804.c linux-rpi/sound/soc/codecs/wm8804.c
  104019. --- linux-3.13.11/sound/soc/codecs/wm8804.c 2014-04-23 01:49:33.000000000 +0200
  104020. +++ linux-rpi/sound/soc/codecs/wm8804.c 2014-04-24 15:35:05.509580657 +0200
  104021. @@ -63,6 +63,7 @@
  104022. struct regmap *regmap;
  104023. struct regulator_bulk_data supplies[WM8804_NUM_SUPPLIES];
  104024. struct notifier_block disable_nb[WM8804_NUM_SUPPLIES];
  104025. + int mclk_div;
  104026. };
  104027. static int txsrc_get(struct snd_kcontrol *kcontrol,
  104028. @@ -277,6 +278,7 @@
  104029. blen = 0x1;
  104030. break;
  104031. case SNDRV_PCM_FORMAT_S24_LE:
  104032. + case SNDRV_PCM_FORMAT_S32_LE:
  104033. blen = 0x2;
  104034. break;
  104035. default:
  104036. @@ -318,7 +320,7 @@
  104037. #define FIXED_PLL_SIZE ((1ULL << 22) * 10)
  104038. static int pll_factors(struct pll_div *pll_div, unsigned int target,
  104039. - unsigned int source)
  104040. + unsigned int source, unsigned int mclk_div)
  104041. {
  104042. u64 Kpart;
  104043. unsigned long int K, Ndiv, Nmod, tmp;
  104044. @@ -330,7 +332,8 @@
  104045. */
  104046. for (i = 0; i < ARRAY_SIZE(post_table); i++) {
  104047. tmp = target * post_table[i].div;
  104048. - if (tmp >= 90000000 && tmp <= 100000000) {
  104049. + if ((tmp >= 90000000 && tmp <= 100000000) &&
  104050. + (mclk_div == post_table[i].mclkdiv)) {
  104051. pll_div->freqmode = post_table[i].freqmode;
  104052. pll_div->mclkdiv = post_table[i].mclkdiv;
  104053. target *= post_table[i].div;
  104054. @@ -387,8 +390,11 @@
  104055. } else {
  104056. int ret;
  104057. struct pll_div pll_div;
  104058. + struct wm8804_priv *wm8804;
  104059. - ret = pll_factors(&pll_div, freq_out, freq_in);
  104060. + wm8804 = snd_soc_codec_get_drvdata(codec);
  104061. +
  104062. + ret = pll_factors(&pll_div, freq_out, freq_in, wm8804->mclk_div);
  104063. if (ret)
  104064. return ret;
  104065. @@ -452,6 +458,7 @@
  104066. int div_id, int div)
  104067. {
  104068. struct snd_soc_codec *codec;
  104069. + struct wm8804_priv *wm8804;
  104070. codec = dai->codec;
  104071. switch (div_id) {
  104072. @@ -459,6 +466,10 @@
  104073. snd_soc_update_bits(codec, WM8804_PLL5, 0x30,
  104074. (div & 0x3) << 4);
  104075. break;
  104076. + case WM8804_MCLK_DIV:
  104077. + wm8804 = snd_soc_codec_get_drvdata(codec);
  104078. + wm8804->mclk_div = div;
  104079. + break;
  104080. default:
  104081. dev_err(dai->dev, "Unknown clock divider: %d\n", div_id);
  104082. return -EINVAL;
  104083. @@ -641,7 +652,7 @@
  104084. };
  104085. #define WM8804_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
  104086. - SNDRV_PCM_FMTBIT_S24_LE)
  104087. + SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE)
  104088. #define WM8804_RATES (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
  104089. SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_64000 | \
  104090. @@ -674,7 +685,7 @@
  104091. .suspend = wm8804_suspend,
  104092. .resume = wm8804_resume,
  104093. .set_bias_level = wm8804_set_bias_level,
  104094. - .idle_bias_off = true,
  104095. + .idle_bias_off = false,
  104096. .controls = wm8804_snd_controls,
  104097. .num_controls = ARRAY_SIZE(wm8804_snd_controls),
  104098. diff -Nur linux-3.13.11/sound/soc/codecs/wm8804.h linux-rpi/sound/soc/codecs/wm8804.h
  104099. --- linux-3.13.11/sound/soc/codecs/wm8804.h 2014-04-23 01:49:33.000000000 +0200
  104100. +++ linux-rpi/sound/soc/codecs/wm8804.h 2014-04-24 15:35:05.509580657 +0200
  104101. @@ -57,5 +57,9 @@
  104102. #define WM8804_CLKOUT_SRC_OSCCLK 4
  104103. #define WM8804_CLKOUT_DIV 1
  104104. +#define WM8804_MCLK_DIV 2
  104105. +
  104106. +#define WM8804_MCLKDIV_256FS 0
  104107. +#define WM8804_MCLKDIV_128FS 1
  104108. #endif /* _WM8804_H */
  104109. diff -Nur linux-3.13.11/sound/soc/Kconfig linux-rpi/sound/soc/Kconfig
  104110. --- linux-3.13.11/sound/soc/Kconfig 2014-04-23 01:49:33.000000000 +0200
  104111. +++ linux-rpi/sound/soc/Kconfig 2014-04-24 15:37:23.655103429 +0200
  104112. @@ -33,6 +33,7 @@
  104113. # All the supported SoCs
  104114. source "sound/soc/atmel/Kconfig"
  104115. source "sound/soc/au1x/Kconfig"
  104116. +source "sound/soc/bcm/Kconfig"
  104117. source "sound/soc/blackfin/Kconfig"
  104118. source "sound/soc/cirrus/Kconfig"
  104119. source "sound/soc/davinci/Kconfig"
  104120. diff -Nur linux-3.13.11/sound/soc/Makefile linux-rpi/sound/soc/Makefile
  104121. --- linux-3.13.11/sound/soc/Makefile 2014-04-23 01:49:33.000000000 +0200
  104122. +++ linux-rpi/sound/soc/Makefile 2014-04-24 15:37:23.655103429 +0200
  104123. @@ -10,6 +10,7 @@
  104124. obj-$(CONFIG_SND_SOC) += generic/
  104125. obj-$(CONFIG_SND_SOC) += atmel/
  104126. obj-$(CONFIG_SND_SOC) += au1x/
  104127. +obj-$(CONFIG_SND_SOC) += bcm/
  104128. obj-$(CONFIG_SND_SOC) += blackfin/
  104129. obj-$(CONFIG_SND_SOC) += cirrus/
  104130. obj-$(CONFIG_SND_SOC) += davinci/
  104131. diff -Nur linux-3.13.11/sound/soc/soc-core.c linux-rpi/sound/soc/soc-core.c
  104132. --- linux-3.13.11/sound/soc/soc-core.c 2014-04-23 01:49:33.000000000 +0200
  104133. +++ linux-rpi/sound/soc/soc-core.c 2014-04-24 15:37:24.751115385 +0200
  104134. @@ -3037,8 +3037,8 @@
  104135. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  104136. uinfo->count = snd_soc_volsw_is_stereo(mc) ? 2 : 1;
  104137. - uinfo->value.integer.min = 0;
  104138. - uinfo->value.integer.max = platform_max - min;
  104139. + uinfo->value.integer.min = min;
  104140. + uinfo->value.integer.max = platform_max;
  104141. return 0;
  104142. }
  104143. @@ -3069,9 +3069,10 @@
  104144. unsigned int val, val_mask;
  104145. int ret;
  104146. - val = ((ucontrol->value.integer.value[0] + min) & mask);
  104147. if (invert)
  104148. - val = max - val;
  104149. + val = ((max - ucontrol->value.integer.value[0] + min) & mask);
  104150. + else
  104151. + val = (ucontrol->value.integer.value[0] & mask);
  104152. val_mask = mask << shift;
  104153. val = val << shift;
  104154. @@ -3080,9 +3081,10 @@
  104155. return ret;
  104156. if (snd_soc_volsw_is_stereo(mc)) {
  104157. - val = ((ucontrol->value.integer.value[1] + min) & mask);
  104158. if (invert)
  104159. - val = max - val;
  104160. + val = ((max - ucontrol->value.integer.value[1] + min) & mask);
  104161. + else
  104162. + val = (ucontrol->value.integer.value[1] & mask);
  104163. val_mask = mask << shift;
  104164. val = val << shift;
  104165. @@ -3120,18 +3122,14 @@
  104166. (snd_soc_read(codec, reg) >> shift) & mask;
  104167. if (invert)
  104168. ucontrol->value.integer.value[0] =
  104169. - max - ucontrol->value.integer.value[0];
  104170. - ucontrol->value.integer.value[0] =
  104171. - ucontrol->value.integer.value[0] - min;
  104172. + max - ucontrol->value.integer.value[0] + min;
  104173. if (snd_soc_volsw_is_stereo(mc)) {
  104174. ucontrol->value.integer.value[1] =
  104175. (snd_soc_read(codec, rreg) >> shift) & mask;
  104176. if (invert)
  104177. ucontrol->value.integer.value[1] =
  104178. - max - ucontrol->value.integer.value[1];
  104179. - ucontrol->value.integer.value[1] =
  104180. - ucontrol->value.integer.value[1] - min;
  104181. + max - ucontrol->value.integer.value[1] + min;
  104182. }
  104183. return 0;